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"
26 #include <QListWidget>
27 #include <QPushButton>
30 using namespace lyx::support;
36 GuiSendTo::GuiSendTo(GuiView & lv)
37 : GuiDialog(lv, "sendto", qt_("Export or Send Document"))
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(formatLW, SIGNAL(itemSelectionChanged()),
52 this, SLOT(changed_adaptor()));
53 connect(commandCO, SIGNAL(textChanged(QString)),
54 this, SLOT(changed_adaptor()));
56 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
58 bc().setApply(applyPB);
59 bc().setCancel(closePB);
63 void GuiSendTo::changed_adaptor()
69 void GuiSendTo::updateContents()
71 all_formats_ = buffer().params().exportableFormats(false);
73 // Save the current selection if any
74 Format const * current_format = 0;
75 int const line = formatLW->currentRow();
76 if (line >= 0 && line <= formatLW->count()
77 && formatLW->selectedItems().size() > 0)
78 current_format = all_formats_[line];
80 // Check whether the current contents of the browser will be
81 // changed by loading the contents of formats
83 keys.resize(all_formats_.size());
85 vector<string>::iterator result = keys.begin();
86 vector<Format const *>::const_iterator it = all_formats_.begin();
87 vector<Format const *>::const_iterator end = all_formats_.end();
89 int current_line = -1;
90 for (int ln = 0; it != end; ++it, ++result, ++ln) {
91 *result = (*it)->prettyname();
93 && (*it)->prettyname() == current_format->prettyname())
100 for (vector<string>::const_iterator it = keys.begin();
101 it != keys.end(); ++it) {
102 formatLW->addItem(qt_(*it));
105 // Restore the selection
106 if (current_line > -1)
107 formatLW->setCurrentItem(formatLW->item(current_line));
111 void GuiSendTo::applyView()
113 int const line = formatLW->currentRow();
114 QString const command = commandCO->currentText().trimmed();
116 if (commandCO->findText(command) == -1)
117 commandCO->insertItem(0, command);
119 if (line < 0 || line > formatLW->count())
122 format_ = all_formats_[line];
127 bool GuiSendTo::isValid()
129 int const line = formatLW->currentRow();
131 if (line < 0 || line > int(formatLW->count()))
134 return (formatLW->selectedItems().size() > 0
135 && formatLW->count() != 0);
139 bool GuiSendTo::initialiseParams(string const &)
142 paramsToDialog(format_, command_);
147 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
149 if (!command.isEmpty())
150 commandCO->addItem(command);
152 bc().setValid(isValid());
156 void GuiSendTo::dispatchParams()
158 if (!format_ || format_->name().empty())
161 string data = format_->name();
162 if (!command_.isEmpty())
163 data += " " + fromqstr(command_);
165 FuncCode const lfun = command_.isEmpty() ?
166 LFUN_BUFFER_EXPORT : getLfun();
168 dispatch(FuncRequest(lfun, data));
171 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
174 } // namespace frontend
177 #include "moc_GuiSendto.cpp"