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"
19 #include "Converter.h"
21 #include "FuncRequest.h"
23 #include "support/filetools.h"
24 #include "support/gettext.h"
25 #include "support/qstring_helpers.h"
30 #include <QListWidget>
31 #include <QPushButton>
34 using namespace lyx::support;
40 GuiSendTo::GuiSendTo(GuiView & lv)
41 : GuiDialog(lv, "sendto", qt_("Export or Send Document")), format_(0)
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(formatLW, SIGNAL(itemSelectionChanged()),
56 this, SLOT(changed_adaptor()));
57 connect(commandCO, SIGNAL(editTextChanged(QString)),
58 this, SLOT(changed_adaptor()));
60 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
62 bc().setApply(applyPB);
63 bc().setCancel(closePB);
67 void GuiSendTo::changed_adaptor()
73 void GuiSendTo::updateContents()
75 FormatList const & all_formats =
76 buffer().params().exportableFormats(false);
77 // Save the current selection if any
78 Format const * current_format = nullptr;
79 int const line = formatLW->currentRow();
80 if (line >= 0 && static_cast<unsigned int>(line) < all_formats.size()
81 && formatLW->selectedItems().size() > 0)
82 current_format = all_formats[line];
83 // Reset the list widget
85 for (Format const * f : all_formats) {
86 formatLW->addItem(toqstr(translateIfPossible(f->prettyname())));
87 // Restore the selection
88 if (current_format && f->prettyname() == current_format->prettyname())
89 formatLW->setCurrentRow(formatLW->count() - 1);
94 void GuiSendTo::applyView()
96 int const line = formatLW->currentRow();
97 QString const command = commandCO->currentText().trimmed();
99 if (commandCO->findText(command) == -1)
100 commandCO->insertItem(0, command);
102 if (line < 0 || line > formatLW->count())
105 FormatList const & all_formats =
106 buffer().params().exportableFormats(false);
107 format_ = all_formats[line];
112 bool GuiSendTo::isValid()
114 int const line = formatLW->currentRow();
116 if (line < 0 || line > int(formatLW->count()))
119 return (formatLW->selectedItems().size() > 0
120 && formatLW->count() != 0);
124 bool GuiSendTo::initialiseParams(string const &)
127 paramsToDialog(format_, command_);
132 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
134 if (!command.isEmpty())
135 commandCO->addItem(command);
137 bc().setValid(isValid());
141 void GuiSendTo::dispatchParams()
143 if (!format_ || format_->name().empty())
146 string sdata = format_->name();
147 if (!command_.isEmpty())
148 sdata += " " + fromqstr(command_);
150 FuncCode const lfun = command_.isEmpty() ?
151 LFUN_BUFFER_EXPORT : getLfun();
153 dispatch(FuncRequest(lfun, sdata));
156 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
159 } // namespace frontend
162 #include "moc_GuiSendto.cpp"