summaryrefslogtreecommitdiffstats
path: root/libk3b/core/k3bjob.cpp
blob: 0e169b1bef17c2211fc1dcb9118ca2166ac964bf (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* 
 *
 * $Id: k3bjob.cpp 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2003 Sebastian Trueg <[email protected]>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <[email protected]>
 *
 * 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 "k3bjob.h"
#include <k3bglobals.h>
#include <k3bcore.h>

#include <tdelocale.h>
#include <kprocess.h>

#include <tqstringlist.h>
#include <kdebug.h>


class K3bJob::Private
{
public:
};


const char* K3bJob::DEFAULT_SIGNAL_CONNECTION = "K3bJobDefault";


K3bJob::K3bJob( K3bJobHandler* handler, TQObject* parent, const char* name )
  : TQObject( parent, name ),
    m_jobHandler( handler ),
    m_canceled(false),
    m_active(false)
{
  connect( this, TQT_SIGNAL(canceled()),
	   this, TQT_SLOT(slotCanceled()) );
}

K3bJob::~K3bJob()
{
  //
  // Normally a job (or the user of a job should take care of this
  // but we do this here for security reasons.
  //
  if( m_active )
    jobFinished( false );
}


void K3bJob::setJobHandler( K3bJobHandler* jh )
{
  m_jobHandler = jh;
}


void K3bJob::jobStarted()
{
  m_canceled = false;
  m_active = true;

  if( jobHandler() && jobHandler()->isJob() )
    static_cast<K3bJob*>(jobHandler())->registerSubJob( this );
  else
    k3bcore->registerJob( this );

  emit started();
}


void K3bJob::jobFinished( bool success )
{
  m_active = false;

  if( jobHandler() && jobHandler()->isJob() )
    static_cast<K3bJob*>(jobHandler())->unregisterSubJob( this );
  else
    k3bcore->unregisterJob( this );

  emit finished( success );
}


void K3bJob::slotCanceled()
{
  m_canceled = true;
}


int K3bJob::waitForMedia( K3bDevice::Device* device,
			  int mediaState,
			  int mediaType,
			  const TQString& message )
{
  // TODO: What about:   emit newSubTask( i18n("Waiting for media") );
  return m_jobHandler->waitForMedia( device, mediaState, mediaType, message );
}


bool K3bJob::questionYesNo( const TQString& text,
			    const TQString& caption,
			    const TQString& yesText,
			    const TQString& noText )
{
  return m_jobHandler->questionYesNo( text, caption, yesText, noText );
}


void K3bJob::blockingInformation( const TQString& text,
				  const TQString& caption )
{
  return m_jobHandler->blockingInformation( text, caption );
}


void K3bJob::connectSubJob( K3bJob* subJob,
			    const char* finishedSlot,
			    bool connectProgress,
			    const char* progressSlot,
			    const char* subProgressSlot,
			    const char* processedSizeSlot,
			    const char* processedSubSizeSlot )
{
  connect( subJob, TQT_SIGNAL(newTask(const TQString&)), this, TQT_SIGNAL(newSubTask(const TQString&)) );
  connect( subJob, TQT_SIGNAL(newSubTask(const TQString&)), this, TQT_SLOT(slotNewSubTask(const TQString&)) );
  connect( subJob, TQT_SIGNAL(debuggingOutput(const TQString&, const TQString&)),
	   this, TQT_SIGNAL(debuggingOutput(const TQString&, const TQString&)) );
  connect( subJob, TQT_SIGNAL(infoMessage(const TQString&, int)),
	   this, TQT_SIGNAL(infoMessage(const TQString&, int)) );
  connect( subJob, TQT_SIGNAL(finished(bool)), this, finishedSlot );

  if( connectProgress ) {
    connect( subJob, TQT_SIGNAL(percent(int)), 
	       this, progressSlot != 0 ? progressSlot : TQT_SIGNAL(subPercent(int)) );
    if( subProgressSlot )
      connect( subJob, TQT_SIGNAL(subPercent(int)), this, subProgressSlot );
    connect( subJob, TQT_SIGNAL(processedSize(int, int)), 
	     this, processedSizeSlot != 0 ? processedSizeSlot : TQT_SIGNAL(processedSubSize(int, int)) );
    if( processedSubSizeSlot )
      connect( subJob, TQT_SIGNAL(processedSubSize(int, int)), this, processedSubSizeSlot );
  }
}


void K3bJob::connectSubJob( K3bJob* subJob,
			    const char* finishedSlot,
			    const char* newTaskSlot,
			    const char* newSubTaskSlot,
			    const char* progressSlot,
			    const char* subProgressSlot,
			    const char* processedSizeSlot,
			    const char* processedSubSizeSlot )
{
  // standard connections
  connect( subJob, TQT_SIGNAL(debuggingOutput(const TQString&, const TQString&)),
	   this, TQT_SIGNAL(debuggingOutput(const TQString&, const TQString&)) );
  connect( subJob, TQT_SIGNAL(infoMessage(const TQString&, int)),
	   this, TQT_SIGNAL(infoMessage(const TQString&, int)) );

  // task connections
  if( newTaskSlot == DEFAULT_SIGNAL_CONNECTION )
    connect( subJob, TQT_SIGNAL(newTask(const TQString&)), this, TQT_SIGNAL(newSubTask(const TQString&)) );
  else if( newTaskSlot )
    connect( subJob, TQT_SIGNAL(newTask(const TQString&)), this, newTaskSlot );

  if( newSubTaskSlot == DEFAULT_SIGNAL_CONNECTION )
    connect( subJob, TQT_SIGNAL(newSubTask(const TQString&)), this, TQT_SLOT(slotNewSubTask(const TQString&)) );
  else if( newSubTaskSlot )
    connect( subJob, TQT_SIGNAL(newSubTask(const TQString&)), this, newSubTaskSlot );

  if( finishedSlot && finishedSlot != DEFAULT_SIGNAL_CONNECTION )
    connect( subJob, TQT_SIGNAL(finished(bool)), this, finishedSlot );

  // progress
  if( progressSlot == DEFAULT_SIGNAL_CONNECTION )
    connect( subJob, TQT_SIGNAL(percent(int)), this, TQT_SIGNAL(subPercent(int)) );
  else if( progressSlot )
    connect( subJob, TQT_SIGNAL(percent(int)), this, progressSlot );

  if( subProgressSlot && subProgressSlot != DEFAULT_SIGNAL_CONNECTION )
    connect( subJob, TQT_SIGNAL(subPercent(int)), this, subProgressSlot );

  // processed size
  if( processedSizeSlot == DEFAULT_SIGNAL_CONNECTION )
    connect( subJob, TQT_SIGNAL(processedSize(int, int)), this, TQT_SIGNAL(processedSubSize(int, int)) );
  else if( processedSizeSlot )
    connect( subJob, TQT_SIGNAL(processedSize(int, int)), this, processedSizeSlot );

  if( processedSubSizeSlot && processedSubSizeSlot != DEFAULT_SIGNAL_CONNECTION )
    connect( subJob, TQT_SIGNAL(processedSubSize(int, int)), this, processedSubSizeSlot );
}


unsigned int K3bJob::numRunningSubJobs() const
{
  return m_runningSubJobs.count(); 
}


void K3bJob::slotNewSubTask( const TQString& str )
{
  emit infoMessage( str, INFO );
}


void K3bJob::registerSubJob( K3bJob* job )
{
  m_runningSubJobs.append( job );
}


void K3bJob::unregisterSubJob( K3bJob* job )
{
  m_runningSubJobs.removeRef( job );
}




class K3bBurnJob::Private
{
public:
};



K3bBurnJob::K3bBurnJob( K3bJobHandler* handler, TQObject* parent, const char* name )
  : K3bJob( handler, parent, name ),
    m_writeMethod( K3b::DEFAULT )
{
  d = new Private;
}


K3bBurnJob::~K3bBurnJob()
{
  delete d;
}


int K3bBurnJob::supportedWritingApps() const
{
  return K3b::DEFAULT | K3b::CDRDAO | K3b::CDRECORD;
}

#include "k3bjob.moc"