File indexing completed on 2025-01-19 03:53:49

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-11-03
0007  * Description : a busy dialog for digiKam
0008  *
0009  * SPDX-FileCopyrightText: 2009-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 "dbusydlg.h"
0016 
0017 // Qt includes
0018 
0019 #include <QPushButton>
0020 #include <QProgressBar>
0021 
0022 // Local includes
0023 
0024 #include "digikam_debug.h"
0025 
0026 namespace Digikam
0027 {
0028 
0029 DBusyThread::DBusyThread(QObject* const parent)
0030     : QThread(parent)
0031 {
0032 }
0033 
0034 DBusyThread::~DBusyThread()
0035 {
0036     wait();
0037 }
0038 
0039 // ----------------------------------------------------------------------------------
0040 
0041 class Q_DECL_HIDDEN DBusyDlg::Private
0042 {
0043 public:
0044 
0045     explicit Private() :
0046         thread(nullptr)
0047     {
0048     }
0049 
0050     DBusyThread* thread;
0051 };
0052 
0053 DBusyDlg::DBusyDlg(const QString& txt, QWidget* const parent)
0054     : QProgressDialog(parent, Qt::FramelessWindowHint),
0055       d(new Private)
0056 {
0057     setLabelText(txt);
0058     setCancelButton(nullptr);
0059     setMinimumDuration(0);
0060     setModal(true);
0061     setAutoClose(false);
0062 
0063     setMaximum(0);
0064     setMinimum(0);
0065     setValue(0);
0066 }
0067 
0068 DBusyDlg::~DBusyDlg()
0069 {
0070     delete d;
0071 }
0072 
0073 void DBusyDlg::setBusyThread(DBusyThread* const thread)
0074 {
0075     d->thread = thread;
0076 
0077     if (d->thread)
0078     {
0079         connect(d->thread, SIGNAL(signalComplete()),
0080                 this, SLOT(slotComplete()));
0081 
0082         qCDebug(DIGIKAM_GENERAL_LOG) << "Thread is started";
0083         d->thread->start();
0084     }
0085 }
0086 
0087 void DBusyDlg::slotComplete()
0088 {
0089     qCDebug(DIGIKAM_GENERAL_LOG) << "Thread is complete";
0090     accept();
0091 }
0092 
0093 } // namespace Digikam
0094 
0095 #include "moc_dbusydlg.cpp"