File indexing completed on 2024-12-01 04:33:14

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2008 Javier Goday <jgoday @ gmail.com>
0004    Idea by Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
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 "kgetkjobadapter.h"
0012 
0013 #include "kget_debug.h"
0014 #include <KLocalizedString>
0015 #include <QDebug>
0016 
0017 KGetKJobAdapter::KGetKJobAdapter(QObject *parent, TransferHandler *transfer)
0018     : KJob(parent)
0019     , m_transferHandler(transfer)
0020 {
0021     setCapabilities(Killable | Suspendable);
0022 }
0023 
0024 KGetKJobAdapter::~KGetKJobAdapter()
0025 {
0026 }
0027 
0028 qulonglong KGetKJobAdapter::processedAmount(Unit unit) const
0029 {
0030     Q_UNUSED(unit)
0031     return m_transferHandler->downloadedSize();
0032 }
0033 
0034 qulonglong KGetKJobAdapter::totalAmount(Unit unit) const
0035 {
0036     Q_UNUSED(unit)
0037     return m_transferHandler->totalSize();
0038 }
0039 
0040 unsigned long KGetKJobAdapter::percent() const
0041 {
0042     return m_transferHandler->percent();
0043 }
0044 
0045 void KGetKJobAdapter::slotUpdateDescription()
0046 {
0047     Q_EMIT description(this,
0048                        i18n("KGet Transfer"),
0049                        qMakePair(QString("source"), m_transferHandler->source().toString()),
0050                        qMakePair(QString("destination"), m_transferHandler->dest().toString()));
0051 
0052     emitSpeed(m_transferHandler->downloadSpeed());
0053     setProcessedAmount(KJob::Bytes, processedAmount(KJob::Bytes));
0054     setTotalAmount(KJob::Bytes, totalAmount(KJob::Bytes));
0055     setPercent(percent());
0056 }
0057 
0058 bool KGetKJobAdapter::doKill()
0059 {
0060     qCDebug(KGET_DEBUG) << "Kill of job adapter called:" << this << m_transferHandler->dest();
0061     Q_EMIT requestStop(this, m_transferHandler);
0062     return KJob::doKill();
0063 }
0064 
0065 bool KGetKJobAdapter::doSuspend()
0066 {
0067     if (m_transferHandler->capabilities() & Transfer::Cap_Resuming) {
0068         Q_EMIT requestSuspend(this, m_transferHandler);
0069         return true;
0070     }
0071 
0072     return false;
0073 }
0074 
0075 bool KGetKJobAdapter::doResume()
0076 {
0077     Q_EMIT requestResume(this, m_transferHandler);
0078     return true;
0079 }
0080 
0081 #include "moc_kgetkjobadapter.cpp"