]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog.C
If I ever see another licence blurb again, it'll be too soon...
[lyx.git] / src / frontends / qt2 / FileDialog.C
1 /**
2  * \file qt2/FileDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11
12 #include <config.h>
13
14 #include "lfuns.h"
15 #include "LString.h"
16 #include "frontends/FileDialog.h"
17 #include "FileDialog_private.h"
18 #include "debug.h"
19 #include "qt_helpers.h"
20 #include "gettext.h"
21
22 #include <qapplication.h>
23
24 #include <utility>
25
26 using std::make_pair;
27 using std::pair;
28 using std::endl;
29
30
31 struct FileDialog::Private {
32         Button b1;
33         Button b2;
34 };
35
36
37 FileDialog::FileDialog(string const & t,
38                        kb_action s, Button b1, Button b2)
39         : private_(new FileDialog::Private), title_(t), success_(s)
40 {
41         private_->b1 = b1;
42         private_->b2 = b2;
43 }
44
45
46 FileDialog::~FileDialog()
47 {
48         delete private_;
49 }
50
51
52 FileDialog::Result const FileDialog::save(string const & path,
53                                             string const & mask,
54                                             string const & suggested)
55 {
56         string filter(mask);
57         if (mask.empty())
58                 filter = _("All files (*)");
59
60         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
61         lyxerr[Debug::GUI] << "Select with path \"" << path
62                            << "\", mask \"" << filter
63                            << "\", suggested \"" << suggested << endl;
64
65         dlg.setMode(QFileDialog::AnyFile);
66
67         if (!suggested.empty())
68                 dlg.setSelection(toqstr(suggested));
69
70         FileDialog::Result result;
71         lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
72         result.first = FileDialog::Chosen;
73         int res = dlg.exec();
74         lyxerr[Debug::GUI] << "result " << res << endl;
75         if (res == QDialog::Accepted)
76                 result.second = string(dlg.selectedFile().data());
77         dlg.hide();
78         return result;
79 }
80
81
82 FileDialog::Result const FileDialog::open(string const & path,
83                                             string const & mask,
84                                             string const & suggested)
85 {
86         string filter(mask);
87         if (mask.empty())
88                 filter = _("All files (*)");
89
90         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
91         lyxerr[Debug::GUI] << "Select with path \"" << path
92                            << "\", mask \"" << filter
93                            << "\", suggested \"" << suggested << endl;
94
95         if (!suggested.empty())
96                 dlg.setSelection(toqstr(suggested));
97
98         FileDialog::Result result;
99         lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
100         result.first = FileDialog::Chosen;
101         int res = dlg.exec();
102         lyxerr[Debug::GUI] << "result " << res << endl;
103         if (res == QDialog::Accepted)
104                 result.second = string(dlg.selectedFile().data());
105         dlg.hide();
106         return result;
107 }
108
109
110 FileDialog::Result const FileDialog::opendir(string const & path,
111                                             string const & suggested)
112 {
113         string filter = _("Directories");
114
115         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
116         lyxerr[Debug::GUI] << "Select with path \"" << path
117                            << "\", suggested \"" << suggested << endl;
118
119         dlg.setMode(QFileDialog::DirectoryOnly);
120
121         if (!suggested.empty())
122                 dlg.setSelection(toqstr(suggested));
123
124         FileDialog::Result result;
125         lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
126         result.first = FileDialog::Chosen;
127         int res = dlg.exec();
128         lyxerr[Debug::GUI] << "result " << res << endl;
129         if (res == QDialog::Accepted)
130                 result.second = string(dlg.selectedFile().data());
131         dlg.hide();
132         return result;
133 }