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

# Cppcheck report - digiKam-nl-search-more-criteria-rev-e2466e0973: ../../core/libs/fileactionmanager/metadatastatusbar.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
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2015-08-21
     * Description : a bar to indicate pending metadata
     *
     * SPDX-FileCopyrightText: 2015 by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "metadatastatusbar.h"

    // Qt includes

    #include <QToolButton>
    #include <QHBoxLayout>
    #include <QApplication>
    #include <QStyle>
    #include <QDebug>

    // KDE includes

    #include <klocalizedstring.h>

    // Local includes

    #include "dexpanderbox.h"
    #include "metaenginesettings.h"
    #include "digikam_globals.h"

    namespace Digikam
    {

    class Q_DECL_HIDDEN MetadataStatusBar::Private
    {
    public:

        Private() = default;

        int               number    = 0;
        bool              enabled   = true;

        DAdjustableLabel* info      = nullptr;
        QToolButton*      applyBtn  = nullptr;
    };

    MetadataStatusBar::MetadataStatusBar(QWidget* const parent)
        : QWidget(parent),
          d      (new Private)
    {
        QHBoxLayout* const vlay = new QHBoxLayout(this);
        d->applyBtn             = new QToolButton(this);
        d->applyBtn->setIcon(QIcon::fromTheme(QLatin1String("view-refresh")));
        d->applyBtn->setToolTip(i18n("Apply pending changes to metadata"));
        d->applyBtn->setFocusPolicy(Qt::NoFocus);
        d->applyBtn->setAutoRaise(true);
        d->applyBtn->setDisabled(true);

        d->info                 = new DAdjustableLabel(this);
        d->info->setContextMenuPolicy(Qt::NoContextMenu);
        d->info->setAutoFillBackground(true);
        d->info->setFocusPolicy(Qt::NoFocus);
        d->info->setAdjustedText(i18n("No pending metadata synchronization"));

        d->info->setWhatsThis(i18n("If lazy synchronization is enabled in metadata settings, "
                                   "the status bar will display the number of items waiting for synchronization"));

        vlay->addWidget(d->applyBtn);
        vlay->addWidget(d->info);
        vlay->setSpacing(layoutSpacing());

        vlay->setContentsMargins(QMargins());
        vlay->setStretchFactor(d->info, 10);

        connect(MetaEngineSettings::instance(), SIGNAL(signalSettingsChanged()),
                this, SLOT(slotSettingsChanged()));

        connect(d->applyBtn, SIGNAL(released()),
                MetadataHubMngr::instance(), SLOT(slotApplyPending()));

        connect(MetadataHubMngr::instance(), SIGNAL(signalPendingMetadata(int)),
                this, SLOT(slotSetPendingItems(int)));

        connect(ProgressManager::instance(), SIGNAL(progressItemAdded(ProgressItem*)),
                this, SLOT(slotAddedProgressItem(ProgressItem*)));

        connect(ProgressManager::instance(), SIGNAL(progressItemCompleted(ProgressItem*)),
                this, SLOT(slotCompletedProgressItem(ProgressItem*)));

        if (MetaEngineSettings::instance()->settings().useLazySync)
        {
            show();
        }
        else
        {
            hide();
        }
    }

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

    void MetadataStatusBar::slotSettingsChanged()
    {
        if (MetaEngineSettings::instance()->settings().useLazySync)
        {
            show();
        }
        else
        {
            hide();
        }
    }

    void MetadataStatusBar::slotSetPendingItems(int number)
    {
        d->number = number;

        if (d->number == 0)
        {
            d->info->setAdjustedText(i18n("No pending metadata synchronization"));
            d->applyBtn->setDisabled(true);
        }
        else
        {
            d->info->setAdjustedText(i18np("1 file awaits synchronization",
                                           "%1 files await synchronization",
                                           d->number));
            d->applyBtn->setEnabled(d->enabled);
        }
    }

    void MetadataStatusBar::slotAddedProgressItem(ProgressItem* item)<--- Either there is a missing override/final keyword, or the parameter 'item' can be declared as pointer to const
    {
        if (item->id() == QLatin1String("MetadataSynchronizer"))
        {
            d->applyBtn->setEnabled(false);
            d->info->setEnabled(false);
            d->enabled = false;
        }
    }

    void MetadataStatusBar::slotCompletedProgressItem(ProgressItem* item)<--- Either there is a missing override/final keyword, or the parameter 'item' can be declared as pointer to const
    {
        if (item->id() == QLatin1String("MetadataSynchronizer"))
        {
            d->applyBtn->setEnabled(d->number > 0);
            d->info->setEnabled(true);
            d->enabled = true;
        }
    }

    } // namespace Digikam

    #include "moc_metadatastatusbar.cpp"