~schumski-deactivatedaccount-deactivatedaccount/k3b/master

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
/*
 *
 * Copyright (C) 2003-2009 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2009 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 "k3btoc.h"
#include <QDebug>
#include <QString>



K3b::Device::Toc::Toc()
    : QList<K3b::Device::Track>()
{
}


K3b::Device::Toc::Toc( const Toc& toc )
    : QList<K3b::Device::Track>( toc )
{
    m_mcn = toc.m_mcn;
}


K3b::Device::Toc::~Toc()
{
}


K3b::Device::Toc& K3b::Device::Toc::operator=( const Toc& toc )
{
    if( &toc == this ) return *this;

    m_mcn = toc.m_mcn;

    QList<K3b::Device::Track>::operator=( toc );

    return *this;
}


K3b::Msf K3b::Device::Toc::firstSector() const
{
    return isEmpty() ? K3b::Msf() : first().firstSector();
}


K3b::Msf K3b::Device::Toc::lastSector() const
{
    if( isEmpty() )
        return 0;
    // the last track's last sector should be the last sector of the entire cd
    return last().lastSector();
}


K3b::Msf K3b::Device::Toc::length() const
{
    // +1 since the last sector is included
    return lastSector() - firstSector() + 1;
}


unsigned int K3b::Device::Toc::discId() const
{
    // calculate cddb-id
    unsigned int id = 0;
    for( Toc::const_iterator it = constBegin(); it != constEnd(); ++it ) {
        unsigned int n = (*it).firstSector().lba() + 150;
        n /= 75;
        while( n > 0 ) {
            id += n % 10;
            n /= 10;
        }
    }
    unsigned int l = length().lba();
    if ( !empty() )
        l -= first().firstSector().lba();
    l /= 75;
    id = ( ( id % 0xff ) << 24 ) | ( l << 8 ) | count();

    return id;
}


K3b::Device::ContentsType K3b::Device::Toc::contentType() const
{
    int audioCnt = 0, dataCnt = 0;
    for( Toc::const_iterator it = constBegin(); it != constEnd(); ++it ) {
        if( (*it).type() == K3b::Device::Track::TYPE_AUDIO )
            audioCnt++;
        else
            dataCnt++;
    }

    if( audioCnt + dataCnt == 0 )
        return K3b::Device::NONE;
    if( audioCnt == 0 )
        return K3b::Device::DATA;
    if( dataCnt == 0 )
        return K3b::Device::AUDIO;
    return K3b::Device::MIXED;
}


int K3b::Device::Toc::sessions() const
{
    if( isEmpty() )
        return 0;
    else if( last().session() == 0 )
        return 1; // default if unknown
    else
        return last().session();
}


QByteArray K3b::Device::Toc::mcn() const
{
    return m_mcn;
}


void K3b::Device::Toc::setMcn( const QByteArray& mcn )
{
    m_mcn = mcn;
}


void K3b::Device::Toc::clear()
{
    QList<Track>::clear();
    m_mcn.resize( 0 );
}


bool K3b::Device::Toc::operator==( const Toc& other ) const
{
    return( QList<Track>::operator==( other ) );
}


bool K3b::Device::Toc::operator!=( const Toc& other ) const
{
    return( QList<Track>::operator!=( other ) );
}


QDebug operator<<( QDebug s, const K3b::Device::Toc& toc )
{
    s.nospace() << toc.count() << " in " << toc.sessions() << " sessions";
    int sessionN = 0;
    int trackN = 0;
    for( K3b::Device::Toc::const_iterator it = toc.constBegin(); it != toc.constEnd(); ++it ) {
        ++trackN;
        if( sessionN != it->session() ) {
            sessionN = it->session();
            s.nospace() << "Session Number " << sessionN;
        }
        s.nospace() << "  Track " << trackN << *it;
    }
    return s;
}