]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QBibtex.C
The initial merge of the Qt frontend, and the necessary compile fixes.
[lyx.git] / src / frontends / qt2 / QBibtex.C
1 /**
2  * \file QBibtex.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #include <config.h>
10
11 #include "support/lstrings.h"
12
13 #include "ControlBibtex.h"
14 #include "gettext.h"
15 #include "debug.h"
16
17 #include <qlineedit.h>
18 #include <qcombobox.h>
19 #include <qpushbutton.h>
20 #include <qlistbox.h>
21 #include <qcheckbox.h>
22
23 #include "QBibtexDialog.h"
24 #include "QBibtex.h"
25 #include "Qt2BC.h"
26  
27 typedef Qt2CB<ControlBibtex, Qt2DB<QBibtexDialog> > base_class;
28
29 QBibtex::QBibtex(ControlBibtex & c)
30         : base_class(c, _("BibTeX"))
31 {
32 }
33
34
35 void QBibtex::build_dialog()
36 {
37         dialog_.reset(new QBibtexDialog(this));
38
39         bc().setOK(dialog_->okPB);
40         bc().setCancel(dialog_->closePB);
41         bc().addReadOnly(dialog_->databaseLB);
42         bc().addReadOnly(dialog_->databasePB);
43         bc().addReadOnly(dialog_->styleCO);
44         bc().addReadOnly(dialog_->styleED);
45         bc().addReadOnly(dialog_->stylePB);
46         bc().addReadOnly(dialog_->bibtocCB);
47         bc().addReadOnly(dialog_->databasePB);
48         bc().addReadOnly(dialog_->deletePB);
49 }
50
51
52 void QBibtex::update_contents()
53 {
54         dialog_->databaseLB->clear();
55
56         string bibs(controller().params().getContents());
57         string bib;
58
59         while (!bibs.empty()) {
60                 bibs = split(bibs, bib, ',');
61                 bib = frontStrip(strip(bib));
62                 if (!bib.empty())
63                         dialog_->databaseLB->inSort(bib.c_str());
64         }
65
66         string bibtotoc = "bibtotoc";
67         string bibstyle(controller().params().getOptions().c_str());
68
69         // bibtotoc exists?
70         if (prefixIs(bibstyle,bibtotoc)) {
71                 dialog_->bibtocCB->setChecked(true);
72
73                 // bibstyle exists?
74                 if (contains(bibstyle,','))
75                         bibstyle = split(bibstyle, bibtotoc, ',');
76                 else
77                         bibstyle = "";
78         } else
79                 dialog_->bibtocCB->setChecked(false);
80
81         dialog_->deletePB->setEnabled(false);
82         dialog_->styleED->setEnabled(false);
83         dialog_->stylePB->setEnabled(false);
84
85         if (bibstyle == "plain" || bibstyle.empty())
86                 dialog_->styleCO->setCurrentItem(0);
87         else if (bibstyle == "unsrt")
88                 dialog_->styleCO->setCurrentItem(1);
89         else if (bibstyle == "alpha")
90                 dialog_->styleCO->setCurrentItem(2);
91         else if (bibstyle == "abbrv")
92                 dialog_->styleCO->setCurrentItem(3);
93         else {
94                 dialog_->styleED->setEnabled(true);
95                 dialog_->stylePB->setEnabled(true);
96                 dialog_->styleED->setText(bibstyle.c_str());
97                 dialog_->styleCO->setCurrentItem(4);
98         }
99
100 }
101
102
103 void QBibtex::apply()
104 {
105         string dbs;
106
107         for (unsigned int i = 0; i < dialog_->databaseLB->count(); ++i) {
108                 dbs += dialog_->databaseLB->text(i).latin1();
109                 if (i != dialog_->databaseLB->count())
110                         dbs += ",";
111         }
112         controller().params().setContents(dbs);
113
114         string bibstyle(dialog_->styleCO->currentText().latin1());
115         if (bibstyle == _("Other ..."))
116                 bibstyle = dialog_->styleED->text().latin1();
117
118         bool const bibtotoc(dialog_->bibtocCB->isChecked());
119
120         if (bibtotoc && (!bibstyle.empty())) {
121                 // both bibtotoc and style
122                 controller().params().setOptions("bibtotoc," + bibstyle);
123         } else if (bibtotoc) {
124                 // bibtotoc and no style
125                 controller().params().setOptions("bibtotoc");
126         } else if (!bibstyle.empty()){
127                 // only style
128                 controller().params().setOptions(bibstyle);
129         }
130 }
131
132
133 bool QBibtex::isValid()
134 {
135         return dialog_->databaseLB->count() != 0 &&
136                 !(dialog_->styleCO->currentItem() == 4 && string(dialog_->styleED->text()).empty());
137 }