]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSendto.cpp
c466505710d0aa529fe5b85fc86aa1209fa65e9e
[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 Jürgen Spitzmüller
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiSendto.h"
14 #include "qt_helpers.h"
15
16 #include "Format.h"
17
18 #include <QListWidget>
19 #include <QPushButton>
20 #include <QCloseEvent>
21
22 using std::vector;
23 using std::string;
24
25
26 namespace lyx {
27 namespace frontend {
28
29 /////////////////////////////////////////////////////////////////////
30 //
31 // GuiSendtoDialog
32 //
33 /////////////////////////////////////////////////////////////////////
34
35 GuiSendtoDialog::GuiSendtoDialog(GuiSendto * form)
36         : form_(form)
37 {
38         setupUi(this);
39
40         connect(okPB, SIGNAL(clicked()),
41                 form, SLOT(slotOK()));
42         connect(applyPB, SIGNAL(clicked()),
43                 form, SLOT(slotApply()));
44         connect(closePB, SIGNAL(clicked()),
45                 form, SLOT(slotClose()));
46
47         connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ),
48                 this, SLOT( slotFormatHighlighted(QListWidgetItem *) ) );
49         connect( formatLW, SIGNAL( itemActivated(QListWidgetItem *) ),
50                 this, SLOT( slotFormatSelected(QListWidgetItem *) ) );
51         connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ),
52                 this, SLOT( changed_adaptor() ) );
53         connect( commandCO, SIGNAL( textChanged(const QString&) ),
54                 this, SLOT( changed_adaptor() ) );
55 }
56
57
58 void GuiSendtoDialog::changed_adaptor()
59 {
60         form_->changed();
61 }
62
63
64 void GuiSendtoDialog::closeEvent(QCloseEvent * e)
65 {
66         form_->slotWMHide();
67         e->accept();
68 }
69
70
71 /////////////////////////////////////////////////////////////////////
72 //
73 // GuiSendto
74 //
75 /////////////////////////////////////////////////////////////////////
76
77
78 GuiSendto::GuiSendto(GuiDialog & parent)
79         : GuiView<GuiSendtoDialog>(parent, _("Send Document to Command"))
80 {
81 }
82
83
84 void GuiSendto::build_dialog()
85 {
86         dialog_.reset(new GuiSendtoDialog(this));
87
88         // Manage the ok, apply, restore and cancel/close buttons
89         bc().setOK(dialog_->okPB);
90         bc().setApply(dialog_->applyPB);
91         bc().setCancel(dialog_->closePB);
92 }
93
94
95 void GuiSendto::update_contents()
96 {
97         all_formats_ = controller().allFormats();
98
99         // Check whether the current contents of the browser will be
100         // changed by loading the contents of formats
101         vector<string> keys;
102         keys.resize(all_formats_.size());
103
104         vector<string>::iterator result = keys.begin();
105         vector<Format const *>::const_iterator it  = all_formats_.begin();
106         vector<Format const *>::const_iterator end = all_formats_.end();
107         for (; it != end; ++it, ++result) {
108                 *result = (*it)->prettyname();
109         }
110
111         // Reload the browser
112         dialog_->formatLW->clear();
113
114         for (vector<string>::const_iterator it = keys.begin();
115              it < keys.end(); ++it) {
116                 dialog_->formatLW->addItem(toqstr(*it));
117         }
118
119         dialog_->commandCO->addItem(toqstr(controller().getCommand()));
120 }
121
122
123 void GuiSendto::applyView()
124 {
125         int const line(dialog_->formatLW->currentRow());
126
127         if (line < 0 || line > int(dialog_->formatLW->count()))
128                 return;
129
130         string const cmd(fromqstr(dialog_->commandCO->currentText()));
131
132         controller().setFormat(all_formats_[line]);
133         controller().setCommand(cmd);
134 }
135
136
137 bool GuiSendto::isValid()
138 {
139         int const line(dialog_->formatLW->currentRow());
140
141         if (line < 0 || line > int(dialog_->formatLW->count()))
142                 return false;
143
144         else return dialog_->formatLW->count() != 0 &&
145                 !dialog_->commandCO->currentText().isEmpty();
146 }
147
148 } // namespace frontend
149 } // namespace lyx
150
151 #include "GuiSendto_moc.cpp"