• 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
webseedsmodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008 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 "webseedsmodel.h"
22 #include <klocale.h>
23 #include <interfaces/webseedinterface.h>
24 #include <interfaces/torrentinterface.h>
25 #include <util/functions.h>
26 
27 using namespace bt;
28 
29 namespace kt
30 {
31 
32  WebSeedsModel::WebSeedsModel(QObject* parent)
33  : QAbstractTableModel(parent),curr_tc(0)
34  {
35  }
36 
37 
38  WebSeedsModel::~WebSeedsModel()
39  {
40  }
41 
42  void WebSeedsModel::changeTC(bt::TorrentInterface* tc)
43  {
44  curr_tc = tc;
45  items.clear();
46  if (tc)
47  {
48  for (Uint32 i = 0;i < tc->getNumWebSeeds();++i)
49  {
50  const bt::WebSeedInterface* ws = curr_tc->getWebSeed(i);
51  Item item;
52  item.status = ws->getStatus();
53  item.downloaded = ws->getTotalDownloaded();
54  item.speed = ws->getDownloadRate();
55  items.append(item);
56  }
57  }
58  reset();
59  }
60 
61  bool WebSeedsModel::update()
62  {
63  if (!curr_tc)
64  return false;
65 
66  bool ret = false;
67 
68  for (Uint32 i = 0;i < curr_tc->getNumWebSeeds();++i)
69  {
70  const bt::WebSeedInterface* ws = curr_tc->getWebSeed(i);
71  Item & item = items[i];
72  bool changed = false;
73  if (item.status != ws->getStatus())
74  {
75  changed = true;
76  item.status = ws->getStatus();
77  }
78 
79  if (item.downloaded != ws->getTotalDownloaded())
80  {
81  changed = true;
82  item.downloaded = ws->getTotalDownloaded();
83  }
84 
85  if (item.speed != ws->getDownloadRate())
86  {
87  changed = true;
88  item.speed = ws->getDownloadRate();
89  }
90 
91  if (changed)
92  {
93  dataChanged(createIndex(i,1),createIndex(i,3));
94  ret = true;
95  }
96  }
97 
98  return ret;
99  }
100 
101  int WebSeedsModel::rowCount(const QModelIndex & parent) const
102  {
103  if (parent.isValid())
104  return 0;
105  else
106  return curr_tc ? curr_tc->getNumWebSeeds() : 0;
107  }
108 
109  int WebSeedsModel::columnCount(const QModelIndex & parent) const
110  {
111  if (parent.isValid())
112  return 0;
113  else
114  return 4;
115  }
116 
117  QVariant WebSeedsModel::headerData(int section, Qt::Orientation orientation,int role) const
118  {
119  if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
120  return QVariant();
121 
122  switch (section)
123  {
124  case 0: return i18n("URL");
125  case 1: return i18n("Speed");
126  case 2: return i18n("Downloaded");
127  case 3: return i18n("Status");
128  default: return QVariant();
129  }
130  }
131 
132  QVariant WebSeedsModel::data(const QModelIndex & index, int role) const
133  {
134  if (!curr_tc)
135  return QVariant();
136 
137  if (!index.isValid() || index.row() >= static_cast<int>(curr_tc->getNumWebSeeds()) || index.row() < 0)
138  return QVariant();
139 
140  if (role == Qt::DisplayRole)
141  {
142  const bt::WebSeedInterface* ws = curr_tc->getWebSeed(index.row());
143  switch (index.column())
144  {
145  case 0: return ws->getUrl().prettyUrl();
146  case 1: return bt::BytesPerSecToString(ws->getDownloadRate());
147  case 2: return bt::BytesToString(ws->getTotalDownloaded());
148  case 3: return ws->getStatus();
149  }
150  }
151  return QVariant();
152  }
153 
154 }
kt::WebSeedsModel::columnCount
virtual int columnCount(const QModelIndex &parent) const
Definition: webseedsmodel.cpp:109
kt::WebSeedsModel::~WebSeedsModel
virtual ~WebSeedsModel()
Definition: webseedsmodel.cpp:38
QObject
kt::WebSeedsModel::update
bool update()
See if we need to update the model.
Definition: webseedsmodel.cpp:61
webseedsmodel.h
kt::WebSeedsModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: webseedsmodel.cpp:132
kt::WebSeedsModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: webseedsmodel.cpp:101
kt::WebSeedsModel::changeTC
void changeTC(bt::TorrentInterface *tc)
Change the current torrent.
Definition: webseedsmodel.cpp:42
kt::WebSeedsModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: webseedsmodel.cpp:117
QAbstractTableModel
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:18 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