• 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
torrentfiletreemodel.h
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 #ifndef KTTORRENTFILETREEMODEL_H
22 #define KTTORRENTFILETREEMODEL_H
23 
24 #include "torrentfilemodel.h"
25 #include <util/bitset.h>
26 
27 class QSortFilterProxyModel;
28 
29 namespace bt
30 {
31  class BEncoder;
32  class BNode;
33 }
34 
35 namespace kt
36 {
37 
42  class TorrentFileTreeModel : public TorrentFileModel
43  {
44  Q_OBJECT
45  protected:
46  struct Node
47  {
48  Node* parent;
49  bt::TorrentFileInterface* file; // file (0 if this is a directory)
50  QString name; // name or directory
51  QList<Node*> children; // child dirs
52  bt::Uint64 size;
53  bt::BitSet chunks;
54  bool chunks_set;
55  float percentage;
56 
57  Node(Node* parent,bt::TorrentFileInterface* file,const QString & name,
58  bt::Uint32 total_chunks);
59  Node(Node* parent,const QString & name, bt::Uint32 total_chunks);
60  ~Node();
61 
62  void insert(const QString & path,bt::TorrentFileInterface* file, bt::Uint32 num_chunks);
63  int row();
64  bt::Uint64 fileSize(const bt::TorrentInterface* tc);
65  bt::Uint64 bytesToDownload(const bt::TorrentInterface* tc);
66  Qt::CheckState checkState(const bt::TorrentInterface* tc) const;
67  QString path();
68  void fillChunks();
69  void updatePercentage(const bt::BitSet & havechunks);
70  void initPercentage(const bt::TorrentInterface* tc,const bt::BitSet & havechunks);
71 
72  void saveExpandedState(const QModelIndex & index,QSortFilterProxyModel* pm,QTreeView* tv,bt::BEncoder* enc);
73  void loadExpandedState(const QModelIndex & index,QSortFilterProxyModel* pm,QTreeView* tv,bt::BNode* node);
74  };
75  public:
76  TorrentFileTreeModel(bt::TorrentInterface* tc,DeselectMode mode,QObject* parent);
77  virtual ~TorrentFileTreeModel();
78 
79  virtual int rowCount(const QModelIndex & parent) const;
80  virtual int columnCount(const QModelIndex & parent) const;
81  virtual QVariant headerData(int section, Qt::Orientation orientation,int role) const;
82  virtual QVariant data(const QModelIndex & index, int role) const;
83  virtual QModelIndex parent(const QModelIndex & index) const;
84  virtual QModelIndex index(int row,int column,const QModelIndex & parent) const;
85  virtual bool setData(const QModelIndex & index, const QVariant & value, int role);
86  virtual void checkAll();
87  virtual void uncheckAll();
88  virtual void invertCheck();
89  virtual bt::Uint64 bytesToDownload();
90  virtual QByteArray saveExpandedState(QSortFilterProxyModel* pm,QTreeView* tv);
91  virtual void loadExpandedState(QSortFilterProxyModel* pm,QTreeView* tv,const QByteArray & state);
92  virtual bt::TorrentFileInterface* indexToFile(const QModelIndex & idx);
93  virtual QString dirPath(const QModelIndex & idx);
94  virtual void changePriority(const QModelIndexList & indexes,bt::Priority newpriority);
95  virtual void onCodecChange();
96  private:
97  void constructTree();
98  void invertCheck(const QModelIndex & idx);
99  bool setCheckState(const QModelIndex & index, Qt::CheckState state);
100  bool setName(const QModelIndex & index,const QString & name);
101  void modifyPathOfFiles(Node* n,const QString & path);
102 
103 
104  protected:
105  Node* root;
106  bool emit_check_state_change;
107  };
108 
109 }
110 
111 #endif
kt::TorrentFileTreeModel::Node::path
QString path()
Definition: torrentfiletreemodel.cpp:301
kt::TorrentFileTreeModel::saveExpandedState
virtual QByteArray saveExpandedState(QSortFilterProxyModel *pm, QTreeView *tv)
Save which items are expanded.
Definition: torrentfiletreemodel.cpp:640
kt::TorrentFileModel::mode
DeselectMode mode
Definition: torrentfilemodel.h:142
kt::TorrentFileTreeModel::columnCount
virtual int columnCount(const QModelIndex &parent) const
Definition: torrentfiletreemodel.cpp:361
kt::TorrentFileTreeModel::loadExpandedState
virtual void loadExpandedState(QSortFilterProxyModel *pm, QTreeView *tv, const QByteArray &state)
Retore the expanded state of the tree.in a QTreeView.
Definition: torrentfiletreemodel.cpp:654
kt::TorrentFileTreeModel::changePriority
virtual void changePriority(const QModelIndexList &indexes, bt::Priority newpriority)
Change the priority of a bunch of items.
Definition: torrentfiletreemodel.cpp:700
kt::TorrentFileModel::tc
bt::TorrentInterface * tc
Definition: torrentfilemodel.h:141
kt::TorrentFileTreeModel::Node::~Node
~Node()
Definition: torrentfiletreemodel.cpp:54
torrentfilemodel.h
kt::TorrentFileTreeModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: torrentfiletreemodel.cpp:369
kt::TorrentFileTreeModel::dirPath
virtual QString dirPath(const QModelIndex &idx)
Get the path of a directory (root directory not included)
Definition: torrentfiletreemodel.cpp:680
kt::TorrentFileTreeModel::uncheckAll
virtual void uncheckAll()
Uncheck all files in the torrent.
Definition: torrentfiletreemodel.cpp:595
kt::TorrentFileTreeModel::Node::insert
void insert(const QString &path, bt::TorrentFileInterface *file, bt::Uint32 num_chunks)
Definition: torrentfiletreemodel.cpp:59
kt::TorrentFileTreeModel::~TorrentFileTreeModel
virtual ~TorrentFileTreeModel()
Definition: torrentfiletreemodel.cpp:322
QObject
kt::TorrentFileTreeModel::Node::name
QString name
Definition: torrentfiletreemodel.h:50
kt::TorrentFileTreeModel::onCodecChange
virtual void onCodecChange()
Codec has changed, so update the model.
Definition: torrentfiletreemodel.cpp:340
kt::TorrentFileTreeModel::parent
virtual QModelIndex parent(const QModelIndex &index) const
Definition: torrentfiletreemodel.cpp:436
kt::TorrentFileTreeModel::Node::chunks_set
bool chunks_set
Definition: torrentfiletreemodel.h:54
kt::TorrentFileTreeModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
Definition: torrentfiletreemodel.cpp:576
kt::TorrentFileTreeModel::Node::initPercentage
void initPercentage(const bt::TorrentInterface *tc, const bt::BitSet &havechunks)
Definition: torrentfiletreemodel.cpp:166
kt::TorrentFileTreeModel::bytesToDownload
virtual bt::Uint64 bytesToDownload()
Calculate the number of bytes to download.
Definition: torrentfiletreemodel.cpp:632
kt::TorrentFileTreeModel::Node::loadExpandedState
void loadExpandedState(const QModelIndex &index, QSortFilterProxyModel *pm, QTreeView *tv, bt::BNode *node)
Definition: torrentfiletreemodel.cpp:275
QTreeView
kt::TorrentFileTreeModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
Definition: torrentfiletreemodel.cpp:452
kt::TorrentFileTreeModel::Node
Definition: torrentfiletreemodel.h:46
kt::TorrentFileTreeModel
Model for displaying file trees of a torrent.
Definition: torrentfiletreemodel.h:42
kt::TorrentFileTreeModel::Node::fillChunks
void fillChunks()
Definition: torrentfiletreemodel.cpp:111
kt::TorrentFileTreeModel::checkAll
virtual void checkAll()
Check all the files in the torrent.
Definition: torrentfiletreemodel.cpp:589
kt::TorrentFileTreeModel::TorrentFileTreeModel
TorrentFileTreeModel(bt::TorrentInterface *tc, DeselectMode mode, QObject *parent)
Definition: torrentfiletreemodel.cpp:312
kt::TorrentFileTreeModel::Node::chunks
bt::BitSet chunks
Definition: torrentfiletreemodel.h:53
kt::TorrentFileTreeModel::Node::file
bt::TorrentFileInterface * file
Definition: torrentfiletreemodel.h:49
kt::TorrentFileModel::DeselectMode
DeselectMode
Definition: torrentfilemodel.h:43
kt::TorrentFileTreeModel::Node::parent
Node * parent
Definition: torrentfiletreemodel.h:48
kt::TorrentFileTreeModel::root
Node * root
Definition: torrentfiletreemodel.h:105
kt::TorrentFileTreeModel::invertCheck
virtual void invertCheck()
Invert the check of each file of the torrent.
Definition: torrentfiletreemodel.cpp:601
QSortFilterProxyModel
kt::TorrentFileTreeModel::Node::saveExpandedState
void saveExpandedState(const QModelIndex &index, QSortFilterProxyModel *pm, QTreeView *tv, bt::BEncoder *enc)
Definition: torrentfiletreemodel.cpp:253
kt::TorrentFileTreeModel::Node::size
bt::Uint64 size
Definition: torrentfiletreemodel.h:52
kt::TorrentFileTreeModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: torrentfiletreemodel.cpp:348
kt::TorrentFileTreeModel::Node::children
QList< Node * > children
Definition: torrentfiletreemodel.h:51
kt::TorrentFileTreeModel::Node::row
int row()
Definition: torrentfiletreemodel.cpp:85
kt::TorrentFileTreeModel::Node::checkState
Qt::CheckState checkState(const bt::TorrentInterface *tc) const
Definition: torrentfiletreemodel.cpp:224
kt::TorrentFileTreeModel::Node::Node
Node(Node *parent, bt::TorrentFileInterface *file, const QString &name, bt::Uint32 total_chunks)
Definition: torrentfiletreemodel.cpp:41
kt::TorrentFileTreeModel::Node::percentage
float percentage
Definition: torrentfiletreemodel.h:55
kt::TorrentFileTreeModel::indexToFile
virtual bt::TorrentFileInterface * indexToFile(const QModelIndex &idx)
Convert a model index to a file.
Definition: torrentfiletreemodel.cpp:668
kt::TorrentFileTreeModel::Node::bytesToDownload
bt::Uint64 bytesToDownload(const bt::TorrentInterface *tc)
Definition: torrentfiletreemodel.cpp:206
kt::TorrentFileTreeModel::emit_check_state_change
bool emit_check_state_change
Definition: torrentfiletreemodel.h:106
kt::TorrentFileTreeModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: torrentfiletreemodel.cpp:383
kt::TorrentFileTreeModel::Node::fileSize
bt::Uint64 fileSize(const bt::TorrentInterface *tc)
Definition: torrentfiletreemodel.cpp:93
kt::TorrentFileModel
Definition: torrentfilemodel.h:39
kt::TorrentFileTreeModel::Node::updatePercentage
void updatePercentage(const bt::BitSet &havechunks)
Definition: torrentfiletreemodel.cpp:132
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