2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QTR_TREE_FILE_MODEL
|
|
|
|
#define QTR_TREE_FILE_MODEL
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QObject>
|
2010-07-28 18:53:25 +00:00
|
|
|
#include <QItemDelegate>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QList>
|
|
|
|
#include <QSet>
|
2010-07-28 18:53:25 +00:00
|
|
|
#include <QSize>
|
|
|
|
#include <QString>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QTreeView>
|
|
|
|
#include <QVariant>
|
2010-07-28 18:53:25 +00:00
|
|
|
|
|
|
|
class QSortFilterProxyModel;
|
|
|
|
class QStyle;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
#include "torrent.h" // FileList
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
class FileTreeItem: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
|
|
|
|
enum { LOW=(1<<0), NORMAL=(1<<1), HIGH=(1<<2) };
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~FileTreeItem( );
|
|
|
|
FileTreeItem( int fileIndex, const QString& name="" ):
|
|
|
|
myIndex(fileIndex), myParent(0), myName(name),
|
|
|
|
myPriority(0), myIsWanted(0),
|
|
|
|
myHaveSize(0), myTotalSize(0) { }
|
|
|
|
|
|
|
|
public:
|
|
|
|
void appendChild( FileTreeItem *child );
|
|
|
|
FileTreeItem * child( const QString& filename );
|
|
|
|
FileTreeItem * child( int row ) { return myChildren.at( row ); }
|
|
|
|
int childCount( ) const { return myChildren.size( ); }
|
|
|
|
FileTreeItem * parent( ) { return myParent; }
|
|
|
|
const FileTreeItem * parent( ) const { return myParent; }
|
|
|
|
int row( ) const;
|
|
|
|
const QString& name( ) const { return myName; }
|
|
|
|
QVariant data( int column ) const;
|
2010-05-05 09:41:14 +00:00
|
|
|
bool update( int index, bool want, int priority, uint64_t total, uint64_t have, bool torrentChanged );
|
2009-04-09 18:55:47 +00:00
|
|
|
void twiddleWanted( QSet<int>& fileIds, bool& );
|
|
|
|
void twiddlePriority( QSet<int>& fileIds, int& );
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setSubtreePriority( int priority, QSet<int>& fileIds );
|
|
|
|
void setSubtreeWanted( bool, QSet<int>& fileIds );
|
|
|
|
QString priorityString( ) const;
|
|
|
|
void getSubtreeSize( uint64_t& have, uint64_t& total ) const;
|
2010-04-03 13:56:23 +00:00
|
|
|
QString fileSizeName( ) const;
|
2009-04-09 18:55:47 +00:00
|
|
|
double progress( ) const;
|
|
|
|
int priority( ) const;
|
|
|
|
int isSubtreeWanted( ) const;
|
|
|
|
|
|
|
|
int myIndex;
|
|
|
|
FileTreeItem * myParent;
|
|
|
|
QList<FileTreeItem*> myChildren;
|
|
|
|
const QString myName;
|
|
|
|
int myPriority;
|
|
|
|
bool myIsWanted;
|
|
|
|
uint64_t myHaveSize;
|
|
|
|
uint64_t myTotalSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileTreeModel: public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
FileTreeModel( QObject *parent = 0);
|
|
|
|
~FileTreeModel( );
|
|
|
|
|
|
|
|
public:
|
|
|
|
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
|
|
|
|
Qt::ItemFlags flags( const QModelIndex& index ) const;
|
|
|
|
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
|
|
|
|
QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const;
|
|
|
|
QModelIndex parent( const QModelIndex& child ) const;
|
|
|
|
QModelIndex parent( const QModelIndex& child, int column ) const;
|
|
|
|
int rowCount( const QModelIndex& parent = QModelIndex( ) ) const;
|
|
|
|
int columnCount( const QModelIndex &parent = QModelIndex( ) ) const;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void priorityChanged( const QSet<int>& fileIndices, int );
|
|
|
|
void wantedChanged( const QSet<int>& fileIndices, bool );
|
|
|
|
|
|
|
|
public:
|
|
|
|
void clear( );
|
|
|
|
void addFile( int index, const QString& filename,
|
|
|
|
bool wanted, int priority,
|
|
|
|
uint64_t size, uint64_t have,
|
2010-05-05 09:41:14 +00:00
|
|
|
QList<QModelIndex>& rowsAdded,
|
|
|
|
bool torrentChanged );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void clearSubtree( const QModelIndex & );
|
|
|
|
QModelIndex indexOf( FileTreeItem *, int column ) const;
|
|
|
|
void parentsChanged( const QModelIndex &, int column );
|
|
|
|
void subtreeChanged( const QModelIndex &, int column );
|
|
|
|
|
|
|
|
private:
|
|
|
|
FileTreeItem * rootItem;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void clicked ( const QModelIndex & index );
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileTreeDelegate: public QItemDelegate
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
FileTreeDelegate( QObject * parent=0 ): QItemDelegate( parent ) { }
|
|
|
|
virtual ~FileTreeDelegate( ) { }
|
|
|
|
|
2010-07-28 18:53:25 +00:00
|
|
|
public:
|
|
|
|
virtual QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const;
|
|
|
|
virtual void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const;
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileTreeView: public QTreeView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
FileTreeView( QWidget * parent=0 );
|
2010-07-28 20:17:16 +00:00
|
|
|
virtual ~FileTreeView( );
|
2009-04-09 18:55:47 +00:00
|
|
|
void clear( );
|
|
|
|
void update( const FileList& files );
|
2010-05-05 09:41:14 +00:00
|
|
|
void update( const FileList& files, bool torrentChanged );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void priorityChanged( const QSet<int>& fileIndices, int );
|
|
|
|
void wantedChanged( const QSet<int>& fileIndices, bool );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool eventFilter( QObject *, QEvent * );
|
|
|
|
|
|
|
|
private:
|
|
|
|
FileTreeModel myModel;
|
2010-07-28 18:53:25 +00:00
|
|
|
QSortFilterProxyModel * myProxy;
|
2009-04-09 18:55:47 +00:00
|
|
|
FileTreeDelegate myDelegate;
|
2010-07-28 18:53:25 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onClicked ( const QModelIndex & index );
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|