3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "GuiSendto.h"
17 #include "Converter.h"
19 #include "FuncRequest.h"
21 #include "qt_helpers.h"
23 #include "support/filetools.h"
24 #include "support/lstrings.h"
26 #include <QListWidget>
27 #include <QPushButton>
28 #include <QCloseEvent>
37 GuiSendTo::GuiSendTo(GuiView & lv)
38 : GuiDialog(lv, "sendto")
41 setViewTitle(_("Send Document to Command"));
43 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
44 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
45 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
47 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
48 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
49 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
50 this, SLOT(slotFormatSelected(QListWidgetItem *)));
51 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
52 this, SLOT(changed_adaptor()));
53 connect(commandCO, SIGNAL(textChanged(QString)),
54 this, SLOT(changed_adaptor()));
56 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
58 bc().setApply(applyPB);
59 bc().setCancel(closePB);
63 void GuiSendTo::changed_adaptor()
69 void GuiSendTo::closeEvent(QCloseEvent * e)
76 void GuiSendTo::updateContents()
78 all_formats_ = allFormats();
80 // Check whether the current contents of the browser will be
81 // changed by loading the contents of formats
83 keys.resize(all_formats_.size());
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 for (; it != end; ++it, ++result)
89 *result = (*it)->prettyname();
94 for (vector<string>::const_iterator it = keys.begin();
95 it != keys.end(); ++it) {
96 formatLW->addItem(toqstr(*it));
99 commandCO->addItem(toqstr(command_));
103 void GuiSendTo::applyView()
105 int const line = formatLW->currentRow();
107 if (line < 0 || line > int(formatLW->count()))
110 format_ = all_formats_[line];
111 command_ = trim(fromqstr(commandCO->currentText()));
115 bool GuiSendTo::isValid()
117 int const line = formatLW->currentRow();
119 if (line < 0 || line > int(formatLW->count()))
122 return formatLW->count() != 0 &&
123 !commandCO->currentText().isEmpty();
127 bool GuiSendTo::initialiseParams(std::string const &)
130 command_ = lyxrc.custom_export_command;
135 void GuiSendTo::dispatchParams()
137 if (command_.empty() || !format_ || format_->name().empty())
140 string const data = format_->name() + " " + command_;
141 dispatch(FuncRequest(getLfun(), data));
144 // FIXME: Move to Converters?
145 vector<Format const *> GuiSendTo::allFormats() const
147 // What formats can we output natively?
148 vector<string> exports;
149 exports.push_back("lyx");
150 exports.push_back("text");
152 if (buffer().isLatex())
153 exports.push_back("latex");
154 else if (buffer().isDocBook())
155 exports.push_back("docbook");
156 else if (buffer().isLiterate())
157 exports.push_back("literate");
159 // Loop over these native formats and ascertain what formats we
161 vector<Format const *> to;
163 vector<string>::const_iterator ex_it = exports.begin();
164 vector<string>::const_iterator ex_end = exports.end();
165 for (; ex_it != ex_end; ++ex_it) {
166 // Start off with the native export format.
167 // "formats" is LyX's list of recognised formats
168 to.push_back(formats.getFormat(*ex_it));
170 Formats::const_iterator fo_it = formats.begin();
171 Formats::const_iterator fo_end = formats.end();
172 for (; fo_it != fo_end; ++fo_it) {
173 // we need to hide the default graphic export formats
174 // from the external menu, because we need them only
175 // for the internal lyx-view and external latex run
176 string const name = fo_it->name();
177 if (name != "eps" && name != "xpm" && name != "png" &&
178 theConverters().isReachable(*ex_it, name))
179 to.push_back(&(*fo_it));
183 // Remove repeated formats.
184 std::sort(to.begin(), to.end());
185 to.erase(std::unique(to.begin(), to.end()), to.end());
191 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
194 } // namespace frontend
197 #include "GuiSendto_moc.cpp"