2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiSendto.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2007-10-06 20:09:40 +00:00
|
|
|
* \author Angus Leeming
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiSendto.h"
|
2008-05-19 10:12:27 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
#include "Buffer.h"
|
2011-05-13 19:39:56 +00:00
|
|
|
#include "BufferParams.h"
|
2016-10-19 22:11:58 +00:00
|
|
|
#include "Converter.h"
|
2007-10-06 20:09:40 +00:00
|
|
|
#include "Format.h"
|
|
|
|
#include "FuncRequest.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
#include "support/filetools.h"
|
2011-09-02 18:40:06 +00:00
|
|
|
#include "support/gettext.h"
|
|
|
|
#include "support/qstring_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2011-08-08 14:20:38 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2008-09-04 09:36:44 +00:00
|
|
|
#include <QLineEdit>
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QListWidget>
|
|
|
|
#include <QPushButton>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-04-25 10:57:54 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiSendTo::GuiSendTo(GuiView & lv)
|
2016-06-09 14:44:56 +00:00
|
|
|
: GuiDialog(lv, "sendto", qt_("Export or Send Document")), format_(0)
|
2007-04-25 10:57:54 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
|
|
|
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
|
|
|
|
|
|
|
connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
|
|
|
|
this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
|
|
|
|
connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
|
|
|
|
this, SLOT(slotFormatSelected(QListWidgetItem *)));
|
|
|
|
connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
|
|
|
|
this, SLOT(changed_adaptor()));
|
2008-09-04 09:36:44 +00:00
|
|
|
connect(formatLW, SIGNAL(itemSelectionChanged()),
|
|
|
|
this, SLOT(changed_adaptor()));
|
2011-08-08 17:21:13 +00:00
|
|
|
connect(commandCO, SIGNAL(editTextChanged(QString)),
|
2007-09-05 20:33:29 +00:00
|
|
|
this, SLOT(changed_adaptor()));
|
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
|
|
|
|
bc().setOK(okPB);
|
|
|
|
bc().setApply(applyPB);
|
|
|
|
bc().setCancel(closePB);
|
2007-04-25 10:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
void GuiSendTo::changed_adaptor()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-02 18:40:06 +00:00
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
void GuiSendTo::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2016-10-19 22:11:58 +00:00
|
|
|
FormatList const & all_formats =
|
2016-10-19 21:30:48 +00:00
|
|
|
buffer().params().exportableFormats(false);
|
2008-09-04 09:36:44 +00:00
|
|
|
// Save the current selection if any
|
2016-08-28 00:27:37 +00:00
|
|
|
Format const * current_format = nullptr;
|
2008-09-04 09:36:44 +00:00
|
|
|
int const line = formatLW->currentRow();
|
2016-10-19 21:30:48 +00:00
|
|
|
if (line >= 0 && static_cast<unsigned int>(line) < all_formats.size()
|
2008-09-04 09:36:44 +00:00
|
|
|
&& formatLW->selectedItems().size() > 0)
|
2016-10-19 21:30:48 +00:00
|
|
|
current_format = all_formats[line];
|
2016-08-28 00:27:37 +00:00
|
|
|
// Reset the list widget
|
2007-09-05 20:33:29 +00:00
|
|
|
formatLW->clear();
|
2016-10-19 21:30:48 +00:00
|
|
|
for (Format const * f : all_formats) {
|
2016-08-28 00:27:37 +00:00
|
|
|
formatLW->addItem(toqstr(translateIfPossible(f->prettyname())));
|
|
|
|
// Restore the selection
|
|
|
|
if (current_format && f->prettyname() == current_format->prettyname())
|
|
|
|
formatLW->setCurrentRow(formatLW->count() - 1);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
void GuiSendTo::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
int const line = formatLW->currentRow();
|
2008-09-04 09:36:44 +00:00
|
|
|
QString const command = commandCO->currentText().trimmed();
|
|
|
|
|
|
|
|
if (commandCO->findText(command) == -1)
|
|
|
|
commandCO->insertItem(0, command);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-04-20 16:32:40 +00:00
|
|
|
if (line < 0 || line > formatLW->count())
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
|
2016-10-19 22:11:58 +00:00
|
|
|
FormatList const & all_formats =
|
2016-10-19 21:30:48 +00:00
|
|
|
buffer().params().exportableFormats(false);
|
|
|
|
format_ = all_formats[line];
|
2008-09-04 09:36:44 +00:00
|
|
|
command_ = command;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
bool GuiSendTo::isValid()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
int const line = formatLW->currentRow();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
if (line < 0 || line > int(formatLW->count()))
|
2006-03-05 17:24:44 +00:00
|
|
|
return false;
|
|
|
|
|
2008-09-04 09:36:44 +00:00
|
|
|
return (formatLW->selectedItems().size() > 0
|
2011-02-10 14:06:53 +00:00
|
|
|
&& formatLW->count() != 0);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
bool GuiSendTo::initialiseParams(string const &)
|
2007-10-06 20:09:40 +00:00
|
|
|
{
|
|
|
|
format_ = 0;
|
2008-09-04 09:36:44 +00:00
|
|
|
paramsToDialog(format_, command_);
|
2007-10-06 20:09:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-16 11:33:07 +00:00
|
|
|
void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
|
2008-09-04 09:36:44 +00:00
|
|
|
{
|
|
|
|
if (!command.isEmpty())
|
|
|
|
commandCO->addItem(command);
|
|
|
|
|
|
|
|
bc().setValid(isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
void GuiSendTo::dispatchParams()
|
|
|
|
{
|
2011-02-10 14:06:53 +00:00
|
|
|
if (!format_ || format_->name().empty())
|
2007-10-06 20:09:40 +00:00
|
|
|
return;
|
|
|
|
|
2011-02-10 14:06:53 +00:00
|
|
|
string data = format_->name();
|
|
|
|
if (!command_.isEmpty())
|
|
|
|
data += " " + fromqstr(command_);
|
|
|
|
|
|
|
|
FuncCode const lfun = command_.isEmpty() ?
|
|
|
|
LFUN_BUFFER_EXPORT : getLfun();
|
|
|
|
|
|
|
|
dispatch(FuncRequest(lfun, data));
|
2007-10-06 20:09:40 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
|
2007-10-06 20:09:40 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-25 10:57:54 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiSendto.cpp"
|