kget
chunkdownloadview.cpp
Go to the documentation of this file.00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <QHeaderView>
00025 #include <QSortFilterProxyModel>
00026 #include <klocale.h>
00027 #include <interfaces/torrentinterface.h>
00028 #include <interfaces/torrentfileinterface.h>
00029 #include <interfaces/chunkdownloadinterface.h>
00030 #include <util/functions.h>
00031 #include <util/log.h>
00032 #include "chunkdownloadview.h"
00033 #include "chunkdownloadmodel.h"
00034
00035 using namespace bt;
00036
00037 namespace kt
00038 {
00039
00040
00041 ChunkDownloadView::ChunkDownloadView(QWidget* parent) : QWidget(parent),curr_tc(0)
00042 {
00043 setupUi(this);
00044 model = new ChunkDownloadModel(this);
00045 QSortFilterProxyModel* pm = new QSortFilterProxyModel(this);
00046 pm->setSourceModel(model);
00047 pm->setSortRole(Qt::UserRole);
00048 m_chunk_view->setModel(pm);
00049 m_chunk_view->setRootIsDecorated(false);
00050 m_chunk_view->setSortingEnabled(true);
00051 m_chunk_view->setAlternatingRowColors(true);
00052 }
00053
00054 ChunkDownloadView::~ChunkDownloadView()
00055 {
00056 }
00057
00058 void ChunkDownloadView::downloadAdded(ChunkDownloadInterface* cd)
00059 {
00060 model->downloadAdded(cd);
00061 }
00062
00063 void ChunkDownloadView::downloadRemoved(ChunkDownloadInterface* cd)
00064 {
00065 model->downloadRemoved(cd);
00066 }
00067
00068 void ChunkDownloadView::update()
00069 {
00070 if (!curr_tc)
00071 return;
00072
00073 model->update();
00074
00075 const TorrentStats & s = curr_tc->getStats();
00076 m_chunks_downloading->setText(QString::number(s.num_chunks_downloading));
00077 m_chunks_downloaded->setText(QString::number(s.num_chunks_downloaded));
00078 m_excluded_chunks->setText(QString::number(s.num_chunks_excluded));
00079 m_chunks_left->setText(QString::number(s.num_chunks_left));
00080 }
00081
00082 void ChunkDownloadView::changeTC(TorrentInterface* tc)
00083 {
00084 curr_tc = tc;
00085 if (!curr_tc)
00086 {
00087 setEnabled(false);
00088 }
00089 else
00090 {
00091 setEnabled(true);
00092 const TorrentStats & s = curr_tc->getStats();
00093 m_total_chunks->setText(QString::number(s.total_chunks));
00094 m_size_chunks->setText(BytesToString(s.chunk_size));
00095 }
00096 model->changeTC(tc);
00097 }
00098
00099 void ChunkDownloadView::removeAll()
00100 {
00101 model->clear();
00102 }
00103
00104 void ChunkDownloadView::saveState(KSharedConfigPtr cfg)
00105 {
00106 KConfigGroup g = cfg->group("ChunkDownloadView");
00107 QByteArray s = m_chunk_view->header()->saveState();
00108 g.writeEntry("state",s.toBase64());
00109 }
00110
00111 void ChunkDownloadView::loadState(KSharedConfigPtr cfg)
00112 {
00113 KConfigGroup g = cfg->group("ChunkDownloadView");
00114 QByteArray s = QByteArray::fromBase64(g.readEntry("state",QByteArray()));
00115 if (!s.isNull())
00116 m_chunk_view->header()->restoreState(s);
00117 }
00118 }
00119
00120 #include "chunkdownloadview.moc"