File indexing completed on 2024-04-28 04:57:29
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2007 - 2008 Lukas Appelhans <l.appelhans@gmx.de> 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 "btdetailswidget.h" 0012 0013 #include "bttransferhandler.h" 0014 0015 #include "kget_debug.h" 0016 0017 #include <KFormat> 0018 0019 BTDetailsWidget::BTDetailsWidget(BTTransferHandler *transfer) 0020 : m_transfer(transfer) 0021 { 0022 setupUi(this); 0023 0024 // Update the view with the correct values 0025 srcEdit->setText(transfer->source().toDisplayString(QUrl::PreferLocalFile)); 0026 destEdit->setText(transfer->dest().toDisplayString(QUrl::PreferLocalFile)); 0027 0028 seederLabel->setText(i18nc("not available", "n/a")); 0029 leecherLabel->setText(i18nc("not available", "n/a")); 0030 chunksDownloadedLabel->setText(i18nc("not available", "n/a")); 0031 chunksExcludedLabel->setText(i18nc("not available", "n/a")); 0032 chunksAllLabel->setText(i18nc("not available", "n/a")); 0033 chunksLeftLabel->setText(i18nc("not available", "n/a")); 0034 dlSpeedLabel->setText(i18nc("not available", "n/a")); 0035 ulSpeedLabel->setText(i18nc("not available", "n/a")); 0036 0037 progressBar->setValue(m_transfer->percent()); 0038 0039 connect(m_transfer, &TransferHandler::transferChangedEvent, this, &BTDetailsWidget::slotTransferChanged); 0040 } 0041 0042 BTDetailsWidget::~BTDetailsWidget() 0043 { 0044 } 0045 0046 void BTDetailsWidget::slotTransferChanged(TransferHandler *transfer, TransferHandler::ChangesFlags flags) 0047 { 0048 Q_UNUSED(transfer) 0049 0050 qCDebug(KGET_DEBUG) << "BTDetailsWidget::slotTransferChanged"; 0051 0052 if (flags & Transfer::Tc_DownloadSpeed) 0053 dlSpeedLabel->setText(KFormat().formatByteSize(m_transfer->downloadSpeed()) + "/s"); 0054 0055 if (flags & Transfer::Tc_UploadSpeed) 0056 ulSpeedLabel->setText(KFormat().formatByteSize(m_transfer->uploadSpeed()) + "/s"); 0057 0058 if (flags & BTTransfer::Tc_SeedsConnected) 0059 seederLabel->setText((m_transfer->seedsConnected() != -1 ? QString().setNum(m_transfer->seedsConnected()) : i18nc("not available", "n/a")) + " (" 0060 + (m_transfer->seedsDisconnected() != -1 ? QString().setNum(m_transfer->seedsDisconnected()) : i18nc("not available", "n/a")) 0061 + ')'); 0062 0063 if (flags & BTTransfer::Tc_LeechesConnected) 0064 leecherLabel->setText((m_transfer->leechesConnected() != -1 ? QString().setNum(m_transfer->leechesConnected()) : i18nc("not available", "n/a")) + " (" 0065 + (m_transfer->leechesDisconnected() != -1 ? QString().setNum(m_transfer->leechesDisconnected()) : i18nc("not available", "n/a")) 0066 + ')'); 0067 0068 if (flags & BTTransfer::Tc_ChunksDownloaded) 0069 chunksDownloadedLabel->setText(m_transfer->chunksDownloaded() != -1 ? QString().setNum(m_transfer->chunksDownloaded()) : i18nc("not available", "n/a")); 0070 0071 if (flags & BTTransfer::Tc_ChunksExcluded) 0072 chunksExcludedLabel->setText(m_transfer->chunksExcluded() != -1 ? QString().setNum(m_transfer->chunksExcluded()) : i18nc("not available", "n/a")); 0073 0074 if (flags & BTTransfer::Tc_ChunksTotal) 0075 chunksAllLabel->setText((m_transfer->chunksTotal() != -1) ? QString().setNum(m_transfer->chunksTotal()) : i18nc("not available", "n/a")); 0076 0077 if (flags & BTTransfer::Tc_ChunksLeft) 0078 chunksLeftLabel->setText((m_transfer->chunksLeft() != -1) ? QString().setNum(m_transfer->chunksLeft()) : i18nc("not available", "n/a")); 0079 0080 if (flags & Transfer::Tc_Percent) 0081 progressBar->setValue(m_transfer->percent()); 0082 0083 if (flags & Transfer::Tc_FileName) 0084 destEdit->setText(m_transfer->dest().toDisplayString(QUrl::PreferLocalFile)); 0085 } 0086 0087 void BTDetailsWidget::showEvent(QShowEvent *event) 0088 { 0089 Q_UNUSED(event) 0090 0091 slotTransferChanged(m_transfer, 0xFFFFFFFF); 0092 } 0093 0094 #include "moc_btdetailswidget.cpp"