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::updateContents()
70 all_formats_ = allFormats();
72 // Check whether the current contents of the browser will be
73 // changed by loading the contents of formats
75 keys.resize(all_formats_.size());
77 vector<string>::iterator result = keys.begin();
78 vector<Format const *>::const_iterator it = all_formats_.begin();
79 vector<Format const *>::const_iterator end = all_formats_.end();
80 for (; it != end; ++it, ++result)
81 *result = (*it)->prettyname();
86 for (vector<string>::const_iterator it = keys.begin();
87 it != keys.end(); ++it) {
88 formatLW->addItem(toqstr(*it));
91 commandCO->addItem(toqstr(command_));
95 void GuiSendTo::applyView()
97 int const line = formatLW->currentRow();
99 if (line < 0 || line > int(formatLW->count()))
102 format_ = all_formats_[line];
103 command_ = trim(fromqstr(commandCO->currentText()));
107 bool GuiSendTo::isValid()
109 int const line = formatLW->currentRow();
111 if (line < 0 || line > int(formatLW->count()))
114 return formatLW->count() != 0 &&
115 !commandCO->currentText().isEmpty();
119 bool GuiSendTo::initialiseParams(string const &)
122 command_ = lyxrc.custom_export_command;
127 void GuiSendTo::dispatchParams()
129 if (command_.empty() || !format_ || format_->name().empty())
132 string const data = format_->name() + " " + command_;
133 dispatch(FuncRequest(getLfun(), data));
136 // FIXME: Move to Converters?
137 vector<Format const *> GuiSendTo::allFormats() const
139 // What formats can we output natively?
140 vector<string> exports;
141 exports.push_back("lyx");
142 exports.push_back("text");
144 if (buffer().isLatex()) {
145 exports.push_back("latex");
146 exports.push_back("pdflatex");
148 else if (buffer().isDocBook())
149 exports.push_back("docbook");
150 else if (buffer().isLiterate())
151 exports.push_back("literate");
153 // Loop over these native formats and ascertain what formats we
155 vector<Format const *> to;
157 vector<string>::const_iterator ex_it = exports.begin();
158 vector<string>::const_iterator ex_end = exports.end();
159 for (; ex_it != ex_end; ++ex_it) {
160 // Start off with the native export format.
161 // "formats" is LyX's list of recognised formats
162 to.push_back(formats.getFormat(*ex_it));
164 Formats::const_iterator fo_it = formats.begin();
165 Formats::const_iterator fo_end = formats.end();
166 for (; fo_it != fo_end; ++fo_it) {
167 // we need to hide the default graphic export formats
168 // from the external menu, because we need them only
169 // for the internal lyx-view and external latex run
170 string const name = fo_it->name();
171 if (name != "eps" && name != "xpm" && name != "png" &&
172 theConverters().isReachable(*ex_it, name))
173 to.push_back(&(*fo_it));
177 // Remove repeated formats.
178 sort(to.begin(), to.end());
179 to.erase(unique(to.begin(), to.end()), to.end());
185 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
188 } // namespace frontend
191 #include "GuiSendto_moc.cpp"