DownloadRepoDialog::DownloadRepoDialog(const Account& account, const ServerRepo& repo, const QString& password, QWidget *parent) : QDialog(parent), repo_(repo), account_(account), merge_without_question_(false) { manual_merge_mode_ = false; setupUi(this); if (!repo.isSubfolder()) { setWindowTitle(tr("Sync library \"%1\"").arg(repo_.name)); } else { setWindowTitle(tr("Sync folder \"%1\"").arg(repo.parent_path)); } mDirectory->setPlaceholderText(getOperatingText(repo_)); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); mRepoIcon->setPixmap(repo.getPixmap()); mRepoName->setText(repo_.name); mOperationText->setText(tr("Sync to folder:")); if (repo_.encrypted) { if (!password.isEmpty()) { mPassword->setText(password); mPassword->setReadOnly(true); } mPassword->setVisible(true); mPasswordLabel->setVisible(true); } else { mPassword->setVisible(false); mPasswordLabel->setVisible(false); } int height = 250; #if defined(Q_OS_MAC) layout()->setContentsMargins(8, 9, 9, 5); layout()->setSpacing(6); verticalLayout_3->setSpacing(6); #endif if (repo.encrypted) { height += 50; } setMinimumHeight(height); setMaximumHeight(height); setDirectoryText(seafApplet->configurator()->worktreeDir()); connect(mSwitchModeHint, SIGNAL(linkActivated(const QString &)), this, SLOT(switchMode())); updateSyncMode(); mMergeHint->hide(); connect(mChooseDirBtn, SIGNAL(clicked()), this, SLOT(chooseDirAction())); connect(mOkBtn, SIGNAL(clicked()), this, SLOT(onOkBtnClicked())); }
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 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(); } } }
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)); }
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(); }