File indexing completed on 2024-05-19 04:29:55
0001 /* This file is part of the KDE project 0002 * 0003 * SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org> 0004 * SPDX-FileCopyrightText: 2009 Boudewijn Rempt <boud@valdyas.org> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "KoUpdater.h" 0010 0011 #include "KoUpdaterPrivate_p.h" 0012 0013 KoUpdater::KoUpdater(KoUpdaterPrivate *_d) 0014 : m_progressPercent(0) 0015 { 0016 d = _d; 0017 Q_ASSERT(!d.isNull()); 0018 0019 connect(this, SIGNAL(sigCancel()), d, SLOT(cancel())); 0020 connect(this, SIGNAL(sigProgress(int)), d, SLOT(setProgress(int))); 0021 connect(this, SIGNAL(sigNestedNameChanged(QString)), d, SLOT(setAutoNestedName(QString))); 0022 connect(this, SIGNAL(sigHasValidRangeChanged(bool)), d, SLOT(setHasValidRange(bool))); 0023 0024 0025 setRange(0, 100); 0026 m_interrupted = false; 0027 } 0028 0029 KoUpdater::~KoUpdater() 0030 { 0031 } 0032 0033 void KoUpdater::cancel() 0034 { 0035 emit sigCancel(); 0036 } 0037 0038 void KoUpdater::setProgress(int percent) 0039 { 0040 const bool percentChanged = m_progressPercent != percent; 0041 0042 if (percentChanged || percent == 0 || percent == 100) { 0043 m_progressPercent = percent; 0044 emit sigProgress( percent ); 0045 } 0046 } 0047 0048 int KoUpdater::progress() const 0049 { 0050 0051 return m_progressPercent; 0052 } 0053 0054 bool KoUpdater::interrupted() const 0055 { 0056 return m_interrupted.loadAcquire(); 0057 } 0058 0059 int KoUpdater::maximum() const 0060 { 0061 return max; 0062 } 0063 0064 void KoUpdater::setValue( int value ) 0065 { 0066 value = qBound(min, value, max); 0067 0068 // Go from range to percent 0069 const int range = max - min; 0070 0071 if (range == 0) { 0072 m_progressPercent = max; 0073 emit sigProgress(max); 0074 } else { 0075 setProgress((100 * (value - min)) / range); 0076 } 0077 } 0078 0079 void KoUpdater::setRange( int minimum, int maximum ) 0080 { 0081 min = minimum; 0082 max = maximum; 0083 range = max - min; 0084 emit sigHasValidRangeChanged(range != 0); 0085 } 0086 0087 void KoUpdater::setFormat( const QString & format ) 0088 { 0089 emit sigNestedNameChanged(format); 0090 } 0091 0092 void KoUpdater::setAutoNestedName(const QString &name) 0093 { 0094 emit sigNestedNameChanged(name); 0095 } 0096 0097 void KoUpdater::setInterrupted(bool value) 0098 { 0099 m_interrupted.storeRelease(value); 0100 } 0101 0102 KoDummyUpdaterHolder::KoDummyUpdaterHolder() 0103 : d(new KoUpdaterPrivate(0, "dummy")) 0104 { 0105 } 0106 0107 KoDummyUpdaterHolder::~KoDummyUpdaterHolder() 0108 { 0109 d->deleteLater(); 0110 } 0111 0112 KoUpdater *KoDummyUpdaterHolder::updater() 0113 { 0114 return d->connectedUpdater(); 0115 }