This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgressDlg.cpp
More file actions
157 lines (129 loc) · 4.1 KB
/
ProgressDlg.cpp
File metadata and controls
157 lines (129 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <QStringBuilder>
#include <QCloseEvent>
#include <QDebug>
#include <QPushButton>
#include <QString>
#include "ProgressDlg.hpp"
ProgressDlg::ProgressDlg()
: BlueSky::Dialog()
, mDone( false )
{
setupUi( this );
QPushButton* close = buttonBox->button( QDialogButtonBox::Close );
close->setEnabled( false );
connect( close, SIGNAL(clicked()), this, SLOT(close ()) );
QPalette p;
p.setColor( QPalette::Base, p.color( QPalette::Window ) );
p.setColor( QPalette::Text, p.color( QPalette::WindowText ) );
txtLog->setPalette( p );
}
void ProgressDlg::setAction( const QString& action,
const QStringList& open,
const QStringList& current,
const QStringList& done )
{
QString act = action;
foreach( QString s, done )
{
act += QStringLiteral( " (<font color=\"green\">" ) % s % QStringLiteral( "</font>)" );
}
foreach( QString s, current )
{
act += QStringLiteral( " (<font color=\"blue\">" ) % s % QStringLiteral( "</font>)" );
}
foreach( QString s, open )
{
act += QStringLiteral( " (<font color=\"red\">" ) % s % QStringLiteral( "</font>)" );
}
lblAction->setText( act );
}
void ProgressDlg::setCurrent(QObject* current)
{
mCurrent = current;
connect( mCurrent, SIGNAL(remoteMessage(QString)),
this, SLOT(remoteMessage(QString)) );
connect( mCurrent, SIGNAL(transportProgress(quint32, quint32, quint32, quint64)),
this, SLOT(transportProgress(quint32, quint32, quint32, quint64)) );
}
void ProgressDlg::closeEvent( QCloseEvent* ev )
{
if( !mDone )
{
ev->ignore();
return;
}
QDialog::closeEvent( ev );
}
void ProgressDlg::transportProgress( quint32 totalObjects,
quint32 indexedObjects,
quint32 receivedObjects,
quint64 receivedBytes )
{
QString recv;
if( receivedBytes > 1024 * 1024 * 950 ) /* 950 is so we get 0.9 gb */
{
recv = QString::number( receivedBytes / (1024*1024*1024.0), 'f', 2 ) % QStringLiteral( " Gb" );
}
else if( receivedBytes > 1024 * 950 )
{
recv = QString::number( receivedBytes / (1024*1024.0), 'f', 2 ) % QStringLiteral( " Mb" );
}
else if( receivedBytes > 950 )
{
recv = QString::number( receivedBytes / 1024.0, 'f', 2 ) % QStringLiteral( " Kb" );
}
else
{
recv = QString::number( receivedBytes );
}
lblTransferSize->setText( recv );
progressBar->setRange( 0, totalObjects * 2 );
progressBar->setValue( indexedObjects + receivedObjects );
}
void ProgressDlg::remoteMessage( const QString& msg )
{
mRawRemoteMessage += msg;
QString output;
QChar outputBuffer[ 256 ];
int outBufPos = 0, outBufLen = 0;
for( int i = 0; i < mRawRemoteMessage.length(); ++i )
{
if( mRawRemoteMessage[ i ] == QChar( L'\r' ) )
{
outBufPos = 0;
}
else if( mRawRemoteMessage[ i ] == QChar( L'\n' ) )
{
if( outBufLen )
output += QString( outputBuffer, outBufLen );
output += QChar( L'\n' );
outBufPos = outBufLen = 0;
}
else
{
outputBuffer[ outBufPos++] = mRawRemoteMessage[ i ];
outBufLen = qMax( outBufLen, outBufPos );
}
}
if( outBufLen )
output += QString( outputBuffer, outBufLen );
QString log = mBaseLog % QStringLiteral( "<br/>" ) %
output.replace( QChar( L'\n' ), QLatin1String("<br/>") ).simplified();
txtLog->setHtml( log );
}
void ProgressDlg::beginStep( const QString& step )
{
mBaseLog += tr( "<font color=\"blue\">%1</font><br/>" ).arg( step );
txtLog->setHtml( mBaseLog );
}
void ProgressDlg::finalizeStep()
{
mBaseLog = txtLog->toHtml() % QStringLiteral( "<br/>" );
mRawRemoteMessage = QString();
txtLog->setHtml( mBaseLog );
}
void ProgressDlg::setDone()
{
mDone = true;
buttonBox->button( QDialogButtonBox::Close )->setEnabled( true );
}