File indexing completed on 2024-03-03 05:09:51

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
0004    Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
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 "dbustransferwrapper.h"
0012 #include "transfergrouphandler.h"
0013 #include "verifier.h"
0014 
0015 #include <QApplication>
0016 #include <QStyle>
0017 
0018 DBusTransferWrapper::DBusTransferWrapper(TransferHandler *parent)
0019     : QObject(parent)
0020     , m_transfer(parent)
0021 {
0022     connect(m_transfer, &TransferHandler::transferChangedEvent, this, &DBusTransferWrapper::slotTransferChanged);
0023     connect(m_transfer, &TransferHandler::capabilitiesChanged, this, &DBusTransferWrapper::capabilitiesChanged);
0024 }
0025 
0026 DBusTransferWrapper::~DBusTransferWrapper()
0027 {
0028 }
0029 
0030 int DBusTransferWrapper::capabilities() const
0031 {
0032     return m_transfer->capabilities();
0033 }
0034 
0035 void DBusTransferWrapper::start()
0036 {
0037     m_transfer->start();
0038 }
0039 
0040 void DBusTransferWrapper::stop()
0041 {
0042     m_transfer->stop();
0043 }
0044 
0045 int DBusTransferWrapper::status() const
0046 {
0047     return (int)m_transfer->status();
0048 }
0049 
0050 int DBusTransferWrapper::elapsedTime() const
0051 {
0052     return m_transfer->elapsedTime();
0053 }
0054 
0055 int DBusTransferWrapper::remainingTime() const
0056 {
0057     return m_transfer->remainingTime();
0058 }
0059 
0060 QString DBusTransferWrapper::groupName() const
0061 {
0062     return m_transfer->group()->name();
0063 }
0064 
0065 QString DBusTransferWrapper::source() const
0066 {
0067     return m_transfer->source().toString();
0068 }
0069 
0070 QString DBusTransferWrapper::dest() const
0071 {
0072     return m_transfer->dest().toString();
0073 }
0074 
0075 bool DBusTransferWrapper::setDirectory(const QString &directory)
0076 {
0077     return m_transfer->setDirectory(QUrl(directory));
0078 }
0079 
0080 qulonglong DBusTransferWrapper::totalSize() const
0081 {
0082     return m_transfer->totalSize();
0083 }
0084 
0085 qulonglong DBusTransferWrapper::downloadedSize() const
0086 {
0087     return m_transfer->downloadedSize();
0088 }
0089 
0090 qulonglong DBusTransferWrapper::uploadedSize() const
0091 {
0092     return m_transfer->uploadedSize();
0093 }
0094 
0095 int DBusTransferWrapper::percent() const
0096 {
0097     return m_transfer->percent();
0098 }
0099 
0100 int DBusTransferWrapper::downloadSpeed() const
0101 {
0102     return m_transfer->downloadSpeed();
0103 }
0104 
0105 int DBusTransferWrapper::uploadSpeed() const
0106 {
0107     return m_transfer->uploadSpeed();
0108 }
0109 
0110 void DBusTransferWrapper::setUploadLimit(int ulLimit, int limit)
0111 {
0112     m_transfer->setUploadLimit(ulLimit, (Transfer::SpeedLimit)limit);
0113 }
0114 
0115 void DBusTransferWrapper::setDownloadLimit(int dlLimit, int limit)
0116 {
0117     m_transfer->setDownloadLimit(dlLimit, (Transfer::SpeedLimit)limit);
0118 }
0119 
0120 int DBusTransferWrapper::uploadLimit(int limit) const
0121 {
0122     return m_transfer->uploadLimit((Transfer::SpeedLimit)limit);
0123 }
0124 
0125 int DBusTransferWrapper::downloadLimit(int limit) const
0126 {
0127     return m_transfer->downloadLimit((Transfer::SpeedLimit)limit);
0128 }
0129 
0130 void DBusTransferWrapper::setMaximumShareRatio(double ratio)
0131 {
0132     m_transfer->setMaximumShareRatio(ratio);
0133 }
0134 
0135 double DBusTransferWrapper::maximumShareRatio()
0136 {
0137     return m_transfer->maximumShareRatio();
0138 }
0139 
0140 QString DBusTransferWrapper::statusText() const
0141 {
0142     return m_transfer->statusText();
0143 }
0144 
0145 QDBusVariant DBusTransferWrapper::statusPixmap() const
0146 {
0147     const QPixmap pix = QIcon::fromTheme(m_transfer->statusIconName()).pixmap(qApp->style()->pixelMetric(QStyle::PixelMetric::PM_SmallIconSize));
0148     return QDBusVariant(QVariant::fromValue(pix));
0149 }
0150 
0151 void DBusTransferWrapper::slotTransferChanged(TransferHandler *transfer, TransferHandler::ChangesFlags changeFlags)
0152 {
0153     Q_UNUSED(transfer)
0154 
0155     Q_EMIT transferChangedEvent(changeFlags);
0156 }
0157 
0158 QString DBusTransferWrapper::verifier(const QString &file)
0159 {
0160     Verifier *verifier = m_transfer->verifier(QUrl(file));
0161     if (verifier) {
0162         return verifier->dBusObjectPath();
0163     }
0164 
0165     return QString();
0166 }
0167 
0168 bool DBusTransferWrapper::repair(const QString &file)
0169 {
0170     return m_transfer->repair(QUrl(file));
0171 }
0172 
0173 #include "moc_dbustransferwrapper.cpp"