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>
30 using namespace lyx::support;
36 GuiSendTo::GuiSendTo(GuiView & lv)
37 : GuiDialog(lv, "sendto", qt_("Send Document to Command"))
41 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
42 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
43 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
45 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
46 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
47 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
48 this, SLOT(slotFormatSelected(QListWidgetItem *)));
49 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
50 this, SLOT(changed_adaptor()));
51 connect(commandCO, SIGNAL(textChanged(QString)),
52 this, SLOT(changed_adaptor()));
54 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
56 bc().setApply(applyPB);
57 bc().setCancel(closePB);
61 void GuiSendTo::changed_adaptor()
67 void GuiSendTo::updateContents()
69 all_formats_ = allFormats();
71 // Check whether the current contents of the browser will be
72 // changed by loading the contents of formats
74 keys.resize(all_formats_.size());
76 vector<string>::iterator result = keys.begin();
77 vector<Format const *>::const_iterator it = all_formats_.begin();
78 vector<Format const *>::const_iterator end = all_formats_.end();
79 for (; it != end; ++it, ++result)
80 *result = (*it)->prettyname();
85 for (vector<string>::const_iterator it = keys.begin();
86 it != keys.end(); ++it) {
87 formatLW->addItem(toqstr(*it));
90 commandCO->addItem(toqstr(command_));
94 void GuiSendTo::applyView()
96 int const line = formatLW->currentRow();
98 if (line < 0 || line > int(formatLW->count()))
101 format_ = all_formats_[line];
102 command_ = trim(fromqstr(commandCO->currentText()));
106 bool GuiSendTo::isValid()
108 int const line = formatLW->currentRow();
110 if (line < 0 || line > int(formatLW->count()))
113 return formatLW->count() != 0 &&
114 !commandCO->currentText().isEmpty();
118 bool GuiSendTo::initialiseParams(string const &)
121 command_ = lyxrc.custom_export_command;
126 void GuiSendTo::dispatchParams()
128 if (command_.empty() || !format_ || format_->name().empty())
131 string const data = format_->name() + " " + command_;
132 dispatch(FuncRequest(getLfun(), data));
135 // FIXME: Move to Converters?
136 vector<Format const *> GuiSendTo::allFormats() const
138 // What formats can we output natively?
139 vector<string> exports;
140 exports.push_back("lyx");
141 exports.push_back("text");
143 if (buffer().isLatex()) {
144 exports.push_back("latex");
145 exports.push_back("pdflatex");
147 else if (buffer().isDocBook())
148 exports.push_back("docbook");
149 else if (buffer().isLiterate())
150 exports.push_back("literate");
152 // Loop over these native formats and ascertain what formats we
154 vector<Format const *> to;
156 vector<string>::const_iterator ex_it = exports.begin();
157 vector<string>::const_iterator ex_end = exports.end();
158 for (; ex_it != ex_end; ++ex_it) {
159 // Start off with the native export format.
160 // "formats" is LyX's list of recognised formats
161 to.push_back(formats.getFormat(*ex_it));
163 Formats::const_iterator fo_it = formats.begin();
164 Formats::const_iterator fo_end = formats.end();
165 for (; fo_it != fo_end; ++fo_it) {
166 // we need to hide the default graphic export formats
167 // from the external menu, because we need them only
168 // for the internal lyx-view and external latex run
169 string const name = fo_it->name();
170 if (name != "eps" && name != "xpm" && name != "png" &&
171 theConverters().isReachable(*ex_it, name))
172 to.push_back(&(*fo_it));
176 // Remove repeated formats.
177 sort(to.begin(), to.end());
178 to.erase(unique(to.begin(), to.end()), to.end());
184 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
187 } // namespace frontend
190 #include "GuiSendto_moc.cpp"