21 #include <tqtooltip.h>
22 #include <tqdatetime.h>
23 #include <tqcheckbox.h>
25 #include <tdeapplication.h>
28 #include <kstringhandler.h>
29 #include <tdeglobal.h>
30 #include <tdelocale.h>
31 #include <kiconloader.h>
33 #include <kpushbutton.h>
34 #include <kstandarddirs.h>
35 #include <kstdguiitem.h>
36 #include <klineedit.h>
42 #include "jobclasses.h"
43 #include "defaultprogress.h"
47 class DefaultProgress::DefaultProgressPrivate
52 KPushButton *cancelClose;
53 KPushButton *openFile;
54 KPushButton *openLocation;
60 DefaultProgress::DefaultProgress(
bool showNow )
62 m_iTotalSize(0), m_iTotalFiles(0), m_iTotalDirs(0),
63 m_iProcessedSize(0), m_iProcessedDirs(0), m_iProcessedFiles(0)
72 DefaultProgress::DefaultProgress( TQWidget* parent,
const char* )
73 : ProgressBase( parent ),
74 m_iTotalSize(0), m_iTotalFiles(0), m_iTotalDirs(0),
75 m_iProcessedSize(0), m_iProcessedDirs(0), m_iProcessedFiles(0)
80 bool DefaultProgress::keepOpen()
const
82 return d->keepOpenChecked;
85 void DefaultProgress::init()
87 d =
new DefaultProgressPrivate;
91 KWin::setIcons( winId(),
92 TDEGlobal::iconLoader()->loadIcon(
"document-save", TDEIcon::NoGroup, 32 ),
93 TDEGlobal::iconLoader()->loadIcon(
"document-save", TDEIcon::NoGroup, 16 ) );
96 TQVBoxLayout *topLayout =
new TQVBoxLayout(
this, KDialog::marginHint(),
97 KDialog::spacingHint() );
98 topLayout->addStrut( 360 );
100 TQGridLayout *grid =
new TQGridLayout( 2, 3 );
101 topLayout->addLayout(grid);
102 grid->addColSpacing(1, KDialog::spacingHint());
104 grid->addWidget(
new TQLabel(i18n(
"Source:"),
this), 0, 0);
106 sourceEdit =
new KLineEdit(
this);
107 sourceEdit->setReadOnly(
true);
108 sourceEdit->setEnableSqueezedText(
true);
109 grid->addWidget(sourceEdit, 0, 2);
111 destInvite =
new TQLabel(i18n(
"Destination:"),
this);
112 grid->addWidget(destInvite, 1, 0);
114 destEdit =
new KLineEdit(
this);
115 destEdit->setReadOnly (
true);
116 destEdit->setEnableSqueezedText(
true);
117 grid->addWidget(destEdit, 1, 2);
119 m_pProgressBar =
new KProgress(
this);
120 topLayout->addWidget( m_pProgressBar );
123 TQHBoxLayout *hBox =
new TQHBoxLayout();
124 topLayout->addLayout(hBox);
126 sizeLabel =
new TQLabel(
this);
127 hBox->addWidget(sizeLabel);
129 resumeLabel =
new TQLabel(
this);
130 hBox->addWidget(resumeLabel);
132 progressLabel =
new TQLabel(
this );
135 progressLabel->setAlignment( TQLabel::AlignRight );
136 hBox->addWidget( progressLabel );
138 hBox =
new TQHBoxLayout();
139 topLayout->addLayout(hBox);
141 speedLabel =
new TQLabel(
this);
142 hBox->addWidget(speedLabel, 1);
144 TQFrame *line =
new TQFrame(
this );
145 line->setFrameShape( TQFrame::HLine );
146 line->setFrameShadow( TQFrame::Sunken );
147 topLayout->addWidget( line );
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);
154 hBox =
new TQHBoxLayout();
155 topLayout->addLayout(hBox);
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);
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();
170 d->cancelClose =
new KPushButton( KStdGuiItem::cancel(),
this );
171 connect( d->cancelClose, TQ_SIGNAL( clicked() ), TQ_SLOT( slotStop() ) );
172 hBox->addWidget( d->cancelClose );
174 resize( sizeHint() );
175 setMaximumHeight(sizeHint().height());
177 d->keepOpenChecked =
false;
178 d->noCaptionYet =
true;
179 setCaption(i18n(
"Progress Dialog"));
182 DefaultProgress::~DefaultProgress()
190 if ( m_iTotalSize == size )
193 if (d->startTime.isNull())
194 d->startTime.start();
198 void DefaultProgress::slotTotalFiles(
TDEIO::Job*,
unsigned long files )
200 if ( m_iTotalFiles == files )
202 m_iTotalFiles = files;
207 void DefaultProgress::slotTotalDirs(
TDEIO::Job*,
unsigned long dirs )
209 if ( m_iTotalDirs == dirs )
215 void DefaultProgress::showTotals()
220 if ( m_iProcessedFiles == 0 && m_iProcessedDirs == 0 )
223 if ( m_iTotalDirs > 1 )
226 tmps = i18n(
"%n folder",
"%n folders", m_iTotalDirs) +
" ";
228 tmps += i18n(
"%n file",
"%n files", m_iTotalFiles);
229 progressLabel->setText( tmps );
234 TQString DefaultProgress::makePercentString(
unsigned long percent,
236 unsigned long totalFiles )
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 );
243 return i18n(
"%1 %" ).arg( percent );
246 void DefaultProgress::slotPercent(
TDEIO::Job*,
unsigned long percent )
248 TQString caption = makePercentString( percent, m_iTotalSize, m_iTotalFiles );
249 m_pProgressBar->setValue( percent );
252 caption.append(i18n(
" (Copying)"));
255 caption.append(i18n(
" (Moving)"));
258 caption.append(i18n(
" (Deleting)"));
261 caption.append(i18n(
" (Creating)"));
264 caption.append(i18n(
" (Done)"));
268 setCaption( caption );
269 d->noCaptionYet =
false;
273 void DefaultProgress::slotInfoMessage(
TDEIO::Job*,
const TQString & msg )
275 speedLabel->setText( msg );
276 speedLabel->setAlignment( speedLabel->alignment() & ~TQt::WordBreak );
281 if ( m_iProcessedSize == bytes )
283 m_iProcessedSize = bytes;
285 TQString tmp = i18n(
"%1 of %2 complete")
288 sizeLabel->setText( tmp );
292 void DefaultProgress::slotProcessedDirs(
TDEIO::Job*,
unsigned long dirs )
294 if ( m_iProcessedDirs == dirs )
296 m_iProcessedDirs = dirs;
299 tmps = i18n(
"%1 / %n folder",
"%1 / %n folders", m_iTotalDirs).arg( m_iProcessedDirs );
301 tmps += i18n(
"%1 / %n file",
"%1 / %n files", m_iTotalFiles).arg( m_iProcessedFiles );
302 progressLabel->setText( tmps );
306 void DefaultProgress::slotProcessedFiles(
TDEIO::Job*,
unsigned long files )
308 if ( m_iProcessedFiles == files )
310 m_iProcessedFiles = files;
313 if ( m_iTotalDirs > 1 ) {
314 tmps = i18n(
"%1 / %n folder",
"%1 / %n folders", m_iTotalDirs).arg( m_iProcessedDirs );
317 tmps += i18n(
"%1 / %n file",
"%1 / %n files", m_iTotalFiles).arg( m_iProcessedFiles );
318 progressLabel->setText( tmps );
322 void DefaultProgress::slotSpeed(
TDEIO::Job*,
unsigned long speed )
325 speedLabel->setText( i18n(
"Stalled") );
333 void DefaultProgress::slotCopying(
TDEIO::Job*,
const KURL& from,
const KURL& to )
335 if ( d->noCaptionYet ) {
336 setCaption(i18n(
"Copy File(s) Progress"));
337 d->noCaptionYet =
false;
340 sourceEdit->setText(from.prettyURL());
341 setDestVisible(
true );
342 checkDestination( to );
343 destEdit->setText(to.prettyURL());
347 void DefaultProgress::slotMoving(
TDEIO::Job*,
const KURL& from,
const KURL& to )
349 if ( d->noCaptionYet ) {
350 setCaption(i18n(
"Move File(s) Progress"));
351 d->noCaptionYet =
false;
354 sourceEdit->setText(from.prettyURL());
355 setDestVisible(
true );
356 checkDestination( to );
357 destEdit->setText(to.prettyURL());
361 void DefaultProgress::slotCreatingDir(
TDEIO::Job*,
const KURL& dir )
363 if ( d->noCaptionYet ) {
364 setCaption(i18n(
"Creating Folder"));
365 d->noCaptionYet =
false;
368 sourceEdit->setText(dir.prettyURL());
369 setDestVisible(
false );
373 void DefaultProgress::slotDeleting(
TDEIO::Job*,
const KURL& url )
375 if ( d->noCaptionYet ) {
376 setCaption(i18n(
"Delete File(s) Progress"));
377 d->noCaptionYet =
false;
380 sourceEdit->setText(url.prettyURL());
381 setDestVisible(
false );
384 void DefaultProgress::slotTransferring(
TDEIO::Job*,
const KURL& url )
386 if ( d->noCaptionYet ) {
387 setCaption(i18n(
"Loading Progress"));
388 d->noCaptionYet =
false;
390 sourceEdit->setText(url.prettyURL());
391 setDestVisible(
false );
394 void DefaultProgress::slotStating(
TDEIO::Job*,
const KURL& url )
396 setCaption(i18n(
"Examining File Progress"));
397 sourceEdit->setText(url.prettyURL());
398 setDestVisible(
false );
401 void DefaultProgress::slotMounting(
TDEIO::Job*,
const TQString & dev,
const TQString & point )
403 setCaption(i18n(
"Mounting %1").arg(dev));
404 sourceEdit->setText(point);
405 setDestVisible(
false );
408 void DefaultProgress::slotUnmounting(
TDEIO::Job*,
const TQString & point )
410 setCaption(i18n(
"Unmounting"));
411 sourceEdit->setText(point);
412 setDestVisible(
false );
418 resumeLabel->setText( i18n(
"Resuming from %1").arg(
TDEIO::number(resume)) );
420 resumeLabel->setText( i18n(
"Not resumable") );
424 void DefaultProgress::setDestVisible(
bool visible )
433 destInvite->setText( i18n(
"Destination:") );
439 destInvite->setText( TQString::null );
440 destEdit->setText( TQString::null );
444 void DefaultProgress::slotClean() {
445 if (d->keepOpenChecked) {
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();
456 speedLabel->setText(i18n(
"%1/s (done)").arg(
TDEIO::convertSize(1000 * m_iTotalSize / s)));
464 void DefaultProgress::slotKeepOpenToggled(
bool keepopen)
466 d->keepOpenChecked=keepopen;
469 void DefaultProgress::checkDestination(
const KURL& dest) {
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 ) )
481 d->openLocation->show();
487 void DefaultProgress::slotOpenFile()
490 proc <<
"konqueror" << d->location.prettyURL();
491 proc.start(TDEProcess::DontCare);
494 void DefaultProgress::slotOpenLocation()
497 d->location.setFileName(
"");
498 proc <<
"konqueror" << d->location.prettyURL();
499 proc.start(TDEProcess::DontCare);
502 void DefaultProgress::virtual_hook(
int id,
void* data )
503 { ProgressBase::virtual_hook(
id, data ); }
507 #include "defaultprogress.moc"
The base class for all jobs.
A namespace for TDEIO globals.
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.
TDEIO_EXPORT TQString number(TDEIO::filesize_t size)
Converts a size to a string representation Not unlike TQString::number(...)
TDEIO_EXPORT TQString convertSeconds(unsigned int seconds)
Convert seconds to a string representing number of days, hours, minutes and seconds.
TDEIO_EXPORT TQString convertSize(TDEIO::filesize_t size)
Converts size from bytes to the string representation.
TQ_ULLONG filesize_t
64-bit file size