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>
31 using namespace lyx::support;
37 GuiSendTo::GuiSendTo(GuiView & lv)
38 : GuiDialog(lv, "sendto", qt_("Send Document to Command"))
42 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
43 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
44 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
46 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
47 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
48 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
49 this, SLOT(slotFormatSelected(QListWidgetItem *)));
50 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
51 this, SLOT(changed_adaptor()));
52 connect(commandCO, SIGNAL(textChanged(QString)),
53 this, SLOT(changed_adaptor()));
55 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
57 bc().setApply(applyPB);
58 bc().setCancel(closePB);
62 void GuiSendTo::changed_adaptor()
68 void GuiSendTo::closeEvent(QCloseEvent * e)
75 void GuiSendTo::updateContents()
77 all_formats_ = allFormats();
79 // Check whether the current contents of the browser will be
80 // changed by loading the contents of formats
82 keys.resize(all_formats_.size());
84 vector<string>::iterator result = keys.begin();
85 vector<Format const *>::const_iterator it = all_formats_.begin();
86 vector<Format const *>::const_iterator end = all_formats_.end();
87 for (; it != end; ++it, ++result)
88 *result = (*it)->prettyname();
93 for (vector<string>::const_iterator it = keys.begin();
94 it != keys.end(); ++it) {
95 formatLW->addItem(toqstr(*it));
98 commandCO->addItem(toqstr(command_));
102 void GuiSendTo::applyView()
104 int const line = formatLW->currentRow();
106 if (line < 0 || line > int(formatLW->count()))
109 format_ = all_formats_[line];
110 command_ = trim(fromqstr(commandCO->currentText()));
114 bool GuiSendTo::isValid()
116 int const line = formatLW->currentRow();
118 if (line < 0 || line > int(formatLW->count()))
121 return formatLW->count() != 0 &&
122 !commandCO->currentText().isEmpty();
126 bool GuiSendTo::initialiseParams(string const &)
129 command_ = lyxrc.custom_export_command;
134 void GuiSendTo::dispatchParams()
136 if (command_.empty() || !format_ || format_->name().empty())
139 string const data = format_->name() + " " + command_;
140 dispatch(FuncRequest(getLfun(), data));
143 // FIXME: Move to Converters?
144 vector<Format const *> GuiSendTo::allFormats() const
146 // What formats can we output natively?
147 vector<string> exports;
148 exports.push_back("lyx");
149 exports.push_back("text");
151 if (buffer().isLatex()) {
152 exports.push_back("latex");
153 exports.push_back("pdflatex");
155 else if (buffer().isDocBook())
156 exports.push_back("docbook");
157 else if (buffer().isLiterate())
158 exports.push_back("literate");
160 // Loop over these native formats and ascertain what formats we
162 vector<Format const *> to;
164 vector<string>::const_iterator ex_it = exports.begin();
165 vector<string>::const_iterator ex_end = exports.end();
166 for (; ex_it != ex_end; ++ex_it) {
167 // Start off with the native export format.
168 // "formats" is LyX's list of recognised formats
169 to.push_back(formats.getFormat(*ex_it));
171 Formats::const_iterator fo_it = formats.begin();
172 Formats::const_iterator fo_end = formats.end();
173 for (; fo_it != fo_end; ++fo_it) {
174 // we need to hide the default graphic export formats
175 // from the external menu, because we need them only
176 // for the internal lyx-view and external latex run
177 string const name = fo_it->name();
178 if (name != "eps" && name != "xpm" && name != "png" &&
179 theConverters().isReachable(*ex_it, name))
180 to.push_back(&(*fo_it));
184 // Remove repeated formats.
185 sort(to.begin(), to.end());
186 to.erase(unique(to.begin(), to.end()), to.end());
192 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
195 } // namespace frontend
198 #include "GuiSendto_moc.cpp"