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/filetools.h"
23 #include "support/gettext.h"
24 #include "support/qstring_helpers.h"
29 #include <QListWidget>
30 #include <QPushButton>
33 using namespace lyx::support;
39 GuiSendTo::GuiSendTo(GuiView & lv)
40 : GuiDialog(lv, "sendto", qt_("Export or Send Document"))
44 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
45 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
46 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
48 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
49 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
50 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
51 this, SLOT(slotFormatSelected(QListWidgetItem *)));
52 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
53 this, SLOT(changed_adaptor()));
54 connect(formatLW, SIGNAL(itemSelectionChanged()),
55 this, SLOT(changed_adaptor()));
56 connect(commandCO, SIGNAL(editTextChanged(QString)),
57 this, SLOT(changed_adaptor()));
59 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
61 bc().setApply(applyPB);
62 bc().setCancel(closePB);
66 void GuiSendTo::changed_adaptor()
72 void GuiSendTo::updateContents()
74 all_formats_ = buffer().params().exportableFormats(false);
76 // Save the current selection if any
77 Format const * current_format = 0;
78 int const line = formatLW->currentRow();
79 if (line >= 0 && line <= formatLW->count()
80 && formatLW->selectedItems().size() > 0)
81 current_format = all_formats_[line];
83 // Check whether the current contents of the browser will be
84 // changed by loading the contents of formats
86 keys.resize(all_formats_.size());
88 vector<string>::iterator result = keys.begin();
89 vector<Format const *>::const_iterator it = all_formats_.begin();
90 vector<Format const *>::const_iterator end = all_formats_.end();
92 int current_line = -1;
93 for (int ln = 0; it != end; ++it, ++result, ++ln) {
94 *result = (*it)->prettyname();
96 && (*it)->prettyname() == current_format->prettyname())
100 // Reload the browser
103 for (vector<string>::const_iterator it = keys.begin();
104 it != keys.end(); ++it) {
105 formatLW->addItem(qt_(*it));
108 // Restore the selection
109 if (current_line > -1)
110 formatLW->setCurrentItem(formatLW->item(current_line));
114 void GuiSendTo::applyView()
116 int const line = formatLW->currentRow();
117 QString const command = commandCO->currentText().trimmed();
119 if (commandCO->findText(command) == -1)
120 commandCO->insertItem(0, command);
122 if (line < 0 || line > formatLW->count())
125 format_ = all_formats_[line];
130 bool GuiSendTo::isValid()
132 int const line = formatLW->currentRow();
134 if (line < 0 || line > int(formatLW->count()))
137 return (formatLW->selectedItems().size() > 0
138 && formatLW->count() != 0);
142 bool GuiSendTo::initialiseParams(string const &)
145 paramsToDialog(format_, command_);
150 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
152 if (!command.isEmpty())
153 commandCO->addItem(command);
155 bc().setValid(isValid());
159 void GuiSendTo::dispatchParams()
161 if (!format_ || format_->name().empty())
164 string data = format_->name();
165 if (!command_.isEmpty())
166 data += " " + fromqstr(command_);
168 FuncCode const lfun = command_.isEmpty() ?
169 LFUN_BUFFER_EXPORT : getLfun();
171 dispatch(FuncRequest(lfun, data));
174 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
177 } // namespace frontend
180 #include "moc_GuiSendto.cpp"