]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSendto.cpp
cosmetics
[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
16 #include "Buffer.h"
17 #include "Converter.h"
18 #include "Format.h"
19 #include "FuncRequest.h"
20 #include "LyXRC.h"
21
22 #include "support/qstring_helpers.h"
23 #include "support/filetools.h"
24
25 #include <QListWidget>
26 #include <QPushButton>
27
28 using namespace std;
29 using namespace lyx::support;
30
31 namespace lyx {
32 namespace frontend {
33
34
35 GuiSendTo::GuiSendTo(GuiView & lv)
36         : GuiDialog(lv, "sendto", qt_("Send Document to Command"))
37 {
38         setupUi(this);
39
40         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
42         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
43
44         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
45                 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
46         connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
47                 this, SLOT(slotFormatSelected(QListWidgetItem *)));
48         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
49                 this, SLOT(changed_adaptor()));
50         connect(commandCO, SIGNAL(textChanged(QString)),
51                 this, SLOT(changed_adaptor()));
52
53         bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
54         bc().setOK(okPB);
55         bc().setApply(applyPB);
56         bc().setCancel(closePB);
57 }
58
59
60 void GuiSendTo::changed_adaptor()
61 {
62         changed();
63 }
64
65
66 void GuiSendTo::updateContents()
67 {
68         all_formats_ = allFormats();
69
70         // Check whether the current contents of the browser will be
71         // changed by loading the contents of formats
72         vector<string> keys;
73         keys.resize(all_formats_.size());
74
75         vector<string>::iterator result = keys.begin();
76         vector<Format const *>::const_iterator it  = all_formats_.begin();
77         vector<Format const *>::const_iterator end = all_formats_.end();
78         for (; it != end; ++it, ++result)
79                 *result = (*it)->prettyname();
80
81         // Reload the browser
82         formatLW->clear();
83
84         for (vector<string>::const_iterator it = keys.begin();
85              it != keys.end(); ++it) {
86                 formatLW->addItem(toqstr(*it));
87         }
88
89         commandCO->addItem(command_);
90 }
91
92
93 void GuiSendTo::applyView()
94 {
95         int const line = formatLW->currentRow();
96
97         if (line < 0 || line > formatLW->count())
98                 return;
99
100         format_ = all_formats_[line];
101         command_ = commandCO->currentText().trimmed();
102 }
103
104
105 bool GuiSendTo::isValid()
106 {
107         int const line = formatLW->currentRow();
108
109         if (line < 0 || line > int(formatLW->count()))
110                 return false;
111
112         return formatLW->count() != 0 &&
113                 !commandCO->currentText().isEmpty();
114 }
115
116
117 bool GuiSendTo::initialiseParams(string const &)
118 {
119         format_ = 0;
120         command_ = toqstr(lyxrc.custom_export_command);
121         return true;
122 }
123
124
125 void GuiSendTo::dispatchParams()
126 {
127         if (command_.isEmpty() || !format_ || format_->name().empty())
128                 return;
129
130         string const data = format_->name() + " " + fromqstr(command_);
131         dispatch(FuncRequest(getLfun(), data));
132 }
133
134 // FIXME: Move to Converters?
135 vector<Format const *> GuiSendTo::allFormats() const
136 {
137         // What formats can we output natively?
138         vector<string> exports;
139         exports.push_back("lyx");
140         exports.push_back("text");
141
142         if (buffer().isLatex()) {
143                 exports.push_back("latex");
144                 exports.push_back("pdflatex");
145         }
146         else if (buffer().isDocBook())
147                 exports.push_back("docbook");
148         else if (buffer().isLiterate())
149                 exports.push_back("literate");
150
151         // Loop over these native formats and ascertain what formats we
152         // can convert to
153         vector<Format const *> to;
154
155         vector<string>::const_iterator ex_it  = exports.begin();
156         vector<string>::const_iterator ex_end = exports.end();
157         for (; ex_it != ex_end; ++ex_it) {
158                 // Start off with the native export format.
159                 // "formats" is LyX's list of recognised formats
160                 to.push_back(formats.getFormat(*ex_it));
161
162                 Formats::const_iterator fo_it  = formats.begin();
163                 Formats::const_iterator fo_end = formats.end();
164                 for (; fo_it != fo_end; ++fo_it) {
165                         // we need to hide the default graphic export formats
166                         // from the external menu, because we need them only
167                         // for the internal lyx-view and external latex run
168                         string const name = fo_it->name();
169                         if (name != "eps" && name != "xpm" && name != "png" &&
170                             theConverters().isReachable(*ex_it, name))
171                                 to.push_back(&(*fo_it));
172                 }
173         }
174
175         // Remove repeated formats.
176         sort(to.begin(), to.end());
177         to.erase(unique(to.begin(), to.end()), to.end());
178
179         return to;
180 }
181
182
183 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
184
185
186 } // namespace frontend
187 } // namespace lyx
188
189 #include "GuiSendto_moc.cpp"