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

# Cppcheck report - digiKam-nl-search-more-criteria-rev-e2466e0973: ../../core/libs/metadataengine/dmetadata/dmetadatasettings.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
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2015-06-22
     * Description : central place for metadata settings
     *
     * SPDX-FileCopyrightText: 2015      by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
     * SPDX-FileCopyrightText: 2015-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "dmetadatasettings.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 DMetadataSettings::Private
    {
    public:

        Private() = default;

        DMetadataSettingsContainer settings;
        QMutex                     mutex;

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

    public:

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

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

        return s;
    }

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

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

        return old;
    }

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

    class Q_DECL_HIDDEN DMetadataSettingsCreator
    {
    public:

        DMetadataSettings object;
    };

    Q_GLOBAL_STATIC(DMetadataSettingsCreator, creator)

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

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

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

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

    DMetadataSettingsContainer DMetadataSettings::settings() const
    {
        QMutexLocker lock(&d->mutex);
        DMetadataSettingsContainer s(d->settings);

        return s;
    }

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

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

        d->writeToConfig();
    }

    void DMetadataSettings::readFromConfig()
    {
        DMetadataSettingsContainer s   = d->readFromConfig();
        DMetadataSettingsContainer old = d->setSettings(s);

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

    } // namespace Digikam

    #include "moc_dmetadatasettings.cpp"