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"
15 #include "qt_helpers.h"
18 #include "BufferParams.h"
20 #include "FuncRequest.h"
22 #include "support/qstring_helpers.h"
23 #include "support/filetools.h"
28 #include <QListWidget>
29 #include <QPushButton>
32 using namespace lyx::support;
38 GuiSendTo::GuiSendTo(GuiView & lv)
39 : GuiDialog(lv, "sendto", qt_("Export or Send Document"))
43 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
44 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
45 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
47 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
48 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
49 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
50 this, SLOT(slotFormatSelected(QListWidgetItem *)));
51 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
52 this, SLOT(changed_adaptor()));
53 connect(formatLW, SIGNAL(itemSelectionChanged()),
54 this, SLOT(changed_adaptor()));
55 connect(commandCO, SIGNAL(editTextChanged(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 bool formatSorter(Format const * lhs, Format const * rhs) {
72 return lhs->prettyname() < rhs->prettyname();
76 void GuiSendTo::updateContents()
78 all_formats_ = buffer().params().exportableFormats(false);
80 sort(all_formats_.begin(), all_formats_.end(), formatSorter);
82 // Save the current selection if any
83 Format const * current_format = 0;
84 int const line = formatLW->currentRow();
85 if (line >= 0 && line <= formatLW->count()
86 && formatLW->selectedItems().size() > 0)
87 current_format = all_formats_[line];
89 // Check whether the current contents of the browser will be
90 // changed by loading the contents of formats
92 keys.resize(all_formats_.size());
94 vector<string>::iterator result = keys.begin();
95 vector<Format const *>::const_iterator it = all_formats_.begin();
96 vector<Format const *>::const_iterator end = all_formats_.end();
98 int current_line = -1;
99 for (int ln = 0; it != end; ++it, ++result, ++ln) {
100 *result = (*it)->prettyname();
102 && (*it)->prettyname() == current_format->prettyname())
106 // Reload the browser
109 for (vector<string>::const_iterator it = keys.begin();
110 it != keys.end(); ++it) {
111 formatLW->addItem(qt_(*it));
114 // Restore the selection
115 if (current_line > -1)
116 formatLW->setCurrentItem(formatLW->item(current_line));
120 void GuiSendTo::applyView()
122 int const line = formatLW->currentRow();
123 QString const command = commandCO->currentText().trimmed();
125 if (commandCO->findText(command) == -1)
126 commandCO->insertItem(0, command);
128 if (line < 0 || line > formatLW->count())
131 format_ = all_formats_[line];
136 bool GuiSendTo::isValid()
138 int const line = formatLW->currentRow();
140 if (line < 0 || line > int(formatLW->count()))
143 return (formatLW->selectedItems().size() > 0
144 && formatLW->count() != 0);
148 bool GuiSendTo::initialiseParams(string const &)
151 paramsToDialog(format_, command_);
156 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
158 if (!command.isEmpty())
159 commandCO->addItem(command);
161 bc().setValid(isValid());
165 void GuiSendTo::dispatchParams()
167 if (!format_ || format_->name().empty())
170 string data = format_->name();
171 if (!command_.isEmpty())
172 data += " " + fromqstr(command_);
174 FuncCode const lfun = command_.isEmpty() ?
175 LFUN_BUFFER_EXPORT : getLfun();
177 dispatch(FuncRequest(lfun, data));
180 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
183 } // namespace frontend
186 #include "moc_GuiSendto.cpp"