1
/* This file is part of the KDE libraries
2
Copyright (C) 2000 Matej Koss <koss@miesto.sk>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16
Boston, MA 02111-1307, USA.
22
#include <qdatetime.h>
24
#include <kapplication.h>
26
#include <kstringhandler.h>
29
#include <kiconloader.h>
30
#include <kpushbutton.h>
31
#include <kstdguiitem.h>
34
#include <kio/jobclasses.h>
36
#include "krprogress.h"
37
#include "../krusader.h"
39
KrProgress::KrProgress( KIO::Job* job )
40
: ProgressBase( krApp ),
41
m_iTotalSize(0), m_iTotalFiles(0), m_iTotalDirs(0),
42
m_iProcessedSize(0), m_iProcessedDirs(0), m_iProcessedFiles(0){
44
#ifdef Q_WS_X11 //FIXME(E): Remove once all the KWin::foo calls have been ported to QWS
45
// Set a useful icon for this window!
46
KWin::setIcons( winId(),
47
KGlobal::iconLoader()->loadIcon( "filesave", KIcon::NoGroup, 32 ),
48
KGlobal::iconLoader()->loadIcon( "filesave", KIcon::NoGroup, 16 ) );
51
QVBoxLayout *topLayout = new QVBoxLayout( this, KDialog::marginHint(),
52
KDialog::spacingHint() );
53
topLayout->addStrut( 360 ); // makes dlg at least that wide
55
QGridLayout *grid = new QGridLayout( 2, 3 );
56
topLayout->addLayout(grid);
57
grid->addColSpacing(1, KDialog::spacingHint());
58
// filenames or action name
59
grid->addWidget(new QLabel(i18n("Source:"), this), 0, 0);
61
sourceLabel = new KSqueezedTextLabel(this);
62
grid->addWidget(sourceLabel, 0, 2);
64
destInvite = new QLabel(i18n("Destination:"), this);
65
grid->addWidget(destInvite, 1, 0);
67
destLabel = new KSqueezedTextLabel(this);
68
grid->addWidget(destLabel, 1, 2);
70
m_pProgressBar = new KProgress(this);
71
topLayout->addWidget( m_pProgressBar );
74
QHBoxLayout *hBox = new QHBoxLayout();
75
topLayout->addLayout(hBox);
77
sizeLabel = new QLabel(this);
78
hBox->addWidget(sizeLabel);
80
resumeLabel = new QLabel(this);
81
hBox->addWidget(resumeLabel);
83
progressLabel = new QLabel( this );
84
/* progressLabel->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding,
85
QSizePolicy::Preferred ) );*/
86
progressLabel->setAlignment( QLabel::AlignRight );
87
hBox->addWidget( progressLabel );
89
hBox = new QHBoxLayout();
90
topLayout->addLayout(hBox);
92
speedLabel = new QLabel(this);
93
hBox->addWidget(speedLabel, 1);
95
QFrame *line = new QFrame( this );
96
line->setFrameShape( QFrame::HLine );
97
line->setFrameShadow( QFrame::Sunken );
98
topLayout->addWidget( line );
100
hBox = new QHBoxLayout();
101
topLayout->addLayout(hBox);
105
KPushButton *pb = new KPushButton( KStdGuiItem::cancel(), this );
106
connect( pb, SIGNAL( clicked() ), SLOT( slotStop() ) );
107
hBox->addWidget( pb );
109
resize( sizeHint() );
110
setMaximumHeight(sizeHint().height());
112
setCaption(i18n("Krusader Progress")); // show something better than kio_uiserver
116
setStopOnClose(true);
117
// Connect global progress info signals
118
connect( job, SIGNAL( percent( KIO::Job*, unsigned long ) ),
119
SLOT( slotPercent( KIO::Job*, unsigned long ) ) );
120
connect( job, SIGNAL( infoMessage( KIO::Job*, const QString & ) ),
121
SLOT( slotInfoMessage( KIO::Job*, const QString & ) ) );
122
connect( job, SIGNAL( totalSize( KIO::Job*, KIO::filesize_t ) ),
123
SLOT( slotTotalSize( KIO::Job*, KIO::filesize_t ) ) );
124
connect( job, SIGNAL( processedSize( KIO::Job*, KIO::filesize_t ) ),
125
SLOT( slotProcessedSize( KIO::Job*, KIO::filesize_t ) ) );
126
connect( job, SIGNAL( speed( KIO::Job*, unsigned long ) ),
127
SLOT( slotSpeed( KIO::Job*, unsigned long ) ) );
129
// change to modal & move to Krusader's center
130
QPoint center((krApp->width()-width())/2,(krApp->height()-height())/2);
131
center = center+(krApp->pos());
132
reparent(krApp,WType_Modal,center);
133
//setWFlags(WType_Modal);
134
//move((krApp->width()-width())/2,(krApp->height()-height())/2);
138
KrProgress::~KrProgress(){}
140
void KrProgress::slotTotalSize( KIO::Job*, KIO::filesize_t bytes ){
141
m_iTotalSize = bytes;
145
void KrProgress::slotTotalFiles( KIO::Job*, unsigned long files ){
146
m_iTotalFiles = files;
151
void KrProgress::slotTotalDirs( KIO::Job*, unsigned long dirs ){
156
void KrProgress::showTotals(){
157
// Show the totals in the progress label, if we still haven't
158
// processed anything. This is useful when the stat'ing phase
159
// of CopyJob takes a long time (e.g. over networks).
160
if ( m_iProcessedFiles == 0 && m_iProcessedDirs == 0 )
163
if ( m_iTotalDirs > 1 )
164
// that we have a singular to translate looks weired but is only logical
165
tmps = i18n("%n directory", "%n directories", m_iTotalDirs) + " ";
166
tmps += i18n("%n file", "%n files", m_iTotalFiles);
167
progressLabel->setText( tmps );
171
void KrProgress::slotPercent( KIO::Job*, unsigned long percent ){
172
QString tmp(i18n( "%1% of %2 ").arg( percent ).arg( KIO::convertSize(m_iTotalSize)));
173
m_pProgressBar->setValue( percent );
174
tmp.append(i18n(" (Reading)"));
180
void KrProgress::slotInfoMessage( KIO::Job*, const QString & msg )
182
speedLabel->setText( msg );
183
speedLabel->setAlignment( speedLabel->alignment() & ~Qt::WordBreak );
187
void KrProgress::slotProcessedSize( KIO::Job*, KIO::filesize_t bytes ) {
188
m_iProcessedSize = bytes;
191
tmp = i18n( "%1 of %2 complete").arg( KIO::convertSize(bytes) ).arg( KIO::convertSize(m_iTotalSize));
192
sizeLabel->setText( tmp );
196
void KrProgress::slotProcessedDirs( KIO::Job*, unsigned long dirs )
198
m_iProcessedDirs = dirs;
201
tmps = i18n("%1 / %n directory", "%1 / %n directories", m_iTotalDirs).arg( m_iProcessedDirs );
203
tmps += i18n("%1 / %n file", "%1 / %n files", m_iTotalFiles).arg( m_iProcessedFiles );
204
progressLabel->setText( tmps );
208
void KrProgress::slotProcessedFiles( KIO::Job*, unsigned long files )
210
m_iProcessedFiles = files;
213
if ( m_iTotalDirs > 1 ) {
214
tmps = i18n("%1 / %n directory", "%1 / %n directories", m_iTotalDirs).arg( m_iProcessedDirs );
217
tmps += i18n("%1 / %n file", "%1 / %n files", m_iTotalFiles).arg( m_iProcessedFiles );
218
progressLabel->setText( tmps );
222
void KrProgress::slotSpeed( KIO::Job*, unsigned long bytes_per_second )
224
if ( bytes_per_second == 0 ) {
225
speedLabel->setText( i18n( "Working") );
227
QTime remaining = KIO::calculateRemaining( m_iTotalSize, m_iProcessedSize, bytes_per_second );
228
speedLabel->setText( i18n( "%1/s ( %2 remaining )").arg( KIO::convertSize( bytes_per_second )).arg( remaining.toString() ) );
233
void KrProgress::setDestVisible( bool visible )
235
// We can't hide the destInvite/destLabel labels,
236
// because it screws up the QGridLayout.
239
destInvite->setText( i18n("Destination:") );
243
destInvite->setText( QString::null );
244
destLabel->setText( QString::null );
248
void KrProgress::virtual_hook( int id, void* data ){
249
ProgressBase::virtual_hook( id, data );
252
void KrProgress::slotStop(){
254
m_pJob->kill(false); // this will call slotFinished
257
slotFinished( 0 ); // here we call it ourselves
263
void KrProgress::closeEvent( QCloseEvent* ) { hide(); slotStop(); }
265
#include "krprogress.moc"