diff --git a/Repository/RepoTreeView.cpp b/Repository/RepoTreeView.cpp index 2ef7834..09ca0d3 100644 --- a/Repository/RepoTreeView.cpp +++ b/Repository/RepoTreeView.cpp @@ -15,8 +15,11 @@ */ #include +#include #include +#include "libGitWrap/Operations/RemoteOperations.hpp" + #include "libMacGitverCore/Widgets/TreeViewCtxMenu.hpp" #include "libMacGitverCore/App/MacGitver.hpp" @@ -143,6 +146,64 @@ void RepoTreeView::onRepoDeactivated(RM::Repo* repo) } } +/** + * @brief This slot is called, when a single fetch operation finishes. + */ +void RepoTreeView::fetchOperationFinished() +{ + Git::FetchOperation* op = qobject_cast( sender() ); + Q_ASSERT( op ); + + Git::Result r( op->result() ); + if ( !r ) { + QMessageBox::warning( this, tr("Operation failed."), + tr("Failed to fetch repository '%1'.\nMessage: %2") + .arg(op->repository().name()).arg(r.errorText()) + ); + } + + // delete the operation + op->deleteLater(); +} + +void RepoTreeView::onCtxFetchAll() +{ + Heaven::Action* action = qobject_cast< Heaven::Action* >( sender() ); + Q_ASSERT( action ); + + RM::Repo* repo = qobject_cast< RM::Repo* >( action->activatedBy() ); + if( repo ) { + Git::Result r; + Git::Repository gitRepo = repo->gitRepo(); + const QStringList aliases( gitRepo.allRemoteNames(r) ); + if ( !r ) { + QMessageBox::warning( this, tr("Lookup of remotes failed"), + tr("Unable to lookup remotes for repository '%1'." + "\nMessage: %2").arg(repo->displayName()) + .arg(r.errorText()) + ); + return; + } + + if ( aliases.isEmpty() ) { + QMessageBox::information( this, tr("No Remotes found"), + tr("No remotes configured for repository '%1'.") + .arg(repo->displayName()) + ); + return; + } + + foreach (const QString& alias, aliases) { + Git::FetchOperation* op = new Git::FetchOperation( repo->gitRepo() ); + op->setRemoteAlias( alias ); + op->setBackgroundMode( true ); + connect( op, SIGNAL(finished()), this, SLOT(fetchOperationFinished()) ); + // TODO: create a central dialog to show progress of parallel operations + op->execute(); + } + } +} + BlueSky::ViewContext* RepoTreeView::createContextObject() const { return new RepositoryContext; diff --git a/Repository/RepoTreeView.hpp b/Repository/RepoTreeView.hpp index 5904fdb..00c0e7e 100644 --- a/Repository/RepoTreeView.hpp +++ b/Repository/RepoTreeView.hpp @@ -46,6 +46,8 @@ private slots: // from actions void onCtxActivate(); void onCtxClose(); + void onCtxFetchAll(); + private slots: // from mRepos void contextMenu( const QModelIndex& index, const QPoint& globalPos ); @@ -53,6 +55,9 @@ private slots: // for MacGitver::repoMan() void onRepoActivated(RM::Repo* repo); void onRepoDeactivated(RM::Repo* repo); +private slots: + void fetchOperationFinished(); + private: QModelIndex deeplyMapToSource( QModelIndex current ) const; BlueSky::ViewContext* createContextObject() const; diff --git a/Repository/RepoTreeViewCtxMenu.hid b/Repository/RepoTreeViewCtxMenu.hid index cbedc14..f1fdc61 100644 --- a/Repository/RepoTreeViewCtxMenu.hid +++ b/Repository/RepoTreeViewCtxMenu.hid @@ -16,8 +16,6 @@ Ui RepoTreeViewCtxMenu { - - Action Activate { Text "&Activate"; StatusToolTip "Make this repository the active one."; @@ -30,10 +28,26 @@ Ui RepoTreeViewCtxMenu { ConnectTo onCtxClose(); }; + + Action FetchAll { + Text "All Remotes"; + StatusToolTip "Fetch repository changes from all remotes."; + ConnectTo onCtxFetchAll(); + }; + + + Menu MenuFetch { + Text "Fetch"; + Action FetchAll; + Separator; + }; + Menu CtxMenuRepo { Action Activate; Separator; + Menu MenuFetch; + Separator; Action Close; }; @@ -41,6 +55,8 @@ Ui RepoTreeViewCtxMenu { Menu CtxMenuSMRepo { Action Activate; + Separator; + Menu MenuFetch; };