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"
16 #include <QCloseEvent>
18 #include "checkedwidgets.h"
20 #include "qt_helpers.h"
21 #include "validators.h"
23 #include "controllers/ControlBibtex.h"
24 #include "controllers/ButtonPolicies.h"
27 #include "support/filetools.h"
28 #include "support/lstrings.h"
30 #include <QPushButton>
31 #include <QListWidget>
34 using lyx::support::changeExtension;
35 using lyx::support::trim;
43 QBibtexDialog::QBibtexDialog(QBibtex * form)
47 QDialog::setModal(true);
49 connect(okPB, SIGNAL(clicked()),
50 form, SLOT(slotOK()));
51 connect(closePB, SIGNAL(clicked()),
52 form, SLOT(slotClose()));
53 connect(stylePB, SIGNAL( clicked() ),
54 this, SLOT( browsePressed() ) );
55 connect(deletePB, SIGNAL( clicked() ),
56 this, SLOT( deletePressed() ) );
57 connect(styleCB, SIGNAL( editTextChanged (const QString&) ),
58 this, SLOT( change_adaptor() ) );
59 connect(databaseLW, SIGNAL( itemSelectionChanged() ),
60 this, SLOT( databaseChanged() ) );
61 connect(bibtocCB, SIGNAL( toggled(bool) ),
62 this, SLOT( change_adaptor() ) );
63 connect(btPrintCO, SIGNAL( activated(int) ),
64 this, SLOT( change_adaptor() ) );
65 connect(addBibPB, SIGNAL( clicked() ),
66 this, SLOT( addPressed() ) );
68 add_ = new UiDialog<Ui::QBibtexAddUi>(this, true);
70 Qt2BC * bcview = new Qt2BC(add_bc_);
72 add_bc_.bp(new OkCancelPolicy);
74 bcview->setOK(add_->addPB);
75 bcview->setCancel(add_->closePB);
77 add_->bibED->setValidator(new PathValidator(true, add_->bibED));
78 addCheckedLineEdit(add_bc_.view(), add_->bibED, 0);
80 connect(add_->bibED, SIGNAL(textChanged(const QString&)),
81 this, SLOT(bibEDChanged()));
82 connect(add_->addPB, SIGNAL(clicked()),
83 this, SLOT(addDatabase()));
84 connect(add_->addPB, SIGNAL(clicked()),
85 add_, SLOT(accept()) );
86 connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
87 this, SLOT(addDatabase()));
88 connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
89 add_, SLOT(accept()));
90 connect(add_->bibLW, SIGNAL(itemSelectionChanged()),
91 this, SLOT(availableChanged()));
92 connect(add_->browsePB, SIGNAL(clicked()),
93 this, SLOT(browseBibPressed()));
94 connect(add_->closePB, SIGNAL( clicked() ),
95 add_, SLOT( reject() ) );
100 QBibtexDialog::~QBibtexDialog()
104 void QBibtexDialog::bibEDChanged()
106 // Indicate to the button controller that the contents have
107 // changed. The actual test of validity is carried out by
108 // the checkedLineEdit.
113 void QBibtexDialog::change_adaptor()
119 void QBibtexDialog::browsePressed()
121 docstring const file = form_->controller().browseBst(docstring());
125 docstring const filen = from_utf8(changeExtension(to_utf8(file), ""));
126 bool present = false;
127 unsigned int pres = 0;
129 for (int i = 0; i != styleCB->count(); ++i) {
130 if (qstring_to_ucs4(styleCB->itemText(i)) == filen) {
137 styleCB->insertItem(0, toqstr(filen));
139 styleCB->setCurrentIndex(pres);
145 void QBibtexDialog::browseBibPressed()
147 docstring const file = trim(form_->controller().browseBib(docstring()));
151 QString const f = toqstr(changeExtension(to_utf8(file), ""));
152 bool present = false;
154 for (int i = 0; i < add_->bibLW->count(); ++i) {
155 if (add_->bibLW->item(i)->text() == f)
160 add_->bibLW->addItem(f);
164 add_->bibED->setText(f);
169 void QBibtexDialog::addPressed()
171 add_bc_.valid(false);
176 void QBibtexDialog::addDatabase()
178 int const sel = add_->bibLW->currentRow();
179 docstring const file = trim(qstring_to_ucs4(add_->bibED->text()));
181 if (sel < 0 && file.empty())
184 // Add the selected browser_bib keys to browser_database
185 // multiple selections are possible
186 for (int i = 0; i != add_->bibLW->count(); ++i) {
187 QListWidgetItem * const item = add_->bibLW->item(i);
188 if (add_->bibLW->isItemSelected(item)) {
189 add_->bibLW->setItemSelected(item, false);
190 QList<QListWidgetItem *> matches =
191 databaseLW->findItems(item->text(), Qt::MatchExactly);
193 databaseLW->addItem(item->text());
198 add_->bibED->clear();
199 QString const f = toqstr(from_utf8(changeExtension(to_utf8(file), "")));
200 QList<QListWidgetItem *> matches =
201 databaseLW->findItems(f, Qt::MatchExactly);
203 databaseLW->addItem(f);
210 void QBibtexDialog::deletePressed()
212 databaseLW->takeItem(databaseLW->currentRow());
218 void QBibtexDialog::databaseChanged()
220 deletePB->setEnabled(!form_->readOnly() && databaseLW->currentRow() != -1);
224 void QBibtexDialog::availableChanged()
230 void QBibtexDialog::closeEvent(QCloseEvent *e)
237 } // namespace frontend
240 #include "QBibtexDialog_moc.cpp"