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

Commit d53552c

Browse files
committed
Use the reimplemented ProgressDlg in CloneDlg, making it functional again.
1 parent 2997cc1 commit d53552c

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

Modules/Remotes/CloneRepositoryDlg.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ void CloneDlg::accept()
157157
}
158158

159159
mProgress = new ProgressDlg;
160+
161+
// TODO: implement a ProgressDlg::minimumDuration
160162
mProgress->show();
161163

162164
if( repoName.endsWith( QLatin1String( ".git" ) ) )
@@ -165,21 +167,47 @@ void CloneDlg::accept()
165167
if( repoName.lastIndexOf( QChar( L'/' ) ) != -1 )
166168
repoName.remove( 0, repoName.lastIndexOf( QChar( L'/' ) ) + 1 );
167169

170+
ProgressDlg::StepInfo::List steps;
171+
steps << ProgressDlg::StepInfo{ QStringLiteral("transfer"), tr("Download Git objects.") }
172+
<< ProgressDlg::StepInfo{ QStringLiteral("index"), tr("Add objects to Git index.") };
173+
174+
if (!clone->bare()) {
175+
steps << ProgressDlg::StepInfo{ QStringLiteral("checkout"),
176+
tr("Checkout the worktree.") };
177+
connect( clone, &Git::CloneOperation::doneCheckout,
178+
this, &CloneDlg::doneCheckout );
179+
}
180+
181+
mProgress->addActivity(tr("Cloning <b>%1</b> to <b>%2</b>")
182+
.arg(repoName).arg(targetDir), clone, steps);
168183

184+
connect( clone, &Git::CloneOperation::finished,
185+
this, &CloneDlg::rootCloneFinished );
186+
connect( clone, &Git::CloneOperation::transportProgress,
187+
this, &CloneDlg::onTransportProgress );
188+
connect( clone, &Git::CloneOperation::checkoutProgress,
189+
this, &CloneDlg::onCheckoutProgress );
190+
connect( clone, &Git::CloneOperation::doneDownloading,
191+
this, &CloneDlg::doneDownload );
192+
connect( clone, &Git::CloneOperation::doneIndexing,
193+
this, &CloneDlg::doneIndexing );
169194

170195
clone->execute();
171196
}
172197

173198
void CloneDlg::doneDownload()
174199
{
200+
mProgress->finished(sender(), QStringLiteral("transfer"));
175201
}
176202

177203
void CloneDlg::doneIndexing()
178204
{
205+
mProgress->finished(sender(), QStringLiteral("index"));
179206
}
180207

181208
void CloneDlg::doneCheckout()
182209
{
210+
mProgress->finished(sender(), QStringLiteral("checkout"));
183211
}
184212

185213
void CloneDlg::rootCloneFinished()
@@ -189,6 +217,7 @@ void CloneDlg::rootCloneFinished()
189217

190218
if ( operation->result() )
191219
{
220+
mProgress->finished(sender());
192221
return;
193222
}
194223

@@ -197,9 +226,56 @@ void CloneDlg::rootCloneFinished()
197226
mProgress->reject();
198227
}
199228

229+
void CloneDlg::onCheckoutProgress(const QString& fileName, quint64 totalFiles,
230+
quint64 completedFiles)
200231
{
232+
QObject* s = sender();
233+
234+
const QString stepCheckout( QStringLiteral("checkout") );
235+
mProgress->setPercentage( s, stepCheckout,
236+
(qreal)completedFiles / totalFiles );
237+
mProgress->setStatusInfo( s, stepCheckout,
238+
tr("Checked out %1 of %2 files (last file: %3).")
239+
.arg(completedFiles).arg(totalFiles).arg(fileName) );
240+
}
201241

242+
void CloneDlg::onTransportProgress(quint32 totalObjects,
243+
quint32 indexedObjects,
244+
quint32 receivedObjects,
245+
quint64 receivedBytes)
246+
{
247+
QString recv;
248+
if( receivedBytes > 1024 * 1024 * 950 ) /* 950 is so we get 0.9 gb */
249+
{
250+
recv = QString::number( receivedBytes / (1024*1024*1024.0), 'f', 2 ) + QStringLiteral(" Gb");
251+
}
252+
else if( receivedBytes > 1024 * 950 )
253+
{
254+
recv = QString::number( receivedBytes / (1024*1024.0), 'f', 2 ) + QStringLiteral(" Mb");
255+
}
256+
else if( receivedBytes > 950 )
257+
{
258+
recv = QString::number( receivedBytes / 1024.0, 'f', 2 ) + QStringLiteral(" Kb");
259+
}
260+
else
202261
{
262+
recv = QString::number( receivedBytes );
203263
}
204264

265+
QObject* s = sender();
266+
const QString stepTransfer(QStringLiteral("transfer"));
267+
mProgress->setPercentage( s, stepTransfer,
268+
(qreal)receivedObjects / totalObjects );
269+
mProgress->setStatusInfo( s, stepTransfer,
270+
tr("Received %1 of %2 objects (%3).")
271+
.arg(receivedObjects)
272+
.arg(totalObjects)
273+
.arg(recv) );
274+
275+
const QString stepIndex(QStringLiteral("index"));
276+
mProgress->setPercentage( s, stepIndex,
277+
(qreal)indexedObjects / totalObjects );
278+
mProgress->setStatusInfo( s, stepIndex, tr("Indexed %1 of %2 objects.")
279+
.arg(indexedObjects)
280+
.arg(totalObjects) );
205281
}

Modules/Remotes/CloneRepositoryDlg.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ private slots:
8989
void doneCheckout();
9090
void rootCloneFinished();
9191

92+
void onCheckoutProgress(const QString& fileName,
93+
quint64 totalFiles,
94+
quint64 completedFiles);
95+
96+
void onTransportProgress(quint32 totalObjects,
97+
quint32 indexedObjects,
98+
quint32 receivedObjects,
99+
quint64 receivedBytes);
92100

93101
private:
94102
ProgressDlg* mProgress = nullptr;

0 commit comments

Comments
 (0)