File indexing completed on 2024-12-01 06:46:03
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2007 Rafael Fernández López <ereslibre@kde.org> 0004 SPDX-FileCopyrightText: 2007 Kevin Ottens <ervin@kde.org> 0005 SPDX-FileCopyrightText: 2009 Shaun Reich <shaun.reich@kdemail.net> 0006 0007 SPDX-License-Identifier: LGPL-2.0-only 0008 */ 0009 0010 #ifndef KWIDGETJOBTRACKER_P_H 0011 #define KWIDGETJOBTRACKER_P_H 0012 0013 #include "kabstractwidgetjobtracker_p.h" 0014 #include "kwidgetjobtracker.h" 0015 0016 #include <QCheckBox> 0017 #include <QDebug> 0018 #include <QElapsedTimer> 0019 #include <QEventLoopLocker> 0020 #include <QMap> 0021 #include <QQueue> 0022 #include <QUrl> 0023 #include <QWidget> 0024 0025 class QPushButton; 0026 class KSqueezedTextLabel; 0027 class QLabel; 0028 class QProgressBar; 0029 0030 class KWidgetJobTrackerPrivate : public KAbstractWidgetJobTrackerPrivate 0031 { 0032 Q_DECLARE_PUBLIC(KWidgetJobTracker) 0033 0034 public: 0035 KWidgetJobTrackerPrivate(QWidget *parent, KWidgetJobTracker *qq) 0036 : KAbstractWidgetJobTrackerPrivate(qq) 0037 , parent(parent) 0038 , eventLoopLocker(nullptr) 0039 { 0040 } 0041 0042 ~KWidgetJobTrackerPrivate() override 0043 { 0044 delete eventLoopLocker; 0045 } 0046 0047 void setStopOnClose(KJob *job, bool stopOnClose) override; 0048 bool stopOnClose(KJob *job) const override; 0049 void setAutoDelete(KJob *job, bool autoDelete) override; 0050 bool autoDelete(KJob *job) const override; 0051 0052 void _k_showProgressWidget(); 0053 0054 class ProgressWidget; 0055 0056 QWidget *parent; 0057 QEventLoopLocker *eventLoopLocker; 0058 QMap<KJob *, ProgressWidget *> progressWidget; 0059 QQueue<KJob *> progressWidgetsToBeShown; 0060 }; 0061 0062 class KWidgetJobTrackerPrivate::ProgressWidget : public QWidget 0063 { 0064 Q_OBJECT 0065 0066 public: 0067 ProgressWidget(KJob *job, KWidgetJobTracker *object, QWidget *parent) 0068 : QWidget(parent) 0069 , tracker(object) 0070 , job(job) 0071 , totalSize(0) 0072 , totalFiles(0) 0073 , totalDirs(0) 0074 , totalItems(0) 0075 , processedSize(0) 0076 , processedDirs(0) 0077 , processedFiles(0) 0078 , processedItems(0) 0079 , totalSizeKnown(false) 0080 , stopOnClose(true) 0081 , jobRegistered(false) 0082 , cancelClose(nullptr) 0083 , openFile(nullptr) 0084 , openLocation(nullptr) 0085 , keepOpenCheck(nullptr) 0086 , pauseButton(nullptr) 0087 , sourceEdit(nullptr) 0088 , destEdit(nullptr) 0089 , progressLabel(nullptr) 0090 , destInvite(nullptr) 0091 , speedLabel(nullptr) 0092 , sizeLabel(nullptr) 0093 , resumeLabel(nullptr) 0094 , progressBar(nullptr) 0095 , suspendedProperty(false) 0096 , refCount(1) 0097 { 0098 if (!parent) { 0099 setWindowFlags(windowFlags() | Qt::Dialog); 0100 } 0101 0102 init(); 0103 } 0104 0105 ~ProgressWidget() override 0106 { 0107 delete tracker->d_func()->eventLoopLocker; 0108 tracker->d_func()->eventLoopLocker = nullptr; 0109 } 0110 0111 KWidgetJobTracker *const tracker; 0112 KJob *const job; 0113 0114 qulonglong totalSize; 0115 qulonglong totalFiles; 0116 qulonglong totalDirs; 0117 qulonglong totalItems; 0118 qulonglong processedSize; 0119 qulonglong processedDirs; 0120 qulonglong processedFiles; 0121 qulonglong processedItems; 0122 0123 bool totalSizeKnown; 0124 bool stopOnClose; 0125 bool jobRegistered; 0126 QString caption; 0127 0128 QPushButton *cancelClose; 0129 QPushButton *openFile; 0130 QPushButton *openLocation; 0131 QCheckBox *keepOpenCheck; 0132 QUrl location; 0133 QElapsedTimer startTime; 0134 QPushButton *pauseButton; 0135 KSqueezedTextLabel *sourceEdit; 0136 KSqueezedTextLabel *destEdit; 0137 QLabel *progressLabel; 0138 QLabel *sourceInvite; 0139 QLabel *destInvite; 0140 QLabel *speedLabel; 0141 QLabel *sizeLabel; 0142 QLabel *resumeLabel; 0143 QProgressBar *progressBar; 0144 QPushButton *arrowButton; 0145 Qt::ArrowType arrowState; 0146 0147 bool suspendedProperty; 0148 0149 int refCount; // will not close the dialog if a modal menu is shown 0150 0151 void init(); 0152 void showTotals(); 0153 void setDestVisible(bool visible); 0154 void checkDestination(const QUrl &dest); 0155 void ref(); 0156 void deref(); 0157 void closeNow(); 0158 0159 bool eventFilter(QObject *watched, QEvent *event) override; 0160 0161 public Q_SLOTS: 0162 virtual void infoMessage(const QString &plain); 0163 virtual void description(const QString &title, const QPair<QString, QString> &field1, const QPair<QString, QString> &field2); 0164 virtual void totalAmount(KJob::Unit unit, qulonglong amount); 0165 virtual void processedAmount(KJob::Unit unit, qulonglong amount); 0166 virtual void percent(unsigned long percent); 0167 virtual void speed(unsigned long value); 0168 virtual void slotClean(); 0169 virtual void suspended(); 0170 virtual void resumed(); 0171 0172 // TODO: Misses canResume() 0173 0174 protected: 0175 void closeEvent(QCloseEvent *event) override; 0176 0177 private Q_SLOTS: 0178 void keepOpenToggled(bool); 0179 void openFileClicked(); 0180 void openLocationClicked(); 0181 void pauseResumeClicked(); 0182 void cancelClicked(); 0183 void arrowClicked(); 0184 }; 0185 0186 void KWidgetJobTrackerPrivate::setStopOnClose(KJob *job, bool stopOnClose) 0187 { 0188 if (!progressWidget.contains(job)) { 0189 return; 0190 } 0191 progressWidget[job]->stopOnClose = stopOnClose; 0192 } 0193 0194 bool KWidgetJobTrackerPrivate::stopOnClose(KJob *job) const 0195 { 0196 if (!progressWidget.contains(job)) { 0197 qWarning() << "no widget found for job" << job; 0198 return true; 0199 } 0200 return progressWidget[job]->stopOnClose; 0201 } 0202 0203 void KWidgetJobTrackerPrivate::setAutoDelete(KJob *job, bool autoDelete) 0204 { 0205 if (!progressWidget.contains(job)) { 0206 return; 0207 } 0208 progressWidget[job]->setAttribute(Qt::WA_DeleteOnClose, autoDelete); 0209 } 0210 0211 bool KWidgetJobTrackerPrivate::autoDelete(KJob *job) const 0212 { 0213 if (!progressWidget.contains(job)) { 0214 qWarning() << "no widget found for job" << job; 0215 return true; 0216 } 0217 return progressWidget[job]->testAttribute(Qt::WA_DeleteOnClose); 0218 } 0219 0220 #endif // KWIDGETJOBTRACKER_P_H