• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kget

chunkdownloadview.cpp

Go to the documentation of this file.
00001 
00003 /***************************************************************************
00004  *   Copyright (C) 2007 by Joris Guisson and Ivan Vasic                    *
00005  *   joris.guisson@gmail.com                                               *
00006  *   ivasic@gmail.com                                                      *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
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"

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal