File indexing completed on 2025-01-05 03:56:30
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-08-20 0007 * Description : central place for MetaEngine settings 0008 * 0009 * SPDX-FileCopyrightText: 2010-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 "metaenginesettings.h" 0016 0017 // Qt includes 0018 0019 #include <QDir> 0020 #include <QFileInfo> 0021 #include <QMutex> 0022 0023 // KDE includes 0024 0025 #include <kconfiggroup.h> 0026 #include <ksharedconfig.h> 0027 0028 // Local includes 0029 0030 #include "digikam_debug.h" 0031 0032 namespace Digikam 0033 { 0034 0035 class Q_DECL_HIDDEN MetaEngineSettings::Private 0036 { 0037 public: 0038 0039 explicit Private () 0040 : mutex (), 0041 configGroup(QLatin1String("Metadata Settings")) 0042 { 0043 } 0044 0045 MetaEngineSettingsContainer settings; 0046 QMutex mutex; 0047 0048 const QString configGroup; 0049 0050 public: 0051 0052 MetaEngineSettingsContainer readFromConfig() const; 0053 void writeToConfig() const; 0054 MetaEngineSettingsContainer setSettings(const MetaEngineSettingsContainer& s); 0055 }; 0056 0057 MetaEngineSettingsContainer MetaEngineSettings::Private::readFromConfig() const 0058 { 0059 MetaEngineSettingsContainer s; 0060 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0061 KConfigGroup group = config->group(configGroup); 0062 s.readFromConfig(group); 0063 0064 return s; 0065 } 0066 0067 void MetaEngineSettings::Private::writeToConfig() const 0068 { 0069 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0070 KConfigGroup group = config->group(configGroup); 0071 settings.writeToConfig(group); 0072 } 0073 0074 MetaEngineSettingsContainer MetaEngineSettings::Private::setSettings(const MetaEngineSettingsContainer& s) 0075 { 0076 QMutexLocker lock(&mutex); 0077 MetaEngineSettingsContainer old; 0078 old = settings; 0079 settings = s; 0080 0081 return old; 0082 } 0083 0084 // ----------------------------------------------------------------------------------------------- 0085 0086 class Q_DECL_HIDDEN MetaEngineSettingsCreator 0087 { 0088 public: 0089 0090 MetaEngineSettings object; 0091 }; 0092 0093 Q_GLOBAL_STATIC(MetaEngineSettingsCreator, metaEngineSettingsCreator) 0094 0095 // ----------------------------------------------------------------------------------------------- 0096 0097 MetaEngineSettings* MetaEngineSettings::instance() 0098 { 0099 return &metaEngineSettingsCreator->object; 0100 } 0101 0102 MetaEngineSettings::MetaEngineSettings() 0103 : d(new Private) 0104 { 0105 readFromConfig(); 0106 qRegisterMetaType<MetaEngineSettingsContainer>("MetaEngineSettingsContainer"); 0107 } 0108 0109 MetaEngineSettings::~MetaEngineSettings() 0110 { 0111 delete d; 0112 } 0113 0114 MetaEngineSettingsContainer MetaEngineSettings::settings() const 0115 { 0116 QMutexLocker lock(&d->mutex); 0117 MetaEngineSettingsContainer s(d->settings); 0118 0119 return s; 0120 } 0121 0122 bool MetaEngineSettings::exifRotate() const 0123 { 0124 return d->settings.exifRotate; 0125 } 0126 0127 void MetaEngineSettings::setSettings(const MetaEngineSettingsContainer& settings) 0128 { 0129 MetaEngineSettingsContainer old = d->setSettings(settings); 0130 Q_EMIT signalMetaEngineSettingsChanged(settings, old); 0131 Q_EMIT signalSettingsChanged(); 0132 d->writeToConfig(); 0133 } 0134 0135 void MetaEngineSettings::readFromConfig() 0136 { 0137 MetaEngineSettingsContainer s = d->readFromConfig(); 0138 MetaEngineSettingsContainer old = d->setSettings(s); 0139 Q_EMIT signalMetaEngineSettingsChanged(s, old); 0140 Q_EMIT signalSettingsChanged(); 0141 } 0142 0143 } // namespace Digikam 0144 0145 #include "moc_metaenginesettings.cpp"