]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog.C
Strip out another 350 redundant #includes.
[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 "frontends/FileDialog.h"
15 #include "FileDialog_private.h"
16 #include "debug.h"
17 #include "qt_helpers.h"
18 #include "gettext.h"
19
20 #include <utility>
21
22 using std::make_pair;
23 using std::pair;
24 using std::endl;
25
26
27 struct FileDialog::Private {
28         Button b1;
29         Button b2;
30 };
31
32
33 FileDialog::FileDialog(string const & t,
34                        kb_action s, Button b1, Button b2)
35         : private_(new FileDialog::Private), title_(t), success_(s)
36 {
37         private_->b1 = b1;
38         private_->b2 = b2;
39 }
40
41
42 FileDialog::~FileDialog()
43 {
44         delete private_;
45 }
46
47
48 FileDialog::Result const FileDialog::save(string const & path,
49                                             string const & mask,
50                                             string const & suggested)
51 {
52         string filter(mask);
53         if (mask.empty())
54                 filter = _("All files (*)");
55
56         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
57         lyxerr[Debug::GUI] << "Select with path \"" << path
58                            << "\", mask \"" << filter
59                            << "\", suggested \"" << suggested << endl;
60
61         dlg.setMode(QFileDialog::AnyFile);
62
63         if (!suggested.empty())
64                 dlg.setSelection(toqstr(suggested));
65
66         FileDialog::Result result;
67         lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
68         result.first = FileDialog::Chosen;
69         int res = dlg.exec();
70         lyxerr[Debug::GUI] << "result " << res << endl;
71         if (res == QDialog::Accepted)
72                 result.second = string(dlg.selectedFile().data());
73         dlg.hide();
74         return result;
75 }
76
77
78 FileDialog::Result const FileDialog::open(string const & path,
79                                             string const & mask,
80                                             string const & suggested)
81 {
82         string filter(mask);
83         if (mask.empty())
84                 filter = _("All files (*)");
85
86         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
87         lyxerr[Debug::GUI] << "Select with path \"" << path
88                            << "\", mask \"" << filter
89                            << "\", suggested \"" << suggested << endl;
90
91         if (!suggested.empty())
92                 dlg.setSelection(toqstr(suggested));
93
94         FileDialog::Result result;
95         lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
96         result.first = FileDialog::Chosen;
97         int res = dlg.exec();
98         lyxerr[Debug::GUI] << "result " << res << endl;
99         if (res == QDialog::Accepted)
100                 result.second = string(dlg.selectedFile().data());
101         dlg.hide();
102         return result;
103 }
104
105
106 FileDialog::Result const FileDialog::opendir(string const & path,
107                                             string const & suggested)
108 {
109         string filter = _("Directories");
110
111         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
112         lyxerr[Debug::GUI] << "Select with path \"" << path
113                            << "\", suggested \"" << suggested << endl;
114
115         dlg.setMode(QFileDialog::DirectoryOnly);
116
117         if (!suggested.empty())
118                 dlg.setSelection(toqstr(suggested));
119
120         FileDialog::Result result;
121         lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
122         result.first = FileDialog::Chosen;
123         int res = dlg.exec();
124         lyxerr[Debug::GUI] << "result " << res << endl;
125         if (res == QDialog::Accepted)
126                 result.second = string(dlg.selectedFile().data());
127         dlg.hide();
128         return result;
129 }