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"
22 #include "support/qstring_helpers.h"
23 #include "support/filetools.h"
25 #include <QListWidget>
26 #include <QPushButton>
29 using namespace lyx::support;
35 GuiSendTo::GuiSendTo(GuiView & lv)
36 : GuiDialog(lv, "sendto", qt_("Send Document to Command"))
40 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
42 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
45 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
46 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
47 this, SLOT(slotFormatSelected(QListWidgetItem *)));
48 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
49 this, SLOT(changed_adaptor()));
50 connect(commandCO, SIGNAL(textChanged(QString)),
51 this, SLOT(changed_adaptor()));
53 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
55 bc().setApply(applyPB);
56 bc().setCancel(closePB);
60 void GuiSendTo::changed_adaptor()
66 void GuiSendTo::updateContents()
68 all_formats_ = allFormats();
70 // Check whether the current contents of the browser will be
71 // changed by loading the contents of formats
73 keys.resize(all_formats_.size());
75 vector<string>::iterator result = keys.begin();
76 vector<Format const *>::const_iterator it = all_formats_.begin();
77 vector<Format const *>::const_iterator end = all_formats_.end();
78 for (; it != end; ++it, ++result)
79 *result = (*it)->prettyname();
84 for (vector<string>::const_iterator it = keys.begin();
85 it != keys.end(); ++it) {
86 formatLW->addItem(toqstr(*it));
89 commandCO->addItem(command_);
93 void GuiSendTo::applyView()
95 int const line = formatLW->currentRow();
97 if (line < 0 || line > formatLW->count())
100 format_ = all_formats_[line];
101 command_ = commandCO->currentText().trimmed();
105 bool GuiSendTo::isValid()
107 int const line = formatLW->currentRow();
109 if (line < 0 || line > int(formatLW->count()))
112 return formatLW->count() != 0 &&
113 !commandCO->currentText().isEmpty();
117 bool GuiSendTo::initialiseParams(string const &)
120 command_ = toqstr(lyxrc.custom_export_command);
125 void GuiSendTo::dispatchParams()
127 if (command_.isEmpty() || !format_ || format_->name().empty())
130 string const data = format_->name() + " " + fromqstr(command_);
131 dispatch(FuncRequest(getLfun(), data));
134 // FIXME: Move to Converters?
135 vector<Format const *> GuiSendTo::allFormats() const
137 // What formats can we output natively?
138 vector<string> exports;
139 exports.push_back("lyx");
140 exports.push_back("text");
142 if (buffer().isLatex()) {
143 exports.push_back("latex");
144 exports.push_back("pdflatex");
146 else if (buffer().isDocBook())
147 exports.push_back("docbook");
148 else if (buffer().isLiterate())
149 exports.push_back("literate");
151 // Loop over these native formats and ascertain what formats we
153 vector<Format const *> to;
155 vector<string>::const_iterator ex_it = exports.begin();
156 vector<string>::const_iterator ex_end = exports.end();
157 for (; ex_it != ex_end; ++ex_it) {
158 // Start off with the native export format.
159 // "formats" is LyX's list of recognised formats
160 to.push_back(formats.getFormat(*ex_it));
162 Formats::const_iterator fo_it = formats.begin();
163 Formats::const_iterator fo_end = formats.end();
164 for (; fo_it != fo_end; ++fo_it) {
165 // we need to hide the default graphic export formats
166 // from the external menu, because we need them only
167 // for the internal lyx-view and external latex run
168 string const name = fo_it->name();
169 if (name != "eps" && name != "xpm" && name != "png" &&
170 theConverters().isReachable(*ex_it, name))
171 to.push_back(&(*fo_it));
175 // Remove repeated formats.
176 sort(to.begin(), to.end());
177 to.erase(unique(to.begin(), to.end()), to.end());
183 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
186 } // namespace frontend
189 #include "GuiSendto_moc.cpp"