]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QBibtex.C
Lots and lots of little trivial bits.
[lyx.git] / src / frontends / qt2 / QBibtex.C
1 /**
2  * \file QBibtex.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon 
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "support/lstrings.h"
18
19 #include "ControlBibtex.h"
20 #include "gettext.h"
21 #include "debug.h"
22 #include "support/filetools.h" // ChangeExtension
23 #include "support/lstrings.h" // getVectorFromString
24 #include <qlineedit.h>
25 #include <qcombobox.h>
26 #include <qpushbutton.h>
27 #include <qlistbox.h>
28 #include <qcheckbox.h>
29
30 #include "QBibtexDialog.h"
31 #include "QBibtex.h"
32 #include "Qt2BC.h"
33
34 using std::vector;
35
36 typedef Qt2CB<ControlBibtex, Qt2DB<QBibtexDialog> > base_class;
37
38 QBibtex::QBibtex()
39         : base_class(_("BibTeX"))
40 {
41 }
42
43
44 void QBibtex::build_dialog()
45 {
46         dialog_.reset(new QBibtexDialog(this));
47
48         bc().setOK(dialog_->okPB);
49         bc().setCancel(dialog_->closePB);
50         bc().addReadOnly(dialog_->databaseLB);
51         bc().addReadOnly(dialog_->databasePB);
52         bc().addReadOnly(dialog_->stylePB);
53         bc().addReadOnly(dialog_->styleCB);
54         bc().addReadOnly(dialog_->bibtocCB);
55         bc().addReadOnly(dialog_->databasePB);
56         bc().addReadOnly(dialog_->deletePB);
57 }
58
59
60 void QBibtex::update_contents()
61 {
62         dialog_->databaseLB->clear();
63
64         string bibs(controller().params().getContents());
65         string bib;
66
67         while (!bibs.empty()) {
68                 bibs = split(bibs, bib, ',');
69                 bib = trim(bib);
70                 if (!bib.empty())
71                         dialog_->databaseLB->inSort(bib.c_str());
72         }
73
74         string bibtotoc = "bibtotoc";
75         string bibstyle(controller().params().getOptions().c_str());
76
77         // bibtotoc exists?
78         if (prefixIs(bibstyle,bibtotoc)) {
79                 dialog_->bibtocCB->setChecked(true);
80
81                 // bibstyle exists?
82                 if (contains(bibstyle,','))
83                         bibstyle = split(bibstyle, bibtotoc, ',');
84                 else
85                         bibstyle = "";
86         } else
87                 dialog_->bibtocCB->setChecked(false);
88
89
90         vector<string> const str = getVectorFromString(
91                 controller().getBibStyles(),"\n");
92         for (vector<string>::const_iterator it = str.begin();
93                 it != str.end(); ++it) {
94                 dialog_->styleCB->insertItem(ChangeExtension(*it,"").c_str());
95         }
96         dialog_->styleCB->insertItem(bibstyle.c_str(),0);
97 }
98
99
100 void QBibtex::apply()
101 {
102         string dbs;
103
104         for (unsigned int i = 0; i < dialog_->databaseLB->count(); ++i) {
105                 dbs += dialog_->databaseLB->text(i).latin1();
106                 if (i != dialog_->databaseLB->count())
107                         dbs += ",";
108         }
109         controller().params().setContents(dbs);
110
111         string bibstyle(dialog_->styleCB->text(0).latin1());
112
113         bool const bibtotoc(dialog_->bibtocCB->isChecked());
114
115         if (bibtotoc && (!bibstyle.empty())) {
116                 // both bibtotoc and style
117                 controller().params().setOptions("bibtotoc," + bibstyle);
118         } else if (bibtotoc) {
119                 // bibtotoc and no style
120                 controller().params().setOptions("bibtotoc");
121         } else if (!bibstyle.empty()){
122                 // only style
123                 controller().params().setOptions(bibstyle);
124         }
125 }
126
127
128 bool QBibtex::isValid()
129 {
130         return dialog_->databaseLB->count() != 0 &&
131                 !string(dialog_->styleCB->text(0)).empty();
132 }