]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSendto.cpp
Substack support for XHTML.
[lyx.git] / src / frontends / qt4 / GuiSendto.cpp
1 /**
2  * \file GuiSendto.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiSendto.h"
15 #include "qt_helpers.h"
16
17 #include "Buffer.h"
18 #include "Format.h"
19 #include "FuncRequest.h"
20
21 #include "support/qstring_helpers.h"
22 #include "support/filetools.h"
23
24 #include <QLineEdit>
25 #include <QListWidget>
26 #include <QPushButton>
27
28 using namespace std;
29 using namespace lyx::support;
30
31 namespace lyx {
32 namespace frontend {
33
34
35 GuiSendTo::GuiSendTo(GuiView & lv)
36         : GuiDialog(lv, "sendto", qt_("Export or Send Document"))
37 {
38         setupUi(this);
39
40         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
42         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
43
44         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
45                 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
46         connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
47                 this, SLOT(slotFormatSelected(QListWidgetItem *)));
48         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
49                 this, SLOT(changed_adaptor()));
50         connect(formatLW, SIGNAL(itemSelectionChanged()),
51                 this, SLOT(changed_adaptor()));
52         connect(commandCO, SIGNAL(textChanged(QString)),
53                 this, SLOT(changed_adaptor()));
54
55         bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
56         bc().setOK(okPB);
57         bc().setApply(applyPB);
58         bc().setCancel(closePB);
59 }
60
61
62 void GuiSendTo::changed_adaptor()
63 {
64         changed();
65 }
66
67
68 void GuiSendTo::updateContents()
69 {
70         all_formats_ = buffer().exportableFormats(false);
71
72         // Save the current selection if any
73         Format const * current_format = 0;
74         int const line = formatLW->currentRow();
75         if (line >= 0 && line <= formatLW->count()
76             && formatLW->selectedItems().size() > 0)
77                 current_format = all_formats_[line];
78
79         // Check whether the current contents of the browser will be
80         // changed by loading the contents of formats
81         vector<string> keys;
82         keys.resize(all_formats_.size());
83
84         vector<string>::iterator result = keys.begin();
85         vector<Format const *>::const_iterator it  = all_formats_.begin();
86         vector<Format const *>::const_iterator end = all_formats_.end();
87
88         int current_line = -1;
89         for (int ln = 0; it != end; ++it, ++result, ++ln) {
90                 *result = (*it)->prettyname();
91                 if (current_format 
92                     && (*it)->prettyname() == current_format->prettyname())
93                         current_line = ln;
94         }
95
96         // Reload the browser
97         formatLW->clear();
98
99         for (vector<string>::const_iterator it = keys.begin();
100              it != keys.end(); ++it) {
101                 formatLW->addItem(qt_(*it));
102         }
103
104         // Restore the selection
105         if (current_line > -1)
106                 formatLW->setCurrentItem(formatLW->item(current_line));
107 }
108
109
110 void GuiSendTo::applyView()
111 {
112         int const line = formatLW->currentRow();
113         QString const command = commandCO->currentText().trimmed();
114
115         if (commandCO->findText(command) == -1)
116                 commandCO->insertItem(0, command);
117
118         if (line < 0 || line > formatLW->count())
119                 return;
120
121         format_ = all_formats_[line];
122         command_ = command;
123 }
124
125
126 bool GuiSendTo::isValid()
127 {
128         int const line = formatLW->currentRow();
129
130         if (line < 0 || line > int(formatLW->count()))
131                 return false;
132
133         return (formatLW->selectedItems().size() > 0
134                 && formatLW->count() != 0);
135 }
136
137
138 bool GuiSendTo::initialiseParams(string const &)
139 {
140         format_ = 0;
141         paramsToDialog(format_, command_);
142         return true;
143 }
144
145
146 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
147 {
148         if (!command.isEmpty())
149                 commandCO->addItem(command);
150
151         bc().setValid(isValid());
152 }
153
154
155 void GuiSendTo::dispatchParams()
156 {
157         if (!format_ || format_->name().empty())
158                 return;
159
160         string data = format_->name();
161         if (!command_.isEmpty())
162                 data += " " + fromqstr(command_);
163
164         FuncCode const lfun = command_.isEmpty() ?
165                 LFUN_BUFFER_EXPORT : getLfun();
166
167         dispatch(FuncRequest(lfun, data));
168 }
169
170 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
171
172
173 } // namespace frontend
174 } // namespace lyx
175
176 #include "moc_GuiSendto.cpp"