File indexing completed on 2025-02-16 04:35:59
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2007 by Javier Goday <jgoday@gmail.com> 0004 Copyright (C) 2009 by Dario Massarin <nekkar@libero.it> 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU 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 #include "kgetglobaljob.h" 0012 #include "kget.h" 0013 #include "transferhandler.h" 0014 0015 #include "kget_debug.h" 0016 #include <KLocalizedString> 0017 #include <KUiServerJobTracker> 0018 #include <QDebug> 0019 0020 KGetGlobalJob::KGetGlobalJob(QObject *parent) 0021 : KJob(parent) 0022 { 0023 setCapabilities(Killable); 0024 } 0025 0026 KGetGlobalJob::~KGetGlobalJob() 0027 { 0028 } 0029 0030 void KGetGlobalJob::update() 0031 { 0032 int runningTransfers = 0; 0033 qulonglong processedAmount = 0; 0034 qulonglong totalAmount = 0; 0035 unsigned long speed = 0; 0036 unsigned long percent = 0; 0037 0038 foreach (TransferHandler *transfer, KGet::allTransfers()) { 0039 if (transfer->status() == Job::Running) { 0040 runningTransfers++; 0041 processedAmount += transfer->downloadedSize(); 0042 speed += transfer->downloadSpeed(); 0043 totalAmount += transfer->totalSize(); 0044 } 0045 } 0046 0047 // qCDebug(KGET_DEBUG) << totalAmount; 0048 0049 if (totalAmount > 0) 0050 percent = 100 * processedAmount / totalAmount; 0051 else 0052 percent = 0; 0053 0054 Q_EMIT description(this, 0055 "KGet global information", 0056 qMakePair(QString("source"), i18np("KGet is downloading %1 file", "KGet is downloading %1 files", runningTransfers))); 0057 0058 emitSpeed(speed); 0059 setTotalAmount(KJob::Bytes, totalAmount); 0060 setProcessedAmount(KJob::Bytes, processedAmount); 0061 0062 setPercent(percent); 0063 } 0064 0065 bool KGetGlobalJob::doKill() 0066 { 0067 qCDebug(KGET_DEBUG) << "Kill of global job called:" << this; 0068 Q_EMIT requestStop(this, nullptr); 0069 return KJob::doKill(); 0070 } 0071 0072 #include "moc_kgetglobaljob.cpp"