]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog_private.C
small cleanup and removal of warnings
[lyx.git] / src / frontends / qt2 / FileDialog_private.C
1 /**
2  * \file FileDialog_private.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 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "QtLyXView.h"
18 #include "debug.h"
19 #include "funcrequest.h"
20 #include "lyxfunc.h"
21 #include "FileDialog_private.h"
22
23 #include "support/lstrings.h"
24
25 #include <qapplication.h>
26 #include <qfiledialog.h>
27 #include <qtoolbutton.h>
28
29
30 namespace {
31         /// return the Qt form of the label
32         string const getLabel(string const & str) {
33                 string label;
34                 string sc(split(str, label, '|'));
35                 if (sc.length() < 2)
36                         return label;
37                 string::size_type pos = label.find(sc[1]);
38                 if (pos == string::npos)
39                         return label;
40                 label.insert(pos, "&");
41                 return label;
42         }
43 }
44
45
46 LyXFileDialog::LyXFileDialog(string const & p, string const & m,
47                              string const & t,
48                 FileDialog::Button const & b1, FileDialog::Button const & b2)
49         : QFileDialog(p.c_str(), m.c_str(),
50                       qApp->mainWidget(), t.c_str(), true),
51           b1_(0), b2_(0)
52 {
53         setCaption(t.c_str());
54
55         if (!b1.first.empty()) {
56                 b1_dir_ = b1.second;
57                 b1_ = new QToolButton(this);
58                 connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
59                 b1_->setText(getLabel(b1.first).c_str());
60                 addToolButton(b1_, true);
61         }
62
63         if (!b2.first.empty()) {
64                 b2_dir_ = b2.second;
65                 b2_ = new QToolButton(this);
66                 connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
67                 b2_->setText(getLabel(b2.first).c_str());
68                 addToolButton(b2_);
69         }
70 }
71
72
73 void LyXFileDialog::buttonClicked()
74 {
75         if (sender() == b1_)
76                 setDir(b1_dir_.c_str());
77         else if (sender() == b2_)
78                 setDir(b2_dir_.c_str());
79 }