]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSendto.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[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
16 #include "Buffer.h"
17 #include "Converter.h"
18 #include "Format.h"
19 #include "FuncRequest.h"
20 #include "LyXRC.h"
21 #include "qt_helpers.h"
22
23 #include "support/filetools.h"
24 #include "support/lstrings.h"
25
26 #include <QListWidget>
27 #include <QPushButton>
28
29 using namespace std;
30 using namespace lyx::support;
31
32 namespace lyx {
33 namespace frontend {
34
35
36 GuiSendTo::GuiSendTo(GuiView & lv)
37         : GuiDialog(lv, "sendto", qt_("Send Document to Command"))
38 {
39         setupUi(this);
40
41         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
42         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
43         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44
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(commandCO, SIGNAL(textChanged(QString)),
52                 this, SLOT(changed_adaptor()));
53
54         bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
55         bc().setOK(okPB);
56         bc().setApply(applyPB);
57         bc().setCancel(closePB);
58 }
59
60
61 void GuiSendTo::changed_adaptor()
62 {
63         changed();
64 }
65
66
67 void GuiSendTo::updateContents()
68 {
69         all_formats_ = allFormats();
70
71         // Check whether the current contents of the browser will be
72         // changed by loading the contents of formats
73         vector<string> keys;
74         keys.resize(all_formats_.size());
75
76         vector<string>::iterator result = keys.begin();
77         vector<Format const *>::const_iterator it  = all_formats_.begin();
78         vector<Format const *>::const_iterator end = all_formats_.end();
79         for (; it != end; ++it, ++result)
80                 *result = (*it)->prettyname();
81
82         // Reload the browser
83         formatLW->clear();
84
85         for (vector<string>::const_iterator it = keys.begin();
86              it != keys.end(); ++it) {
87                 formatLW->addItem(toqstr(*it));
88         }
89
90         commandCO->addItem(toqstr(command_));
91 }
92
93
94 void GuiSendTo::applyView()
95 {
96         int const line = formatLW->currentRow();
97
98         if (line < 0 || line > int(formatLW->count()))
99                 return;
100
101         format_ = all_formats_[line];
102         command_ = trim(fromqstr(commandCO->currentText()));
103 }
104
105
106 bool GuiSendTo::isValid()
107 {
108         int const line = formatLW->currentRow();
109
110         if (line < 0 || line > int(formatLW->count()))
111                 return false;
112
113         return formatLW->count() != 0 &&
114                 !commandCO->currentText().isEmpty();
115 }
116
117
118 bool GuiSendTo::initialiseParams(string const &)
119 {
120         format_ = 0;
121         command_ = lyxrc.custom_export_command;
122         return true;
123 }
124
125
126 void GuiSendTo::dispatchParams()
127 {
128         if (command_.empty() || !format_ || format_->name().empty())
129                 return;
130
131         string const data = format_->name() + " " + command_;
132         dispatch(FuncRequest(getLfun(), data));
133 }
134
135 // FIXME: Move to Converters?
136 vector<Format const *> GuiSendTo::allFormats() const
137 {
138         // What formats can we output natively?
139         vector<string> exports;
140         exports.push_back("lyx");
141         exports.push_back("text");
142
143         if (buffer().isLatex()) {
144                 exports.push_back("latex");
145                 exports.push_back("pdflatex");
146         }
147         else if (buffer().isDocBook())
148                 exports.push_back("docbook");
149         else if (buffer().isLiterate())
150                 exports.push_back("literate");
151
152         // Loop over these native formats and ascertain what formats we
153         // can convert to
154         vector<Format const *> to;
155
156         vector<string>::const_iterator ex_it  = exports.begin();
157         vector<string>::const_iterator ex_end = exports.end();
158         for (; ex_it != ex_end; ++ex_it) {
159                 // Start off with the native export format.
160                 // "formats" is LyX's list of recognised formats
161                 to.push_back(formats.getFormat(*ex_it));
162
163                 Formats::const_iterator fo_it  = formats.begin();
164                 Formats::const_iterator fo_end = formats.end();
165                 for (; fo_it != fo_end; ++fo_it) {
166                         // we need to hide the default graphic export formats
167                         // from the external menu, because we need them only
168                         // for the internal lyx-view and external latex run
169                         string const name = fo_it->name();
170                         if (name != "eps" && name != "xpm" && name != "png" &&
171                             theConverters().isReachable(*ex_it, name))
172                                 to.push_back(&(*fo_it));
173                 }
174         }
175
176         // Remove repeated formats.
177         sort(to.begin(), to.end());
178         to.erase(unique(to.begin(), to.end()), to.end());
179
180         return to;
181 }
182
183
184 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
185
186
187 } // namespace frontend
188 } // namespace lyx
189
190 #include "GuiSendto_moc.cpp"