~ubuntu-branches/ubuntu/hardy/krusader/hardy

« back to all changes in this revision

Viewing changes to krusader/Dialogs/krprogress.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Angel Ramos
  • Date: 2004-12-30 16:18:26 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041230161826-wx99gkdypyalazpv
Tags: 1.51-1
* New upstream release (Closes: #280037, #287015).
* Moved from section utils to kde (Closes: #286748).
* Renamed dk.po to da.po (Closes: #269414).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE libraries
 
2
   Copyright (C) 2000 Matej Koss <koss@miesto.sk>
 
3
 
 
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.
 
7
 
 
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.
 
12
 
 
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.
 
17
*/
 
18
 
 
19
#include <qtimer.h>
 
20
#include <qlayout.h>
 
21
#include <qtooltip.h>
 
22
#include <qdatetime.h>
 
23
 
 
24
#include <kapplication.h>
 
25
#include <kdialog.h>
 
26
#include <kstringhandler.h>
 
27
#include <kglobal.h>
 
28
#include <klocale.h>
 
29
#include <kiconloader.h>
 
30
#include <kpushbutton.h>
 
31
#include <kstdguiitem.h>
 
32
#include <kwin.h>
 
33
 
 
34
#include <kio/jobclasses.h>
 
35
 
 
36
#include "krprogress.h"
 
37
#include "../krusader.h"
 
38
 
 
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){
 
43
 
 
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 ) );
 
49
#endif
 
50
 
 
51
  QVBoxLayout *topLayout = new QVBoxLayout( this, KDialog::marginHint(),
 
52
                                            KDialog::spacingHint() );
 
53
  topLayout->addStrut( 360 );   // makes dlg at least that wide
 
54
 
 
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);
 
60
 
 
61
  sourceLabel = new KSqueezedTextLabel(this);
 
62
  grid->addWidget(sourceLabel, 0, 2);
 
63
 
 
64
  destInvite = new QLabel(i18n("Destination:"), this);
 
65
  grid->addWidget(destInvite, 1, 0);
 
66
 
 
67
  destLabel = new KSqueezedTextLabel(this);
 
68
  grid->addWidget(destLabel, 1, 2);
 
69
 
 
70
  m_pProgressBar = new KProgress(this);
 
71
  topLayout->addWidget( m_pProgressBar );
 
72
 
 
73
  // processed info
 
74
  QHBoxLayout *hBox = new QHBoxLayout();
 
75
  topLayout->addLayout(hBox);
 
76
 
 
77
  sizeLabel = new QLabel(this);
 
78
  hBox->addWidget(sizeLabel);
 
79
 
 
80
  resumeLabel = new QLabel(this);
 
81
  hBox->addWidget(resumeLabel);
 
82
 
 
83
  progressLabel = new QLabel( this );
 
84
/*  progressLabel->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding,
 
85
                                             QSizePolicy::Preferred ) );*/
 
86
  progressLabel->setAlignment( QLabel::AlignRight );
 
87
  hBox->addWidget( progressLabel );
 
88
 
 
89
  hBox = new QHBoxLayout();
 
90
  topLayout->addLayout(hBox);
 
91
 
 
92
  speedLabel = new QLabel(this);
 
93
  hBox->addWidget(speedLabel, 1);
 
94
 
 
95
  QFrame *line = new QFrame( this );
 
96
  line->setFrameShape( QFrame::HLine );
 
97
  line->setFrameShadow( QFrame::Sunken );
 
98
  topLayout->addWidget( line );
 
99
 
 
100
  hBox = new QHBoxLayout();
 
101
  topLayout->addLayout(hBox);
 
102
 
 
103
  hBox->addStretch(1);
 
104
 
 
105
  KPushButton *pb = new KPushButton( KStdGuiItem::cancel(), this );
 
106
  connect( pb, SIGNAL( clicked() ), SLOT( slotStop() ) );
 
107
  hBox->addWidget( pb );
 
108
 
 
109
  resize( sizeHint() );
 
110
  setMaximumHeight(sizeHint().height());
 
111
 
 
112
  setCaption(i18n("Krusader Progress")); // show something better than kio_uiserver
 
113
 
 
114
  setJob(job);
 
115
  setOnlyClean(false);
 
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 ) ) );
 
128
 
 
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);
 
135
  show();
 
136
}
 
137
 
 
138
KrProgress::~KrProgress(){}
 
