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
|
/*
*
* $Id: k3baudiocdtrackdrag.cpp 619556 2007-01-03 17:38:12Z trueg $
* Copyright (C) 2005 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 "k3baudiocdtrackdrag.h"
#include <k3bdevice.h>
#include <k3bdevicemanager.h>
#include <k3btoc.h>
#include <k3btrack.h>
#include <k3bcore.h>
#include <tqdatastream.h>
#include <tqcstring.h>
// FIXME: multiple tracks
K3bAudioCdTrackDrag::K3bAudioCdTrackDrag( const K3bDevice::Toc& toc, const TQValueList<int>& cdTrackNumbers,
const K3bCddbResultEntry& cddb,
K3bDevice::Device* lastDev, TQWidget* dragSource, const char* name )
: TQStoredDrag( "k3b/audio_track_drag", dragSource, name ),
m_toc(toc),
m_cdTrackNumbers(cdTrackNumbers),
m_cddb(cddb),
m_device(lastDev)
{
TQByteArray data;
TQDataStream s( data, IO_WriteOnly );
s << (unsigned int)toc.count();
for( K3bDevice::Toc::const_iterator it = toc.begin(); it != toc.end(); ++it ) {
const K3bDevice::Track& track = *it;
s << track.firstSector().lba() << track.lastSector().lba();
}
TQTextStream t( s.device() );
t << cddb.cdArtist << endl
<< cddb.cdTitle << endl;
for( unsigned int i = 0; i < toc.count(); ++i ) {
t << cddb.artists[i] << endl
<< cddb.titles[i] << endl;
}
s << (unsigned int)cdTrackNumbers.count();
for( TQValueList<int>::const_iterator it = cdTrackNumbers.begin();
it != cdTrackNumbers.end(); ++it )
s << *it;
if( lastDev )
t << lastDev->blockDeviceName() << endl;
else
t << endl;
// TODO: the rest
setEncodedData( data );
}
bool K3bAudioCdTrackDrag::decode( const TQMimeSource* e,
K3bDevice::Toc& toc, TQValueList<int>& trackNumbers,
K3bCddbResultEntry& cddb, K3bDevice::Device** dev )
{
TQByteArray data = e->encodedData( "k3b/audio_track_drag" );
TQDataStream s( data, IO_ReadOnly );
unsigned int trackCnt;
s >> trackCnt;
for( unsigned int i = 0; i < trackCnt; ++i ) {
int fs, ls;
s >> fs;
s >> ls;
toc.append( K3bDevice::Track( fs, ls, K3bDevice::Track::AUDIO ) );
}
TQTextStream t( s.device() );
cddb.artists.clear();
cddb.titles.clear();
cddb.cdArtist = t.readLine();
cddb.cdTitle = t.readLine();
for( unsigned int i = 0; i < trackCnt; ++i ) {
cddb.artists.append( t.readLine() );
cddb.titles.append( t.readLine() );
}
s >> trackCnt;
trackNumbers.clear();
for( unsigned int i = 0; i < trackCnt; ++i ) {
int trackNumber = 0;
s >> trackNumber;
trackNumbers.append( trackNumber );
}
TQString devName = t.readLine();
if( dev && !devName.isEmpty() )
*dev = k3bcore->deviceManager()->findDevice( devName );
return true;
}
|