summaryrefslogtreecommitdiffstats
path: root/src/k3bjobinterface.cpp
blob: 60e4436d90a4e3f3f4d507af3fc15640ed275610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* 
 *
 * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
 * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * See the file "COPYING" for the exact licensing terms.
 */

#include "k3bjobinterface.h"

#include <k3bjob.h>

#include <qcstring.h>
#include <qdatastream.h>


K3bJobInterface::K3bJobInterface( QObject* parent )
  : QObject( parent ),
    DCOPObject( "K3bJobInterface" ),
    m_job( 0 )
{
}


void K3bJobInterface::setJob( K3bJob* job )
{
  if( m_job )
    m_job->disconnect( this );

  m_job = job;
  m_lastProgress = m_lastSubProgress = 0;

  if( m_job ) {
    connect( m_job, SIGNAL(newTask(const QString&)), this, SLOT(slotNewTask(const QString&)) );
    connect( m_job, SIGNAL(newSubTask(const QString&)), this, SLOT(slotNewSubTask(const QString&)) );
    connect( m_job, SIGNAL(infoMessage(const QString&, int)), this, SLOT(slotInfoMessage(const QString&, int)) );
    connect( m_job, SIGNAL(finished(bool)), this, SLOT(slotFinished(bool)) );
    connect( m_job, SIGNAL(started()), this, SLOT(slotStarted()) );
    connect( m_job, SIGNAL(canceled()), this, SLOT(slotCanceled()) );
    connect( m_job, SIGNAL(percent(int)), this, SLOT(slotProgress(int)) );
    connect( m_job, SIGNAL(subPercent(int)), this, SLOT(slotSubProgress(int)) );
    connect( m_job, SIGNAL(nextTrack(int, int)), this, SLOT(slotNextTrack(int, int)) );

    if( m_job->inherits( "K3bBurnJob" ) ) {
      connect( m_job, SIGNAL(bufferStatus(int)), this, SLOT(slotBuffer(int)) );
      connect( m_job, SIGNAL(deviceBuffer(int)), this, SLOT(slotDeviceBuffer(int)) );
    }

    connect( m_job, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
  }
}


bool K3bJobInterface::jobRunning() const
{
  return ( m_job && m_job->active() );
}


QString K3bJobInterface::jobDescription() const
{
  if( m_job )
    return m_job->jobDescription();
  else
    return QString::null;
}


QString K3bJobInterface::jobDetails() const
{
  if( m_job )
    return m_job->jobDetails();
  else
    return QString::null;
}


void K3bJobInterface::slotStarted()
{
  m_lastProgress = m_lastSubProgress = 0;
  emitDCOPSignal( "started()", QByteArray() );
}


void K3bJobInterface::slotCanceled()
{
  emitDCOPSignal( "canceled()", QByteArray() );
}


void K3bJobInterface::slotFinished( bool success )
{
  QByteArray params;
  QDataStream stream(params, IO_WriteOnly);
  stream << success;
  emitDCOPSignal( "finished(bool)", params );
}


void K3bJobInterface::slotInfoMessage( const QString& message, int type )
{
  QByteArray params;
  QDataStream stream(params, IO_WriteOnly);
  stream << message << type;
  emitDCOPSignal( "infoMessage(QString)", params );
}


void K3bJobInterface::slotProgress( int val )
{
  if( m_lastProgress != val ) {
    m_lastProgress = val;
    QByteArray params;
    QDataStream stream(params, IO_WriteOnly);
    stream << val;
    emitDCOPSignal( "progress(int)", params );
  }
}


void K3bJobInterface::slotSubProgress( int val )
{
  if( m_lastSubProgress != val ) {
    m_lastSubProgress = val;
    QByteArray params;
    QDataStream stream(params, IO_WriteOnly);
    stream << val;
    emitDCOPSignal( "subProgress(int)", params );
  }
}


void K3bJobInterface::slotNewTask( const QString& task )
{
  QByteArray params;
  QDataStream stream(params, IO_WriteOnly);
  stream << task;
  emitDCOPSignal( "newTask(QString)", params );
}


void K3bJobInterface::slotNewSubTask( const QString& task )
{
  QByteArray params;
  QDataStream stream(params, IO_WriteOnly);
  stream << task;
  emitDCOPSignal( "newSubTask(QString)", params );
}


void K3bJobInterface::slotBuffer( int val )
{
  QByteArray params;
  QDataStream stream(params, IO_WriteOnly);
  stream << val;
  emitDCOPSignal( "buffer(int)", params );
}


void K3bJobInterface::slotDeviceBuffer( int val )
{
  QByteArray params;
  QDataStream stream(params, IO_WriteOnly);
  stream << val;
  emitDCOPSignal( "deviceBuffer(int)", params );
}


void K3bJobInterface::slotNextTrack( int track, int numTracks )
{
  QByteArray params;
  QDataStream stream(params, IO_WriteOnly);
  stream << track << numTracks;
  emitDCOPSignal( "nextTrack(int,int)", params );
}


void K3bJobInterface::slotDestroyed()
{
  m_job = 0;
}

#include "k3bjobinterface.moc"