]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog.C
Minor bits 'n' bobs from Michael, J�rgen and Jean-Marc.
[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 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <config.h>
16
17 #include "commandtags.h"
18 #include "LString.h"
19 #include "frontends/FileDialog.h"
20 #include "FileDialog_private.h"
21 #include "debug.h"
22 #include "qt_helpers.h"
23 #include "gettext.h"
24
25 #include <qapplication.h>
26
27 #include <utility>
28
29 using std::make_pair;
30 using std::pair;
31 using std::endl;
32
33
34 struct FileDialog::Private {
35         Button b1;
36         Button b2;
37 };
38
39
40 FileDialog::FileDialog(LyXView * lv, string const & t,
41                        kb_action s, Button b1, Button b2)
42         : private_(new FileDialog::Private), lv_(lv), title_(t), success_(s)
43 {
44         private_->b1 = b1;
45         private_->b2 = b2;
46 }
47
48
49 FileDialog::~FileDialog()
50 {
51         delete private_;
52 }
53
54
55 FileDialog::Result const FileDialog::save(string const & path,
56                                             string const & mask,
57                                             string const & suggested)
58 {
59         string filter(mask);
60         if (mask.empty())
61                 filter = _("All files (*)");
62
63         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
64         lyxerr[Debug::GUI] << "Select with path \"" << path
65                            << "\", mask \"" << filter
66                            << "\", suggested \"" << suggested << endl;
67
68         dlg.setMode(QFileDialog::AnyFile);
69
70         if (!suggested.empty())
71                 dlg.setSelection(toqstr(suggested));
72
73         FileDialog::Result result;
74         lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
75         result.first = FileDialog::Chosen;
76         int res = dlg.exec();
77         lyxerr[Debug::GUI] << "result " << res << endl;
78         if (res == QDialog::Accepted)
79                 result.second = string(dlg.selectedFile().data());
80         dlg.hide();
81         return result;
82 }
83
84
85 FileDialog::Result const FileDialog::open(string const & path,
86                                             string const & mask,
87                                             string const & suggested)
88 {
89         string filter(mask);
90         if (mask.empty())
91                 filter = _("*|All files");
92
93         LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
94         lyxerr[Debug::GUI] << "Select with path \"" << path
95                            << "\", mask \"" << filter
96                            << "\", suggested \"" << suggested << endl;
97
98         if (!suggested.empty())
99                 dlg.setSelection(toqstr(suggested));
100
101         FileDialog::Result result;
102         lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
103         result.first = FileDialog::Chosen;
104         int res = dlg.exec();
105         lyxerr[Debug::GUI] << "result " << res << endl;
106         if (res == QDialog::Accepted)
107                 result.second = string(dlg.selectedFile().data());
108         dlg.hide();
109         return result;
110 }