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