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

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • transfer-plugins
  • bittorrent
  • advanceddetails
chunkdownloadview.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007 by Joris Guisson and Ivan Vasic *
3  * joris.guisson@gmail.com *
4  * ivasic@gmail.com *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20  ***************************************************************************/
21 #include "chunkdownloadview.h"
22 
23 #include <QHeaderView>
24 #include <QSortFilterProxyModel>
25 #include <klocale.h>
26 #include <interfaces/torrentinterface.h>
27 #include <interfaces/torrentfileinterface.h>
28 #include <interfaces/chunkdownloadinterface.h>
29 #include <util/functions.h>
30 #include <util/log.h>
31 #include "chunkdownloadmodel.h"
32 
33 using namespace bt;
34 
35 namespace kt
36 {
37 
38 
39  ChunkDownloadView::ChunkDownloadView(QWidget* parent) : QWidget(parent),curr_tc(0)
40  {
41  setupUi(this);
42  model = new ChunkDownloadModel(this);
43  m_chunk_view->setModel(model);
44  m_chunk_view->setRootIsDecorated(false);
45  m_chunk_view->setSortingEnabled(true);
46  m_chunk_view->setAlternatingRowColors(true);
47  m_chunk_view->setUniformRowHeights(true);
48  }
49 
50  ChunkDownloadView::~ChunkDownloadView()
51  {
52  }
53 
54  void ChunkDownloadView::downloadAdded(ChunkDownloadInterface* cd)
55  {
56  model->downloadAdded(cd);
57  }
58 
59  void ChunkDownloadView::downloadRemoved(ChunkDownloadInterface* cd)
60  {
61  model->downloadRemoved(cd);
62  }
63 
64  void ChunkDownloadView::update()
65  {
66  if (!curr_tc)
67  return;
68 
69  model->update();
70  const TorrentStats & s = curr_tc->getStats();
71  m_chunks_downloading->setText(QString::number(s.num_chunks_downloading));
72  m_chunks_downloaded->setText(QString::number(s.num_chunks_downloaded));
73  m_excluded_chunks->setText(QString::number(s.num_chunks_excluded));
74  m_chunks_left->setText(QString::number(s.num_chunks_left));
75  }
76 
77  void ChunkDownloadView::changeTC(TorrentInterface* tc)
78  {
79  curr_tc = tc;
80  if (!curr_tc)
81  {
82  setEnabled(false);
83  }
84  else
85  {
86  setEnabled(true);
87  const TorrentStats & s = curr_tc->getStats();
88  m_total_chunks->setText(QString::number(s.total_chunks));
89  m_size_chunks->setText(BytesToString(s.chunk_size));
90  }
91  model->changeTC(tc);
92  }
93 
94  void ChunkDownloadView::removeAll()
95  {
96  model->clear();
97  }
98 
99  void ChunkDownloadView::saveState(KSharedConfigPtr cfg)
100  {
101  KConfigGroup g = cfg->group("ChunkDownloadView");
102  QByteArray s = m_chunk_view->header()->saveState();
103  g.writeEntry("state",s.toBase64());
104  }
105 
106  void ChunkDownloadView::loadState(KSharedConfigPtr cfg)
107  {
108  KConfigGroup g = cfg->group("ChunkDownloadView");
109  QByteArray s = QByteArray::fromBase64(g.readEntry("state",QByteArray()));
110  if (!s.isNull())
111  {
112  QHeaderView* v = m_chunk_view->header();
113  v->restoreState(s);
114  m_chunk_view->sortByColumn(v->sortIndicatorSection(),v->sortIndicatorOrder());
115  model->sort(v->sortIndicatorSection(),v->sortIndicatorOrder());
116  }
117  }
118 }
119 
120 #include "chunkdownloadview.moc"
kt::ChunkDownloadView::saveState
void saveState(KSharedConfigPtr cfg)
Definition: chunkdownloadview.cpp:99
kt::ChunkDownloadModel
Definition: chunkdownloadmodel.h:39
chunkdownloadview.h
QWidget
kt::ChunkDownloadView::downloadRemoved
void downloadRemoved(bt::ChunkDownloadInterface *cd)
A download has been removed.
Definition: chunkdownloadview.cpp:59
kt::ChunkDownloadView::downloadAdded
void downloadAdded(bt::ChunkDownloadInterface *cd)
A peer has been added.
Definition: chunkdownloadview.cpp:54
kt::ChunkDownloadModel::changeTC
void changeTC(bt::TorrentInterface *tc)
change the current torrent
Definition: chunkdownloadmodel.cpp:151
chunkdownloadmodel.h
kt::ChunkDownloadModel::update
void update()
Update the model.
Definition: chunkdownloadmodel.cpp:166
kt::ChunkDownloadModel::downloadAdded
void downloadAdded(bt::ChunkDownloadInterface *cd)
A peer has been added.
Definition: chunkdownloadmodel.cpp:101
kt::ChunkDownloadView::changeTC
void changeTC(bt::TorrentInterface *tc)
Change the torrent to display.
Definition: chunkdownloadview.cpp:77
kt::ChunkDownloadView::removeAll
void removeAll()
Remove all items.
Definition: chunkdownloadview.cpp:94
kt::ChunkDownloadModel::downloadRemoved
void downloadRemoved(bt::ChunkDownloadInterface *cd)
A download has been removed.
Definition: chunkdownloadmodel.cpp:134
kt::ChunkDownloadModel::sort
void sort(int col, Qt::SortOrder order)
Definition: chunkdownloadmodel.cpp:285
kt::ChunkDownloadView::update
void update()
Check to see if the GUI needs to be updated.
Definition: chunkdownloadview.cpp:64
kt::ChunkDownloadView::~ChunkDownloadView
virtual ~ChunkDownloadView()
Definition: chunkdownloadview.cpp:50
kt::ChunkDownloadModel::clear
void clear()
Definition: chunkdownloadmodel.cpp:159
kt::ChunkDownloadView::loadState
void loadState(KSharedConfigPtr cfg)
Definition: chunkdownloadview.cpp:106
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

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

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal