Revert "transmission: update from 2.13 to 2.22"
[tomato.git] / release / src / router / transmission / qt / file-tree.h
bloba8ee214dd4fc07d29188d4a1246bb2e58c2d7b36
1 /*
2 * This file Copyright (C) Mnemosyne LLC
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10 * $Id: file-tree.h 11092 2010-08-01 20:36:13Z charles $
13 #ifndef QTR_TREE_FILE_MODEL
14 #define QTR_TREE_FILE_MODEL
16 #include <QAbstractItemModel>
17 #include <QObject>
18 #include <QItemDelegate>
19 #include <QList>
20 #include <QSet>
21 #include <QSize>
22 #include <QString>
23 #include <QTreeView>
24 #include <QVariant>
26 class QSortFilterProxyModel;
27 class QStyle;
29 #include "torrent.h" // FileList
31 /****
32 *****
33 ****/
35 class FileTreeItem: public QObject
37 Q_OBJECT;
39 enum { LOW=(1<<0), NORMAL=(1<<1), HIGH=(1<<2) };
41 public:
42 virtual ~FileTreeItem( );
43 FileTreeItem( int fileIndex, const QString& name="" ):
44 myIndex(fileIndex), myParent(0), myName(name),
45 myPriority(0), myIsWanted(0),
46 myHaveSize(0), myTotalSize(0) { }
48 public:
49 void appendChild( FileTreeItem *child );
50 FileTreeItem * child( const QString& filename );
51 FileTreeItem * child( int row ) { return myChildren.at( row ); }
52 int childCount( ) const { return myChildren.size( ); }
53 FileTreeItem * parent( ) { return myParent; }
54 const FileTreeItem * parent( ) const { return myParent; }
55 int row( ) const;
56 const QString& name( ) const { return myName; }
57 QVariant data( int column ) const;
58 bool update( int index, bool want, int priority, uint64_t total, uint64_t have, bool torrentChanged );
59 void twiddleWanted( QSet<int>& fileIds, bool& );
60 void twiddlePriority( QSet<int>& fileIds, int& );
62 private:
63 void setSubtreePriority( int priority, QSet<int>& fileIds );
64 void setSubtreeWanted( bool, QSet<int>& fileIds );
65 QString priorityString( ) const;
66 void getSubtreeSize( uint64_t& have, uint64_t& total ) const;
67 QString fileSizeName( ) const;
68 double progress( ) const;
69 int priority( ) const;
70 int isSubtreeWanted( ) const;
72 int myIndex;
73 FileTreeItem * myParent;
74 QList<FileTreeItem*> myChildren;
75 const QString myName;
76 int myPriority;
77 bool myIsWanted;
78 uint64_t myHaveSize;
79 uint64_t myTotalSize;
82 class FileTreeModel: public QAbstractItemModel
84 Q_OBJECT
86 public:
87 FileTreeModel( QObject *parent = 0);
88 ~FileTreeModel( );
90 public:
91 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
92 Qt::ItemFlags flags( const QModelIndex& index ) const;
93 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
94 QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const;
95 QModelIndex parent( const QModelIndex& child ) const;
96 QModelIndex parent( const QModelIndex& child, int column ) const;
97 int rowCount( const QModelIndex& parent = QModelIndex( ) ) const;
98 int columnCount( const QModelIndex &parent = QModelIndex( ) ) const;
100 signals:
101 void priorityChanged( const QSet<int>& fileIndices, int );
102 void wantedChanged( const QSet<int>& fileIndices, bool );
104 public:
105 void clear( );
106 void addFile( int index, const QString& filename,
107 bool wanted, int priority,
108 uint64_t size, uint64_t have,
109 QList<QModelIndex>& rowsAdded,
110 bool torrentChanged );
112 private:
113 void clearSubtree( const QModelIndex & );
114 QModelIndex indexOf( FileTreeItem *, int column ) const;
115 void parentsChanged( const QModelIndex &, int column );
116 void subtreeChanged( const QModelIndex &, int column );
118 private:
119 FileTreeItem * rootItem;
121 public slots:
122 void clicked ( const QModelIndex & index );
125 class FileTreeDelegate: public QItemDelegate
127 Q_OBJECT
129 public:
130 FileTreeDelegate( QObject * parent=0 ): QItemDelegate( parent ) { }
131 virtual ~FileTreeDelegate( ) { }
133 public:
134 virtual QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const;
135 virtual void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const;
138 class FileTreeView: public QTreeView
140 Q_OBJECT
142 public:
143 FileTreeView( QWidget * parent=0 );
144 virtual ~FileTreeView( );
145 void clear( );
146 void update( const FileList& files );
147 void update( const FileList& files, bool torrentChanged );
149 signals:
150 void priorityChanged( const QSet<int>& fileIndices, int );
151 void wantedChanged( const QSet<int>& fileIndices, bool );
153 protected:
154 bool eventFilter( QObject *, QEvent * );
156 private:
157 FileTreeModel myModel;
158 QSortFilterProxyModel * myProxy;
159 FileTreeDelegate myDelegate;
161 public slots:
162 void onClicked ( const QModelIndex & index );
165 #endif