139
 
 
140
void KrProgress::slotTotalSize( KIO::Job*, KIO::filesize_t bytes ){
 
141
  m_iTotalSize = bytes;
 
142
}
 
143
 
 
144
 
 
145
void KrProgress::slotTotalFiles( KIO::Job*, unsigned long files ){
 
146
  m_iTotalFiles = files;
 
147
  showTotals();
 
148
}
 
149
 
 
150
 
 
151
void KrProgress::slotTotalDirs( KIO::Job*, unsigned long dirs ){
 
152
  m_iTotalDirs = dirs;
 
153
  showTotals();
 
154
}
 
155
 
 
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 )
 
161
  {
 
162
    QString tmps;
 
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 );
 
168
  }
 
169
}
 
170
 
 
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)"));
 
175
 
 
176
  setCaption( tmp );
 
177
}
 
178
 
 
179
 
 
180
void KrProgress::slotInfoMessage( KIO::Job*, const QString & msg )
 
181
{
 
182
  speedLabel->setText( msg );
 
183
  speedLabel->setAlignment( speedLabel->alignment() & ~Qt::WordBreak );
 
184
}
 
185
 
 
186
 
 
187
void KrProgress::slotProcessedSize( KIO::Job*, KIO::filesize_t bytes ) {
 
188
  m_iProcessedSize = bytes;
 
189
 
 
190
  QString tmp;
 
191
  tmp = i18n( "%1 of %2 complete").arg( KIO::convertSize(bytes) ).arg( KIO::convertSize(m_iTotalSize));
 
192
  sizeLabel->setText( tmp );
 
193
}
 
194
 
 
195
 
 
196
void KrProgress::slotProcessedDirs( KIO::Job*, unsigned long dirs )
 
197
{
 
198
  m_iProcessedDirs = dirs;
 
199
 
 
200
  QString tmps;
 
201
  tmps = i18n("%1 / %n directory", "%1 / %n directories", m_iTotalDirs).arg( m_iProcessedDirs );
 
202
  tmps += "   ";
 
203
  tmps += i18n("%1 / %n file", "%1 / %n files", m_iTotalFiles).arg( m_iProcessedFiles );
 
204
  progressLabel->setText( tmps );
 
205
}
 
206
 
 
207
 
 
208
void KrProgress::slotProcessedFiles( KIO::Job*, unsigned long files )
 
209
{
 
210
  m_iProcessedFiles = files;
 
211
 
 
212
  QString tmps;
 
213
  if ( m_iTotalDirs > 1 ) {
 
214
    tmps = i18n("%1 / %n directory", "%1 / %n directories", m_iTotalDirs).arg( m_iProcessedDirs );
 
215
    tmps += "   ";
 
216
  }
 
217
  tmps += i18n("%1 / %n file", "%1 / %n files", m_iTotalFiles).arg( m_iProcessedFiles );
 
218
  progressLabel->setText( tmps );
 
219
}
 
220
 
 
221
 
 
222
void KrProgress::slotSpeed( KIO::Job*, unsigned long bytes_per_second )
 
223
{
 
224
  if ( bytes_per_second == 0 ) {
 
225
    speedLabel->setText( i18n( "Working") );
 
226
  } else {
 
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() ) );
 
229
  }
 
230
}
 
231
 
 
232
 
 
233
void KrProgress::setDestVisible( bool visible )
 
234
{
 
235
  // We can't hide the destInvite/destLabel labels,
 
236
  // because it screws up the QGridLayout.
 
237
  if (visible)
 
238
  {
 
239
    destInvite->setText( i18n("Destination:") );
 
240
  }
 
241
  else
 
242
  {
 
243
    destInvite->setText( QString::null );
 
244
    destLabel->setText( QString::null );
 
245
  }
 
246
}
 
247
 
 
248
void KrProgress::virtual_hook( int id, void* data ){
 
249
  ProgressBase::virtual_hook( id, data );
 
250
}
 
251
 
 
252
void KrProgress::slotStop(){
 
253
  if ( m_pJob ) {
 
254
    m_pJob->kill(false); // this will call slotFinished
 
255
    m_pJob = 0L;
 
256
  } else {
 
257
    slotFinished( 0 ); // here we call it ourselves
 
258
  }
 
259
 
 
260
  emit stopped();
 
261
}
 
262
 
 
263
void KrProgress::closeEvent( QCloseEvent* ) { hide(); slotStop(); }
 
264
 
 
265
#include "krprogress.moc"