2014-06-03 14:33:07 +02:00
|
|
|
/* Contacts (for explanations, congratulations, insults) :
|
|
|
|
* - <florian.bigard@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SEAFILETREE_H
|
|
|
|
#define SEAFILETREE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QList>
|
|
|
|
#include <QPair>
|
|
|
|
|
|
|
|
#include "cloudfileservice.h"
|
|
|
|
|
|
|
|
// Reproduce the file system of Seafile server libraries
|
|
|
|
// Analog to a tree
|
|
|
|
class SeafileTree : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
public:
|
2014-06-03 14:33:07 +02:00
|
|
|
SeafileTree();
|
2014-06-04 17:58:28 +02:00
|
|
|
SeafileTree(const SeafileTree& copy);
|
2014-06-03 14:33:07 +02:00
|
|
|
~SeafileTree();
|
|
|
|
|
|
|
|
class Entry {
|
2014-06-04 17:58:28 +02:00
|
|
|
public:
|
|
|
|
enum Type { DIR = 0, FILE = 1, LIBRARY = 2, NONE = 3 };
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
Entry(const QString& name = QString(), const QString& id = QString(),
|
|
|
|
const Type& type = NONE)
|
|
|
|
: name_(name), id_(id), type_(type) {}
|
2014-06-05 14:24:06 +02:00
|
|
|
Entry(const Entry& entry)
|
|
|
|
: name_(entry.name()), id_(entry.id()), type_(entry.type()) {}
|
2014-06-03 14:33:07 +02:00
|
|
|
~Entry();
|
|
|
|
|
|
|
|
QString name() const;
|
2014-06-04 17:58:28 +02:00
|
|
|
void set_name(const QString& name);
|
2014-06-03 14:33:07 +02:00
|
|
|
QString id() const;
|
2014-06-04 17:58:28 +02:00
|
|
|
void set_id(const QString& id);
|
2014-06-03 14:33:07 +02:00
|
|
|
Type type() const;
|
2014-06-04 17:58:28 +02:00
|
|
|
void set_type(const Type& type);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
bool is_dir() const;
|
|
|
|
bool is_file() const;
|
|
|
|
bool is_library() const;
|
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
Entry& operator=(const Entry& entry);
|
|
|
|
bool operator==(const Entry& a) const;
|
|
|
|
bool operator!=(const Entry& a) const;
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
QString ToString() const;
|
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
static QString TypeToString(const Type& type);
|
|
|
|
static Type StringToType(const QString& type);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
private:
|
2014-06-03 14:33:07 +02:00
|
|
|
QString name_, id_;
|
|
|
|
Type type_;
|
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
friend QDataStream& operator<<(QDataStream& out,
|
|
|
|
const SeafileTree::Entry& entry);
|
|
|
|
friend QDataStream& operator>>(QDataStream& in, SeafileTree::Entry& entry);
|
2014-06-03 14:33:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef QList<Entry> Entries;
|
|
|
|
|
|
|
|
// Node of the tree
|
|
|
|
// Contains an entry
|
|
|
|
class TreeItem {
|
2014-06-04 17:58:28 +02:00
|
|
|
public:
|
|
|
|
TreeItem(const Entry& entry = Entry(),
|
|
|
|
const QList<TreeItem*>& children = QList<TreeItem*>())
|
|
|
|
: entry_(entry), children_(children) {}
|
2014-06-05 14:24:06 +02:00
|
|
|
TreeItem(const TreeItem& copy)
|
|
|
|
: entry_(copy.entry()), children_(copy.children()) {}
|
2014-06-03 14:33:07 +02:00
|
|
|
~TreeItem();
|
|
|
|
|
|
|
|
TreeItem* child(int i) const;
|
2014-06-04 17:58:28 +02:00
|
|
|
QList<TreeItem*> children() const;
|
2014-06-03 14:33:07 +02:00
|
|
|
// List of each child's entry
|
2014-06-04 17:58:28 +02:00
|
|
|
Entries children_entries() const;
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
void set_children(const QList<TreeItem*>& children);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
Entry entry() const;
|
2014-06-04 17:58:28 +02:00
|
|
|
void set_entry(const Entry& entry);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
void AppendChild(TreeItem* child);
|
|
|
|
void AppendChild(const Entry& entry);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
// True if child is removed
|
2014-06-04 17:58:28 +02:00
|
|
|
bool RemoveChild(TreeItem* child);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
// nullptr if we didn't find a child entry with the given name
|
2014-06-04 17:58:28 +02:00
|
|
|
TreeItem* FindChild(const QString& name) const;
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
// Convert the node in QString (for debug)
|
|
|
|
QString ToString(int i) const;
|
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
private:
|
2014-06-03 14:33:07 +02:00
|
|
|
Entry entry_;
|
2014-06-04 17:58:28 +02:00
|
|
|
QList<TreeItem*> children_;
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
friend QDataStream& operator<<(QDataStream& out,
|
|
|
|
SeafileTree::TreeItem* item);
|
|
|
|
friend QDataStream& operator>>(QDataStream& in,
|
|
|
|
SeafileTree::TreeItem*& item);
|
2014-06-03 14:33:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
QList<TreeItem*> libraries() const;
|
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
void AddLibrary(const QString& name, const QString& id);
|
|
|
|
void DeleteLibrary(const QString& id);
|
|
|
|
bool AddEntry(const QString& library, const QString& path,
|
|
|
|
const Entry& entry);
|
|
|
|
bool DeleteEntry(const QString& library, const QString& path,
|
|
|
|
const Entry& entry);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
// Get a list of pair (path, entry) corresponding to the subfiles (and
|
|
|
|
// recursively to the subsubfiles...) of the given item
|
|
|
|
QList<QPair<QString, SeafileTree::Entry>> GetRecursiveFilesOfDir(
|
|
|
|
const QString& path, const TreeItem* item);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
// nullptr if we didn't find the library with the given id
|
2014-06-04 17:58:28 +02:00
|
|
|
TreeItem* FindLibrary(const QString& library);
|
2014-06-03 14:33:07 +02:00
|
|
|
// nullptr if we didn't find the item
|
2014-06-04 17:58:28 +02:00
|
|
|
TreeItem* FindFromAbsolutePath(const QString& library, const QString& path);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
// Compare the server entries with the tree
|
|
|
|
// Emit signals (ToDelete, ToAdd, ToUpdate)
|
2014-06-04 17:58:28 +02:00
|
|
|
void CheckEntries(const Entries& server_entries, const Entry& library,
|
|
|
|
const QString& path);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
// Destroy the tree
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
// Print the tree in the debug log
|
|
|
|
void Print() const;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
// Entry to delete in the tree
|
2014-06-04 17:58:28 +02:00
|
|
|
void ToDelete(const QString& library, const QString& path,
|
|
|
|
const SeafileTree::Entry& entry);
|
2014-06-03 14:33:07 +02:00
|
|
|
// Entry to add in the tree
|
2014-06-04 17:58:28 +02:00
|
|
|
void ToAdd(const QString& library, const QString& path,
|
|
|
|
const SeafileTree::Entry& entry);
|
2014-06-03 14:33:07 +02:00
|
|
|
// Entry to update in the tree
|
2014-06-04 17:58:28 +02:00
|
|
|
void ToUpdate(const QString& library, const QString& path,
|
|
|
|
const SeafileTree::Entry& entry);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
private:
|
2014-06-03 14:33:07 +02:00
|
|
|
QList<TreeItem*> libraries_;
|
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
friend QDataStream& operator<<(QDataStream& out, const SeafileTree& tree);
|
|
|
|
friend QDataStream& operator>>(QDataStream& in, SeafileTree& tree);
|
2014-06-03 14:33:07 +02:00
|
|
|
};
|
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
QDataStream& operator<<(QDataStream& out, const SeafileTree& tree);
|
|
|
|
QDataStream& operator>>(QDataStream& in, SeafileTree& tree);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
QDataStream& operator<<(QDataStream& out, const SeafileTree::Entry& entry);
|
|
|
|
QDataStream& operator>>(QDataStream& in, SeafileTree::Entry& entry);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
2014-06-04 17:58:28 +02:00
|
|
|
QDataStream& operator<<(QDataStream& out, SeafileTree::TreeItem* item);
|
|
|
|
QDataStream& operator>>(QDataStream& in, SeafileTree::TreeItem*& item);
|
2014-06-03 14:33:07 +02:00
|
|
|
|
|
|
|
#endif // SEAFILETREE_H
|