Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 30f6fb0

Browse files
committed
Repository Module: reimplemented CloneDlg that inherits ExpandableDlg
1 parent c1c3175 commit 30f6fb0

7 files changed

+186
-292
lines changed

Modules/Repository/CMakeLists.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ SET( SRC_FILES
1616
RepoTreeView.cpp
1717
RepositoryContext.cpp
1818

19-
CreateRepositoryDlg.cpp
2019
CloneRepositoryDlg.cpp
21-
CloneOptionsWdgt.cpp
20+
CreateRepositoryDlg.cpp
2221
ProgressDlg.cpp
2322
)
2423

@@ -30,18 +29,16 @@ SET( HDR_FILES
3029
RepoTreeView.hpp
3130
RepositoryContext.hpp
3231

32+
CloneRepositoryDlg.hpp
3333
CreateRepositoryDlg.h
34-
CloneRepositoryDlg.h
35-
CloneOptionsWdgt.hpp
3634
ProgressDlg.hpp
3735
)
3836

3937
SET( UI_FILES
4038

41-
CreateRepositoryDlg.ui
42-
CloneRepositoryDlg.ui
4339
CloneOptionsWdgt.ui
44-
ProgressDlg.ui
40+
CloneRepositoryDlg.ui
41+
CreateRepositoryDlg.ui
4542
)
4643

4744
SET( HID_FILES
Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +0,0 @@
1-
#include "CloneOptionsWdgt.hpp"
2-
3-
#include <QLayout>
4-
5-
6-
CloneOptionsWdgt::CloneOptionsWdgt(QWidget *parent) :
7-
QWidget(parent)
8-
{
9-
setupUi(this);
10-
11-
// margin is controlled by the parent widget's layout
12-
layout()->setMargin(0);
13-
}
14-
15-
CloneOptionsWdgt::~CloneOptionsWdgt()
16-
{
17-
}
18-
19-
void CloneOptionsWdgt::on_txtCloneMode_currentIndexChanged(int index)
20-
{
21-
// Note: clone modes are fixed
22-
mCloneMode = static_cast<CloneMode>( index );
23-
grpSubmodules->setEnabled( mCloneMode == cmCheckout );
24-
}
25-
26-
void CloneOptionsWdgt::on_chkInitSubmodules_toggled(bool checked)
27-
{
28-
chkSubmodulesRecursive->setEnabled( checked );
29-
if( !checked )
30-
{
31-
chkSubmodulesRecursive->setChecked( false );
32-
}
33-
}
Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1 @@
1-
#ifndef UICLONEOPTIONS_HPP
2-
#define UICLONEOPTIONS_HPP
31

4-
#include <QWidget>
5-
6-
#include "ui_CloneOptionsWdgt.h"
7-
8-
9-
class CloneOptionsWdgt : public QWidget, Ui::CloneOptionsWdgt
10-
{
11-
Q_OBJECT
12-
13-
friend class CloneRepositoryDlg;
14-
15-
public:
16-
enum CloneMode {
17-
cmCheckout = 0,
18-
cmBare,
19-
cmMirror
20-
};
21-
22-
public:
23-
explicit CloneOptionsWdgt(QWidget *parent = 0);
24-
~CloneOptionsWdgt();
25-
26-
private slots:
27-
void on_txtCloneMode_currentIndexChanged(int index);
28-
29-
void on_chkInitSubmodules_toggled(bool checked);
30-
31-
private:
32-
CloneMode mCloneMode;
33-
};
34-
35-
#endif // UICLONEOPTIONS_HPP

Modules/Repository/CloneRepositoryDlg.cpp

Lines changed: 78 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* 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]>
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.
@@ -14,31 +17,50 @@
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

Comments
 (0)