1 /* This file is part of the KDE project 2 * Copyright (C) 2006-2007 Thomas Zander <zander@kde.org> 3 * Copyright (C) 2009 Boudewijn Rempt <boud@valdyas.org> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef KO_UPDATERPRIVATE__P_H 22 #define KO_UPDATERPRIVATE__P_H 23 24 #include "KoProgressUpdater.h" 25 26 #include <QTime> 27 #include <QVector> 28 29 /** 30 * KoUpdaterPrivate is the gui-thread side of KoUpdater. Communication 31 * between KoUpdater and KoUpdaterPrivate is handled through queued 32 * connections -- this is the main app thread part of the 33 * KoUpdater-KoUpdaterPrivate bridge. 34 * 35 * The gui thread can iterate over its list of KoUpdaterPrivate 36 * instances for the total progress computation: the queued signals 37 * from the threads will only arrive when the eventloop in the gui 38 * thread has a chance to deliver them. 39 */ 40 class KoUpdaterPrivate : public QObject 41 { 42 43 Q_OBJECT 44 45 public: 46 KoUpdaterPrivate(KoProgressUpdater * parent,int weight,const QString & name)47 KoUpdaterPrivate(KoProgressUpdater *parent, int weight, const QString& name) 48 : QObject(0) 49 , m_progress(0) 50 , m_weight(weight) 51 , m_interrupted(false) 52 , m_hasOutput(parent->hasOutput()) 53 , m_parent(parent) 54 { 55 setObjectName(name); 56 } 57 58 /// when deleting an updater, make sure the accompanying thread is 59 /// interrupted, too. 60 ~KoUpdaterPrivate() override; 61 interrupted()62 bool interrupted() const { return m_interrupted; } 63 progress()64 int progress() const { return m_progress; } 65 weight()66 int weight() const { return m_weight; } 67 68 class TimePoint { 69 public: 70 QTime time; 71 int value; 72 TimePoint(int value_)73 explicit TimePoint(int value_) :time(QTime::currentTime()), value(value_) {} TimePoint()74 TimePoint() {} 75 }; 76 addPoint(int value)77 void addPoint(int value) { 78 if (m_hasOutput) { 79 m_points.append(TimePoint(value)); 80 } 81 } 82 getPoints()83 const QVector<TimePoint> & getPoints() const { 84 return m_points; 85 } 86 87 public Q_SLOTS: 88 89 /// Cancel comes from KoUpdater 90 void cancel(); 91 92 /// Interrupt comes from the gui, through KoProgressUpdater, goes 93 /// to KoUpdater to signal running tasks they might as well quit. 94 void interrupt(); 95 96 /// progress comes from KoUpdater 97 void setProgress(int percent); 98 99 Q_SIGNALS: 100 101 /// Emitted whenever the progress changed 102 void sigUpdated(); 103 104 /// Emitted whenever the parent KoProgressUpdater is interrupted, 105 /// for instance through a press on a cancel button 106 void sigInterrupted(); 107 108 private: 109 int m_progress; // always in percent 110 int m_weight; 111 bool m_interrupted; 112 bool m_hasOutput; 113 114 KoProgressUpdater *m_parent; 115 QVector<TimePoint> m_points; 116 }; 117 118 Q_DECLARE_TYPEINFO(KoUpdaterPrivate::TimePoint, Q_MOVABLE_TYPE); 119 120 #endif 121