File: FileTreeItem.h

package info (click to toggle)
transmission 3.00-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 33,160 kB
  • sloc: ansic: 81,055; objc: 18,449; cpp: 16,303; sh: 4,470; javascript: 4,281; makefile: 1,081; xml: 139
file content (121 lines) | stat: -rw-r--r-- 2,468 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * 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.
 *
 */

#pragma once

#include <cstdint>

#include <QCoreApplication>
#include <QHash>
#include <QList>
#include <QSet>
#include <QString>
#include <QVariant>

class FileTreeItem
{
    Q_DECLARE_TR_FUNCTIONS(FileTreeItem)
    Q_DISABLE_COPY(FileTreeItem)

public:
/* *INDENT-OFF* */
    enum
    {
        LOW = (1 << 0),
        NORMAL = (1 << 1),
        HIGH = (1 << 2)
    };
/* *INDENT-ON* */

public:
    FileTreeItem(QString const& name = QString(), int fileIndex = -1, uint64_t size = 0) :
        myName(name),
        myFileIndex(fileIndex),
        myTotalSize(size),
        myParent(nullptr),
        myPriority(0),
        myIsWanted(false),
        myHaveSize(0),
        myFirstUnhashedRow(0)
    {
    }

    ~FileTreeItem();

public:
    void appendChild(FileTreeItem* child);
    FileTreeItem* child(QString const& filename);

    FileTreeItem* child(int row)
    {
        return myChildren.at(row);
    }

    int childCount() const
    {
        return myChildren.size();
    }

    FileTreeItem* parent()
    {
        return myParent;
    }

    FileTreeItem const* parent() const
    {
        return myParent;
    }

    int row() const;

    QString const& name() const
    {
        return myName;
    }

    QVariant data(int column, int role) const;
    std::pair<int, int> update(QString const& 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;

private:
    QString priorityString() const;
    QString sizeString() const;
    void getSubtreeWantedSize(uint64_t& have, uint64_t& total) const;
    double progress() const;
    uint64_t size() const;
    QHash<QString, int> const& getMyChildRows();

private:
    QString myName;
    int const myFileIndex;
    uint64_t const myTotalSize;

    FileTreeItem* myParent;
    QList<FileTreeItem*> myChildren;
    QHash<QString, int> myChildRows;
    int myPriority;
    bool myIsWanted;
    uint64_t myHaveSize;
    size_t myFirstUnhashedRow;
};