File indexing completed on 2025-01-19 03:59:31

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-01-30
0007  * Description : maintenance dialog
0008  *
0009  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "maintenancedlg_p.h"
0016 
0017 namespace Digikam
0018 {
0019 
0020 MaintenanceSettings MaintenanceDlg::settings() const
0021 {
0022     MaintenanceSettings prm;
0023     prm.wholeAlbums                         = d->albumSelectors->wholeAlbumsChecked();
0024     prm.wholeTags                           = d->albumSelectors->wholeTagsChecked();
0025     prm.albums                              = d->albumSelectors->selectedAlbums();
0026     prm.tags                                = d->albumSelectors->selectedTags();
0027     prm.useMutiCoreCPU                      = d->useMutiCoreCPU->isChecked();
0028     prm.newItems                            = d->expanderBox->isChecked(Private::NewItems);
0029     prm.databaseCleanup                     = d->expanderBox->isChecked(Private::DbCleanup);
0030     prm.cleanThumbDb                        = d->cleanThumbsDb->isChecked();
0031     prm.cleanFacesDb                        = d->cleanFacesDb->isChecked();
0032     prm.cleanSimilarityDb                   = d->cleanSimilarityDb->isChecked();
0033     prm.shrinkDatabases                     = d->shrinkDatabases->isChecked();
0034     prm.thumbnails                          = d->expanderBox->isChecked(Private::Thumbnails);
0035     prm.scanThumbs                          = d->scanThumbs->isChecked();
0036     prm.fingerPrints                        = d->expanderBox->isChecked(Private::FingerPrints);
0037     prm.scanFingerPrints                    = d->scanFingerPrints->isChecked();
0038     prm.duplicates                          = d->expanderBox->isChecked(Private::Duplicates);
0039     prm.minSimilarity                       = d->similarityRange->minValue();
0040     prm.maxSimilarity                       = d->similarityRange->maxValue();
0041     prm.duplicatesRestriction               = (HaarIface::DuplicatesSearchRestrictions)
0042                                                   d->searchResultRestriction->itemData(d->searchResultRestriction->currentIndex()).toInt();
0043     prm.faceManagement                      = d->expanderBox->isChecked(Private::FaceManagement);
0044     prm.faceSettings.alreadyScannedHandling = (FaceScanSettings::AlreadyScannedHandling)
0045                                                   d->faceScannedHandling->itemData(d->faceScannedHandling->currentIndex()).toInt();
0046     prm.faceSettings.task                   = d->retrainAllFaces->isChecked() ? FaceScanSettings::RetrainAll
0047                                                                               : FaceScanSettings::DetectAndRecognize;
0048     prm.faceSettings.albums                 = d->albumSelectors->selectedAlbums();
0049 
0050     prm.autotagsAssignment                  = d->expanderBox->isChecked(Private::AutotagsAssignment);
0051     prm.autotaggingScanMode                 = d->autotaggingScanMode->itemData(d->autotaggingScanMode->currentIndex()).toInt();
0052     prm.modelSelectionMode                  = d->modelSelectionMode->itemData(d->modelSelectionMode->currentIndex()).toInt();
0053 
0054     prm.qualitySort                         = d->expanderBox->isChecked(Private::ImageQualitySorter);
0055     prm.qualityScanMode                     = d->qualityScanMode->itemData(d->qualityScanMode->currentIndex()).toInt();
0056     prm.qualitySettingsSelected             = (int)d->qualitySelector->settingsSelected();
0057 
0058     if (prm.qualitySettingsSelected == ImageQualityConfSelector::GlobalSettings)
0059     {
0060         ImageQualityContainer imgq;
0061         imgq.readFromConfig();
0062         prm.quality                         = imgq;
0063     }
0064     else
0065     {
0066         prm.quality                         = d->qualitySelector->customSettings();
0067     }
0068 
0069     prm.metadataSync                        = d->expanderBox->isChecked(Private::MetadataSync);
0070     prm.syncDirection                       = d->syncDirection->itemData(d->syncDirection->currentIndex()).toInt();
0071 
0072     return prm;
0073 }
0074 
0075 void MaintenanceDlg::readSettings()
0076 {
0077     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0078     KConfigGroup group        = config->group(d->configGroupName);
0079     d->expanderBox->readSettings(group);
0080     d->albumSelectors->loadState();
0081 
0082     d->useLastSettings->blockSignals(true);
0083     d->useLastSettings->setChecked(group.readEntry(d->configUseLastSettings, false));
0084     d->useLastSettings->blockSignals(false);
0085 
0086     if (d->useLastSettings->isChecked())
0087     {
0088         MaintenanceSettings prm;
0089 
0090         d->useMutiCoreCPU->setChecked(group.readEntry(d->configUseMutiCoreCPU,                                  prm.useMutiCoreCPU));
0091         d->expanderBox->setChecked(Private::NewItems,           group.readEntry(d->configNewItems,              prm.newItems));
0092 
0093         d->expanderBox->setChecked(Private::DbCleanup,          group.readEntry(d->configCleanupDatabase,       prm.databaseCleanup));
0094         d->cleanThumbsDb->setChecked(group.readEntry(d->configCleanupThumbDatabase,                             prm.cleanThumbDb));
0095         d->cleanFacesDb->setChecked(group.readEntry(d->configCleanupFacesDatabase,                              prm.cleanFacesDb));
0096         d->cleanSimilarityDb->setChecked(group.readEntry(d->configCleanupSimilarityDatabase,                    prm.cleanSimilarityDb));
0097         d->shrinkDatabases->setChecked(group.readEntry(d->configShrinkDatabases,                                prm.shrinkDatabases));
0098 
0099         d->expanderBox->setChecked(Private::Thumbnails,         group.readEntry(d->configThumbnails,            prm.thumbnails));
0100         d->scanThumbs->setChecked(group.readEntry(d->configScanThumbs,                                          prm.scanThumbs));
0101 
0102         d->expanderBox->setChecked(Private::FingerPrints,       group.readEntry(d->configFingerPrints,          prm.fingerPrints));
0103         d->scanFingerPrints->setChecked(group.readEntry(d->configScanFingerPrints,                              prm.scanFingerPrints));
0104 
0105         d->expanderBox->setChecked(Private::Duplicates,         group.readEntry(d->configDuplicates,            prm.duplicates));
0106         d->similarityRange->setInterval(group.readEntry(d->configMinSimilarity,                                 prm.minSimilarity),
0107                                         group.readEntry(d->configMaxSimilarity,                                 prm.maxSimilarity));
0108         int restrictions = d->searchResultRestriction->findData(group.readEntry(d->configDuplicatesRestriction, (int)prm.duplicatesRestriction));
0109         d->searchResultRestriction->setCurrentIndex(restrictions);
0110 
0111         d->expanderBox->setChecked(Private::FaceManagement,     group.readEntry(d->configFaceManagement,        prm.faceManagement));
0112         int faceHandling = d->faceScannedHandling->findData(group.readEntry(d->configFaceScannedHandling,       (int)prm.faceSettings.alreadyScannedHandling));
0113         d->faceScannedHandling->setCurrentIndex(faceHandling);
0114 
0115         d->expanderBox->setChecked(Private::AutotagsAssignment, group.readEntry(d->configAutotagsAssignment,    prm.autotagsAssignment));
0116         int tagScanMode  = d->autotaggingScanMode->findData(group.readEntry(d->configAutotaggingScanMode,       prm.autotaggingScanMode));
0117         d->autotaggingScanMode->setCurrentIndex(tagScanMode);
0118         int tagSelection = d->modelSelectionMode->findData(group.readEntry(d->configModelSelectionMode,         prm.modelSelectionMode));
0119         d->modelSelectionMode->setCurrentIndex(tagSelection);
0120 
0121         d->expanderBox->setChecked(Private::ImageQualitySorter, group.readEntry(d->configImageQualitySorter,    prm.qualitySort));
0122         int qualityMod   = d->qualityScanMode->findData(group.readEntry(d->configQualityScanMode,               prm.qualityScanMode));
0123         d->qualityScanMode->setCurrentIndex(qualityMod);
0124         d->qualitySelector->setSettingsSelected(
0125             (ImageQualityConfSelector::SettingsType)group.readEntry(d->configQualitySettingsSelected,           prm.qualitySettingsSelected));
0126 
0127         ImageQualityContainer imq;
0128         imq.readFromConfig(group);
0129         d->qualitySelector->setCustomSettings(imq);
0130 
0131         d->expanderBox->setChecked(Private::MetadataSync,       group.readEntry(d->configMetadataSync,          prm.metadataSync));
0132         int direction    = d->syncDirection->findData(group.readEntry(d->configSyncDirection,                   prm.syncDirection));
0133         d->syncDirection->setCurrentIndex(direction);
0134     }
0135 
0136     for (int i = Private::NewItems ; i < Private::Stretch ; ++i)
0137     {
0138         slotItemToggled(i, d->expanderBox->isChecked(i));
0139     }
0140 
0141     winId();
0142     DXmlGuiWindow::setGoodDefaultWindowSize(windowHandle());
0143     DXmlGuiWindow::restoreWindowSize(windowHandle(), group);
0144     resize(windowHandle()->size());
0145 }
0146 
0147 void MaintenanceDlg::writeSettings()
0148 {
0149     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0150     KConfigGroup group        = config->group(d->configGroupName);
0151     d->expanderBox->writeSettings(group);
0152     d->albumSelectors->saveState();
0153 
0154     group.writeEntry(d->configUseLastSettings, d->useLastSettings->isChecked());
0155 
0156     if (d->useLastSettings->isChecked())
0157     {
0158         MaintenanceSettings prm   = settings();
0159 
0160         group.writeEntry(d->configUseMutiCoreCPU,             prm.useMutiCoreCPU);
0161         group.writeEntry(d->configNewItems,                   prm.newItems);
0162         group.writeEntry(d->configCleanupDatabase,            prm.databaseCleanup);
0163         group.writeEntry(d->configCleanupThumbDatabase,       prm.cleanThumbDb);
0164         group.writeEntry(d->configCleanupFacesDatabase,       prm.cleanFacesDb);
0165         group.writeEntry(d->configCleanupSimilarityDatabase,  prm.cleanSimilarityDb);
0166         group.writeEntry(d->configShrinkDatabases,            prm.shrinkDatabases);
0167         group.writeEntry(d->configThumbnails,                 prm.thumbnails);
0168         group.writeEntry(d->configScanThumbs,                 prm.scanThumbs);
0169         group.writeEntry(d->configFingerPrints,               prm.fingerPrints);
0170         group.writeEntry(d->configScanFingerPrints,           prm.scanFingerPrints);
0171         group.writeEntry(d->configDuplicates,                 prm.duplicates);
0172         group.writeEntry(d->configMinSimilarity,              prm.minSimilarity);
0173         group.writeEntry(d->configMaxSimilarity,              prm.maxSimilarity);
0174         group.writeEntry(d->configDuplicatesRestriction,      (int)prm.duplicatesRestriction);
0175         group.writeEntry(d->configFaceManagement,             prm.faceManagement);
0176         group.writeEntry(d->configFaceScannedHandling,        (int)prm.faceSettings.alreadyScannedHandling);
0177         group.writeEntry(d->configAutotagsAssignment,         prm.autotagsAssignment);
0178         group.writeEntry(d->configAutotaggingScanMode,        prm.autotaggingScanMode);
0179         group.writeEntry(d->configModelSelectionMode,         prm.modelSelectionMode);
0180         group.writeEntry(d->configImageQualitySorter,         prm.qualitySort);
0181         group.writeEntry(d->configQualityScanMode,            prm.qualityScanMode);
0182         group.writeEntry(d->configQualitySettingsSelected,    prm.qualitySettingsSelected);
0183 
0184         ImageQualityContainer imq = d->qualitySelector->customSettings();
0185         imq.writeToConfig(group);
0186 
0187         group.writeEntry(d->configMetadataSync,               prm.metadataSync);
0188         group.writeEntry(d->configSyncDirection,              prm.syncDirection);
0189     }
0190 
0191     DXmlGuiWindow::saveWindowSize(windowHandle(), group);
0192 }
0193 
0194 void MaintenanceDlg::slotUseLastSettings(bool checked)
0195 {
0196     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0197     KConfigGroup group        = config->group(d->configGroupName);
0198 
0199     group.writeEntry(d->configUseLastSettings, d->useLastSettings->isChecked());
0200 
0201     if (checked)
0202     {
0203         readSettings();
0204     }
0205     else
0206     {
0207         MaintenanceSettings prm;
0208 
0209         d->useMutiCoreCPU->setChecked(prm.useMutiCoreCPU);
0210         d->expanderBox->setChecked(Private::NewItems,           prm.newItems);
0211 
0212         d->expanderBox->setChecked(Private::DbCleanup,          prm.databaseCleanup);
0213         d->cleanThumbsDb->setChecked(prm.cleanThumbDb);
0214         d->cleanFacesDb->setChecked(prm.cleanFacesDb);
0215         d->cleanSimilarityDb->setChecked(prm.cleanSimilarityDb);
0216         d->shrinkDatabases->setChecked(prm.shrinkDatabases);
0217 
0218         d->expanderBox->setChecked(Private::Thumbnails,         prm.thumbnails);
0219         d->scanThumbs->setChecked(prm.scanThumbs);
0220 
0221         d->expanderBox->setChecked(Private::FingerPrints,       prm.fingerPrints);
0222         d->scanFingerPrints->setChecked(prm.scanFingerPrints);
0223 
0224         d->expanderBox->setChecked(Private::Duplicates,         prm.duplicates);
0225         d->similarityRange->setInterval(prm.minSimilarity,      prm.maxSimilarity);
0226         int restrictions = d->searchResultRestriction->findData(prm.duplicatesRestriction);
0227         d->searchResultRestriction->setCurrentIndex(restrictions);
0228 
0229         d->expanderBox->setChecked(Private::FaceManagement,     prm.faceManagement);
0230         d->faceScannedHandling->setCurrentIndex(prm.faceSettings.alreadyScannedHandling);
0231 
0232         d->expanderBox->setChecked(Private::AutotagsAssignment, prm.autotagsAssignment);
0233         d->autotaggingScanMode->setCurrentIndex(prm.autotaggingScanMode);
0234 
0235         d->expanderBox->setChecked(Private::ImageQualitySorter, prm.qualitySort);
0236         d->qualityScanMode->setCurrentIndex(prm.qualityScanMode);
0237 
0238         d->expanderBox->setChecked(Private::MetadataSync,       prm.metadataSync);
0239         d->syncDirection->setCurrentIndex(prm.syncDirection);
0240     }
0241 }
0242 
0243 } // namespace Digikam