1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/* This file is part of the KDE project
Copyright (C) 2007 by Javier Goday <jgoday@gmail.com>
Copyright (C) 2009 by Dario Massarin <nekkar@libero.it>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include "kgetglobaljob.h"
#include "kget.h"
#include "transferhandler.h"
#include "kget_debug.h"
#include <KLocalizedString>
#include <KUiServerJobTracker>
#include <QDebug>
KGetGlobalJob::KGetGlobalJob(QObject *parent)
: KJob(parent)
{
setCapabilities(Killable);
}
KGetGlobalJob::~KGetGlobalJob()
{
}
void KGetGlobalJob::update()
{
int runningTransfers = 0;
qulonglong processedAmount = 0;
qulonglong totalAmount = 0;
unsigned long speed = 0;
unsigned long percent = 0;
foreach (TransferHandler *transfer, KGet::allTransfers()) {
if (transfer->status() == Job::Running) {
runningTransfers++;
processedAmount += transfer->downloadedSize();
speed += transfer->downloadSpeed();
totalAmount += transfer->totalSize();
}
}
// qCDebug(KGET_DEBUG) << totalAmount;
if (totalAmount > 0)
percent = 100 * processedAmount / totalAmount;
else
percent = 0;
Q_EMIT description(this,
"KGet global information",
qMakePair(QString("source"), i18np("KGet is downloading %1 file", "KGet is downloading %1 files", runningTransfers)));
emitSpeed(speed);
setTotalAmount(KJob::Bytes, totalAmount);
setProcessedAmount(KJob::Bytes, processedAmount);
setPercent(percent);
}
bool KGetGlobalJob::doKill()
{
qCDebug(KGET_DEBUG) << "Kill of global job called:" << this;
Q_EMIT requestStop(this, nullptr);
return KJob::doKill();
}
#include "moc_kgetglobaljob.cpp"
|