Warning, file /office/calligra/libs/widgetutils/KoUpdater.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  *
0003  * Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
0004  * Copyright (C) 2009 Boudewijn Rempt <boud@valdyas.org>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  */
0021 #ifndef KO_UPDATER_H
0022 #define KO_UPDATER_H
0023 
0024 #include "KoProgressProxy.h"
0025 #include <QObject>
0026 #include <QPointer>
0027 
0028 class KoProgressUpdater;
0029 class KoUpdaterPrivate;
0030 
0031 
0032 /**
0033  * An KoUpdater is a helper for keeping the progress of each subtask up to speed.
0034  * This class is not thread safe, and it should only be used from one thread.
0035  * The thread it is used in can be different from any other subtask or the
0036  * KoProgressUpdater, though.
0037  *
0038  * It is possible to create a KoProgressUpdater on a KoUpdater for when you
0039  * need to recursively split up progress reporting. (For instance, when your
0040  * progress reporting routine can be called by other progress reporting
0041  * routines.)
0042  *
0043  * KoUpdater implements KoProgressProxy because it is possible to recursively
0044  * create another KoProgressUpdater with an updater as progress proxy.
0045  *
0046  * @see KoProgressUpdater::startSubtask()
0047  */
0048 class KOWIDGETUTILS_EXPORT KoUpdater : public QObject, public KoProgressProxy {
0049 
0050     Q_OBJECT
0051 
0052 public:
0053 
0054     /**
0055      * Call this when this subtask wants to abort all the actions.
0056      */
0057     void cancel();
0058 
0059 public Q_SLOTS:
0060     /**
0061      * Update your progress. Progress is always from 0 to 100.
0062      * The global progress shown to the user is determined by the total
0063      * amount of subtasks there are. This means that each subtasks can just
0064      * report its own private progress in the range from 0 to 100.
0065      */
0066     void setProgress(int percent);
0067 
0068 public:
0069     /**
0070      * return true when this task should stop processing immediately.
0071      * When the task has been cancelled all the subtasks will get interrupted
0072      * and should stop working.  It is therefor important to have repeated calls to
0073      * this method at regular (time) intervals and as soon as the method returns true
0074      * cancel the subtask.
0075      * @return true when this task should stop processing immediately.
0076      */
0077     bool interrupted() const;
0078 
0079     /**
0080      * return the progress this subtask has made.
0081      */
0082     int progress() const;
0083 
0084 public: // KoProgressProxy implementation
0085 
0086     int maximum() const override;
0087     void setValue( int value ) override;
0088     void setRange( int minimum, int maximum ) override;
0089     void setFormat( const QString & format ) override;
0090 
0091 Q_SIGNALS:
0092 
0093     /// emitted whenever the subtask has called cancel on us
0094     void sigCancel();
0095 
0096     /// emitted whenever the subtask has called setProgress on us
0097     void sigProgress( int percent );
0098 
0099 protected:
0100 
0101     friend class KoProgressUpdater;
0102     KoUpdater(KoUpdaterPrivate *p);
0103 
0104 public:
0105 
0106     QPointer<KoUpdaterPrivate> d;
0107     int range;
0108     int min;
0109     int max;
0110 
0111 private Q_SLOTS:
0112 
0113     void interrupt();
0114 
0115 private:
0116 
0117     bool m_interrupted;
0118     int  m_progressPercent;
0119 };
0120 
0121 #endif