1 /*
2     SPDX-FileCopyrightText: 2010 Michal Malek <michalm@jabster.pl>
3     SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "k3bjobinterface.h"
9 #include "k3bjobinterfaceadaptor.h"
10 #include "k3bjob.h"
11 
12 #include <QDBusConnection>
13 #include <QDataStream>
14 
15 namespace K3b {
16 
17 
JobInterface(Job * job)18 JobInterface::JobInterface( Job* job )
19 :
20     QObject( job ),
21     m_job( job ),
22     m_lastProgress( 0 ),
23     m_lastSubProgress( 0 )
24 {
25     if( m_job ) {
26         connect( m_job, SIGNAL(newTask(QString)), this, SIGNAL(newTask(QString)) );
27         connect( m_job, SIGNAL(newSubTask(QString)), this, SIGNAL(newSubTask(QString)) );
28         connect( m_job, SIGNAL(infoMessage(QString,int)), this, SIGNAL(infoMessage(QString,int)) );
29         connect( m_job, SIGNAL(finished(bool)), this, SIGNAL(finished(bool)) );
30         connect( m_job, SIGNAL(started()), this, SIGNAL(started()) );
31         connect( m_job, SIGNAL(canceled()), this, SIGNAL(canceled()) );
32         connect( m_job, SIGNAL(percent(int)), this, SLOT(slotProgress(int)) );
33         connect( m_job, SIGNAL(subPercent(int)), this, SLOT(slotSubProgress(int)) );
34         connect( m_job, SIGNAL(nextTrack(int,int)), this, SIGNAL(nextTrack(int,int)) );
35 
36         if( m_job->inherits( "K3b::BurnJob" ) ) {
37             connect( m_job, SIGNAL(bufferStatus(int)), this, SIGNAL(buffer(int)) );
38             connect( m_job, SIGNAL(deviceBuffer(int)), this, SIGNAL(deviceBuffer(int)) );
39         }
40     }
41 
42     new K3bJobInterfaceAdaptor( this );
43     QDBusConnection::sessionBus().registerObject( "/job", this );
44 }
45 
46 
~JobInterface()47 JobInterface::~JobInterface()
48 {
49     QDBusConnection::sessionBus().unregisterObject( "/job" );
50 }
51 
52 
jobRunning() const53 bool JobInterface::jobRunning() const
54 {
55     return ( m_job && m_job->active() );
56 }
57 
58 
jobDescription() const59 QString JobInterface::jobDescription() const
60 {
61     if( m_job )
62         return m_job->jobDescription();
63     else
64         return QString();
65 }
66 
67 
jobDetails() const68 QString JobInterface::jobDetails() const
69 {
70     if( m_job )
71         return m_job->jobDetails();
72     else
73         return QString();
74 }
75 
76 
slotProgress(int val)77 void JobInterface::slotProgress( int val )
78 {
79     if( m_lastProgress != val )
80         Q_EMIT progress( val );
81 }
82 
83 
slotSubProgress(int val)84 void JobInterface::slotSubProgress( int val )
85 {
86     if( m_lastSubProgress != val )
87         Q_EMIT subProgress( val );
88 }
89 
90 } // namespace K3b
91 
92 
93