• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
defaultprogress.cpp
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., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include <tqtimer.h>
20#include <tqlayout.h>
21#include <tqtooltip.h>
22#include <tqdatetime.h>
23#include <tqcheckbox.h>
24
25#include <tdeapplication.h>
26#include <kdebug.h>
27#include <kdialog.h>
28#include <kstringhandler.h>
29#include <tdeglobal.h>
30#include <tdelocale.h>
31#include <kiconloader.h>
32#include <tdeprocess.h>
33#include <kpushbutton.h>
34#include <kstandarddirs.h>
35#include <kstdguiitem.h>
36#include <klineedit.h>
37
38#ifdef TQ_WS_X11
39#include <twin.h>
40#endif
41
42#include "jobclasses.h"
43#include "defaultprogress.h"
44
45namespace TDEIO {
46
47class DefaultProgress::DefaultProgressPrivate
48{
49public:
50 bool keepOpenChecked;
51 bool noCaptionYet;
52 KPushButton *cancelClose;
53 KPushButton *openFile;
54 KPushButton *openLocation;
55 TQCheckBox *keepOpen;
56 KURL location;
57 TQTime startTime;
58};
59
60DefaultProgress::DefaultProgress( bool showNow )
61 : ProgressBase( 0 ),
62 m_iTotalSize(0), m_iTotalFiles(0), m_iTotalDirs(0),
63 m_iProcessedSize(0), m_iProcessedDirs(0), m_iProcessedFiles(0)
64{
65 init();
66
67 if ( showNow ) {
68 show();
69 }
70}
71
72DefaultProgress::DefaultProgress( TQWidget* parent, const char* /*name*/ )
73 : ProgressBase( parent ),
74 m_iTotalSize(0), m_iTotalFiles(0), m_iTotalDirs(0),
75 m_iProcessedSize(0), m_iProcessedDirs(0), m_iProcessedFiles(0)
76{
77 init();
78}
79
80bool DefaultProgress::keepOpen() const
81{
82 return d->keepOpenChecked;
83}
84
85void DefaultProgress::init()
86{
87 d = new DefaultProgressPrivate;
88
89#ifdef TQ_WS_X11 //FIXME(E): Remove once all the KWin::foo calls have been ported to QWS
90 // Set a useful icon for this window!
91 KWin::setIcons( winId(),
92 TDEGlobal::iconLoader()->loadIcon( "document-save", TDEIcon::NoGroup, 32 ),
93 TDEGlobal::iconLoader()->loadIcon( "document-save", TDEIcon::NoGroup, 16 ) );
94#endif
95
96 TQVBoxLayout *topLayout = new TQVBoxLayout( this, KDialog::marginHint(),
97 KDialog::spacingHint() );
98 topLayout->addStrut( 360 ); // makes dlg at least that wide
99
100 TQGridLayout *grid = new TQGridLayout( 2, 3 );
101 topLayout->addLayout(grid);
102 grid->addColSpacing(1, KDialog::spacingHint());
103 // filenames or action name
104 grid->addWidget(new TQLabel(i18n("Source:"), this), 0, 0);
105
106 sourceEdit = new KLineEdit(this);
107 sourceEdit->setReadOnly(true);
108 sourceEdit->setEnableSqueezedText(true);
109 grid->addWidget(sourceEdit, 0, 2);
110
111 destInvite = new TQLabel(i18n("Destination:"), this);
112 grid->addWidget(destInvite, 1, 0);
113
114 destEdit = new KLineEdit(this);
115 destEdit->setReadOnly (true);
116 destEdit->setEnableSqueezedText(true);
117 grid->addWidget(destEdit, 1, 2);
118
119 m_pProgressBar = new KProgress(this);
120 topLayout->addWidget( m_pProgressBar );
121
122 // processed info
123 TQHBoxLayout *hBox = new TQHBoxLayout();
124 topLayout->addLayout(hBox);
125
126 sizeLabel = new TQLabel(this);
127 hBox->addWidget(sizeLabel);
128
129 resumeLabel = new TQLabel(this);
130 hBox->addWidget(resumeLabel);
131
132 progressLabel = new TQLabel( this );
133/* progressLabel->setSizePolicy( TQSizePolicy( TQSizePolicy::MinimumExpanding,
134 TQSizePolicy::Preferred ) );*/
135 progressLabel->setAlignment( TQLabel::AlignRight );
136 hBox->addWidget( progressLabel );
137
138 hBox = new TQHBoxLayout();
139 topLayout->addLayout(hBox);
140
141 speedLabel = new TQLabel(this);
142 hBox->addWidget(speedLabel, 1);
143
144 TQFrame *line = new TQFrame( this );
145 line->setFrameShape( TQFrame::HLine );
146 line->setFrameShadow( TQFrame::Sunken );
147 topLayout->addWidget( line );
148
149 d->keepOpen = new TQCheckBox( i18n("&Keep this window open after transfer is complete"), this);
150 connect( d->keepOpen, TQ_SIGNAL( toggled(bool) ), TQ_SLOT( slotKeepOpenToggled(bool) ) );
151 topLayout->addWidget(d->keepOpen);
152 d->keepOpen->hide();
153
154 hBox = new TQHBoxLayout();
155 topLayout->addLayout(hBox);
156
157 d->openFile = new KPushButton( i18n("Open &File"), this );
158 connect( d->openFile, TQ_SIGNAL( clicked() ), TQ_SLOT( slotOpenFile() ) );
159 hBox->addWidget( d->openFile );
160 d->openFile->setEnabled(false);
161 d->openFile->hide();
162
163 d->openLocation = new KPushButton( i18n("Open &Destination"), this );
164 connect( d->openLocation, TQ_SIGNAL( clicked() ), TQ_SLOT( slotOpenLocation() ) );
165 hBox->addWidget( d->openLocation );
166 d->openLocation->hide();
167
168 hBox->addStretch(1);
169
170 d->cancelClose = new KPushButton( KStdGuiItem::cancel(), this );
171 connect( d->cancelClose, TQ_SIGNAL( clicked() ), TQ_SLOT( slotStop() ) );
172 hBox->addWidget( d->cancelClose );
173
174 resize( sizeHint() );
175 setMaximumHeight(sizeHint().height());
176
177 d->keepOpenChecked = false;
178 d->noCaptionYet = true;
179 setCaption(i18n("Progress Dialog")); // show something better than tdeio_uiserver
180}
181
182DefaultProgress::~DefaultProgress()
183{
184 delete d;
185}
186
187void DefaultProgress::slotTotalSize( TDEIO::Job*, TDEIO::filesize_t size )
188{
189 // size is measured in bytes
190 if ( m_iTotalSize == size )
191 return;
192 m_iTotalSize = size;
193 if (d->startTime.isNull())
194 d->startTime.start();
195}
196
197
198void DefaultProgress::slotTotalFiles( TDEIO::Job*, unsigned long files )
199{
200 if ( m_iTotalFiles == files )
201 return;
202 m_iTotalFiles = files;
203 showTotals();
204}
205
206
207void DefaultProgress::slotTotalDirs( TDEIO::Job*, unsigned long dirs )
208{
209 if ( m_iTotalDirs == dirs )
210 return;
211 m_iTotalDirs = dirs;
212 showTotals();
213}
214
215void DefaultProgress::showTotals()
216{
217 // Show the totals in the progress label, if we still haven't
218 // processed anything. This is useful when the stat'ing phase
219 // of CopyJob takes a long time (e.g. over networks).
220 if ( m_iProcessedFiles == 0 && m_iProcessedDirs == 0 )
221 {
222 TQString tmps;
223 if ( m_iTotalDirs > 1 )
224 // that we have a singular to translate looks weired but is only logical
225 // xgettext: no-c-format
226 tmps = i18n("%n folder", "%n folders", m_iTotalDirs) + " ";
227 // xgettext: no-c-format
228 tmps += i18n("%n file", "%n files", m_iTotalFiles);
229 progressLabel->setText( tmps );
230 }
231}
232
233//static
234TQString DefaultProgress::makePercentString( unsigned long percent,
235 TDEIO::filesize_t totalSize,
236 unsigned long totalFiles )
237{
238 if ( totalSize )
239 return i18n( "%1 % of %2 " ).arg( TQString::number(percent) , TDEIO::convertSize( totalSize ) );
240 else if ( totalFiles )
241 return i18n( "%1 % of 1 file", "%1 % of %n files", totalFiles ).arg( percent );
242 else
243 return i18n( "%1 %" ).arg( percent );
244}
245
246void DefaultProgress::slotPercent( TDEIO::Job*, unsigned long percent )
247{
248 TQString caption = makePercentString( percent, m_iTotalSize, m_iTotalFiles );
249 m_pProgressBar->setValue( percent );
250 switch(mode) {
251 case Copy:
252 caption.append(i18n(" (Copying)"));
253 break;
254 case Move:
255 caption.append(i18n(" (Moving)"));
256 break;
257 case Delete:
258 caption.append(i18n(" (Deleting)"));
259 break;
260 case Create:
261 caption.append(i18n(" (Creating)"));
262 break;
263 case Done:
264 caption.append(i18n(" (Done)"));
265 break;
266 }
267
268 setCaption( caption );
269 d->noCaptionYet = false;
270}
271
272
273void DefaultProgress::slotInfoMessage( TDEIO::Job*, const TQString & msg )
274{
275 speedLabel->setText( msg );
276 speedLabel->setAlignment( speedLabel->alignment() & ~TQt::WordBreak );
277}
278
279
280void DefaultProgress::slotProcessedSize( TDEIO::Job*, TDEIO::filesize_t bytes ) {
281 if ( m_iProcessedSize == bytes )
282 return;
283 m_iProcessedSize = bytes;
284
285 TQString tmp = i18n( "%1 of %2 complete")
286 .arg( TDEIO::convertSize(bytes) )
287 .arg( TDEIO::convertSize(m_iTotalSize));
288 sizeLabel->setText( tmp );
289}
290
291
292void DefaultProgress::slotProcessedDirs( TDEIO::Job*, unsigned long dirs )
293{
294 if ( m_iProcessedDirs == dirs )
295 return;
296 m_iProcessedDirs = dirs;
297
298 TQString tmps;
299 tmps = i18n("%1 / %n folder", "%1 / %n folders", m_iTotalDirs).arg( m_iProcessedDirs );
300 tmps += " ";
301 tmps += i18n("%1 / %n file", "%1 / %n files", m_iTotalFiles).arg( m_iProcessedFiles );
302 progressLabel->setText( tmps );
303}
304
305
306void DefaultProgress::slotProcessedFiles( TDEIO::Job*, unsigned long files )
307{
308 if ( m_iProcessedFiles == files )
309 return;
310 m_iProcessedFiles = files;
311
312 TQString tmps;
313 if ( m_iTotalDirs > 1 ) {
314 tmps = i18n("%1 / %n folder", "%1 / %n folders", m_iTotalDirs).arg( m_iProcessedDirs );
315 tmps += " ";
316 }
317 tmps += i18n("%1 / %n file", "%1 / %n files", m_iTotalFiles).arg( m_iProcessedFiles );
318 progressLabel->setText( tmps );
319}
320
321
322void DefaultProgress::slotSpeed( TDEIO::Job*, unsigned long speed )
323{
324 if ( speed == 0 ) {
325 speedLabel->setText( i18n( "Stalled") );
326 } else {
327 speedLabel->setText( i18n( "%1/s ( %2 remaining )").arg( TDEIO::convertSize( speed ))
328 .arg( TDEIO::convertSeconds( TDEIO::calculateRemainingSeconds( m_iTotalSize, m_iProcessedSize, speed ))) );
329 }
330}
331
332
333void DefaultProgress::slotCopying( TDEIO::Job*, const KURL& from, const KURL& to )
334{
335 if ( d->noCaptionYet ) {
336 setCaption(i18n("Copy File(s) Progress"));
337 d->noCaptionYet = false;
338 }
339 mode = Copy;
340 sourceEdit->setText(from.prettyURL());
341 setDestVisible( true );
342 checkDestination( to );
343 destEdit->setText(to.prettyURL());
344}
345
346
347void DefaultProgress::slotMoving( TDEIO::Job*, const KURL& from, const KURL& to )
348{
349 if ( d->noCaptionYet ) {
350 setCaption(i18n("Move File(s) Progress"));
351 d->noCaptionYet = false;
352 }
353 mode = Move;
354 sourceEdit->setText(from.prettyURL());
355 setDestVisible( true );
356 checkDestination( to );
357 destEdit->setText(to.prettyURL());
358}
359
360
361void DefaultProgress::slotCreatingDir( TDEIO::Job*, const KURL& dir )
362{
363 if ( d->noCaptionYet ) {
364 setCaption(i18n("Creating Folder"));
365 d->noCaptionYet = false;
366 }
367 mode = Create;
368 sourceEdit->setText(dir.prettyURL());
369 setDestVisible( false );
370}
371
372
373void DefaultProgress::slotDeleting( TDEIO::Job*, const KURL& url )
374{
375 if ( d->noCaptionYet ) {
376 setCaption(i18n("Delete File(s) Progress"));
377 d->noCaptionYet = false;
378 }
379 mode = Delete;
380 sourceEdit->setText(url.prettyURL());
381 setDestVisible( false );
382}
383
384void DefaultProgress::slotTransferring( TDEIO::Job*, const KURL& url )
385{
386 if ( d->noCaptionYet ) {
387 setCaption(i18n("Loading Progress"));
388 d->noCaptionYet = false;
389 }
390 sourceEdit->setText(url.prettyURL());
391 setDestVisible( false );
392}
393
394void DefaultProgress::slotStating( TDEIO::Job*, const KURL& url )
395{
396 setCaption(i18n("Examining File Progress"));
397 sourceEdit->setText(url.prettyURL());
398 setDestVisible( false );
399}
400
401void DefaultProgress::slotMounting( TDEIO::Job*, const TQString & dev, const TQString & point )
402{
403 setCaption(i18n("Mounting %1").arg(dev));
404 sourceEdit->setText(point);
405 setDestVisible( false );
406}
407
408void DefaultProgress::slotUnmounting( TDEIO::Job*, const TQString & point )
409{
410 setCaption(i18n("Unmounting"));
411 sourceEdit->setText(point);
412 setDestVisible( false );
413}
414
415void DefaultProgress::slotCanResume( TDEIO::Job*, TDEIO::filesize_t resume )
416{
417 if ( resume ) {
418 resumeLabel->setText( i18n("Resuming from %1").arg(TDEIO::number(resume)) );
419 } else {
420 resumeLabel->setText( i18n("Not resumable") );
421 }
422}
423
424void DefaultProgress::setDestVisible( bool visible )
425{
426 // We can't hide the destInvite/destEdit labels,
427 // because it screws up the TQGridLayout.
428 if (visible)
429 {
430 destInvite->show();
431 destEdit->show();
432
433 destInvite->setText( i18n("Destination:") );
434 }
435 else
436 {
437 destInvite->hide();
438 destEdit->hide();
439 destInvite->setText( TQString::null );
440 destEdit->setText( TQString::null );
441 }
442}
443
444void DefaultProgress::slotClean() {
445 if (d->keepOpenChecked) {
446 mode = Done;
447 slotPercent(0, 100);
448 d->cancelClose->setGuiItem( KStdGuiItem::close() );
449 d->openFile->setEnabled(true);
450 slotProcessedSize(0, m_iTotalSize);
451 d->keepOpen->setEnabled(false);
452 if (!d->startTime.isNull()) {
453 int s = d->startTime.elapsed();
454 if (!s)
455 s = 1;
456 speedLabel->setText(i18n("%1/s (done)").arg(TDEIO::convertSize(1000 * m_iTotalSize / s)));
457 }
458 setOnlyClean(false);
459 }
460 else
461 hide();
462}
463
464void DefaultProgress::slotKeepOpenToggled(bool keepopen)
465{
466 d->keepOpenChecked=keepopen;
467}
468
469void DefaultProgress::checkDestination(const KURL& dest) {
470 bool ok = true;
471 if ( dest.isLocalFile() ) {
472 TQString path = dest.path( -1 );
473 TQStringList tmpDirs = TDEGlobal::dirs()->resourceDirs( "tmp" );
474 for ( TQStringList::Iterator it = tmpDirs.begin() ; ok && it != tmpDirs.end() ; ++it )
475 if ( path.contains( *it ) )
476 ok = false; // it's in the tmp resource
477 }
478
479 if ( ok ) {
480 d->openFile->show();
481 d->openLocation->show();
482 d->keepOpen->show();
483 d->location=dest;
484 }
485}
486
487void DefaultProgress::slotOpenFile()
488{
489 TDEProcess proc;
490 proc << "konqueror" << d->location.prettyURL();
491 proc.start(TDEProcess::DontCare);
492}
493
494void DefaultProgress::slotOpenLocation()
495{
496 TDEProcess proc;
497 d->location.setFileName("");
498 proc << "konqueror" << d->location.prettyURL();
499 proc.start(TDEProcess::DontCare);
500}
501
502void DefaultProgress::virtual_hook( int id, void* data )
503{ ProgressBase::virtual_hook( id, data ); }
504
505} /* namespace */
506
507#include "defaultprogress.moc"
TDEIO::Job
The base class for all jobs.
Definition: jobclasses.h:67
TDEIO
A namespace for TDEIO globals.
Definition: authinfo.h:29
TDEIO::calculateRemainingSeconds
TDEIO_EXPORT unsigned int calculateRemainingSeconds(TDEIO::filesize_t totalSize, TDEIO::filesize_t processedSize, TDEIO::filesize_t speed)
Calculates remaining time in seconds from total size, processed size and speed.
Definition: global.cpp:103
TDEIO::number
TDEIO_EXPORT TQString number(TDEIO::filesize_t size)
Converts a size to a string representation Not unlike TQString::number(...)
Definition: global.cpp:96
TDEIO::convertSeconds
TDEIO_EXPORT TQString convertSeconds(unsigned int seconds)
Convert seconds to a string representing number of days, hours, minutes and seconds.
Definition: global.cpp:112
TDEIO::convertSize
TDEIO_EXPORT TQString convertSize(TDEIO::filesize_t size)
Converts size from bytes to the string representation.
Definition: global.cpp:53
TDEIO::filesize_t
TQ_ULLONG filesize_t
64-bit file size
Definition: global.h:39

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.4
This website is maintained by Timothy Pearson.