2 * \file QBibtexDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #include "ControlBibtex.h"
15 #include "qt_helpers.h"
18 #include "support/filetools.h"
19 #include "support/lyxalgo.h" // eliminate_duplicates
22 #include <qpushbutton.h>
23 #include <qcombobox.h>
24 #include <qlineedit.h>
26 #include <qcheckbox.h>
27 #include <qfiledialog.h>
29 #include "ui/QBibtexAddDialogBase.h"
30 #include "QBibtexDialog.h"
36 QBibtexDialog::QBibtexDialog(QBibtex * form)
37 : QBibtexDialogBase(0, 0, false, 0),
40 connect(okPB, SIGNAL(clicked()),
41 form, SLOT(slotOK()));
42 connect(closePB, SIGNAL(clicked()),
43 form, SLOT(slotClose()));
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()));
55 void QBibtexDialog::change_adaptor()
61 void QBibtexDialog::browsePressed()
64 QFileDialog::getOpenFileName(QString::null,
65 qt_("BibTeX style files (*.bst)"),
68 qt_("Select a BibTeX style"));
70 string const filen = ChangeExtension(fromqstr(file), "");
72 unsigned int pres = 0;
74 for (unsigned int i = 0; i != styleCB->count(); i++) {
75 if (fromqstr(styleCB->text(i)) == filen) {
82 styleCB->insertItem(toqstr(filen),0);
84 styleCB->setCurrentItem(pres);
90 void QBibtexDialog::browseBibPressed()
92 QString const file = QFileDialog::getOpenFileName(QString::null,
93 qt_("BibTeX database files (*.bib)"), add_, 0, qt_("Select a BibTeX database to add"));
96 string const f = ChangeExtension(fromqstr(file), "");
99 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
100 if (fromqstr(add_->bibLB->text(i)) == f)
105 add_->bibLB->insertItem(toqstr(f));
109 add_->bibED->setText(toqstr(f));
113 void QBibtexDialog::addPressed()
119 void QBibtexDialog::addDatabase()
121 QString const file = add_->bibED->text();
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)
132 databaseLB->insertItem(f.c_str());
139 void QBibtexDialog::deletePressed()
141 databaseLB->removeItem(databaseLB->currentItem());
146 void QBibtexDialog::databaseChanged()
148 deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
152 void QBibtexDialog::availableChanged()
154 add_->bibED->setText(add_->bibLB->currentText());
158 void QBibtexDialog::closeEvent(QCloseEvent *e)