]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiBibtex.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / GuiBibtex.cpp
index 15d84ea45c09c384d6175421edf79339b8aac5dc..cfc696664ad77fb9e4a1d73976bb58aef662b6eb 100644 (file)
 
 #include "ButtonPolicy.h"
 
+#include "frontends/alert.h"
+
+#include "insets/InsetBibtex.h"
+
 #include "support/debug.h"
+#include "support/ExceptionMessage.h"
 #include "support/FileFilterList.h"
+#include "support/FileName.h"
 #include "support/filetools.h" // changeExtension
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -133,8 +139,7 @@ void GuiBibtex::browsePressed()
        if (file.isEmpty())
                return;
 
-       // FIXME UNICODE
-       QString const filen = toqstr(changeExtension(fromqstr(file), ""));
+       QString const filen = changeExtension(file, "");
        bool present = false;
        unsigned int pres = 0;
 
@@ -160,7 +165,7 @@ void GuiBibtex::browseBibPressed()
        if (file.isEmpty())
                return;
 
-       QString const f = toqstr(changeExtension(fromqstr(file), ""));
+       QString const f = changeExtension(file, "");
        bool present = false;
 
        for (int i = 0; i < add_->bibLW->count(); ++i) {
@@ -203,9 +208,7 @@ void GuiBibtex::addDatabase()
                        if (matches.empty()) {
                                QString label = item->text();
                                QListWidgetItem * db = new QListWidgetItem(label);
-                               db->setFlags(db->flags() | Qt::ItemIsSelectable
-                                       | Qt::ItemIsUserCheckable);
-                               db->setCheckState(Qt::Checked);
+                               db->setFlags(db->flags() | Qt::ItemIsSelectable);
                                databaseLW->addItem(db);
                        }
                }
@@ -213,14 +216,12 @@ void GuiBibtex::addDatabase()
 
        if (!file.isEmpty()) {
                add_->bibED->clear();
-               QString const f = toqstr(changeExtension(fromqstr(file), ""));
+               QString const f = changeExtension(file, "");
                QList<QListWidgetItem *> matches =
                        databaseLW->findItems(f, Qt::MatchExactly);
                if (matches.empty()) {
                        QListWidgetItem * db = new QListWidgetItem(f);
-                       db->setFlags(db->flags() | Qt::ItemIsSelectable
-                               | Qt::ItemIsUserCheckable);
-                       db->setCheckState(Qt::Checked);
+                       db->setFlags(db->flags() | Qt::ItemIsSelectable);
                        databaseLW->addItem(db);
                }
        }
@@ -285,34 +286,25 @@ void GuiBibtex::updateContents()
        databaseLW->clear();
 
        docstring bibs = params_["bibfiles"];
-       docstring embs = params_["embed"];
        docstring bib;
-       docstring emb;
 
        while (!bibs.empty()) {
                bibs = split(bibs, bib, ',');
-               embs = split(embs, emb, ',');
                bib = trim(bib);
                if (!bib.empty()) {
                        QListWidgetItem * db = new QListWidgetItem(toqstr(bib));
-                       db->setFlags(db->flags() | Qt::ItemIsSelectable
-                               | Qt::ItemIsUserCheckable);
-                       db->setCheckState(emb.empty() ? Qt::Unchecked : Qt::Checked);
+                       db->setFlags(db->flags() | Qt::ItemIsSelectable);
                        databaseLW->addItem(db);
                }
        }
 
        add_->bibLW->clear();
 
-       vector<string> bib_str;
-       getBibFiles(bib_str);
-       for (vector<string>::const_iterator it = bib_str.begin();
-               it != bib_str.end(); ++it) {
-               string bibItem(changeExtension(*it, ""));
-               add_->bibLW->addItem(toqstr(bibItem));
-       }
+       QStringList bibfiles = bibFiles();
+       for (int i = 0; i != bibfiles.count(); ++i)
+               add_->bibLW->addItem(changeExtension(bibfiles[i], ""));
 
-       string bibstyle = getStylefile();
+       QString bibstyle = styleFile();
 
        bibtocCB->setChecked(bibtotoc() && !bibtopic);
        bibtocCB->setEnabled(!bibtopic);
@@ -334,20 +326,18 @@ void GuiBibtex::updateContents()
 
        styleCB->clear();
 
-       int item_nr(-1);
+       int item_nr = -1;
 
