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