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.
13 #include "QBibtexDialog.h"
15 #include <QCloseEvent>
17 #include "checkedwidgets.h"
19 #include "qt_helpers.h"
20 #include "validators.h"
22 #include "controllers/ControlBibtex.h"
23 #include "controllers/ButtonPolicies.h"
25 #include "support/filetools.h"
26 #include "support/lstrings.h"
28 #include <qpushbutton.h>
29 #include <qlineedit.h>
30 #include <q3listbox.h>
32 using lyx::support::ChangeExtension;
33 using lyx::support::trim;
41 QBibtexDialog::QBibtexDialog(QBibtex * form)
46 connect(okPB, SIGNAL(clicked()),
47 form, SLOT(slotOK()));
48 connect(closePB, SIGNAL(clicked()),
49 form, SLOT(slotClose()));
51 connect( stylePB, SIGNAL( clicked() ), this, SLOT( browsePressed() ) );
52 connect( deletePB, SIGNAL( clicked() ), this, SLOT( deletePressed() ) );
53 connect( styleCB, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
54 connect( databaseLB, SIGNAL( selectionChanged() ), this, SLOT( databaseChanged() ) );
55 connect( bibtocCB, SIGNAL( toggled(bool) ), this, SLOT( change_adaptor() ) );
56 connect( btPrintCO, SIGNAL( activated(int) ), this, SLOT( change_adaptor() ) );
57 connect( addBibPB, SIGNAL( clicked() ), this, SLOT( addPressed() ) );
59 add_ = new UiDialog<Ui::QBibtexAddUi>(this, true);
61 Qt2BC * bcview = new Qt2BC(add_bc_);
63 add_bc_.bp(new OkCancelPolicy);
65 bcview->setOK(add_->addPB);
66 bcview->setCancel(add_->closePB);
68 add_->bibED->setValidator(new PathValidator(false, add_->bibED));
69 addCheckedLineEdit(add_bc_.view(), add_->bibED, 0);
71 connect(add_->bibED, SIGNAL(textChanged(const QString&)),
72 this, SLOT(bibEDChanged()));
73 connect(add_->addPB, SIGNAL(clicked()),
74 this, SLOT(addDatabase()));
75 connect(add_->bibLB, SIGNAL(selected(Q3ListBoxItem *)),
76 this, SLOT(addDatabase()));
77 connect(add_->bibLB, SIGNAL(selected(Q3ListBoxItem *)),
78 add_, SLOT(accept()));
79 connect(add_->bibLB, SIGNAL(currentChanged(Q3ListBoxItem *)),
80 this, SLOT(availableChanged()));
81 connect(add_->browsePB, SIGNAL(clicked()),
82 this, SLOT(browseBibPressed()));
84 connect( add_->addPB, SIGNAL( clicked() ), this, SLOT( accept() ) );
85 connect( add_->closePB, SIGNAL( clicked() ), this, SLOT( reject() ) );
90 QBibtexDialog::~QBibtexDialog()
94 void QBibtexDialog::bibEDChanged()
96 // Indicate to the button controller that the contents have
97 // changed. The actual test of validity is carried out by
98 // the checkedLineEdit.
103 void QBibtexDialog::change_adaptor()
109 void QBibtexDialog::browsePressed()
111 string const file = form_->controller().browseBst("");
114 string const filen = ChangeExtension(file, "");
115 bool present = false;
116 unsigned int pres = 0;
118 for (int i = 0; i != styleCB->count(); ++i) {
119 if (fromqstr(styleCB->text(i)) == filen) {
126 styleCB->insertItem(toqstr(filen),0);
128 styleCB->setCurrentItem(pres);
134 void QBibtexDialog::browseBibPressed()
136 string const file = trim(form_->controller().browseBib(""));
139 string const f = ChangeExtension(file, "");
140 bool present = false;
142 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
143 if (fromqstr(add_->bibLB->text(i)) == f)
148 add_->bibLB->insertItem(toqstr(f));
152 add_->bibED->setText(toqstr(f));
157 void QBibtexDialog::addPressed()
160 add_bc_.valid(false);
164 void QBibtexDialog::addDatabase()
166 int const sel = add_->bibLB->currentItem();
167 string const file = trim(fromqstr(add_->bibED->text()));
169 if (sel < 0 && file.empty())
172 // Add the selected browser_bib keys to browser_database
173 // multiple selections are possible
174 for (unsigned int i = 0; i != add_->bibLB->count(); i++) {
175 if (add_->bibLB->isSelected(i)) {
176 // do not allow duplicates
177 if ((databaseLB->findItem(add_->bibLB->text(i))) == 0)
178 databaseLB->insertItem(add_->bibLB->text(i));
183 QString const f = toqstr(ChangeExtension(file, ""));
184 if ((databaseLB->findItem(f)) == 0)
185 databaseLB->insertItem(f);
192 void QBibtexDialog::deletePressed()
194 databaseLB->removeItem(databaseLB->currentItem());
199 void QBibtexDialog::databaseChanged()
201 deletePB->setEnabled(!form_->readOnly() && databaseLB->currentItem() != -1);
205 void QBibtexDialog::availableChanged()
211 void QBibtexDialog::closeEvent(QCloseEvent *e)
217 } // namespace frontend