11/*
22 * MacGitver
3- * Copyright (C) 2012 Sascha Cunz <sascha@babbelbox.org>
3+ * Copyright (C) 2015 The MacGitver-Developers <dev@macgitver.org>
4+ *
5+ * (C) Sascha Cunz <sascha@macgitver.org>
6+ * (C) Nils Fenner <nils@macgitver.org>
47 *
58 * This program is free software; you can redistribute it and/or modify it under the terms of the
69 * GNU General Public License (Version 2) as published by the Free Software Foundation.
1417 *
1518 */
1619
17- #include < QFileDialog>
18- #include < QMessageBox>
20+ #include " CloneRepositoryDlg.hpp"
1921
2022#include " libMacGitverCore/Config/Config.h"
2123
2224#include " libGitWrap/Operations/CloneOperation.hpp"
2325
2426#include " libMacGitverCore/App/MacGitver.hpp"
2527
26- #include " CloneRepositoryDlg.h "
27- #include " CloneOptionsWdgt.hpp "
28+ #include < QFileDialog >
29+ #include < QMessageBox >
2830#include " ProgressDlg.hpp"
2931
30- CloneRepositoryDlg::CloneRepositoryDlg ()
31- : mProgress( NULL )
32+
33+ CloneOptionsWdgt::CloneOptionsWdgt ( )
3234{
33- setupUi ( this );
35+ setupUi (this );
36+ }
3437
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+ }
3744
38- checkValid ();
45+ void CloneOptionsWdgt::on_chkInitSubmodules_toggled (bool checked)
46+ {
47+ chkSubmodulesRecursive->setEnabled ( checked );
48+ if ( !checked )
49+ {
50+ chkSubmodulesRecursive->setChecked ( false );
51+ }
3952}
4053
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 ()
4264{
4365 QString fn = txtPath->text ();
4466 if ( fn.isEmpty () )
@@ -59,7 +81,7 @@ void CloneRepositoryDlg::onBrowse()
5981 fd->open ( this , SLOT (onBrowseHelper (QString)) );
6082}
6183
62- void CloneRepositoryDlg ::onBrowseHelper ( const QString& directory )
84+ void CloneWdgt ::onBrowseHelper ( const QString& directory )
6385{
6486 if ( directory.isEmpty () )
6587 {
@@ -70,12 +92,30 @@ void CloneRepositoryDlg::onBrowseHelper( const QString& directory )
7092 txtPath->setText ( directory );
7193}
7294
73- void CloneRepositoryDlg::checkValid ()
95+
96+ CloneDlg::CloneDlg ()
97+ : mCloneWdgt(new CloneWdgt)
98+ , mCloneOptsWdgt(new CloneOptionsWdgt)
7499{
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);
77104
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 () ) );
79119 if ( wanted.exists () )
80120 {
81121 QStringList sl = wanted.entryList ( QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot );
@@ -85,16 +125,20 @@ void CloneRepositoryDlg::checkValid()
85125 }
86126 }
87127
88- buttonBox-> button ( QDialogButtonBox::Ok )-> setEnabled ( okay );
128+ setAcceptable ( okay );
89129}
90130
91- void CloneRepositoryDlg ::accept ()
131+ void CloneDlg ::accept ()
92132{
93133 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 () )
98142 {
99143 targetDir += QString::fromUtf8 (" /%1" )
100144 .arg ( QUrl ( repoName ).fileName () );
@@ -103,13 +147,13 @@ void CloneRepositoryDlg::accept()
103147 clone->setBackgroundMode ( true );
104148 clone->setUrl ( repoName );
105149 clone->setPath ( targetDir );
106- clone->setRemoteAlias ( txtRemoteAlias->text () );
150+ clone->setRemoteAlias ( mCloneWdgt -> txtRemoteAlias ->text () );
107151
108- if ( mCloneOpts )
152+ if ( mCloneOptsWdgt )
109153 {
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 () );
113157 }
114158
115159 mProgress = new ProgressDlg;
@@ -140,7 +184,7 @@ void CloneRepositoryDlg::accept()
140184 clone->execute ();
141185}
142186
143- void CloneRepositoryDlg ::beginDownloading ()
187+ void CloneDlg ::beginDownloading ()
144188{
145189 disconnect ( sender (), SIGNAL (transportProgress (quint32,quint32,quint32,quint64)),
146190 this , SLOT (beginDownloading ()) );
@@ -151,13 +195,13 @@ void CloneRepositoryDlg::beginDownloading()
151195 updateAction ();
152196}
153197
154- void CloneRepositoryDlg ::doneDownload ()
198+ void CloneDlg ::doneDownload ()
155199{
156200 mStates [ Download ] = Done;
157201 updateAction ();
158202}
159203
160- void CloneRepositoryDlg ::doneIndexing ()
204+ void CloneDlg ::doneIndexing ()
161205{
162206 mStates [ Index ] = Done;
163207
@@ -167,13 +211,13 @@ void CloneRepositoryDlg::doneIndexing()
167211 updateAction ();
168212}
169213
170- void CloneRepositoryDlg ::doneCheckout ()
214+ void CloneDlg ::doneCheckout ()
171215{
172216 mStates [ Checkout ] = Done;
173217 updateAction ();
174218}
175219
176- void CloneRepositoryDlg ::rootCloneFinished ()
220+ void CloneDlg ::rootCloneFinished ()
177221{
178222 Git::BaseOperation* operation = static_cast <Git::BaseOperation*>( sender () );
179223 Q_ASSERT ( operation );
@@ -189,7 +233,7 @@ void CloneRepositoryDlg::rootCloneFinished()
189233 mProgress ->reject ();
190234}
191235
192- void CloneRepositoryDlg ::updateAction ()
236+ void CloneDlg ::updateAction ()
193237{
194238 QStringList open, current, done;
195239
@@ -213,27 +257,3 @@ void CloneRepositoryDlg::updateAction()
213257
214258 mProgress ->setAction ( mAction , open, current, done );
215259}
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