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"
26 #include "support/filetools.h"
27 #include "support/lstrings.h"
29 #include <QPushButton>
30 #include <QListWidget>
33 using lyx::support::changeExtension;
34 using lyx::support::trim;
42 QBibtexDialog::QBibtexDialog(QBibtex * form)
46 QDialog::setModal(true);
48 connect(okPB, SIGNAL(clicked()),
49 form, SLOT(slotOK()));
50 connect(closePB, SIGNAL(clicked()),
51 form, SLOT(slotClose()));
52 connect(stylePB, SIGNAL( clicked() ),
53 this, SLOT( browsePressed() ) );
54 connect(deletePB, SIGNAL( clicked() ),
55 this, SLOT( deletePressed() ) );
56 connect(styleCB, SIGNAL( textChanged(const QString&) ),
57 this, SLOT( change_adaptor() ) );
58 connect(databaseLW, SIGNAL( selectionChanged() ),
59 this, SLOT( databaseChanged() ) );
60 connect(bibtocCB, SIGNAL( toggled(bool) ),
61 this, SLOT( change_adaptor() ) );
62 connect(btPrintCO, SIGNAL( activated(int) ),
63 this, SLOT( change_adaptor() ) );
64 connect(addBibPB, SIGNAL( clicked() ),
65 this, SLOT( addPressed() ) );
67 add_ = new UiDialog<Ui::QBibtexAddUi>(this, true);
69 Qt2BC * bcview = new Qt2BC(add_bc_);
71 add_bc_.bp(new OkCancelPolicy);
73 bcview->setOK(add_->addPB);
74 bcview->setCancel(add_->closePB);
76 add_->bibED->setValidator(new PathValidator(false, add_->bibED));
77 addCheckedLineEdit(add_bc_.view(), add_->bibED, 0);
79 connect(add_->bibED, SIGNAL(textChanged(const QString&)),
80 this, SLOT(bibEDChanged()));
81 connect(add_->addPB, SIGNAL(clicked()),
82 this, SLOT(addDatabase()));
83 connect(add_->addPB, SIGNAL(clicked()),
84 add_, SLOT(accept()) );
85 connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
86 this, SLOT(addDatabase()));
87 connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
88 add_, SLOT(accept()));
89 connect(add_->bibLW, SIGNAL(itemChanged(QListWidgetItem *)),
90 this, SLOT(availableChanged()));
91 connect(add_->browsePB, SIGNAL(clicked()),
92 this, SLOT(browseBibPressed()));
93 connect(add_->closePB, SIGNAL( clicked() ),
94 add_, SLOT( reject() ) );
99 QBibtexDialog::~QBibtexDialog()
103 void QBibtexDialog::bibEDChanged()
105 // Indicate to the button controller that the contents have
106 // changed. The actual test of validity is carried out by
107 // the checkedLineEdit.
112 void QBibtexDialog::change_adaptor()
118 void QBibtexDialog::browsePressed()
120 string const file = form_->controller().browseBst("");
123 string const filen = changeExtension(file, "");
124 bool present = false;
125 unsigned int pres = 0;
127 for (int i = 0; i != styleCB->count(); ++i) {
128 if (fromqstr(styleCB->text(i)) == filen) {
135 styleCB->insertItem(toqstr(filen),0);
137 styleCB->setCurrentItem(pres);
143 void QBibtexDialog::browseBibPressed()
145 string const file = trim(form_->controller().browseBib(""));
148 QString const f = toqstr(changeExtension(file, ""));
149 bool present = false;
151 for (int i = 0; i < add_->bibLW->count(); ++i) {
152 if (add_->bibLW->item(i)->text() == f)
157 add_->bibLW->addItem(toqstr(f));
161 add_->bibED->setText(toqstr(f));
166 void QBibtexDialog::addPressed()
169 add_bc_.valid(false);
173 void QBibtexDialog::addDatabase()
175 int const sel = add_->bibLW->currentRow();
176 string const file = trim(fromqstr(add_->bibED->text()));
178 if (sel < 0 && file.empty())
181 // Add the selected browser_bib keys to browser_database
182 // multiple selections are possible
183 for (int i = 0; i != add_->bibLW->count(); ++i) {
184 QListWidgetItem * const item = add_->bibLW->item(i);
185 if (add_->bibLW->isItemSelected(item)) {
186 add_->bibLW->setItemSelected(item, false);
187 QList<QListWidgetItem *> matches =
188 databaseLW->findItems(item->text(), Qt::MatchExactly);
190 databaseLW->addItem(item->text());
195 add_->bibED->clear();
196 QString const f = toqstr(changeExtension(file, ""));
197 QList<QListWidgetItem *> matches =
198 databaseLW->findItems(f, Qt::MatchExactly);
200 databaseLW->addItem(f);
207 void QBibtexDialog::deletePressed()
209 databaseLW->takeItem(databaseLW->currentRow());
214 void QBibtexDialog::databaseChanged()
216 deletePB->setEnabled(!form_->readOnly() && databaseLW->currentRow() != -1);
220 void QBibtexDialog::availableChanged()
226 void QBibtexDialog::closeEvent(QCloseEvent *e)
233 } // namespace frontend
236 #include "QBibtexDialog_moc.cpp"