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