-       vector<string> str;
-       getBibStyles(str);
-       for (vector<string>::const_iterator it = str.begin();
-               it != str.end(); ++it) {
-               string item(changeExtension(*it, ""));
+       QStringList str = bibStyles();
+       for (int i = 0; i != str.count(); ++i) {
+               QString item = changeExtension(str[i], "");
                if (item == bibstyle)
-                       item_nr = int(it - str.begin());
-               styleCB->addItem(toqstr(item));
+                       item_nr = i;
+               styleCB->addItem(item);
        }
 
-       if (item_nr == -1 && !bibstyle.empty()) {
-               styleCB->addItem(toqstr(bibstyle));
+       if (item_nr == -1 && !bibstyle.isEmpty()) {
+               styleCB->addItem(bibstyle);
                item_nr = styleCB->count() - 1;
        }
 
@@ -360,19 +350,18 @@ void GuiBibtex::updateContents()
 
 void GuiBibtex::applyView()
 {
-       QString dbs = databaseLW->item(0)->text();
-       docstring emb = databaseLW->item(0)->checkState() == Qt::Checked ? _("true") : _("false");
+       docstring dbs;
 
        unsigned int maxCount = databaseLW->count();
-       for (unsigned int i = 1; i < maxCount; i++) {
-               dbs += ',';
-               dbs += databaseLW->item(i)->text();
-               emb += ',';
-               emb += databaseLW->item(i)->checkState() == Qt::Checked ? _("true") : _("false");
+       for (unsigned int i = 0; i < maxCount; i++) {
+               if (i != 0)
+                       dbs += ',';
+               QString item = databaseLW->item(i)->text();
+               docstring bibfile = qstring_to_ucs4(item);
+               dbs += bibfile;
        }
 
-       params_["bibfiles"] = qstring_to_ucs4(dbs);
-       params_["embed"] = emb;
+       params_["bibfiles"] = dbs;
 
        docstring const bibstyle = qstring_to_ucs4(styleCB->currentText());
        bool const bibtotoc = bibtocCB->isChecked();
@@ -448,41 +437,35 @@ QString GuiBibtex::browseBst(QString const & in_name) const
 }
 
 
-void GuiBibtex::getBibStyles(vector<string> & data) const
+QStringList GuiBibtex::bibStyles() const
 {
-       data.clear();
-
-       getTexFileList("bstFiles.lst", data);
-       // test, if we have a valid list, otherwise run rescan
-       if (data.empty()) {
+       QStringList data = texFileList("bstFiles.lst");
+       // test whether we have a valid list, otherwise run rescan
+       if (data.isEmpty()) {
                rescanBibStyles();
-               getTexFileList("bstFiles.lst", data);
+               data = texFileList("bstFiles.lst");
        }
-       vector<string>::iterator it  = data.begin();
-       vector<string>::iterator end = data.end();
-       for (; it != end; ++it)
-               *it = support::onlyFilename(*it);
+       for (int i = 0; i != data.size(); ++i)
+               data[i] = onlyFilename(data[i]);
        // sort on filename only (no path)
-       sort(data.begin(), data.end());
+       data.sort();
+       return data;
 }
 
 
-void GuiBibtex::getBibFiles(vector<string> & data) const
+QStringList GuiBibtex::bibFiles() const
 {
-       data.clear();
-
-       getTexFileList("bibFiles.lst", data);
-       // test, if we have a valid list, otherwise run rescan
-       if (data.empty()) {
+       QStringList data = texFileList("bibFiles.lst");
+       // test whether we have a valid list, otherwise run rescan
+       if (data.isEmpty()) {
                rescanBibStyles();
-               getTexFileList("bibFiles.lst", data);
+               data = texFileList("bibFiles.lst");
        }
-       vector<string>::iterator it  = data.begin();
-       vector<string>::iterator end = data.end();
-       for (; it != end; ++it)
-               *it = support::onlyFilename(*it);
+       for (int i = 0; i != data.size(); ++i)
+               data[i] = onlyFilename(data[i]);
        // sort on filename only (no path)
-       sort(data.begin(), data.end());
+       data.sort();
+       return data;
 }
 
 
@@ -504,45 +487,48 @@ bool GuiBibtex::bibtotoc() const
 }
 
 
-string const GuiBibtex::getStylefile() const
+QString GuiBibtex::styleFile() const
 {
        // the different bibtex packages have (and need) their
        // own "plain" stylefiles
-       biblio::CiteEngine const engine = buffer().params().getEngine();
-       docstring defaultstyle;
+       biblio::CiteEngine const engine = buffer().params().citeEngine();
+       QString defaultstyle;
        switch (engine) {
        case biblio::ENGINE_BASIC:
-               defaultstyle = from_ascii("plain");
+               defaultstyle = "plain";
                break;
        case biblio::ENGINE_NATBIB_AUTHORYEAR:
-               defaultstyle = from_ascii("plainnat");
+               defaultstyle = "plainnat";
                break;
        case biblio::ENGINE_NATBIB_NUMERICAL:
-               defaultstyle = from_ascii("plainnat");
+               defaultstyle = "plainnat";
                break;
        case biblio::ENGINE_JURABIB:
-               defaultstyle = from_ascii("jurabib");
+               defaultstyle = "jurabib";
                break;
        }
 
-       docstring bst = params_["options"];
+       QString bst = toqstr(params_["options"]);
        if (bibtotoc()){
                // bibstyle exists?
-               if (contains(bst, ',')) {
-                       docstring bibtotoc = from_ascii("bibtotoc");
-                       bst = split(bst, bibtotoc, ',');
-               } else
-                       bst.erase();
+               int pos = bst.indexOf(',');
+               if (pos != -1) {
+                       // FIXME: check
+                       // docstring bibtotoc = from_ascii("bibtotoc");
+                       // bst = split(bst, bibtotoc, ',');
+                       bst = bst.mid(pos);     
+               } else {
+                       bst.clear();
+               }
        }
 
        // propose default style file for new insets
        // existing insets might have (legally) no bst files
        // (if the class already provides a style)
-       if (bst.empty() && params_["bibfiles"].empty())
+       if (bst.isEmpty() && params_["bibfiles"].empty())
                bst = defaultstyle;
 
-       // FIXME UNICODE
-       return to_utf8(bst);
+       return bst;
 }