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")
43 setViewTitle(_("Send Document to Command"));
45 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
46 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
47 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
49 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
50 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
51 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
52 this, SLOT(slotFormatSelected(QListWidgetItem *)));
53 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
54 this, SLOT(changed_adaptor()));
55 connect(commandCO, SIGNAL(textChanged(QString)),
56 this, SLOT(changed_adaptor()));
58 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
60 bc().setApply(applyPB);
61 bc().setCancel(closePB);
65 void GuiSendTo::changed_adaptor()
71 void GuiSendTo::closeEvent(QCloseEvent * e)
78 void GuiSendTo::updateContents()
80 all_formats_ = allFormats();
82 // Check whether the current contents of the browser will be
83 // changed by loading the contents of formats
85 keys.resize(all_formats_.size());
87 vector<string>::iterator result = keys.begin();
88 vector<Format const *>::const_iterator it = all_formats_.begin();
89 vector<Format const *>::const_iterator end = all_formats_.end();
90 for (; it != end; ++it, ++result)
91 *result = (*it)->prettyname();
96 for (vector<string>::const_iterator it = keys.begin();
97 it != keys.end(); ++it) {
98 formatLW->addItem(toqstr(*it));
101 commandCO->addItem(toqstr(command_));
105 void GuiSendTo::applyView()
107 int const line = formatLW->currentRow();
109 if (line < 0 || line > int(formatLW->count()))
112 format_ = all_formats_[line];
113 command_ = trim(fromqstr(commandCO->currentText()));
117 bool GuiSendTo::isValid()
119 int const line = formatLW->currentRow();
121 if (line < 0 || line > int(formatLW->count()))
124 return formatLW->count() != 0 &&
125 !commandCO->currentText().isEmpty();
129 bool GuiSendTo::initialiseParams(std::string const &)
132 command_ = lyxrc.custom_export_command;
137 void GuiSendTo::dispatchParams()
139 if (command_.empty() || !format_ || format_->name().empty())
142 string const data = format_->name() + " " + command_;
143 dispatch(FuncRequest(getLfun(), data));
146 // FIXME: Move to Converters?
147 vector<Format const *> GuiSendTo::allFormats() const
149 // What formats can we output natively?
150 vector<string> exports;
151 exports.push_back("lyx");
152 exports.push_back("text");
154 if (buffer().isLatex())
155 exports.push_back("latex");
156 else if (buffer().isDocBook())
157 exports.push_back("docbook");
158 else if (buffer().isLiterate())
159 exports.push_back("literate");
161 // Loop over these native formats and ascertain what formats we
163 vector<Format const *> to;
165 vector<string>::const_iterator ex_it = exports.begin();
166 vector<string>::const_iterator ex_end = exports.end();
167 for (; ex_it != ex_end; ++ex_it) {
168 // Start off with the native export format.
169 // "formats" is LyX's list of recognised formats
170 to.push_back(formats.getFormat(*ex_it));
172 Formats::const_iterator fo_it = formats.begin();
173 Formats::const_iterator fo_end = formats.end();
174 for (; fo_it != fo_end; ++fo_it) {
175 // we need to hide the default graphic export formats
176 // from the external menu, because we need them only
177 // for the internal lyx-view and external latex run
178 string const name = fo_it->name();
179 if (name != "eps" && name != "xpm" && name != "png" &&
180 theConverters().isReachable(*ex_it, name))
181 to.push_back(&(*fo_it));
185 // Remove repeated formats.
186 std::sort(to.begin(), to.end());
187 to.erase(std::unique(to.begin(), to.end()), to.end());
193 Dialog * createGuiSendTo(LyXView & lv) { return new GuiSendTo(lv); }
196 } // namespace frontend
199 #include "GuiSendto_moc.cpp"