File indexing completed on 2024-12-01 07:38:57
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2005 Dario Massarin <nekkar@libero.it> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 */ 0010 0011 #include "transferdetails.h" 0012 0013 #include "core/kget.h" 0014 0015 #include <KIO/Global> 0016 #include <KLocalizedString> 0017 0018 #include "kget_debug.h" 0019 0020 #include <QDebug> 0021 #include <QStyle> 0022 #include <QVBoxLayout> 0023 0024 TransferDetails::TransferDetails(TransferHandler *transfer) 0025 : QWidget(nullptr) 0026 , m_transfer(transfer) 0027 { 0028 m_genericWidget = new QWidget(this); 0029 0030 frm.setupUi(m_genericWidget); 0031 0032 m_layout = new QVBoxLayout(this); 0033 m_layout->addWidget(m_genericWidget); 0034 setLayout(m_layout); 0035 0036 frm.sourceContentEdit->setText(m_transfer->source().toString()); 0037 frm.destContentEdit->setText(m_transfer->dest().toLocalFile()); 0038 0039 // This updates the widget with the right values 0040 slotTransferChanged(transfer, 0xFFFFFFFF); 0041 0042 connect(transfer, &TransferHandler::transferChangedEvent, this, &TransferDetails::slotTransferChanged); 0043 } 0044 0045 TransferDetails::~TransferDetails() 0046 { 0047 } 0048 0049 QWidget *TransferDetails::detailsWidget(TransferHandler *handler) 0050 { 0051 QWidget *details = KGet::factory(handler)->createDetailsWidget(handler); 0052 0053 if (!details) { // the transfer factory doesn't override the details widget so use the generic one 0054 details = new TransferDetails(handler); 0055 } 0056 0057 return details; 0058 } 0059 0060 void TransferDetails::slotTransferChanged(TransferHandler *transfer, TransferHandler::ChangesFlags flags) 0061 { 0062 qCDebug(KGET_DEBUG) << "TransferDetails::slotTransferChanged"; 0063 0064 Q_UNUSED(transfer) 0065 0066 if (flags & Transfer::Tc_Status) { 0067 frm.statusPixmapContentLabel->setPixmap( 0068 QIcon::fromTheme(m_transfer->statusIconName()).pixmap(style()->pixelMetric(QStyle::PixelMetric::PM_SmallIconSize))); 0069 frm.statusTextContentLabel->setText(m_transfer->statusText()); 0070 0071 if (m_transfer->status() == Job::Finished) { 0072 frm.speedContentLabel->setText(i18n("Average speed: %1/s", KIO::convertSize(m_transfer->averageDownloadSped()))); 0073 } 0074 } 0075 0076 if ((flags & Transfer::Tc_TotalSize) || (flags & Transfer::Tc_DownloadedSize)) { 0077 frm.completedContentLabel->setText(i18n("%1 of %2", KIO::convertSize(m_transfer->downloadedSize()), KIO::convertSize(m_transfer->totalSize()))); 0078 } 0079 0080 if (flags & Transfer::Tc_Percent) { 0081 frm.progressBar->setValue(m_transfer->percent()); 0082 } 0083 0084 if ((flags & Transfer::Tc_DownloadSpeed) && (m_transfer->status() != Job::Finished)) { 0085 int speed = m_transfer->downloadSpeed(); 0086 0087 if (speed == 0) { 0088 if (m_transfer->status() == Job::Running) 0089 frm.speedContentLabel->setText(i18n("Stalled")); 0090 else 0091 frm.speedContentLabel->setText(QString()); 0092 } else { 0093 frm.speedContentLabel->setText(i18n("%1/s", KIO::convertSize(speed))); 0094 } 0095 } 0096 0097 if (flags & Transfer::Tc_FileName) { 0098 frm.destContentEdit->setText(m_transfer->dest().toLocalFile()); 0099 } 0100 0101 if (flags & Transfer::Tc_Source) { 0102 frm.sourceContentEdit->setText(m_transfer->source().toString()); 0103 } 0104 0105 frm.remainingTimeLabel->setText(KIO::convertSeconds(m_transfer->remainingTime())); 0106 } 0107 0108 #include "moc_transferdetails.cpp"