File indexing completed on 2025-01-05 04:55:50

0001 /*
0002     progressdialog.cpp
0003 
0004     This file is part of libkleopatra, the KDE keymanagement library
0005     SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include <config-libkleo.h>
0011 
0012 #include "progressdialog.h"
0013 
0014 #ifndef QT_NO_PROGRESSDIALOG
0015 
0016 #include "progressbar.h"
0017 
0018 #include <kleo_ui_debug.h>
0019 
0020 #include <KLocalizedString>
0021 
0022 #include <QTimer>
0023 
0024 Kleo::ProgressDialog::ProgressDialog(QGpgME::Job *job, const QString &baseText, QWidget *creator, Qt::WindowFlags f)
0025     : QProgressDialog(creator, f)
0026     , mBaseText(baseText)
0027 {
0028     Q_ASSERT(job);
0029     setBar(new ProgressBar(this /*, "replacement progressbar in Kleo::ProgressDialog"*/));
0030 
0031     setMinimumDuration(2000 /*ms*/);
0032     setAutoReset(false);
0033     setAutoClose(false);
0034     setLabelText(baseText);
0035     setModal(false);
0036     setRange(0, 0); // activate busy indicator
0037 
0038     if (!connect(job, &QGpgME::Job::jobProgress, this, &ProgressDialog::slotProgress)) {
0039         qCWarning(KLEO_UI_LOG) << "new-style connect failed; connecting to QGpgME::Job::jobProgress the old way";
0040         connect(job, SIGNAL(jobProgress(int, int)), this, SLOT(slotProgress(int, int)));
0041     }
0042     if (!connect(job, &QGpgME::Job::done, this, &ProgressDialog::slotDone)) {
0043         qCWarning(KLEO_UI_LOG) << "new-style connect failed; connecting to QGpgME::Job::done the old way";
0044         connect(job, SIGNAL(done()), this, SLOT(slotDone()));
0045     }
0046     connect(this, &QProgressDialog::canceled, job, &QGpgME::Job::slotCancel);
0047 
0048     QTimer::singleShot(minimumDuration(), this, &ProgressDialog::forceShow);
0049 }
0050 
0051 Kleo::ProgressDialog::~ProgressDialog()
0052 {
0053 }
0054 
0055 void Kleo::ProgressDialog::setMinimumDuration(int ms)
0056 {
0057     if (0 < ms && ms < minimumDuration()) {
0058         QTimer::singleShot(ms, this, &ProgressDialog::forceShow);
0059     }
0060     QProgressDialog::setMinimumDuration(ms);
0061 }
0062 
0063 void Kleo::ProgressDialog::slotProgress(int current, int total)
0064 {
0065     qCDebug(KLEO_UI_LOG) << "Kleo::ProgressDialog::slotProgress(" << current << "," << total << ")";
0066     setRange(current, total);
0067 }
0068 
0069 void Kleo::ProgressDialog::slotDone()
0070 {
0071     qCDebug(KLEO_UI_LOG) << "Kleo::ProgressDialog::slotDone()";
0072     hide();
0073     deleteLater();
0074 }
0075 
0076 #endif // QT_NO_PROGRESSDIALOG
0077 
0078 #include "moc_progressdialog.cpp"