void RepoTreeView::onItemDoubleClicked(const QModelIndex& index) { QStandardItem *item = getRepoItem(index); if (!item) { return; } if (item->type() == REPO_ITEM_TYPE) { RepoItem *it = (RepoItem *)item; const LocalRepo& local_repo = it->localRepo(); if (local_repo.isValid()) { // open local folder for downloaded repo QDesktopServices::openUrl(QUrl::fromLocalFile(local_repo.worktree)); } else { // open seahub repo page for not downloaded repo // if (seafApplet->isPro()) { FileBrowserDialog* dialog = new FileBrowserDialog(it->repo(), this); const QRect screen = QApplication::desktop()->screenGeometry(); dialog->setAttribute(Qt::WA_DeleteOnClose, true); dialog->show(); dialog->move(screen.center() - dialog->rect().center()); dialog->raise(); // } else { // const Account& account = seafApplet->accountManager()->accounts()[0]; // if (account.isValid()) { // QUrl url = account.getAbsoluteUrl("repo/" + it->repo().id); // QDesktopServices::openUrl(url); // } // } } } }
void RepoTreeModel::removeReposDeletedOnServer(const std::vector<ServerRepo>& repos) { int i, n; DeleteRepoData data; n = repos.size(); for (i = 0; i < n; i++) { const ServerRepo& repo = repos[i]; data.map.insert(repo.id, &repo); } forEachRepoItem(&RepoTreeModel::collectDeletedRepos, (void *)&data); QListIterator<RepoItem*> iter(data.itemsToDelete); while(iter.hasNext()) { RepoItem *item = iter.next(); const ServerRepo& repo = item->repo(); qDebug("remove repo %s(%s) from \"%s\"\n", toCStr(repo.name), toCStr(repo.id), toCStr(((RepoCategoryItem*)item->parent())->name())); item->parent()->removeRow(item->row()); } }
void RepoTreeModel::checkGroupRepo(const ServerRepo& repo) { QStandardItem *root = invisibleRootItem(); RepoCategoryItem *group = NULL; int row, n = root->rowCount(); // First find for create the group // Starts from row 2 because the first two rows are "My Libraries" and "Shared Libraries" for (row = 2; row < n; row ++) { RepoCategoryItem *item = (RepoCategoryItem *)(root->child(row)); if (item->groupId() == repo.group_id) { group = item; break; } } if (!group) { group = new RepoCategoryItem(repo.group_name, repo.group_id); appendRow(group); } // Find the repo in this group n = group->rowCount(); for (row = 0; row < n; row++) { RepoItem *item = (RepoItem *)(group->child(row)); if (item->repo().id == repo.id) { updateRepoItem(item, repo); return; } } // Current repo not in this group yet RepoItem *item = new RepoItem(repo); group->appendRow(item); }
bool RepoFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { RepoTreeModel *tree_model = (RepoTreeModel *)(sourceModel()); QStandardItem *item_l = tree_model->itemFromIndex(left); QStandardItem *item_r = tree_model->itemFromIndex(right); /** * When we have filter: sort category by matched repos count * When we have no filter: sort category by category index order * */ if (item_l->type() == REPO_CATEGORY_TYPE) { // repo categories RepoCategoryItem *cl = (RepoCategoryItem *)item_l; RepoCategoryItem *cr = (RepoCategoryItem *)item_r; if (has_filter_) { // printf ("%s matched: %d, %s matched: %d\n", // cl->name().toUtf8().data(), cl->matchedReposCount(), // cr->name().toUtf8().data(), cr->matchedReposCount()); return cl->matchedReposCount() > cr->matchedReposCount(); } else { int cat_l = cl->categoryIndex(); int cat_r = cr->categoryIndex(); if (cat_l == cat_r) { return cl->name() < cr->name(); } else { return cat_l < cat_r; } } } else { // repos RepoItem *cl = (RepoItem *)item_l; RepoItem *cr = (RepoItem *)item_r; return cl->repo().mtime > cr->repo().mtime; } return false; }
void RepoTreeModel::checkSyncedRepo(const ServerRepo& repo) { int row, n = synced_repos_category_->rowCount(); for (row = 0; row < n; row++) { RepoItem *item = (RepoItem *)(synced_repos_category_->child(row)); if (item->repo().id == repo.id) { updateRepoItem(item, repo); return; } } // The repo is new RepoItem *item = new RepoItem(repo); synced_repos_category_->appendRow(item); }
void RepoTreeModel::checkVirtualRepo(const ServerRepo& repo) { if (item(kIndexOfVirtualReposCategory) != virtual_repos_category_) { insertRow(kIndexOfVirtualReposCategory, virtual_repos_category_); } int row, n = virtual_repos_category_->rowCount(); for (row = 0; row < n; row++) { RepoItem *item = (RepoItem *)(virtual_repos_category_->child(row)); if (item->repo().id == repo.id) { updateRepoItem(item, repo); return; } } // The repo is new RepoItem *item = new RepoItem(repo); virtual_repos_category_->appendRow(item); }
void RepoTreeModel::onFilterTextChanged(const QString& text) { // Recalculate the matched repos count for each category QStandardItem *root = invisibleRootItem(); int row, n; n = root->rowCount(); QRegExp re = makeFilterRegExp(text); for (row = 0; row < n; row++) { RepoCategoryItem *category = (RepoCategoryItem *)root->child(row); int j, total, matched = 0; total = category->rowCount(); for (j = 0; j < total; j++) { RepoItem *item = (RepoItem *)category->child(j); if (item->repo().name.contains(re)) { matched++; } } category->setMatchedReposCount(matched); } }
void RepoTreeModel::checkGroupRepo(const ServerRepo& repo) { QStandardItem *root = invisibleRootItem(); RepoCategoryItem *group = NULL; int row, n = root->rowCount(); for (row = 0; row < n; row ++) { RepoCategoryItem *item = (RepoCategoryItem *)(root->child(row)); if (item->groupId() == repo.group_id) { group = item; break; } } if (!group) { if (repo.group_name == "Organization") { group = new RepoCategoryItem(CAT_INDEX_PUBLIC_REPOS, tr("Organization"), repo.group_id); // Insert pub repos after "recent updated", "my libraries", "shared libraries" insertRow(3, group); } else { group = new RepoCategoryItem(CAT_INDEX_GROUP_REPOS, repo.group_name, repo.group_id); appendRow(group); } } // Find the repo in this group n = group->rowCount(); for (row = 0; row < n; row++) { RepoItem *item = (RepoItem *)(group->child(row)); if (item->repo().id == repo.id) { updateRepoItem(item, repo); return; } } // Current repo not in this group yet RepoItem *item = new RepoItem(repo); group->appendRow(item); }
void RepoTreeView::updateRepoActions() { RepoItem *item = NULL; QItemSelection selected = selectionModel()->selection(); QModelIndexList indexes = selected.indexes(); if (indexes.size() != 0) { const QModelIndex& index = indexes.at(0); QSortFilterProxyModel *proxy = (QSortFilterProxyModel *)model(); RepoTreeModel *tree_model = (RepoTreeModel *)(proxy->sourceModel()); QStandardItem *it = tree_model->itemFromIndex(proxy->mapToSource(index)); if (it && it->type() == REPO_ITEM_TYPE) { item = (RepoItem *)it; } } if (!item) { // No repo item is selected download_action_->setEnabled(false); download_toolbar_action_->setEnabled(false); sync_now_action_->setEnabled(false); open_local_folder_action_->setEnabled(false); open_local_folder_toolbar_action_->setEnabled(false); unsync_action_->setEnabled(false); resync_action_->setEnabled(false); toggle_auto_sync_action_->setEnabled(false); view_on_web_action_->setEnabled(false); show_detail_action_->setEnabled(false); return; } LocalRepo r; seafApplet->rpcClient()->getLocalRepo(item->repo().id, &r); item->setLocalRepo(r); if (item->localRepo().isValid()) { const LocalRepo& local_repo = item->localRepo(); download_action_->setEnabled(false); download_toolbar_action_->setEnabled(false); sync_now_action_->setEnabled(true); sync_now_action_->setData(QVariant::fromValue(local_repo)); open_local_folder_action_->setData(QVariant::fromValue(local_repo)); open_local_folder_action_->setEnabled(true); open_local_folder_toolbar_action_->setData(QVariant::fromValue(local_repo)); open_local_folder_toolbar_action_->setEnabled(true); unsync_action_->setData(QVariant::fromValue(local_repo)); unsync_action_->setEnabled(true); resync_action_->setData(QVariant::fromValue(local_repo)); resync_action_->setEnabled(true); toggle_auto_sync_action_->setData(QVariant::fromValue(local_repo)); toggle_auto_sync_action_->setEnabled(true); QIcon q_pause = ::getMenuIconSet(":/images/pause-gray.png"); QIcon q_play = ::getMenuIconSet(":/images/play-gray.png"); if (local_repo.auto_sync) { toggle_auto_sync_action_->setText(tr("Disable auto sync")); toggle_auto_sync_action_->setToolTip(tr("Disable auto sync")); toggle_auto_sync_action_->setIcon(q_pause); } else { toggle_auto_sync_action_->setText(tr("Enable auto sync")); toggle_auto_sync_action_->setToolTip(tr("Enable auto sync")); toggle_auto_sync_action_->setIcon(q_play); } } else { if (item->repoDownloadable()) { download_action_->setEnabled(true); download_toolbar_action_->setEnabled(true); download_action_->setData(QVariant::fromValue(item->repo())); download_toolbar_action_->setData(QVariant::fromValue(item->repo())); } else { download_action_->setEnabled(false); download_toolbar_action_->setEnabled(false); } sync_now_action_->setEnabled(false); open_local_folder_action_->setEnabled(false); open_local_folder_toolbar_action_->setEnabled(false); unsync_action_->setEnabled(false); resync_action_->setEnabled(false); toggle_auto_sync_action_->setEnabled(false); } view_on_web_action_->setEnabled(true); view_on_web_action_->setData(item->repo().id); show_detail_action_->setEnabled(true); show_detail_action_->setData(QVariant::fromValue(item->repo())); if (item->cloneTask().isCancelable()) { cancel_download_action_->setEnabled(true); cancel_download_action_->setData(QVariant::fromValue(item->repo())); } else { cancel_download_action_->setEnabled(false); } emit dataChanged(indexes.at(0), indexes.at(0)); }
void RepoTreeView::updateRepoActions() { RepoItem *item = NULL; QItemSelection selected = selectionModel()->selection(); QModelIndexList indexes = selected.indexes(); if (indexes.size() != 0) { const QModelIndex& index = indexes.at(0); QStandardItem *it = ((RepoTreeModel *)model())->itemFromIndex(index); if (it && it->type() == REPO_ITEM_TYPE) { item = (RepoItem *)it; } } if (!item) { // No repo item is selected download_action_->setEnabled(false); open_local_folder_action_->setEnabled(false); unsync_action_->setEnabled(false); toggle_auto_sync_action_->setEnabled(false); view_on_web_action_->setEnabled(false); show_detail_action_->setEnabled(false); return; } LocalRepo r; seafApplet->rpcClient()->getLocalRepo(item->repo().id, &r); item->setLocalRepo(r); if (item->localRepo().isValid()) { const LocalRepo& local_repo = item->localRepo(); download_action_->setEnabled(false); open_local_folder_action_->setData(QVariant::fromValue(local_repo)); open_local_folder_action_->setEnabled(true); unsync_action_->setData(QVariant::fromValue(local_repo)); unsync_action_->setEnabled(true); toggle_auto_sync_action_->setData(QVariant::fromValue(local_repo)); toggle_auto_sync_action_->setEnabled(true); if (local_repo.auto_sync) { toggle_auto_sync_action_->setText(tr("Disable auto sync")); toggle_auto_sync_action_->setToolTip(tr("Disable auto sync")); toggle_auto_sync_action_->setIcon(QIcon(":/images/pause.png")); } else { toggle_auto_sync_action_->setText(tr("Enable auto sync")); toggle_auto_sync_action_->setToolTip(tr("Enable auto sync")); toggle_auto_sync_action_->setIcon(QIcon(":/images/play.png")); } } else { download_action_->setEnabled(true); download_action_->setData(QVariant::fromValue(item->repo())); open_local_folder_action_->setEnabled(false); unsync_action_->setEnabled(false); toggle_auto_sync_action_->setEnabled(false); } view_on_web_action_->setEnabled(true); view_on_web_action_->setData(item->repo().id); show_detail_action_->setEnabled(true); show_detail_action_->setData(QVariant::fromValue(item->repo())); }