Cppcheck - HTML report - digiKam-nl-search-more-criteria-rev-e2466e0973

# Cppcheck report - digiKam-nl-search-more-criteria-rev-e2466e0973: ../../core/libs/metadataengine/engine/metaenginesettings.cpp

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2010-08-20
     * Description : central place for MetaEngine settings
     *
     * SPDX-FileCopyrightText: 2010-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "metaenginesettings.h"

    // Qt includes

    #include <QDir>
    #include <QFileInfo>
    #include <QMutex>

    // KDE includes

    #include <kconfiggroup.h>
    #include <ksharedconfig.h>

    // Local includes

    #include "digikam_debug.h"

    namespace Digikam
    {

    class Q_DECL_HIDDEN MetaEngineSettings::Private
    {
    public:

        Private() = default;

        MetaEngineSettingsContainer settings;
        QMutex                      mutex;

        const QString               configGroup = QLatin1String("Metadata Settings");

    public:

        MetaEngineSettingsContainer readFromConfig() const;
        void                        writeToConfig()  const;
        MetaEngineSettingsContainer setSettings(const MetaEngineSettingsContainer& s);
    };

    MetaEngineSettingsContainer MetaEngineSettings::Private::readFromConfig() const
    {
        MetaEngineSettingsContainer s;
        KSharedConfig::Ptr config = KSharedConfig::openConfig();
        KConfigGroup group        = config->group(configGroup);
        s.readFromConfig(group);

        return s;
    }

    void MetaEngineSettings::Private::writeToConfig() const
    {
        KSharedConfig::Ptr config = KSharedConfig::openConfig();
        KConfigGroup group        = config->group(configGroup);
        settings.writeToConfig(group);
    }

    MetaEngineSettingsContainer MetaEngineSettings::Private::setSettings(const MetaEngineSettingsContainer& s)
    {
        QMutexLocker lock(&mutex);
        MetaEngineSettingsContainer old;
        old      = settings;
        settings = s;

        return old;
    }

    // -----------------------------------------------------------------------------------------------

    class Q_DECL_HIDDEN MetaEngineSettingsCreator
    {
    public:

        MetaEngineSettings object;
    };

    Q_GLOBAL_STATIC(MetaEngineSettingsCreator, creator)

    // -----------------------------------------------------------------------------------------------

    MetaEngineSettings::MetaEngineSettings()
        : QObject(),
          d      (new Private)
    {
        readFromConfig();
        qRegisterMetaType<MetaEngineSettingsContainer>("MetaEngineSettingsContainer");
    }

    MetaEngineSettings::~MetaEngineSettings()
    {
        delete d;
    }

    MetaEngineSettings* MetaEngineSettings::instance()
    {
        return &creator->object;
    }

    MetaEngineSettingsContainer MetaEngineSettings::settings() const
    {
        QMutexLocker lock(&d->mutex);
        MetaEngineSettingsContainer s(d->settings);

        return s;
    }

    void MetaEngineSettings::setSettings(const MetaEngineSettingsContainer& settings)<--- Shadow argument
    {
        MetaEngineSettingsContainer old = d->setSettings(settings);

        Q_EMIT signalMetaEngineSettingsChanged(settings, old);
        Q_EMIT signalSettingsChanged();

        d->writeToConfig();
    }

    bool MetaEngineSettings::isMetadataWriteEnabled() const
    {
        return d->settings.isMetadataWriteEnabled();
    }

    bool MetaEngineSettings::exifRotate() const
    {
        return d->settings.exifRotate;
    }

    void MetaEngineSettings::readFromConfig()
    {
        MetaEngineSettingsContainer s   = d->readFromConfig();
        MetaEngineSettingsContainer old = d->setSettings(s);

        Q_EMIT signalMetaEngineSettingsChanged(s, old);
        Q_EMIT signalSettingsChanged();
    }

    } // namespace Digikam

    #include "moc_metaenginesettings.cpp"