]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSendto.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / qt2 / QSendto.C
1 /**
2  * \file QSendto.C
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 "QSendto.h"
14 #include "QSendtoDialog.h"
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17
18 #include "format.h"
19
20 #include "controllers/ControlSendto.h"
21
22 #include <qcombobox.h>
23 #include <qlistbox.h>
24 #include <qpushbutton.h>
25
26 using std::vector;
27 using std::string;
28
29 namespace lyx {
30 namespace frontend {
31
32 typedef QController<ControlSendto, QView<QSendtoDialog> > base_class;
33
34
35 QSendto::QSendto(Dialog & parent)
36         : base_class(parent, _("LyX: Send Document to Command"))
37 {
38 }
39
40
41 void QSendto::build_dialog()
42 {
43         dialog_.reset(new QSendtoDialog(this));
44
45         // Manage the ok, apply, restore and cancel/close buttons
46         bcview().setOK(dialog_->okPB);
47         bcview().setApply(dialog_->applyPB);
48         bcview().setCancel(dialog_->closePB);
49 }
50
51
52 void QSendto::update_contents()
53 {
54         all_formats_ = controller().allFormats();
55
56         // Check whether the current contents of the browser will be
57         // changed by loading the contents of formats
58         vector<string> keys;
59         keys.resize(all_formats_.size());
60
61         vector<string>::iterator result = keys.begin();
62         vector<Format const *>::const_iterator it  = all_formats_.begin();
63         vector<Format const *>::const_iterator end = all_formats_.end();
64         for (; it != end; ++it, ++result) {
65                 *result = (*it)->prettyname();
66         }
67
68         // Reload the browser
69         dialog_->formatLB->clear();
70
71         for (vector<string>::const_iterator it = keys.begin();
72              it < keys.end(); ++it) {
73                 dialog_->formatLB->insertItem(toqstr(*it));
74         }
75
76         dialog_->commandCO->insertItem(toqstr(controller().getCommand()));
77 }
78
79
80 void QSendto::apply()
81 {
82         int const line(dialog_->formatLB->currentItem());
83
84         if (line < 0 || line > int(dialog_->formatLB->count()))
85                 return;
86
87         string const cmd(fromqstr(dialog_->commandCO->currentText()));
88
89         controller().setFormat(all_formats_[line]);
90         controller().setCommand(cmd);
91 }
92
93
94 bool QSendto::isValid()
95 {
96         int const line(dialog_->formatLB->currentItem());
97
98         if (line < 0 || line > int(dialog_->formatLB->count()))
99                 return false;
100
101         else return dialog_->formatLB->count() != 0 &&
102                 !dialog_->commandCO->currentText().isEmpty();
103 }
104
105 } // namespace frontend
106 } // namespace lyx