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 TransferManager::cancelDownload(const QString& repo_id, const QString& path) { FileDownloadTask* task = getDownloadTask(repo_id, path); QSharedPointer<FileDownloadTask> shared_task = task->sharedFromThis().objectCast<FileDownloadTask>(); if (!task) { return; } if (task == current_download_) { task->cancel(); } else { pending_downloads_.removeOne(shared_task); } }
FileDownloadTask* TransferManager::addDownloadTask(const Account& account, const QString& repo_id, const QString& path, const QString& local_path) { FileDownloadTask* existing_task = getDownloadTask(repo_id, path); if (existing_task) { return existing_task; } FileDownloadTask* task = new FileDownloadTask(account, repo_id, path, local_path); QSharedPointer<FileDownloadTask> shared_task = task->sharedFromThis().objectCast<FileDownloadTask>(); connect(task, SIGNAL(finished(bool)), this, SLOT(onDownloadTaskFinished(bool))); if (current_download_) { pending_downloads_.enqueue(shared_task); } else { startDownloadTask(shared_task); } return task; }
void FileDownloadHelper::downloadFile(const QString &id) { DataManager data_mgr(account_); QString cached_file = data_mgr.getLocalCachedFile(repo_.id, path_, id); if (!cached_file.isEmpty()) { openFile(cached_file, false); return; } // endless loop for setPasswordDialog while(true) { FileDownloadTask *task = data_mgr.createDownloadTask(repo_.id, path_); FileBrowserProgressDialog dialog(task, parent_); if (dialog.exec()) { QString full_path = data_mgr.getLocalCachedFile(repo_.id, path_, task->fileId()); if (!full_path.isEmpty()) openFile(full_path, true); break; } // if the user canceled the task, don't bother it if (task->error() == FileNetworkTask::TaskCanceled) break; // if the repo_sitory is encrypted and password is incorrect if (repo_.encrypted && task->httpErrorCode() == 400) { SetRepoPasswordDialog password_dialog(repo_, parent_); if (password_dialog.exec()) continue; // the user canceled the dialog? skip break; } QString msg = QObject::tr("Unable to download item \"%1\"").arg(path_); seafApplet->warningBox(msg); break; } }
void DataManager::onFileDownloadFinished(bool success) { FileDownloadTask *task = qobject_cast<FileDownloadTask *>(sender()); if (task == NULL) return; if (success) { filecache_->saveCachedFileId(task->repoId(), task->path(), account_.getSignature(), task->fileId(), task->localFilePath()); // TODO we don't want to watch readonly files AutoUpdateManager::instance()->watchCachedFile(account_, task->repoId(), task->path()); } }