2015-06-10 21:27:11 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2015-06-12 22:41:36 +00:00
|
|
|
#include <cstdint>
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
#include <QCoreApplication>
|
2015-06-10 21:27:11 +00:00
|
|
|
#include <QHash>
|
2015-06-12 22:12:12 +00:00
|
|
|
#include <QList>
|
2015-06-10 21:27:11 +00:00
|
|
|
#include <QSet>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
class FileTreeItem
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(FileTreeItem)
|
|
|
|
Q_DISABLE_COPY(FileTreeItem)
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2019-02-10 11:05:16 +00:00
|
|
|
/* *INDENT-OFF* */
|
2015-08-10 19:40:58 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
LOW = (1 << 0),
|
|
|
|
NORMAL = (1 << 1),
|
|
|
|
HIGH = (1 << 2)
|
2015-08-10 19:40:58 +00:00
|
|
|
};
|
2019-02-10 11:05:16 +00:00
|
|
|
/* *INDENT-ON* */
|
2015-08-10 19:40:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem(QString const& name = QString(), int fileIndex = -1, uint64_t size = 0) :
|
2017-04-19 12:04:45 +00:00
|
|
|
myName(name),
|
|
|
|
myFileIndex(fileIndex),
|
|
|
|
myTotalSize(size),
|
|
|
|
myParent(nullptr),
|
|
|
|
myPriority(0),
|
|
|
|
myIsWanted(false),
|
|
|
|
myHaveSize(0),
|
|
|
|
myFirstUnhashedRow(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
~FileTreeItem();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
|
|
|
void appendChild(FileTreeItem* child);
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem* child(QString const& filename);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
FileTreeItem* child(int row)
|
|
|
|
{
|
|
|
|
return myChildren.at(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
int childCount() const
|
|
|
|
{
|
|
|
|
return myChildren.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeItem* parent()
|
|
|
|
{
|
|
|
|
return myParent;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
FileTreeItem const* parent() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return myParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
int row() const;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const& name() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return myName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const;
|
2017-04-20 16:02:19 +00:00
|
|
|
std::pair<int, int> update(QString const& name, bool want, int priority, uint64_t have, bool updateFields);
|
2017-04-19 12:04:45 +00:00
|
|
|
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;
|
2017-04-20 16:02:19 +00:00
|
|
|
QHash<QString, int> const& getMyChildRows();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
private:
|
2015-06-12 22:12:12 +00:00
|
|
|
QString myName;
|
2017-04-20 16:02:19 +00:00
|
|
|
int const myFileIndex;
|
|
|
|
uint64_t const myTotalSize;
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
FileTreeItem* myParent;
|
2015-06-10 21:27:11 +00:00
|
|
|
QList<FileTreeItem*> myChildren;
|
2017-04-19 12:04:45 +00:00
|
|
|
QHash<QString, int> myChildRows;
|
2015-06-10 21:27:11 +00:00
|
|
|
int myPriority;
|
|
|
|
bool myIsWanted;
|
|
|
|
uint64_t myHaveSize;
|
|
|
|
size_t myFirstUnhashedRow;
|
|
|
|
};
|