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.
16 #include "QBibtexDialog.h"
17 #include "ui/QBibtexAddDialogBase.h"
19 #include "qt_helpers.h"
21 #include "controllers/ControlBibtex.h"
23 #include "support/filetools.h" // ChangeExtension
24 #include "support/lstrings.h"
26 #include <qcombobox.h>
27 #include <qpushbutton.h>
29 #include <qcheckbox.h>
32 using lyx::support::ChangeExtension;
33 using lyx::support::contains;
34 using lyx::support::prefixIs;
35 using lyx::support::split;
36 using lyx::support::trim;
44 typedef QController<ControlBibtex, QView<QBibtexDialog> > base_class;
46 QBibtex::QBibtex(Dialog & parent)
47 : base_class(parent, _("BibTeX"))
52 void QBibtex::build_dialog()
54 dialog_.reset(new QBibtexDialog(this));
56 bcview().setOK(dialog_->okPB);
57 bcview().setCancel(dialog_->closePB);
58 bcview().addReadOnly(dialog_->databaseLB);
59 bcview().addReadOnly(dialog_->stylePB);
60 bcview().addReadOnly(dialog_->styleCB);
61 bcview().addReadOnly(dialog_->bibtocCB);
62 bcview().addReadOnly(dialog_->addBibPB);
63 bcview().addReadOnly(dialog_->deletePB);
67 void QBibtex::update_contents()
69 bool bibtopic = controller().usingBibtopic();
71 dialog_->databaseLB->clear();
73 string bibs(controller().params().getContents());
76 while (!bibs.empty()) {
77 bibs = split(bibs, bib, ',');
80 dialog_->databaseLB->insertItem(toqstr(bib));
83 dialog_->add_->bibLB->clear();
85 vector<string> bib_str;
86 controller().getBibFiles(bib_str);
87 for (vector<string>::const_iterator it = bib_str.begin();
88 it != bib_str.end(); ++it) {
89 string bibItem(ChangeExtension(*it, ""));
90 dialog_->add_->bibLB->insertItem(toqstr(bibItem));
93 string bibtotoc = "bibtotoc";
94 string bibstyle(controller().params().getOptions());
97 if (prefixIs(bibstyle, bibtotoc)){
99 if (contains(bibstyle,','))
100 bibstyle = split(bibstyle, bibtotoc, ',');
105 if (prefixIs(bibstyle, bibtotoc) && !bibtopic)
106 dialog_->bibtocCB->setChecked(true);
108 dialog_->bibtocCB->setChecked(false);
110 dialog_->bibtocCB->setEnabled(!bibtopic);
112 string btprint(controller().params().getSecOptions());
114 if (btprint == "btPrintNotCited")
116 else if (btprint == "btPrintAll")
119 dialog_->btPrintCO->setCurrentItem(btp);
120 dialog_->btPrintCO->setEnabled(bibtopic);
122 dialog_->styleCB->clear();
127 controller().getBibStyles(str);
128 for (vector<string>::const_iterator it = str.begin();
129 it != str.end(); ++it) {
130 string item(ChangeExtension(*it, ""));
131 if (item == bibstyle)
132 item_nr = int(it - str.begin());
133 dialog_->styleCB->insertItem(toqstr(item));
137 dialog_->styleCB->insertItem(toqstr(bibstyle));
138 item_nr = dialog_->styleCB->count() - 1;
141 dialog_->styleCB->setCurrentItem(item_nr);
145 void QBibtex::apply()
147 string dbs(fromqstr(dialog_->databaseLB->text(0)));
149 unsigned int maxCount = dialog_->databaseLB->count();
150 for (unsigned int i = 1; i < maxCount; i++) {
152 dbs += fromqstr(dialog_->databaseLB->text(i));
155 controller().params().setContents(dbs);
157 string const bibstyle(fromqstr(dialog_->styleCB->currentText()));
158 bool const bibtotoc(dialog_->bibtocCB->isChecked());
160 if (bibtotoc && (!bibstyle.empty())) {
161 // both bibtotoc and style
162 controller().params().setOptions("bibtotoc," + bibstyle);
163 } else if (bibtotoc) {
164 // bibtotoc and no style
165 controller().params().setOptions("bibtotoc");
167 // only style. An empty one is valid, because some
168 // documentclasses have an own \bibliographystyle{}
170 controller().params().setOptions(bibstyle);
173 // bibtopic allows three kinds of sections:
174 // 1. sections that include all cited references of the database(s)
175 // 2. sections that include all uncited references of the database(s)
176 // 3. sections that include all references of the database(s), cited or not
177 int btp = dialog_->btPrintCO->currentItem();
181 controller().params().setSecOptions("btPrintCited");
184 controller().params().setSecOptions("btPrintNotCited");
187 controller().params().setSecOptions("btPrintAll");
191 if (!controller().usingBibtopic())
192 controller().params().setSecOptions("");
196 bool QBibtex::isValid()
198 return dialog_->databaseLB->count() != 0;
201 } // namespace frontend