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.
10 #include "kgetglobaljob.h"
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()
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
);
38 void KGetGlobalJob::unregisterJob(KJob
*job
)
40 m_jobs
.removeAll(job
);
42 if(m_jobs
.size() <= 0) {
48 qulonglong
KGetGlobalJob::processedAmount(Unit unit
) const
50 qulonglong amount
= 0;
51 foreach(KJob
*child
, m_jobs
) {
52 amount
+= child
->processedAmount(unit
);
58 qulonglong
KGetGlobalJob::totalAmount(Unit unit
) const
60 qulonglong amount
= 0;
61 foreach(KJob
*child
, m_jobs
) {
62 amount
+= child
->totalAmount(unit
);
68 unsigned long KGetGlobalJob::percent() const
70 if (totalAmount(KJob::Bytes
) > 0)
71 return 100 * processedAmount(KJob::Bytes
) / totalAmount(KJob::Bytes
);
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());