1 | /* |
---|
2 | * This file Copyright (C) 2009-2015 Mnemosyne LLC |
---|
3 | * |
---|
4 | * It may be used under the GNU GPL versions 2 or 3 |
---|
5 | * or any future license endorsed by Mnemosyne LLC. |
---|
6 | * |
---|
7 | * $Id: FileTreeItem.h 14537 2015-06-10 21:27:11Z mikedld $ |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef QTR_FILE_TREE_ITEM_H |
---|
11 | #define QTR_FILE_TREE_ITEM_H |
---|
12 | |
---|
13 | #include <stdint.h> |
---|
14 | |
---|
15 | #include <QObject> |
---|
16 | #include <QList> |
---|
17 | #include <QHash> |
---|
18 | #include <QSet> |
---|
19 | #include <QString> |
---|
20 | #include <QVariant> |
---|
21 | |
---|
22 | class FileTreeItem: public QObject |
---|
23 | { |
---|
24 | Q_OBJECT |
---|
25 | |
---|
26 | enum { LOW=(1<<0), NORMAL=(1<<1), HIGH=(1<<2) }; |
---|
27 | |
---|
28 | public: |
---|
29 | |
---|
30 | virtual ~FileTreeItem(); |
---|
31 | |
---|
32 | FileTreeItem (const QString& name=QString (), int fileIndex=-1, uint64_t size=0): |
---|
33 | myFileIndex (fileIndex), |
---|
34 | myParent (0), |
---|
35 | myName (name), |
---|
36 | myPriority (0), |
---|
37 | myIsWanted (0), |
---|
38 | myHaveSize (0), |
---|
39 | myTotalSize (size), |
---|
40 | myFirstUnhashedRow (0) {} |
---|
41 | |
---|
42 | public: |
---|
43 | void appendChild (FileTreeItem *child); |
---|
44 | FileTreeItem * child (const QString& filename); |
---|
45 | FileTreeItem * child (int row) { return myChildren.at(row); } |
---|
46 | int childCount () const { return myChildren.size(); } |
---|
47 | FileTreeItem * parent () { return myParent; } |
---|
48 | const FileTreeItem * parent () const { return myParent; } |
---|
49 | int row () const; |
---|
50 | const QString& name () const { return myName; } |
---|
51 | QVariant data (int column, int role) const; |
---|
52 | std::pair<int,int> update (const QString& name, bool want, int priority, uint64_t have, bool updateFields); |
---|
53 | void twiddleWanted (QSet<int>& fileIds, bool&); |
---|
54 | void twiddlePriority (QSet<int>& fileIds, int&); |
---|
55 | int fileIndex () const { return myFileIndex; } |
---|
56 | uint64_t totalSize () const { return myTotalSize; } |
---|
57 | QString path () const; |
---|
58 | bool isComplete () const; |
---|
59 | |
---|
60 | private: |
---|
61 | void setSubtreePriority (int priority, QSet<int>& fileIds); |
---|
62 | void setSubtreeWanted (bool, QSet<int>& fileIds); |
---|
63 | QString priorityString () const; |
---|
64 | QString sizeString () const; |
---|
65 | void getSubtreeWantedSize (uint64_t& have, uint64_t& total) const; |
---|
66 | double progress () const; |
---|
67 | int priority () const; |
---|
68 | int isSubtreeWanted () const; |
---|
69 | |
---|
70 | const int myFileIndex; |
---|
71 | FileTreeItem * myParent; |
---|
72 | QList<FileTreeItem*> myChildren; |
---|
73 | QHash<QString,int> myChildRows; |
---|
74 | const QHash<QString,int>& getMyChildRows(); |
---|
75 | QString myName; |
---|
76 | int myPriority; |
---|
77 | bool myIsWanted; |
---|
78 | uint64_t myHaveSize; |
---|
79 | const uint64_t myTotalSize; |
---|
80 | size_t myFirstUnhashedRow; |
---|
81 | }; |
---|
82 | |
---|
83 | #endif // QTR_FILE_TREE_ITEM_H |
---|