]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSendto.C
Juergen's QSendto.
[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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "Qt2BC.h"
18 #include "ControlSendto.h"
19 #include "QSendtoDialog.h"
20 #include "QSendto.h"
21
22 #include <qcombobox.h>
23 #include <qlabel.h>
24 #include <qlistbox.h>
25 #include <qpushbutton.h>
26
27 #include "debug.h"
28 #include "gettext.h"
29 #include "converter.h"
30
31 using std::vector;
32
33 typedef Qt2CB<ControlSendto, Qt2DB<QSendtoDialog> > base_class;
34
35 QSendto::QSendto()
36         : base_class(_("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         bc().setOK(dialog_->okPB);
47         bc().setApply(dialog_->applyPB);
48         bc().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(it->c_str());
74         }
75
76         dialog_->commandCO->insertItem(controller().getCommand().c_str());
77 }
78
79 void QSendto::apply()
80 {
81         int const line(dialog_->formatLB->currentItem());
82
83         if (line < 0 || line > dialog_->formatLB->count())
84                 return;
85
86         string const cmd(dialog_->commandCO->currentText().latin1());
87
88         controller().setFormat(all_formats_[line]);
89         controller().setCommand(cmd);
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                 !string(dialog_->commandCO->currentText()).empty();
101 }