File indexing completed on 2024-05-19 05:05:19
0001 /*************************************************************************** 0002 * SPDX-License-Identifier: GPL-2.0-or-later 0003 * * 0004 * SPDX-FileCopyrightText: 2004-2023 Thomas Fischer <fischer@unix-ag.uni-kl.de> 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, see <https://www.gnu.org/licenses/>. * 0018 ***************************************************************************/ 0019 0020 /// This file has been automatically generated using the script 'preferences-generator.py' 0021 /// based on configuration data from file 'preferences.json'. If there are any problems or 0022 /// bugs, you need to fix those two files and re-generated both 'preferences.h' and 0023 /// 'preferences.cpp'. Manual changes in this file will be overwritten the next time the 0024 /// script will be run. You have been warned. 0025 0026 #include <Preferences> 0027 0028 #include <set> 0029 0030 #include <QCoreApplication> 0031 #ifdef HAVE_KFI18N 0032 #include <KLocalizedString> 0033 #else // HAVE_KFI18N 0034 #define i18n(text) QStringLiteral(text) 0035 #define i18nc(comment,text) QStringLiteral(text) 0036 #endif // HAVE_KFI18N 0037 #ifdef HAVE_KF 0038 #include <KSharedConfig> 0039 #include <KConfigWatcher> 0040 #include <KConfigGroup> 0041 #endif // HAVE_KF 0042 0043 #ifdef HAVE_KF 0044 #include <NotificationHub> 0045 #endif // HAVE_KF 0046 0047 #include <QVector> 0048 #include <QDir> 0049 0050 class Preferences::Private 0051 { 0052 public: 0053 #ifdef HAVE_KF 0054 KSharedConfigPtr config; 0055 KConfigWatcher::Ptr watcher; 0056 0057 bool dirtyFlagBibliographySystem; 0058 Preferences::BibliographySystem cachedBibliographySystem; 0059 bool dirtyFlagPersonNameFormat; 0060 QString cachedPersonNameFormat; 0061 bool dirtyFlagCopyReferenceCommand; 0062 QString cachedCopyReferenceCommand; 0063 bool dirtyFlagPageSize; 0064 Preferences::PageSize cachedPageSize; 0065 bool dirtyFlagBackupScope; 0066 Preferences::BackupScope cachedBackupScope; 0067 bool dirtyFlagNumberOfBackups; 0068 int cachedNumberOfBackups; 0069 bool dirtyFlagIdSuggestionFormatStrings; 0070 QStringList cachedIdSuggestionFormatStrings; 0071 bool dirtyFlagActiveIdSuggestionFormatString; 0072 QString cachedActiveIdSuggestionFormatString; 0073 bool dirtyFlagLyXUseAutomaticPipeDetection; 0074 bool cachedLyXUseAutomaticPipeDetection; 0075 bool dirtyFlagLyXPipePath; 0076 QString cachedLyXPipePath; 0077 bool dirtyFlagBibTeXEncoding; 0078 QString cachedBibTeXEncoding; 0079 bool dirtyFlagBibTeXStringDelimiter; 0080 QString cachedBibTeXStringDelimiter; 0081 bool dirtyFlagBibTeXCommentContext; 0082 Preferences::CommentContext cachedBibTeXCommentContext; 0083 bool dirtyFlagBibTeXCommentPrefix; 0084 QString cachedBibTeXCommentPrefix; 0085 bool dirtyFlagBibTeXKeywordCasing; 0086 KBibTeX::Casing cachedBibTeXKeywordCasing; 0087 bool dirtyFlagBibTeXProtectCasing; 0088 bool cachedBibTeXProtectCasing; 0089 bool dirtyFlagBibTeXListSeparator; 0090 QString cachedBibTeXListSeparator; 0091 bool dirtyFlagbibTeXEntriesSortedByIdentifier; 0092 bool cachedbibTeXEntriesSortedByIdentifier; 0093 bool dirtyFlagLaTeXBabelLanguage; 0094 QString cachedLaTeXBabelLanguage; 0095 bool dirtyFlagBibTeXBibliographyStyle; 0096 QString cachedBibTeXBibliographyStyle; 0097 bool dirtyFlagFileViewDoubleClickAction; 0098 Preferences::FileViewDoubleClickAction cachedFileViewDoubleClickAction; 0099 bool dirtyFlagColorCodes; 0100 QVector<QPair<QString, QString>> cachedColorCodes; 0101 #endif // HAVE_KF 0102 0103 Private(Preferences *) 0104 { 0105 #ifdef HAVE_KF 0106 config = KSharedConfig::openConfig(QStringLiteral("kbibtexrc")); 0107 watcher = KConfigWatcher::create(config); 0108 dirtyFlagBibliographySystem = true; 0109 cachedBibliographySystem = Preferences::defaultBibliographySystem; 0110 dirtyFlagPersonNameFormat = true; 0111 cachedPersonNameFormat = Preferences::defaultPersonNameFormat; 0112 dirtyFlagCopyReferenceCommand = true; 0113 cachedCopyReferenceCommand = Preferences::defaultCopyReferenceCommand; 0114 dirtyFlagPageSize = true; 0115 cachedPageSize = Preferences::defaultPageSize; 0116 dirtyFlagBackupScope = true; 0117 cachedBackupScope = Preferences::defaultBackupScope; 0118 dirtyFlagNumberOfBackups = true; 0119 cachedNumberOfBackups = Preferences::defaultNumberOfBackups; 0120 dirtyFlagIdSuggestionFormatStrings = true; 0121 cachedIdSuggestionFormatStrings = Preferences::defaultIdSuggestionFormatStrings; 0122 dirtyFlagActiveIdSuggestionFormatString = true; 0123 cachedActiveIdSuggestionFormatString = Preferences::defaultActiveIdSuggestionFormatString; 0124 dirtyFlagLyXUseAutomaticPipeDetection = true; 0125 cachedLyXUseAutomaticPipeDetection = Preferences::defaultLyXUseAutomaticPipeDetection; 0126 dirtyFlagLyXPipePath = true; 0127 cachedLyXPipePath = Preferences::defaultLyXPipePath; 0128 dirtyFlagBibTeXEncoding = true; 0129 cachedBibTeXEncoding = Preferences::defaultBibTeXEncoding; 0130 dirtyFlagBibTeXStringDelimiter = true; 0131 cachedBibTeXStringDelimiter = Preferences::defaultBibTeXStringDelimiter; 0132 dirtyFlagBibTeXCommentContext = true; 0133 cachedBibTeXCommentContext = Preferences::defaultBibTeXCommentContext; 0134 dirtyFlagBibTeXCommentPrefix = true; 0135 cachedBibTeXCommentPrefix = Preferences::defaultBibTeXCommentPrefix; 0136 dirtyFlagBibTeXKeywordCasing = true; 0137 cachedBibTeXKeywordCasing = Preferences::defaultBibTeXKeywordCasing; 0138 dirtyFlagBibTeXProtectCasing = true; 0139 cachedBibTeXProtectCasing = Preferences::defaultBibTeXProtectCasing; 0140 dirtyFlagBibTeXListSeparator = true; 0141 cachedBibTeXListSeparator = Preferences::defaultBibTeXListSeparator; 0142 dirtyFlagbibTeXEntriesSortedByIdentifier = true; 0143 cachedbibTeXEntriesSortedByIdentifier = Preferences::defaultbibTeXEntriesSortedByIdentifier; 0144 dirtyFlagLaTeXBabelLanguage = true; 0145 cachedLaTeXBabelLanguage = Preferences::defaultLaTeXBabelLanguage; 0146 dirtyFlagBibTeXBibliographyStyle = true; 0147 cachedBibTeXBibliographyStyle = Preferences::defaultBibTeXBibliographyStyle; 0148 dirtyFlagFileViewDoubleClickAction = true; 0149 cachedFileViewDoubleClickAction = Preferences::defaultFileViewDoubleClickAction; 0150 dirtyFlagColorCodes = true; 0151 cachedColorCodes = Preferences::defaultColorCodes; 0152 #endif // HAVE_KF 0153 } 0154 0155 #ifdef HAVE_KF 0156 inline bool validateValueForBibliographySystem(const Preferences::BibliographySystem valueToBeChecked) { 0157 for (QVector<QPair<Preferences::BibliographySystem, QString>>::ConstIterator it = Preferences::availableBibliographySystems.constBegin(); it != Preferences::availableBibliographySystems.constEnd(); ++it) 0158 if (it->first == valueToBeChecked) return true; 0159 return false; 0160 } 0161 0162 inline bool validateValueForPersonNameFormat(const QString &valueToBeChecked) { 0163 return valueToBeChecked.contains(QStringLiteral("%f")) && valueToBeChecked.contains(QStringLiteral("%l")) && valueToBeChecked.contains(QStringLiteral("%s")); 0164 } 0165 0166 inline bool validateValueForCopyReferenceCommand(const QString &valueToBeChecked) { 0167 return valueToBeChecked.isEmpty() || Preferences::availableCopyReferenceCommands.contains(valueToBeChecked); 0168 } 0169 0170 inline bool validateValueForPageSize(const Preferences::PageSize valueToBeChecked) { 0171 for (QVector<QPair<Preferences::PageSize, QString>>::ConstIterator it = Preferences::availablePageSizes.constBegin(); it != Preferences::availablePageSizes.constEnd(); ++it) 0172 if (it->first == valueToBeChecked) return true; 0173 return false; 0174 } 0175 0176 inline bool validateValueForBackupScope(const Preferences::BackupScope valueToBeChecked) { 0177 for (QVector<QPair<Preferences::BackupScope, QString>>::ConstIterator it = Preferences::availableBackupScopes.constBegin(); it != Preferences::availableBackupScopes.constEnd(); ++it) 0178 if (it->first == valueToBeChecked) return true; 0179 return false; 0180 } 0181 0182 inline bool validateValueForNumberOfBackups(const int valueToBeChecked) { 0183 return valueToBeChecked >= 0; 0184 } 0185 0186 inline bool validateValueForIdSuggestionFormatStrings(const QStringList &valueToBeChecked) { 0187 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'))); 0188 } 0189 0190 inline bool validateValueForActiveIdSuggestionFormatString(const QString &valueToBeChecked) { 0191 Q_UNUSED(valueToBeChecked) 0192 return true; 0193 } 0194 0195 inline bool validateValueForLyXUseAutomaticPipeDetection(const bool valueToBeChecked) { 0196 Q_UNUSED(valueToBeChecked) 0197 return true; 0198 } 0199 0200 inline bool validateValueForLyXPipePath(const QString &valueToBeChecked) { 0201 return valueToBeChecked.startsWith(QLatin1Char('/')); 0202 } 0203 0204 inline bool validateValueForBibTeXEncoding(const QString &valueToBeChecked) { 0205 return Preferences::availableBibTeXEncodings.contains(valueToBeChecked); 0206 } 0207 0208 inline bool validateValueForBibTeXStringDelimiter(const QString &valueToBeChecked) { 0209 return Preferences::availableBibTeXStringDelimiters.contains(valueToBeChecked); 0210 } 0211 0212 inline bool validateValueForBibTeXCommentContext(const Preferences::CommentContext valueToBeChecked) { 0213 for (QVector<QPair<Preferences::CommentContext, QString>>::ConstIterator it = Preferences::availableBibTeXCommentContexts.constBegin(); it != Preferences::availableBibTeXCommentContexts.constEnd(); ++it) 0214 if (it->first == valueToBeChecked) return true; 0215 return false; 0216 } 0217 0218 inline bool validateValueForBibTeXCommentPrefix(const QString &valueToBeChecked) { 0219 return valueToBeChecked.isEmpty() || valueToBeChecked.startsWith(QStringLiteral("%")); 0220 } 0221 0222 inline bool validateValueForBibTeXKeywordCasing(const KBibTeX::Casing valueToBeChecked) { 0223 for (QVector<QPair<KBibTeX::Casing, QString>>::ConstIterator it = Preferences::availableBibTeXKeywordCasings.constBegin(); it != Preferences::availableBibTeXKeywordCasings.constEnd(); ++it) 0224 if (it->first == valueToBeChecked) return true; 0225 return false; 0226 } 0227 0228 inline bool validateValueForBibTeXProtectCasing(const bool valueToBeChecked) { 0229 Q_UNUSED(valueToBeChecked) 0230 return true; 0231 } 0232 0233 inline bool validateValueForBibTeXListSeparator(const QString &valueToBeChecked) { 0234 return Preferences::availableBibTeXListSeparators.contains(valueToBeChecked); 0235 } 0236 0237 inline bool validateValueForbibTeXEntriesSortedByIdentifier(const bool valueToBeChecked) { 0238 Q_UNUSED(valueToBeChecked) 0239 return true; 0240 } 0241 0242 inline bool validateValueForLaTeXBabelLanguage(const QString &valueToBeChecked) { 0243 return !valueToBeChecked.isEmpty(); 0244 } 0245 0246 inline bool validateValueForBibTeXBibliographyStyle(const QString &valueToBeChecked) { 0247 return !valueToBeChecked.isEmpty(); 0248 } 0249 0250 inline bool validateValueForFileViewDoubleClickAction(const Preferences::FileViewDoubleClickAction valueToBeChecked) { 0251 for (QVector<QPair<Preferences::FileViewDoubleClickAction, QString>>::ConstIterator it = Preferences::availableFileViewDoubleClickActions.constBegin(); it != Preferences::availableFileViewDoubleClickActions.constEnd(); ++it) 0252 if (it->first == valueToBeChecked) return true; 0253 return false; 0254 } 0255 0256 inline bool validateValueForColorCodes(const QVector<QPair<QString, QString>> &valueToBeChecked) { 0257 static const QString white{QStringLiteral("#ffffff")}, black{QStringLiteral("#000000")}; 0258 for (QVector<QPair<QString, QString>>::ConstIterator it = valueToBeChecked.constBegin(); it != valueToBeChecked.constEnd(); ++it) 0259 if (it->first.isEmpty() || it->second.isEmpty() || it->first == white || it->first == black) 0260 return false; 0261 return true; 0262 } 0263 0264 QVector<QPair<QString, QString>> readEntryColorCodes(const KConfigGroup &configGroup, const QString &key) const 0265 { 0266 const QString rawEntry = configGroup.readEntry(key, QString()); 0267 if (rawEntry.isEmpty()) return Preferences::defaultColorCodes; 0268 #if QT_VERSION >= 0x050e00 0269 const QStringList pairs = rawEntry.split(QStringLiteral("\0\0"), Qt::SkipEmptyParts); 0270 #else // QT_VERSION < 0x050e00 0271 const QStringList pairs = rawEntry.split(QStringLiteral("\0\0"), QString::SkipEmptyParts); 0272 #endif // QT_VERSION >= 0x050e00 0273 if (pairs.isEmpty()) return Preferences::defaultColorCodes; 0274 QVector<QPair<QString, QString>> result; 0275 for (const QString &pair : pairs) { 0276 #if QT_VERSION >= 0x050e00 0277 const QStringList colorLabelPair = pair.split(QStringLiteral("\0"), Qt::SkipEmptyParts); 0278 #else // QT_VERSION < 0x050e00 0279 const QStringList colorLabelPair = pair.split(QStringLiteral("\0"), QString::SkipEmptyParts); 0280 #endif // QT_VERSION >= 0x050e00 0281 if (colorLabelPair.length() != 2) return Preferences::defaultColorCodes; 0282 result.append(qMakePair(colorLabelPair[0], colorLabelPair[1])); 0283 } 0284 return result; 0285 } 0286 0287 void writeEntryColorCodes(KConfigGroup &configGroup, const QString &key, const QVector<QPair<QString, QString>> &valueToBeWritten) 0288 { 0289 QString rawEntry; 0290 for (QVector<QPair<QString, QString>>::ConstIterator it = valueToBeWritten.constBegin(); it != valueToBeWritten.constEnd(); ++it) { 0291 if (!rawEntry.isEmpty()) rawEntry.append(QStringLiteral("\0\0")); 0292 rawEntry = rawEntry.append(it->first).append(QStringLiteral("\0")).append(it->second); 0293 } 0294 configGroup.writeEntry(key, rawEntry, KConfig::Notify); 0295 } 0296 #endif // HAVE_KF 0297 }; 0298 0299 Preferences &Preferences::instance() 0300 { 0301 static Preferences singleton; 0302 return singleton; 0303 } 0304 0305 Preferences::Preferences() 0306 : d(new Preferences::Private(this)) 0307 { 0308 #ifdef HAVE_KF 0309 QObject::connect(d->watcher.data(), &KConfigWatcher::configChanged, QCoreApplication::instance(), [this](const KConfigGroup &group, const QByteArrayList &names) { 0310 std::set<int> eventsToPublish; 0311 if (group.name() == QStringLiteral("General") && names.contains("BibliographySystem")) { 0312 /// Configuration setting BibliographySystem got changed by another Preferences instance"; 0313 d->dirtyFlagBibliographySystem = true; 0314 eventsToPublish.insert(NotificationHub::EventBibliographySystemChanged); 0315 } 0316 if (group.name() == QStringLiteral("General") && names.contains("PersonNameFormat")) { 0317 /// Configuration setting PersonNameFormat got changed by another Preferences instance"; 0318 d->dirtyFlagPersonNameFormat = true; 0319 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0320 } 0321 if (group.name() == QStringLiteral("LaTeX") && names.contains("CopyReferenceCommand")) { 0322 /// Configuration setting CopyReferenceCommand got changed by another Preferences instance"; 0323 d->dirtyFlagCopyReferenceCommand = true; 0324 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0325 } 0326 if (group.name() == QStringLiteral("General") && names.contains("PageSize")) { 0327 /// Configuration setting PageSize got changed by another Preferences instance"; 0328 d->dirtyFlagPageSize = true; 0329 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0330 } 0331 if (group.name() == QStringLiteral("InputOutput") && names.contains("BackupScope")) { 0332 /// Configuration setting BackupScope got changed by another Preferences instance"; 0333 d->dirtyFlagBackupScope = true; 0334 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0335 } 0336 if (group.name() == QStringLiteral("InputOutput") && names.contains("NumberOfBackups")) { 0337 /// Configuration setting NumberOfBackups got changed by another Preferences instance"; 0338 d->dirtyFlagNumberOfBackups = true; 0339 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0340 } 0341 if (group.name() == QStringLiteral("IdSuggestions") && names.contains("IdSuggestionFormatStrings")) { 0342 /// Configuration setting IdSuggestionFormatStrings got changed by another Preferences instance"; 0343 d->dirtyFlagIdSuggestionFormatStrings = true; 0344 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0345 } 0346 if (group.name() == QStringLiteral("IdSuggestions") && names.contains("ActiveIdSuggestionFormatString")) { 0347 /// Configuration setting ActiveIdSuggestionFormatString got changed by another Preferences instance"; 0348 d->dirtyFlagActiveIdSuggestionFormatString = true; 0349 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0350 } 0351 if (group.name() == QStringLiteral("LyX") && names.contains("LyXUseAutomaticPipeDetection")) { 0352 /// Configuration setting LyXUseAutomaticPipeDetection got changed by another Preferences instance"; 0353 d->dirtyFlagLyXUseAutomaticPipeDetection = true; 0354 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0355 } 0356 if (group.name() == QStringLiteral("LyX") && names.contains("LyXPipePath")) { 0357 /// Configuration setting LyXPipePath got changed by another Preferences instance"; 0358 d->dirtyFlagLyXPipePath = true; 0359 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0360 } 0361 if (group.name() == QStringLiteral("FileExporterBibTeX") && names.contains("BibTeXEncoding")) { 0362 /// Configuration setting BibTeXEncoding got changed by another Preferences instance"; 0363 d->dirtyFlagBibTeXEncoding = true; 0364 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0365 } 0366 if (group.name() == QStringLiteral("FileExporterBibTeX") && names.contains("BibTeXStringDelimiter")) { 0367 /// Configuration setting BibTeXStringDelimiter got changed by another Preferences instance"; 0368 d->dirtyFlagBibTeXStringDelimiter = true; 0369 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0370 } 0371 if (group.name() == QStringLiteral("FileExporterBibTeX") && names.contains("BibTeXCommentContext")) { 0372 /// Configuration setting BibTeXCommentContext got changed by another Preferences instance"; 0373 d->dirtyFlagBibTeXCommentContext = true; 0374 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0375 } 0376 if (group.name() == QStringLiteral("FileExporterBibTeX") && names.contains("BibTeXCommentPrefix")) { 0377 /// Configuration setting BibTeXCommentPrefix got changed by another Preferences instance"; 0378 d->dirtyFlagBibTeXCommentPrefix = true; 0379 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0380 } 0381 if (group.name() == QStringLiteral("FileExporterBibTeX") && names.contains("BibTeXKeywordCasing")) { 0382 /// Configuration setting BibTeXKeywordCasing got changed by another Preferences instance"; 0383 d->dirtyFlagBibTeXKeywordCasing = true; 0384 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0385 } 0386 if (group.name() == QStringLiteral("FileExporterBibTeX") && names.contains("BibTeXProtectCasing")) { 0387 /// Configuration setting BibTeXProtectCasing got changed by another Preferences instance"; 0388 d->dirtyFlagBibTeXProtectCasing = true; 0389 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0390 } 0391 if (group.name() == QStringLiteral("FileExporterBibTeX") && names.contains("BibTeXListSeparator")) { 0392 /// Configuration setting BibTeXListSeparator got changed by another Preferences instance"; 0393 d->dirtyFlagBibTeXListSeparator = true; 0394 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0395 } 0396 if (group.name() == QStringLiteral("FileExporterBibTeX") && names.contains("bibTeXEntriesSortedByIdentifier")) { 0397 /// Configuration setting bibTeXEntriesSortedByIdentifier got changed by another Preferences instance"; 0398 d->dirtyFlagbibTeXEntriesSortedByIdentifier = true; 0399 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0400 } 0401 if (group.name() == QStringLiteral("FileExporterLaTeXbased") && names.contains("LaTeXBabelLanguage")) { 0402 /// Configuration setting LaTeXBabelLanguage got changed by another Preferences instance"; 0403 d->dirtyFlagLaTeXBabelLanguage = true; 0404 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0405 } 0406 if (group.name() == QStringLiteral("FileExporterLaTeXbased") && names.contains("BibTeXBibliographyStyle")) { 0407 /// Configuration setting BibTeXBibliographyStyle got changed by another Preferences instance"; 0408 d->dirtyFlagBibTeXBibliographyStyle = true; 0409 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0410 } 0411 if (group.name() == QStringLiteral("User Interface") && names.contains("FileViewDoubleClickAction")) { 0412 /// Configuration setting FileViewDoubleClickAction got changed by another Preferences instance"; 0413 d->dirtyFlagFileViewDoubleClickAction = true; 0414 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0415 } 0416 if (group.name() == QStringLiteral("Color Labels") && names.contains("ColorCodes")) { 0417 /// Configuration setting ColorCodes got changed by another Preferences instance"; 0418 d->dirtyFlagColorCodes = true; 0419 eventsToPublish.insert(NotificationHub::EventConfigurationChanged); 0420 } 0421 0422 for (const int eventId : eventsToPublish) 0423 NotificationHub::publishEvent(eventId); 0424 }); 0425 #endif // HAVE_KF 0426 } 0427 0428 Preferences::~Preferences() 0429 { 0430 delete d; 0431 } 0432 0433 const QVector<QPair<Preferences::BibliographySystem, QString>> Preferences::availableBibliographySystems {{Preferences::BibliographySystem::BibTeX, i18n("BibTeX")}, {Preferences::BibliographySystem::BibLaTeX, i18n("BibLaTeX")}}; 0434 const Preferences::BibliographySystem Preferences::defaultBibliographySystem = Preferences::availableBibliographySystems.front().first; 0435 0436 Preferences::BibliographySystem Preferences::bibliographySystem() 0437 { 0438 #ifdef HAVE_KF 0439 if (d->dirtyFlagBibliographySystem) { 0440 d->config->reparseConfiguration(); 0441 static const KConfigGroup configGroup(d->config, QStringLiteral("General")); 0442 const Preferences::BibliographySystem valueFromConfig = static_cast<Preferences::BibliographySystem>(configGroup.readEntry(QStringLiteral("BibliographySystem"), static_cast<int>(Preferences::defaultBibliographySystem))); 0443 if (d->validateValueForBibliographySystem(valueFromConfig)) { 0444 d->cachedBibliographySystem = valueFromConfig; 0445 d->dirtyFlagBibliographySystem = false; 0446 } else { 0447 /// Configuration file setting for BibliographySystem has an invalid value, using default as fallback 0448 setBibliographySystem(Preferences::defaultBibliographySystem); 0449 } 0450 } 0451 return d->cachedBibliographySystem; 0452 #else // HAVE_KF 0453 return defaultBibliographySystem; 0454 #endif // HAVE_KF 0455 } 0456 0457 #ifdef HAVE_KF 0458 bool Preferences::setBibliographySystem(const Preferences::BibliographySystem newValue) 0459 { 0460 if (!d->validateValueForBibliographySystem(newValue)) return false; 0461 d->dirtyFlagBibliographySystem = false; 0462 d->cachedBibliographySystem = newValue; 0463 static KConfigGroup configGroup(d->config, QStringLiteral("General")); 0464 const Preferences::BibliographySystem valueFromConfig = static_cast<Preferences::BibliographySystem>(configGroup.readEntry(QStringLiteral("BibliographySystem"), static_cast<int>(Preferences::defaultBibliographySystem))); 0465 if (valueFromConfig == newValue) return false; 0466 configGroup.writeEntry(QStringLiteral("BibliographySystem"), static_cast<int>(newValue), KConfig::Notify); 0467 d->config->sync(); 0468 return true; 0469 } 0470 #endif // HAVE_KF 0471 0472 const QString Preferences::personNameFormatLastFirst = QStringLiteral("<%l><, %s><, %f>"); 0473 const QString Preferences::personNameFormatFirstLast = QStringLiteral("<%f ><%l>< %s>"); 0474 const QString Preferences::defaultPersonNameFormat = Preferences::personNameFormatLastFirst; 0475 0476 const QString &Preferences::personNameFormat() 0477 { 0478 #ifdef HAVE_KF 0479 if (d->dirtyFlagPersonNameFormat) { 0480 d->config->reparseConfiguration(); 0481 static const KConfigGroup configGroup(d->config, QStringLiteral("General")); 0482 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("PersonNameFormat"), Preferences::defaultPersonNameFormat); 0483 if (d->validateValueForPersonNameFormat(valueFromConfig)) { 0484 d->cachedPersonNameFormat = valueFromConfig; 0485 d->dirtyFlagPersonNameFormat = false; 0486 } else { 0487 /// Configuration file setting for PersonNameFormat has an invalid value, using default as fallback 0488 setPersonNameFormat(Preferences::defaultPersonNameFormat); 0489 } 0490 } 0491 return d->cachedPersonNameFormat; 0492 #else // HAVE_KF 0493 return defaultPersonNameFormat; 0494 #endif // HAVE_KF 0495 } 0496 0497 #ifdef HAVE_KF 0498 bool Preferences::setPersonNameFormat(const QString &newValue) 0499 { 0500 if (!d->validateValueForPersonNameFormat(newValue)) return false; 0501 d->dirtyFlagPersonNameFormat = false; 0502 d->cachedPersonNameFormat = newValue; 0503 static KConfigGroup configGroup(d->config, QStringLiteral("General")); 0504 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("PersonNameFormat"), Preferences::defaultPersonNameFormat); 0505 if (valueFromConfig == newValue) return false; 0506 configGroup.writeEntry(QStringLiteral("PersonNameFormat"), newValue, KConfig::Notify); 0507 d->config->sync(); 0508 return true; 0509 } 0510 #endif // HAVE_KF 0511 0512 const QStringList Preferences::availableCopyReferenceCommands {QStringLiteral("cite"), QStringLiteral("citealt"), QStringLiteral("citeauthor"), QStringLiteral("citeauthor*"), QStringLiteral("citeyear"), QStringLiteral("citeyearpar"), QStringLiteral("shortcite"), QStringLiteral("citet"), QStringLiteral("citet*"), QStringLiteral("citep"), QStringLiteral("citep*")}; 0513 const QString Preferences::defaultCopyReferenceCommand = Preferences::availableCopyReferenceCommands.front(); 0514 0515 const QString &Preferences::copyReferenceCommand() 0516 { 0517 #ifdef HAVE_KF 0518 if (d->dirtyFlagCopyReferenceCommand) { 0519 d->config->reparseConfiguration(); 0520 static const KConfigGroup configGroup(d->config, QStringLiteral("LaTeX")); 0521 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("CopyReferenceCommand"), Preferences::defaultCopyReferenceCommand); 0522 if (d->validateValueForCopyReferenceCommand(valueFromConfig)) { 0523 d->cachedCopyReferenceCommand = valueFromConfig; 0524 d->dirtyFlagCopyReferenceCommand = false; 0525 } else { 0526 /// Configuration file setting for CopyReferenceCommand has an invalid value, using default as fallback 0527 setCopyReferenceCommand(Preferences::defaultCopyReferenceCommand); 0528 } 0529 } 0530 return d->cachedCopyReferenceCommand; 0531 #else // HAVE_KF 0532 return defaultCopyReferenceCommand; 0533 #endif // HAVE_KF 0534 } 0535 0536 #ifdef HAVE_KF 0537 bool Preferences::setCopyReferenceCommand(const QString &newValue) 0538 { 0539 QString sanitizedNewValue = newValue; 0540 const QString lowerSanitizedNewValue = sanitizedNewValue.toLower(); 0541 for (const QString &knownCopyReferenceCommand : availableCopyReferenceCommands) 0542 if (knownCopyReferenceCommand.toLower() == lowerSanitizedNewValue) { 0543 sanitizedNewValue = knownCopyReferenceCommand; 0544 break; 0545 } 0546 if (!d->validateValueForCopyReferenceCommand(sanitizedNewValue)) return false; 0547 d->dirtyFlagCopyReferenceCommand = false; 0548 d->cachedCopyReferenceCommand = sanitizedNewValue; 0549 static KConfigGroup configGroup(d->config, QStringLiteral("LaTeX")); 0550 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("CopyReferenceCommand"), Preferences::defaultCopyReferenceCommand); 0551 if (valueFromConfig == sanitizedNewValue) return false; 0552 configGroup.writeEntry(QStringLiteral("CopyReferenceCommand"), sanitizedNewValue, KConfig::Notify); 0553 d->config->sync(); 0554 return true; 0555 } 0556 #endif // HAVE_KF 0557 0558 const QVector<QPair<Preferences::PageSize, QString>> Preferences::availablePageSizes {{Preferences::PageSize::A4, QStringLiteral("a4paper")}, {Preferences::PageSize::Letter, QStringLiteral("letter")}, {Preferences::PageSize::Legal, QStringLiteral("legal")}}; 0559 const Preferences::PageSize Preferences::defaultPageSize = Preferences::availablePageSizes.front().first; 0560 0561 Preferences::PageSize Preferences::pageSize() 0562 { 0563 #ifdef HAVE_KF 0564 if (d->dirtyFlagPageSize) { 0565 d->config->reparseConfiguration(); 0566 static const KConfigGroup configGroup(d->config, QStringLiteral("General")); 0567 const Preferences::PageSize valueFromConfig = static_cast<Preferences::PageSize>(configGroup.readEntry(QStringLiteral("PageSize"), static_cast<int>(Preferences::defaultPageSize))); 0568 if (d->validateValueForPageSize(valueFromConfig)) { 0569 d->cachedPageSize = valueFromConfig; 0570 d->dirtyFlagPageSize = false; 0571 } else { 0572 /// Configuration file setting for PageSize has an invalid value, using default as fallback 0573 setPageSize(Preferences::defaultPageSize); 0574 } 0575 } 0576 return d->cachedPageSize; 0577 #else // HAVE_KF 0578 return defaultPageSize; 0579 #endif // HAVE_KF 0580 } 0581 0582 #ifdef HAVE_KF 0583 bool Preferences::setPageSize(const Preferences::PageSize newValue) 0584 { 0585 if (!d->validateValueForPageSize(newValue)) return false; 0586 d->dirtyFlagPageSize = false; 0587 d->cachedPageSize = newValue; 0588 static KConfigGroup configGroup(d->config, QStringLiteral("General")); 0589 const Preferences::PageSize valueFromConfig = static_cast<Preferences::PageSize>(configGroup.readEntry(QStringLiteral("PageSize"), static_cast<int>(Preferences::defaultPageSize))); 0590 if (valueFromConfig == newValue) return false; 0591 configGroup.writeEntry(QStringLiteral("PageSize"), static_cast<int>(newValue), KConfig::Notify); 0592 d->config->sync(); 0593 return true; 0594 } 0595 #endif // HAVE_KF 0596 0597 const QVector<QPair<Preferences::BackupScope, QString>> Preferences::availableBackupScopes {{Preferences::BackupScope::None, i18n("No backups")}, {Preferences::BackupScope::LocalOnly, i18n("Local files only")}, {Preferences::BackupScope::BothLocalAndRemote, i18n("Both local and remote files")}}; 0598 const Preferences::BackupScope Preferences::defaultBackupScope = Preferences::availableBackupScopes.front().first; 0599 0600 Preferences::BackupScope Preferences::backupScope() 0601 { 0602 #ifdef HAVE_KF 0603 if (d->dirtyFlagBackupScope) { 0604 d->config->reparseConfiguration(); 0605 static const KConfigGroup configGroup(d->config, QStringLiteral("InputOutput")); 0606 const Preferences::BackupScope valueFromConfig = static_cast<Preferences::BackupScope>(configGroup.readEntry(QStringLiteral("BackupScope"), static_cast<int>(Preferences::defaultBackupScope))); 0607 if (d->validateValueForBackupScope(valueFromConfig)) { 0608 d->cachedBackupScope = valueFromConfig; 0609 d->dirtyFlagBackupScope = false; 0610 } else { 0611 /// Configuration file setting for BackupScope has an invalid value, using default as fallback 0612 setBackupScope(Preferences::defaultBackupScope); 0613 } 0614 } 0615 return d->cachedBackupScope; 0616 #else // HAVE_KF 0617 return defaultBackupScope; 0618 #endif // HAVE_KF 0619 } 0620 0621 #ifdef HAVE_KF 0622 bool Preferences::setBackupScope(const Preferences::BackupScope newValue) 0623 { 0624 if (!d->validateValueForBackupScope(newValue)) return false; 0625 d->dirtyFlagBackupScope = false; 0626 d->cachedBackupScope = newValue; 0627 static KConfigGroup configGroup(d->config, QStringLiteral("InputOutput")); 0628 const Preferences::BackupScope valueFromConfig = static_cast<Preferences::BackupScope>(configGroup.readEntry(QStringLiteral("BackupScope"), static_cast<int>(Preferences::defaultBackupScope))); 0629 if (valueFromConfig == newValue) return false; 0630 configGroup.writeEntry(QStringLiteral("BackupScope"), static_cast<int>(newValue), KConfig::Notify); 0631 d->config->sync(); 0632 return true; 0633 } 0634 #endif // HAVE_KF 0635 0636 const int Preferences::defaultNumberOfBackups = 5; 0637 0638 int Preferences::numberOfBackups() 0639 { 0640 #ifdef HAVE_KF 0641 if (d->dirtyFlagNumberOfBackups) { 0642 d->config->reparseConfiguration(); 0643 static const KConfigGroup configGroup(d->config, QStringLiteral("InputOutput")); 0644 const int valueFromConfig = configGroup.readEntry(QStringLiteral("NumberOfBackups"), Preferences::defaultNumberOfBackups); 0645 if (d->validateValueForNumberOfBackups(valueFromConfig)) { 0646 d->cachedNumberOfBackups = valueFromConfig; 0647 d->dirtyFlagNumberOfBackups = false; 0648 } else { 0649 /// Configuration file setting for NumberOfBackups has an invalid value, using default as fallback 0650 setNumberOfBackups(Preferences::defaultNumberOfBackups); 0651 } 0652 } 0653 return d->cachedNumberOfBackups; 0654 #else // HAVE_KF 0655 return defaultNumberOfBackups; 0656 #endif // HAVE_KF 0657 } 0658 0659 #ifdef HAVE_KF 0660 bool Preferences::setNumberOfBackups(const int newValue) 0661 { 0662 if (!d->validateValueForNumberOfBackups(newValue)) return false; 0663 d->dirtyFlagNumberOfBackups = false; 0664 d->cachedNumberOfBackups = newValue; 0665 static KConfigGroup configGroup(d->config, QStringLiteral("InputOutput")); 0666 const int valueFromConfig = configGroup.readEntry(QStringLiteral("NumberOfBackups"), Preferences::defaultNumberOfBackups); 0667 if (valueFromConfig == newValue) return false; 0668 configGroup.writeEntry(QStringLiteral("NumberOfBackups"), newValue, KConfig::Notify); 0669 d->config->sync(); 0670 return true; 0671 } 0672 #endif // HAVE_KF 0673 0674 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")}; 0675 0676 const QStringList &Preferences::idSuggestionFormatStrings() 0677 { 0678 #ifdef HAVE_KF 0679 if (d->dirtyFlagIdSuggestionFormatStrings) { 0680 d->config->reparseConfiguration(); 0681 static const KConfigGroup configGroup(d->config, QStringLiteral("IdSuggestions")); 0682 const QStringList valueFromConfig = configGroup.readEntry(QStringLiteral("IdSuggestionFormatStrings"), Preferences::defaultIdSuggestionFormatStrings); 0683 if (d->validateValueForIdSuggestionFormatStrings(valueFromConfig)) { 0684 d->cachedIdSuggestionFormatStrings = valueFromConfig; 0685 d->dirtyFlagIdSuggestionFormatStrings = false; 0686 } else { 0687 /// Configuration file setting for IdSuggestionFormatStrings has an invalid value, using default as fallback 0688 setIdSuggestionFormatStrings(Preferences::defaultIdSuggestionFormatStrings); 0689 } 0690 } 0691 return d->cachedIdSuggestionFormatStrings; 0692 #else // HAVE_KF 0693 return defaultIdSuggestionFormatStrings; 0694 #endif // HAVE_KF 0695 } 0696 0697 #ifdef HAVE_KF 0698 bool Preferences::setIdSuggestionFormatStrings(const QStringList &newValue) 0699 { 0700 if (!d->validateValueForIdSuggestionFormatStrings(newValue)) return false; 0701 d->dirtyFlagIdSuggestionFormatStrings = false; 0702 d->cachedIdSuggestionFormatStrings = newValue; 0703 static KConfigGroup configGroup(d->config, QStringLiteral("IdSuggestions")); 0704 const QStringList valueFromConfig = configGroup.readEntry(QStringLiteral("IdSuggestionFormatStrings"), Preferences::defaultIdSuggestionFormatStrings); 0705 if (valueFromConfig == newValue) return false; 0706 configGroup.writeEntry(QStringLiteral("IdSuggestionFormatStrings"), newValue, KConfig::Notify); 0707 d->config->sync(); 0708 return true; 0709 } 0710 #endif // HAVE_KF 0711 0712 const QString Preferences::defaultActiveIdSuggestionFormatString {}; 0713 0714 const QString &Preferences::activeIdSuggestionFormatString() 0715 { 0716 #ifdef HAVE_KF 0717 if (d->dirtyFlagActiveIdSuggestionFormatString) { 0718 d->config->reparseConfiguration(); 0719 static const KConfigGroup configGroup(d->config, QStringLiteral("IdSuggestions")); 0720 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("ActiveIdSuggestionFormatString"), Preferences::defaultActiveIdSuggestionFormatString); 0721 if (d->validateValueForActiveIdSuggestionFormatString(valueFromConfig)) { 0722 d->cachedActiveIdSuggestionFormatString = valueFromConfig; 0723 d->dirtyFlagActiveIdSuggestionFormatString = false; 0724 } else { 0725 /// Configuration file setting for ActiveIdSuggestionFormatString has an invalid value, using default as fallback 0726 setActiveIdSuggestionFormatString(Preferences::defaultActiveIdSuggestionFormatString); 0727 } 0728 } 0729 return d->cachedActiveIdSuggestionFormatString; 0730 #else // HAVE_KF 0731 return defaultActiveIdSuggestionFormatString; 0732 #endif // HAVE_KF 0733 } 0734 0735 #ifdef HAVE_KF 0736 bool Preferences::setActiveIdSuggestionFormatString(const QString &newValue) 0737 { 0738 if (!d->validateValueForActiveIdSuggestionFormatString(newValue)) return false; 0739 d->dirtyFlagActiveIdSuggestionFormatString = false; 0740 d->cachedActiveIdSuggestionFormatString = newValue; 0741 static KConfigGroup configGroup(d->config, QStringLiteral("IdSuggestions")); 0742 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("ActiveIdSuggestionFormatString"), Preferences::defaultActiveIdSuggestionFormatString); 0743 if (valueFromConfig == newValue) return false; 0744 configGroup.writeEntry(QStringLiteral("ActiveIdSuggestionFormatString"), newValue, KConfig::Notify); 0745 d->config->sync(); 0746 return true; 0747 } 0748 #endif // HAVE_KF 0749 0750 const bool Preferences::defaultLyXUseAutomaticPipeDetection = true; 0751 0752 bool Preferences::lyXUseAutomaticPipeDetection() 0753 { 0754 #ifdef HAVE_KF 0755 if (d->dirtyFlagLyXUseAutomaticPipeDetection) { 0756 d->config->reparseConfiguration(); 0757 static const KConfigGroup configGroup(d->config, QStringLiteral("LyX")); 0758 const bool valueFromConfig = configGroup.readEntry(QStringLiteral("LyXUseAutomaticPipeDetection"), Preferences::defaultLyXUseAutomaticPipeDetection); 0759 if (d->validateValueForLyXUseAutomaticPipeDetection(valueFromConfig)) { 0760 d->cachedLyXUseAutomaticPipeDetection = valueFromConfig; 0761 d->dirtyFlagLyXUseAutomaticPipeDetection = false; 0762 } else { 0763 /// Configuration file setting for LyXUseAutomaticPipeDetection has an invalid value, using default as fallback 0764 setLyXUseAutomaticPipeDetection(Preferences::defaultLyXUseAutomaticPipeDetection); 0765 } 0766 } 0767 return d->cachedLyXUseAutomaticPipeDetection; 0768 #else // HAVE_KF 0769 return defaultLyXUseAutomaticPipeDetection; 0770 #endif // HAVE_KF 0771 } 0772 0773 #ifdef HAVE_KF 0774 bool Preferences::setLyXUseAutomaticPipeDetection(const bool newValue) 0775 { 0776 if (!d->validateValueForLyXUseAutomaticPipeDetection(newValue)) return false; 0777 d->dirtyFlagLyXUseAutomaticPipeDetection = false; 0778 d->cachedLyXUseAutomaticPipeDetection = newValue; 0779 static KConfigGroup configGroup(d->config, QStringLiteral("LyX")); 0780 const bool valueFromConfig = configGroup.readEntry(QStringLiteral("LyXUseAutomaticPipeDetection"), Preferences::defaultLyXUseAutomaticPipeDetection); 0781 if (valueFromConfig == newValue) return false; 0782 configGroup.writeEntry(QStringLiteral("LyXUseAutomaticPipeDetection"), newValue, KConfig::Notify); 0783 d->config->sync(); 0784 return true; 0785 } 0786 #endif // HAVE_KF 0787 0788 const QString Preferences::defaultLyXPipePath = QDir::homePath() + QStringLiteral("/.lyxpipe.in"); 0789 0790 const QString &Preferences::lyXPipePath() 0791 { 0792 #ifdef HAVE_KF 0793 if (d->dirtyFlagLyXPipePath) { 0794 d->config->reparseConfiguration(); 0795 static const KConfigGroup configGroup(d->config, QStringLiteral("LyX")); 0796 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("LyXPipePath"), Preferences::defaultLyXPipePath); 0797 if (d->validateValueForLyXPipePath(valueFromConfig)) { 0798 d->cachedLyXPipePath = valueFromConfig; 0799 d->dirtyFlagLyXPipePath = false; 0800 } else { 0801 /// Configuration file setting for LyXPipePath has an invalid value, using default as fallback 0802 setLyXPipePath(Preferences::defaultLyXPipePath); 0803 } 0804 } 0805 return d->cachedLyXPipePath; 0806 #else // HAVE_KF 0807 return defaultLyXPipePath; 0808 #endif // HAVE_KF 0809 } 0810 0811 #ifdef HAVE_KF 0812 bool Preferences::setLyXPipePath(const QString &newValue) 0813 { 0814 QString sanitizedNewValue = newValue; 0815 if (sanitizedNewValue.endsWith(QStringLiteral(".out"))) 0816 sanitizedNewValue = sanitizedNewValue.left(sanitizedNewValue.length() - 4); 0817 if (!sanitizedNewValue.endsWith(QStringLiteral(".in"))) 0818 sanitizedNewValue = sanitizedNewValue.append(QStringLiteral(".in")); 0819 if (!d->validateValueForLyXPipePath(sanitizedNewValue)) return false; 0820 d->dirtyFlagLyXPipePath = false; 0821 d->cachedLyXPipePath = sanitizedNewValue; 0822 static KConfigGroup configGroup(d->config, QStringLiteral("LyX")); 0823 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("LyXPipePath"), Preferences::defaultLyXPipePath); 0824 if (valueFromConfig == sanitizedNewValue) return false; 0825 configGroup.writeEntry(QStringLiteral("LyXPipePath"), sanitizedNewValue, KConfig::Notify); 0826 d->config->sync(); 0827 return true; 0828 } 0829 #endif // HAVE_KF 0830 0831 const QStringList Preferences::availableBibTeXEncodings {QStringLiteral("LaTeX"), QStringLiteral("ISO-8859-1"), QStringLiteral("ISO-8859-2"), QStringLiteral("ISO-8859-3"), QStringLiteral("ISO-8859-4"), QStringLiteral("ISO-8859-5"), QStringLiteral("ISO-8859-6"), QStringLiteral("ISO-8859-7"), QStringLiteral("ISO-8859-8"), QStringLiteral("ISO-8859-9"), QStringLiteral("ISO-8859-10"), QStringLiteral("ISO-8859-13"), QStringLiteral("ISO-8859-14"), QStringLiteral("ISO-8859-15"), QStringLiteral("ISO-8859-16"), QStringLiteral("UTF-8"), QStringLiteral("UTF-16"), QStringLiteral("UTF-16BE"), QStringLiteral("UTF-16LE"), QStringLiteral("UTF-32"), QStringLiteral("UTF-32BE"), QStringLiteral("UTF-32LE"), QStringLiteral("KOI8-R"), QStringLiteral("KOI8-U"), QStringLiteral("Big5"), QStringLiteral("Big5-HKSCS"), QStringLiteral("GB18030"), QStringLiteral("EUC-JP"), QStringLiteral("EUC-KR"), QStringLiteral("ISO 2022-JP"), QStringLiteral("Shift-JIS"), QStringLiteral("Windows-949"), QStringLiteral("Windows-1250"), QStringLiteral("Windows-1251"), QStringLiteral("Windows-1252"), QStringLiteral("Windows-1253"), QStringLiteral("Windows-1254"), QStringLiteral("Windows-1255"), QStringLiteral("Windows-1256"), QStringLiteral("Windows-1257"), QStringLiteral("Windows-1258")}; 0832 const QString Preferences::defaultBibTeXEncoding = QStringLiteral("UTF-8"); 0833 0834 const QString &Preferences::bibTeXEncoding() 0835 { 0836 #ifdef HAVE_KF 0837 if (d->dirtyFlagBibTeXEncoding) { 0838 d->config->reparseConfiguration(); 0839 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 0840 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXEncoding"), Preferences::defaultBibTeXEncoding); 0841 if (d->validateValueForBibTeXEncoding(valueFromConfig)) { 0842 d->cachedBibTeXEncoding = valueFromConfig; 0843 d->dirtyFlagBibTeXEncoding = false; 0844 } else { 0845 /// Configuration file setting for BibTeXEncoding has an invalid value, using default as fallback 0846 setBibTeXEncoding(Preferences::defaultBibTeXEncoding); 0847 } 0848 } 0849 return d->cachedBibTeXEncoding; 0850 #else // HAVE_KF 0851 return defaultBibTeXEncoding; 0852 #endif // HAVE_KF 0853 } 0854 0855 #ifdef HAVE_KF 0856 bool Preferences::setBibTeXEncoding(const QString &newValue) 0857 { 0858 QString sanitizedNewValue = newValue; 0859 const QString lowerSanitizedNewValue = sanitizedNewValue.toLower(); 0860 for (const QString &knownBibTeXEncoding : availableBibTeXEncodings) 0861 if (knownBibTeXEncoding.toLower() == lowerSanitizedNewValue) { 0862 sanitizedNewValue = knownBibTeXEncoding; 0863 break; 0864 } 0865 if (!d->validateValueForBibTeXEncoding(sanitizedNewValue)) return false; 0866 d->dirtyFlagBibTeXEncoding = false; 0867 d->cachedBibTeXEncoding = sanitizedNewValue; 0868 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 0869 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXEncoding"), Preferences::defaultBibTeXEncoding); 0870 if (valueFromConfig == sanitizedNewValue) return false; 0871 configGroup.writeEntry(QStringLiteral("BibTeXEncoding"), sanitizedNewValue, KConfig::Notify); 0872 d->config->sync(); 0873 return true; 0874 } 0875 #endif // HAVE_KF 0876 0877 const QStringList Preferences::availableBibTeXStringDelimiters {QStringLiteral("{}"), QStringLiteral("\"\""), QStringLiteral("()")}; 0878 const QString Preferences::defaultBibTeXStringDelimiter = Preferences::availableBibTeXStringDelimiters.front(); 0879 0880 const QString &Preferences::bibTeXStringDelimiter() 0881 { 0882 #ifdef HAVE_KF 0883 if (d->dirtyFlagBibTeXStringDelimiter) { 0884 d->config->reparseConfiguration(); 0885 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 0886 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXStringDelimiter"), Preferences::defaultBibTeXStringDelimiter); 0887 if (d->validateValueForBibTeXStringDelimiter(valueFromConfig)) { 0888 d->cachedBibTeXStringDelimiter = valueFromConfig; 0889 d->dirtyFlagBibTeXStringDelimiter = false; 0890 } else { 0891 /// Configuration file setting for BibTeXStringDelimiter has an invalid value, using default as fallback 0892 setBibTeXStringDelimiter(Preferences::defaultBibTeXStringDelimiter); 0893 } 0894 } 0895 return d->cachedBibTeXStringDelimiter; 0896 #else // HAVE_KF 0897 return defaultBibTeXStringDelimiter; 0898 #endif // HAVE_KF 0899 } 0900 0901 #ifdef HAVE_KF 0902 bool Preferences::setBibTeXStringDelimiter(const QString &newValue) 0903 { 0904 QString sanitizedNewValue = newValue; 0905 const QString lowerSanitizedNewValue = sanitizedNewValue.toLower(); 0906 for (const QString &knownBibTeXStringDelimiter : availableBibTeXStringDelimiters) 0907 if (knownBibTeXStringDelimiter.toLower() == lowerSanitizedNewValue) { 0908 sanitizedNewValue = knownBibTeXStringDelimiter; 0909 break; 0910 } 0911 if (!d->validateValueForBibTeXStringDelimiter(sanitizedNewValue)) return false; 0912 d->dirtyFlagBibTeXStringDelimiter = false; 0913 d->cachedBibTeXStringDelimiter = sanitizedNewValue; 0914 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 0915 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXStringDelimiter"), Preferences::defaultBibTeXStringDelimiter); 0916 if (valueFromConfig == sanitizedNewValue) return false; 0917 configGroup.writeEntry(QStringLiteral("BibTeXStringDelimiter"), sanitizedNewValue, KConfig::Notify); 0918 d->config->sync(); 0919 return true; 0920 } 0921 #endif // HAVE_KF 0922 0923 const QVector<QPair<Preferences::CommentContext, QString>> Preferences::availableBibTeXCommentContexts {{Preferences::CommentContext::Verbatim, i18nc("Comment Context: The comment's text appears verbatim in the bibliography", "Verbatim")}, {Preferences::CommentContext::Prefix, i18nc("Comment Quoting: All lines of the comment share a common prefix like '%% ' which is not part of the comment's text", "Use prefix like '%% '")}, {Preferences::CommentContext::Command, i18nc("Comment Quoting: The comment is inside @comment{..}", "Use command @comment{...}")}}; 0924 const Preferences::CommentContext Preferences::defaultBibTeXCommentContext = Preferences::availableBibTeXCommentContexts.front().first; 0925 0926 Preferences::CommentContext Preferences::bibTeXCommentContext() 0927 { 0928 #ifdef HAVE_KF 0929 if (d->dirtyFlagBibTeXCommentContext) { 0930 d->config->reparseConfiguration(); 0931 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 0932 const Preferences::CommentContext valueFromConfig = static_cast<Preferences::CommentContext>(configGroup.readEntry(QStringLiteral("BibTeXCommentContext"), static_cast<int>(Preferences::defaultBibTeXCommentContext))); 0933 if (d->validateValueForBibTeXCommentContext(valueFromConfig)) { 0934 d->cachedBibTeXCommentContext = valueFromConfig; 0935 d->dirtyFlagBibTeXCommentContext = false; 0936 } else { 0937 /// Configuration file setting for BibTeXCommentContext has an invalid value, using default as fallback 0938 setBibTeXCommentContext(Preferences::defaultBibTeXCommentContext); 0939 } 0940 } 0941 return d->cachedBibTeXCommentContext; 0942 #else // HAVE_KF 0943 return defaultBibTeXCommentContext; 0944 #endif // HAVE_KF 0945 } 0946 0947 #ifdef HAVE_KF 0948 bool Preferences::setBibTeXCommentContext(const Preferences::CommentContext newValue) 0949 { 0950 if (!d->validateValueForBibTeXCommentContext(newValue)) return false; 0951 d->dirtyFlagBibTeXCommentContext = false; 0952 d->cachedBibTeXCommentContext = newValue; 0953 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 0954 const Preferences::CommentContext valueFromConfig = static_cast<Preferences::CommentContext>(configGroup.readEntry(QStringLiteral("BibTeXCommentContext"), static_cast<int>(Preferences::defaultBibTeXCommentContext))); 0955 if (valueFromConfig == newValue) return false; 0956 configGroup.writeEntry(QStringLiteral("BibTeXCommentContext"), static_cast<int>(newValue), KConfig::Notify); 0957 d->config->sync(); 0958 return true; 0959 } 0960 #endif // HAVE_KF 0961 0962 const QString Preferences::defaultBibTeXCommentPrefix = QString(); 0963 0964 const QString &Preferences::bibTeXCommentPrefix() 0965 { 0966 #ifdef HAVE_KF 0967 if (d->dirtyFlagBibTeXCommentPrefix) { 0968 d->config->reparseConfiguration(); 0969 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 0970 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXCommentPrefix"), Preferences::defaultBibTeXCommentPrefix); 0971 if (d->validateValueForBibTeXCommentPrefix(valueFromConfig)) { 0972 d->cachedBibTeXCommentPrefix = valueFromConfig; 0973 d->dirtyFlagBibTeXCommentPrefix = false; 0974 } else { 0975 /// Configuration file setting for BibTeXCommentPrefix has an invalid value, using default as fallback 0976 setBibTeXCommentPrefix(Preferences::defaultBibTeXCommentPrefix); 0977 } 0978 } 0979 return d->cachedBibTeXCommentPrefix; 0980 #else // HAVE_KF 0981 return defaultBibTeXCommentPrefix; 0982 #endif // HAVE_KF 0983 } 0984 0985 #ifdef HAVE_KF 0986 bool Preferences::setBibTeXCommentPrefix(const QString &newValue) 0987 { 0988 if (!d->validateValueForBibTeXCommentPrefix(newValue)) return false; 0989 d->dirtyFlagBibTeXCommentPrefix = false; 0990 d->cachedBibTeXCommentPrefix = newValue; 0991 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 0992 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXCommentPrefix"), Preferences::defaultBibTeXCommentPrefix); 0993 if (valueFromConfig == newValue) return false; 0994 configGroup.writeEntry(QStringLiteral("BibTeXCommentPrefix"), newValue, KConfig::Notify); 0995 d->config->sync(); 0996 return true; 0997 } 0998 #endif // HAVE_KF 0999 1000 const QVector<QPair<KBibTeX::Casing, QString>> Preferences::availableBibTeXKeywordCasings {{KBibTeX::Casing::LowerCase, i18nc("Casing of strings", "lowercase")}, {KBibTeX::Casing::InitialCapital, i18nc("Casing of strings", "Initial capital")}, {KBibTeX::Casing::UpperCamelCase, i18nc("Casing of strings", "UpperCamelCase")}, {KBibTeX::Casing::LowerCamelCase, i18nc("Casing of strings", "lowerCamelCase")}, {KBibTeX::Casing::UpperCase, i18nc("Casing of strings", "UPPERCASE")}}; 1001 const KBibTeX::Casing Preferences::defaultBibTeXKeywordCasing = Preferences::availableBibTeXKeywordCasings.front().first; 1002 1003 KBibTeX::Casing Preferences::bibTeXKeywordCasing() 1004 { 1005 #ifdef HAVE_KF 1006 if (d->dirtyFlagBibTeXKeywordCasing) { 1007 d->config->reparseConfiguration(); 1008 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 1009 const KBibTeX::Casing valueFromConfig = static_cast<KBibTeX::Casing>(configGroup.readEntry(QStringLiteral("BibTeXKeywordCasing"), static_cast<int>(Preferences::defaultBibTeXKeywordCasing))); 1010 if (d->validateValueForBibTeXKeywordCasing(valueFromConfig)) { 1011 d->cachedBibTeXKeywordCasing = valueFromConfig; 1012 d->dirtyFlagBibTeXKeywordCasing = false; 1013 } else { 1014 /// Configuration file setting for BibTeXKeywordCasing has an invalid value, using default as fallback 1015 setBibTeXKeywordCasing(Preferences::defaultBibTeXKeywordCasing); 1016 } 1017 } 1018 return d->cachedBibTeXKeywordCasing; 1019 #else // HAVE_KF 1020 return defaultBibTeXKeywordCasing; 1021 #endif // HAVE_KF 1022 } 1023 1024 #ifdef HAVE_KF 1025 bool Preferences::setBibTeXKeywordCasing(const KBibTeX::Casing newValue) 1026 { 1027 if (!d->validateValueForBibTeXKeywordCasing(newValue)) return false; 1028 d->dirtyFlagBibTeXKeywordCasing = false; 1029 d->cachedBibTeXKeywordCasing = newValue; 1030 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 1031 const KBibTeX::Casing valueFromConfig = static_cast<KBibTeX::Casing>(configGroup.readEntry(QStringLiteral("BibTeXKeywordCasing"), static_cast<int>(Preferences::defaultBibTeXKeywordCasing))); 1032 if (valueFromConfig == newValue) return false; 1033 configGroup.writeEntry(QStringLiteral("BibTeXKeywordCasing"), static_cast<int>(newValue), KConfig::Notify); 1034 d->config->sync(); 1035 return true; 1036 } 1037 #endif // HAVE_KF 1038 1039 const bool Preferences::defaultBibTeXProtectCasing = true; 1040 1041 bool Preferences::bibTeXProtectCasing() 1042 { 1043 #ifdef HAVE_KF 1044 if (d->dirtyFlagBibTeXProtectCasing) { 1045 d->config->reparseConfiguration(); 1046 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 1047 const bool valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXProtectCasing"), Preferences::defaultBibTeXProtectCasing); 1048 if (d->validateValueForBibTeXProtectCasing(valueFromConfig)) { 1049 d->cachedBibTeXProtectCasing = valueFromConfig; 1050 d->dirtyFlagBibTeXProtectCasing = false; 1051 } else { 1052 /// Configuration file setting for BibTeXProtectCasing has an invalid value, using default as fallback 1053 setBibTeXProtectCasing(Preferences::defaultBibTeXProtectCasing); 1054 } 1055 } 1056 return d->cachedBibTeXProtectCasing; 1057 #else // HAVE_KF 1058 return defaultBibTeXProtectCasing; 1059 #endif // HAVE_KF 1060 } 1061 1062 #ifdef HAVE_KF 1063 bool Preferences::setBibTeXProtectCasing(const bool newValue) 1064 { 1065 if (!d->validateValueForBibTeXProtectCasing(newValue)) return false; 1066 d->dirtyFlagBibTeXProtectCasing = false; 1067 d->cachedBibTeXProtectCasing = newValue; 1068 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 1069 const bool valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXProtectCasing"), Preferences::defaultBibTeXProtectCasing); 1070 if (valueFromConfig == newValue) return false; 1071 configGroup.writeEntry(QStringLiteral("BibTeXProtectCasing"), newValue, KConfig::Notify); 1072 d->config->sync(); 1073 return true; 1074 } 1075 #endif // HAVE_KF 1076 1077 const QStringList Preferences::availableBibTeXListSeparators {QStringLiteral("; "), QStringLiteral(", ")}; 1078 const QString Preferences::defaultBibTeXListSeparator = Preferences::availableBibTeXListSeparators.front(); 1079 1080 const QString &Preferences::bibTeXListSeparator() 1081 { 1082 #ifdef HAVE_KF 1083 if (d->dirtyFlagBibTeXListSeparator) { 1084 d->config->reparseConfiguration(); 1085 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 1086 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXListSeparator"), Preferences::defaultBibTeXListSeparator); 1087 if (d->validateValueForBibTeXListSeparator(valueFromConfig)) { 1088 d->cachedBibTeXListSeparator = valueFromConfig; 1089 d->dirtyFlagBibTeXListSeparator = false; 1090 } else { 1091 /// Configuration file setting for BibTeXListSeparator has an invalid value, using default as fallback 1092 setBibTeXListSeparator(Preferences::defaultBibTeXListSeparator); 1093 } 1094 } 1095 return d->cachedBibTeXListSeparator; 1096 #else // HAVE_KF 1097 return defaultBibTeXListSeparator; 1098 #endif // HAVE_KF 1099 } 1100 1101 #ifdef HAVE_KF 1102 bool Preferences::setBibTeXListSeparator(const QString &newValue) 1103 { 1104 QString sanitizedNewValue = newValue; 1105 const QString lowerSanitizedNewValue = sanitizedNewValue.toLower(); 1106 for (const QString &knownBibTeXListSeparator : availableBibTeXListSeparators) 1107 if (knownBibTeXListSeparator.toLower() == lowerSanitizedNewValue) { 1108 sanitizedNewValue = knownBibTeXListSeparator; 1109 break; 1110 } 1111 if (!d->validateValueForBibTeXListSeparator(sanitizedNewValue)) return false; 1112 d->dirtyFlagBibTeXListSeparator = false; 1113 d->cachedBibTeXListSeparator = sanitizedNewValue; 1114 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 1115 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXListSeparator"), Preferences::defaultBibTeXListSeparator); 1116 if (valueFromConfig == sanitizedNewValue) return false; 1117 configGroup.writeEntry(QStringLiteral("BibTeXListSeparator"), sanitizedNewValue, KConfig::Notify); 1118 d->config->sync(); 1119 return true; 1120 } 1121 #endif // HAVE_KF 1122 1123 const bool Preferences::defaultbibTeXEntriesSortedByIdentifier = false; 1124 1125 bool Preferences::bibTeXEntriesSortedByIdentifier() 1126 { 1127 #ifdef HAVE_KF 1128 if (d->dirtyFlagbibTeXEntriesSortedByIdentifier) { 1129 d->config->reparseConfiguration(); 1130 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 1131 const bool valueFromConfig = configGroup.readEntry(QStringLiteral("bibTeXEntriesSortedByIdentifier"), Preferences::defaultbibTeXEntriesSortedByIdentifier); 1132 if (d->validateValueForbibTeXEntriesSortedByIdentifier(valueFromConfig)) { 1133 d->cachedbibTeXEntriesSortedByIdentifier = valueFromConfig; 1134 d->dirtyFlagbibTeXEntriesSortedByIdentifier = false; 1135 } else { 1136 /// Configuration file setting for bibTeXEntriesSortedByIdentifier has an invalid value, using default as fallback 1137 setbibTeXEntriesSortedByIdentifier(Preferences::defaultbibTeXEntriesSortedByIdentifier); 1138 } 1139 } 1140 return d->cachedbibTeXEntriesSortedByIdentifier; 1141 #else // HAVE_KF 1142 return defaultbibTeXEntriesSortedByIdentifier; 1143 #endif // HAVE_KF 1144 } 1145 1146 #ifdef HAVE_KF 1147 bool Preferences::setbibTeXEntriesSortedByIdentifier(const bool newValue) 1148 { 1149 if (!d->validateValueForbibTeXEntriesSortedByIdentifier(newValue)) return false; 1150 d->dirtyFlagbibTeXEntriesSortedByIdentifier = false; 1151 d->cachedbibTeXEntriesSortedByIdentifier = newValue; 1152 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterBibTeX")); 1153 const bool valueFromConfig = configGroup.readEntry(QStringLiteral("bibTeXEntriesSortedByIdentifier"), Preferences::defaultbibTeXEntriesSortedByIdentifier); 1154 if (valueFromConfig == newValue) return false; 1155 configGroup.writeEntry(QStringLiteral("bibTeXEntriesSortedByIdentifier"), newValue, KConfig::Notify); 1156 d->config->sync(); 1157 return true; 1158 } 1159 #endif // HAVE_KF 1160 1161 const QString Preferences::defaultLaTeXBabelLanguage = QStringLiteral("english"); 1162 1163 const QString &Preferences::laTeXBabelLanguage() 1164 { 1165 #ifdef HAVE_KF 1166 if (d->dirtyFlagLaTeXBabelLanguage) { 1167 d->config->reparseConfiguration(); 1168 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterLaTeXbased")); 1169 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("LaTeXBabelLanguage"), Preferences::defaultLaTeXBabelLanguage); 1170 if (d->validateValueForLaTeXBabelLanguage(valueFromConfig)) { 1171 d->cachedLaTeXBabelLanguage = valueFromConfig; 1172 d->dirtyFlagLaTeXBabelLanguage = false; 1173 } else { 1174 /// Configuration file setting for LaTeXBabelLanguage has an invalid value, using default as fallback 1175 setLaTeXBabelLanguage(Preferences::defaultLaTeXBabelLanguage); 1176 } 1177 } 1178 return d->cachedLaTeXBabelLanguage; 1179 #else // HAVE_KF 1180 return defaultLaTeXBabelLanguage; 1181 #endif // HAVE_KF 1182 } 1183 1184 #ifdef HAVE_KF 1185 bool Preferences::setLaTeXBabelLanguage(const QString &newValue) 1186 { 1187 if (!d->validateValueForLaTeXBabelLanguage(newValue)) return false; 1188 d->dirtyFlagLaTeXBabelLanguage = false; 1189 d->cachedLaTeXBabelLanguage = newValue; 1190 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterLaTeXbased")); 1191 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("LaTeXBabelLanguage"), Preferences::defaultLaTeXBabelLanguage); 1192 if (valueFromConfig == newValue) return false; 1193 configGroup.writeEntry(QStringLiteral("LaTeXBabelLanguage"), newValue, KConfig::Notify); 1194 d->config->sync(); 1195 return true; 1196 } 1197 #endif // HAVE_KF 1198 1199 const QString Preferences::defaultBibTeXBibliographyStyle = QStringLiteral("plain"); 1200 1201 const QString &Preferences::bibTeXBibliographyStyle() 1202 { 1203 #ifdef HAVE_KF 1204 if (d->dirtyFlagBibTeXBibliographyStyle) { 1205 d->config->reparseConfiguration(); 1206 static const KConfigGroup configGroup(d->config, QStringLiteral("FileExporterLaTeXbased")); 1207 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXBibliographyStyle"), Preferences::defaultBibTeXBibliographyStyle); 1208 if (d->validateValueForBibTeXBibliographyStyle(valueFromConfig)) { 1209 d->cachedBibTeXBibliographyStyle = valueFromConfig; 1210 d->dirtyFlagBibTeXBibliographyStyle = false; 1211 } else { 1212 /// Configuration file setting for BibTeXBibliographyStyle has an invalid value, using default as fallback 1213 setBibTeXBibliographyStyle(Preferences::defaultBibTeXBibliographyStyle); 1214 } 1215 } 1216 return d->cachedBibTeXBibliographyStyle; 1217 #else // HAVE_KF 1218 return defaultBibTeXBibliographyStyle; 1219 #endif // HAVE_KF 1220 } 1221 1222 #ifdef HAVE_KF 1223 bool Preferences::setBibTeXBibliographyStyle(const QString &newValue) 1224 { 1225 if (!d->validateValueForBibTeXBibliographyStyle(newValue)) return false; 1226 d->dirtyFlagBibTeXBibliographyStyle = false; 1227 d->cachedBibTeXBibliographyStyle = newValue; 1228 static KConfigGroup configGroup(d->config, QStringLiteral("FileExporterLaTeXbased")); 1229 const QString valueFromConfig = configGroup.readEntry(QStringLiteral("BibTeXBibliographyStyle"), Preferences::defaultBibTeXBibliographyStyle); 1230 if (valueFromConfig == newValue) return false; 1231 configGroup.writeEntry(QStringLiteral("BibTeXBibliographyStyle"), newValue, KConfig::Notify); 1232 d->config->sync(); 1233 return true; 1234 } 1235 #endif // HAVE_KF 1236 1237 const QVector<QPair<Preferences::FileViewDoubleClickAction, QString>> Preferences::availableFileViewDoubleClickActions {{Preferences::FileViewDoubleClickAction::OpenEditor, i18nc("What to do if double-clicking on a file view item", "Open Editor")}, {Preferences::FileViewDoubleClickAction::ViewDocument, i18nc("What to do if double-clicking on a file view item", "View Document")}}; 1238 const Preferences::FileViewDoubleClickAction Preferences::defaultFileViewDoubleClickAction = Preferences::availableFileViewDoubleClickActions.front().first; 1239 1240 Preferences::FileViewDoubleClickAction Preferences::fileViewDoubleClickAction() 1241 { 1242 #ifdef HAVE_KF 1243 if (d->dirtyFlagFileViewDoubleClickAction) { 1244 d->config->reparseConfiguration(); 1245 static const KConfigGroup configGroup(d->config, QStringLiteral("User Interface")); 1246 const Preferences::FileViewDoubleClickAction valueFromConfig = static_cast<Preferences::FileViewDoubleClickAction>(configGroup.readEntry(QStringLiteral("FileViewDoubleClickAction"), static_cast<int>(Preferences::defaultFileViewDoubleClickAction))); 1247 if (d->validateValueForFileViewDoubleClickAction(valueFromConfig)) { 1248 d->cachedFileViewDoubleClickAction = valueFromConfig; 1249 d->dirtyFlagFileViewDoubleClickAction = false; 1250 } else { 1251 /// Configuration file setting for FileViewDoubleClickAction has an invalid value, using default as fallback 1252 setFileViewDoubleClickAction(Preferences::defaultFileViewDoubleClickAction); 1253 } 1254 } 1255 return d->cachedFileViewDoubleClickAction; 1256 #else // HAVE_KF 1257 return defaultFileViewDoubleClickAction; 1258 #endif // HAVE_KF 1259 } 1260 1261 #ifdef HAVE_KF 1262 bool Preferences::setFileViewDoubleClickAction(const Preferences::FileViewDoubleClickAction newValue) 1263 { 1264 if (!d->validateValueForFileViewDoubleClickAction(newValue)) return false; 1265 d->dirtyFlagFileViewDoubleClickAction = false; 1266 d->cachedFileViewDoubleClickAction = newValue; 1267 static KConfigGroup configGroup(d->config, QStringLiteral("User Interface")); 1268 const Preferences::FileViewDoubleClickAction valueFromConfig = static_cast<Preferences::FileViewDoubleClickAction>(configGroup.readEntry(QStringLiteral("FileViewDoubleClickAction"), static_cast<int>(Preferences::defaultFileViewDoubleClickAction))); 1269 if (valueFromConfig == newValue) return false; 1270 configGroup.writeEntry(QStringLiteral("FileViewDoubleClickAction"), static_cast<int>(newValue), KConfig::Notify); 1271 d->config->sync(); 1272 return true; 1273 } 1274 #endif // HAVE_KF 1275 1276 const QVector<QPair<QString, QString>> Preferences::defaultColorCodes {{QStringLiteral("#c30"), i18nc("Color Labels", "Important")}, {QStringLiteral("#03f"), i18nc("Color Labels", "Unread")}, {QStringLiteral("#096"), i18nc("Color Labels", "Read")}, {QStringLiteral("#fd0"), i18nc("Color Labels", "Watch")}}; 1277 1278 const QVector<QPair<QString, QString>> &Preferences::colorCodes() 1279 { 1280 #ifdef HAVE_KF 1281 if (d->dirtyFlagColorCodes) { 1282 d->config->reparseConfiguration(); 1283 static const KConfigGroup configGroup(d->config, QStringLiteral("Color Labels")); 1284 const QVector<QPair<QString, QString>> valueFromConfig = d->readEntryColorCodes(configGroup, QStringLiteral("ColorCodes")); 1285 if (d->validateValueForColorCodes(valueFromConfig)) { 1286 d->cachedColorCodes = valueFromConfig; 1287 d->dirtyFlagColorCodes = false; 1288 } else { 1289 /// Configuration file setting for ColorCodes has an invalid value, using default as fallback 1290 setColorCodes(Preferences::defaultColorCodes); 1291 } 1292 } 1293 return d->cachedColorCodes; 1294 #else // HAVE_KF 1295 return defaultColorCodes; 1296 #endif // HAVE_KF 1297 } 1298 1299 #ifdef HAVE_KF 1300 bool Preferences::setColorCodes(const QVector<QPair<QString, QString>> &newValue) 1301 { 1302 if (!d->validateValueForColorCodes(newValue)) return false; 1303 d->dirtyFlagColorCodes = false; 1304 d->cachedColorCodes = newValue; 1305 static KConfigGroup configGroup(d->config, QStringLiteral("Color Labels")); 1306 const QVector<QPair<QString, QString>> valueFromConfig = d->readEntryColorCodes(configGroup, QStringLiteral("ColorCodes")); 1307 if (valueFromConfig == newValue) return false; 1308 d->writeEntryColorCodes(configGroup, QStringLiteral("ColorCodes"), newValue); 1309 d->config->sync(); 1310 return true; 1311 } 1312 #endif // HAVE_KF