1 #ifndef SEAFILE_CLIENT_REPO_TREE_MODEL_H 2 #define SEAFILE_CLIENT_REPO_TREE_MODEL_H 3 4 #include <vector> 5 #include <QStandardItemModel> 6 #include <QSortFilterProxyModel> 7 #include <QModelIndex> 8 9 class ServerRepo; 10 class RepoItem; 11 class RepoCategoryItem; 12 class QTimer; 13 class RepoTreeView; 14 15 /** 16 * Tree model for repos. There are two levels of items: 17 * 18 * The first level: (RepoCategory) 19 * - My Libraries 20 * - Shared Libraries 21 * - Group 1 22 * - Group 2 23 * - Group N 24 * 25 * The sencond level is the libraries belonging to the first level item (RepoItem) 26 * 27 * - My Libraries 28 * - Notes 29 * - Musics 30 * - Logs 31 */ 32 class RepoTreeModel : public QStandardItemModel { 33 Q_OBJECT 34 35 public: 36 /** 37 * The default sorting order of repo categroies. 38 */ 39 enum RepoCategoryIndex { 40 CAT_INDEX_RECENT_UPDATED = 0, 41 CAT_INDEX_MY_REPOS, 42 CAT_INDEX_VIRTUAL_REPOS, 43 CAT_INDEX_SHARED_REPOS, 44 CAT_INDEX_PUBLIC_REPOS, 45 CAT_INDEX_GROUP_REPOS, 46 CAT_INDEX_SYNCED_REPOS, 47 }; 48 49 RepoTreeModel(QObject *parent=0); 50 ~RepoTreeModel(); 51 void setRepos(const std::vector<ServerRepo>& repos); 52 53 void clear(); 54 setTreeView(RepoTreeView * view)55 void setTreeView(RepoTreeView *view) { tree_view_ = view; } treeView()56 RepoTreeView* treeView() { return tree_view_; } 57 58 void updateRepoItemAfterSyncNow(const QString& repo_id); 59 void onFilterTextChanged(const QString& text); 60 int repo_category_height; 61 62 signals: 63 void repoStatusChanged(const QModelIndex& index); 64 65 private slots: 66 void refreshLocalRepos(); 67 68 private: 69 void checkPersonalRepo(const ServerRepo& repo); 70 void checkVirtualRepo(const ServerRepo& repo); 71 void checkSharedRepo(const ServerRepo& repo); 72 void checkOrgRepo(const ServerRepo& repo); 73 void checkGroupRepo(const ServerRepo& repo); 74 void checkSyncedRepo(const ServerRepo& repo); 75 void initialize(); 76 void updateLocalReposPerm(const QList<ServerRepo>& repos); 77 void updateRepoItem(RepoItem *item, const ServerRepo& repo); 78 void refreshRepoItem(RepoItem *item, void *data); 79 80 void forEachRepoItem(void (RepoTreeModel::*func)(RepoItem *, void *), 81 void *data, 82 QStandardItem *root = nullptr); 83 84 void forEachCategoryItem(void (*func)(RepoCategoryItem*, void *), 85 void *data, 86 QStandardItem *root = nullptr); 87 88 void removeReposDeletedOnServer(const std::vector<ServerRepo> &repos); 89 90 void collectDeletedRepos(RepoItem *item, void *vdata); 91 void updateRepoItemAfterSyncNow(RepoItem *item, void *data); 92 QModelIndex proxiedIndexFromItem(const QStandardItem* item); 93 94 RepoCategoryItem *recent_updated_category_; 95 RepoCategoryItem *my_repos_category_; 96 RepoCategoryItem *virtual_repos_category_; 97 RepoCategoryItem *shared_repos_category_; 98 RepoCategoryItem *org_repos_category_; 99 RepoCategoryItem *groups_root_category_; 100 RepoCategoryItem *synced_repos_category_; 101 102 QTimer *refresh_local_timer_; 103 104 RepoTreeView *tree_view_; 105 }; 106 107 /** 108 * This model is used to implement (only show repos filtered by user typed text) 109 */ 110 class RepoFilterProxyModel : public QSortFilterProxyModel { 111 Q_OBJECT 112 public: 113 RepoFilterProxyModel(QObject* parent=0); 114 115 void setSourceModel(QAbstractItemModel *source_model); 116 117 void setFilterText(const QString& text); 118 bool filterAcceptsRow(int source_row, 119 const QModelIndex & source_parent) const; 120 bool lessThan(const QModelIndex &left, 121 const QModelIndex &right) const; 122 Qt::ItemFlags flags(const QModelIndex& index) const; 123 124 private slots: 125 void onRepoStatusChanged(const QModelIndex& source_index); 126 127 private: 128 bool has_filter_; 129 }; 130 131 #endif // SEAFILE_CLIENT_REPO_TREE_MODEL_H 132