File indexing completed on 2024-05-19 04:29:55

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org>
0003  * SPDX-FileCopyrightText: 2009 Boudewijn Rempt <boud@valdyas.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #ifndef KO_UPDATERPRIVATE__P_H
0009 #define KO_UPDATERPRIVATE__P_H
0010 
0011 #include <QObject>
0012 #include <QPointer>
0013 #include <QTime>
0014 #include <QVector>
0015 
0016 class KoUpdater;
0017 
0018 /**
0019  * KoUpdaterPrivate is the gui-thread side of KoUpdater. Communication
0020  * between KoUpdater and KoUpdaterPrivate is handled through queued
0021  * connections -- this is the main app thread part of the
0022  * KoUpdater-KoUpdaterPrivate bridge.
0023  *
0024  * The gui thread can iterate over its list of KoUpdaterPrivate
0025  * instances for the total progress computation: the queued signals
0026  * from the threads will only arrive when the eventloop in the gui
0027  * thread has a chance to deliver them.
0028  */
0029 class KoUpdaterPrivate : public QObject
0030 {
0031 
0032     Q_OBJECT
0033 
0034 public:
0035 
0036     KoUpdaterPrivate(int weight, const QString& name, bool isPersistent = false);
0037 
0038     /// when deleting an updater, make sure the accompanying thread is
0039     /// interrupted, too.
0040     ~KoUpdaterPrivate() override;
0041 
0042     bool interrupted() const { return m_interrupted; }
0043 
0044     int progress() const { return m_progress; }
0045 
0046     int weight() const { return m_weight; }
0047 
0048     QString autoNestedName() const;
0049     QString subTaskName() const;
0050     QString mergedSubTaskName() const;
0051 
0052     bool hasValidRange() const;
0053     bool isPersistent() const;
0054     bool isCompleted() const;
0055 
0056     QPointer<KoUpdater> connectedUpdater() const;
0057 
0058 public Q_SLOTS:
0059 
0060     /// Cancel comes from KoUpdater
0061     void cancel();
0062 
0063     void setInterrupted(bool value = true);
0064 
0065     /// progress comes from KoUpdater
0066     void setProgress( int percent );
0067 
0068     void setAutoNestedName(const QString &name);
0069     void setHasValidRange(bool value);
0070 
0071 
0072 Q_SIGNALS:
0073 
0074     /// Emitted whenever the progress changed
0075     void sigUpdated();
0076 
0077     /// Emitted whenever the operation is cancelled by the downstream updater
0078     void sigCancelled();
0079 
0080 private:
0081     int m_progress; // always in percent
0082     int m_weight;
0083     bool m_interrupted;
0084     QString m_autoNestedName;
0085     QString m_subTaskName;
0086     bool m_hasValidRange;
0087     bool m_isPersistent;
0088     QPointer<KoUpdater> m_connectedUpdater;
0089 };
0090 
0091 #endif