diff --git a/src/global/preferences.cpp b/src/global/preferences.cpp index cd77e839..7d630854 100644 --- a/src/global/preferences.cpp +++ b/src/global/preferences.cpp @@ -1,468 +1,460 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "preferences.h" #include #include #ifdef HAVE_KF5 #include #include #include #include #else // HAVE_KF5 #define I18N_NOOP(text) QObject::tr(text) #define i18n(text) QObject::tr(text) #endif // HAVE_KF5 #ifdef HAVE_KF5 #include "notificationhub.h" #endif // HAVE_KF5 const QString Preferences::groupColor = QStringLiteral("Color Labels"); const QString Preferences::keyColorCodes = QStringLiteral("colorCodes"); const QStringList Preferences::defaultColorCodes {QStringLiteral("#cc3300"), QStringLiteral("#0033ff"), QStringLiteral("#009966"), QStringLiteral("#f0d000")}; const QString Preferences::keyColorLabels = QStringLiteral("colorLabels"); // FIXME // clazy warns: QString(const char*) being called [-Wclazy-qstring-uneeded-heap-allocations] // ... but using QStringLiteral may break the translation process? const QStringList Preferences::defaultColorLabels {I18N_NOOP("Important"), I18N_NOOP("Unread"), I18N_NOOP("Read"), I18N_NOOP("Watch")}; const QString Preferences::groupGeneral = QStringLiteral("General"); const QString Preferences::groupUserInterface = QStringLiteral("User Interface"); const QString Preferences::keyElementDoubleClickAction = QStringLiteral("elementDoubleClickAction"); const Preferences::ElementDoubleClickAction Preferences::defaultElementDoubleClickAction = ActionOpenEditor; const QString Preferences::keyEncoding = QStringLiteral("encoding"); const QString Preferences::defaultEncoding = QStringLiteral("LaTeX"); const QString Preferences::keyStringDelimiter = QStringLiteral("stringDelimiter"); const QString Preferences::defaultStringDelimiter = QStringLiteral("{}"); const QString Preferences::keyQuoteComment = QStringLiteral("quoteComment"); const Preferences::QuoteComment Preferences::defaultQuoteComment = qcNone; const QString Preferences::keyKeywordCasing = QStringLiteral("keywordCasing"); const KBibTeX::Casing Preferences::defaultKeywordCasing = KBibTeX::cLowerCase; const QString Preferences::keyProtectCasing = QStringLiteral("protectCasing"); const Qt::CheckState Preferences::defaultProtectCasing = Qt::PartiallyChecked; const QString Preferences::keyListSeparator = QStringLiteral("ListSeparator"); const QString Preferences::defaultListSeparator = QStringLiteral("; "); class Preferences::Private { public: #ifdef HAVE_KF5 KSharedConfigPtr config; KConfigWatcher::Ptr watcher; #endif // HAVE_KF5 Private(Preferences *) { #ifdef HAVE_KF5 config = KSharedConfig::openConfig(QStringLiteral("kbibtexrc")); watcher = KConfigWatcher::create(config); dirtyFlagBibliographySystem = true; cachedBibliographySystem = defaultBibliographySystem; dirtyFlagPersonNameFormatting = true; cachedPersonNameFormatting = defaultPersonNameFormatting; dirtyFlagCopyReferenceCommand = true; cachedCopyReferenceCommand = defaultCopyReferenceCommand; dirtyFlagPageSize = true; cachedPageSize = defaultPageSize; dirtyFlagBackupScope = true; cachedBackupScope = defaultBackupScope; dirtyFlagNumberOfBackups = true; cachedNumberOfBackups = defaultNumberOfBackups; dirtyFlagIdSuggestionFormatStrings = true; cachedIdSuggestionFormatStrings = defaultIdSuggestionFormatStrings; dirtyFlagActiveIdSuggestionFormatString = true; cachedActiveIdSuggestionFormatString = defaultActiveIdSuggestionFormatString; dirtyFlagLyXUseAutomaticPipeDetection = true; cachedLyXUseAutomaticPipeDetection = defaultLyXUseAutomaticPipeDetection; dirtyFlagLyXPipePath = true; cachedLyXPipePath = defaultLyXPipePath; #endif // HAVE_KF5 } #ifdef HAVE_KF5 inline bool validateValueForBibliographySystem(const int valueToBeChecked) { for (QVector>::ConstIterator it = Preferences::availableBibliographySystems.constBegin(); it != Preferences::availableBibliographySystems.constEnd(); ++it) if (static_cast(it->first) == valueToBeChecked) return true; return false; } inline bool validateValueForPersonNameFormatting(const QString &valueToBeChecked) { return valueToBeChecked.contains(QStringLiteral("%f")) && valueToBeChecked.contains(QStringLiteral("%l")) && valueToBeChecked.contains(QStringLiteral("%s")); } inline bool validateValueForPageSize(const int valueToBeChecked) { for (const auto &dbItem : Preferences::availablePageSizes) if (static_cast(dbItem.internalPageSizeId) == valueToBeChecked) return true; return false; } inline bool validateValueForCopyReferenceCommand(const QString &/*valueToBeChecked*/) { return true; } inline bool validateValueForBackupScope(const int valueToBeChecked) { for (const auto &dbItem : Preferences::availableBackupScopes) if (static_cast(dbItem.first) == valueToBeChecked) return true; return false; } inline bool validateValueForNumberOfBackups(const int valueToBeChecked) { return valueToBeChecked >= 0; } inline bool validateValueForIdSuggestionFormatStrings(const QStringList &valueToBeChecked) { return !valueToBeChecked.isEmpty() && (valueToBeChecked.front().contains(QLatin1Char('A')) || valueToBeChecked.front().contains(QLatin1Char('a')) || valueToBeChecked.front().contains(QLatin1Char('y')) || valueToBeChecked.front().contains(QLatin1Char('Y')) || valueToBeChecked.front().contains(QLatin1Char('T'))); } inline bool validateValueForActiveIdSuggestionFormatString(const QString &) { return true; } inline bool validateValueForLyXUseAutomaticPipeDetection(const bool) { return true; } inline bool validateValueForLyXPipePath(const QString &valueToBeChecked) { return valueToBeChecked.startsWith(QLatin1Char('/')); } #define getterSetter(type, typeInConfig, stem, notificationEventId, configGroupName) \ bool dirtyFlag##stem; \ type cached##stem; \ bool set##stem(const type &newValue) { \ dirtyFlag##stem = false; \ cached##stem = newValue; \ static KConfigGroup configGroup(config, QStringLiteral(configGroupName)); \ const typeInConfig valueFromConfig = configGroup.readEntry(QStringLiteral(#stem), static_cast(Preferences::default##stem)); \ const typeInConfig newValuePOD = static_cast(newValue); \ if (valueFromConfig == newValuePOD) return false; \ configGroup.writeEntry(QStringLiteral(#stem), newValuePOD, KConfig::Notify /** to catch changes via KConfigWatcher */); \ config->sync(); \ NotificationHub::publishEvent(notificationEventId); \ return true; \ } \ type get##stem() { \ if (dirtyFlag##stem) { \ config->reparseConfiguration(); static const KConfigGroup configGroup(config, QStringLiteral(configGroupName)); \ const typeInConfig valueFromConfiguration = configGroup.readEntry(QStringLiteral(#stem), static_cast(Preferences::default##stem)); \ if (validateValueFor##stem(valueFromConfiguration)) { \ cached##stem = static_cast(valueFromConfiguration); \ dirtyFlag##stem = false; \ } else { \ qWarning() << "Configuration file setting for" << #stem << "has an invalid value, using default as fallback"; \ set##stem(Preferences::default##stem); \ } \ } \ return cached##stem; \ } getterSetter(Preferences::BibliographySystem, int, BibliographySystem, NotificationHub::EventBibliographySystemChanged, "General") getterSetter(QString, QString, PersonNameFormatting, NotificationHub::EventConfigurationChanged, "General") getterSetter(QPageSize::PageSizeId, int, PageSize, NotificationHub::EventConfigurationChanged, "General") getterSetter(QString, QString, CopyReferenceCommand, NotificationHub::EventConfigurationChanged, "LaTeX") getterSetter(Preferences::BackupScope, int, BackupScope, NotificationHub::EventConfigurationChanged, "InputOutput") getterSetter(int, int, NumberOfBackups, NotificationHub::EventConfigurationChanged, "InputOutput") getterSetter(QStringList, QStringList, IdSuggestionFormatStrings, NotificationHub::EventConfigurationChanged, "IdSuggestions") getterSetter(QString, QString, ActiveIdSuggestionFormatString, NotificationHub::EventConfigurationChanged, "IdSuggestions") getterSetter(bool, bool, LyXUseAutomaticPipeDetection, NotificationHub::EventConfigurationChanged, "LyX") getterSetter(QString, QString, LyXPipePath, NotificationHub::EventConfigurationChanged, "LyX") #endif // HAVE_KF5 }; Preferences &Preferences::instance() { static Preferences singleton; return singleton; } Preferences::Preferences() : d(new Preferences::Private(this)) { #ifdef HAVE_KF5 QObject::connect(d->watcher.data(), &KConfigWatcher::configChanged, [this](const KConfigGroup & group, const QByteArrayList & names) { QSet eventsToPublish; #define eventCheck(type, stem, notificationEventId, configGroupName) \ if (group.name() == QStringLiteral(configGroupName) && names.contains(#stem)) { \ qDebug() << "Configuration setting"<<#stem<<"got changed by another Preferences instance"; \ d->dirtyFlag##stem = true; \ eventsToPublish.insert(notificationEventId); \ } eventCheck(Preferences::BibliographySystem, BibliographySystem, NotificationHub::EventBibliographySystemChanged, "General") eventCheck(QString, PersonNameFormatting, NotificationHub::EventConfigurationChanged, "General") eventCheck(QPageSize::PageSizeId, PageSize, NotificationHub::EventConfigurationChanged, "General") eventCheck(QString, CopyReferenceCommand, NotificationHub::EventConfigurationChanged, "LaTeX") eventCheck(Preferences::BackupScope, BackupScope, NotificationHub::EventConfigurationChanged, "InputOutput") eventCheck(int, NumberOfBackups, NotificationHub::EventConfigurationChanged, "InputOutput") for (const int eventId : eventsToPublish) NotificationHub::publishEvent(eventId); }); #endif // HAVE_KF5 } Preferences::~Preferences() { delete d; } const Preferences::BibliographySystem Preferences::defaultBibliographySystem = Preferences::BibTeX; Preferences::BibliographySystem Preferences::bibliographySystem() { #ifdef HAVE_KF5 return d->getBibliographySystem(); #else // HAVE_KF5 return defaultBibliographySystem; #endif // HAVE_KF5 } bool Preferences::setBibliographySystem(const Preferences::BibliographySystem bibliographySystem) { #ifdef HAVE_KF5 return d->setBibliographySystem(bibliographySystem); #else // HAVE_KF5 Q_UNUSED(bibliographySystem); return true; #endif // HAVE_KF5 } const QVector> Preferences::availableBibliographySystems {{Preferences::BibTeX, i18n("BibTeX")}, {Preferences::BibLaTeX, i18n("BibLaTeX")}}; const QString Preferences::personNameFormatLastFirst = QStringLiteral("<%l><, %s><, %f>"); const QString Preferences::personNameFormatFirstLast = QStringLiteral("<%f ><%l>< %s>"); const QString Preferences::defaultPersonNameFormatting = Preferences::personNameFormatLastFirst; QString Preferences::personNameFormatting() { #ifdef HAVE_KF5 return d->getPersonNameFormatting(); #else // HAVE_KF5 return defaultPersonNameFormatting; #endif // HAVE_KF5 } bool Preferences::setPersonNameFormatting(const QString &personNameFormatting) { #ifdef HAVE_KF5 return d->setPersonNameFormatting(personNameFormatting); #else // HAVE_KF5 Q_UNUSED(personNameFormatting); return true; #endif // HAVE_KF5 } const QVector Preferences::availableCopyReferenceCommands {QStringLiteral("cite"), QStringLiteral("citealt"), QStringLiteral("citeauthor"), QStringLiteral("citeauthor*"), QStringLiteral("citeyear"), QStringLiteral("citeyearpar"), QStringLiteral("shortcite"), QStringLiteral("citet"), QStringLiteral("citet*"), QStringLiteral("citep"), QStringLiteral("citep*")}; // TODO more const QString Preferences::defaultCopyReferenceCommand = availableCopyReferenceCommands.first(); QString Preferences::copyReferenceCommand() { #ifdef HAVE_KF5 return d->getCopyReferenceCommand(); #else // HAVE_KF5 return defaultCopyReferenceCommand; #endif // HAVE_KF5 } bool Preferences::setCopyReferenceCommand(const QString ©ReferenceCommand) { #ifdef HAVE_KF5 return d->setCopyReferenceCommand(copyReferenceCommand); #else // HAVE_KF5 Q_UNUSED(copyReferenceCommand); return true; #endif // HAVE_KF5 } -const QVector Preferences::availablePageSizes {{QPageSize::A4, i18n("A4"), QStringLiteral("a4paper")}, {QPageSize::Letter, i18n("Letter"), QStringLiteral("letter")}, {QPageSize::Legal, i18n("Legal"), QStringLiteral("legal")}}; +const QVector Preferences::availablePageSizes {{QPageSize::A4, QStringLiteral("a4paper")}, {QPageSize::Letter, QStringLiteral("letter")}, {QPageSize::Legal, QStringLiteral("legal")}}; const QPageSize::PageSizeId Preferences::defaultPageSize = Preferences::availablePageSizes.front().internalPageSizeId; QPageSize::PageSizeId Preferences::pageSize() { #ifdef HAVE_KF5 return d->getPageSize(); #else // HAVE_KF5 return defaultPageSize; #endif // HAVE_KF5 } bool Preferences::setPageSize(const QPageSize::PageSizeId pageSizeId) { #ifdef HAVE_KF5 return d->setPageSize(pageSizeId); #else // HAVE_KF5 Q_UNUSED(pageSizeId); return true; #endif // HAVE_KF5 } -QString Preferences::pageSizeToLocalizedName(const QPageSize::PageSizeId pageSizeId) -{ - for (const auto &dbItem : availablePageSizes) - if (dbItem.internalPageSizeId == pageSizeId) - return dbItem.localizedName; - return QPageSize::name(pageSizeId); -} - QString Preferences::pageSizeToLaTeXName(const QPageSize::PageSizeId pageSizeId) { for (const auto &dbItem : availablePageSizes) if (dbItem.internalPageSizeId == pageSizeId) return dbItem.laTeXName; return QPageSize::name(pageSizeId).toLower(); ///< just a wild guess } const QVector> Preferences::availableBackupScopes {{Preferences::NoBackup, i18n("No backups")}, {Preferences::LocalOnly, i18n("Local files only")}, {Preferences::BothLocalAndRemote, i18n("Both local and remote files")}}; const Preferences::BackupScope Preferences::defaultBackupScope = Preferences::availableBackupScopes.at(1).first; Preferences::BackupScope Preferences::backupScope() { #ifdef HAVE_KF5 return d->getBackupScope(); #else // HAVE_KF5 return defaultBackupScope; #endif // HAVE_KF5 } bool Preferences::setBackupScope(const Preferences::BackupScope backupScope) { #ifdef HAVE_KF5 return d->setBackupScope(backupScope); #else // HAVE_KF5 Q_UNUSED(backupScope); return true; #endif // HAVE_KF5 } const int Preferences::defaultNumberOfBackups = 5; int Preferences::numberOfBackups() { #ifdef HAVE_KF5 return d->getNumberOfBackups(); #else // HAVE_KF5 return defaultNumberOfBackups; #endif // HAVE_KF5 } bool Preferences::setNumberOfBackups(const int numberOfBackups) { #ifdef HAVE_KF5 return d->setNumberOfBackups(numberOfBackups); #else // HAVE_KF5 Q_UNUSED(numberOfBackups); return true; #endif // HAVE_KF5 } const QStringList Preferences::defaultIdSuggestionFormatStrings {QStringLiteral("A"), QStringLiteral("A2|y"), QStringLiteral("A3|y"), QStringLiteral("A4|y|\":|T5"), QStringLiteral("al|\":|T"), QStringLiteral("al|y"), QStringLiteral("al|Y"), QStringLiteral("Al\"-|\"-|y"), QStringLiteral("Al\"+|Y"), QStringLiteral("al|y|T"), QStringLiteral("al|Y|T3"), QStringLiteral("al|Y|T3l"), QStringLiteral("a|\":|Y|\":|T1"), QStringLiteral("a|y"), QStringLiteral("A|\":|Y")}; QStringList Preferences::idSuggestionFormatStrings() { #ifdef HAVE_KF5 return d->getIdSuggestionFormatStrings(); #else // HAVE_KF5 return defaultIdSuggestionFormatStrings; #endif // HAVE_KF5 } bool Preferences::setIdSuggestionFormatStrings(const QStringList &idSuggestionFormatStrings) { #ifdef HAVE_KF5 return d->setIdSuggestionFormatStrings(idSuggestionFormatStrings); #else // HAVE_KF5 Q_UNUSED(idSuggestionFormatStrings); return true; #endif // HAVE_KF5 } const QString Preferences::defaultActiveIdSuggestionFormatString; ///< intentially empty QString Preferences::activeIdSuggestionFormatString() { #ifdef HAVE_KF5 return d->getActiveIdSuggestionFormatString(); #else // HAVE_KF5 return defaultActiveIdSuggestionFormatString; #endif // HAVE_KF5 } bool Preferences::setActiveIdSuggestionFormatString(const QString &activeIdSuggestionFormatString) { #ifdef HAVE_KF5 return d->setActiveIdSuggestionFormatString(activeIdSuggestionFormatString); #else // HAVE_KF5 Q_UNUSED(activeIdSuggestionFormatString); return true; #endif // HAVE_KF5 } const bool Preferences::defaultLyXUseAutomaticPipeDetection = true; bool Preferences::lyXUseAutomaticPipeDetection() { #ifdef HAVE_KF5 return d->getLyXUseAutomaticPipeDetection(); #else // HAVE_KF5 return defaultLyXUseAutomaticPipeDetection; #endif // HAVE_KF5 } bool Preferences::setLyXUseAutomaticPipeDetection(const bool lyXUseAutomaticPipeDetection) { #ifdef HAVE_KF5 return d->setLyXUseAutomaticPipeDetection(lyXUseAutomaticPipeDetection); #else // HAVE_KF5 Q_UNUSED(lyXUseAutomaticPipeDetection); return true; #endif // HAVE_KF5 } const QString Preferences::defaultLyXPipePath = QDir::homePath() + QStringLiteral("/.lyxpipe.in"); QString Preferences::lyXPipePath() { #ifdef HAVE_KF5 return d->getLyXPipePath(); #else // HAVE_KF5 return defaultLyXPipePath; #endif // HAVE_KF5 } bool Preferences::setLyXPipePath(const QString &lyXPipePath) { #ifdef HAVE_KF5 QString sanitizedLyXPipePath = lyXPipePath; if (sanitizedLyXPipePath.endsWith(QStringLiteral(".out"))) sanitizedLyXPipePath = sanitizedLyXPipePath.left(sanitizedLyXPipePath.length() - 4); if (!sanitizedLyXPipePath.endsWith(QStringLiteral(".in"))) sanitizedLyXPipePath = sanitizedLyXPipePath.append(QStringLiteral(".in")); return d->setLyXPipePath(sanitizedLyXPipePath); #else // HAVE_KF5 Q_UNUSED(lyXPipePath); return true; #endif // HAVE_KF5 } diff --git a/src/global/preferences.h b/src/global/preferences.h index 5b86b460..a6642058 100644 --- a/src/global/preferences.h +++ b/src/global/preferences.h @@ -1,177 +1,175 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GLOBAL_PREFERENCES_H #define KBIBTEX_GLOBAL_PREFERENCES_H #include #include "kbibtex.h" /** @author Thomas Fischer */ class Preferences { public: static Preferences &instance(); ~Preferences(); protected: Preferences(); public: /// *** Bibliography system, as of now either BibTeX or BibLaTeX /// Bibliography system: either BibTeX or BibLaTeX enum BibliographySystem { BibTeX = 0, BibLaTeX = 1 }; /// Default bibliography system if nothing else is set or defined static const BibliographySystem defaultBibliographySystem; /// Retrieve current bibliography system BibliographySystem bibliographySystem(); /// Set bibliography system /// @return true if the set bibliography system is differed from the previous value, false if both were the same bool setBibliographySystem(const BibliographySystem bibliographySystem); /// Map of supported bibliography systems, should be the same as in enum BibliographySystem static const QVector> availableBibliographySystems; /// *** Name formatting like "Firstname Lastname", "Lastname, Firstname", or any other combination /// Predefined value for a person formatting, where last name comes before first name static const QString personNameFormatLastFirst; /// Predefined value for a person formatting, where first name comes before last name static const QString personNameFormatFirstLast; /// Default name formatting for a person if nothing else is set or defined static const QString defaultPersonNameFormatting; /// Retrieve current name formatting QString personNameFormatting(); /// Set name formatting /// @return true if the set formatting is differed from the previous value, false if both were the same bool setPersonNameFormatting(const QString &personNameFormatting); /// *** LaTeX cite command to use if copying references, such as \cite{smith2011} or \citep{smith2011} static const QVector availableCopyReferenceCommands; static const QString defaultCopyReferenceCommand; QString copyReferenceCommand(); /// Set copy reference command /// @return true if the set copy reference command is differed from the previous value, false if both were the same bool setCopyReferenceCommand(const QString ©ReferenceCommand); /// *** Default paper size /// Default paper size if nothing else is set or defined static const QPageSize::PageSizeId defaultPageSize; /// Retrieve current paper size QPageSize::PageSizeId pageSize(); /// Set paper size /// @return true if the set paper size is differed from the previous value, false if both were the same bool setPageSize(const QPageSize::PageSizeId pageSizeId); /// List of supported paper sizes including mappings to localized names and LaTeX names typedef struct { QPageSize::PageSizeId internalPageSizeId; - QString localizedName; QString laTeXName; } PageSizeDatabase; static const QVector availablePageSizes; - static QString pageSizeToLocalizedName(const QPageSize::PageSizeId pageSize); static QString pageSizeToLaTeXName(const QPageSize::PageSizeId pageSize); /// *** Backups of bibliography files enum BackupScope { NoBackup, LocalOnly, BothLocalAndRemote }; /// Default backup scope if nothing else is set or defined static const BackupScope defaultBackupScope; /// Retrieve current backup scope BackupScope backupScope(); /// Set backup scope /// @return true if the set backup scope is differed from the previous value, false if both were the same bool setBackupScope(const BackupScope backupScope); /// Map of supported backup scopes, should be the same as in enum BackupScope static const QVector> availableBackupScopes; /// Default number of backups if nothing else is set or defined static const int defaultNumberOfBackups; /// Retrieve current number of backups int numberOfBackups(); /// Set number of backups /// @return true if the set number of backups is differed from the previous value, false if both were the same bool setNumberOfBackups(const int numberOfBackups); /// *** Id Suggestions static const QStringList defaultIdSuggestionFormatStrings; QStringList idSuggestionFormatStrings(); bool setIdSuggestionFormatStrings(const QStringList &idSuggestionFormatStrings); static const QString defaultActiveIdSuggestionFormatString; QString activeIdSuggestionFormatString(); bool setActiveIdSuggestionFormatString(const QString &activeIdSuggestionFormatString); /// *** LyX interaction via pipes static const bool defaultLyXUseAutomaticPipeDetection; bool lyXUseAutomaticPipeDetection(); bool setLyXUseAutomaticPipeDetection(const bool lyXUseAutomaticPipeDetection); static const QString defaultLyXPipePath; QString lyXPipePath(); bool setLyXPipePath(const QString &lyXPipePath); enum ElementDoubleClickAction { ActionOpenEditor = 0, ActionViewDocument = 1 }; /** * Preferences for File objects */ enum QuoteComment { qcNone = 0, qcCommand = 1, qcPercentSign = 2 }; static const QString groupColor; static const QString keyColorCodes; static const QStringList defaultColorCodes; static const QString keyColorLabels; static const QStringList defaultColorLabels; static const QString groupGeneral; static const QString groupUserInterface; static const QString keyElementDoubleClickAction; static const ElementDoubleClickAction defaultElementDoubleClickAction; static const QString keyEncoding; static const QString defaultEncoding; static const QString keyStringDelimiter; static const QString defaultStringDelimiter; static const QString keyQuoteComment; static const QuoteComment defaultQuoteComment; static const QString keyKeywordCasing; static const KBibTeX::Casing defaultKeywordCasing; static const QString keyProtectCasing; static const Qt::CheckState defaultProtectCasing; static const QString keyListSeparator; static const QString defaultListSeparator; private: Q_DISABLE_COPY(Preferences) class Private; Private *const d; }; #endif // KBIBTEX_GLOBAL_PREFERENCES_H diff --git a/src/gui/preferences/settingsfileexporterpdfpswidget.cpp b/src/gui/preferences/settingsfileexporterpdfpswidget.cpp index 41305903..ccdc90e5 100644 --- a/src/gui/preferences/settingsfileexporterpdfpswidget.cpp +++ b/src/gui/preferences/settingsfileexporterpdfpswidget.cpp @@ -1,152 +1,152 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "settingsfileexporterpdfpswidget.h" #include #include #include #include #include #include #include #include "guihelper.h" #include "fileexportertoolchain.h" #include "preferences.h" class SettingsFileExporterPDFPSWidget::SettingsFileExporterPDFPSWidgetPrivate { private: SettingsFileExporterPDFPSWidget *p; KComboBox *comboBoxPaperSize; KComboBox *comboBoxBabelLanguage; KComboBox *comboBoxBibliographyStyle; KSharedConfigPtr config; const QString configGroupName, configGroupNameGeneral ; public: SettingsFileExporterPDFPSWidgetPrivate(SettingsFileExporterPDFPSWidget *parent) : p(parent), config(KSharedConfig::openConfig(QStringLiteral("kbibtexrc"))), configGroupName(QStringLiteral("FileExporterPDFPS")), configGroupNameGeneral(QStringLiteral("General")) { setupGUI(); } void loadState() { KConfigGroup configGroupGeneral(config, configGroupNameGeneral); int row = qMax(0, GUIHelper::selectValue(comboBoxPaperSize->model(), static_cast(Preferences::instance().pageSize()), Qt::UserRole)); comboBoxPaperSize->setCurrentIndex(row); KConfigGroup configGroup(config, configGroupName); QString babelLanguage = configGroup.readEntry(FileExporterToolchain::keyBabelLanguage, FileExporterToolchain::defaultBabelLanguage); row = GUIHelper::selectValue(comboBoxBabelLanguage->model(), babelLanguage); comboBoxBabelLanguage->setCurrentIndex(row); QString bibliographyStyle = configGroup.readEntry(FileExporterToolchain::keyBibliographyStyle, FileExporterToolchain::defaultBibliographyStyle); row = GUIHelper::selectValue(comboBoxBibliographyStyle->model(), bibliographyStyle); comboBoxBibliographyStyle->setCurrentIndex(row); } void saveState() { KConfigGroup configGroupGeneral(config, configGroupNameGeneral); Preferences::instance().setPageSize(static_cast(comboBoxPaperSize->currentData().toInt())); KConfigGroup configGroup(config, configGroupName); configGroup.writeEntry(FileExporterToolchain::keyBabelLanguage, comboBoxBabelLanguage->lineEdit()->text()); configGroup.writeEntry(FileExporterToolchain::keyBibliographyStyle, comboBoxBibliographyStyle->lineEdit()->text()); config->sync(); } void resetToDefaults() { int row = qMax(0, GUIHelper::selectValue(comboBoxPaperSize->model(), static_cast(Preferences::defaultPageSize), Qt::UserRole)); comboBoxPaperSize->setCurrentIndex(row); row = GUIHelper::selectValue(comboBoxBabelLanguage->model(), FileExporterToolchain::defaultBabelLanguage); comboBoxBabelLanguage->setCurrentIndex(row); row = GUIHelper::selectValue(comboBoxBibliographyStyle->model(), FileExporterToolchain::defaultBibliographyStyle); comboBoxBibliographyStyle->setCurrentIndex(row); } void setupGUI() { QFormLayout *layout = new QFormLayout(p); comboBoxPaperSize = new KComboBox(false, p); comboBoxPaperSize->setObjectName(QStringLiteral("comboBoxPaperSize")); layout->addRow(i18n("Paper Size:"), comboBoxPaperSize); for (const auto &dbItem : Preferences::availablePageSizes) - comboBoxPaperSize->addItem(dbItem.localizedName, dbItem.internalPageSizeId); + comboBoxPaperSize->addItem(QPageSize::name(dbItem.internalPageSizeId), dbItem.internalPageSizeId); connect(comboBoxPaperSize, static_cast(&QComboBox::currentIndexChanged), p, &SettingsAbstractWidget::changed); comboBoxBabelLanguage = new KComboBox(true, p); comboBoxBabelLanguage->setObjectName(QStringLiteral("comboBoxBabelLanguage")); layout->addRow(i18n("Language for 'babel':"), comboBoxBabelLanguage); comboBoxBabelLanguage->addItem(QStringLiteral("english")); comboBoxBabelLanguage->addItem(QStringLiteral("ngerman")); comboBoxBabelLanguage->addItem(QStringLiteral("swedish")); connect(comboBoxBabelLanguage->lineEdit(), &QLineEdit::textChanged, p, &SettingsFileExporterPDFPSWidget::changed); comboBoxBibliographyStyle = new KComboBox(true, p); comboBoxBibliographyStyle->setObjectName(QStringLiteral("comboBoxBibliographyStyle")); layout->addRow(i18n("Bibliography style:"), comboBoxBibliographyStyle); static const QStringList styles {QString(QStringLiteral("abbrv")), QString(QStringLiteral("alpha")), QString(QStringLiteral("plain")), QString(QStringLiteral("agsm")), QString(QStringLiteral("dcu")), QString(QStringLiteral("jmr")), QString(QStringLiteral("jphysicsB")), QString(QStringLiteral("kluwer")), QString(QStringLiteral("nederlands"))}; for (const QString &style : styles) { comboBoxBibliographyStyle->addItem(style); } connect(comboBoxBibliographyStyle->lineEdit(), &QLineEdit::textChanged, p, &SettingsFileExporterPDFPSWidget::changed); } }; SettingsFileExporterPDFPSWidget::SettingsFileExporterPDFPSWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new SettingsFileExporterPDFPSWidgetPrivate(this)) { d->loadState(); } SettingsFileExporterPDFPSWidget::~SettingsFileExporterPDFPSWidget() { delete d; } QString SettingsFileExporterPDFPSWidget::label() const { return i18n("PDF & Postscript"); } QIcon SettingsFileExporterPDFPSWidget::icon() const { return QIcon::fromTheme(QStringLiteral("application-pdf")); } void SettingsFileExporterPDFPSWidget::loadState() { d->loadState(); } void SettingsFileExporterPDFPSWidget::saveState() { d->saveState(); } void SettingsFileExporterPDFPSWidget::resetToDefaults() { d->resetToDefaults(); }