File indexing completed on 2025-01-05 03:57:13

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2003-16-10
0007  * Description : application settings interface
0008  *
0009  * SPDX-FileCopyrightText: 2003-2004 by Renchi Raju <renchi dot raju at gmail dot com>
0010  * SPDX-FileCopyrightText: 2003-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2007      by Arnd Baecker <arnd dot baecker at web dot de>
0012  * SPDX-FileCopyrightText: 2014      by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0013  * SPDX-FileCopyrightText: 2014      by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
0014  * SPDX-FileCopyrightText: 2017      by Simon Frei <freisim93 at gmail dot com>
0015  *
0016  * SPDX-License-Identifier: GPL-2.0-or-later
0017  *
0018  * ============================================================ */
0019 
0020 #include "applicationsettings_p.h"
0021 
0022 namespace Digikam
0023 {
0024 
0025 int ApplicationSettings::getUpdateType() const
0026 {
0027     return d->updateType;
0028 }
0029 
0030 void ApplicationSettings::setUpdateType(int type)
0031 {
0032     d->updateType = type;
0033 }
0034 
0035 bool ApplicationSettings::getUpdateWithDebug() const
0036 {
0037     return d->updateWithDebug;
0038 }
0039 
0040 void ApplicationSettings::setUpdateWithDebug(bool dbg)
0041 {
0042     d->updateWithDebug = dbg;
0043 }
0044 
0045 void ApplicationSettings::setCurrentTheme(const QString& theme)
0046 {
0047     d->currentTheme = theme;
0048 }
0049 
0050 QString ApplicationSettings::getCurrentTheme() const
0051 {
0052     return d->currentTheme;
0053 }
0054 
0055 void ApplicationSettings::setShowSplashScreen(bool val)
0056 {
0057     d->showSplash = val;
0058 }
0059 
0060 bool ApplicationSettings::getShowSplashScreen() const
0061 {
0062     return d->showSplash;
0063 }
0064 
0065 void ApplicationSettings::setSidebarTitleStyle(DMultiTabBar::TextStyle style)
0066 {
0067     d->sidebarTitleStyle = style;
0068 }
0069 
0070 DMultiTabBar::TextStyle ApplicationSettings::getSidebarTitleStyle() const
0071 {
0072     return d->sidebarTitleStyle;
0073 }
0074 
0075 void ApplicationSettings::setUseTrash(bool val)
0076 {
0077     d->useTrash = val;
0078 }
0079 
0080 bool ApplicationSettings::getUseTrash() const
0081 {
0082     return d->useTrash;
0083 }
0084 
0085 void ApplicationSettings::setShowTrashDeleteDialog(bool val)
0086 {
0087     d->showTrashDeleteDialog = val;
0088 }
0089 
0090 bool ApplicationSettings::getShowTrashDeleteDialog() const
0091 {
0092     return d->showTrashDeleteDialog;
0093 }
0094 
0095 void ApplicationSettings::setShowPermanentDeleteDialog(bool val)
0096 {
0097     d->showPermanentDeleteDialog = val;
0098 }
0099 
0100 bool ApplicationSettings::getShowPermanentDeleteDialog() const
0101 {
0102     return d->showPermanentDeleteDialog;
0103 }
0104 
0105 void ApplicationSettings::setApplySidebarChangesDirectly(bool val)
0106 {
0107     d->sidebarApplyDirectly = val;
0108 }
0109 
0110 bool ApplicationSettings::getApplySidebarChangesDirectly() const
0111 {
0112     return d->sidebarApplyDirectly;
0113 }
0114 
0115 void ApplicationSettings::setUseNativeFileDialog(bool val)
0116 {
0117     d->useNativeFileDialog = val;
0118 }
0119 
0120 bool ApplicationSettings::getUseNativeFileDialog() const
0121 {
0122     return d->useNativeFileDialog;
0123 }
0124 
0125 void ApplicationSettings::setDrawFramesToGrouped(bool val)
0126 {
0127     d->drawFramesToGrouped = val;
0128 }
0129 
0130 bool ApplicationSettings::getDrawFramesToGrouped() const
0131 {
0132     return d->drawFramesToGrouped;
0133 }
0134 
0135 void ApplicationSettings::setExpandNewCurrentItem(bool val)
0136 {
0137     d->expandNewCurrentItem = val;
0138 }
0139 
0140 bool ApplicationSettings::getExpandNewCurrentItem() const
0141 {
0142     return d->expandNewCurrentItem;
0143 }
0144 
0145 void ApplicationSettings::setScrollItemToCenter(bool val)
0146 {
0147     d->scrollItemToCenter = val;
0148 }
0149 
0150 bool ApplicationSettings::getScrollItemToCenter() const
0151 {
0152     return d->scrollItemToCenter;
0153 }
0154 
0155 void ApplicationSettings::setShowOnlyPersonTagsInPeopleSidebar(bool val)
0156 {
0157     d->showOnlyPersonTagsInPeopleSidebar = val;
0158 }
0159 
0160 bool ApplicationSettings::showOnlyPersonTagsInPeopleSidebar() const
0161 {
0162     return d->showOnlyPersonTagsInPeopleSidebar;
0163 }
0164 
0165 void ApplicationSettings::setDetectFacesInNewImages(bool val)
0166 {
0167     d->detectFacesInNewImages = val;
0168 }
0169 
0170 bool ApplicationSettings::getDetectFacesInNewImages() const
0171 {
0172     return d->detectFacesInNewImages;
0173 }
0174 
0175 void ApplicationSettings::setStringComparisonType(ApplicationSettings::StringComparisonType val)
0176 {
0177     d->stringComparisonType = val;
0178 }
0179 
0180 ApplicationSettings::StringComparisonType ApplicationSettings::getStringComparisonType() const
0181 {
0182     return d->stringComparisonType;
0183 }
0184 
0185 bool ApplicationSettings::isStringTypeNatural() const
0186 {
0187     return (d->stringComparisonType == ApplicationSettings::Natural);
0188 }
0189 
0190 void ApplicationSettings::setVersionManagerSettings(const VersionManagerSettings& settings)
0191 {
0192     d->versionSettings = settings;
0193 }
0194 
0195 VersionManagerSettings ApplicationSettings::getVersionManagerSettings() const
0196 {
0197     return d->versionSettings;
0198 }
0199 
0200 double ApplicationSettings::getFaceDetectionAccuracy() const
0201 {
0202     return d->faceDetectionAccuracy;
0203 }
0204 
0205 void ApplicationSettings::setFaceDetectionAccuracy(double value)
0206 {
0207     d->faceDetectionAccuracy = value;
0208 }
0209 
0210 bool ApplicationSettings::getFaceDetectionYoloV3() const
0211 {
0212     return d->faceDetectionYoloV3;
0213 }
0214 
0215 void ApplicationSettings::setFaceDetectionYoloV3(bool yolo)
0216 {
0217     d->faceDetectionYoloV3 = yolo;
0218 }
0219 
0220 void ApplicationSettings::setApplicationStyle(const QString& style)
0221 {
0222     if (d->applicationStyle.compare(style, Qt::CaseInsensitive) != 0)
0223     {
0224         d->applicationStyle = style;
0225         qApp->setStyle(d->applicationStyle);
0226         qApp->style()->polish(qApp);
0227         qCDebug(DIGIKAM_GENERAL_LOG) << "Switch to widget style: " << d->applicationStyle;
0228     }
0229 }
0230 
0231 QString ApplicationSettings::getApplicationStyle() const
0232 {
0233     return d->applicationStyle;
0234 }
0235 
0236 void ApplicationSettings::setIconTheme(const QString& theme)
0237 {
0238     d->applicationIcon = theme;
0239 }
0240 
0241 QString ApplicationSettings::getIconTheme() const
0242 {
0243     return d->applicationIcon;
0244 }
0245 
0246 void ApplicationSettings::setShowThumbbar(bool val)
0247 {
0248     d->showThumbbar = val;
0249 }
0250 
0251 bool ApplicationSettings::getShowThumbbar() const
0252 {
0253     return d->showThumbbar;
0254 }
0255 
0256 void ApplicationSettings::setRatingFilterCond(int val)
0257 {
0258     d->ratingFilterCond = val;
0259 }
0260 
0261 int ApplicationSettings::getRatingFilterCond() const
0262 {
0263     return d->ratingFilterCond;
0264 }
0265 
0266 void ApplicationSettings::setScanAtStart(bool val)
0267 {
0268     d->scanAtStart = val;
0269 }
0270 
0271 bool ApplicationSettings::getScanAtStart() const
0272 {
0273     return d->scanAtStart;
0274 }
0275 
0276 void ApplicationSettings::setCleanAtStart(bool val)
0277 {
0278     d->cleanAtStart = val;
0279 }
0280 
0281 bool ApplicationSettings::getCleanAtStart() const
0282 {
0283     return d->cleanAtStart;
0284 }
0285 
0286 void ApplicationSettings::setDatabaseDirSetAtCmd(bool val)
0287 {
0288     d->databaseDirSetAtCmd = val;
0289 }
0290 
0291 bool ApplicationSettings::getDatabaseDirSetAtCmd() const
0292 {
0293     return d->databaseDirSetAtCmd;
0294 }
0295 
0296 void ApplicationSettings::setMinimumSimilarityBound(int val)
0297 {
0298     d->minimumSimilarityBound = val;
0299 }
0300 
0301 int  ApplicationSettings::getMinimumSimilarityBound() const
0302 {
0303     return d->minimumSimilarityBound;
0304 }
0305 
0306 void ApplicationSettings::setDuplicatesSearchLastMinSimilarity(int val)
0307 {
0308     d->duplicatesSearchLastMinSimilarity = val;
0309 }
0310 
0311 int  ApplicationSettings::getDuplicatesSearchLastMinSimilarity() const
0312 {
0313     return d->duplicatesSearchLastMinSimilarity;
0314 }
0315 
0316 void ApplicationSettings::setDuplicatesSearchLastMaxSimilarity(int val)
0317 {
0318     d->duplicatesSearchLastMaxSimilarity = val;
0319 }
0320 
0321 int  ApplicationSettings::getDuplicatesSearchLastMaxSimilarity() const
0322 {
0323     return d->duplicatesSearchLastMaxSimilarity;
0324 }
0325 
0326 void ApplicationSettings::setDuplicatesAlbumTagRelation(int val)
0327 {
0328     d->duplicatesSearchLastAlbumTagRelation = val;
0329 }
0330 
0331 int  ApplicationSettings::getDuplicatesAlbumTagRelation() const
0332 {
0333     return d->duplicatesSearchLastAlbumTagRelation;
0334 }
0335 
0336 void ApplicationSettings::setDuplicatesReferenceImageSelectionMethod(HaarIface::RefImageSelMethod val)
0337 {
0338     d->duplicatesSearchLastReferenceImageSelectionMethod = val;
0339 }
0340 
0341 HaarIface::RefImageSelMethod ApplicationSettings::getDuplicatesRefImageSelMethod() const
0342 {
0343     return d->duplicatesSearchLastReferenceImageSelectionMethod;
0344 }
0345 
0346 
0347 void ApplicationSettings::setDuplicatesSearchRestrictions(int val)
0348 {
0349     d->duplicatesSearchLastRestrictions = val;
0350 }
0351 
0352 int  ApplicationSettings::getDuplicatesSearchRestrictions() const
0353 {
0354     return d->duplicatesSearchLastRestrictions;
0355 }
0356 
0357 void ApplicationSettings::setGroupingOperateOnAll(ApplicationSettings::OperationType type,
0358                                                   ApplicationSettings::ApplyToEntireGroup applyAll)
0359 {
0360     if (!d->groupingOperateOnAll.contains(type))
0361     {
0362         throw std::invalid_argument("ApplicationSettings::setGroupingOperateOnAll: Invalid operation type.");
0363     }
0364 
0365     d->groupingOperateOnAll[type] = applyAll;
0366     return;
0367 }
0368 
0369 ApplicationSettings::ApplyToEntireGroup ApplicationSettings::getGroupingOperateOnAll(
0370         ApplicationSettings::OperationType type) const
0371 {
0372     if (!d->groupingOperateOnAll.contains(type))
0373     {
0374         throw std::invalid_argument("ApplicationSettings::getGroupingOperateOnAll: Invalid operation type.");
0375     }
0376 
0377     if (type == ApplicationSettings::Unspecified)
0378     {
0379         return ApplicationSettings::No;
0380     }
0381 
0382     return d->groupingOperateOnAll[type];
0383 }
0384 
0385 bool ApplicationSettings::askGroupingOperateOnAll(ApplicationSettings::OperationType type)
0386 {
0387     if (!d->groupingOperateOnAll.contains(type))
0388     {
0389         throw std::invalid_argument("ApplicationSettings::askGroupingOperateOnAll: Invalid operation type.");
0390     }
0391 
0392     if (type == ApplicationSettings::Unspecified)
0393     {
0394         return false;
0395     }
0396 
0397     QPointer<QMessageBox> msgBox = new QMessageBox(qApp->activeWindow());
0398     msgBox->setWindowTitle(qApp->applicationName());
0399     msgBox->setStandardButtons(QMessageBox::No | QMessageBox::Yes);
0400     msgBox->setText(QLatin1String("<p>") + ApplicationSettings::operationTypeTitle(type) +
0401                     QLatin1String("</p>") + i18n("Do you want to do this operation on all group items?"));
0402 
0403     QCheckBox* const chkBox = new QCheckBox(i18n("Remember choice for this operation"), msgBox);
0404     msgBox->setCheckBox(chkBox);
0405 
0406     if (msgBox->exec() == QMessageBox::No)
0407     {
0408         if (chkBox->isChecked())
0409         {
0410             setGroupingOperateOnAll(type, ApplicationSettings::No);
0411         }
0412 
0413         return false;
0414     }
0415 
0416     if (chkBox->isChecked())
0417     {
0418         setGroupingOperateOnAll(type, ApplicationSettings::Yes);
0419     }
0420 
0421     delete msgBox;
0422 
0423     return true;
0424 }
0425 
0426 QString ApplicationSettings::operationTypeTitle(ApplicationSettings::OperationType type)
0427 {
0428     switch (type)
0429     {
0430         case ApplicationSettings::Metadata:
0431             return i18n("Metadata");
0432 
0433         case ApplicationSettings::LightTable:
0434             return i18n("Light Table");
0435 
0436         case ApplicationSettings::BQM:
0437             return i18n("Batch Queue Manager");
0438 
0439         case ApplicationSettings::Slideshow:
0440             return i18n("Slideshow");
0441 
0442         case ApplicationSettings::Rename:
0443             return i18n("Renaming");
0444 
0445         case ApplicationSettings::ImportExport:
0446             return i18n("Import/Export tools");
0447 
0448         case ApplicationSettings::Tools:
0449             return i18n("Tools (editor, panorama, stack blending, calendar, "
0450                         "external program)");
0451         default:
0452             throw std::invalid_argument("ApplicationSettings::operationTypeTitle: Invalid operation type.");
0453     }
0454 }
0455 
0456 QString ApplicationSettings::operationTypeExplanation(ApplicationSettings::OperationType type)
0457 {
0458     switch (type)
0459     {
0460         case ApplicationSettings::Metadata:
0461             return i18n("Operations related to metadata, labels, ratings, tags, geolocation and rotation");
0462 
0463         case ApplicationSettings::LightTable:
0464             return i18n("Adding items to the Light Table");
0465 
0466         case ApplicationSettings::BQM:
0467             return i18n("Adding items to the Batch Queue Manager");
0468 
0469         case ApplicationSettings::Slideshow:
0470             return i18n("Opening items in the Slideshow");
0471 
0472         case ApplicationSettings::Rename:
0473             return i18n("Renaming items");
0474 
0475         case ApplicationSettings::ImportExport:
0476             return i18n("Passing items to import/export tools");
0477 
0478         case ApplicationSettings::Tools:
0479             return i18n("Several tools including the editor, panorama, stack blending, "
0480                         "calendar, html gallery and opening with external programs");
0481         default:
0482             return QString();
0483     }
0484 }
0485 
0486 void ApplicationSettings::setApplicationFont(const QFont& font)
0487 {
0488     if (d->applicationFont != font)
0489     {
0490         d->applicationFont = font;
0491         qApp->setFont(d->applicationFont);
0492         qCDebug(DIGIKAM_GENERAL_LOG) << "Switch to application font: " << d->applicationFont;
0493     }
0494 }
0495 
0496 QFont ApplicationSettings::getApplicationFont() const
0497 {
0498     return d->applicationFont;
0499 }
0500 
0501 bool ApplicationSettings::getHelpBoxNotificationSeen()
0502 {
0503     KSharedConfigPtr config = KSharedConfig::openConfig();
0504     KConfigGroup group      = config->group(QLatin1String("Notification Messages"));
0505     bool value              = group.readEntry("HelpBoxNotifSeen", false);
0506 
0507     return value;
0508 }
0509 
0510 void ApplicationSettings::setHelpBoxNotificationSeen(bool val)
0511 {
0512     KSharedConfigPtr config = KSharedConfig::openConfig();
0513     KConfigGroup group      = config->group(QLatin1String("Notification Messages"));
0514 
0515     group.writeEntry("HelpBoxNotifSeen", val);
0516     config->sync();
0517 }
0518 
0519 } // namespace Digikam