File indexing completed on 2024-05-05 04:59:12
0001 /*************************************************************************** 0002 * Copyright (C) 2007 by Joris Guisson and Ivan Vasic * 0003 * joris.guisson@gmail.com * 0004 * ivasic@gmail.com * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the * 0018 * Free Software Foundation, Inc., * 0019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0020 ***************************************************************************/ 0021 #include "chunkdownloadview.h" 0022 0023 #include <KConfigGroup> 0024 #include <KLocalizedString> 0025 #include <QHeaderView> 0026 #include <QSortFilterProxyModel> 0027 0028 #include "chunkdownloadmodel.h" 0029 #include <interfaces/torrentfileinterface.h> 0030 #include <interfaces/torrentinterface.h> 0031 #include <util/functions.h> 0032 #include <util/log.h> 0033 0034 using namespace bt; 0035 0036 namespace kt 0037 { 0038 0039 ChunkDownloadView::ChunkDownloadView(QWidget *parent) 0040 : QWidget(parent) 0041 , curr_tc(nullptr) 0042 { 0043 setupUi(this); 0044 model = new ChunkDownloadModel(this); 0045 m_chunk_view->setModel(model); 0046 m_chunk_view->setRootIsDecorated(false); 0047 m_chunk_view->setSortingEnabled(true); 0048 m_chunk_view->setAlternatingRowColors(true); 0049 m_chunk_view->setUniformRowHeights(true); 0050 } 0051 0052 ChunkDownloadView::~ChunkDownloadView() 0053 { 0054 } 0055 0056 void ChunkDownloadView::downloadAdded(ChunkDownloadInterface *cd) 0057 { 0058 model->downloadAdded(cd); 0059 } 0060 0061 void ChunkDownloadView::downloadRemoved(ChunkDownloadInterface *cd) 0062 { 0063 model->downloadRemoved(cd); 0064 } 0065 0066 void ChunkDownloadView::update() 0067 { 0068 if (!curr_tc) 0069 return; 0070 0071 model->update(); 0072 const TorrentStats &s = curr_tc->getStats(); 0073 m_chunks_downloading->setText(QString::number(s.num_chunks_downloading)); 0074 m_chunks_downloaded->setText(QString::number(s.num_chunks_downloaded)); 0075 m_excluded_chunks->setText(QString::number(s.num_chunks_excluded)); 0076 m_chunks_left->setText(QString::number(s.num_chunks_left)); 0077 } 0078 0079 void ChunkDownloadView::changeTC(TorrentInterface *tc) 0080 { 0081 curr_tc = tc; 0082 if (!curr_tc) { 0083 setEnabled(false); 0084 } else { 0085 setEnabled(true); 0086 const TorrentStats &s = curr_tc->getStats(); 0087 m_total_chunks->setText(QString::number(s.total_chunks)); 0088 m_size_chunks->setText(BytesToString(s.chunk_size)); 0089 } 0090 model->changeTC(tc); 0091 } 0092 0093 void ChunkDownloadView::removeAll() 0094 { 0095 model->clear(); 0096 } 0097 0098 void ChunkDownloadView::saveState(KSharedConfigPtr cfg) 0099 { 0100 KConfigGroup g = cfg->group("ChunkDownloadView"); 0101 QByteArray s = m_chunk_view->header()->saveState(); 0102 g.writeEntry("state", s.toBase64()); 0103 } 0104 0105 void ChunkDownloadView::loadState(KSharedConfigPtr cfg) 0106 { 0107 KConfigGroup g = cfg->group("ChunkDownloadView"); 0108 QByteArray s = QByteArray::fromBase64(g.readEntry("state", QByteArray())); 0109 if (!s.isNull()) { 0110 QHeaderView *v = m_chunk_view->header(); 0111 v->restoreState(s); 0112 m_chunk_view->sortByColumn(v->sortIndicatorSection(), v->sortIndicatorOrder()); 0113 model->sort(v->sortIndicatorSection(), v->sortIndicatorOrder()); 0114 } 0115 } 0116 } 0117 0118 #include "moc_chunkdownloadview.cpp"