1
1
/*
2
2
* MacGitver
3
- * Copyright (C) 2012 Sascha Cunz <[email protected] >
3
+ * Copyright (C) 2015 The MacGitver-Developers <[email protected] >
4
+ *
5
+ * (C) Sascha Cunz <[email protected] >
6
+ * (C) Nils Fenner <[email protected] >
4
7
*
5
8
* This program is free software; you can redistribute it and/or modify it under the terms of the
6
9
* GNU General Public License (Version 2) as published by the Free Software Foundation.
14
17
*
15
18
*/
16
19
17
- #include < QFileDialog>
18
- #include < QMessageBox>
20
+ #include " CloneRepositoryDlg.hpp"
19
21
20
22
#include " libMacGitverCore/Config/Config.h"
21
23
22
24
#include " libGitWrap/Operations/CloneOperation.hpp"
23
25
24
26
#include " libMacGitverCore/App/MacGitver.hpp"
25
27
26
- #include " CloneRepositoryDlg.h "
27
- #include " CloneOptionsWdgt.hpp "
28
+ #include < QFileDialog >
29
+ #include < QMessageBox >
28
30
#include " ProgressDlg.hpp"
29
31
30
- CloneRepositoryDlg::CloneRepositoryDlg ()
31
- : mProgress( NULL )
32
+
33
+ CloneOptionsWdgt::CloneOptionsWdgt ( )
32
34
{
33
- setupUi ( this );
35
+ setupUi (this );
36
+ }
34
37
35
- connect ( btnBrowseTo, SIGNAL (clicked ()), SLOT (onBrowse ()) );
36
- connect ( txtPath, SIGNAL (textChanged (QString)), SLOT (checkValid ()) );
38
+ void CloneOptionsWdgt::on_txtCloneMode_currentIndexChanged (int index)
39
+ {
40
+ // Note: clone modes are fixed
41
+ mCloneMode = static_cast <CloneMode>( index );
42
+ grpSubmodules->setEnabled ( mCloneMode == cmCheckout );
43
+ }
37
44
38
- checkValid ();
45
+ void CloneOptionsWdgt::on_chkInitSubmodules_toggled (bool checked)
46
+ {
47
+ chkSubmodulesRecursive->setEnabled ( checked );
48
+ if ( !checked )
49
+ {
50
+ chkSubmodulesRecursive->setChecked ( false );
51
+ }
39
52
}
40
53
41
- void CloneRepositoryDlg::onBrowse ()
54
+
55
+ CloneWdgt::CloneWdgt ()
56
+ {
57
+ setupUi ( this );
58
+
59
+ connect (btnBrowseTo, &QAbstractButton::clicked,
60
+ this , &CloneWdgt::onBrowse);
61
+ }
62
+
63
+ void CloneWdgt::onBrowse ()
42
64
{
43
65
QString fn = txtPath->text ();
44
66
if ( fn.isEmpty () )
@@ -59,7 +81,7 @@ void CloneRepositoryDlg::onBrowse()
59
81
fd->open ( this , SLOT (onBrowseHelper (QString)) );
60
82
}
61
83
62
- void CloneRepositoryDlg ::onBrowseHelper ( const QString& directory )
84
+ void CloneWdgt ::onBrowseHelper ( const QString& directory )
63
85
{
64
86
if ( directory.isEmpty () )
65
87
{
@@ -70,12 +92,30 @@ void CloneRepositoryDlg::onBrowseHelper( const QString& directory )
70
92
txtPath->setText ( directory );
71
93
}
72
94
73
- void CloneRepositoryDlg::checkValid ()
95
+
96
+ CloneDlg::CloneDlg ()
97
+ : mCloneWdgt(new CloneWdgt)
98
+ , mCloneOptsWdgt(new CloneOptionsWdgt)
74
99
{
75
- bool okay = !txtPath->text ().isEmpty () &&
76
- !txtUrl->text ().isEmpty ();
100
+ setDialogWidgets (mCloneWdgt , mCloneOptsWdgt );
101
+
102
+ connect (mCloneWdgt ->txtPath , &QLineEdit::textChanged,
103
+ this , &CloneDlg::checkValid);
77
104
78
- QDir wanted ( QDir::toNativeSeparators ( txtPath->text () ) );
105
+ checkValid ();
106
+ }
107
+
108
+ void CloneDlg::checkValid ()
109
+ {
110
+ if (!mCloneWdgt ) {
111
+ setAcceptable (false );
112
+ return ;
113
+ }
114
+
115
+ bool okay = !mCloneWdgt ->txtPath ->text ().isEmpty () &&
116
+ !mCloneWdgt ->txtUrl ->text ().isEmpty ();
117
+
118
+ QDir wanted ( QDir::toNativeSeparators ( mCloneWdgt ->txtPath ->text () ) );
79
119
if ( wanted.exists () )
80
120
{
81
121
QStringList sl = wanted.entryList ( QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot );
@@ -85,16 +125,20 @@ void CloneRepositoryDlg::checkValid()
85
125
}
86
126
}
87
127
88
- buttonBox-> button ( QDialogButtonBox::Ok )-> setEnabled ( okay );
128
+ setAcceptable ( okay );
89
129
}
90
130
91
- void CloneRepositoryDlg ::accept ()
131
+ void CloneDlg ::accept ()
92
132
{
93
133
Git::CloneOperation* clone = new Git::CloneOperation ( this );
94
- QString repoName = QUrl ( txtUrl->text () ).adjusted ( QUrl::NormalizePathSegments | QUrl::StripTrailingSlash ).toString ();
95
- QString targetDir = QUrl ( txtPath->text () ).adjusted ( QUrl::NormalizePathSegments | QUrl::StripTrailingSlash ).toString ();
96
-
97
- if ( chkAppendRepoName->isChecked () )
134
+ QString repoName = QUrl (mCloneWdgt ->txtUrl ->text () )
135
+ .adjusted (QUrl::NormalizePathSegments |
136
+ QUrl::StripTrailingSlash ).toString ();
137
+ QString targetDir = QUrl (mCloneWdgt ->txtPath ->text () )
138
+ .adjusted (QUrl::NormalizePathSegments |
139
+ QUrl::StripTrailingSlash ).toString ();
140
+
141
+ if ( mCloneWdgt ->chkAppendRepoName ->isChecked () )
98
142
{
99
143
targetDir += QString::fromUtf8 (" /%1" )
100
144
.arg ( QUrl ( repoName ).fileName () );
@@ -103,13 +147,13 @@ void CloneRepositoryDlg::accept()
103
147
clone->setBackgroundMode ( true );
104
148
clone->setUrl ( repoName );
105
149
clone->setPath ( targetDir );
106
- clone->setRemoteAlias ( txtRemoteAlias->text () );
150
+ clone->setRemoteAlias ( mCloneWdgt -> txtRemoteAlias ->text () );
107
151
108
- if ( mCloneOpts )
152
+ if ( mCloneOptsWdgt )
109
153
{
110
- clone->setBare ( mCloneOpts ->mCloneMode == CloneOptionsWdgt::cmBare );
111
- clone->setReference ( mCloneOpts ->txtBranch ->text () );
112
- clone->setDepth ( mCloneOpts ->txtCloneDepth ->value () );
154
+ clone->setBare ( mCloneOptsWdgt ->mCloneMode == CloneOptionsWdgt::cmBare );
155
+ clone->setReference ( mCloneOptsWdgt ->txtBranch ->text () );
156
+ clone->setDepth ( mCloneOptsWdgt ->txtCloneDepth ->value () );
113
157
}
114
158
115
159
mProgress = new ProgressDlg;
@@ -140,7 +184,7 @@ void CloneRepositoryDlg::accept()
140
184
clone->execute ();
141
185
}
142
186
143
- void CloneRepositoryDlg ::beginDownloading ()
187
+ void CloneDlg ::beginDownloading ()
144
188
{
145
189
disconnect ( sender (), SIGNAL (transportProgress (quint32,quint32,quint32,quint64)),
146
190
this , SLOT (beginDownloading ()) );
@@ -151,13 +195,13 @@ void CloneRepositoryDlg::beginDownloading()
151
195
updateAction ();
152
196
}
153
197
154
- void CloneRepositoryDlg ::doneDownload ()
198
+ void CloneDlg ::doneDownload ()
155
199
{
156
200
mStates [ Download ] = Done;
157
201
updateAction ();
158
202
}
159
203
160
- void CloneRepositoryDlg ::doneIndexing ()
204
+ void CloneDlg ::doneIndexing ()
161
205
{
162
206
mStates [ Index ] = Done;
163
207
@@ -167,13 +211,13 @@ void CloneRepositoryDlg::doneIndexing()
167
211
updateAction ();
168
212
}
169
213
170
- void CloneRepositoryDlg ::doneCheckout ()
214
+ void CloneDlg ::doneCheckout ()
171
215
{
172
216
mStates [ Checkout ] = Done;
173
217
updateAction ();
174
218
}
175
219
176
- void CloneRepositoryDlg ::rootCloneFinished ()
220
+ void CloneDlg ::rootCloneFinished ()
177
221
{
178
222
Git::BaseOperation* operation = static_cast <Git::BaseOperation*>( sender () );
179
223
Q_ASSERT ( operation );
@@ -189,7 +233,7 @@ void CloneRepositoryDlg::rootCloneFinished()
189
233
mProgress ->reject ();
190
234
}
191
235
192
- void CloneRepositoryDlg ::updateAction ()
236
+ void CloneDlg ::updateAction ()
193
237
{
194
238
QStringList open , current, done;
195
239
@@ -213,27 +257,3 @@ void CloneRepositoryDlg::updateAction()
213
257
214
258
mProgress ->setAction ( mAction , open , current, done );
215
259
}
216
-
217
- void CloneRepositoryDlg::on_btnCloneopts_toggled (bool checked)
218
- {
219
- if ( checked )
220
- {
221
- if ( !mCloneOpts )
222
- {
223
- mCloneOpts = new CloneOptionsWdgt ();
224
- }
225
-
226
- optsLayout->addWidget ( mCloneOpts );
227
- mCloneOpts ->show ();
228
- }
229
- else
230
- {
231
- optsLayout->removeWidget ( mCloneOpts );
232
- if ( mCloneOpts )
233
- {
234
- mCloneOpts ->hide ();
235
- }
236
- layout ()->activate ();
237
- resize ( width (), minimumSizeHint ().height () );
238
- }
239
- }
0 commit comments