summaryrefslogtreecommitdiffstats
path: root/libk3b/projects/audiocd/k3baudiojobtempdata.cpp
blob: 697a9f554f2302de8a85da247e8b77f5c678290c (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
/* 
 *
 * $Id: k3baudiojobtempdata.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 "k3baudiojobtempdata.h"
#include "k3baudiodoc.h"
#include "k3baudiotrack.h"
#include <k3bglobals.h>
#include <k3bversion.h>
#include <k3bmsf.h>
#include <k3bcore.h>

#include <tqfile.h>
#include <textstream.h>
#include <tqvaluevector.h>

#include <kdebug.h>


class K3bAudioJobTempData::Private
{
public:
  Private( K3bAudioDoc* _doc ) 
    : doc(_doc) {
  }

  TQValueVector<TQString> bufferFiles;
  TQValueVector<TQString> infFiles;
  TQString tocFile;

  K3bAudioDoc* doc;
};


K3bAudioJobTempData::K3bAudioJobTempData( K3bAudioDoc* doc, TQObject* parent, const char* name )
  : TQObject( parent, name )
{
  d = new Private( doc );
}


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


const TQString& K3bAudioJobTempData::bufferFileName( int track )
{
  if( (int)d->bufferFiles.count() < track )
    prepareTempFileNames();
  return d->bufferFiles.at(track-1);
}

const TQString& K3bAudioJobTempData::bufferFileName( K3bAudioTrack* track )
{
  return bufferFileName( track->trackNumber() );
}


const TQString& K3bAudioJobTempData::tocFileName()
{
  if( d->tocFile.isEmpty() )
    prepareTempFileNames();
  return d->tocFile;
}


const TQString& K3bAudioJobTempData::infFileName( int track )
{
  if( (int)d->infFiles.count() < track )
    prepareTempFileNames();
  return d->infFiles.at( track - 1 );
}

const TQString& K3bAudioJobTempData::infFileName( K3bAudioTrack* track )
{
  return infFileName( track->trackNumber() );
}


K3bAudioDoc* K3bAudioJobTempData::doc() const
{
  return d->doc;
}


void K3bAudioJobTempData::prepareTempFileNames( const TQString& path ) 
{
  d->bufferFiles.clear();
  d->infFiles.clear();

  TQString prefix = K3b::findUniqueFilePrefix( "k3b_audio_", path ) + "_";

  for( int i = 0; i < d->doc->numOfTracks(); i++ ) {
    d->bufferFiles.append( prefix + TQString::number( i+1 ).rightJustify( 2, '0' ) + ".wav" );
    d->infFiles.append( prefix + TQString::number( i+1 ).rightJustify( 2, '0' ) + ".inf" );
  }

  d->tocFile = prefix + ".toc";
}


void K3bAudioJobTempData::cleanup()
{
  for( uint i = 0; i < d->infFiles.count(); ++i ) {
    if( TQFile::exists( d->infFiles[i] ) )
      TQFile::remove(  d->infFiles[i] );
  }

  for( uint i = 0; i < d->bufferFiles.count(); ++i ) {
    if( TQFile::exists( d->bufferFiles[i] ) )
      TQFile::remove(  d->bufferFiles[i] );
  }

  if( TQFile::exists( d->tocFile ) )
    TQFile::remove(  d->tocFile );
}


#include "k3baudiojobtempdata.moc"