]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSendto.cpp
Compile fix for qt versions below 4.6.
[lyx.git] / src / frontends / qt4 / GuiSendto.cpp
1 /**
2  * \file GuiSendto.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiSendto.h"
15 #include "qt_helpers.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "Format.h"
20 #include "FuncRequest.h"
21
22 #include "support/qstring_helpers.h"
23 #include "support/filetools.h"
24
25 #include <QLineEdit>
26 #include <QListWidget>
27 #include <QPushButton>
28
29 using namespace std;
30 using namespace lyx::support;
31
32 namespace lyx {
33 namespace frontend {
34
35
36 GuiSendTo::GuiSendTo(GuiView & lv)
37         : GuiDialog(lv, "sendto", qt_("Export or Send Document"))
38 {
39         setupUi(this);
40
41         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
42         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
43         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44
45         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
46                 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
47         connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
48                 this, SLOT(slotFormatSelected(QListWidgetItem *)));
49         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
50                 this, SLOT(changed_adaptor()));
51         connect(formatLW, SIGNAL(itemSelectionChanged()),
52                 this, SLOT(changed_adaptor()));
53         connect(commandCO, SIGNAL(textChanged(QString)),
54                 this, SLOT(changed_adaptor()));
55
56         bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
57         bc().setOK(okPB);
58         bc().setApply(applyPB);
59         bc().setCancel(closePB);
60 }
61
62
63 void GuiSendTo::changed_adaptor()
64 {
65         changed();
66 }
67
68
69 void GuiSendTo::updateContents()
70 {
71         all_formats_ = buffer().params().exportableFormats(false);
72
73         // Save the current selection if any
74         Format const * current_format = 0;
75         int const line = formatLW->currentRow();
76         if (line >= 0 && line <= formatLW->count()
77             && formatLW->selectedItems().size() > 0)
78                 current_format = all_formats_[line];
79
80         // Check whether the current contents of the browser will be
81         // changed by loading the contents of formats
82         vector<string> keys;
83         keys.resize(all_formats_.size());
84
85         vector<string>::iterator result = keys.begin();
86         vector<Format const *>::const_iterator it  = all_formats_.begin();
87         vector<Format const *>::const_iterator end = all_formats_.end();
88
89         int current_line = -1;
90         for (int ln = 0; it != end; ++it, ++result, ++ln) {
91                 *result = (*it)->prettyname();
92                 if (current_format 
93                     && (*it)->prettyname() == current_format->prettyname())
94                         current_line = ln;
95         }
96
97         // Reload the browser
98         formatLW->clear();
99
100         for (vector<string>::const_iterator it = keys.begin();
101              it != keys.end(); ++it) {
102                 formatLW->addItem(qt_(*it));
103         }
104
105         // Restore the selection
106         if (current_line > -1)
107                 formatLW->setCurrentItem(formatLW->item(current_line));
108 }
109
110
111 void GuiSendTo::applyView()
112 {
113         int const line = formatLW->currentRow();
114         QString const command = commandCO->currentText().trimmed();
115
116         if (commandCO->findText(command) == -1)
117                 commandCO->insertItem(0, command);
118
119         if (line < 0 || line > formatLW->count())
120                 return;
121
122         format_ = all_formats_[line];
123         command_ = command;
124 }
125
126
127 bool GuiSendTo::isValid()
128 {
129         int const line = formatLW->currentRow();
130
131         if (line < 0 || line > int(formatLW->count()))
132                 return false;
133
134         return (formatLW->selectedItems().size() > 0
135                 && formatLW->count() != 0);
136 }
137
138
139 bool GuiSendTo::initialiseParams(string const &)
140 {
141         format_ = 0;
142         paramsToDialog(format_, command_);
143         return true;
144 }
145
146
147 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
148 {
149         if (!command.isEmpty())
150                 commandCO->addItem(command);
151
152         bc().setValid(isValid());
153 }
154
155
156 void GuiSendTo::dispatchParams()
157 {
158         if (!format_ || format_->name().empty())
159                 return;
160
161         string data = format_->name();
162         if (!command_.isEmpty())
163                 data += " " + fromqstr(command_);
164
165         FuncCode const lfun = command_.isEmpty() ?
166                 LFUN_BUFFER_EXPORT : getLfun();
167
168         dispatch(FuncRequest(lfun, data));
169 }
170
171 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
172
173
174 } // namespace frontend
175 } // namespace lyx
176
177 #include "moc_GuiSendto.cpp"