Commit 027ee852 authored by Richard Lärkäng's avatar Richard Lärkäng
Browse files

Some bugfixes in CDInfo

Updates to tests
Use less deprecated functions
KIO::Job -> KJob

svn path=/trunk/KDE/kdemultimedia/libkcddb/; revision=538750
parent aef458da
......@@ -23,7 +23,7 @@ libkcddb_la_SOURCES = \
libkcddb_la_LDFLAGS = $(all_libraries) -version-info 1:0:0 -no-undefined
libkcddb_la_LIBADD = $(LIB_KDECORE) $(LIB_KIO) $(mb_lib)
METASOURCES = AUTO
......@@ -35,3 +35,5 @@ kcddbinclude_HEADERS = \
kcddbconfig.lo: configbase.h
include ../admin/Doxyfile.am
......@@ -26,7 +26,7 @@
namespace KCDDB
{
AsyncCDDBPLookup::AsyncCDDBPLookup()
: CDDBPLookup(),
: CDDBPLookup(),
state_(Idle)
{
......@@ -45,7 +45,7 @@ namespace KCDDB
)
{
socket_ = new KNetwork::KBufferedSocket(hostname,QString::number(port));
socket_->setBlocking( false );
connect (socket_, SIGNAL(gotError(int)), SLOT(slotGotError(int)));
......@@ -73,7 +73,7 @@ namespace KCDDB
AsyncCDDBPLookup::slotGotError(int error)
{
state_ = Idle;
if ( error == KNetwork::KSocketBase::LookupFailure )
emit finished( HostNotFound );
else if ( error == KNetwork::KSocketBase::ConnectionTimedOut ||
......@@ -206,11 +206,12 @@ namespace KCDDB
state_ = Idle;
char c;
while ( socket_->bytesAvailable() )
socket_->getch();
socket_->getChar(&c);
close();
emit finished( result_ );
break;
......@@ -220,7 +221,7 @@ namespace KCDDB
break;
}
}
QString
AsyncCDDBPLookup::readLine()
{
......
......@@ -118,7 +118,7 @@ namespace KCDDB
}
void
AsyncHTTPLookup::slotResult( KIO::Job *job )
AsyncHTTPLookup::slotResult( KJob *job )
{
if ( 0 != job->error() )
{
......@@ -143,8 +143,8 @@ namespace KCDDB
connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ),
SLOT( slotData( KIO::Job *, const QByteArray & ) ) );
connect( job, SIGNAL( result( KIO::Job * ) ),
SLOT( slotResult( KIO::Job * ) ) );
connect( job, SIGNAL( result( KJob * ) ),
SLOT( slotResult( KJob * ) ) );
return Success;
}
......
......@@ -23,6 +23,8 @@
#include "httplookup.h"
class KJob;
namespace KCDDB
{
class AsyncHTTPLookup : public HTTPLookup
......@@ -48,7 +50,7 @@ namespace KCDDB
void requestCDInfoForMatch();
void slotData( KIO::Job *, const QByteArray & );
void slotResult( KIO::Job * );
void slotResult( KJob * );
protected:
virtual Result fetchURL();
......
......@@ -33,15 +33,15 @@ namespace KCDDB
{
}
CDDB::Result AsyncHTTPSubmit::runJob(KIO::Job* job)
{
connect(job, SIGNAL(result(KIO::Job *)), SLOT(slotFinished(KIO::Job *)));
connect(job, SIGNAL(result(KJob *)), SLOT(slotFinished(KJob *)));
return CDDB::Success;
}
void AsyncHTTPSubmit::slotFinished(KIO::Job* job)
void AsyncHTTPSubmit::slotFinished(KJob* job)
{
kDebug() << "Finished" << endl;
......
......@@ -21,6 +21,8 @@
#include "httpsubmit.h"
class KJob;
namespace KCDDB
{
class AsyncHTTPSubmit : public HTTPSubmit
......@@ -35,7 +37,7 @@ namespace KCDDB
protected:
virtual Result runJob(KIO::Job* job);
private slots:
void slotFinished(KIO::Job*);
void slotFinished(KJob*);
} ;
}
......
......@@ -21,6 +21,7 @@
#include "cdinfo.h"
#include <qdatastream.h>
#include <kdebug.h>
#include <kio/job.h>
namespace KCDDB
{
......@@ -38,13 +39,13 @@ namespace KCDDB
CDDB::Result AsyncSMTPSubmit::runJob(KIO::Job* job)
{
connect( job, SIGNAL( result( KIO::Job* ) ),
this, SLOT(slotDone( KIO::Job* ) ) );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT(slotDone( KJob* ) ) );
return Success;
}
void AsyncSMTPSubmit::slotDone( KIO::Job* job )
void AsyncSMTPSubmit::slotDone( KJob* job )
{
kDebug(60010) << k_funcinfo << endl;
if ( job->error()==0 )
......
......@@ -20,7 +20,12 @@
*/
#include "smtpsubmit.h"
#include <kio/job.h>
class KJob;
namespace KIO
{
class Job;
}
namespace KCDDB
{
......@@ -36,7 +41,7 @@ namespace KCDDB
signals:
void finished( CDDB::Result );
protected slots:
void slotDone( KIO::Job * );
void slotDone( KJob * );
protected:
virtual Result runJob(KIO::Job* job);
} ;
......
......@@ -37,7 +37,7 @@ namespace KCDDB
{
QDir dir( cacheDir );
QString category(info.get(Category).toString());
if ( !dir.exists( category ) )
dir.mkdir( category );
......@@ -71,8 +71,8 @@ namespace KCDDB
if ( f.exists() && f.open(QIODevice::ReadOnly) )
{
QTextStream ts(&f);
ts.setEncoding(QTextStream::UnicodeUTF8);
QString cddbData = ts.read();
ts.setCodec("UTF-8");
QString cddbData = ts.readAll();
f.close();
CDInfo info;
info.load(cddbData);
......@@ -91,7 +91,7 @@ namespace KCDDB
void
Cache::store(const CDInfoList& list, const Config& c)
{
CDInfoList::ConstIterator it=list.begin();
CDInfoList::ConstIterator it=list.begin();
while (it!=list.end())
{
CDInfo info( *it );
......@@ -116,7 +116,7 @@ namespace KCDDB
if ( f.open(QIODevice::WriteOnly) )
{
QTextStream ts(&f);
ts.setEncoding(QTextStream::UnicodeUTF8);
ts.setCodec("UTF-8");
ts << info.toString();
f.close();
}
......
......@@ -139,7 +139,7 @@ namespace KCDDB
uint
CDDB::statusCode( const QString & line )
{
QStringList tokenList = QStringList::split( ' ', line );
QStringList tokenList = line.split(' ', QString::SkipEmptyParts );
uint serverStatus = tokenList[ 0 ].toUInt();
......
......@@ -104,7 +104,7 @@ namespace KCDDB
}
kDebug(60010) << "WRITE: [" << line << "]" << endl;
QByteArray buf(line.utf8());
QByteArray buf(line.toUtf8());
buf.append( '\n' );
return socket_->writeBlock( buf.data(), buf.length() );
......
......@@ -2,6 +2,7 @@
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002-2005 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002-2004 Nadeem Hasan <nhasan@nadmm.com>
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -88,7 +89,7 @@ namespace KCDDB
QVariant
get(const QString& type)
{
return data[type.upper()];
return data[type.toUpper()];
}
QVariant
get(Type type)
......@@ -120,12 +121,12 @@ namespace KCDDB
kDebug(60010) << "Error: custom cdinfo::set data can not start with T and contain a _" << endl;
return;
}
if(type.upper() == "DTITLE"){
if(type.toUpper() == "DTITLE"){
kDebug(60010) << "Error: type: DTITLE is reserved and can not be set." << endl;
return;
}
data[type.upper()] = d;
data[type.toUpper()] = d;
}
void
set(Type type, const QVariant &d)
......@@ -227,7 +228,7 @@ namespace KCDDB
QMap<QString, QVariant>::const_iterator i = d->data.constBegin();
while (i != d->data.constEnd()) {
if(i.key() != "COMMENT" && i.key() != "TITLE" && i.key() != "ARTIST" && i.key() != "TRACKNUMBER") {
out += QString("T%1_%2=%3\n").arg(i.key()).arg(track).arg( i.data().toString());
out += d->createLine(QString("T%1_%2").arg(i.key()).arg(track),i.value().toString());
}
++i;
}
......@@ -266,7 +267,7 @@ namespace KCDDB
bool
CDInfo::load(const QString & string)
{
return load(QStringList::split('\n', string));
return load(string.split('\n',QString::SkipEmptyParts));
}
bool
......@@ -280,35 +281,35 @@ namespace KCDDB
QStringList::ConstIterator it = lineList.begin();
QRegExp rev("# Revision: (\\d+)");
QRegExp eol("[\r\n]");
while ( it != lineList.end() )
{
QString line(*it);
line.replace(eol,"");
++it;
QStringList tokenList = KStringHandler::perlSplit('=', line, 2);
if (rev.search(line) != -1)
if (rev.indexIn(line) != -1)
{
set("revision", rev.cap(1).toUInt());
continue;
}
QString key = tokenList[0].trimmed();
QString value;
QStringList tokenList = KStringHandler::perlSplit('=', line, 2);
if (2 != tokenList.count())
{
if (!key.startsWith("EXT"))
continue;
continue;
}
else
value = d->unescape ( tokenList[1].trimmed() );
QString key = tokenList[0].trimmed();
QString value = d->unescape ( tokenList[1] );
if ( "DTITLE" == key )
{
dtitle += value;
}
else if ( "TTITLE" == key.left( 6 ) )
else if ( key.startsWith("TTITLE") )
{
uint trackNumber = key.mid(6).toUInt();
......@@ -328,7 +329,7 @@ namespace KCDDB
{
set(Year, value);
}
else if ( "EXTT" == key.left( 4 ) )
else if ( key.startsWith("EXTT") )
{
uint trackNumber = key.mid( 4 ).toUInt();
......@@ -336,30 +337,29 @@ namespace KCDDB
QString extt = track(trackNumber).get(Comment).toString();
track(trackNumber).set(Comment, extt+value );
}
else if ( "T" == key.left( 1 ))
else if ( key.startsWith("T") )
{
// Custom Track data
uint trackNumber = key.mid( key.indexOf('_')+1 ).toUInt();
checkTrack( trackNumber );
QString data = QString("^T.*_%1$").arg(trackNumber);
if ( key.indexOf( data ) )
QRegExp data(QString("^T.*_%1$").arg(trackNumber));
if ( key.contains( data ) )
{
QString k = key.mid(1, key.indexOf('_')-1);
TrackInfo& ti = track(trackNumber);
ti.set( k, ti.get(k).toString().append(value) );
}
}
else if (key.contains(QRegExp( "^.*$" ) ))
else
{
// Custom Disk data
d->append( key, value );
}
}
int slashPos = dtitle.indexOf('/');
int slashPos = dtitle.indexOf(" / ");
if (-1 == slashPos)
{
......@@ -370,7 +370,7 @@ namespace KCDDB
else
{
set(Artist, dtitle.left(slashPos).trimmed());
set(Title, dtitle.mid(slashPos + 1).trimmed());
set(Title, dtitle.mid(slashPos + 3).trimmed());
}
bool isSampler = true;
......@@ -453,12 +453,7 @@ namespace KCDDB
// Custom track data
for (int i = 0; i < trackInfoList.count(); ++i)
{
QStringList lines = QStringList::split('\n', trackInfoList[i].toString(), true);
for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it)
if(!(*it).isEmpty())
s += d->createLine((*it).mid(0,(*it).indexOf('=')), (*it).mid((*it).indexOf('=')+1) );
}
s += trackInfoList[i].toString();
QStringList cddbKeywords;
cddbKeywords
......@@ -477,7 +472,7 @@ namespace KCDDB
while (i != d->data.constEnd()){
if (!cddbKeywords.contains(i.key()))
{
s+= d->createLine(QString("%1").arg(i.key()), i.data().toString());
s+= d->createLine(i.key(), i.value().toString());
}
++i;
}
......
......@@ -34,13 +34,20 @@ namespace KCDDB
*/
enum Type
{
Title,
Comment,
Artist,
Genre,
Year,
Length,
Category
Title, /**< The title of the track or CD */
Comment, /**< A comment for the track or CD */
Artist, /**< The artist of the track or CD */
Genre, /**< The genre of the track or CD */
Year, /**< The year the cd or track was produced
By default, the year of the track is the
same as for the whole cd
@todo Doesn't do that for tracks right now.*/
Length, /**< The length of a track or a full CD
@todo In what unit? */
Category /**< The freedb category of the entry.
Needs to be one of: blues, classical,
country, data, fold, jazz, misc, newage,
reggae, rock, soundtrack */
};
/**
......@@ -49,12 +56,12 @@ namespace KCDDB
class KDE_EXPORT TrackInfo
{
public:
TrackInfo();
virtual ~TrackInfo();
TrackInfo(const TrackInfo& clone);
TrackInfo& operator=(const TrackInfo& clone);
/**
* Get data for type that has been assigned to this track.
* @p type is case insensitive.
......@@ -65,7 +72,7 @@ namespace KCDDB
* Helper function that calls type with the common name
*/
QVariant get(Type type) const;
/**
* Set any data from this track.
* @p type is case insensitive.
......@@ -84,12 +91,12 @@ namespace KCDDB
* tracknumber must be assigned before calling this.
*/
QString toString() const;
/**
* internal
*/
void clear();
private:
class TrackInfoPrivate *d;
......@@ -110,7 +117,7 @@ namespace KCDDB
public:
CDInfo();
virtual ~CDInfo();
CDInfo(const CDInfo& clone);
CDInfo& operator=(const CDInfo& clone);
......@@ -130,7 +137,7 @@ namespace KCDDB
* internal
*/
void clear();
/**
* @return true if the cd information is valid
*/
......@@ -138,10 +145,10 @@ namespace KCDDB
/**
* @param submit If submit is true only returns CDDB compatible information
* @return a string containing all of the CD's information.
* @return a string containing all of the CD's information.
*/
QString toString(bool submit=false) const;
/**
* Get data for type that has been assigned to this disc.
* @p type is case insensitive.
......@@ -152,7 +159,7 @@ namespace KCDDB
* Helper function that calls type with the common name
*/
QVariant get(Type type) const;
/**
* Set any data from this disc.
* @p type is case insensitive.
......@@ -182,13 +189,13 @@ namespace KCDDB
* Returns number of tracks on CD
*/
int numberOfTracks() const;
protected:
/**
* Checks to make sure that trackNumber exists
*/
void checkTrack( int trackNumber );
private:
class CDInfoPrivate *d;
TrackInfoList trackInfoList;
......
......@@ -51,9 +51,9 @@ namespace KCDDB
void CDInfoEncodingWidget::slotEncodingChanged(const QString& encoding)
{
KCharsets* charsets = KGlobal::charsets();
QTextCodec* codec = charsets->codecForName(charsets->encodingForName(encoding));
songsBox->clear();
QStringList newTitles;
......@@ -63,7 +63,7 @@ namespace KCDDB
songsBox->clear();
songsBox->insertStringList(newTitles);
titleLabel->setText(i18nc("artist - cdtitle", "%1 - %2",
codec->toUnicode(m_artist.latin1()), codec->toUnicode(m_title.latin1())));
}
......
......@@ -277,7 +277,7 @@ namespace KCDDB
SIGNAL(finished( CDDB::Result ) ),
SLOT( slotSubmitFinished( CDDB::Result ) ) );
}
break;
}
case Submit::SMTP:
......@@ -303,7 +303,7 @@ namespace KCDDB
return CDDB::UnknownError;
break;
}
CDDB::Result r = cdInfoSubmit->submit( cdInfo, offsetList );
if ( blockingMode() )
......@@ -314,7 +314,7 @@ namespace KCDDB
return r;
}
void
Client::store(const CDInfo &cdInfo)
{
......
......@@ -148,7 +148,7 @@ namespace KCDDB
break;
}
}
break;
......@@ -170,7 +170,7 @@ namespace KCDDB
return;
break;
break;
default:
......
......@@ -26,7 +26,7 @@
namespace KCDDB
{
Lookup::Lookup()
: CDDB()
: CDDB()
{
}
......@@ -42,7 +42,7 @@ namespace KCDDB
if ( 200 == serverStatus )
{
QStringList tokenList = QStringList::split( ' ', line );
QStringList tokenList = line.split( ' ', QString::SkipEmptyParts );
matchList_.append( qMakePair( tokenList[ 1 ], tokenList[ 2 ] ) );
return Success;
}
......@@ -61,7 +61,7 @@ namespace KCDDB
void
Lookup::parseExtraMatch( const QString & line )
{
QStringList tokenList = QStringList::split( ' ', line );
QStringList tokenList = line.split( ' ', QString::SkipEmptyParts );
matchList_.append( qMakePair( tokenList[ 0 ], tokenList[ 1 ] ) );
}
......
......@@ -90,7 +90,7 @@ namespace KCDDB
return result;
}
Mirror
Sites::parseLine(const QString& line)
{
......@@ -111,7 +111,7 @@ namespace KCDDB