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>
39 GuiSendTo::GuiSendTo(LyXView & lv)
40 : GuiDialog(lv, "sendto"), Controller(this)
43 setViewTitle(_("Send Document to Command"));
44 setController(this, false);
46 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
47 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
48 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
50 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
51 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
52 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
53 this, SLOT(slotFormatSelected(QListWidgetItem *)));
54 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
55 this, SLOT(changed_adaptor()));
56 connect(commandCO, SIGNAL(textChanged(QString)),
57 this, SLOT(changed_adaptor()));
59 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
61 bc().setApply(applyPB);
62 bc().setCancel(closePB);
66 void GuiSendTo::changed_adaptor()
72 void GuiSendTo::closeEvent(QCloseEvent * e)
79 void GuiSendTo::updateContents()
81 all_formats_ = allFormats();
83 // Check whether the current contents of the browser will be
84 // changed by loading the contents of formats
86 keys.resize(all_formats_.size());
88 vector<string>::iterator result = keys.begin();
89 vector<Format const *>::const_iterator it = all_formats_.begin();
90 vector<Format const *>::const_iterator end = all_formats_.end();
91 for (; it != end; ++it, ++result)
92 *result = (*it)->prettyname();
97 for (vector<string>::const_iterator it = keys.begin();
98 it != keys.end(); ++it) {
99 formatLW->addItem(toqstr(*it));
102 commandCO->addItem(toqstr(command_));
106 void GuiSendTo::applyView()
108 int const line = formatLW->currentRow();
110 if (line < 0 || line > int(formatLW->count()))
113 format_ = all_formats_[line];
114 command_ = trim(fromqstr(commandCO->currentText()));
118 bool GuiSendTo::isValid()
120 int const line = formatLW->currentRow();
122 if (line < 0 || line > int(formatLW->count()))
125 return formatLW->count() != 0 &&
126 !commandCO->currentText().isEmpty();
130 bool GuiSendTo::initialiseParams(std::string const &)
133 command_ = lyxrc.custom_export_command;
138 void GuiSendTo::dispatchParams()
140 if (command_.empty() || !format_ || format_->name().empty())
143 string const data = format_->name() + " " + command_;
144 dispatch(FuncRequest(getLfun(), data));
147 // FIXME: Move to Converters?
148 vector<Format const *> GuiSendTo::allFormats() const
150 // What formats can we output natively?
151 vector<string> exports;
152 exports.push_back("lyx");
153 exports.push_back("text");
155 if (buffer().isLatex())
156 exports.push_back("latex");
157 else if (buffer().isDocBook())
158 exports.push_back("docbook");
159 else if (buffer().isLiterate())
160 exports.push_back("literate");
162 // Loop over these native formats and ascertain what formats we
164 vector<Format const *> to;
166 vector<string>::const_iterator ex_it = exports.begin();
167 vector<string>::const_iterator ex_end = exports.end();
168 for (; ex_it != ex_end; ++ex_it) {
169 // Start off with the native export format.
170 // "formats" is LyX's list of recognised formats
171 to.push_back(formats.getFormat(*ex_it));
173 Formats::const_iterator fo_it = formats.begin();
174 Formats::const_iterator fo_end = formats.end();
175 for (; fo_it != fo_end; ++fo_it) {
176 // we need to hide the default graphic export formats
177 // from the external menu, because we need them only
178 // for the internal lyx-view and external latex run
179 string const name = fo_it->name();
180 if (name != "eps" && name != "xpm" && name != "png" &&
181 theConverters().isReachable(*ex_it, name))
182 to.push_back(&(*fo_it));
186 // Remove repeated formats.
187 std::sort(to.begin(), to.end());
188 to.erase(std::unique(to.begin(), to.end()), to.end());
194 Dialog * createGuiSendTo(LyXView & lv) { return new GuiSendTo(lv); }
197 } // namespace frontend
200 #include "GuiSendto_moc.cpp"