]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSendto.cpp
There is no need now to cache format information in the SendTo
[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 "BufferParams.h"
19 #include "Format.h"
20 #include "FuncRequest.h"
21
22 #include "support/filetools.h"
23 #include "support/gettext.h"
24 #include "support/qstring_helpers.h"
25
26 #include <algorithm>
27
28 #include <QLineEdit>
29 #include <QListWidget>
30 #include <QPushButton>
31
32 using namespace std;
33 using namespace lyx::support;
34
35 namespace lyx {
36 namespace frontend {
37
38
39 GuiSendTo::GuiSendTo(GuiView & lv)
40         : GuiDialog(lv, "sendto", qt_("Export or Send Document")), format_(0)
41 {
42         setupUi(this);
43
44         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
45         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
46         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
47
48         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
49                 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
50         connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
51                 this, SLOT(slotFormatSelected(QListWidgetItem *)));
52         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
53                 this, SLOT(changed_adaptor()));
54         connect(formatLW, SIGNAL(itemSelectionChanged()),
55                 this, SLOT(changed_adaptor()));
56         connect(commandCO, SIGNAL(editTextChanged(QString)),
57                 this, SLOT(changed_adaptor()));
58
59         bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
60         bc().setOK(okPB);
61         bc().setApply(applyPB);
62         bc().setCancel(closePB);
63 }
64
65
66 void GuiSendTo::changed_adaptor()
67 {
68         changed();
69 }
70
71
72 void GuiSendTo::updateContents()
73 {
74         vector<Format const *> const & all_formats = 
75             buffer().params().exportableFormats(false);
76         // Save the current selection if any
77         Format const * current_format = nullptr;
78         int const line = formatLW->currentRow();
79         if (line >= 0 && static_cast<unsigned int>(line) < all_formats.size()
80             && formatLW->selectedItems().size() > 0)
81                 current_format = all_formats[line];
82         // Reset the list widget
83         formatLW->clear();
84         for (Format const * f : all_formats) {
85                 formatLW->addItem(toqstr(translateIfPossible(f->prettyname())));
86                 // Restore the selection
87                 if (current_format && f->prettyname() == current_format->prettyname())
88                         formatLW->setCurrentRow(formatLW->count() - 1);
89         }
90 }
91
92
93 void GuiSendTo::applyView()
94 {
95         int const line = formatLW->currentRow();
96         QString const command = commandCO->currentText().trimmed();
97
98         if (commandCO->findText(command) == -1)
99                 commandCO->insertItem(0, command);
100
101         if (line < 0 || line > formatLW->count())
102                 return;
103
104         vector<Format const *> const & all_formats = 
105             buffer().params().exportableFormats(false);
106         format_ = all_formats[line];
107         command_ = command;
108 }
109
110
111 bool GuiSendTo::isValid()
112 {
113         int const line = formatLW->currentRow();
114
115         if (line < 0 || line > int(formatLW->count()))
116                 return false;
117
118         return (formatLW->selectedItems().size() > 0
119                 && formatLW->count() != 0);
120 }
121
122
123 bool GuiSendTo::initialiseParams(string const &)
124 {
125         format_ = 0;
126         paramsToDialog(format_, command_);
127         return true;
128 }
129
130
131 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
132 {
133         if (!command.isEmpty())
134                 commandCO->addItem(command);
135
136         bc().setValid(isValid());
137 }
138
139
140 void GuiSendTo::dispatchParams()
141 {
142         if (!format_ || format_->name().empty())
143                 return;
144
145         string data = format_->name();
146         if (!command_.isEmpty())
147                 data += " " + fromqstr(command_);
148
149         FuncCode const lfun = command_.isEmpty() ?
150                 LFUN_BUFFER_EXPORT : getLfun();
151
152         dispatch(FuncRequest(lfun, data));
153 }
154
155 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
156
157
158 } // namespace frontend
159 } // namespace lyx
160
161 #include "moc_GuiSendto.cpp"