Warning, file /office/calligra/libs/widgetutils/KoUpdater.cpp 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 
0022 #include "KoUpdater.h"
0023 
0024 #include "KoUpdaterPrivate_p.h"
0025 
0026 KoUpdater::KoUpdater(KoUpdaterPrivate *p)
0027     : QObject(p),
0028       m_progressPercent(0)
0029 {
0030     d = p;
0031     Q_ASSERT(p);
0032     Q_ASSERT(!d.isNull());
0033 
0034     connect( this, SIGNAL(sigCancel()), d, SLOT(cancel()) );
0035     connect( this, SIGNAL(sigProgress(int)), d, SLOT(setProgress(int)) );
0036     connect( d, SIGNAL(sigInterrupted()), this, SLOT(interrupt()) );
0037 
0038     setRange(0, 100);
0039     m_interrupted = false;
0040 }
0041 
0042 void KoUpdater::cancel()
0043 {
0044     emit sigCancel();
0045 }
0046 
0047 void KoUpdater::setProgress(int percent)
0048 {
0049     if (m_progressPercent >= percent) {
0050         return;
0051     }
0052     d->addPoint(percent);
0053 
0054     m_progressPercent = percent;
0055 
0056     emit sigProgress( percent );
0057 }
0058 
0059 int KoUpdater::progress() const
0060 {
0061 
0062     return m_progressPercent;
0063 }
0064 
0065 bool KoUpdater::interrupted() const
0066 {
0067     return m_interrupted;
0068 }
0069 
0070 int KoUpdater::maximum() const
0071 {
0072     return 100;
0073 }
0074 
0075 void KoUpdater::setValue( int value )
0076 {
0077 
0078     if ( value < min ) value = min;
0079     if ( value > max ) value = max;
0080     // Go from range to percent
0081     if (range == 0) return;
0082     setProgress( ((100 * value ) / range) + 1 );
0083 }
0084 
0085 void KoUpdater::setRange( int minimum, int maximum )
0086 {
0087     min = minimum - 1;
0088     max = maximum;
0089     range = max - min;
0090 }
0091 
0092 void KoUpdater::setFormat( const QString & format )
0093 {
0094     Q_UNUSED(format);
0095     // XXX: Do nothing
0096 }
0097 
0098 void KoUpdater::interrupt()
0099 {
0100     m_interrupted = true;
0101 }