File indexing completed on 2024-04-21 03:56:18

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 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef KSTATUSBARJOBTRACKER_P_H
0010 #define KSTATUSBARJOBTRACKER_P_H
0011 
0012 #include "kabstractwidgetjobtracker_p.h"
0013 #include "kstatusbarjobtracker.h"
0014 
0015 #include <QBoxLayout>
0016 #include <QMap>
0017 #include <QStackedWidget>
0018 #include <QWidget>
0019 
0020 class QPushButton;
0021 class QCheckBox;
0022 class QLabel;
0023 class QProgressBar;
0024 
0025 class KStatusBarJobTrackerPrivate : public KAbstractWidgetJobTrackerPrivate
0026 {
0027     Q_DECLARE_PUBLIC(KStatusBarJobTracker)
0028 
0029 public:
0030     KStatusBarJobTrackerPrivate(KStatusBarJobTracker *q, QWidget *parent, bool withStopButton)
0031         : KAbstractWidgetJobTrackerPrivate(q)
0032         , parent(parent)
0033         , currentProgressWidget(nullptr)
0034         , showStopButton(withStopButton)
0035     {
0036     }
0037 
0038     class ProgressWidget;
0039 
0040     QWidget *parent;
0041     QMap<KJob *, ProgressWidget *> progressWidget;
0042     ProgressWidget *currentProgressWidget;
0043     bool showStopButton;
0044 };
0045 
0046 class KStatusBarJobTrackerPrivate::ProgressWidget : public QWidget
0047 {
0048     Q_OBJECT
0049 
0050 public:
0051     ProgressWidget(KJob *job, KStatusBarJobTracker *object, QWidget *parent)
0052         : q(object)
0053         , job(job)
0054     {
0055         init(job, parent);
0056     }
0057 
0058     ~ProgressWidget() override
0059     {
0060         beingDeleted = true;
0061         delete widget;
0062 
0063         q->unregisterJob(job);
0064     }
0065 
0066     KStatusBarJobTracker *const q;
0067     KJob *const job;
0068 
0069     QWidget *widget = nullptr;
0070     QProgressBar *progressBar = nullptr;
0071     QLabel *label = nullptr;
0072     QPushButton *button = nullptr;
0073     QBoxLayout *box = nullptr;
0074     QStackedWidget *stack = nullptr;
0075 
0076     // qlonglong totalSize = -1;
0077 
0078     KStatusBarJobTracker::StatusBarModes mode = KStatusBarJobTracker::NoInformation;
0079     bool beingDeleted = false;
0080 
0081     void init(KJob *job, QWidget *parent);
0082 
0083     void setMode(KStatusBarJobTracker::StatusBarModes newMode);
0084 
0085 public Q_SLOTS:
0086     virtual void description(const QString &title, const QPair<QString, QString> &field1, const QPair<QString, QString> &field2);
0087     virtual void totalAmount(KJob::Unit unit, qulonglong amount);
0088     virtual void percent(unsigned long percent);
0089     virtual void speed(unsigned long value);
0090     virtual void slotClean();
0091 
0092 private Q_SLOTS:
0093     void killJob();
0094 
0095 protected:
0096     bool eventFilter(QObject *obj, QEvent *event) override;
0097 };
0098 
0099 #endif // KSTATUSBARJOBTRACKER_P_H