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
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2012-01-26
 * Description : a progress bar with information dispatched to progress manager
 *
 * SPDX-FileCopyrightText: 2012-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#include "dprogresswdg.h"

// Qt includes

#include <QString>
#include <QIcon>

// Local includes

#include "progressmanager.h"

namespace Digikam
{

class Q_DECL_HIDDEN DProgressWdg::Private
{
public:

    Private() = default;

    ProgressItem* findProgressItem() const
    {
        return ProgressManager::instance()->findItembyId(progressId);
    }

public:

    QString progressId;
};

DProgressWdg::DProgressWdg(QWidget* const parent)
    : QProgressBar(parent),
      d           (new Private)
{
    connect(this, &DProgressWdg::valueChanged,
            this, &DProgressWdg::slotValueChanged);
}

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

void DProgressWdg::slotValueChanged(int)
{
    float percents           = ((float)value() / (float)maximum()) * 100.0;
    ProgressItem* const item = d->findProgressItem();

    if (item)
    {
        item->setProgress(percents);
    }
}

void DProgressWdg::progressCompleted()
{
    ProgressItem* const item = d->findProgressItem();

    if (item)
    {
        item->setComplete();
    }
}

void DProgressWdg::progressThumbnailChanged(const QPixmap& thumb)
{
    ProgressItem* const item = d->findProgressItem();

    if (item)
    {
        item->setThumbnail(thumb);
    }
}

void DProgressWdg::progressStatusChanged(const QString& status)
{
    ProgressItem* const item = d->findProgressItem();

    if (item)
    {
        item->setStatus(status);
    }
}

void DProgressWdg::progressScheduled(const QString& title, bool canBeCanceled, bool hasThumb)
{
    ProgressItem* const item = ProgressManager::createProgressItem(title,<--- Variable 'item' can be declared as pointer to const
                                                                   QString(),
                                                                   canBeCanceled,
                                                                   hasThumb);

    if (canBeCanceled)
    {
        connect(item, SIGNAL(progressItemCanceledById(QString)),
                this, SLOT(slotProgressCanceled(QString)));
    }

    d->progressId = item->id();
}

void DProgressWdg::slotProgressCanceled(const QString& id)
{
    if (d->progressId == id)
    {
        Q_EMIT signalProgressCanceled();
    }
}

} // namespace Digikam

#include "moc_dprogresswdg.cpp"