diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-03 02:15:56 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-03 02:15:56 +0000 |
commit | 50b48aec6ddd451a6d1709c0942477b503457663 (patch) | |
tree | a9ece53ec06fd0a2819de7a2a6de997193566626 /libk3bdevice/k3btoc.cpp | |
download | k3b-50b48aec6ddd451a6d1709c0942477b503457663.tar.gz k3b-50b48aec6ddd451a6d1709c0942477b503457663.zip |
Added abandoned KDE3 version of K3B
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/k3b@1084400 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libk3bdevice/k3btoc.cpp')
-rw-r--r-- | libk3bdevice/k3btoc.cpp | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/libk3bdevice/k3btoc.cpp b/libk3bdevice/k3btoc.cpp new file mode 100644 index 0000000..570bc9e --- /dev/null +++ b/libk3bdevice/k3btoc.cpp @@ -0,0 +1,163 @@ +/* + * + * $Id: k3btoc.cpp 619556 2007-01-03 17:38:12Z trueg $ + * Copyright (C) 2003-2007 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 "k3btoc.h" +#include "k3bdebug.h" + +#include <qstring.h> + + +K3bDevice::Toc::Toc() + : QValueList<K3bDevice::Track>() +{ +} + + +K3bDevice::Toc::Toc( const Toc& toc ) + : QValueList<K3bDevice::Track>( toc ) +{ + m_firstSector = toc.firstSector(); +} + + +K3bDevice::Toc::~Toc() +{ +} + + +K3bDevice::Toc& K3bDevice::Toc::operator=( const Toc& toc ) +{ + if( &toc == this ) return *this; + + m_firstSector = toc.firstSector(); + + QValueList<K3bDevice::Track>::operator=( toc ); + + return *this; +} + + +const K3b::Msf& K3bDevice::Toc::firstSector() const +{ + return m_firstSector; +} + + +K3b::Msf K3bDevice::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 K3bDevice::Toc::length() const +{ + // +1 since the last sector is included + return lastSector() - firstSector() + 1; +} + + +unsigned int K3bDevice::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(); + l /= 75; + id = ( ( id % 0xff ) << 24 ) | ( l << 8 ) | count(); + + return id; +} + + +int K3bDevice::Toc::contentType() const +{ + int audioCnt = 0, dataCnt = 0; + for( Toc::const_iterator it = constBegin(); it != constEnd(); ++it ) { + if( (*it).type() == K3bDevice::Track::AUDIO ) + audioCnt++; + else + dataCnt++; + } + + if( audioCnt + dataCnt == 0 ) + return K3bDevice::NONE; + if( audioCnt == 0 ) + return K3bDevice::DATA; + if( dataCnt == 0 ) + return K3bDevice::AUDIO; + return K3bDevice::MIXED; +} + + +int K3bDevice::Toc::sessions() const +{ + if( isEmpty() ) + return 0; + else if( last().session() == 0 ) + return 1; // default if unknown + else + return last().session(); +} + + +void K3bDevice::Toc::clear() +{ + QValueList<Track>::clear(); + m_mcn.resize( 0 ); + m_firstSector = 0; +} + + +void K3bDevice::Toc::debug() const +{ + k3bDebug() << count() << " in " << sessions() << " sessions" << endl; + int sessionN = 0; + int trackN = 0; + for( Toc::const_iterator it = begin(); it != end(); ++it ) { + ++trackN; + if( sessionN != (*it).session() ) { + sessionN = (*it).session(); + k3bDebug() << "Session Number " << sessionN << endl; + } + k3bDebug() << " Track " << trackN << ( (*it).type() == Track::AUDIO ? " AUDIO" : " DATA" ) + << " " << (*it).firstSector().lba() << " - " << (*it).lastSector().lba() + << " (" << (*it).length().lba() << ")" << endl; + } +} + + +bool K3bDevice::Toc::operator==( const Toc& other ) const +{ + return( m_firstSector == other.m_firstSector && + QValueList<Track>::operator==( other ) ); +} + + +bool K3bDevice::Toc::operator!=( const Toc& other ) const +{ + return( m_firstSector != other.m_firstSector || + QValueList<Track>::operator!=( other ) ); +} |