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