This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRemotesModule.cpp
More file actions
134 lines (116 loc) · 4.14 KB
/
RemotesModule.cpp
File metadata and controls
134 lines (116 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* MacGitver
* Copyright (C) 2012 Sascha Cunz <sascha@babbelbox.org>
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License (Version 2) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if
* not, see <http://www.gnu.org/licenses/>.
*
*/
#include <QtPlugin>
#include <QFileDialog>
#include <QMessageBox>
#include "libGitWrap/Operations/RemoteOperations.hpp"
#include "libMacGitverCore/App/MacGitver.hpp"
#include "libMacGitverCore/RepoMan/Repo.hpp"
#include "RemoteCreateEditDlg.h"
#include "RemotesModule.h"
#include "RemotesView.h"
RemotesModule::RemotesModule()
{
}
BlueSky::View* RemotesModule::createRemotesView()
{
return new RemotesView;
}
void RemotesModule::initialize()
{
setupActions( this );
acRemotesAC->mergeInto( "RemotesMP" );
acRemotesFetchAC->mergeInto( "RemotesFetchMP" );
MacGitver::self().registerView( "Remotes", tr( "Remotes" ),
&RemotesModule::createRemotesView );
}
void RemotesModule::deinitialize()
{
MacGitver::self().unregisterView( "Remotes" );
}
/**
* @brief Menu action to create a remote and add it to a repository.
*/
void RemotesModule::onRemoteCreateEdit()
{
// TODO: requires a repository context (the repo to add the remote to)
// To edit an existing remote, the remote context is required
RemoteCreateEditDlg dlg;
//TODO: dlg.setContext( ctx );
dlg.exec();
}
void RemotesModule::onRemoteDelete()
{
// TODO: requires the remote context (the remote to delete)
}
/**
* @brief Menu action to fetch all remotes of a repository.
*/
void RemotesModule::onRemotesFetchAll()
{
// TODO: requires a repository context (the repo to fetch all remotes from)
// A sub-context (i.e. a branch) can further restrict, what is fetched
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( 0, 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( 0, 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();
}
}
}
/**
* @brief Called, when an non-blocking Git::Operation finished.
*/
void RemotesModule::onOperationFinished()
{
Git::BaseOperation* op = qobject_cast<Git::BaseOperation*>( sender() );
Q_ASSERT( op );
Git::Result r( op->result() );
if ( !r ) {
QMessageBox::warning( 0, tr("Operation failed."),
tr("Operation failed. Message:\n %1").arg(r.errorText())
);
}
// delete the operation
op->deleteLater();
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( Remotes, RemotesModule )
#endif