Disable clipboardsharing in view only mode.
[kdenetwork.git] / kget / core / kgetglobaljob.cpp
blob96a5d2dbf6f07f0f56fed65050d9d37a9bd2329f
1 /* This file is part of the KDE project
3 Copyright (C) 2007 by Javier Goday <jgoday@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU 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 #include "kgetglobaljob.h"
12 #include <QTimer>
14 KGetGlobalJob::KGetGlobalJob(QObject *parent)
15 : KJob(parent), m_jobs()
17 m_timer = new QTimer(this);
18 m_timer->setSingleShot(false);
20 connect(m_timer, SIGNAL(timeout()), this, SLOT(update()));
23 KGetGlobalJob::~KGetGlobalJob()
25 delete m_timer;
28 void KGetGlobalJob::registerJob(KJob *job)
30 if(!m_jobs.contains(job)) {
31 if(m_jobs.size() <= 0) {
32 m_timer->start(DEFAULT_UPDATE_TIME);
34 m_jobs.append(job);
38 void KGetGlobalJob::unregisterJob(KJob *job)
40 m_jobs.removeAll(job);
42 if(m_jobs.size() <= 0) {
43 update();
44 m_timer->stop();
48 qulonglong KGetGlobalJob::processedAmount(Unit unit) const
50 qulonglong amount = 0;
51 foreach(KJob *child, m_jobs) {
52 amount += child->processedAmount(unit);
55 return amount;
58 qulonglong KGetGlobalJob::totalAmount(Unit unit) const
60 qulonglong amount = 0;
61 foreach(KJob *child, m_jobs) {
62 amount += child->totalAmount(unit);
65 return amount;
68 unsigned long KGetGlobalJob::percent() const
70 if (totalAmount(KJob::Bytes) > 0)
71 return 100 * processedAmount(KJob::Bytes) / totalAmount(KJob::Bytes);
72 else
73 return 0;
76 void KGetGlobalJob::update()
78 emit description(this, "KGet global information",
79 qMakePair(QString("source"), QString("KGet is downloading %1 files").arg(m_jobs.size())),
80 qMakePair(QString("destination"), QString("to different locations")));
82 setProcessedAmount(KJob::Bytes, processedAmount(KJob::Bytes));
83 setTotalAmount(KJob::Bytes, totalAmount(KJob::Bytes));
84 setPercent(percent());