File indexing completed on 2025-01-05 03:57:55
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2013-12-20 0007 * Description : Settings for Showfoto 0008 * 0009 * SPDX-FileCopyrightText: 2013-2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com> 0010 * SPDX-FileCopyrightText: 2013-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "showfotosettings.h" 0017 0018 // Qt includes 0019 0020 #include <QStyle> 0021 #include <QApplication> 0022 #include <QFontDatabase> 0023 0024 // KDE includes 0025 0026 #include <ksharedconfig.h> 0027 #include <kconfiggroup.h> 0028 0029 // Local includes 0030 0031 #include "digikam_config.h" 0032 #include "digikam_debug.h" 0033 #include "setupmisc.h" 0034 #include "thememanager.h" 0035 0036 namespace ShowFoto 0037 { 0038 0039 class Q_DECL_HIDDEN ShowfotoSettings::Private 0040 { 0041 0042 public: 0043 0044 explicit Private() 0045 : deleteItem2Trash (true), 0046 showFormatOverThumbnail (false), 0047 showCoordinates (false), 0048 showSplash (true), 0049 nativeFileDialog (false), 0050 itemCenter (false), 0051 reverseSort (false), 0052 showToolTip (true), 0053 showFileName (true), 0054 showFileDate (false), 0055 showFileSize (false), 0056 showFileType (false), 0057 showFileDim (true), 0058 showPhotoMake (true), 0059 showPhotoLens (true), 0060 showPhotoFocal (true), 0061 showPhotoExpo (true), 0062 showPhotoFlash (false), 0063 showPhotoWB (false), 0064 showPhotoDate (true), 0065 showPhotoMode (false), 0066 updateType (0), 0067 updateWithDebug (false), 0068 rightSideBarStyle (0), 0069 sortOrder (0) 0070 { 0071 } 0072 0073 static const QString configGroupDefault; 0074 0075 static const QString configLastOpenedDir; 0076 static const QString configDeleteItem2Trash; 0077 static const QString configCurrentTheme; 0078 static const QString configRightSideBarStyle; 0079 static const QString configUpdateType; 0080 static const QString configUpdateWithDebug; 0081 static const QString configApplicationStyle; 0082 static const QString configIconTheme; 0083 static const QString configApplicationFont; 0084 static const QString configShowFormatOverThumbnail; 0085 static const QString configShowCoordinates; 0086 static const QString configShowSplash; 0087 static const QString configNativeFileDialog; 0088 static const QString configItemCenter; 0089 static const QString configSortOrder; 0090 static const QString configReverseSort; 0091 0092 static const QString configShowToolTip; 0093 0094 static const QString configShowFileName; 0095 static const QString configShowFileDate; 0096 static const QString configShowFileSize; 0097 static const QString configShowFileType; 0098 static const QString configShowFileDim; 0099 0100 static const QString configShowPhotoMake; 0101 static const QString configShowPhotoLens; 0102 static const QString configShowPhotoFocal; 0103 static const QString configShowPhotoExpo; 0104 static const QString configShowPhotoFlash; 0105 static const QString configShowPhotoWB; 0106 static const QString configShowPhotoDate; 0107 static const QString configShowPhotoMode; 0108 0109 static const QString configToolTipsFont; 0110 0111 bool deleteItem2Trash; 0112 bool showFormatOverThumbnail; 0113 bool showCoordinates; 0114 bool showSplash; 0115 bool nativeFileDialog; 0116 bool itemCenter; 0117 bool reverseSort; 0118 0119 bool showToolTip; 0120 0121 bool showFileName; 0122 bool showFileDate; 0123 bool showFileSize; 0124 bool showFileType; 0125 bool showFileDim; 0126 0127 bool showPhotoMake; 0128 bool showPhotoLens; 0129 bool showPhotoFocal; 0130 bool showPhotoExpo; 0131 bool showPhotoFlash; 0132 bool showPhotoWB; 0133 bool showPhotoDate; 0134 bool showPhotoMode; 0135 0136 int updateType; 0137 bool updateWithDebug; 0138 int rightSideBarStyle; 0139 int sortOrder; 0140 0141 QFont toolTipsFont; 0142 0143 QString lastOpenedDir; 0144 QString theme; 0145 QString applicationStyle; 0146 QString applicationIcon; 0147 QFont applicationFont; 0148 0149 KSharedConfigPtr config; 0150 KConfigGroup group; 0151 }; 0152 0153 /// Configuration Group 0154 const QString ShowfotoSettings::Private::configGroupDefault(QLatin1String("ImageViewer Settings")); 0155 0156 /// Misc. & Showfoto Generals Settings 0157 const QString ShowfotoSettings::Private::configLastOpenedDir(QLatin1String("Last Opened Directory")); 0158 const QString ShowfotoSettings::Private::configDeleteItem2Trash(QLatin1String("DeleteItem2Trash")); 0159 const QString ShowfotoSettings::Private::configCurrentTheme(QLatin1String("Theme")); 0160 const QString ShowfotoSettings::Private::configUpdateType(QLatin1String("Update Type")); 0161 const QString ShowfotoSettings::Private::configUpdateWithDebug(QLatin1String("Update With Debug")); 0162 const QString ShowfotoSettings::Private::configRightSideBarStyle(QLatin1String("Sidebar Title Style")); 0163 const QString ShowfotoSettings::Private::configApplicationStyle(QLatin1String("Application Style")); 0164 const QString ShowfotoSettings::Private::configIconTheme(QLatin1String("Icon Theme")); 0165 const QString ShowfotoSettings::Private::configApplicationFont(QLatin1String("Application Font")); 0166 const QString ShowfotoSettings::Private::configShowFormatOverThumbnail(QLatin1String("ShowMimeOverImage")); 0167 const QString ShowfotoSettings::Private::configShowCoordinates(QLatin1String("Show Coordinates")); 0168 const QString ShowfotoSettings::Private::configShowSplash(QLatin1String("ShowSplash")); 0169 const QString ShowfotoSettings::Private::configNativeFileDialog(QLatin1String("Use Native File Dialog")); 0170 const QString ShowfotoSettings::Private::configItemCenter(QLatin1String("Item To Center")); 0171 const QString ShowfotoSettings::Private::configSortOrder(QLatin1String("SortOrder")); 0172 const QString ShowfotoSettings::Private::configReverseSort(QLatin1String("ReverseSort")); 0173 0174 /// Tool Tip Enable/Disable 0175 const QString ShowfotoSettings::Private::configShowToolTip(QLatin1String("Show ToolTips")); 0176 0177 /// Tool Tip File Properties 0178 const QString ShowfotoSettings::Private::configShowFileName(QLatin1String("ToolTips Show File Name")); 0179 const QString ShowfotoSettings::Private::configShowFileDate(QLatin1String("ToolTips Show File Date")); 0180 const QString ShowfotoSettings::Private::configShowFileSize(QLatin1String("ToolTips Show File Size")); 0181 const QString ShowfotoSettings::Private::configShowFileType(QLatin1String("ToolTips Show Image Type")); 0182 const QString ShowfotoSettings::Private::configShowFileDim(QLatin1String("ToolTips Show Image Dim")); 0183 0184 /// Tool Tip Photograph Info 0185 const QString ShowfotoSettings::Private::configShowPhotoMake(QLatin1String("ToolTips Show Photo Make")); 0186 const QString ShowfotoSettings::Private::configShowPhotoLens(QLatin1String("ToolTips Show Photo Lens")); 0187 const QString ShowfotoSettings::Private::configShowPhotoFocal(QLatin1String("ToolTips Show Photo Focal")); 0188 const QString ShowfotoSettings::Private::configShowPhotoExpo(QLatin1String("ToolTips Show Photo Expo")); 0189 const QString ShowfotoSettings::Private::configShowPhotoFlash(QLatin1String("ToolTips Show Photo Flash")); 0190 const QString ShowfotoSettings::Private::configShowPhotoWB(QLatin1String("ToolTips Show Photo WB")); 0191 const QString ShowfotoSettings::Private::configShowPhotoDate(QLatin1String("ToolTips Show Photo Date")); 0192 const QString ShowfotoSettings::Private::configShowPhotoMode(QLatin1String("ToolTips Show Photo Mode")); 0193 0194 /// Tool Tips Font 0195 const QString ShowfotoSettings::Private::configToolTipsFont(QLatin1String("ToolTips Font")); 0196 0197 // ------------------------------------------------------------------------------------------------- 0198 0199 class Q_DECL_HIDDEN ShowfotoSettingsCreator 0200 { 0201 public: 0202 0203 ShowfotoSettings object; 0204 }; 0205 0206 Q_GLOBAL_STATIC(ShowfotoSettingsCreator, creator) 0207 0208 // ------------------------------------------------------------------------------------------------- 0209 0210 ShowfotoSettings* ShowfotoSettings::instance() 0211 { 0212 return &creator->object; 0213 } 0214 0215 ShowfotoSettings::ShowfotoSettings() 0216 : QObject(), 0217 d (new Private) 0218 { 0219 d->config = KSharedConfig::openConfig(); 0220 d->group = d->config->group(d->configGroupDefault); 0221 init(); 0222 readSettings(); 0223 } 0224 0225 ShowfotoSettings::~ShowfotoSettings() 0226 { 0227 delete d; 0228 } 0229 0230 void ShowfotoSettings::init() 0231 { 0232 d->updateType = 0; 0233 d->updateWithDebug = false; 0234 d->rightSideBarStyle = 0; 0235 d->sortOrder = 0; 0236 d->deleteItem2Trash = true; 0237 d->showSplash = true; 0238 d->reverseSort = false; 0239 0240 d->showFormatOverThumbnail = false; 0241 d->showCoordinates = false; 0242 d->nativeFileDialog = false; 0243 d->itemCenter = false; 0244 0245 d->showToolTip = true; 0246 0247 d->showFileName = true; 0248 d->showFileDate = false; 0249 d->showFileSize = false; 0250 d->showFileType = false; 0251 d->showFileDim = true; 0252 0253 d->showPhotoMake = true; 0254 d->showPhotoLens = true; 0255 d->showPhotoFocal = true; 0256 d->showPhotoExpo = true; 0257 d->showPhotoFlash = false; 0258 d->showPhotoWB = false; 0259 d->showPhotoDate = true; 0260 d->showPhotoMode = true; 0261 0262 d->applicationStyle = qApp->style()->objectName(); 0263 d->applicationIcon = QString(); 0264 d->applicationFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont); 0265 } 0266 0267 void ShowfotoSettings::readSettings() 0268 { 0269 KConfigGroup group = d->group; 0270 0271 d->lastOpenedDir = group.readEntry(d->configLastOpenedDir, QString()); 0272 d->deleteItem2Trash = group.readEntry(d->configDeleteItem2Trash, true); 0273 d->theme = group.readEntry(d->configCurrentTheme, Digikam::ThemeManager::instance()->defaultThemeName()); 0274 d->updateType = group.readEntry(d->configUpdateType, 0); 0275 d->updateWithDebug = group.readEntry(d->configUpdateWithDebug, false); 0276 d->rightSideBarStyle = group.readEntry(d->configRightSideBarStyle, 0); 0277 0278 #if defined Q_OS_WIN || defined Q_OS_MACOS 0279 0280 QString defaultStyle = QLatin1String("Breeze"); 0281 0282 #else 0283 0284 QString defaultStyle = qApp->style()->objectName(); 0285 0286 #endif 0287 0288 #ifdef HAVE_APPSTYLE_SUPPORT 0289 0290 QString style = group.readEntry(d->configApplicationStyle, defaultStyle); 0291 0292 if (style == QLatin1String("Macintosh")) // See bug @475572 0293 { 0294 style = QLatin1String("Breeze"); 0295 } 0296 0297 setApplicationStyle(style); 0298 0299 #else 0300 0301 setApplicationStyle(QLatin1String("Breeze")); 0302 0303 #endif 0304 0305 d->applicationIcon = group.readEntry(d->configIconTheme, QString()); 0306 0307 setApplicationFont(group.readEntry(d->configApplicationFont, QFontDatabase::systemFont(QFontDatabase::GeneralFont))); 0308 0309 d->showSplash = group.readEntry(d->configShowSplash, true); 0310 0311 #ifdef Q_OS_MACOS 0312 0313 d->nativeFileDialog = group.readEntry(d->configNativeFileDialog, true); 0314 0315 #else 0316 0317 d->nativeFileDialog = group.readEntry(d->configNativeFileDialog, false); 0318 0319 #endif 0320 0321 d->itemCenter = group.readEntry(d->configItemCenter, false); 0322 d->sortOrder = group.readEntry(d->configSortOrder, 0); 0323 d->reverseSort = group.readEntry(d->configReverseSort, false); 0324 d->showFormatOverThumbnail = group.readEntry(d->configShowFormatOverThumbnail, false); 0325 d->showCoordinates = group.readEntry(d->configShowCoordinates, false); 0326 0327 d->showToolTip = group.readEntry(d->configShowToolTip, true); 0328 0329 d->showFileName = group.readEntry(d->configShowFileName, true); 0330 d->showFileDate = group.readEntry(d->configShowFileDate, false); 0331 d->showFileSize = group.readEntry(d->configShowFileSize, false); 0332 d->showFileType = group.readEntry(d->configShowFileType, false); 0333 d->showFileDim = group.readEntry(d->configShowFileDim, true); 0334 0335 d->showPhotoMake = group.readEntry(d->configShowPhotoMake, true); 0336 d->showPhotoLens = group.readEntry(d->configShowPhotoLens, true); 0337 d->showPhotoFocal = group.readEntry(d->configShowPhotoFocal, true); 0338 d->showPhotoExpo = group.readEntry(d->configShowPhotoExpo, true); 0339 d->showPhotoFlash = group.readEntry(d->configShowPhotoFlash, false); 0340 d->showPhotoWB = group.readEntry(d->configShowPhotoWB, false); 0341 d->showPhotoDate = group.readEntry(d->configShowPhotoDate, true); 0342 d->showPhotoMode = group.readEntry(d->configShowPhotoMode, true); 0343 0344 d->toolTipsFont = group.readEntry(d->configToolTipsFont, QFontDatabase::systemFont(QFontDatabase::GeneralFont)); 0345 } 0346 0347 QString ShowfotoSettings::getLastOpenedDir() const 0348 { 0349 return d->lastOpenedDir; 0350 } 0351 0352 bool ShowfotoSettings::getDeleteItem2Trash() const 0353 { 0354 return d->deleteItem2Trash; 0355 } 0356 0357 QString ShowfotoSettings::getCurrentTheme() const 0358 { 0359 return d->theme; 0360 } 0361 0362 int ShowfotoSettings::getUpdateType() const 0363 { 0364 return d->updateType; 0365 } 0366 0367 bool ShowfotoSettings::getUpdateWithDebug() const 0368 { 0369 return d->updateWithDebug; 0370 } 0371 0372 int ShowfotoSettings::getRightSideBarStyle() const 0373 { 0374 return d->rightSideBarStyle; 0375 } 0376 0377 bool ShowfotoSettings::getShowFormatOverThumbnail() const 0378 { 0379 return d->showFormatOverThumbnail; 0380 } 0381 0382 bool ShowfotoSettings::getShowCoordinates() const 0383 { 0384 return d->showCoordinates; 0385 } 0386 0387 QString ShowfotoSettings::getApplicationStyle() const 0388 { 0389 return d->applicationStyle; 0390 } 0391 0392 QString ShowfotoSettings::getIconTheme() const 0393 { 0394 return d->applicationIcon; 0395 } 0396 0397 QFont ShowfotoSettings::getApplicationFont() const 0398 { 0399 return d->applicationFont; 0400 } 0401 0402 bool ShowfotoSettings::getShowSplash() const 0403 { 0404 return d->showSplash; 0405 } 0406 0407 bool ShowfotoSettings::getNativeFileDialog() const 0408 { 0409 return d->nativeFileDialog; 0410 } 0411 0412 bool ShowfotoSettings::getItemCenter() const 0413 { 0414 return d->itemCenter; 0415 } 0416 0417 int ShowfotoSettings::getSortRole() const 0418 { 0419 return d->sortOrder; 0420 } 0421 0422 bool ShowfotoSettings::getReverseSort() const 0423 { 0424 return d->reverseSort; 0425 } 0426 0427 bool ShowfotoSettings::getShowToolTip() const 0428 { 0429 return d->showToolTip; 0430 } 0431 0432 bool ShowfotoSettings::getShowFileName() const 0433 { 0434 return d->showFileName; 0435 } 0436 0437 bool ShowfotoSettings::getShowFileDate() const 0438 { 0439 return d->showFileDate; 0440 } 0441 0442 bool ShowfotoSettings::getShowFileSize() const 0443 { 0444 return d->showFileSize; 0445 } 0446 0447 bool ShowfotoSettings::getShowFileType() const 0448 { 0449 return d->showFileType; 0450 } 0451 0452 bool ShowfotoSettings::getShowFileDim() const 0453 { 0454 return d->showFileDim; 0455 } 0456 0457 bool ShowfotoSettings::getShowPhotoMake() const 0458 { 0459 return d->showPhotoMake; 0460 } 0461 0462 bool ShowfotoSettings::getShowPhotoLens() const 0463 { 0464 return d->showPhotoLens; 0465 } 0466 0467 bool ShowfotoSettings::getShowPhotoFocal() const 0468 { 0469 return d->showPhotoFocal; 0470 } 0471 0472 bool ShowfotoSettings::getShowPhotoExpo() const 0473 { 0474 return d->showPhotoExpo; 0475 } 0476 0477 bool ShowfotoSettings::getShowPhotoFlash() const 0478 { 0479 return d->showPhotoFlash; 0480 } 0481 0482 bool ShowfotoSettings::getShowPhotoWB() const 0483 { 0484 return d->showPhotoWB; 0485 } 0486 0487 bool ShowfotoSettings::getShowPhotoDate() const 0488 { 0489 return d->showPhotoDate; 0490 } 0491 0492 bool ShowfotoSettings::getShowPhotoMode() const 0493 { 0494 return d->showPhotoMode; 0495 } 0496 0497 QFont ShowfotoSettings::getToolTipFont() const 0498 { 0499 return d->toolTipsFont; 0500 } 0501 0502 void ShowfotoSettings::setShowToolTip(bool show) 0503 { 0504 d->group.writeEntry(d->configShowToolTip, show); 0505 } 0506 0507 void ShowfotoSettings::setShowFileName(bool show) 0508 { 0509 d->group.writeEntry(d->configShowFileName, show); 0510 } 0511 0512 void ShowfotoSettings::setShowFileDate(bool show) 0513 { 0514 d->group.writeEntry(d->configShowFileDate, show); 0515 } 0516 0517 void ShowfotoSettings::setShowFileSize(bool show) 0518 { 0519 d->group.writeEntry(d->configShowFileSize, show); 0520 } 0521 0522 void ShowfotoSettings::setShowFileType(bool show) 0523 { 0524 d->group.writeEntry(d->configShowFileType, show); 0525 } 0526 0527 void ShowfotoSettings::setShowFileDim(bool show) 0528 { 0529 d->group.writeEntry(d->configShowFileDim, show); 0530 } 0531 0532 void ShowfotoSettings::setShowPhotoMake(bool show) 0533 { 0534 d->group.writeEntry(d->configShowPhotoMake, show); 0535 } 0536 0537 void ShowfotoSettings::setShowPhotoLens(bool show) 0538 { 0539 d->group.writeEntry(d->configShowPhotoLens, show); 0540 } 0541 0542 void ShowfotoSettings::setShowPhotoFocal(bool show) 0543 { 0544 d->group.writeEntry(d->configShowPhotoFocal, show); 0545 } 0546 0547 void ShowfotoSettings::setShowPhotoExpo(bool show) 0548 { 0549 d->group.writeEntry(d->configShowPhotoExpo, show); 0550 } 0551 0552 void ShowfotoSettings::setShowPhotoFlash(bool show) 0553 { 0554 d->group.writeEntry(d->configShowPhotoFlash, show); 0555 } 0556 0557 void ShowfotoSettings::setShowPhotoWB(bool show) 0558 { 0559 d->group.writeEntry(d->configShowPhotoWB, show); 0560 } 0561 0562 void ShowfotoSettings::setShowPhotoDate(bool show) 0563 { 0564 d->group.writeEntry(d->configShowPhotoDate, show); 0565 } 0566 0567 void ShowfotoSettings::setShowPhotoMode(bool show) 0568 { 0569 d->group.writeEntry(d->configShowPhotoMode, show); 0570 } 0571 0572 void ShowfotoSettings::setToolTipFont(const QFont& font) 0573 { 0574 d->group.writeEntry(d->configToolTipsFont, font); 0575 } 0576 0577 void ShowfotoSettings::setLastOpenedDir(const QString& dir) 0578 { 0579 d->group.writeEntry(d->configLastOpenedDir, dir); 0580 } 0581 0582 void ShowfotoSettings::setDeleteItem2Trash(bool D2t) 0583 { 0584 d->group.writeEntry(d->configDeleteItem2Trash, D2t); 0585 } 0586 0587 void ShowfotoSettings::setCurrentTheme(const QString& theme) 0588 { 0589 d->group.writeEntry(d->configCurrentTheme, theme); 0590 } 0591 0592 void ShowfotoSettings::setUpdateType(int type) 0593 { 0594 d->group.writeEntry(d->configUpdateType, type); 0595 } 0596 0597 void ShowfotoSettings::setUpdateWithDebug(bool dbg) 0598 { 0599 d->group.writeEntry(d->configUpdateWithDebug, dbg); 0600 } 0601 0602 void ShowfotoSettings::setRightSideBarStyle(int style) 0603 { 0604 d->group.writeEntry(d->configRightSideBarStyle, style); 0605 } 0606 0607 void ShowfotoSettings::setApplicationStyle(const QString& style) 0608 { 0609 if (d->applicationStyle.compare(style, Qt::CaseInsensitive) != 0) 0610 { 0611 d->applicationStyle = style; 0612 qApp->setStyle(d->applicationStyle); 0613 qApp->style()->polish(qApp); 0614 qCDebug(DIGIKAM_SHOWFOTO_LOG) << "Switch to widget style: " << d->applicationStyle; 0615 d->group.writeEntry(d->configApplicationStyle, d->applicationStyle); 0616 } 0617 } 0618 0619 void ShowfotoSettings::setIconTheme(const QString& theme) 0620 { 0621 d->group.writeEntry(d->configIconTheme, theme); 0622 } 0623 0624 void ShowfotoSettings::setApplicationFont(const QFont& font) 0625 { 0626 if (d->applicationFont != font) 0627 { 0628 d->applicationFont = font; 0629 qApp->setFont(d->applicationFont); 0630 qCDebug(DIGIKAM_SHOWFOTO_LOG) << "Switch to application font: " << d->applicationFont; 0631 d->group.writeEntry(d->configApplicationFont, d->applicationFont); 0632 } 0633 } 0634 0635 void ShowfotoSettings::setShowFormatOverThumbnail(bool show) 0636 { 0637 d->group.writeEntry(d->configShowFormatOverThumbnail, show); 0638 } 0639 0640 void ShowfotoSettings::setShowCoordinates(bool show) 0641 { 0642 d->group.writeEntry(d->configShowCoordinates, show); 0643 } 0644 0645 void ShowfotoSettings::setShowSplash(bool show) 0646 { 0647 d->group.writeEntry(d->configShowSplash, show); 0648 } 0649 0650 void ShowfotoSettings::setNativeFileDialog(bool item) 0651 { 0652 d->group.writeEntry(d->configNativeFileDialog, item); 0653 } 0654 0655 void ShowfotoSettings::setItemCenter(bool item) 0656 { 0657 d->group.writeEntry(d->configItemCenter, item); 0658 } 0659 0660 void ShowfotoSettings::setSortRole(int order) 0661 { 0662 d->group.writeEntry(d->configSortOrder, order); 0663 } 0664 0665 void ShowfotoSettings::setReverseSort(bool reverse) 0666 { 0667 d->group.writeEntry(d->configReverseSort, reverse); 0668 } 0669 0670 void ShowfotoSettings::syncConfig() 0671 { 0672 d->config->sync(); 0673 } 0674 0675 } // namespace Showfoto 0676 0677 #include "moc_showfotosettings.cpp"