]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QBibtexDialog.C
Get rid of the static_casts.
[lyx.git] / src / frontends / qt2 / QBibtexDialog.C
1 /**
2  * \file QBibtexDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13
14 #include "ControlBibtex.h"
15 #include "qt_helpers.h"
16 #include "debug.h"
17
18 #include "support/filetools.h"
19 #include "support/lyxalgo.h" // eliminate_duplicates
20
21 #include <qwidget.h>
22 #include <qpushbutton.h>
23 #include <qcombobox.h>
24 #include <qlineedit.h>
25 #include <qlistbox.h>
26 #include <qcheckbox.h>
27 #include <qfiledialog.h>
28
29 #include "ui/QBibtexAddDialogBase.h"
30 #include "QBibtexDialog.h"
31 #include "QBibtex.h"
32
33 #include <vector>
34
35
36 QBibtexDialog::QBibtexDialog(QBibtex * form)
37         : QBibtexDialogBase(0, 0, false, 0),
38         form_(form)
39 {
40         connect(okPB, SIGNAL(clicked()),
41                 form, SLOT(slotOK()));
42         connect(closePB, SIGNAL(clicked()),
43                 form, SLOT(slotClose()));
44
45         add_ = new QBibtexAddDialogBase(this, "", true);
46         connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
47         connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addDatabase()));
48         connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addDatabase()));
49         connect(add_->bibLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
50         connect(add_->bibLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
51         connect(add_->browsePB, SIGNAL(clicked()), this, SLOT(browseBibPressed()));
52 }
53
54
55 void QBibtexDialog::change_adaptor()
56 {
57         form_->changed();
58 }
59
60
61 void QBibtexDialog::browsePressed()
62 {
63         QString const file =
64                 QFileDialog::getOpenFileName(QString::null,
65                                              qt_("BibTeX style files (*.bst)"),
66                                              this,
67                                              0,
68                                              qt_("Select a BibTeX style"));
69         if (!file.isNull()) {
70                 string const filen = ChangeExtension(fromqstr(file), "");
71                 bool present = false;
72                 unsigned int pres = 0;
73
74                 for (unsigned int i = 0; i != styleCB->count(); i++) {
75                         if (fromqstr(styleCB->text(i)) == filen) {
76                                 present = true;
77                                 pres = i;
78                         }
79                 }
80
81                 if (!present)
82                         styleCB->insertItem(toqstr(filen),0);
83
84                 styleCB->setCurrentItem(pres);
85                 form_->changed();
86         }
87 }
88
89
90 void QBibtexDialog::browseBibPressed()
91 {
92         QString const file = QFileDialog::getOpenFileName(QString::null,
93                 qt_("BibTeX database files (*.bib)"), add_, 0, qt_("Select a BibTeX database to add"));
94
95         if (!file.isNull()) {
96                 string const f = ChangeExtension(fromqstr(file), "");
97                 bool present = false;
98
99                 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
100                         if (fromqstr(add_->bibLB->text(i)) == f)
101                                 present = true;
102                 }
103
104                 if (!present) {
105                         add_->bibLB->insertItem(toqstr(f));
106                         form_->changed();
107                 }
108
109                 add_->bibED->setText(toqstr(f));
110         }
111 }
112
113 void QBibtexDialog::addPressed()
114 {
115         add_->exec();
116 }
117
118
119 void QBibtexDialog::addDatabase()
120 {
121         QString const file = add_->bibED->text();
122
123         if (!file.isNull()) {
124                 string const f = ChangeExtension(fromqstr(file), "");
125                 bool present = false;
126                 for (unsigned int i = 0; i != databaseLB->count(); ++i) {
127                         if (fromqstr(databaseLB->text(i)) == f)
128                                 present = true;
129
130                 }
131                 if (!present) {
132                         databaseLB->insertItem(f.c_str());
133                         form_->changed();
134                 }
135         }
136 }
137
138
139 void QBibtexDialog::deletePressed()
140 {
141         databaseLB->removeItem(databaseLB->currentItem());
142 }
143
144
145
146 void QBibtexDialog::databaseChanged()
147 {
148         deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
149 }
150
151
152 void QBibtexDialog::availableChanged()
153 {
154         add_->bibED->setText(add_->bibLB->currentText());
155 }
156
157
158 void QBibtexDialog::closeEvent(QCloseEvent *e)
159 {
160         form_->slotWMHide();
161         e->accept();
162 }