File indexing completed on 2024-10-06 04:26:00
0001 /* 0002 SPDX-FileCopyrightText: 2003-2010 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-FileCopyrightText: 2010 Michal Malek <michalm@jabster.pl> 0004 SPDX-FileCopyrightText: 1998-2010 Sebastian Trueg <trueg@k3b.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 0010 #include "k3bjobprogressdialog.h" 0011 #include "k3bapplication.h" 0012 #include "k3bemptydiscwaiter.h" 0013 #include "k3bdebuggingoutputdialog.h" 0014 #include "k3bjobinterface.h" 0015 #include "k3bthemedlabel.h" 0016 #include "k3b.h" 0017 #include "k3bjob.h" 0018 #include "k3bdevice.h" 0019 #include "k3bdevicemanager.h" 0020 #include "k3bdeviceglobals.h" 0021 #include "k3bglobals.h" 0022 #include "k3bkjobbridge.h" 0023 #include "k3bstdguiitems.h" 0024 #include "k3bversion.h" 0025 #include "k3bthememanager.h" 0026 0027 #include <KColorScheme> 0028 #include <KConfig> 0029 #include <KSharedConfig> 0030 #include <KJobTrackerInterface> 0031 #include <KFormat> 0032 #include <KNotification> 0033 #include <KSqueezedTextLabel> 0034 #include <KLocalizedString> 0035 #include <KIO/Global> 0036 #include <KIO/JobTracker> 0037 #include <KMessageBox> 0038 0039 #include <QDebug> 0040 #include <QDateTime> 0041 #include <QString> 0042 #include <QCloseEvent> 0043 #include <QIcon> 0044 #include <QFont> 0045 #include <QKeyEvent> 0046 #include <QDialogButtonBox> 0047 #include <QFrame> 0048 #include <QGridLayout> 0049 #include <QHBoxLayout> 0050 #include <QLabel> 0051 #include <QProgressBar> 0052 #include <QPushButton> 0053 #include <QScrollBar> 0054 #include <QTreeWidget> 0055 #include <QVBoxLayout> 0056 0057 0058 class K3b::JobProgressDialog::Private 0059 { 0060 public: 0061 int lastProgress; 0062 0063 QFrame* headerFrame; 0064 QFrame* progressHeaderFrame; 0065 QTreeWidget* viewInfo; 0066 }; 0067 0068 0069 0070 K3b::JobProgressDialog::JobProgressDialog( QWidget* parent, 0071 bool showSubProgress ) 0072 : QDialog( parent ) 0073 { 0074 d = new Private; 0075 setupGUI(); 0076 0077 if( !showSubProgress ) { 0078 m_progressSubPercent->hide(); 0079 } 0080 0081 m_job = 0; 0082 } 0083 0084 0085 /* 0086 * Destroys the object and frees any allocated resources 0087 */ 0088 K3b::JobProgressDialog::~JobProgressDialog() 0089 { 0090 qDebug(); 0091 delete d; 0092 } 0093 0094 0095 void K3b::JobProgressDialog::setupGUI() 0096 { 0097 QVBoxLayout* mainLayout = new QVBoxLayout( this ); 0098 0099 // header 0100 // ------------------------------------------------------------------------------------------ 0101 QFrame* headerParentFrame = new QFrame( this ); 0102 headerParentFrame->setFrameShape( QFrame::StyledPanel ); 0103 headerParentFrame->setFrameShadow( QFrame::Sunken ); 0104 headerParentFrame->setLineWidth( 1 ); 0105 headerParentFrame->setLayout( new QVBoxLayout() ); 0106 headerParentFrame->layout()->setSpacing(0); 0107 headerParentFrame->layout()->setContentsMargins(0, 0, 0, 0); 0108 0109 d->headerFrame = new QFrame( headerParentFrame ); 0110 d->headerFrame->setFrameStyle( QFrame::NoFrame ); 0111 d->headerFrame->setAutoFillBackground( true ); 0112 headerParentFrame->layout()->addWidget( d->headerFrame ); 0113 0114 QHBoxLayout* headerLayout = new QHBoxLayout( d->headerFrame ); 0115 headerLayout->setContentsMargins( 0, 0, 0, 0 ); 0116 headerLayout->setSpacing( 0 ); 0117 m_pixLabel = new K3b::ThemedLabel( d->headerFrame ); 0118 headerLayout->addWidget( m_pixLabel ); 0119 0120 m_labelJob = new K3b::ThemedLabel( d->headerFrame ); 0121 //TODO fix me 0122 //m_labelJob->setMinimumVisibleText( 40 ); 0123 QFont m_labelJob_font( m_labelJob->font() ); 0124 m_labelJob_font.setPointSize( m_labelJob_font.pointSize() + 2 ); 0125 m_labelJob_font.setBold( true ); 0126 m_labelJob->setFont( m_labelJob_font ); 0127 m_labelJob->setAlignment( Qt::AlignVCenter | Qt::AlignRight ); 0128 0129 m_labelJobDetails = new K3b::ThemedLabel( d->headerFrame ); 0130 m_labelJobDetails->setAlignment( Qt::AlignVCenter | Qt::AlignRight ); 0131 0132 QVBoxLayout* jobLabelsLayout = new QVBoxLayout; 0133 jobLabelsLayout->addWidget( m_labelJob ); 0134 jobLabelsLayout->addWidget( m_labelJobDetails ); 0135 jobLabelsLayout->setContentsMargins( -1, -1, 10, -1 ); 0136 headerLayout->addLayout( jobLabelsLayout ); 0137 headerLayout->setAlignment( jobLabelsLayout, Qt::AlignVCenter ); 0138 0139 mainLayout->addWidget( headerParentFrame ); 0140 // ------------------------------------------------------------------------------------------ 0141 0142 d->viewInfo = new QTreeWidget( this ); 0143 d->viewInfo->setAllColumnsShowFocus( true ); 0144 d->viewInfo->setHeaderHidden( true ); 0145 d->viewInfo->setSortingEnabled( false ); 0146 d->viewInfo->setRootIsDecorated( false ); 0147 d->viewInfo->setSelectionMode( QAbstractItemView::NoSelection ); 0148 d->viewInfo->setFocusPolicy( Qt::NoFocus ); 0149 mainLayout->addWidget( d->viewInfo, 1 ); 0150 0151 0152 // progress header 0153 // ------------------------------------------------------------------------------------------ 0154 QFrame* progressHeaderParentFrame = new QFrame( this ); 0155 progressHeaderParentFrame->setFrameShape( QFrame::StyledPanel ); 0156 progressHeaderParentFrame->setFrameShadow( QFrame::Sunken ); 0157 progressHeaderParentFrame->setLineWidth( 1 ); 0158 progressHeaderParentFrame->setLayout( new QVBoxLayout() ); 0159 progressHeaderParentFrame->layout()->setSpacing(0); 0160 progressHeaderParentFrame->layout()->setContentsMargins(0, 0, 0, 0); 0161 0162 d->progressHeaderFrame = new QFrame( progressHeaderParentFrame ); 0163 d->progressHeaderFrame->setFrameStyle( QFrame::NoFrame ); 0164 d->progressHeaderFrame->setAutoFillBackground( true ); 0165 progressHeaderParentFrame->layout()->addWidget( d->progressHeaderFrame ); 0166 0167 QHBoxLayout* progressHeaderLayout = new QHBoxLayout( d->progressHeaderFrame ); 0168 progressHeaderLayout->setContentsMargins( 0, 0, 0, 0 ); 0169 progressHeaderLayout->setSpacing( 0 ); 0170 0171 m_labelTask = new K3b::ThemedLabel( d->progressHeaderFrame ); 0172 QFont m_labelTask_font( m_labelTask->font() ); 0173 m_labelTask_font.setPointSize( m_labelTask_font.pointSize() + 2 ); 0174 m_labelTask_font.setBold( true ); 0175 m_labelTask->setFont( m_labelTask_font ); 0176 0177 m_labelRemainingTime = new QLabel( d->progressHeaderFrame ); 0178 m_labelElapsedTime = new QLabel( d->progressHeaderFrame ); 0179 0180 QVBoxLayout* jobProgressLayout = new QVBoxLayout( d->progressHeaderFrame ); 0181 jobProgressLayout->addWidget( m_labelTask ); 0182 jobProgressLayout->addWidget( m_labelRemainingTime ); 0183 jobProgressLayout->addWidget( m_labelElapsedTime ); 0184 jobProgressLayout->setContentsMargins( 10, -1, -1, -1 ); 0185 0186 progressHeaderLayout->addLayout( jobProgressLayout ); 0187 progressHeaderLayout->setAlignment( jobProgressLayout, Qt::AlignVCenter ); 0188 progressHeaderLayout->addWidget( new K3b::ThemedLabel( K3b::Theme::PROGRESS_RIGHT, d->progressHeaderFrame ) ); 0189 mainLayout->addWidget( progressHeaderParentFrame ); 0190 // ------------------------------------------------------------------------------------------ 0191 0192 QHBoxLayout* layout3 = new QHBoxLayout; 0193 0194 m_labelSubTask = new KSqueezedTextLabel( this ); 0195 m_labelSubTask->setTextElideMode( Qt::ElideRight ); 0196 layout3->addWidget( m_labelSubTask ); 0197 0198 m_labelSubProcessedSize = new QLabel( this ); 0199 m_labelSubProcessedSize->setAlignment( Qt::AlignVCenter | Qt::AlignRight ); 0200 layout3->addWidget( m_labelSubProcessedSize ); 0201 mainLayout->addLayout( layout3 ); 0202 0203 m_progressSubPercent = new QProgressBar( this ); 0204 mainLayout->addWidget( m_progressSubPercent ); 0205 0206 QHBoxLayout* layout4 = new QHBoxLayout; 0207 0208 QLabel* textLabel5 = new QLabel( i18n("Overall progress:"), this ); 0209 layout4->addWidget( textLabel5 ); 0210 0211 m_labelProcessedSize = new QLabel( this ); 0212 m_labelProcessedSize->setAlignment( Qt::AlignVCenter | Qt::AlignRight ); 0213 layout4->addWidget( m_labelProcessedSize ); 0214 mainLayout->addLayout( layout4 ); 0215 0216 m_progressPercent = new QProgressBar( this ); 0217 mainLayout->addWidget( m_progressPercent ); 0218 0219 m_frameExtraInfo = new QFrame( this ); 0220 m_frameExtraInfo->setFrameShape( QFrame::NoFrame ); 0221 m_frameExtraInfo->setFrameShadow( QFrame::Raised ); 0222 m_frameExtraInfoLayout = new QGridLayout( m_frameExtraInfo ); 0223 m_frameExtraInfoLayout->setContentsMargins( 0, 0, 0,0 ); 0224 mainLayout->addWidget( m_frameExtraInfo ); 0225 0226 QDialogButtonBox* buttonBox = new QDialogButtonBox( this ); 0227 m_cancelButton = buttonBox->addButton( QDialogButtonBox::Cancel ); 0228 connect( m_cancelButton, SIGNAL(clicked()), this, SLOT(reject()) ); 0229 0230 m_showDbgOutButton = buttonBox->addButton( i18n("Show Debugging Output"), QDialogButtonBox::NoRole ); 0231 connect( m_showDbgOutButton, SIGNAL(clicked()), this, SLOT(slotShowDebuggingOutput()) ); 0232 0233 m_closeButton = buttonBox->addButton( QDialogButtonBox::Close ); 0234 connect( m_closeButton, SIGNAL(clicked()), this, SLOT(accept()) ); 0235 0236 mainLayout->addWidget( buttonBox ); 0237 0238 m_pixLabel->setThemePixmap( K3b::Theme::PROGRESS_WORKING ); 0239 0240 slotThemeChanged(); 0241 0242 if (k3bappcore) { 0243 connect( k3bappcore->themeManager(), SIGNAL(themeChanged()), 0244 this, SLOT(slotThemeChanged()) ); 0245 } 0246 } 0247 0248 0249 void K3b::JobProgressDialog::setExtraInfo( QWidget *extra ) 0250 { 0251 extra->setParent( m_frameExtraInfo ); 0252 m_frameExtraInfoLayout->addWidget( extra, 0, 0 ); 0253 } 0254 0255 0256 bool K3b::JobProgressDialog::event( QEvent *event ) 0257 { 0258 if( event->type() == QEvent::StyleChange ) { 0259 slotThemeChanged(); 0260 } 0261 return QDialog::event( event ); 0262 } 0263 0264 0265 void K3b::JobProgressDialog::showEvent( QShowEvent* e ) 0266 { 0267 if( !e->spontaneous() ) { 0268 if( KConfigGroup( KSharedConfig::openConfig(), QStringLiteral("General Options") ).readEntry( "hide main window while writing", false ) ) { 0269 k3bappcore->k3bMainWindow()->hide(); 0270 } 0271 } 0272 QDialog::showEvent( e ); 0273 } 0274 0275 0276 void K3b::JobProgressDialog::closeEvent( QCloseEvent* e ) 0277 { 0278 if (m_closeButton->isVisible()) { 0279 QDialog::closeEvent(e); 0280 k3bappcore->k3bMainWindow()->show(); 0281 0282 if (!m_plainCaption.isEmpty()) 0283 k3bappcore->k3bMainWindow()->setPlainCaption(m_plainCaption); 0284 0285 accept(); 0286 } else 0287 e->ignore(); 0288 } 0289 0290 0291 void K3b::JobProgressDialog::slotProcessedSize( int processed, int size ) 0292 { 0293 //#if KDE_IS_VERSION( 4, 3, 80 ) 0294 m_labelProcessedSize->setText( i18nc( "%1 and %2 are byte sizes formatted via KFormat::formatByteSize", 0295 "%1 of %2", 0296 KFormat().formatByteSize( ( double )( ( qulonglong )processed*1024ULL*1024ULL ), 0297 1, 0298 KFormat::DefaultBinaryDialect, 0299 KFormat::UnitMegaByte ), 0300 KFormat().formatByteSize( ( double )( ( qulonglong )size*1024ULL*1024ULL ), 0301 1, 0302 KFormat::DefaultBinaryDialect, 0303 KFormat::UnitMegaByte ) ) ); 0304 //#else 0305 // m_labelProcessedSize->setText( i18nc( "%1 and %2 are byte sizes formatted via KFormat::formatByteSize", 0306 // "%1 of %2", 0307 // KFormat().formatByteSize( ( double )( ( qulonglong )processed*1024ULL*1024ULL ) ), 0308 // KFormat().formatByteSize( ( double )( ( qulonglong )size*1024ULL*1024ULL ) ) ) ); 0309 //#endif 0310 } 0311 0312 0313 void K3b::JobProgressDialog::slotProcessedSubSize( int processedTrackSize, int trackSize ) 0314 { 0315 //#if KDE_IS_VERSION( 4, 3, 80 ) 0316 m_labelSubProcessedSize->setText( i18nc( "%1 and %2 are byte sizes formatted via KFormat::formatByteSize", 0317 "%1 of %2", 0318 KFormat().formatByteSize( ( double )( ( qulonglong )processedTrackSize*1024ULL*1024ULL ), 0319 1, 0320 KFormat::DefaultBinaryDialect, 0321 KFormat::UnitMegaByte ), 0322 KFormat().formatByteSize( ( double )( ( qulonglong )trackSize*1024ULL*1024ULL ), 0323 1, 0324 KFormat::DefaultBinaryDialect, 0325 KFormat::UnitMegaByte ) ) ); 0326 //#else 0327 // m_labelSubProcessedSize->setText( i18nc( "%1 and %2 are byte sizes formatted via KFormat::formatByteSize", 0328 // "%1 of %2", 0329 // KFormat().formatByteSize( ( double )( ( qulonglong )processedTrackSize*1024ULL*1024ULL ) ), 0330 // KFormat().formatByteSize( ( double )( ( qulonglong )trackSize*1024ULL*1024ULL ) ) ) ); 0331 //#endif 0332 } 0333 0334 0335 void K3b::JobProgressDialog::slotInfoMessage( const QString& infoString, int type ) 0336 { 0337 QTreeWidgetItem* currentInfoItem = new QTreeWidgetItem( d->viewInfo ); 0338 currentInfoItem->setText( 0, infoString ); 0339 0340 // set the icon 0341 switch( type ) { 0342 case K3b::Job::MessageError: 0343 currentInfoItem->setIcon( 0, QIcon::fromTheme( "dialog-error" ) ); 0344 break; 0345 case K3b::Job::MessageWarning: 0346 currentInfoItem->setIcon( 0, QIcon::fromTheme( "dialog-warning" ) ); 0347 break; 0348 case K3b::Job::MessageSuccess: 0349 currentInfoItem->setIcon( 0, QIcon::fromTheme( "dialog-ok" ) ); 0350 break; 0351 case K3b::Job::MessageInfo: 0352 default: 0353 currentInfoItem->setIcon( 0, QIcon::fromTheme( "dialog-information" ) ); 0354 } 0355 0356 d->viewInfo->scrollToItem( currentInfoItem, QAbstractItemView::EnsureVisible ); 0357 } 0358 0359 0360 void K3b::JobProgressDialog::slotFinished( bool success ) 0361 { 0362 qDebug() << "received finished signal!"; 0363 0364 m_logFile.close(); 0365 0366 const KColorScheme colorScheme( QPalette::Normal, KColorScheme::Window ); 0367 QPalette taskPalette( m_labelTask->palette() ); 0368 0369 // Only show elapsed time at the end of the task 0370 // setVisible( false ) would move elapsed time one line up ... 0371 m_labelRemainingTime->setText( "" ); 0372 m_labelElapsedTime->setText(i18nc("@info %1 is a duration formatted", 0373 "Elapsed time: %1", QTime::fromMSecsSinceStartOfDay(m_timer.elapsed()).toString("hh:mm:ss"))); 0374 m_timer.invalidate(); 0375 0376 if( success ) { 0377 m_pixLabel->setThemePixmap( K3b::Theme::PROGRESS_SUCCESS ); 0378 0379 taskPalette.setColor( QPalette::WindowText, 0380 colorScheme.foreground( KColorScheme::PositiveText ).color() ); 0381 0382 m_labelTask->setText( i18n("Success.") ); 0383 m_labelSubTask->setText( QString() ); 0384 0385 m_progressPercent->setValue(100); 0386 m_progressSubPercent->setValue(100); 0387 slotProgress(100); 0388 0389 KNotification::event("SuccessfullyFinished", i18n("Successfully finished.")); 0390 } 0391 else { 0392 m_pixLabel->setThemePixmap( K3b::Theme::PROGRESS_FAIL ); 0393 0394 taskPalette.setColor( QPalette::WindowText, 0395 colorScheme.foreground( KColorScheme::NegativeText ).color() ); 0396 0397 if( m_bCanceled ) { 0398 m_labelTask->setText( i18n("Canceled.") ); 0399 } 0400 else { 0401 m_labelTask->setText( i18n("Error.") ); 0402 } 0403 KNotification::event("FinishedWithError", i18n("Finished with errors")); 0404 } 0405 0406 m_labelTask->setPalette( taskPalette ); 0407 0408 m_cancelButton->hide(); 0409 m_showDbgOutButton->show(); 0410 m_closeButton->show(); 0411 } 0412 0413 0414 void K3b::JobProgressDialog::slotCanceled() 0415 { 0416 qDebug(); 0417 m_bCanceled = true; 0418 } 0419 0420 0421 void K3b::JobProgressDialog::setJob( K3b::Job* job ) 0422 { 0423 qDebug(); 0424 m_bCanceled = false; 0425 0426 // clear everything 0427 m_cancelButton->show(); 0428 m_showDbgOutButton->hide(); 0429 m_closeButton->hide(); 0430 m_closeButton->setEnabled( true ); 0431 0432 d->viewInfo->clear(); 0433 m_progressPercent->setValue(0); 0434 m_progressSubPercent->setValue(0); 0435 m_labelTask->setText(""); 0436 m_labelSubTask->setText(""); 0437 m_labelProcessedSize->setText(""); 0438 m_labelSubProcessedSize->setText(""); 0439 if (k3bappcore) 0440 m_labelTask->setPalette( k3bappcore->themeManager()->currentTheme()->palette() ); 0441 m_logCache.clear(); 0442 0443 // disconnect from the former job 0444 if( m_job ) 0445 disconnect( m_job ); 0446 m_job = job; 0447 0448 if( job ) { 0449 qDebug() << "connecting"; 0450 connect( job, SIGNAL(infoMessage(QString,int)), this, SLOT(slotInfoMessage(QString,int)) ); 0451 0452 connect( job, SIGNAL(percent(int)), m_progressPercent, SLOT(setValue(int)) ); 0453 connect( job, SIGNAL(percent(int)), this, SLOT(slotProgress(int)) ); 0454 connect( job, SIGNAL(subPercent(int)), m_progressSubPercent, SLOT(setValue(int)) ); 0455 0456 connect( job, SIGNAL(processedSubSize(int,int)), this, SLOT(slotProcessedSubSize(int,int)) ); 0457 connect( job, SIGNAL(processedSize(int,int)), this, SLOT(slotProcessedSize(int,int)) ); 0458 0459 connect( job, SIGNAL(newTask(QString)), this, SLOT(slotNewTask(QString)) ); 0460 connect( job, SIGNAL(newSubTask(QString)), this, SLOT(slotNewSubTask(QString)) ); 0461 connect( job, SIGNAL(started()), this, SLOT(slotStarted()) ); 0462 connect( job, SIGNAL(finished(bool)), this, SLOT(slotFinished(bool)) ); 0463 connect( job, SIGNAL(canceled()), this, SLOT(slotCanceled()) ); 0464 0465 connect( job, SIGNAL(debuggingOutput(QString,QString)), 0466 this, SLOT(slotDebuggingOutput(QString,QString)) ); 0467 0468 m_labelJob->setText( m_job->jobDescription() ); 0469 m_labelJobDetails->setText( m_job->jobDetails() ); 0470 0471 setWindowTitle( m_job->jobDescription() ); 0472 0473 if (KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("General Options")).readEntry("Show progress OSD", false)) { 0474 KIO::getJobTracker()->registerJob(new KJobBridge(*job)); 0475 } 0476 } 0477 } 0478 0479 0480 void K3b::JobProgressDialog::reject() 0481 { 0482 if( m_job && m_job->active() ) { 0483 if( KMessageBox::questionTwoActions( this, 0484 i18n("Do you really want to cancel?"), 0485 i18n("Cancel Confirmation"), 0486 KStandardGuiItem::ok(), 0487 KStandardGuiItem::cancel()) == KMessageBox::PrimaryAction ) { 0488 if( m_job ) { 0489 m_job->cancel(); 0490 m_closeButton->setEnabled(true); 0491 } 0492 } 0493 } 0494 } 0495 0496 0497 void K3b::JobProgressDialog::slotNewSubTask(const QString& name) 0498 { 0499 qDebug() << name; 0500 m_labelSubTask->setText(name); 0501 m_labelSubProcessedSize->setText(""); 0502 m_progressSubPercent->setValue(0); 0503 } 0504 0505 0506 void K3b::JobProgressDialog::slotNewTask(const QString& name) 0507 { 0508 qDebug() << name; 0509 m_labelTask->setText( name ); 0510 } 0511 0512 0513 void K3b::JobProgressDialog::slotStarted() 0514 { 0515 qDebug(); 0516 d->lastProgress = 0; 0517 m_lastProgressUpdateTime = 0; 0518 m_timer.start(); 0519 m_plainCaption = k3bappcore->k3bMainWindow()->windowTitle(); 0520 0521 m_logFile.open(); 0522 } 0523 0524 0525 void K3b::JobProgressDialog::slotDebuggingOutput( const QString& type, const QString& output ) 0526 { 0527 m_logCache.addOutput( type, output ); 0528 m_logFile.addOutput( type, output ); 0529 } 0530 0531 0532 void K3b::JobProgressDialog::slotShowDebuggingOutput() 0533 { 0534 K3b::DebuggingOutputDialog debugWidget( this ); 0535 debugWidget.setOutput( m_logCache.toString() ); 0536 debugWidget.exec(); 0537 } 0538 0539 0540 void K3b::JobProgressDialog::slotProgress( int percent ) 0541 { 0542 if (percent > d->lastProgress) { 0543 d->lastProgress = percent; 0544 m_plainCaption.remove(QRegularExpression("\\(.+?\\) ")); 0545 k3bappcore->k3bMainWindow()->setPlainCaption(QString("(%1%) %2").arg(percent).arg(m_plainCaption)); 0546 0547 setWindowTitle(QString("(%1%) %2").arg(percent).arg(m_job->jobDescription())); 0548 } 0549 0550 if (m_timer.isValid()) { 0551 qint64 elapsed = m_timer.elapsed(); 0552 m_labelElapsedTime->setText(i18nc("@info %1 is a duration formatted", 0553 "Elapsed time: %1", QTime::fromMSecsSinceStartOfDay(elapsed).toString("hh:mm:ss"))); 0554 // Update "Remaining time" max. each second (1000 ms) 0555 if (elapsed - m_lastProgressUpdateTime > 999) { 0556 m_labelRemainingTime->setText(i18nc("@info %1 is a duration formatted", 0557 "Remaining: %1", QTime::fromMSecsSinceStartOfDay( 0558 (d->lastProgress > 0 && d->lastProgress < 100) ? elapsed * (100 - d->lastProgress) / d->lastProgress : 0).toString("hh:mm:ss"))); 0559 m_lastProgressUpdateTime = elapsed; 0560 } 0561 } 0562 } 0563 0564 0565 void K3b::JobProgressDialog::keyPressEvent( QKeyEvent* e ) 0566 { 0567 qDebug() << e; 0568 0569 switch ( e->key() ) { 0570 case Qt::Key_Enter: 0571 case Qt::Key_Return: 0572 // if the process finished this closes the dialog 0573 if( m_closeButton->isVisible() ) 0574 accept(); 0575 break; 0576 0577 case Qt::Key_Escape: 0578 // simulate button clicks 0579 if( m_job && m_job->active() ) 0580 reject(); 0581 else if( m_closeButton->isVisible() ) 0582 accept(); 0583 break; 0584 0585 default: 0586 QDialog::keyPressEvent( e ); 0587 break; 0588 } 0589 } 0590 0591 0592 QSize K3b::JobProgressDialog::sizeHint() const 0593 { 0594 QSize s = QDialog::sizeHint(); 0595 if( s.width() < s.height() ) 0596 s.setWidth( s.height() ); 0597 return s; 0598 } 0599 0600 0601 int K3b::JobProgressDialog::startJob( K3b::Job* job ) 0602 { 0603 if( job ) { 0604 setJob( job ); 0605 new JobInterface( job ); 0606 } 0607 else if( !m_job ) { 0608 qCritical() << "(K3b::JobProgressDialog) null job!" << Qt::endl; 0609 return -1; 0610 } 0611 0612 QMetaObject::invokeMethod( m_job, "start", Qt::QueuedConnection ); 0613 return exec(); 0614 } 0615 0616 0617 K3b::Device::MediaType K3b::JobProgressDialog::waitForMedium( K3b::Device::Device* device, 0618 Device::MediaStates mediaState, 0619 Device::MediaTypes mediaType, 0620 const K3b::Msf& minMediaSize, 0621 const QString& message ) 0622 { 0623 return K3b::EmptyDiscWaiter::wait( device, mediaState, mediaType, minMediaSize, message, this ); 0624 } 0625 0626 0627 bool K3b::JobProgressDialog::questionYesNo( const QString& text, 0628 const QString& caption, 0629 const KGuiItem& buttonYes, 0630 const KGuiItem& buttonNo ) 0631 { 0632 return ( KMessageBox::questionTwoActions( this, 0633 text, 0634 caption, 0635 buttonYes, 0636 buttonNo ) == KMessageBox::PrimaryAction ); 0637 } 0638 0639 0640 void K3b::JobProgressDialog::blockingInformation( const QString& text, 0641 const QString& caption ) 0642 { 0643 KMessageBox::information( this, text, caption ); 0644 } 0645 0646 0647 void K3b::JobProgressDialog::slotThemeChanged() 0648 { 0649 if (k3bappcore == Q_NULLPTR) 0650 return; 0651 if( K3b::Theme* theme = k3bappcore->themeManager()->currentTheme() ) { 0652 d->progressHeaderFrame->setPalette( theme->palette() ); 0653 d->headerFrame->setPalette( theme->palette() ); 0654 } 0655 } 0656 0657 #include "moc_k3bjobprogressdialog.cpp"