3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
17 #include "QBibtexDialog.h"
18 #include "ui/QBibtexAddUi.h"
20 #include "qt_helpers.h"
21 #include "validators.h"
25 #include "controllers/ControlBibtex.h"
27 #include "support/filetools.h" // changeExtension
28 #include "support/lstrings.h"
30 #include <QPushButton>
31 #include <QListWidget>
35 using lyx::support::changeExtension;
36 using lyx::support::split;
37 using lyx::support::trim;
45 typedef QController<ControlBibtex, QView<QBibtexDialog> > bibtex_base_class;
47 QBibtex::QBibtex(Dialog & parent)
48 : bibtex_base_class(parent, _("BibTeX Bibliography"))
53 void QBibtex::build_dialog()
55 dialog_.reset(new QBibtexDialog(this));
57 bcview().setOK(dialog_->okPB);
58 bcview().setCancel(dialog_->closePB);
59 bcview().addReadOnly(dialog_->databaseLW);
60 bcview().addReadOnly(dialog_->stylePB);
61 bcview().addReadOnly(dialog_->styleCB);
62 bcview().addReadOnly(dialog_->bibtocCB);
63 bcview().addReadOnly(dialog_->addBibPB);
64 bcview().addReadOnly(dialog_->deletePB);
68 void QBibtex::update_contents()
70 PathValidator * path_validator =
71 getPathValidator(dialog_->add_->bibED);
73 path_validator->setChecker(kernel().docType(), lyxrc);
75 bool bibtopic = controller().usingBibtopic();
77 dialog_->databaseLW->clear();
79 docstring bibs(controller().params()["bibfiles"]);
82 while (!bibs.empty()) {
83 bibs = split(bibs, bib, ',');
86 dialog_->databaseLW->addItem(toqstr(bib));
89 dialog_->add_->bibLW->clear();
91 vector<string> bib_str;
92 controller().getBibFiles(bib_str);
93 for (vector<string>::const_iterator it = bib_str.begin();
94 it != bib_str.end(); ++it) {
95 string bibItem(changeExtension(*it, ""));
96 dialog_->add_->bibLW->addItem(toqstr(bibItem));
99 string bibstyle(controller().getStylefile());
101 dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
102 dialog_->bibtocCB->setEnabled(!bibtopic);
104 docstring btprint(controller().params()["btprint"]);
106 if (btprint == "btPrintNotCited")
108 else if (btprint == "btPrintAll")
111 dialog_->btPrintCO->setCurrentIndex(btp);
112 dialog_->btPrintCO->setEnabled(bibtopic);
114 dialog_->styleCB->clear();
119 controller().getBibStyles(str);
120 for (vector<string>::const_iterator it = str.begin();
121 it != str.end(); ++it) {
122 string item(changeExtension(*it, ""));
123 if (item == bibstyle)
124 item_nr = int(it - str.begin());
125 dialog_->styleCB->addItem(toqstr(item));
128 if (item_nr == -1 && !bibstyle.empty()) {
129 dialog_->styleCB->addItem(toqstr(bibstyle));
130 item_nr = dialog_->styleCB->count() - 1;
134 dialog_->styleCB->setCurrentIndex(item_nr);
136 dialog_->styleCB->clearEditText();
140 void QBibtex::apply()
142 docstring dbs(qstring_to_ucs4(dialog_->databaseLW->item(0)->text()));
144 unsigned int maxCount = dialog_->databaseLW->count();
145 for (unsigned int i = 1; i < maxCount; i++) {
147 dbs += qstring_to_ucs4(dialog_->databaseLW->item(i)->text());
150 controller().params()["bibfiles"] = dbs;
152 docstring const bibstyle(qstring_to_ucs4(dialog_->styleCB->currentText()));
153 bool const bibtotoc(dialog_->bibtocCB->isChecked());
155 if (bibtotoc && (!bibstyle.empty())) {
156 // both bibtotoc and style
157 controller().params()["options"] = "bibtotoc," + bibstyle;
158 } else if (bibtotoc) {
159 // bibtotoc and no style
160 controller().params()["options"] = lyx::from_ascii("bibtotoc");
162 // only style. An empty one is valid, because some
163 // documentclasses have an own \bibliographystyle{}
165 controller().params()["options"] = bibstyle;
168 // bibtopic allows three kinds of sections:
169 // 1. sections that include all cited references of the database(s)
170 // 2. sections that include all uncited references of the database(s)
171 // 3. sections that include all references of the database(s), cited or not
172 int btp = dialog_->btPrintCO->currentIndex();
176 controller().params()["btprint"] = lyx::from_ascii("btPrintCited");
179 controller().params()["btprint"] = lyx::from_ascii("btPrintNotCited");
182 controller().params()["btprint"] = lyx::from_ascii("btPrintAll");
186 if (!controller().usingBibtopic())
187 controller().params()["btprint"] = docstring();
191 bool QBibtex::isValid()
193 return dialog_->databaseLW->count() != 0;
196 } // namespace frontend