コード例 #1
0
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;
        };
    }
}
コード例 #2
0
void DataManager::onCreateSubrepoRefreshSuccess(const ServerRepo& repo)
{
    // okay, all green
    if (repo.isValid()) {
        ServerRepo fixed_repo = repo;
        fixed_repo.parent_path = create_subrepo_parent_path_;
        fixed_repo.parent_repo_id = create_subrepo_parent_repo_id_;
        emit createSubrepoSuccess(fixed_repo);
        return;
    }

    // it is not expected
    emit createSubrepoFailed(ApiError::fromHttpError(500));
}
コード例 #3
0
void EventDetailsDialog::getCommitDetailsFailed(const ApiError& error)
{
    ServerRepo repo = RepoService::instance()->getRepo(event_.repo_id);

    if (!repo.isValid()) {
        return;
    }

    if (repo.encrypted &&
        error.type() == ApiError::HTTP_ERROR &&
        error.httpErrorCode() == 400) {

        SetRepoPasswordDialog dialog(repo, this);

        if (dialog.exec() == QDialog::Accepted) {
            sendRequest();
        } else {
            reject();
        }
    }
}
コード例 #4
0
void DataManager::onCreateSubrepoSuccess(const QString& new_repoid)
{
    // if we have it, we are lucky
    ServerRepo repo = RepoService::instance()->getRepo(new_repoid);
    if (repo.isValid()) {
        ServerRepo fixed_repo = repo;
        fixed_repo.parent_path = create_subrepo_parent_path_;
        fixed_repo.parent_repo_id = create_subrepo_parent_repo_id_;
        emit createSubrepoSuccess(fixed_repo);
        return;
    }

    // if not found, we need call get repo (list repo is not reliable here)
    get_repo_req_.reset(new GetRepoRequest(account_, new_repoid));

    // connect
    connect(get_repo_req_.data(), SIGNAL(success(const ServerRepo&)),
            this, SLOT(onCreateSubrepoRefreshSuccess(const ServerRepo&)));
    connect(get_repo_req_.data(), SIGNAL(failed(const ApiError&)),
            this, SIGNAL(createSubrepoFailed(const ApiError&)));

    get_repo_req_->send();
}