File indexing completed on 2024-04-21 04:49:10
0001 /* 0002 SPDX-FileCopyrightText: 2011 Michal Malek <michalm@jabster.pl> 0003 SPDX-FileCopyrightText: 1998-2011 Sebastian Trueg <trueg@k3b.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "k3bkjobbridge.h" 0009 #include "k3bjob.h" 0010 #include "k3b_i18n.h" 0011 0012 0013 namespace K3b 0014 { 0015 0016 class KJobBridge::Private 0017 { 0018 public: 0019 Private( Job& j ) 0020 : 0021 job( j ) 0022 { 0023 } 0024 0025 Job& job; 0026 }; 0027 0028 KJobBridge::KJobBridge( Job& job ) 0029 : d( new Private( job ) ) 0030 { 0031 connect( &d->job, SIGNAL(finished(bool)), this, SLOT(slotFinished(bool)) ); 0032 connect( &d->job, SIGNAL(infoMessage(QString,int)), this, SLOT(slotInfoMessage(QString,int)) ); 0033 connect( &d->job, SIGNAL(percent(int)), this, SLOT(slotPercent(int)) ); 0034 connect( &d->job, SIGNAL(processedSize(int,int)), this, SLOT(slotProcessedSize(int,int)) ); 0035 connect( &d->job, SIGNAL(newTask(QString)), this, SLOT(slotNewTask(QString)) ); 0036 0037 setCapabilities( Killable ); 0038 } 0039 0040 0041 KJobBridge::~KJobBridge() 0042 { 0043 } 0044 0045 0046 void KJobBridge::start() 0047 { 0048 d->job.start(); 0049 } 0050 0051 0052 bool KJobBridge::doKill() 0053 { 0054 d->job.cancel(); 0055 return true; 0056 } 0057 0058 0059 void KJobBridge::slotFinished( bool success ) 0060 { 0061 if( success ) 0062 setError( NoError ); 0063 else if( d->job.hasBeenCanceled() ) 0064 setError( KilledJobError ); 0065 else 0066 setError( UserDefinedError ); 0067 0068 emitResult(); 0069 } 0070 0071 0072 void KJobBridge::slotInfoMessage( const QString& message, int type ) 0073 { 0074 if( type == Job::MessageError ) 0075 setErrorText( message ); 0076 else if( type == Job::MessageWarning ) 0077 emit warning( this, message ); 0078 } 0079 0080 0081 void KJobBridge::slotPercent( int progress ) 0082 { 0083 setPercent( progress ); 0084 } 0085 0086 0087 void KJobBridge::slotProcessedSize( int processed, int size ) 0088 { 0089 setTotalAmount( Bytes, static_cast<qulonglong>( size ) * 1024ULL * 1024ULL ); 0090 setProcessedAmount( Bytes, static_cast<qulonglong>( processed ) * 1024ULL * 1024ULL ); 0091 } 0092 0093 0094 void KJobBridge::slotNewTask( const QString& task ) 0095 { 0096 if( !d->job.jobSource().isEmpty() && !d->job.jobTarget().isEmpty() ) { 0097 emit description( this, task, 0098 qMakePair( i18n( "Source" ), d->job.jobSource() ), 0099 qMakePair( i18n( "Target" ), d->job.jobTarget() ) ); 0100 } else { 0101 emit description( this, task ); 0102 } 0103 emit infoMessage( this, task ); 0104 } 0105 0106 } // namespace K3b 0107 0108 #include "moc_k3bkjobbridge.cpp"