1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 16:24:02 +00:00
transmission/qt/FileTreeItem.h

90 lines
2.4 KiB
C
Raw Normal View History

/*
* This file Copyright (C) 2009-2015 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
* $Id$
*/
#ifndef QTR_FILE_TREE_ITEM_H
#define QTR_FILE_TREE_ITEM_H
#include <cstdint>
2015-06-12 22:12:12 +00:00
#include <QCoreApplication>
#include <QHash>
2015-06-12 22:12:12 +00:00
#include <QList>
#include <QSet>
#include <QString>
#include <QVariant>
2015-06-12 22:12:12 +00:00
class FileTreeItem
{
2015-06-12 22:12:12 +00:00
Q_DECLARE_TR_FUNCTIONS (FileTreeItem)
Q_DISABLE_COPY (FileTreeItem)
public:
enum
{
LOW = (1 << 0),
NORMAL = (1 << 1),
HIGH = (1 << 2)
};
public:
2015-06-12 22:12:12 +00:00
FileTreeItem (const QString& name = QString (), int fileIndex = -1, uint64_t size = 0):
myName (name),
2015-06-12 22:12:12 +00:00
myFileIndex (fileIndex),
myTotalSize (size),
myParent (nullptr),
myPriority (0),
2015-06-12 22:12:12 +00:00
myIsWanted (false),
myHaveSize (0),
myFirstUnhashedRow (0) {}
2015-06-12 22:12:12 +00:00
~FileTreeItem();
public:
2015-06-12 22:12:12 +00:00
void appendChild (FileTreeItem * child);
FileTreeItem * child (const QString& filename);
2015-06-12 22:12:12 +00:00
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, int role) const;
2015-06-12 22:12:12 +00:00
std::pair<int, int> update (const QString& name, bool want, int priority, uint64_t have, bool updateFields);
void setSubtreeWanted (bool, QSet<int>& fileIds);
void setSubtreePriority (int priority, QSet<int>& fileIds);
int fileIndex () const { return myFileIndex; }
uint64_t totalSize () const { return myTotalSize; }
QString path () const;
bool isComplete () const;
int priority () const;
int isSubtreeWanted () const;
2015-06-12 22:12:12 +00:00
private:
QString priorityString () const;
QString sizeString () const;
void getSubtreeWantedSize (uint64_t& have, uint64_t& total) const;
double progress () const;
uint64_t size () const;
2015-06-12 22:12:12 +00:00
const QHash<QString,int>& getMyChildRows();
2015-06-12 22:12:12 +00:00
private:
QString myName;
const int myFileIndex;
2015-06-12 22:12:12 +00:00
const uint64_t myTotalSize;
FileTreeItem * myParent;
QList<FileTreeItem*> myChildren;
QHash<QString,int> myChildRows;
int myPriority;
bool myIsWanted;
uint64_t myHaveSize;
size_t myFirstUnhashedRow;
};
#endif // QTR_FILE_TREE_ITEM_H