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"
|
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)
|
2011-02-10 14:06:53 +00:00
|
|
|
: GuiDialog(lv, "sendto", qt_("Export or Send Document"))
|
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
|
|
|
{
|
2011-05-13 19:39:56 +00:00
|
|
|
all_formats_ = buffer().params().exportableFormats(false);
|
2011-08-08 14:20:38 +00:00
|
|
|
|
2008-09-04 09:36:44 +00:00
|
|
|
// Save the current selection if any
|
|
|
|
Format const * current_format = 0;
|
|
|
|
int const line = formatLW->currentRow();
|
|
|
|
if (line >= 0 && line <= formatLW->count()
|
|
|
|
&& formatLW->selectedItems().size() > 0)
|
|
|
|
current_format = all_formats_[line];
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
// Check whether the current contents of the browser will be
|
|
|
|
// changed by loading the contents of formats
|
|
|
|
vector<string> keys;
|
|
|
|
keys.resize(all_formats_.size());
|
|
|
|
|
|
|
|
vector<string>::iterator result = keys.begin();
|
|
|
|
vector<Format const *>::const_iterator it = all_formats_.begin();
|
|
|
|
vector<Format const *>::const_iterator end = all_formats_.end();
|
2008-09-04 09:36:44 +00:00
|
|
|
|
|
|
|
int current_line = -1;
|
|
|
|
for (int ln = 0; it != end; ++it, ++result, ++ln) {
|
2006-03-05 17:24:44 +00:00
|
|
|
*result = (*it)->prettyname();
|
2008-09-04 09:36:44 +00:00
|
|
|
if (current_format
|
|
|
|
&& (*it)->prettyname() == current_format->prettyname())
|
|
|
|
current_line = ln;
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// Reload the browser
|
2007-09-05 20:33:29 +00:00
|
|
|
formatLW->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
for (vector<string>::const_iterator it = keys.begin();
|
2007-09-05 20:33:29 +00:00
|
|
|
it != keys.end(); ++it) {
|
2008-05-19 10:12:27 +00:00
|
|
|
formatLW->addItem(qt_(*it));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 09:36:44 +00:00
|
|
|
// Restore the selection
|
|
|
|
if (current_line > -1)
|
|
|
|
formatLW->setCurrentItem(formatLW->item(current_line));
|
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;
|
|
|
|
|
2007-10-06 20:09:40 +00:00
|
|
|
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"
|