void SeafileRpcClient::getSyncStatus(LocalRepo &repo) { if (repo.worktree_invalid) { repo.setSyncInfo("error", "invalid worktree"); return; } GError *error = NULL; SeafileSyncTask *task = (SeafileSyncTask *) searpc_client_call__object (seafile_rpc_client_, "seafile_get_repo_sync_task", SEAFILE_TYPE_SYNC_TASK, &error, 1, "string", toCStr(repo.id)); if (error) { repo.setSyncInfo("unknown"); return; } if (!task) { repo.setSyncInfo("waiting for sync"); return; } char *state = NULL; char *err = NULL; g_object_get(task, "state", &state, "error", &err, NULL); repo.setSyncInfo(state, g_strcmp0(state, "error") == 0 ? err : NULL); g_free (state); g_free (err); g_object_unref(task); }
void InitVirtualDriveDialog::startDownload(const QString& repo_id) { default_repo_id_ = repo_id; LocalRepo repo; seafApplet->rpcClient()->getLocalRepo(repo_id, &repo); if (repo.isValid()) { // This repo is already here qDebug("The default library has already been downloaded"); default_repo_path_ = repo.worktree; finish(); return; } download_default_repo_req_ = new DownloadRepoRequest(account_, repo_id, false); connect(download_default_repo_req_, SIGNAL(success(const RepoDownloadInfo&)), this, SLOT(onDownloadRepoSuccess(const RepoDownloadInfo&))); connect(download_default_repo_req_, SIGNAL(failed(const ApiError&)), this, SLOT(onDownloadRepoFailure(const ApiError&))); download_default_repo_req_->send(); }
void SeafileTrayIcon::onMessageClicked() { if (repo_id_.isEmpty()) return; LocalRepo repo; if (seafApplet->rpcClient()->getLocalRepo(repo_id_, &repo) != 0 || !repo.isValid() || repo.worktree_invalid) return; showInGraphicalShell(repo.worktree); }
void SeafileExtensionHandler::onLockFileSuccess() { LockFileRequest *req = qobject_cast<LockFileRequest *>(sender()); LocalRepo repo; seafApplet->rpcClient()->getLocalRepo(req->repoId(), &repo); if (repo.isValid()) { seafApplet->rpcClient()->markFileLockState(req->repoId(), req->path(), req->lock()); QString path = QDir::toNativeSeparators(QDir(repo.worktree).absoluteFilePath(req->path().mid(1))); SHChangeNotify(SHCNE_ATTRIBUTES, SHCNF_PATH, path.toUtf8().data(), NULL); } }
void SeafileTrayIcon::onMessageClicked() { if (repo_id_.isEmpty()) return; LocalRepo repo; if (seafApplet->rpcClient()->getLocalRepo(repo_id_, &repo) != 0 || !repo.isValid() || repo.worktree_invalid) return; DiffReader *reader = new DiffReader(repo, previous_commit_id_, commit_id_); QThreadPool::globalInstance()->start(reader); }
string OriCommand::cmd_remote(strstream &str) { FUSE_PLOG("Command: remote"); string subcmd; strwstream resp; LocalRepo *repo = priv->getRepo(); // Parse Command str.readPStr(subcmd); RWKey::sp lock = priv->nsLock.writeLock(); if (subcmd == "list") { map<string, Peer> peers = repo->getPeers(); map<string, Peer>::iterator it; strwstream resp; // System variables resp.writeUInt32(peers.size()); for (it = peers.begin(); it != peers.end(); it++) { resp.writeLPStr(it->first); resp.writeLPStr(it->second.getBlob()); } return resp.str(); } if (subcmd == "add") { string name, url; strwstream resp; str.readLPStr(name); str.readLPStr(url); repo->addPeer(name, url); resp.writeLPStr(""); return resp.str(); } if (subcmd == "del") { string name; strwstream resp; str.readLPStr(name); repo->removePeer(name); resp.writeLPStr(""); return resp.str(); } return "Unknown remote subcommand"; }
void RepoService::openLocalFile(const QString& repo_id, const QString& path_in_repo, QWidget *dialog_parent) { LocalRepo r; seafApplet->rpcClient()->getLocalRepo(repo_id, &r); if (r.isValid()) { QString path = QDir(r.worktree).filePath(path_in_repo); openFile(path); } else { ServerRepo repo = getRepo(repo_id); if (!repo.isValid()) { return; } const QString path = "/" + path_in_repo; const Account account = seafApplet->accountManager()->currentAccount(); DataManager data_mgr(account); // endless loop for setPasswordDialog while(1) { FileDownloadTask *task = data_mgr.createDownloadTask(repo_id, path); FileBrowserProgressDialog dialog(task, dialog_parent); task->start(); if (dialog.exec()) { QString full_path = data_mgr.getLocalCachedFile(repo_id, path, task->fileId()); if (!full_path.isEmpty()) openFile(full_path); break; } // if the user canceled the task, don't bother it if (task->error() == FileNetworkTask::TaskCanceled) break; // if the repository is encrypted and password is incorrect if (repo.encrypted && task->httpErrorCode() == 400) { SetRepoPasswordDialog password_dialog(repo, dialog_parent); if (password_dialog.exec()) continue; // the user cancel the dialog here? skip break; } QString msg = QObject::tr("Unable to download item \"%1\"").arg(path_in_repo); seafApplet->warningBox(msg); break; }; } }
void SyncErrorsTableView::onItemDoubleClicked(const QModelIndex& index) { SyncErrorsTableModel *model = (SyncErrorsTableModel *)this->model(); SyncError error = model->errorAt(index.row()); // printf("error repo id is %s\n", error.repo_id.toUtf8().data()); if (!error.repo_id.isEmpty()) { LocalRepo repo; seafApplet->rpcClient()->getLocalRepo(error.repo_id, &repo); if (repo.isValid()) { QDesktopServices::openUrl(QUrl::fromLocalFile(repo.worktree)); } } }
void RepoTreeModel::updateRepoItemAfterSyncNow(RepoItem *item, void *data) { QString repo_id = *(QString *)data; LocalRepo r = item->localRepo(); if (r.isValid() && r.id == repo_id) { // We manually set the sync state of the repo to "SYNC_STATE_ING" to give // the user immediate feedback r.setSyncInfo("initializing"); r.sync_state = LocalRepo::SYNC_STATE_ING; r.sync_state_str = tr("sync initializing"); item->setLocalRepo(r); item->setSyncNowClicked(true); } }
QVariant LocalReposListModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } LocalRepo repo = repos_[index.row()]; switch(role) { case Qt::DisplayRole: return repo.name; case Qt::DecorationRole: return repo.getIcon(); } return QVariant(); }
void SeafileRpcClient::getSyncStatus(LocalRepo &repo) { if (repo.worktree_invalid) { repo.setSyncInfo("error", "invalid worktree"); return; } GError *error = NULL; SeafileSyncTask *task = (SeafileSyncTask *) searpc_client_call__object (seafile_rpc_client_, "seafile_get_repo_sync_task", SEAFILE_TYPE_SYNC_TASK, &error, 1, "string", toCStr(repo.id)); if (error) { repo.setSyncInfo("unknown"); g_error_free(error); return; } if (!task) { repo.setSyncInfo("waiting for sync"); return; } char *state = NULL; char *err = NULL; g_object_get(task, "state", &state, "error", &err, NULL); // seaf-daemon would retry three times for errors like quota/permission // before setting the "state" field to "error", but the GUI should display // the error from the beginning. if (err != NULL && strlen(err) > 0 && strcmp(err, "Success") != 0) { state = g_strdup("error"); } repo.setSyncInfo(state, g_strcmp0(state, "error") == 0 ? err : NULL); if (repo.sync_state == LocalRepo::SYNC_STATE_ING) { getRepoTransferInfo(repo.id, &repo.transfer_rate, &repo.transfer_percentage); } g_free (state); g_free (err); g_object_unref(task); }
/* * Rebuild the index */ int cmd_rebuildindex(int argc, char * const argv[]) { if (argc != 1) { cout << "rebuildindex takes no arguments!" << endl; cout << "Usage: ori rebuildindex" << endl; } if (!repository.rebuildIndex()) return 1; return 0; }
string OriCommand::cmd_branch(strstream &str) { FUSE_PLOG("Command: branch"); string subcmd; strwstream resp; LocalRepo *repo = priv->getRepo(); // Parse Command str.readPStr(subcmd); if (subcmd == "get") { resp.writeLPStr(repo->getBranch()); return resp.str(); } if (subcmd == "set") { string branch; str.readPStr(branch); repo->setBranch(branch); resp.writeLPStr(""); return resp.str(); } if (subcmd == "list") { set<string> branches = repo->listBranches(); set<string>::iterator it; resp.writeUInt32(branches.size()); for (it = branches.begin(); it != branches.end(); it++) { resp.writeLPStr(*it); } return resp.str(); } return "Unknown remote subcommand"; }