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

Commit

Permalink
Repository Module: reimplemented CloneDlg that inherits ExpandableDlg
Browse files Browse the repository at this point in the history
  • Loading branch information
antis81 committed Apr 9, 2015
1 parent c1c3175 commit 30f6fb0
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 292 deletions.
11 changes: 4 additions & 7 deletions Modules/Repository/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ SET( SRC_FILES
RepoTreeView.cpp
RepositoryContext.cpp

CreateRepositoryDlg.cpp
CloneRepositoryDlg.cpp
CloneOptionsWdgt.cpp
CreateRepositoryDlg.cpp
ProgressDlg.cpp
)

Expand All @@ -30,18 +29,16 @@ SET( HDR_FILES
RepoTreeView.hpp
RepositoryContext.hpp

CloneRepositoryDlg.hpp
CreateRepositoryDlg.h
CloneRepositoryDlg.h
CloneOptionsWdgt.hpp
ProgressDlg.hpp
)

SET( UI_FILES

CreateRepositoryDlg.ui
CloneRepositoryDlg.ui
CloneOptionsWdgt.ui
ProgressDlg.ui
CloneRepositoryDlg.ui
CreateRepositoryDlg.ui
)

SET( HID_FILES
Expand Down
33 changes: 0 additions & 33 deletions Modules/Repository/CloneOptionsWdgt.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +0,0 @@
#include "CloneOptionsWdgt.hpp"

#include <QLayout>


CloneOptionsWdgt::CloneOptionsWdgt(QWidget *parent) :
QWidget(parent)
{
setupUi(this);

// margin is controlled by the parent widget's layout
layout()->setMargin(0);
}

CloneOptionsWdgt::~CloneOptionsWdgt()
{
}

void CloneOptionsWdgt::on_txtCloneMode_currentIndexChanged(int index)
{
// Note: clone modes are fixed
mCloneMode = static_cast<CloneMode>( index );
grpSubmodules->setEnabled( mCloneMode == cmCheckout );
}

void CloneOptionsWdgt::on_chkInitSubmodules_toggled(bool checked)
{
chkSubmodulesRecursive->setEnabled( checked );
if( !checked )
{
chkSubmodulesRecursive->setChecked( false );
}
}
34 changes: 0 additions & 34 deletions Modules/Repository/CloneOptionsWdgt.hpp
Original file line number Diff line number Diff line change
@@ -1,35 +1 @@
#ifndef UICLONEOPTIONS_HPP
#define UICLONEOPTIONS_HPP

#include <QWidget>

#include "ui_CloneOptionsWdgt.h"


class CloneOptionsWdgt : public QWidget, Ui::CloneOptionsWdgt
{
Q_OBJECT

friend class CloneRepositoryDlg;

public:
enum CloneMode {
cmCheckout = 0,
cmBare,
cmMirror
};

public:
explicit CloneOptionsWdgt(QWidget *parent = 0);
~CloneOptionsWdgt();

private slots:
void on_txtCloneMode_currentIndexChanged(int index);

void on_chkInitSubmodules_toggled(bool checked);

private:
CloneMode mCloneMode;
};

#endif // UICLONEOPTIONS_HPP
136 changes: 78 additions & 58 deletions Modules/Repository/CloneRepositoryDlg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*
* MacGitver
* Copyright (C) 2012 Sascha Cunz <sascha@babbelbox.org>
* Copyright (C) 2015 The MacGitver-Developers <dev@macgitver.org>
*
* (C) Sascha Cunz <sascha@macgitver.org>
* (C) Nils Fenner <nils@macgitver.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.
Expand All @@ -14,31 +17,50 @@
*
*/

#include <QFileDialog>
#include <QMessageBox>
#include "CloneRepositoryDlg.hpp"

#include "libMacGitverCore/Config/Config.h"

#include "libGitWrap/Operations/CloneOperation.hpp"

#include "libMacGitverCore/App/MacGitver.hpp"

#include "CloneRepositoryDlg.h"
#include "CloneOptionsWdgt.hpp"
#include <QFileDialog>
#include <QMessageBox>
#include "ProgressDlg.hpp"

CloneRepositoryDlg::CloneRepositoryDlg()
: mProgress( NULL )

CloneOptionsWdgt::CloneOptionsWdgt()
{
setupUi( this );
setupUi(this);
}

connect( btnBrowseTo, SIGNAL(clicked()), SLOT(onBrowse()) );
connect( txtPath, SIGNAL(textChanged(QString)), SLOT(checkValid()) );
void CloneOptionsWdgt::on_txtCloneMode_currentIndexChanged(int index)
{
// Note: clone modes are fixed
mCloneMode = static_cast<CloneMode>( index );
grpSubmodules->setEnabled( mCloneMode == cmCheckout );
}

checkValid();
void CloneOptionsWdgt::on_chkInitSubmodules_toggled(bool checked)
{
chkSubmodulesRecursive->setEnabled( checked );
if( !checked )
{
chkSubmodulesRecursive->setChecked( false );
}
}

void CloneRepositoryDlg::onBrowse()

CloneWdgt::CloneWdgt()
{
setupUi( this );

connect(btnBrowseTo, &QAbstractButton::clicked,
this, &CloneWdgt::onBrowse);
}

void CloneWdgt::onBrowse()
{
QString fn = txtPath->text();
if( fn.isEmpty() )
Expand All @@ -59,7 +81,7 @@ void CloneRepositoryDlg::onBrowse()
fd->open( this, SLOT(onBrowseHelper(QString)) );
}

void CloneRepositoryDlg::onBrowseHelper( const QString& directory )
void CloneWdgt::onBrowseHelper( const QString& directory )
{
if( directory.isEmpty() )
{
Expand All @@ -70,12 +92,30 @@ void CloneRepositoryDlg::onBrowseHelper( const QString& directory )
txtPath->setText( directory );
}

void CloneRepositoryDlg::checkValid()

CloneDlg::CloneDlg()
: mCloneWdgt(new CloneWdgt)
, mCloneOptsWdgt(new CloneOptionsWdgt)
{
bool okay = !txtPath->text().isEmpty() &&
!txtUrl->text().isEmpty();
setDialogWidgets(mCloneWdgt, mCloneOptsWdgt);

connect(mCloneWdgt->txtPath, &QLineEdit::textChanged,
this, &CloneDlg::checkValid);

QDir wanted( QDir::toNativeSeparators( txtPath->text() ) );
checkValid();
}

void CloneDlg::checkValid()
{
if (!mCloneWdgt) {
setAcceptable(false);
return;
}

bool okay = !mCloneWdgt->txtPath->text().isEmpty() &&
!mCloneWdgt->txtUrl->text().isEmpty();

QDir wanted( QDir::toNativeSeparators( mCloneWdgt->txtPath->text() ) );
if( wanted.exists() )
{
QStringList sl = wanted.entryList( QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot );
Expand All @@ -85,16 +125,20 @@ void CloneRepositoryDlg::checkValid()
}
}

buttonBox->button( QDialogButtonBox::Ok )->setEnabled( okay );
setAcceptable( okay );
}

void CloneRepositoryDlg::accept()
void CloneDlg::accept()
{
Git::CloneOperation* clone = new Git::CloneOperation( this );
QString repoName = QUrl( txtUrl->text() ).adjusted( QUrl::NormalizePathSegments | QUrl::StripTrailingSlash ).toString();
QString targetDir = QUrl( txtPath->text() ).adjusted( QUrl::NormalizePathSegments | QUrl::StripTrailingSlash ).toString();

if ( chkAppendRepoName->isChecked() )
QString repoName = QUrl(mCloneWdgt->txtUrl->text() )
.adjusted(QUrl::NormalizePathSegments |
QUrl::StripTrailingSlash ).toString();
QString targetDir = QUrl(mCloneWdgt->txtPath->text() )
.adjusted(QUrl::NormalizePathSegments |
QUrl::StripTrailingSlash ).toString();

if ( mCloneWdgt->chkAppendRepoName->isChecked() )
{
targetDir += QString::fromUtf8("/%1")
.arg( QUrl( repoName ).fileName() );
Expand All @@ -103,13 +147,13 @@ void CloneRepositoryDlg::accept()
clone->setBackgroundMode( true );
clone->setUrl( repoName );
clone->setPath( targetDir );
clone->setRemoteAlias( txtRemoteAlias->text() );
clone->setRemoteAlias( mCloneWdgt->txtRemoteAlias->text() );

if ( mCloneOpts )
if ( mCloneOptsWdgt )
{
clone->setBare( mCloneOpts->mCloneMode == CloneOptionsWdgt::cmBare );
clone->setReference( mCloneOpts->txtBranch->text() );
clone->setDepth( mCloneOpts->txtCloneDepth->value() );
clone->setBare( mCloneOptsWdgt->mCloneMode == CloneOptionsWdgt::cmBare );
clone->setReference( mCloneOptsWdgt->txtBranch->text() );
clone->setDepth( mCloneOptsWdgt->txtCloneDepth->value() );
}

mProgress = new ProgressDlg;
Expand Down Expand Up @@ -140,7 +184,7 @@ void CloneRepositoryDlg::accept()
clone->execute();
}

void CloneRepositoryDlg::beginDownloading()
void CloneDlg::beginDownloading()
{
disconnect( sender(), SIGNAL(transportProgress(quint32,quint32,quint32,quint64)),
this, SLOT(beginDownloading()) );
Expand All @@ -151,13 +195,13 @@ void CloneRepositoryDlg::beginDownloading()
updateAction();
}

void CloneRepositoryDlg::doneDownload()
void CloneDlg::doneDownload()
{
mStates[ Download ] = Done;
updateAction();
}

void CloneRepositoryDlg::doneIndexing()
void CloneDlg::doneIndexing()
{
mStates[ Index ] = Done;

Expand All @@ -167,13 +211,13 @@ void CloneRepositoryDlg::doneIndexing()
updateAction();
}

void CloneRepositoryDlg::doneCheckout()
void CloneDlg::doneCheckout()
{
mStates[ Checkout ] = Done;
updateAction();
}

void CloneRepositoryDlg::rootCloneFinished()
void CloneDlg::rootCloneFinished()
{
Git::BaseOperation* operation = static_cast<Git::BaseOperation*>( sender() );
Q_ASSERT( operation );
Expand All @@ -189,7 +233,7 @@ void CloneRepositoryDlg::rootCloneFinished()
mProgress->reject();
}

void CloneRepositoryDlg::updateAction()
void CloneDlg::updateAction()
{
QStringList open, current, done;

Expand All @@ -213,27 +257,3 @@ void CloneRepositoryDlg::updateAction()

mProgress->setAction( mAction, open, current, done );
}

void CloneRepositoryDlg::on_btnCloneopts_toggled(bool checked)
{
if ( checked )
{
if ( !mCloneOpts )
{
mCloneOpts = new CloneOptionsWdgt();
}

optsLayout->addWidget( mCloneOpts );
mCloneOpts->show();
}
else
{
optsLayout->removeWidget( mCloneOpts );
if ( mCloneOpts )
{
mCloneOpts->hide();
}
layout()->activate();
resize( width(), minimumSizeHint().height() );
}
}
Loading

0 comments on commit 30f6fb0

Please sign in to comment.