1 /*
2 progressdialog.cpp
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "progressdialog.h"
11 #include "kleo_ui_debug.h"
12
13 #ifndef QT_NO_PROGRESSDIALOG
14
15 #include "progressbar.h"
16
17
18 #include <KLocalizedString>
19
20 #include <QTimer>
21
22
ProgressDialog(QGpgME::Job * job,const QString & baseText,QWidget * creator,Qt::WindowFlags f)23 Kleo::ProgressDialog::ProgressDialog(QGpgME::Job *job, const QString &baseText,
24 QWidget *creator, Qt::WindowFlags f)
25 : QProgressDialog(creator, f), mBaseText(baseText)
26 {
27 Q_ASSERT(job);
28 setBar(new ProgressBar(this/*, "replacement progressbar in Kleo::ProgressDialog"*/));
29
30 setMinimumDuration(2000 /*ms*/);
31 setAutoReset(false);
32 setAutoClose(false);
33 setLabelText(baseText);
34 setModal(false);
35 setRange(0, 0); // activate busy indicator
36
37 connect(job, &QGpgME::Job::progress, this, &ProgressDialog::slotProgress);
38 connect(job, &QGpgME::Job::done, this, &ProgressDialog::slotDone);
39 connect(this, &QProgressDialog::canceled, job, &QGpgME::Job::slotCancel);
40
41 QTimer::singleShot(minimumDuration(), this, &ProgressDialog::forceShow);
42 }
43
~ProgressDialog()44 Kleo::ProgressDialog::~ProgressDialog()
45 {
46
47 }
48
setMinimumDuration(int ms)49 void Kleo::ProgressDialog::setMinimumDuration(int ms)
50 {
51 if (0 < ms && ms < minimumDuration()) {
52 QTimer::singleShot(ms, this, &ProgressDialog::forceShow);
53 }
54 QProgressDialog::setMinimumDuration(ms);
55 }
56
slotProgress(const QString & what,int current,int total)57 void Kleo::ProgressDialog::slotProgress(const QString &what, int current, int total)
58 {
59 qCDebug(KLEO_UI_LOG) << "Kleo::ProgressDialog::slotProgress( \"" << what << "\","
60 << current << "," << total << ")";
61 if (mBaseText.isEmpty()) {
62 setLabelText(what);
63 } else if (what.isEmpty()) {
64 setLabelText(mBaseText);
65 } else {
66 setLabelText(i18n("%1: %2", mBaseText, what));
67 }
68 setRange(current, total);
69 }
70
slotDone()71 void Kleo::ProgressDialog::slotDone()
72 {
73 qCDebug(KLEO_UI_LOG) << "Kleo::ProgressDialog::slotDone()";
74 hide();
75 deleteLater();
76 }
77
78 #endif // QT_NO_PROGRESSDIALOG
79