summaryrefslogtreecommitdiffstats
path: root/libkcddb
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commite2de64d6f1beb9e492daf5b886e19933c1fa41dd (patch)
tree9047cf9e6b5c43878d5bf82660adae77ceee097a /libkcddb
downloadtdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.tar.gz
tdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libkcddb')
-rw-r--r--libkcddb/Makefile.am33
-rw-r--r--libkcddb/TODO12
-rw-r--r--libkcddb/asynccddbplookup.cpp352
-rw-r--r--libkcddb/asynccddbplookup.h94
-rw-r--r--libkcddb/asynchttplookup.cpp159
-rw-r--r--libkcddb/asynchttplookup.h62
-rw-r--r--libkcddb/asynchttpsubmit.cpp55
-rw-r--r--libkcddb/asynchttpsubmit.h44
-rw-r--r--libkcddb/asyncsmtpsubmit.cpp57
-rw-r--r--libkcddb/asyncsmtpsubmit.h46
-rw-r--r--libkcddb/cache.cpp131
-rw-r--r--libkcddb/cache.h57
-rw-r--r--libkcddb/categories.cpp50
-rw-r--r--libkcddb/categories.h42
-rw-r--r--libkcddb/cddb.cpp227
-rw-r--r--libkcddb/cddb.h92
-rw-r--r--libkcddb/cddbplookup.cpp113
-rw-r--r--libkcddb/cddbplookup.h56
-rw-r--r--libkcddb/cdinfo.cpp339
-rw-r--r--libkcddb/cdinfo.h146
-rw-r--r--libkcddb/cdinfodialogbase.ui429
-rw-r--r--libkcddb/cdinfodialogbase.ui.h248
-rw-r--r--libkcddb/cdinfoencodingwidget.cpp70
-rw-r--r--libkcddb/cdinfoencodingwidget.h45
-rw-r--r--libkcddb/cdinfoencodingwidgetbase.ui70
-rw-r--r--libkcddb/client.cpp315
-rw-r--r--libkcddb/client.h104
-rw-r--r--libkcddb/config.cpp56
-rw-r--r--libkcddb/config.h45
-rw-r--r--libkcddb/configbase.kcfgc4
-rw-r--r--libkcddb/genres.cpp123
-rw-r--r--libkcddb/genres.h43
-rw-r--r--libkcddb/httplookup.cpp186
-rw-r--r--libkcddb/httplookup.h82
-rw-r--r--libkcddb/httpsubmit.cpp60
-rw-r--r--libkcddb/httpsubmit.h41
-rw-r--r--libkcddb/kcmcddb/Makefile.am23
-rw-r--r--libkcddb/kcmcddb/cddbconfigwidget.cpp108
-rw-r--r--libkcddb/kcmcddb/cddbconfigwidget.h43
-rw-r--r--libkcddb/kcmcddb/cddbconfigwidgetbase.ui594
-rw-r--r--libkcddb/kcmcddb/kcmcddb-emailsettings.upd6
-rw-r--r--libkcddb/kcmcddb/kcmcddb.cpp132
-rw-r--r--libkcddb/kcmcddb/kcmcddb.h55
-rw-r--r--libkcddb/kcmcddb/libkcddb.desktop187
-rw-r--r--libkcddb/libkcddb.kcfg66
-rw-r--r--libkcddb/lookup.cpp87
-rw-r--r--libkcddb/lookup.h65
-rw-r--r--libkcddb/sites.cpp119
-rw-r--r--libkcddb/sites.h53
-rw-r--r--libkcddb/smtpsubmit.cpp60
-rw-r--r--libkcddb/smtpsubmit.h43
-rw-r--r--libkcddb/submit.cpp101
-rw-r--r--libkcddb/submit.h65
-rw-r--r--libkcddb/synccddbplookup.cpp222
-rw-r--r--libkcddb/synccddbplookup.h51
-rw-r--r--libkcddb/synchttplookup.cpp131
-rw-r--r--libkcddb/synchttplookup.h50
-rw-r--r--libkcddb/synchttpsubmit.cpp46
-rw-r--r--libkcddb/synchttpsubmit.h37
-rw-r--r--libkcddb/syncsmtpsubmit.cpp46
-rw-r--r--libkcddb/syncsmtpsubmit.h38
-rw-r--r--libkcddb/test/Makefile.am48
-rw-r--r--libkcddb/test/asynccddblookuptest.cpp113
-rw-r--r--libkcddb/test/asynccddblookuptest.h27
-rw-r--r--libkcddb/test/asynchttplookuptest.cpp111
-rw-r--r--libkcddb/test/asynchttplookuptest.h27
-rw-r--r--libkcddb/test/asynchttpsubmittest.cpp80
-rw-r--r--libkcddb/test/asynchttpsubmittest.h25
-rw-r--r--libkcddb/test/asyncsmtpsubmittest.cpp81
-rw-r--r--libkcddb/test/asyncsmtpsubmittest.h25
-rw-r--r--libkcddb/test/sitestest.cpp47
-rw-r--r--libkcddb/test/synccddblookuptest.cpp84
-rw-r--r--libkcddb/test/synchttplookuptest.cpp84
-rw-r--r--libkcddb/test/synchttpsubmittest.cpp79
-rw-r--r--libkcddb/test/syncsmtpsubmittest.cpp81
-rw-r--r--libkcddb/test/utf8test.cpp50
76 files changed, 7478 insertions, 0 deletions
diff --git a/libkcddb/Makefile.am b/libkcddb/Makefile.am
new file mode 100644
index 00000000..e5b88c90
--- /dev/null
+++ b/libkcddb/Makefile.am
@@ -0,0 +1,33 @@
+SUBDIRS = . kcmcddb test
+
+INCLUDES = -I$(srcdir)/.. $(all_includes)
+
+lib_LTLIBRARIES = libkcddb.la
+
+libkcddb_la_SOURCES = \
+ cache.cpp cdinfo.cpp config.cpp client.cpp cddb.cpp lookup.cpp \
+ cddbplookup.cpp synccddbplookup.cpp asynccddbplookup.cpp httplookup.cpp \
+ synchttplookup.cpp asynchttplookup.cpp smtpsubmit.cpp \
+ asyncsmtpsubmit.cpp syncsmtpsubmit.cpp configbase.kcfgc \
+ submit.cpp sites.cpp httpsubmit.cpp asynchttpsubmit.cpp \
+ synchttpsubmit.cpp cdinfodialogbase.ui categories.cpp genres.cpp \
+ cdinfoencodingwidget.cpp cdinfoencodingwidgetbase.ui
+
+libkcddb_la_LDFLAGS = $(all_libraries) -version-info 1:0:0
+libkcddb_la_LIBADD = $(LIB_KDECORE) $(LIB_KIO)
+
+METASOURCES = AUTO
+
+kde_kcfg_DATA = libkcddb.kcfg
+
+kcddbincludedir = $(includedir)/libkcddb
+kcddbinclude_HEADERS = \
+ cache.h cdinfo.h client.h config.h cddb.h configbase.h
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/libkcddb.pot
+
+config.lo: configbase.h
+
+include $(top_srcdir)/admin/Doxyfile.am
+
diff --git a/libkcddb/TODO b/libkcddb/TODO
new file mode 100644
index 00000000..a556d761
--- /dev/null
+++ b/libkcddb/TODO
@@ -0,0 +1,12 @@
+Better error checking, for example checking if the config is empty
+
+Try to comply with freedb's: "Guidelines for optimal freedb support"
+http://www.freedb.org/modules.php?name=Sections&sop=viewarticle&artid=38
+
+Saving playlist
+
+Make it possible for a program to in some way mark that
+an entry is not coming from freedb, but created from the
+program. Now it's not possible to know the difference, so
+the revision of a new entry is always 1 instead of 0 as
+it should be
diff --git a/libkcddb/asynccddbplookup.cpp b/libkcddb/asynccddbplookup.cpp
new file mode 100644
index 00000000..f1ebe528
--- /dev/null
+++ b/libkcddb/asynccddbplookup.cpp
@@ -0,0 +1,352 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2005 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kdebug.h>
+
+#include "asynccddbplookup.h"
+
+namespace KCDDB
+{
+ AsyncCDDBPLookup::AsyncCDDBPLookup()
+ : CDDBPLookup(),
+ state_(Idle)
+ {
+
+ }
+
+ AsyncCDDBPLookup::~AsyncCDDBPLookup()
+ {
+ }
+
+ CDDB::Result
+ AsyncCDDBPLookup::lookup
+ (
+ const QString & hostname,
+ uint port,
+ const TrackOffsetList & trackOffsetList
+ )
+ {
+ socket_ = new KNetwork::KBufferedSocket(hostname,QString::number(port));
+
+ socket_->setBlocking( false );
+
+ connect (socket_, SIGNAL(gotError(int)), SLOT(slotGotError(int)));
+
+ connect (socket_, SIGNAL( connected(const KResolverEntry &) ),
+ SLOT( slotConnectionSuccess() ) );
+
+ connect (socket_, SIGNAL( readyRead() ), SLOT( slotReadyRead() ) );
+
+ if ( trackOffsetList.count() < 3 )
+ return UnknownError;
+
+ trackOffsetList_ = trackOffsetList;
+
+ state_ = WaitingForConnection;
+
+ if ( !socket_->connect(hostname, QString::number(port)) )
+ {
+ state_ = Idle;
+ emit finished( NoResponse );
+ return NoResponse;
+ }
+
+ return Success;
+ }
+
+ void
+ AsyncCDDBPLookup::slotGotError(int error)
+ {
+ state_ = Idle;
+
+ if ( error == KNetwork::KSocketBase::LookupFailure )
+ emit finished( HostNotFound );
+ else if ( error == KNetwork::KSocketBase::ConnectionTimedOut ||
+ error == KNetwork::KSocketBase::NetFailure )
+ emit finished( NoResponse );
+ else
+ emit finished( UnknownError );
+ }
+
+ void
+ AsyncCDDBPLookup::slotConnectionSuccess()
+ {
+ kdDebug(60010) << "Connection successful" << endl;
+ state_ = WaitingForGreeting;
+ }
+
+ void
+ AsyncCDDBPLookup::slotReadyRead()
+ {
+ kdDebug(60010) << "Ready to read. State: " << stateToString() << endl;
+
+ while ( Idle != state_ && isConnected() && socket_->canReadLine() )
+ read();
+ }
+
+ void
+ AsyncCDDBPLookup::read()
+ {
+ switch ( state_ )
+ {
+ case WaitingForGreeting:
+
+ if ( !parseGreeting( readLine() ) )
+ {
+ result_ = ServerError;
+ doQuit();
+ return;
+ }
+
+ doHandshake();
+
+ break;
+
+ case WaitingForHandshake:
+
+ if ( !parseHandshake( readLine() ) )
+ {
+ result_ = ServerError;
+ doQuit();
+ return;
+ }
+
+ doProto();
+
+ break;
+
+ case WaitingForProtoResponse:
+
+ // Ignore the response for now
+ readLine();
+
+ doQuery();
+
+ break;
+
+ case WaitingForQueryResponse:
+ result_ = parseQuery( readLine() );
+
+ switch ( result_ )
+ {
+ case Success:
+ requestCDInfoForMatch();
+ break;
+
+ case MultipleRecordFound:
+ state_ = WaitingForMoreMatches;
+ break;
+
+ default: // Error :(
+ doQuit();
+ return;
+ }
+
+ break;
+
+ case WaitingForMoreMatches:
+ {
+ QString line = readLine();
+
+ if (line.startsWith("."))
+ requestCDInfoForMatch();
+ else
+ parseExtraMatch( line );
+ }
+
+ break;
+
+ case WaitingForCDInfoResponse:
+ {
+ Result result = parseRead( readLine() );
+
+ if ( Success != result )
+ {
+ result_ = result;
+ doQuit();
+ return;
+ }
+
+ state_ = WaitingForCDInfoData;
+ }
+
+ break;
+
+ case WaitingForCDInfoData:
+ {
+ QString line = readLine();
+
+ if (line.startsWith("."))
+ {
+ parseCDInfoData();
+ requestCDInfoForMatch();
+ }
+ else
+ cdInfoBuffer_ << line;
+ }
+
+ break;
+
+ case WaitingForQuitResponse:
+
+ state_ = Idle;
+
+ while ( socket_->bytesAvailable() )
+ socket_->getch();
+
+ close();
+
+ emit finished( result_ );
+
+ break;
+
+ default:
+
+ break;
+ }
+ }
+
+ QString
+ AsyncCDDBPLookup::readLine()
+ {
+ return QString::fromUtf8(socket_->readLine());
+ }
+
+ void
+ AsyncCDDBPLookup::doHandshake()
+ {
+ sendHandshake();
+
+ state_ = WaitingForHandshake;
+ }
+
+ void
+ AsyncCDDBPLookup::doProto()
+ {
+ sendProto();
+
+ state_ = WaitingForProtoResponse;
+ }
+
+ void
+ AsyncCDDBPLookup::doQuery()
+ {
+ sendQuery();
+
+ state_ = WaitingForQueryResponse;
+ }
+
+ void
+ AsyncCDDBPLookup::requestCDInfoForMatch()
+ {
+ if (matchList_.isEmpty())
+ {
+ result_ = cdInfoList_.isEmpty()? NoRecordFound : Success;
+ doQuit();
+ return;
+ }
+
+ CDDBMatch match = matchList_.first();
+ matchList_.remove( match );
+
+ sendRead( match );
+
+ state_ = WaitingForCDInfoResponse;
+ }
+
+ void
+ AsyncCDDBPLookup::parseCDInfoData()
+ {
+ CDInfo info;
+
+ if (info.load( cdInfoBuffer_ ))
+ {
+ info.category = category_;
+ cdInfoList_.append( info );
+ }
+
+ cdInfoBuffer_.clear();
+ }
+
+ void
+ AsyncCDDBPLookup::doQuit()
+ {
+ state_ = WaitingForQuitResponse;
+
+ sendQuit();
+ }
+
+ QString
+ AsyncCDDBPLookup::stateToString() const
+ {
+ switch (state_)
+ {
+ case Idle:
+ return "Idle";
+ break;
+
+ case WaitingForConnection:
+ return "WaitingForConnection";
+ break;
+
+ case WaitingForGreeting:
+ return "WaitingForGreeting";
+ break;
+
+ case WaitingForProtoResponse:
+ return "WaitingForProtoResponse";
+ break;
+
+ case WaitingForHandshake:
+ return "WaitingForHandshake";
+ break;
+
+ case WaitingForQueryResponse:
+ return "WaitingForQueryResponse";
+ break;
+
+ case WaitingForMoreMatches:
+ return "WaitingForMoreMatches";
+ break;
+
+ case WaitingForCDInfoResponse:
+ return "WaitingForCDInfoResponse";
+ break;
+
+ case WaitingForCDInfoData:
+ return "WaitingForCDInfoData";
+ break;
+
+ case WaitingForQuitResponse:
+ return "WaitingForQuitResponse";
+ break;
+
+ default:
+ return "Unknown";
+ break;
+ }
+ }
+}
+
+
+#include "asynccddbplookup.moc"
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/asynccddbplookup.h b/libkcddb/asynccddbplookup.h
new file mode 100644
index 00000000..f0a39c84
--- /dev/null
+++ b/libkcddb/asynccddbplookup.h
@@ -0,0 +1,94 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_ASYNC_CDDBP_LOOKUP_H
+#define KCDDB_ASYNC_CDDBP_LOOKUP_H
+
+#include <qobject.h>
+
+#include "cddbplookup.h"
+
+namespace KCDDB
+{
+ class AsyncCDDBPLookup : public CDDBPLookup
+ {
+ Q_OBJECT
+
+ public:
+
+ enum State
+ {
+ Idle,
+ WaitingForConnection,
+ WaitingForGreeting,
+ WaitingForHandshake,
+ WaitingForProtoResponse,
+ WaitingForQueryResponse,
+ WaitingForMoreMatches,
+ WaitingForCDInfoResponse,
+ WaitingForCDInfoData,
+ WaitingForQuitResponse
+ };
+
+ AsyncCDDBPLookup();
+
+ virtual ~AsyncCDDBPLookup();
+
+ Result lookup( const QString &, uint, const TrackOffsetList & );
+
+ signals:
+
+ void finished( CDDB::Result );
+ void quit( CDDB::Result );
+
+ protected slots:
+
+ void slotGotError(int error);
+ void slotConnectionSuccess();
+ void slotReadyRead();
+
+ protected:
+
+ void doHandshake();
+ void doProto();
+ void doQuery();
+ void doQuit();
+
+ bool parseQueryResponse( const QString & );
+ void requestCDInfoForMatch();
+ bool parseCDInfoResponse( const QString & );
+ void parseCDInfoData();
+
+ void read();
+
+ QString readLine();
+
+ QString stateToString() const;
+
+ private:
+
+ State state_;
+ Result result_;
+ QStringList cdInfoBuffer_;
+ };
+}
+
+#endif // KCDDB_ASYNC_CDDBP_LOOKUP_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/asynchttplookup.cpp b/libkcddb/asynchttplookup.cpp
new file mode 100644
index 00000000..a183b3d5
--- /dev/null
+++ b/libkcddb/asynchttplookup.cpp
@@ -0,0 +1,159 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <qstringlist.h>
+#include <qapplication.h>
+
+#include <kdebug.h>
+#include <kio/job.h>
+
+#include "asynchttplookup.h"
+
+namespace KCDDB
+{
+ AsyncHTTPLookup::AsyncHTTPLookup()
+ : HTTPLookup()
+ {
+ block_ = false;
+ }
+
+ AsyncHTTPLookup::~AsyncHTTPLookup()
+ {
+ // Empty.
+ }
+
+ CDDB::Result
+ AsyncHTTPLookup::lookup
+ (
+ const QString & hostName,
+ uint port,
+ const TrackOffsetList & trackOffsetList
+ )
+ {
+ if ( trackOffsetList.count() < 3 )
+ return UnknownError;
+
+ trackOffsetList_ = trackOffsetList;
+
+ connect( this, SIGNAL( queryReady() ), SLOT( slotQueryReady() ) );
+ connect( this, SIGNAL( readReady() ), SLOT( requestCDInfoForMatch() ) );
+
+ initURL( hostName, port );
+
+ // Run a query.
+ result_ = runQuery();
+
+ return result_;
+ }
+
+ CDDB::Result
+ AsyncHTTPLookup::runQuery()
+ {
+ data_ = QByteArray();
+ state_ = WaitingForQueryResponse;
+
+ result_ = sendQuery();
+
+ return result_;
+ }
+
+ void
+ AsyncHTTPLookup::slotQueryReady()
+ {
+ kdDebug(60010) << "Matches Found: " << matchList_.count() << endl;
+
+ if ( Success != result_ )
+ {
+ emit finished( result_ );
+ return;
+ }
+
+ requestCDInfoForMatch();
+ }
+
+ void
+ AsyncHTTPLookup::requestCDInfoForMatch()
+ {
+ if ( matchList_.isEmpty() )
+ {
+ result_ = cdInfoList_.isEmpty()? NoRecordFound : Success;
+ emit finished( result_ );
+ return;
+ }
+
+ CDDBMatch match = matchList_.first();
+ matchList_.remove( match );
+
+ data_ = QByteArray();
+ state_ = WaitingForReadResponse;
+
+ result_ = sendRead( match );
+
+ if ( Success != result_ )
+ emit finished( result_ );
+ }
+
+ void
+ AsyncHTTPLookup::slotData( KIO::Job *, const QByteArray &data )
+ {
+ if (data.size() > 0)
+ {
+ QDataStream stream(data_, IO_WriteOnly | IO_Append);
+ stream.writeRawBytes(data.data(), data.size());
+ }
+ }
+
+ void
+ AsyncHTTPLookup::slotResult( KIO::Job *job )
+ {
+ if ( 0 != job->error() )
+ {
+ result_ = ServerError;
+ if ( !block_ )
+ emit queryReady();
+ return;
+ }
+
+ jobFinished();
+ }
+
+ CDDB::Result
+ AsyncHTTPLookup::fetchURL()
+ {
+ kdDebug(60010) << "About to fetch: " << cgiURL_.url() << endl;
+
+ KIO::TransferJob* job = KIO::get( cgiURL_, false, false );
+
+ if ( 0 == job )
+ return ServerError;
+
+ connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ),
+ SLOT( slotData( KIO::Job *, const QByteArray & ) ) );
+ connect( job, SIGNAL( result( KIO::Job * ) ),
+ SLOT( slotResult( KIO::Job * ) ) );
+
+ return Success;
+ }
+
+}
+
+#include "asynchttplookup.moc"
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/asynchttplookup.h b/libkcddb/asynchttplookup.h
new file mode 100644
index 00000000..2c4ede05
--- /dev/null
+++ b/libkcddb/asynchttplookup.h
@@ -0,0 +1,62 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_ASYNC_HTTP_LOOKUP_H
+#define KCDDB_ASYNC_HTTP_LOOKUP_H
+
+#include "httplookup.h"
+
+namespace KCDDB
+{
+ class AsyncHTTPLookup : public HTTPLookup
+ {
+
+ Q_OBJECT
+
+ public:
+
+ AsyncHTTPLookup();
+ virtual ~AsyncHTTPLookup();
+
+ Result lookup( const QString &, uint, const TrackOffsetList & );
+
+ CDInfoList lookupResponse() const;
+
+ signals:
+
+ void finished( CDDB::Result );
+
+ protected slots:
+ void slotQueryReady();
+ void requestCDInfoForMatch();
+
+ void slotData( KIO::Job *, const QByteArray & );
+ void slotResult( KIO::Job * );
+
+ protected:
+ virtual Result fetchURL();
+
+ Result runQuery();
+ };
+}
+
+#endif // KCDDB_ASYNC_HTTP_LOOKUP_H
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/asynchttpsubmit.cpp b/libkcddb/asynchttpsubmit.cpp
new file mode 100644
index 00000000..ffabc2db
--- /dev/null
+++ b/libkcddb/asynchttpsubmit.cpp
@@ -0,0 +1,55 @@
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "asynchttpsubmit.h"
+#include <kio/job.h>
+#include <kdebug.h>
+
+namespace KCDDB
+{
+ AsyncHTTPSubmit::AsyncHTTPSubmit(const QString& from, const QString& hostname, uint port)
+ : HTTPSubmit(from, hostname, port)
+ {
+
+ }
+
+ AsyncHTTPSubmit::~AsyncHTTPSubmit()
+ {
+
+ }
+
+ CDDB::Result AsyncHTTPSubmit::runJob(KIO::Job* job)
+ {
+ connect(job, SIGNAL(result(KIO::Job *)), SLOT(slotFinished(KIO::Job *)));
+
+ return CDDB::Success;
+ }
+
+ void AsyncHTTPSubmit::slotFinished(KIO::Job* job)
+ {
+ kdDebug() << "Finished" << endl;
+
+ if ( job->error()==0 )
+ emit finished( Success );
+ else
+ emit finished( UnknownError );
+ }
+}
+
+#include "asynchttpsubmit.moc"
diff --git a/libkcddb/asynchttpsubmit.h b/libkcddb/asynchttpsubmit.h
new file mode 100644
index 00000000..e40f243d
--- /dev/null
+++ b/libkcddb/asynchttpsubmit.h
@@ -0,0 +1,44 @@
+#ifndef ASYNCHTTPSUBMIT_H
+#define ASYNCHTTPSUBMIT_H
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "httpsubmit.h"
+
+namespace KCDDB
+{
+ class AsyncHTTPSubmit : public HTTPSubmit
+ {
+ Q_OBJECT
+ public:
+ AsyncHTTPSubmit(const QString& from, const QString& hostname, uint port);
+ virtual ~AsyncHTTPSubmit();
+
+ signals:
+ void finished( CDDB::Result );
+ protected:
+ virtual Result runJob(KIO::Job* job);
+ private slots:
+ void slotFinished(KIO::Job*);
+ } ;
+}
+
+
+#endif // ASYNCHTTPSUBMIT_H
+
diff --git a/libkcddb/asyncsmtpsubmit.cpp b/libkcddb/asyncsmtpsubmit.cpp
new file mode 100644
index 00000000..a51d9eb5
--- /dev/null
+++ b/libkcddb/asyncsmtpsubmit.cpp
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "asyncsmtpsubmit.h"
+#include "cdinfo.h"
+#include <qdatastream.h>
+#include <kdebug.h>
+
+namespace KCDDB
+{
+ AsyncSMTPSubmit::AsyncSMTPSubmit(const QString& hostname, uint port,
+ const QString& username, const QString& from, const QString& to )
+ : SMTPSubmit( hostname, port, username, from, to )
+ {
+
+ }
+
+ AsyncSMTPSubmit::~AsyncSMTPSubmit()
+ {
+
+ }
+
+ CDDB::Result AsyncSMTPSubmit::runJob(KIO::Job* job)
+ {
+ connect( job, SIGNAL( result( KIO::Job* ) ),
+ this, SLOT(slotDone( KIO::Job* ) ) );
+
+ return Success;
+ }
+
+ void AsyncSMTPSubmit::slotDone( KIO::Job* job )
+ {
+ kdDebug(60010) << k_funcinfo << endl;
+ if ( job->error()==0 )
+ emit finished( Success );
+ else
+ emit finished( UnknownError );
+ }
+}
+
+#include "asyncsmtpsubmit.moc"
diff --git a/libkcddb/asyncsmtpsubmit.h b/libkcddb/asyncsmtpsubmit.h
new file mode 100644
index 00000000..7a76f25d
--- /dev/null
+++ b/libkcddb/asyncsmtpsubmit.h
@@ -0,0 +1,46 @@
+#ifndef ASYNCSMTPSUBMIT_H
+#define ASYNCSMTPSUBMIT_H
+/*
+ Copyright (C) 2003-2004 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "smtpsubmit.h"
+#include <kio/job.h>
+
+namespace KCDDB
+{
+ class AsyncSMTPSubmit : public SMTPSubmit
+ {
+ Q_OBJECT
+
+ public:
+ AsyncSMTPSubmit(const QString& hostname, uint port, const QString& username,
+ const QString& from, const QString& to);
+ virtual ~AsyncSMTPSubmit();
+
+ signals:
+ void finished( CDDB::Result );
+ protected slots:
+ void slotDone( KIO::Job * );
+ protected:
+ virtual Result runJob(KIO::Job* job);
+ } ;
+}
+
+#endif // ASYNCSMTPSUBMIT_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/cache.cpp b/libkcddb/cache.cpp
new file mode 100644
index 00000000..1dda49e4
--- /dev/null
+++ b/libkcddb/cache.cpp
@@ -0,0 +1,131 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kdebug.h>
+#include <kstandarddirs.h>
+
+#include <qfile.h>
+#include <qdir.h>
+
+#include "cache.h"
+#include "config.h"
+
+namespace KCDDB
+{
+ QString
+ Cache::fileName( const QString &category, const QString &discid, const QString &cacheDir )
+ {
+ QDir dir( cacheDir );
+ if ( !dir.exists( category ) )
+ dir.mkdir( category );
+
+ return cacheDir + "/" + category + "/" + discid;
+ }
+
+ CDInfoList
+ Cache::lookup( const QString &cddbId )
+ {
+ kdDebug(60010) << "Looking up " << cddbId << " in CDDB cache" << endl;
+
+ CDInfoList infoList;
+ Config c;
+ c.readConfig();
+ QStringList cddbCacheDirs = c.cacheLocations();
+
+ for (QStringList::Iterator cddbCacheDir = cddbCacheDirs.begin();
+ cddbCacheDir != cddbCacheDirs.end(); ++cddbCacheDir)
+ {
+ QDir dir( *cddbCacheDir );
+ QStringList dirList = dir.entryList( QDir::Dirs );
+
+ QStringList::ConstIterator it = dirList.begin();
+
+ while ( it != dirList.end() )
+ {
+ QString category( *it );
+ if ( category[ 0 ] != '.' )
+ {
+ QFile f( *cddbCacheDir + "/" + category + "/" + cddbId );
+ if ( f.exists() && f.open(IO_ReadOnly) )
+ {
+ QTextStream ts(&f);
+ ts.setEncoding(QTextStream::UnicodeUTF8);
+ QString cddbData = ts.read();
+ f.close();
+ CDInfo info;
+ info.load(cddbData);
+ info.category = category;
+
+ infoList.append( info );
+ }
+ }
+ ++it;
+ }
+ }
+
+ return infoList;
+ }
+
+ void
+ Cache::store(const CDInfoList& list)
+ {
+ CDInfoList::ConstIterator it=list.begin();
+ while (it!=list.end())
+ {
+ CDInfo info( *it );
+ store(info);
+ ++it;
+ }
+ }
+
+ void
+ Cache::store(const CDInfo& info)
+ {
+ Config c;
+ c.readConfig();
+
+ QString cacheDir = c.cacheLocations().first();
+ QDir d(cacheDir);
+ if (!d.exists())
+ d.mkdir(cacheDir);
+
+ // The same entry can contain several discids (separated by a ','),
+ // so we save the entry to all of them
+ QStringList discids = QStringList::split(',', info.id);
+ for (QStringList::Iterator it = discids.begin(); it != discids.end(); ++it)
+ {
+ QString cacheFile = fileName(info.category, *it, cacheDir);
+
+ kdDebug(60010) << "Storing " << cacheFile << " in CDDB cache" << endl;
+
+ QFile f(cacheFile);
+ if ( f.open(IO_WriteOnly) )
+ {
+ QTextStream ts(&f);
+ ts.setEncoding(QTextStream::UnicodeUTF8);
+ ts << info.toString();
+ f.close();
+ }
+ }
+ }
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/cache.h b/libkcddb/cache.h
new file mode 100644
index 00000000..f7b861b2
--- /dev/null
+++ b/libkcddb/cache.h
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_CACHE_H
+#define KCDDB_CACHE_H
+
+#include <qpair.h>
+#include <qstring.h>
+
+#include "cdinfo.h"
+#include <kdemacros.h>
+namespace KCDDB
+{
+ class KDE_EXPORT Cache
+ {
+ public:
+
+ enum Policy
+ {
+ Only,
+ Use,
+ Ignore
+ };
+
+ static CDInfoList lookup( const QString & );
+ static void store( const CDInfoList & );
+ // KDE4: Should probably take a TrackOffsetList too, so
+ // the list can be stored in the file, and we can make
+ // sure the discid is correct (had to do the same fix in
+ // both kscd and kaudiocreator)
+ static void store( const CDInfo & );
+
+ private:
+ static QString fileName( const QString &category, const QString& discid, const QString &cacheDir );
+ };
+}
+
+#endif // KCDDB_CACHE_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/categories.cpp b/libkcddb/categories.cpp
new file mode 100644
index 00000000..522da81b
--- /dev/null
+++ b/libkcddb/categories.cpp
@@ -0,0 +1,50 @@
+// Copyright (C) 2005 by Shaheed Haque (srhaque@iee.org). All rights reserved.
+//
+// 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.
+//
+
+#include <categories.h>
+#include <klocale.h>
+
+KCDDB::Categories::Categories()
+{
+ // These are only 11 Category values defined by CDDB. See
+ //
+ // http://www.freedb.org/modules.php?name=Sections&sop=viewarticle&artid=26
+ //
+ m_cddb << "blues" << "classical" << "country" <<
+ "data" << "folk" << "jazz" << "misc" <<
+ "newage" << "reggae" << "rock" << "soundtrack";
+ m_i18n << i18n("Blues") << i18n("Classical") << i18n("music genre", "Country") <<
+ i18n("Data") << i18n("Folk") << i18n("Jazz") << i18n("Miscellaneous") <<
+ i18n("New Age") << i18n("Reggae") << i18n("Rock") << i18n("Soundtrack");
+}
+
+const QString KCDDB::Categories::cddb2i18n(const QString &category) const
+{
+ int index = m_cddb.findIndex(category.stripWhiteSpace());
+ if (index != -1)
+ {
+ return m_i18n[index];
+ }
+ else
+ {
+ return cddb2i18n("misc");
+ }
+}
+
+const QString KCDDB::Categories::i18n2cddb(const QString &category) const
+{
+ int index = m_i18n.findIndex(category.stripWhiteSpace());
+ if (index != -1)
+ {
+ return m_cddb[index];
+ }
+ else
+ {
+ return "misc";
+ }
+}
diff --git a/libkcddb/categories.h b/libkcddb/categories.h
new file mode 100644
index 00000000..01147111
--- /dev/null
+++ b/libkcddb/categories.h
@@ -0,0 +1,42 @@
+// Copyright (C) 2005 by Shaheed Haque (srhaque@iee.org). All rights reserved.
+//
+// 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.
+//
+#ifndef KCDDB_CATEGORIES_H
+#define KCDDB_CATEGORIES_H
+
+#include <qstring.h>
+#include <qstringlist.h>
+
+namespace KCDDB
+{
+ /**
+ * Category values defined by CDDB.
+ */
+ class Categories
+ {
+ public:
+ Categories();
+
+ const QStringList &cddbList() const { return m_cddb; };
+ const QStringList &i18nList() const { return m_i18n; };
+
+ /**
+ * Lookup the CDDB category, and return the i18n'd version.
+ */
+ const QString cddb2i18n(const QString &category) const;
+
+ /**
+ * Lookup the i18n category, and return the CDDB version.
+ */
+ const QString i18n2cddb(const QString &category) const;
+ private:
+ QStringList m_cddb;
+ QStringList m_i18n;
+ };
+}
+
+#endif
diff --git a/libkcddb/cddb.cpp b/libkcddb/cddb.cpp
new file mode 100644
index 00000000..3e5cb893
--- /dev/null
+++ b/libkcddb/cddb.cpp
@@ -0,0 +1,227 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ CopyRight (C) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <qregexp.h>
+#include <qstringlist.h>
+
+#include <kdebug.h>
+#include <kstringhandler.h>
+#include <klocale.h>
+
+#include "cddb.h"
+
+namespace KCDDB
+{
+ CDDB::CDDB()
+ : user_( "libkcddb-user" ),
+ localHostName_( "localHost" ),
+ readOnly_( false )
+ {
+
+ }
+
+ CDDB::~CDDB()
+ {
+ // Empty.
+ }
+
+ QString
+ CDDB::trackOffsetListToId()
+ {
+ return trackOffsetListToId( trackOffsetList_ );
+ }
+ QString
+ CDDB::trackOffsetListToId( const TrackOffsetList & list )
+ {
+ // Taken from version by Michael Matz in kio_audiocd.
+ unsigned int id = 0;
+ int numTracks = list.count() - 2;
+
+ // The last two in the list are disc begin and disc end.
+ for ( int i = numTracks-1; i >= 0; i-- )
+ {
+ int n = list[ i ]/75;
+ while ( n > 0 )
+ {
+ id += n % 10;
+ n /= 10;
+ }
+ }
+
+ unsigned int l = list[numTracks + 1] / 75;
+ l -= list[0] / 75;
+
+ id = ( ( id % 255 ) << 24 ) | ( l << 8 ) | numTracks;
+
+ return QString::number( id, 16 ).rightJustify( 8, '0' );
+ }
+
+ QString
+ CDDB::trackOffsetListToString()
+ {
+ QString ret;
+ uint numTracks = trackOffsetList_.count()-2;
+
+ // Disc start.
+ ret.append( QString::number( numTracks ) );
+ ret.append( " " );
+
+ for ( uint i = 0; i < numTracks; i++ )
+ {
+ ret.append( QString::number( trackOffsetList_[ i ] ) );
+ ret.append( " " );
+ }
+
+ unsigned int discLengthInSec = ( trackOffsetList_[ numTracks+1 ] ) / 75;
+
+ ret.append( QString::number( discLengthInSec ) );
+
+ return ret;
+ }
+
+ bool
+ CDDB::parseGreeting( const QString & line )
+ {
+ uint serverStatus = statusCode( line );
+
+ if ( 200 == serverStatus )
+ {
+ kdDebug(60010) << "Server response: read-only" << endl;
+ readOnly_ = true;
+ }
+ else if ( 201 == serverStatus )
+ {
+ kdDebug(60010) << "Server response: read-write" << endl;
+ }
+ else
+ {
+ kdDebug(60010) << "Server response: bugger off" << endl;
+ return false;
+ }
+
+ return true;
+ }
+
+ bool
+ CDDB::parseHandshake( const QString & line )
+ {
+ uint serverStatus = statusCode( line );
+
+ if ( ( 200 != serverStatus ) && ( 402 != serverStatus ) )
+ {
+ kdDebug(60010) << "Handshake was too tight. Letting go." << endl;
+ return false;
+ }
+
+ kdDebug(60010) << "Handshake was warm and firm" << endl;
+
+ return true;
+ }
+
+ uint
+ CDDB::statusCode( const QString & line )
+ {
+ QStringList tokenList = QStringList::split( ' ', line );
+
+ uint serverStatus = tokenList[ 0 ].toUInt();
+
+ return serverStatus;
+ }
+
+/* CDDB::Transport
+ CDDB::stringToTransport(const QString & s)
+ {
+ if ("HTTP" == s )
+ return HTTP;
+ else if ( "CDDBP" == s )
+ return CDDBP;
+ else
+ return SMTP;
+ }*/
+
+ QString
+ CDDB::resultToString(Result r)
+ {
+ switch (r)
+ {
+ case Success:
+ return i18n("Success");
+ break;
+
+ case ServerError:
+ return i18n("Server error");
+ break;
+
+ case HostNotFound:
+ return i18n("Host not found");
+ break;
+
+ case NoResponse:
+ return i18n("No response");
+ break;
+
+ case NoRecordFound:
+ return i18n("No record found");
+ break;
+
+ case MultipleRecordFound:
+ return i18n("Multiple records found");
+ break;
+
+ case CannotSave:
+ return i18n("Cannot save");
+ break;
+
+ case InvalidCategory:
+ return i18n("Invalid category");
+ break;
+
+ default:
+ return i18n("Unknown error");
+ break;
+ }
+ }
+
+/* QString
+ CDDB::transportToString(uint t)
+ {
+ switch (Transport(t))
+ {
+ case HTTP:
+ return "HTTP";
+ break;
+
+ case CDDBP:
+ return "CDDBP";
+ break;
+
+ case SMTP:
+ return "SMTP";
+ break;
+
+ default:
+ return "UnknownTransport";
+ break;
+ }
+ }*/
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/cddb.h b/libkcddb/cddb.h
new file mode 100644
index 00000000..b32821de
--- /dev/null
+++ b/libkcddb/cddb.h
@@ -0,0 +1,92 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ CopyRight (C) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_CDDB_H
+#define KCDDB_CDDB_H
+
+#include <qstring.h>
+#include <qpair.h>
+#include <qvaluelist.h>
+
+#include <kdelibs_export.h>
+
+/** The KCDDB namespace collects all the CDDB-related classes and methods. */
+namespace KCDDB
+{
+ /** This list is used to calculate the CDDB disc id.
+ Insert the start frames ((minute*60 + seconds)*75+frames)
+ of all tracks, followed by the first frame of the disc and the last
+ frame of the disc. The first frame is for most audio CD's the same
+ as the first frame of the first track, the
+ last one is the start frame of the leadout track.
+ */
+ typedef QValueList<uint> TrackOffsetList;
+
+ /** This is just a container class used for interpreting results
+ of CDDB queries.
+ */
+ class KDE_EXPORT CDDB
+ {
+ public:
+
+ enum Result
+ {
+ Success,
+ ServerError,
+ HostNotFound,
+ NoResponse,
+ NoRecordFound,
+ MultipleRecordFound,
+ CannotSave,
+ InvalidCategory,
+ UnknownError
+ };
+
+ CDDB();
+ virtual ~CDDB();
+
+ static QString resultToString(Result);
+ static QString trackOffsetListToId( const TrackOffsetList & );
+
+ static QString clientName() { return QString::fromLatin1("libkcddb"); }
+ static QString clientVersion() { return QString::fromLatin1("0.31"); }
+
+ protected:
+ bool parseGreeting( const QString & );
+ bool parseHandshake( const QString & );
+
+ uint statusCode( const QString & );
+
+ QString trackOffsetListToId();
+ QString trackOffsetListToString();
+
+ QString user_;
+ QString localHostName_;
+
+ bool readOnly_;
+
+ TrackOffsetList trackOffsetList_;
+ };
+}
+
+#endif // KCDDB_CDDB_H
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/cddbplookup.cpp b/libkcddb/cddbplookup.cpp
new file mode 100644
index 00000000..d2ec1b26
--- /dev/null
+++ b/libkcddb/cddbplookup.cpp
@@ -0,0 +1,113 @@
+/*
+ Copyright ( C ) 2002 Rik Hemsley ( rikkus ) <rik@kde.org>
+ Copyright ( C ) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright ( C ) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or ( at your option ) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kdebug.h>
+
+#include "cddbplookup.h"
+
+namespace KCDDB
+{
+ CDDBPLookup::CDDBPLookup()
+ : Lookup()
+ {
+
+ }
+
+ CDDBPLookup::~CDDBPLookup()
+ {
+ delete socket_;
+ }
+
+ void
+ CDDBPLookup::sendHandshake()
+ {
+ QString handshake = QString( "cddb hello %1 %2 %3 %4" )
+ .arg( user_ )
+ .arg( localHostName_ )
+ .arg( clientName() )
+ .arg( clientVersion() );
+
+ writeLine( handshake );
+ }
+
+ void
+ CDDBPLookup::sendProto()
+ {
+ writeLine( "proto 6" );
+ }
+
+ void
+ CDDBPLookup::sendQuery()
+ {
+ QString query = QString( "cddb query %1 %2" )
+ .arg( trackOffsetListToId() )
+ .arg( trackOffsetListToString() );
+
+ writeLine( query );
+ }
+
+ void
+ CDDBPLookup::sendRead( const CDDBMatch & match )
+ {
+ category_ = match.first;
+ QString discid = match.second;
+
+ QString readRequest = QString( "cddb read %1 %2" )
+ .arg( category_ )
+ .arg( discid );
+
+ writeLine( readRequest );
+ }
+
+ void
+ CDDBPLookup::sendQuit()
+ {
+ writeLine( "quit" );
+ }
+
+ void
+ CDDBPLookup::close()
+ {
+ kdDebug(60010) << "Disconnect from server..." << endl;
+ if ( isConnected() )
+ {
+ socket_->close();
+ }
+ }
+
+ Q_LONG
+ CDDBPLookup::writeLine( const QString & line )
+ {
+ if ( !isConnected() )
+ {
+ kdDebug(60010) << "socket status: " << socket_->state() << endl;
+ return -1;
+ }
+
+ kdDebug(60010) << "WRITE: [" << line << "]" << endl;
+ QCString buf = line.utf8();
+ buf.append( "\n" );
+
+ return socket_->writeBlock( buf.data(), buf.length() );
+ }
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/cddbplookup.h b/libkcddb/cddbplookup.h
new file mode 100644
index 00000000..da263b95
--- /dev/null
+++ b/libkcddb/cddbplookup.h
@@ -0,0 +1,56 @@
+/*
+ Copyright (C) 2002 Rik Hemsley ( rikkus ) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or ( at your option ) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_CDDBP_LOOKUP_H
+#define KCDDB_CDDBP_LOOKUP_H
+
+#include <kbufferedsocket.h>
+
+#include "lookup.h"
+
+namespace KCDDB
+{
+ class CDDBPLookup : public Lookup
+ {
+ public:
+ CDDBPLookup();
+ virtual ~CDDBPLookup();
+
+ void sendHandshake();
+ void sendProto();
+ void sendQuery();
+ void sendRead( const CDDBMatch & );
+ void sendQuit();
+
+ void close();
+ protected:
+ Q_LONG writeLine( const QString & );
+
+ bool isConnected()
+ { return KNetwork::KClientSocketBase::Connected == socket_->state(); }
+
+ KNetwork::KBufferedSocket* socket_;
+ };
+}
+
+#endif
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/cdinfo.cpp b/libkcddb/cdinfo.cpp
new file mode 100644
index 00000000..a08e9b8f
--- /dev/null
+++ b/libkcddb/cdinfo.cpp
@@ -0,0 +1,339 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002-2004 Nadeem Hasan <nhasan@nadmm.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kdebug.h>
+#include <kstringhandler.h>
+
+#include "cdinfo.h"
+#include "cddb.h"
+
+namespace KCDDB
+{
+ TrackInfo::TrackInfo()
+ {
+ }
+
+ TrackInfo::TrackInfo(const TrackInfo& clone)
+ : title(clone.title),
+ extt(clone.extt)
+ {
+ }
+
+ TrackInfo::~TrackInfo()
+ {
+ }
+
+ TrackInfo& TrackInfo::operator=(const TrackInfo& clone)
+ {
+ title = clone.title;
+ extt = clone.extt;
+ return *this;
+ }
+
+
+ CDInfo::CDInfo()
+ : year(0),
+ length(0),
+ revision(0)
+ {
+ }
+
+ CDInfo::CDInfo(const CDInfo& clone)
+ : id(clone.id),
+ artist(clone.artist),
+ title(clone.title),
+ genre(clone.genre),
+ category(clone.category),
+ extd(clone.extd),
+ year(clone.year),
+ length(clone.length),
+ revision(clone.revision),
+ trackInfoList(clone.trackInfoList)
+
+ {
+ }
+
+ CDInfo::~CDInfo()
+ {
+ }
+
+ CDInfo& CDInfo::operator=(const CDInfo& clone)
+ {
+ id = clone.id;
+ artist = clone.artist;
+ title = clone.title;
+ genre = clone.genre;
+ category = clone.category;
+ extd = clone.extd;
+ year = clone.year;
+ length = clone.length;
+ revision = clone.revision;
+ trackInfoList = clone.trackInfoList;
+ return *this;
+ }
+
+ QVariant TrackInfo::get(const QString &type) const {
+ if(type == "title")
+ return title;
+ if(type == "extt")
+ return extt;
+ return QVariant();
+ }
+
+ bool
+ CDInfo::load(const QString & s)
+ {
+ return load(QStringList::split('\n', s));
+ }
+
+ bool
+ CDInfo::load(const QStringList & lineList)
+ {
+ clear();
+
+ // We'll append to this until we've seen all the lines, then parse it after.
+ QString dtitle;
+
+ QStringList::ConstIterator it = lineList.begin();
+
+ QRegExp rev("# Revision: (\\d+)");
+
+ while ( it != lineList.end() )
+ {
+ QString line(*it);
+ ++it;
+
+ QStringList tokenList = KStringHandler::perlSplit('=', line, 2);
+
+ if (rev.search(line) != -1)
+ {
+ revision = rev.cap(1).toUInt();;
+ continue;
+ }
+
+ QString key = tokenList[0].stripWhiteSpace();
+ QString value;
+ if (2 != tokenList.count())
+ {
+ if (!key.startsWith("EXT"))
+ continue;
+ }
+ else
+ value = unescape ( tokenList[1].stripWhiteSpace() );
+
+ if ( "DISCID" == key )
+ {
+ id = value;
+ }
+ else if ( "DTITLE" == key )
+ {
+ dtitle += value;
+ }
+ else if ( "DYEAR" == key )
+ {
+ year = value.toUInt();
+ }
+ else if ( "DGENRE" == key )
+ {
+ genre += value;
+ }
+ else if ( "TTITLE" == key.left( 6 ) )
+ {
+ uint trackNumber = key.mid(6).toUInt();
+
+ checkTrack( trackNumber );
+
+ trackInfoList[ trackNumber ].title.append( value );
+ }
+ else if ( "EXTD" == key )
+ {
+ extd.append( value );
+ }
+ else if ( "EXTT" == key.left( 4 ) )
+ {
+ uint trackNumber = key.mid( 4 ).toUInt();
+
+ checkTrack( trackNumber );
+
+ trackInfoList[ trackNumber ].extt.append( value );
+ }
+ }
+
+ int slashPos = dtitle.find('/');
+
+ if (-1 == slashPos)
+ {
+ // Use string for title _and_ artist.
+ artist = title = dtitle;
+ }
+ else
+ {
+ artist = dtitle.left(slashPos).stripWhiteSpace();
+ title = dtitle.mid(slashPos + 1).stripWhiteSpace();
+ }
+
+ if ( genre.isEmpty() )
+ genre = "Unknown";
+
+ kdDebug(60010) << "Loaded CDInfo for " << id << endl;
+
+ return true;
+ }
+
+ QString
+ CDInfo::toString(bool submit) const
+ {
+ QString s;
+
+ if (revision != 0)
+ s += "# Revision: " + QString::number(revision) + "\n";
+
+ if (submit)
+ {
+ s += "#\n";
+ s += QString("# Submitted via: %1 %2\n").arg(CDDB::clientName(),
+ CDDB::clientVersion());
+ }
+
+ s += "DISCID=" + escape( id ) + "\n";
+ s += createLine("DTITLE",escape( artist ) + " / " + escape( title ));
+ s += "DYEAR=" + (0 == year ? QString::null : QString::number(year)) + "\n";
+ s += createLine("DGENRE",escape( genre ));
+
+ for (uint i = 0; i < trackInfoList.count(); ++i)
+ {
+ s += createLine(QString("TTITLE%1").arg(i),
+ escape( trackInfoList[ i ].title));
+ }
+
+ s += createLine("EXTD", escape( extd ));
+
+ for (uint i = 0; i < trackInfoList.count(); ++i)
+ {
+ s += createLine(QString("EXTT%1").arg(i), escape(trackInfoList[i].extt));
+ }
+
+ s +="PLAYORDER=\n";
+
+ return s;
+ }
+
+ // Creates a line in the form NAME=VALUE, and splits it into several
+ // lines if the line gets longer than 256 chars
+ QString
+ CDInfo::createLine(const QString& name, const QString& value) const
+ {
+ Q_ASSERT(name.length() < 254);
+
+ uint maxLength = 256 - name.length() - 2;
+
+ QString tmpValue = value;
+
+ QString lines;
+
+ while (tmpValue.length() > maxLength)
+ {
+ lines += QString("%1=%2\n").arg(name,tmpValue.left(maxLength));
+ tmpValue = tmpValue.mid(maxLength);
+ }
+
+ lines += QString("%1=%2\n").arg(name,tmpValue);
+
+ return lines;
+ }
+
+ void
+ CDInfo::checkTrack( uint trackNumber )
+ {
+ if ( trackInfoList.count() < trackNumber + 1 )
+ {
+ while ( trackInfoList.count() < trackNumber + 1 )
+ trackInfoList.append(TrackInfo());
+ }
+ }
+
+ QString
+ CDInfo::escape( const QString& value )
+ {
+ QString s = value;
+ s.replace( "\\", "\\\\" );
+ s.replace( "\n", "\\n" );
+ s.replace( "\t", "\\t" );
+
+ return s;
+ }
+
+ QString
+ CDInfo::unescape( const QString& value )
+ {
+ QString s = value;
+
+ s.replace( "\\n", "\n" );
+ s.replace( "\\t", "\t" );
+ s.replace( "\\\\", "\\" );
+
+ return s;
+ }
+
+ void
+ CDInfo::clear()
+ {
+ id = artist = title = genre = extd = QString::null;
+ length = year = revision = 0;
+ trackInfoList.clear();
+ }
+
+ bool
+ CDInfo::isValid() const
+ {
+ if (id.isEmpty())
+ return false;
+
+ if (id == "0")
+ return false;
+
+ return true;
+ }
+
+ QVariant CDInfo::get(const QString &type) const {
+ if(type == "id")
+ return id;
+ if(type == "artist")
+ return artist;
+ if(type == "title")
+ return title;
+ if(type == "genre")
+ return genre;
+ if(type == "category")
+ return category;
+ if(type == "extd")
+ return extd;
+ if(type == "year")
+ return year;
+ if(type == "length")
+ return length;
+ if(type == "revision")
+ return revision;
+ return QVariant();
+ }
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/cdinfo.h b/libkcddb/cdinfo.h
new file mode 100644
index 00000000..554e2ff6
--- /dev/null
+++ b/libkcddb/cdinfo.h
@@ -0,0 +1,146 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002-2004 Nadeem Hasan <nhasan@nadmm.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_CDINFO_H
+#define KCDDB_CDINFO_H
+
+#include <qstringlist.h>
+#include <qvaluelist.h>
+#include <kdemacros.h>
+#include <qvariant.h>
+
+namespace KCDDB
+{
+ /**
+ * Information about a sepecific track in a cd.
+ */
+ class KDE_EXPORT TrackInfo
+ {
+ public:
+
+ TrackInfo();
+ ~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.
+ * For example <code>get("title")</code>
+ */
+ QVariant get(const QString &type) const;
+#ifndef KDE_NO_COMPAT
+ // Use get("title");
+ QString title;
+ // Use get("extt");
+ QString extt;
+#endif
+ };
+
+ typedef QValueList<TrackInfo> TrackInfoList;
+
+ /**
+ * Information about a CD
+ *
+ * Typically CDInfo is obtained from the client such as:
+ * <code>KCDDB::Client *cddb = new KCDDB::Client();
+ * cddb->lookup(discSignature);
+ * CDInfo info = cddb->bestLookupResponse();</code>
+ */
+ class KDE_EXPORT CDInfo
+ {
+ public:
+
+ CDInfo();
+ ~CDInfo();
+ CDInfo(const CDInfo& clone);
+ CDInfo& operator=(const CDInfo& clone);
+
+ /**
+ * Load CDInfo from a string that is CDDB compatible
+ * @return true if successful
+ */
+ bool load(const QString &);
+ /**
+ * Load CDInfo from a stringList that is CDDB compatible
+ * @return true if successful
+ */
+ bool load(const QStringList &);
+
+ /**
+ * Clear all information, setting this to invalid
+ * internal
+ */
+ void clear();
+
+ /**
+ * @return true if the cd information is valid
+ */
+ bool isValid() const;
+ /**
+ * @param submit If submit is true only returns CDDB compatible 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.
+ * For example <code>get("title")</code>
+ */
+ QVariant get(const QString &type) const;
+ // Use get(...)
+ QString id;
+ QString artist;
+ QString title;
+ QString genre;
+ QString category;
+ QString extd;
+ uint year;
+ uint length; // in milliseconds
+ uint revision;
+
+ TrackInfoList trackInfoList;
+
+ protected:
+ /**
+ * @returns a valid CDDB line made up of name and value
+ */
+ QString createLine(const QString& name, const QString& value) const;
+ /**
+ * Checks to make sure that trackNumber exists
+ */
+ void checkTrack( uint );
+ /**
+ * escape's string for CDDB processing
+ */
+ static QString escape( const QString & );
+ /**
+ * fixes an escaped string that has been CDDB processed
+ */
+ static QString unescape( const QString & );
+ };
+
+ typedef QValueList<CDInfo> CDInfoList;
+}
+
+#endif // KCDDB_CDINFO_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/cdinfodialogbase.ui b/libkcddb/cdinfodialogbase.ui
new file mode 100644
index 00000000..76ee8141
--- /dev/null
+++ b/libkcddb/cdinfodialogbase.ui
@@ -0,0 +1,429 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>CDInfoDialogBase</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>CDInfoDialogBase</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>501</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout1</cstring>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel" row="5" column="2">
+ <property name="name">
+ <cstring>lb_revision</cstring>
+ </property>
+ <property name="text">
+ <string>Revision:</string>
+ </property>
+ </widget>
+ <widget class="KLineEdit" row="1" column="1" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>m_title</cstring>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Use the name of the artist if there is no title.</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="4" column="0">
+ <property name="name">
+ <cstring>lb_category</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Category:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>m_category</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="5" column="1">
+ <property name="name">
+ <cstring>m_id</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="KLineEdit" row="0" column="1" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>m_artist</cstring>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Write names as "first last", not "last, first". Omit any leading "The". Use "Various" for compilations.</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>lb_artist</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Artist:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>m_artist</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="3" column="0">
+ <property name="name">
+ <cstring>lb_year</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Year:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>m_year</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="4" column="2">
+ <property name="name">
+ <cstring>lb_genre</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Genre:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>m_genre</cstring>
+ </property>
+ </widget>
+ <widget class="KComboBox" row="4" column="1">
+ <property name="name">
+ <cstring>m_category</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Disc Id values must be unique within a category.</string>
+ </property>
+ </widget>
+ <widget class="KIntSpinBox" row="3" column="1">
+ <property name="name">
+ <cstring>m_year</cstring>
+ </property>
+ <property name="maxValue">
+ <number>2100</number>
+ </property>
+ <property name="minValue">
+ <number>0</number>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="6" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>m_multiple</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Multiple artists</string>
+ </property>
+ </widget>
+ <widget class="KLineEdit" row="2" column="1" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>m_comment</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="2" column="0">
+ <property name="name">
+ <cstring>lb_comment</cstring>
+ </property>
+ <property name="text">
+ <string>Comment:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>le_discInfo</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="1" column="0">
+ <property name="name">
+ <cstring>lb_title</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Title:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>m_title</cstring>
+ </property>
+ </widget>
+ <widget class="KComboBox" row="4" column="3">
+ <property name="name">
+ <cstring>m_genre</cstring>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="duplicatesEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Avoid custom values, as they will be written to CDDB as-is.</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="5" column="0">
+ <property name="name">
+ <cstring>lb_id</cstring>
+ </property>
+ <property name="text">
+ <string>Disc Id:</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="3" column="2">
+ <property name="name">
+ <cstring>lb_length</cstring>
+ </property>
+ <property name="text">
+ <string>Length:</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="5" column="3">
+ <property name="name">
+ <cstring>m_revision</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="3" column="3">
+ <property name="name">
+ <cstring>m_length</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ </grid>
+ </widget>
+ <widget class="KListView">
+ <column>
+ <property name="text">
+ <string>Track</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Length</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Title</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Comment</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Artist</string>
+ </property>
+ <property name="clickable">
+ <bool>true</bool>
+ </property>
+ <property name="resizable">
+ <bool>true</bool>
+ </property>
+ </column>
+ <property name="name">
+ <cstring>m_trackList</cstring>
+ </property>
+ <property name="allColumnsShowFocus">
+ <bool>true</bool>
+ </property>
+ <property name="defaultRenameAction">
+ <enum>Accept</enum>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>For a CD-Extra, set title to "Data".</string>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout2</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <spacer>
+ <property name="name">
+ <cstring>spacer1</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>231</width>
+ <height>41</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>m_changeEncoding</cstring>
+ </property>
+ <property name="text">
+ <string>Change Encoding...</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>lb_playingOrder</cstring>
+ </property>
+ <property name="text">
+ <string>Playing order:</string>
+ </property>
+ </widget>
+ <widget class="KLineEdit">
+ <property name="name">
+ <cstring>m_playOrder</cstring>
+ </property>
+ </widget>
+ </vbox>
+</widget>
+<customwidgets>
+</customwidgets>
+<connections>
+ <connection>
+ <sender>m_trackList</sender>
+ <signal>selectionChanged(QListViewItem*)</signal>
+ <receiver>CDInfoDialogBase</receiver>
+ <slot>slotTrackSelected(QListViewItem*)</slot>
+ </connection>
+ <connection>
+ <sender>m_trackList</sender>
+ <signal>doubleClicked(QListViewItem*,const QPoint&amp;,int)</signal>
+ <receiver>CDInfoDialogBase</receiver>
+ <slot>slotTrackDoubleClicked(QListViewItem*,const QPoint&amp;,int)</slot>
+ </connection>
+ <connection>
+ <sender>m_artist</sender>
+ <signal>textChanged(const QString&amp;)</signal>
+ <receiver>CDInfoDialogBase</receiver>
+ <slot>artistChanged(const QString&amp;)</slot>
+ </connection>
+ <connection>
+ <sender>m_genre</sender>
+ <signal>textChanged(const QString&amp;)</signal>
+ <receiver>CDInfoDialogBase</receiver>
+ <slot>genreChanged(const QString&amp;)</slot>
+ </connection>
+ <connection>
+ <sender>m_multiple</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>CDInfoDialogBase</receiver>
+ <slot>slotMultipleArtists(bool)</slot>
+ </connection>
+ <connection>
+ <sender>m_changeEncoding</sender>
+ <signal>clicked()</signal>
+ <receiver>CDInfoDialogBase</receiver>
+ <slot>slotChangeEncoding()</slot>
+ </connection>
+</connections>
+<tabstops>
+ <tabstop>m_artist</tabstop>
+ <tabstop>m_title</tabstop>
+ <tabstop>m_comment</tabstop>
+ <tabstop>m_year</tabstop>
+ <tabstop>m_category</tabstop>
+ <tabstop>m_genre</tabstop>
+ <tabstop>m_trackList</tabstop>
+ <tabstop>m_playOrder</tabstop>
+</tabstops>
+<includes>
+ <include location="local" impldecl="in implementation">kdialog.h</include>
+ <include location="local" impldecl="in implementation">qdatetime.h</include>
+ <include location="local" impldecl="in declaration">libkcddb/cdinfo.h</include>
+ <include location="local" impldecl="in declaration">libkcddb/cddb.h</include>
+ <include location="local" impldecl="in declaration">libkcddb/categories.h</include>
+ <include location="local" impldecl="in declaration">libkcddb/genres.h</include>
+ <include location="local" impldecl="in implementation">cdinfodialogbase.ui.h</include>
+</includes>
+<forwards>
+ <forward>class KCDDBDlgBasePrivate</forward>
+</forwards>
+<variables>
+ <variable access="private">KCDDB::Genres m_genres;</variable>
+ <variable access="private">KCDDB::Categories m_categories;</variable>
+ <variable access="private">static const char *SEPARATOR;</variable>
+ <variable access="public">static const unsigned TRACK_ARTIST = 4;</variable>
+ <variable access="private">KCDDBDlgBasePrivate *d;</variable>
+ <variable access="public">static const unsigned TRACK_TIME = 1;</variable>
+ <variable access="public">static const unsigned TRACK_NUMBER = 0;</variable>
+ <variable access="public">static const unsigned TRACK_TITLE = 2;</variable>
+ <variable access="public">static const unsigned TRACK_COMMENT = 3;</variable>
+</variables>
+<signals>
+ <signal>play(int i)</signal>
+ <signal>discInfoClicked()</signal>
+ <signal>trackInfoClicked(unsigned)</signal>
+</signals>
+<slots>
+ <slot access="protected">slotTrackSelected( QListViewItem * item )</slot>
+ <slot access="protected">slotNextTrack()</slot>
+ <slot access="protected">slotTrackDoubleClicked( QListViewItem * item, const QPoint &amp;, int column )</slot>
+ <slot>setInfo( const KCDDB::CDInfo &amp; info, KCDDB::TrackOffsetList &amp; trackStartFrames )</slot>
+ <slot>artistChanged( const QString &amp; newArtist )</slot>
+ <slot>genreChanged( const QString &amp; newGenre )</slot>
+ <slot>slotMultipleArtists( bool hasMultipleArtist )</slot>
+ <slot access="private">slotChangeEncoding()</slot>
+</slots>
+<functions>
+ <function access="private" specifier="non virtual">init()</function>
+ <function access="private" specifier="non virtual">destroy()</function>
+ <function returnType="QString">framesTime( unsigned frames )</function>
+ <function returnType="KCDDB::CDInfo">info() const</function>
+</functions>
+<layoutdefaults spacing="6" margin="11"/>
+<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/>
+<includehints>
+ <includehint>klineedit.h</includehint>
+ <includehint>kcombobox.h</includehint>
+ <includehint>knuminput.h</includehint>
+ <includehint>klistview.h</includehint>
+</includehints>
+</UI>
diff --git a/libkcddb/cdinfodialogbase.ui.h b/libkcddb/cdinfodialogbase.ui.h
new file mode 100644
index 00000000..1291010a
--- /dev/null
+++ b/libkcddb/cdinfodialogbase.ui.h
@@ -0,0 +1,248 @@
+/****************************************************************************
+** ui.h extension file, included from the uic-generated form implementation.
+**
+** If you wish to add, delete or rename functions or slots use
+** Qt Designer which will update this file, preserving your code. Create an
+** init() function in place of a constructor, and a destroy() function in
+** place of a destructor.
+*****************************************************************************/
+
+#include <qtextcodec.h>
+#include <kdebug.h>
+#include <kdialogbase.h>
+#include <kglobal.h>
+#include <kcharsets.h>
+
+#include "cdinfoencodingwidget.h"
+
+const char *CDInfoDialogBase::SEPARATOR = " / ";
+
+void CDInfoDialogBase::init()
+{
+ m_categories = KCDDB::Categories();
+ m_category->insertStringList(m_categories.i18nList());
+ m_genres = KCDDB::Genres();
+ m_genre->insertStringList(m_genres.i18nList());
+
+ // We want control over the visibility of this column. See artistChanged().
+ m_trackList->setColumnWidthMode(TRACK_ARTIST, QListView::Manual);
+
+ // Make the user-definable values in-place editable.
+ m_trackList->setRenameable(TRACK_NUMBER, false);
+ m_trackList->setRenameable(TRACK_TIME, false);
+ m_trackList->setRenameable(TRACK_TITLE, true);
+ m_trackList->setRenameable(TRACK_COMMENT, true);
+ m_trackList->setRenameable(TRACK_ARTIST, true);
+}
+
+void CDInfoDialogBase::destroy()
+{
+}
+
+void CDInfoDialogBase::slotTrackSelected( QListViewItem *item )
+{
+ emit play(item->text(0).toUInt()-1);
+}
+
+void CDInfoDialogBase::slotNextTrack()
+{
+ if (m_trackList->currentItem())
+ {
+ QListViewItem *item = m_trackList->currentItem()->nextSibling();
+ m_trackList->setSelected(item, true);
+ m_trackList->ensureItemVisible(item);
+ }
+}
+
+void CDInfoDialogBase::slotTrackDoubleClicked( QListViewItem *item, const QPoint &, int column)
+{
+ m_trackList->rename(item, column);
+}
+
+void CDInfoDialogBase::setInfo( const KCDDB::CDInfo &info, KCDDB::TrackOffsetList &trackStartFrames )
+{
+ m_artist->setText(info.artist.stripWhiteSpace());
+ m_title->setText(info.title.stripWhiteSpace());
+ m_category->setCurrentText(m_categories.cddb2i18n(info.category));
+
+ // Make sure the revision is set before the genre to allow the genreChanged() handler to fire.
+ m_revision->setText(QString::number(info.revision));
+ m_genre->setCurrentText(m_genres.cddb2i18n(info.genre));
+ m_year->setValue(info.year);
+ m_comment->setText(info.extd.stripWhiteSpace());
+ m_id->setText(info.id.stripWhiteSpace());
+
+ // Now do the individual tracks.
+ unsigned tracks = info.trackInfoList.count();
+ m_length->setText(framesTime(trackStartFrames[tracks + 1] - trackStartFrames[0]));
+ m_trackList->clear();
+ for (unsigned i = 0; i < tracks; i++)
+ {
+ QListViewItem *item = new QListViewItem(m_trackList, 0);
+
+ item->setText(TRACK_NUMBER, QString().sprintf("%02d", i + 1));
+ item->setText(TRACK_TIME, framesTime(trackStartFrames[i + ((i + 1 < tracks) ? 1 : 2)] - trackStartFrames[i]));
+ QString title = info.trackInfoList[i].title;
+ int separator = title.find(SEPARATOR);
+ if (info.artist != "Various" || separator == -1 || !m_multiple->isChecked() )
+ {
+ item->setText(TRACK_ARTIST, "");
+ item->setText(TRACK_TITLE, title);
+ }
+ else
+ {
+ // We seem to have a compilation.
+ item->setText(TRACK_ARTIST, title.left(separator));
+ item->setText(TRACK_TITLE, title.mid(separator + 3));
+ }
+ item->setText(TRACK_COMMENT, info.trackInfoList[i].extt);
+ }
+ // FIXME KDE4: handle playorder here too, once KCDDBInfo::CDInfo is updated.
+
+ if (info.artist == "Various" || m_multiple->isChecked()){
+ m_trackList->adjustColumn(TRACK_ARTIST);
+ }
+}
+
+QString CDInfoDialogBase::framesTime(unsigned frames)
+{
+ QTime time;
+ double ms;
+
+ ms = frames * 1000 / 75.0;
+ time = time.addMSecs((int)ms);
+
+ // Use ".zzz" for milliseconds...
+ QString temp2;
+ if (time.hour() > 0)
+ temp2 = time.toString("hh:mm:ss");
+ else
+ temp2 = time.toString("mm:ss");
+ return temp2;
+} // framesTime
+
+KCDDB::CDInfo CDInfoDialogBase::info() const
+{
+ KCDDB::CDInfo info;
+ KCDDB::TrackInfo track;
+
+ info.artist = m_artist->text().stripWhiteSpace();
+ info.title = m_title->text().stripWhiteSpace();
+ info.category = m_categories.i18n2cddb(m_category->currentText());
+ info.genre = m_genres.i18n2cddb(m_genre->currentText());
+ info.year = m_year->value();
+ info.extd = m_comment->text().stripWhiteSpace();
+ info.revision = m_revision->text().stripWhiteSpace().toUInt();
+ info.id = m_id->text().stripWhiteSpace();
+ for (QListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
+ {
+ // Combine the track artist if present with the title.
+ QString trackArtist = item->text(TRACK_ARTIST).stripWhiteSpace();
+ track.title = trackArtist;
+ if (!trackArtist.isEmpty())
+ {
+ track.title.append(SEPARATOR);
+ }
+ track.title.append(item->text(TRACK_TITLE).stripWhiteSpace());
+ track.extt = item->text(TRACK_COMMENT).stripWhiteSpace();
+ info.trackInfoList.append(track);
+ // FIXME KDE4: handle track lengths here too, once KCDDBInfo::CDInfo is updated.
+ }
+ // FIXME KDE4: handle playorder here too, once KCDDBInfo::CDInfo is updated.
+ return info;
+}
+
+
+void CDInfoDialogBase::artistChanged( const QString &newArtist )
+{
+ // Enable special handling of compilations.
+ if (newArtist.stripWhiteSpace().compare("Various")) {
+ m_multiple->setChecked(false);
+ } else {
+ m_multiple->setChecked(true);
+ }
+}
+
+void CDInfoDialogBase::genreChanged( const QString &newGenre )
+{
+ // Disable changes to category if the version number indicates that a record
+ // is already in the database, or if the genre is poorly set. The latter
+ // condition also provides a "back-door" override.
+ m_category->setEnabled((m_revision->text().stripWhiteSpace().toUInt() < 1) ||
+ (newGenre.compare("Unknown") == 0));
+}
+
+
+void CDInfoDialogBase::slotMultipleArtists( bool hasMultipleArtist)
+{
+ if(hasMultipleArtist){
+ for (QListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
+ {
+ QString title = item->text(TRACK_TITLE);
+ int separator = title.find(SEPARATOR);
+ if (separator != -1)
+ {
+ // Artists probably entered already
+ item->setText(TRACK_ARTIST, title.left(separator));
+ item->setText(TRACK_TITLE, title.mid(separator + 3));
+ }
+ }
+ m_trackList->adjustColumn(TRACK_ARTIST);
+ m_trackList->adjustColumn(TRACK_TITLE);
+ }
+ else{
+ for (QListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
+ {
+ QString artist = item->text(TRACK_ARTIST);
+ if (!artist.isEmpty())
+ {
+ item->setText(TRACK_ARTIST, QString::null);
+ item->setText(TRACK_TITLE, artist + SEPARATOR + item->text(TRACK_TITLE));
+ }
+ }
+ m_trackList->hideColumn(TRACK_ARTIST);
+ m_trackList->adjustColumn(TRACK_TITLE);
+ }
+}
+
+
+void CDInfoDialogBase::slotChangeEncoding()
+{
+ kdDebug() << k_funcinfo << endl;
+
+ KDialogBase* dialog = new KDialogBase(this, 0, true, i18n("Change Encoding"),
+ KDialogBase::Ok | KDialogBase::Cancel);
+
+ QStringList songTitles;
+ for (QListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
+ {
+ QString title = item->text(TRACK_ARTIST).stripWhiteSpace();
+ if (!title.isEmpty())
+ title.append(SEPARATOR);
+ title.append(item->text(TRACK_TITLE).stripWhiteSpace());
+ songTitles << title;
+ }
+
+ KCDDB::CDInfoEncodingWidget* encWidget = new KCDDB::CDInfoEncodingWidget(
+ dialog, m_artist->text(),m_title->text(), songTitles);
+
+ dialog->setMainWidget(encWidget);
+
+ if (dialog->exec())
+ {
+ KCharsets* charsets = KGlobal::charsets();
+ QTextCodec* codec = charsets->codecForName(charsets->encodingForName(encWidget->selectedEncoding()));
+
+ m_artist->setText(codec->toUnicode(m_artist->text().latin1()));
+ m_title->setText(codec->toUnicode(m_title->text().latin1()));
+ m_genre->setCurrentText(codec->toUnicode(m_genre->currentText().latin1()));
+ m_comment->setText(codec->toUnicode(m_comment->text().latin1()));
+
+ for (QListViewItem *item = m_trackList->firstChild(); item; item=item->nextSibling())
+ {
+ item->setText(TRACK_ARTIST,codec->toUnicode(item->text(TRACK_ARTIST).latin1()));
+ item->setText(TRACK_TITLE,codec->toUnicode(item->text(TRACK_TITLE).latin1()));
+ item->setText(TRACK_COMMENT,codec->toUnicode(item->text(TRACK_COMMENT).latin1()));
+ }
+ }
+}
diff --git a/libkcddb/cdinfoencodingwidget.cpp b/libkcddb/cdinfoencodingwidget.cpp
new file mode 100644
index 00000000..eb59be32
--- /dev/null
+++ b/libkcddb/cdinfoencodingwidget.cpp
@@ -0,0 +1,70 @@
+/*
+ Copyright (C) 2005 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <qcombobox.h>
+#include <qlistbox.h>
+#include <qlabel.h>
+#include <qtextcodec.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kcharsets.h>
+#include "cdinfoencodingwidget.h"
+
+namespace KCDDB
+{
+ CDInfoEncodingWidget::CDInfoEncodingWidget(QWidget* parent, const QString& artist,
+ const QString& title, const QStringList& songTitles)
+ : CDInfoEncodingWidgetBase(parent), m_artist(artist), m_title(title),
+ m_songTitles(songTitles)
+ {
+ encodingCombo->insertStringList(KGlobal::charsets()->descriptiveEncodingNames());
+
+ slotEncodingChanged(encodingCombo->currentText());
+
+ connect(encodingCombo,SIGNAL(activated(const QString&)),
+ this,SLOT(slotEncodingChanged(const QString&)));
+ }
+
+ QString CDInfoEncodingWidget::selectedEncoding()
+ {
+ return encodingCombo->currentText();
+ }
+
+ void CDInfoEncodingWidget::slotEncodingChanged(const QString& encoding)
+ {
+ KCharsets* charsets = KGlobal::charsets();
+
+ QTextCodec* codec = charsets->codecForName(charsets->encodingForName(encoding));
+
+ songsBox->clear();
+ QStringList newTitles;
+
+ for (QStringList::const_iterator it = m_songTitles.begin();
+ it != m_songTitles.end(); ++it)
+ newTitles << codec->toUnicode((*it).latin1());
+
+ songsBox->clear();
+ songsBox->insertStringList(newTitles);
+
+ titleLabel->setText(i18n("artist - cdtitle", "%1 - %2").arg(
+ codec->toUnicode(m_artist.latin1()), codec->toUnicode(m_title.latin1())));
+ }
+}
+
+#include "cdinfoencodingwidget.moc"
diff --git a/libkcddb/cdinfoencodingwidget.h b/libkcddb/cdinfoencodingwidget.h
new file mode 100644
index 00000000..87f9b7a3
--- /dev/null
+++ b/libkcddb/cdinfoencodingwidget.h
@@ -0,0 +1,45 @@
+/*
+ Copyright (C) 2005 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_CDINFOENCODINGWIDGET_H
+#define KCDDB_CDINFOENCODINGWIDGET_H
+
+#include "cdinfoencodingwidgetbase.h"
+
+namespace KCDDB
+{
+ class CDInfoEncodingWidget : public CDInfoEncodingWidgetBase
+ {
+ Q_OBJECT
+ public:
+ CDInfoEncodingWidget(QWidget* parent, const QString& artist, const QString& title,
+ const QStringList& songTitles);
+
+ QString selectedEncoding();
+
+ private slots:
+ void slotEncodingChanged(const QString &);
+
+ private:
+ QString m_artist, m_title;
+ QStringList m_songTitles;
+ } ;
+}
+
+#endif // KCDDB_CDINFOENCODINGWIDGET_H
diff --git a/libkcddb/cdinfoencodingwidgetbase.ui b/libkcddb/cdinfoencodingwidgetbase.ui
new file mode 100644
index 00000000..e5156908
--- /dev/null
+++ b/libkcddb/cdinfoencodingwidgetbase.ui
@@ -0,0 +1,70 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>CDInfoEncodingWidgetBase</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>CDInfoEncodingWidgetBase</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>344</width>
+ <height>369</height>
+ </rect>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>encodingLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Encoding:</string>
+ </property>
+ </widget>
+ <widget class="QComboBox" row="0" column="1">
+ <property name="name">
+ <cstring>encodingCombo</cstring>
+ </property>
+ </widget>
+ <widget class="QGroupBox" row="1" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>groupBox1</cstring>
+ </property>
+ <property name="title">
+ <string>Preview</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>titleLabel</cstring>
+ </property>
+ <property name="frameShape">
+ <enum>LineEditPanel</enum>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="QListBox">
+ <property name="name">
+ <cstring>songsBox</cstring>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>300</width>
+ <height>250</height>
+ </size>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ </grid>
+</widget>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>
diff --git a/libkcddb/client.cpp b/libkcddb/client.cpp
new file mode 100644
index 00000000..07e5e089
--- /dev/null
+++ b/libkcddb/client.cpp
@@ -0,0 +1,315 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "client.h"
+#include "synccddbplookup.h"
+#include "asynccddbplookup.h"
+#include "synchttplookup.h"
+#include "asynchttplookup.h"
+#include "syncsmtpsubmit.h"
+#include "asyncsmtpsubmit.h"
+#include "synchttpsubmit.h"
+#include "asynchttpsubmit.h"
+#include "cache.h"
+#include "lookup.h"
+
+#include <kdebug.h>
+
+namespace KCDDB
+{
+ class Client::Private
+ {
+ public:
+
+ Private()
+ : block( true )
+ {}
+
+ Config config;
+ CDInfoList cdInfoList;
+ bool block;
+ };
+
+ Client::Client()
+ : QObject(),
+ cdInfoLookup(0),
+ cdInfoSubmit(0)
+ {
+ d = new Private;
+ d->config.readConfig();
+ }
+
+ Client::~Client()
+ {
+ delete d;
+ delete cdInfoLookup;
+ delete cdInfoSubmit;
+ }
+
+ Config &
+ Client::config() const
+ {
+ return d->config;
+ }
+
+ void
+ Client::setBlockingMode( bool enable )
+ {
+ d->block = enable;
+ }
+
+ bool
+ Client::blockingMode() const
+ {
+ return d->block;
+ }
+
+ CDInfoList
+ Client::lookupResponse() const
+ {
+ return d->cdInfoList;
+ }
+
+ CDInfo
+ Client::bestLookupResponse() const
+ {
+ CDInfo info;
+
+ uint maxrev = 0;
+
+ for ( CDInfoList::Iterator it = d->cdInfoList.begin();
+ it != d->cdInfoList.end(); ++it )
+ {
+ if ( ( *it ).revision >= maxrev )
+ {
+ info = *it;
+ maxrev = info.revision;
+ }
+ }
+
+ return info;
+ }
+
+ CDDB::Result
+ Client::lookup(const TrackOffsetList & trackOffsetList)
+ {
+ d->cdInfoList.clear();
+
+ QString cddbId = Lookup::trackOffsetListToId( trackOffsetList );
+
+ if ( cddbId.isNull() )
+ {
+ kdDebug(60010) << "Can't create cddbid from offset list" << endl;
+ return Lookup::NoRecordFound;
+ }
+
+ if ( Cache::Ignore != d->config.cachePolicy() )
+ {
+ d->cdInfoList = Cache::lookup( cddbId );
+
+ kdDebug(60010) << "Found " << d->cdInfoList.count() << " hit(s)" << endl;
+
+ if ( !d->cdInfoList.isEmpty() )
+ {
+ if ( !blockingMode() )
+ emit finished( Lookup::Success );
+
+ return CDDB::Success;
+ }
+ }
+
+ if ( Cache::Only == d->config.cachePolicy() )
+ {
+ kdDebug(60010) << "Only trying cache. Give up now." << endl;
+ if ( !blockingMode() )
+ emit finished( Lookup::NoRecordFound );
+ return CDDB::NoRecordFound;
+ }
+
+ CDDB::Result r;
+ Lookup::Transport t = ( Lookup::Transport )d->config.lookupTransport();
+
+ // just in case we have an info lookup hanging around, prevent mem leakage
+ delete cdInfoLookup;
+
+ if ( blockingMode() )
+ {
+
+ if( Lookup::CDDBP == t )
+ cdInfoLookup = new SyncCDDBPLookup();
+ else
+ cdInfoLookup = new SyncHTTPLookup();
+
+ r = cdInfoLookup->lookup( d->config.hostname(),
+ d->config.port(), trackOffsetList );
+
+ if ( CDDB::Success == r )
+ {
+ d->cdInfoList = cdInfoLookup->lookupResponse();
+ Cache::store( d->cdInfoList );
+ }
+
+ delete cdInfoLookup;
+ cdInfoLookup = 0L;
+ }
+ else
+ {
+ if( Lookup::CDDBP == t )
+ {
+ cdInfoLookup = new AsyncCDDBPLookup();
+
+ connect( static_cast<AsyncCDDBPLookup *>( cdInfoLookup ),
+ SIGNAL( finished( CDDB::Result ) ),
+ SLOT( slotFinished( CDDB::Result ) ) );
+ }
+ else
+ {
+ cdInfoLookup = new AsyncHTTPLookup();
+
+ connect( static_cast<AsyncHTTPLookup *>( cdInfoLookup ),
+ SIGNAL( finished( CDDB::Result ) ),
+ SLOT( slotFinished( CDDB::Result ) ) );
+ }
+
+ r = cdInfoLookup->lookup( d->config.hostname(),
+ d->config.port(), trackOffsetList );
+
+ if ( Lookup::Success != r )
+ {
+ delete cdInfoLookup;
+ cdInfoLookup = 0L;
+ }
+ }
+
+ return r;
+ }
+
+ void
+ Client::slotFinished( CDDB::Result r )
+ {
+ if ( cdInfoLookup && CDDB::Success == r )
+ {
+ d->cdInfoList = cdInfoLookup->lookupResponse();
+ Cache::store( d->cdInfoList );
+ }
+ else
+ d->cdInfoList.clear();
+
+ emit finished( r );
+
+ if ( cdInfoLookup ) // in case someone called lookup() while finished() was being processed, and deleted cdInfoLookup.
+ {
+ cdInfoLookup->deleteLater();
+ cdInfoLookup = 0L;
+ }
+ }
+
+ void
+ Client::slotSubmitFinished( CDDB::Result r )
+ {
+ emit finished( r );
+
+ cdInfoSubmit->deleteLater();
+ cdInfoSubmit=0L;
+ }
+
+ CDDB::Result
+ Client::submit(const CDInfo &cdInfo, const TrackOffsetList& offsetList)
+ {
+ // Check if it's valid
+
+ if (!cdInfo.isValid())
+ return CDDB::CannotSave;
+
+ uint last=0;
+ for (uint i=0; i < (offsetList.count()-2); i++)
+ {
+ if(last >= offsetList[i])
+ return CDDB::CannotSave;
+ last = offsetList[i];
+ }
+
+ //TODO Check that it is edited
+
+ // just in case we have a cdInfoSubmit, prevent memory leakage
+ delete cdInfoSubmit;
+
+ QString from = d->config.emailAddress();
+
+ switch (d->config.submitTransport())
+ {
+ case Submit::HTTP:
+ {
+ QString hostname = d->config.httpSubmitServer();
+ uint port = d->config.httpSubmitPort();
+
+ if ( blockingMode() )
+ cdInfoSubmit = new SyncHTTPSubmit(from, hostname, port);
+ else
+ {
+ cdInfoSubmit = new AsyncHTTPSubmit(from, hostname, port);
+ connect( static_cast<AsyncHTTPSubmit *>( cdInfoSubmit ),
+ SIGNAL(finished( CDDB::Result ) ),
+ SLOT( slotSubmitFinished( CDDB::Result ) ) );
+ }
+
+ break;
+ }
+ case Submit::SMTP:
+ {
+ QString hostname = d->config.smtpHostname();
+ uint port = d->config.smtpPort();
+ QString username = d->config.smtpUsername();
+
+ if ( blockingMode() )
+ cdInfoSubmit = new SyncSMTPSubmit( hostname, port, username, from, d->config.submitAddress() );
+ else
+ {
+ cdInfoSubmit = new AsyncSMTPSubmit( hostname, port, username, from, d->config.submitAddress() );
+ connect( static_cast<AsyncSMTPSubmit *>( cdInfoSubmit ),
+ SIGNAL( finished( CDDB::Result ) ),
+ SLOT( slotSubmitFinished( CDDB::Result ) ) );
+ }
+ break;
+ }
+ default:
+ kdDebug(60010) << k_funcinfo << "Unsupported transport: " << endl;
+// << CDDB::transportToString(d->config.submitTransport()) << endl;
+ return CDDB::UnknownError;
+ break;
+ }
+
+ CDDB::Result r = cdInfoSubmit->submit( cdInfo, offsetList );
+
+ if ( blockingMode() )
+ {
+ delete cdInfoSubmit;
+ cdInfoSubmit = 0L;
+ }
+
+ return r;
+ }
+}
+
+#include "client.moc"
+
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/client.h b/libkcddb/client.h
new file mode 100644
index 00000000..08188bb9
--- /dev/null
+++ b/libkcddb/client.h
@@ -0,0 +1,104 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_CLIENT_H
+#define KCDDB_CLIENT_H
+
+#include "config.h"
+#include "cdinfo.h"
+#include <qobject.h>
+#include "cddb.h"
+#include <kdemacros.h>
+
+namespace KCDDB
+{
+ class Lookup;
+ class Submit;
+
+ /**
+ * Class used to obtain CDDB information about a CD
+ *
+ * Example:
+ * <code>KCDDB::Client *cddb = new KCDDB::Client();
+ * cddb->lookup(discSignature);
+ * CDInfo info = cddb->bestLookupResponse();</code>
+ */
+ class KDE_EXPORT Client : public QObject
+ {
+ Q_OBJECT
+
+ public:
+
+ /**
+ * Uses settings read from config.
+ */
+ Client();
+
+ virtual ~Client();
+
+ Config & config() const;
+
+ /**
+ * @return a list of CDDB entries that match the disc signature
+ */
+ CDInfoList lookupResponse() const;
+ /**
+ * @return a the CDDB entries that is the best match to the disc signature
+ */
+ CDInfo bestLookupResponse() const;
+
+ /**
+ * @return if the results of the lookup: Success, NoRecordFound, etc
+ */
+ CDDB::Result lookup(const TrackOffsetList &trackOffsetList);
+ /**
+ * @returns the results of trying to submit
+ */
+ CDDB::Result submit(const CDInfo &cdInfo, const TrackOffsetList &trackOffsetList);
+
+ void setBlockingMode( bool );
+ bool blockingMode() const;
+
+ signals:
+ /**
+ * emited when not blocking and lookup() finished.
+ */
+ void finished( CDDB::Result result );
+
+ protected slots:
+ /**
+ * Called when the lookup is finished with the result
+ */
+ void slotFinished( CDDB::Result result );
+ /**
+ * Called when the submit is finished with the result
+ */
+ void slotSubmitFinished( CDDB::Result result );
+
+ private:
+ class Private;
+ Private * d;
+ Lookup * cdInfoLookup;
+ Submit * cdInfoSubmit;
+ };
+}
+
+#endif // KCDDB_CLIENT_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/config.cpp b/libkcddb/config.cpp
new file mode 100644
index 00000000..54e61a2a
--- /dev/null
+++ b/libkcddb/config.cpp
@@ -0,0 +1,56 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kemailsettings.h>
+
+#include <libkcddb/config.h>
+
+namespace KCDDB
+{
+ Config::Config()
+ : ConfigBase()
+ {
+ loadEmailSettings();
+ }
+
+ void Config::loadEmailSettings()
+ {
+ KEMailSettings kes;
+ kes.setProfile( kes.defaultProfileName() );
+
+ static_cast<KConfigSkeleton::ItemString *>(findItem("emailAddress"))
+ ->setDefaultValue(kes.getSetting( KEMailSettings::EmailAddress ));
+ static_cast<KConfigSkeleton::ItemString *>(findItem("replyTo"))
+ ->setDefaultValue(kes.getSetting( KEMailSettings::ReplyToAddress ));
+ static_cast<KConfigSkeleton::ItemString *>(findItem("smtpHostname"))
+ ->setDefaultValue(kes.getSetting( KEMailSettings::OutServer ));
+ }
+
+ void Config::reparse()
+ {
+ loadEmailSettings();
+
+ readConfig();
+ }
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/config.h b/libkcddb/config.h
new file mode 100644
index 00000000..ac16da6f
--- /dev/null
+++ b/libkcddb/config.h
@@ -0,0 +1,45 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_CONFIG_H
+#define KCDDB_CONFIG_H
+
+#include "cache.h"
+#include "cddb.h"
+#include "configbase.h"
+#include <qstring.h>
+#include <kdelibs_export.h>
+namespace KCDDB
+{
+ class KDE_EXPORT Config : public ConfigBase
+ {
+ public:
+ Config();
+
+ void reparse();
+ private:
+ void loadEmailSettings();
+ };
+}
+
+#endif // KCDDB_CONFIG_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/configbase.kcfgc b/libkcddb/configbase.kcfgc
new file mode 100644
index 00000000..fe089fc8
--- /dev/null
+++ b/libkcddb/configbase.kcfgc
@@ -0,0 +1,4 @@
+ClassName=ConfigBase
+File=libkcddb.kcfg
+Mutators=true
+Visibility=KDE_EXPORT
diff --git a/libkcddb/genres.cpp b/libkcddb/genres.cpp
new file mode 100644
index 00000000..1eeee324
--- /dev/null
+++ b/libkcddb/genres.cpp
@@ -0,0 +1,123 @@
+// Copyright (C) 2005 by Shaheed Haque (srhaque@iee.org). All rights reserved.
+//
+// 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.
+//
+
+#include <genres.h>
+#include <klocale.h>
+
+KCDDB::Genres::Genres()
+{
+ // The Genre is completely arbitrary. But we follow kaudiocreator's cue
+ // and make life easy for people.
+ //
+ // To cope with preexisting records which don't match an entry, we will
+ // add one later if needed.
+ m_cddb << "Unknown" << "A Cappella" << "Acid Jazz" <<
+ "Acid Punk" << "Acid" << "Acoustic" << "Alternative" <<
+ "Alt. Rock" << "Ambient" << "Anime" << "Avantgarde" <<
+ "Ballad" << "Bass" << "Beat" << "Bebop" <<
+ "Big Band" << "Black Metal" << "Bluegrass" << "Blues" <<
+ "Booty Bass" << "BritPop" << "Cabaret" << "Celtic" <<
+ "Chamber Music" << "Chanson" << "Chorus" << "Christian Gangsta Rap" <<
+ "Christian Rap" << "Christian Rock" << "Classical" << "Classic Rock" <<
+ "Club-house" << "Club" << "Comedy" << "Contemporary Christian" <<
+ "Country" << "Crossover" << "Cult" << "Dance Hall" <<
+ "Dance" << "Darkwave" << "Death Metal" << "Disco" <<
+ "Dream" << "Drum & Bass" << "Drum Solo" << "Duet" <<
+ "Easy Listening" << "Electronic" << "Ethnic" << "Eurodance" <<
+ "Euro-House" << "Euro-Techno" << "Fast-Fusion" << "Folklore" <<
+ "Folk/Rock" << "Folk" << "Freestyle" << "Funk" <<
+ "Fusion" << "Game" << "Gangsta Rap" << "Goa" <<
+ "Gospel" << "Gothic Rock" << "Gothic" << "Grunge" <<
+ "Hardcore" << "Hard Rock" << "Heavy Metal" << "Hip-Hop" <<
+ "House" << "Humor" << "Indie" << "Industrial" <<
+ "Instrumental Pop" << "Instrumental Rock" << "Instrumental" << "Jazz+Funk" <<
+ "Jazz" << "JPop" << "Jungle" << "Latin" << "Lo-Fi" <<
+ "Meditative" << "Merengue" << "Metal" << "Musical" <<
+ "National Folk" << "Native American" << "Negerpunk" << "New Age" <<
+ "New Wave" << "Noise" << "Oldies" << "Opera" <<
+ "Other" << "Polka" << "Polsk Punk" << "Pop-Funk" <<
+ "Pop/Funk" << "Pop" << "Porn Groove" << "Power Ballad" <<
+ "Pranks" << "Primus" << "Progressive Rock" << "Psychedelic Rock" <<
+ "Psychedelic" << "Punk Rock" << "Punk" << "R&B" <<
+ "Rap" << "Rave" << "Reggae" << "Retro" <<
+ "Revival" << "Rhythmic Soul" << "Rock & Roll" << "Rock" <<
+ "Salsa" << "Samba" << "Satire" << "Showtunes" <<
+ "Ska" << "Slow Jam" << "Slow Rock" << "Sonata" <<
+ "Soul" << "Sound Clip" << "Soundtrack" << "Southern Rock" <<
+ "Space" << "Speech" << "Swing" << "Symphonic Rock" <<
+ "Symphony" << "Synthpop" << "Tango" << "Techno-Industrial" <<
+ "Techno" << "Terror" << "Thrash Metal" << "Top 40" <<
+ "Trailer" << "Trance" << "Tribal" << "Trip-Hop" <<
+ "Vocal";
+ m_i18n << i18n("Unknown") << i18n("A Cappella") << i18n("Acid Jazz") <<
+ i18n("Acid Punk") << i18n("Acid") << i18n("Acoustic") << i18n("Alternative") <<
+ i18n("Alt. Rock") << i18n("Ambient") << i18n("Anime") << i18n("Avantgarde") <<
+ i18n("Ballad") << i18n("Bass") << i18n("Beat") << i18n("Bebop") <<
+ i18n("Big Band") << i18n("Black Metal") << i18n("Bluegrass") << i18n("Blues") <<
+ i18n("Booty Bass") << i18n("BritPop") << i18n("Cabaret") << i18n("Celtic") <<
+ i18n("Chamber Music") << i18n("Chanson") << i18n("Chorus") << i18n("Christian Gangsta Rap") <<
+ i18n("Christian Rap") << i18n("Christian Rock") << i18n("Classical") << i18n("Classic Rock") <<
+ i18n("Club-house") << i18n("Club") << i18n("Comedy") << i18n("Contemporary Christian") <<
+ i18n("music genre", "Country") << i18n("Crossover") << i18n("Cult") << i18n("Dance Hall") <<
+ i18n("Dance") << i18n("Darkwave") << i18n("Death Metal") << i18n("Disco") <<
+ i18n("Dream") << i18n("Drum & Bass") << i18n("Drum Solo") << i18n("Duet") <<
+ i18n("Easy Listening") << i18n("Electronic") << i18n("Ethnic") << i18n("Eurodance") <<
+ i18n("Euro-House") << i18n("Euro-Techno") << i18n("Fast-Fusion") << i18n("Folklore") <<
+ i18n("Folk/Rock") << i18n("Folk") << i18n("Freestyle") << i18n("Funk") <<
+ i18n("Fusion") << i18n("Game") << i18n("Gangsta Rap") << i18n("Goa") <<
+ i18n("Gospel") << i18n("Gothic Rock") << i18n("Gothic") << i18n("Grunge") <<
+ i18n("Hardcore") << i18n("Hard Rock") << i18n("Heavy Metal") << i18n("Hip-Hop") <<
+ i18n("House") << i18n("Humor") << i18n("Indie") << i18n("Industrial") <<
+ i18n("Instrumental Pop") << i18n("Instrumental Rock") << i18n("Instrumental") << i18n("Jazz+Funk") <<
+ i18n("Jazz") << i18n("JPop") << i18n("Jungle") << i18n("Latin") << i18n("Lo-Fi") <<
+ i18n("Meditative") << i18n("Merengue") << i18n("Metal") << i18n("Musical") <<
+ i18n("National Folk") << i18n("Native American") << i18n("Negerpunk") << i18n("New Age") <<
+ i18n("New Wave") << i18n("Noise") << i18n("Oldies") << i18n("Opera") <<
+ i18n("Other") << i18n("Polka") << i18n("Polsk Punk") << i18n("Pop-Funk") <<
+ i18n("Pop/Funk") << i18n("Pop") << i18n("Porn Groove") << i18n("Power Ballad") <<
+ i18n("Pranks") << i18n("Primus") << i18n("Progressive Rock") << i18n("Psychedelic Rock") <<
+ i18n("Psychedelic") << i18n("Punk Rock") << i18n("Punk") << i18n("R&B") <<
+ i18n("Rap") << i18n("Rave") << i18n("Reggae") << i18n("Retro") <<
+ i18n("Revival") << i18n("Rhythmic Soul") << i18n("Rock & Roll") << i18n("Rock") <<
+ i18n("Salsa") << i18n("Samba") << i18n("Satire") << i18n("Showtunes") <<
+ i18n("Ska") << i18n("Slow Jam") << i18n("Slow Rock") << i18n("Sonata") <<
+ i18n("Soul") << i18n("Sound Clip") << i18n("Soundtrack") << i18n("Southern Rock") <<
+ i18n("Space") << i18n("Speech") << i18n("Swing") << i18n("Symphonic Rock") <<
+ i18n("Symphony") << i18n("Synthpop") << i18n("Tango") << i18n("Techno-Industrial") <<
+ i18n("Techno") << i18n("Terror") << i18n("Thrash Metal") << i18n("Top 40") <<
+ i18n("Trailer") << i18n("Trance") << i18n("Tribal") << i18n("Trip-Hop") <<
+ i18n("Vocal");
+}
+
+const QString KCDDB::Genres::cddb2i18n(const QString &genre) const
+{
+ QString userDefinedGenre = genre.stripWhiteSpace();
+ int index = m_cddb.findIndex(userDefinedGenre);
+ if (index != -1)
+ {
+ return m_i18n[index];
+ }
+ else
+ {
+ return userDefinedGenre;
+ }
+}
+
+const QString KCDDB::Genres::i18n2cddb(const QString &genre) const
+{
+ QString userDefinedGenre = genre.stripWhiteSpace();
+ int index = m_i18n.findIndex(userDefinedGenre);
+ if (index != -1)
+ {
+ return m_cddb[index];
+ }
+ else
+ {
+ return userDefinedGenre;
+ }
+}
diff --git a/libkcddb/genres.h b/libkcddb/genres.h
new file mode 100644
index 00000000..4456f894
--- /dev/null
+++ b/libkcddb/genres.h
@@ -0,0 +1,43 @@
+// Copyright (C) 2005 by Shaheed Haque (srhaque@iee.org). All rights reserved.
+//
+// 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.
+//
+#ifndef KCDDB_GENRES_H
+#define KCDDB_GENRES_H
+
+#include <qstring.h>
+#include <qstringlist.h>
+
+namespace KCDDB
+{
+ /**
+ * The Genre is completely arbitrary. But we follow kaudiocreator's cue
+ * and make life easy for people.
+ */
+ class Genres
+ {
+ public:
+ Genres();
+
+ const QStringList &cddbList() const { return m_cddb; };
+ const QStringList &i18nList() const { return m_i18n; };
+
+ /**
+ * Lookup the CDDB genre, and return the i18n'd version.
+ */
+ const QString cddb2i18n(const QString &genre) const;
+
+ /**
+ * Lookup the i18n genre, and return the CDDB version if we can.
+ */
+ const QString i18n2cddb(const QString &genre) const;
+ private:
+ QStringList m_cddb;
+ QStringList m_i18n;
+ };
+}
+
+#endif
diff --git a/libkcddb/httplookup.cpp b/libkcddb/httplookup.cpp
new file mode 100644
index 00000000..f85da894
--- /dev/null
+++ b/libkcddb/httplookup.cpp
@@ -0,0 +1,186 @@
+/*
+ Copyright ( C ) 2002 Rik Hemsley ( rikkus ) <rik@kde.org>
+ Copyright ( C ) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright ( C ) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or ( at your option ) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kio/job.h>
+#include <kdebug.h>
+
+#include "httplookup.h"
+
+namespace KCDDB
+{
+ HTTPLookup::HTTPLookup()
+ : Lookup(),
+ block_( true ), state_( Idle ), result_( Success )
+ {
+ }
+
+ HTTPLookup::~HTTPLookup()
+ {
+ }
+
+ CDDB::Result
+ HTTPLookup::sendQuery()
+ {
+ QString cmd = QString( "cddb query %1 %2" )
+ .arg( trackOffsetListToId(), trackOffsetListToString() ) ;
+
+ makeURL( cmd );
+ Result result = fetchURL();
+
+ return result;
+ }
+
+ CDDB::Result
+ HTTPLookup::sendRead( const CDDBMatch & match )
+ {
+ category_ = match.first;
+ QString discid = match.second;
+
+ QString cmd = QString( "cddb read %1 %2" )
+ .arg( category_, discid );
+
+ makeURL( cmd );
+ Result result = fetchURL();
+
+ return result;
+ }
+
+ void
+ HTTPLookup::initURL( const QString & hostName, uint port )
+ {
+ cgiURL_.setProtocol( "http" );
+ cgiURL_.setHost( hostName );
+ cgiURL_.setPort( port );
+ cgiURL_.setPath( "/~cddb/cddb.cgi" );
+
+ return;
+ }
+
+ void
+ HTTPLookup::makeURL( const QString & cmd )
+ {
+ // The whole query has to constructed each time as the
+ // CDDB CGI script expects the parameters in strict order
+
+ cgiURL_.setQuery( QString::null );
+
+ QString hello = QString("%1 %2 %3 %4")
+ .arg(user_, localHostName_, clientName(), clientVersion());
+
+ cgiURL_.addQueryItem( "cmd", cmd );
+ cgiURL_.addQueryItem( "hello", hello );
+ cgiURL_.addQueryItem( "proto", "6" );
+ }
+
+ void
+ HTTPLookup::jobFinished()
+ {
+ QStringList lineList = QStringList::split( "\n", QString::fromUtf8(data_, data_.size()) );
+ QStringList::ConstIterator it = lineList.begin();
+
+ switch ( state_ )
+ {
+ case WaitingForQueryResponse:
+
+ if ( it != lineList.end() )
+ {
+ QString line( *it );
+
+ result_ = parseQuery( line );
+
+ switch ( result_ )
+ {
+ case Success:
+
+ if ( !block_ )
+ emit queryReady();
+ break;
+
+ case MultipleRecordFound:
+
+ ++it;
+ while ( it != lineList.end() )
+ {
+ QString line( *it );
+
+ if ( '.' == line[ 0 ] )
+ {
+ result_ = Success;
+
+ if ( !block_ )
+ emit queryReady();
+ break;
+ }
+
+ parseExtraMatch( line );
+ ++it;
+ }
+
+ break;
+
+ case ServerError:
+ case NoRecordFound:
+ if ( !block_ )
+ emit queryReady();
+
+ return;
+ break;
+
+ default:
+
+ break;
+ }
+
+ }
+
+ break;
+
+ case WaitingForReadResponse:
+
+ {
+ CDInfo info;
+
+ if ( info.load( QString::fromUtf8(data_,data_.size()) ) )
+ {
+ info.category = category_;
+ cdInfoList_.append( info );
+ }
+
+ if ( !block_ )
+ emit readReady();
+ }
+
+ return;
+
+ break;
+
+ default:
+
+ break;
+ }
+
+ result_ = Success;
+ }
+}
+
+#include "httplookup.moc"
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/httplookup.h b/libkcddb/httplookup.h
new file mode 100644
index 00000000..7404accd
--- /dev/null
+++ b/libkcddb/httplookup.h
@@ -0,0 +1,82 @@
+/*
+ Copyright (C) 2002 Rik Hemsley ( rikkus ) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or ( at your option ) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_HTTP_LOOKUP_H
+#define KCDDB_HTTP_LOOKUP_H
+
+#include <kurl.h>
+
+#include "lookup.h"
+
+namespace KIO
+{
+ class TransferJob;
+ class Job;
+}
+
+namespace KCDDB
+{
+ class HTTPLookup : public Lookup
+ {
+
+ Q_OBJECT
+
+ public:
+
+ enum State
+ {
+ Idle,
+ WaitingForQueryResponse,
+ WaitingForReadResponse
+ };
+
+ HTTPLookup();
+ virtual ~HTTPLookup();
+
+ protected:
+
+ void initURL( const QString &, uint );
+ void makeURL( const QString & );
+ virtual Result fetchURL() = 0;
+
+ void jobFinished();
+
+ Result sendQuery();
+ Result sendRead( const CDDBMatch & );
+
+ signals:
+
+ void queryReady();
+ void readReady();
+
+ protected:
+
+ bool block_;
+ KURL cgiURL_;
+ QByteArray data_;
+ State state_;
+ Result result_;
+ };
+}
+
+#endif
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/httpsubmit.cpp b/libkcddb/httpsubmit.cpp
new file mode 100644
index 00000000..9b06fcb2
--- /dev/null
+++ b/libkcddb/httpsubmit.cpp
@@ -0,0 +1,60 @@
+/*
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+#include "httpsubmit.h"
+#include <kdebug.h>
+#include <kio/job.h>
+
+namespace KCDDB
+{
+ HTTPSubmit::HTTPSubmit(const QString& from, const QString& hostname, uint port)
+ : Submit(), from_(from)
+ {
+ url_.setProtocol("http");
+ url_.setHost(hostname);
+ url_.setPort(port);
+ url_.setPath("/~cddb/submit.cgi");
+ }
+
+ HTTPSubmit::~HTTPSubmit()
+ {
+
+ }
+
+ KIO::Job* HTTPSubmit::createJob(const CDInfo& cdInfo)
+ {
+ KIO::TransferJob* job = KIO::http_post(url_, diskData_.utf8(), false);
+
+ job->addMetaData("content-type", "Content-Type: text/plain");
+ QString header;
+
+ header += "Content-Type: text/plain\n";
+
+ header += "Category: " + cdInfo.category + "\n";
+ header += "Discid: " + cdInfo.id + "\n";
+ header += "User-Email: " + from_ + "\n";
+ // Change to test for testing
+ header += "Submit-Mode: submit\n";
+ header += "Charset: UTF-8";
+
+ job->addMetaData("customHTTPHeader", header);
+
+ return job;
+ }
+}
diff --git a/libkcddb/httpsubmit.h b/libkcddb/httpsubmit.h
new file mode 100644
index 00000000..0ab3c72a
--- /dev/null
+++ b/libkcddb/httpsubmit.h
@@ -0,0 +1,41 @@
+#ifndef HTTPSUBMIT_H
+#define HTTPSUBMIT_H
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "submit.h"
+#include <kurl.h>
+
+namespace KCDDB
+{
+ class HTTPSubmit : public Submit
+ {
+ public:
+ HTTPSubmit(const QString& from, const QString& hostname, uint port);
+ virtual ~HTTPSubmit();
+
+ protected:
+ virtual KIO::Job* createJob(const CDInfo& cdInfo);
+
+ KURL url_;
+ QString from_;
+ } ;
+}
+
+#endif // HTTPSUBMIT_H
diff --git a/libkcddb/kcmcddb/Makefile.am b/libkcddb/kcmcddb/Makefile.am
new file mode 100644
index 00000000..cc638047
--- /dev/null
+++ b/libkcddb/kcmcddb/Makefile.am
@@ -0,0 +1,23 @@
+INCLUDES = -I$(srcdir)/../.. -I.. $(all_includes)
+
+kde_module_LTLIBRARIES = kcm_cddb.la
+
+kcm_cddb_la_SOURCES = \
+ cddbconfigwidgetbase.ui cddbconfigwidget.cpp kcmcddb.cpp
+
+kcm_cddb_la_LDFLAGS = \
+ $(all_libraries) -module -avoid-version -no-undefined
+
+kcm_cddb_la_LIBADD = ../libkcddb.la $(LIB_KDEUI)
+
+kcm_cddb_la_COMPILE_FIRST = ../configbase.h
+
+METASOURCES = AUTO
+
+xdg_apps_DATA = libkcddb.desktop
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kcmcddb.pot
+
+updatedir = $(kde_datadir)/kconf_update
+update_DATA = kcmcddb-emailsettings.upd
diff --git a/libkcddb/kcmcddb/cddbconfigwidget.cpp b/libkcddb/kcmcddb/cddbconfigwidget.cpp
new file mode 100644
index 00000000..067af2e0
--- /dev/null
+++ b/libkcddb/kcmcddb/cddbconfigwidget.cpp
@@ -0,0 +1,108 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2004 Richard Lärkäng <nouseforaname@home.se>
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "cddbconfigwidget.h"
+
+#include "libkcddb/sites.h"
+#include "libkcddb/lookup.h"
+
+#include <qlistbox.h>
+#include <qcombobox.h>
+#include <qspinbox.h>
+#include <qlineedit.h>
+#include <kfiledialog.h>
+#include <kapplication.h>
+#include <klocale.h>
+#include <kinputdialog.h>
+#include <kmessagebox.h>
+#include <keditlistbox.h>
+#include <qwidgetstack.h>
+#include <kurlrequester.h>
+#include <qbuttongroup.h>
+#include <qcheckbox.h>
+
+CDDBConfigWidget::CDDBConfigWidget(QWidget * parent, const char * name)
+ : CDDBConfigWidgetBase(parent, name)
+{
+ // Connections from widgets are made in designer.
+
+ KURLRequester* urlReq = new KURLRequester(this);
+ urlReq->setMode(KFile::Directory);
+
+ KEditListBox* editListBox = new KEditListBox(i18n("Cache Locations"), urlReq->customEditor(), cacheLocationsParent, "kcfg_cacheLocations");
+ cacheLocationsParent->raiseWidget(editListBox);
+
+ kcfg_submitTransport->remove(needsAuthenticationBox);
+}
+
+void CDDBConfigWidget::showMirrorList()
+{
+ KCDDB::Sites s;
+
+ QValueList<KCDDB::Mirror> sites = s.siteList();
+ QMap<QString, KCDDB::Mirror> keys;
+ for (QValueList<KCDDB::Mirror>::Iterator it = sites.begin(); it != sites.end(); ++it)
+ if ((*it).transport == KCDDB::Lookup::CDDBP)
+ keys[(*it).address + "(CDDBP, " + QString::number((*it).port) + ") " + (*it).description] = *it;
+ else
+ keys[(*it).address + "(HTTP, " + QString::number((*it).port) + ") " + (*it).description] = *it;
+
+ bool ok;
+
+ if (keys.isEmpty())
+ {
+ KMessageBox::information(this, i18n("Could not fetch mirror list."), i18n("Could Not Fetch"));
+ return;
+ }
+
+ QStringList result = KInputDialog::getItemList(i18n("Select mirror"),
+ i18n("Select one of these mirrors"), keys.keys(),
+ QStringList(), false, &ok, this);
+
+ if (ok && result.count() == 1)
+ {
+ KCDDB::Mirror m = keys[*(result.begin())];
+
+ kcfg_lookupTransport->setCurrentItem(m.transport == KCDDB::Lookup::CDDBP ? 0 : 1);
+ kcfg_hostname->setText(m.address);
+ kcfg_port->setValue(m.port);
+ }
+}
+
+void CDDBConfigWidget::protocolChanged()
+{
+ // Change the port if the port is the default-value for the old protocol
+
+ if (kcfg_lookupTransport->currentText() == i18n("HTTP") && kcfg_port->value() == 8880)
+ kcfg_port->setValue(80);
+ else if (kcfg_lookupTransport->currentText() == i18n("CDDB") && kcfg_port->value() == 80)
+ kcfg_port->setValue(8880);
+}
+
+void CDDBConfigWidget::needAuthenticationChanged(bool needsAuth)
+{
+ kcfg_smtpUsername->setEnabled(needsAuth);
+ if (!needsAuth)
+ kcfg_smtpUsername->clear();
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
+
+#include "cddbconfigwidget.moc"
diff --git a/libkcddb/kcmcddb/cddbconfigwidget.h b/libkcddb/kcmcddb/cddbconfigwidget.h
new file mode 100644
index 00000000..3d9136e6
--- /dev/null
+++ b/libkcddb/kcmcddb/cddbconfigwidget.h
@@ -0,0 +1,43 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef CDDB_CONFIG_WIDGET_H
+#define CDDB_CONFIG_WIDGET_H
+
+#include "cddbconfigwidgetbase.h"
+
+class CDDBConfigWidget : public CDDBConfigWidgetBase
+{
+ Q_OBJECT
+
+ public:
+
+ CDDBConfigWidget(QWidget * parent = 0, const char * name = 0);
+
+ protected slots:
+
+ virtual void showMirrorList();
+
+ virtual void protocolChanged();
+
+ virtual void needAuthenticationChanged(bool);
+};
+
+#endif // CDDB_CONFIG_WIDGET_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/kcmcddb/cddbconfigwidgetbase.ui b/libkcddb/kcmcddb/cddbconfigwidgetbase.ui
new file mode 100644
index 00000000..2158159a
--- /dev/null
+++ b/libkcddb/kcmcddb/cddbconfigwidgetbase.ui
@@ -0,0 +1,594 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>CDDBConfigWidgetBase</class>
+<comment>Used for configuring libkcddb.</comment>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>CDDBConfigWidgetBase</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>452</width>
+ <height>573</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>CDDB Settings</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <widget class="QTabWidget">
+ <property name="name">
+ <cstring>tabWidget2</cstring>
+ </property>
+ <widget class="QWidget">
+ <property name="name">
+ <cstring>tab</cstring>
+ </property>
+ <attribute name="title">
+ <string>&amp;Lookup</string>
+ </attribute>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QButtonGroup">
+ <property name="name">
+ <cstring>kcfg_cachePolicy</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>4</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Mode</string>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>6</number>
+ </property>
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>cacheOnly</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Cache only</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Only check in the local cache for CD information.</string>
+ </property>
+ </widget>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>cacheAndRemote</cstring>
+ </property>
+ <property name="text">
+ <string>Cache &amp;and remote</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Check for locally cached CD information before trying to look up at remote CDDB server.</string>
+ </property>
+ </widget>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>remoteOnly</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Remote only</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Only try to look up at remote CDDB server.</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>serverBox</cstring>
+ </property>
+ <property name="title">
+ <string>CDDB Server</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>11</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>TextLabel7</cstring>
+ </property>
+ <property name="text">
+ <string>CDD&amp;B server:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>kcfg_hostname</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="1" column="0">
+ <property name="name">
+ <cstring>TextLabel9</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Transport:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>kcfg_lookupTransport</cstring>
+ </property>
+ </widget>
+ <widget class="QComboBox" row="1" column="1">
+ <item>
+ <property name="text">
+ <string>CDDB</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>HTTP</string>
+ </property>
+ </item>
+ <property name="name">
+ <cstring>kcfg_lookupTransport</cstring>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Type of lookup which should be tried at the CDDB server.</string>
+ </property>
+ </widget>
+ <widget class="KPushButton" row="1" column="2" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>mirrorListButton</cstring>
+ </property>
+ <property name="text">
+ <string>Show &amp;Mirror List</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox" row="0" column="4">
+ <property name="name">
+ <cstring>kcfg_port</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>4</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maxValue">
+ <number>64000</number>
+ </property>
+ <property name="value">
+ <number>8880</number>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Port to connect to on CDDB server.</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="0" column="3">
+ <property name="name">
+ <cstring>TextLabel8</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Port:</string>
+ </property>
+ <property name="alignment">
+ <set>AlignVCenter|AlignRight</set>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>kcfg_port</cstring>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="0" column="1" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>kcfg_hostname</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>freedb.freedb.org</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Name of CDDB server which will be used to look up CD information.</string>
+ </property>
+ </widget>
+ </grid>
+ </widget>
+ <widget class="QWidgetStack">
+ <property name="name">
+ <cstring>cacheLocationsParent</cstring>
+ </property>
+ <widget class="QWidget">
+ <property name="name">
+ <cstring>WStackPage</cstring>
+ </property>
+ <attribute name="id">
+ <number>0</number>
+ </attribute>
+ </widget>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer5</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>41</width>
+ <height>260</height>
+ </size>
+ </property>
+ </spacer>
+ </vbox>
+ </widget>
+ <widget class="QWidget">
+ <property name="name">
+ <cstring>tab</cstring>
+ </property>
+ <attribute name="title">
+ <string>&amp;Submit</string>
+ </attribute>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLineEdit" row="0" column="1">
+ <property name="name">
+ <cstring>kcfg_emailAddress</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>Email address:</string>
+ </property>
+ </widget>
+ <spacer row="2" column="1">
+ <property name="name">
+ <cstring>spacer4</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>21</width>
+ <height>240</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QButtonGroup" row="1" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>kcfg_submitTransport</cstring>
+ </property>
+ <property name="title">
+ <string>Submit Method</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <spacer row="7" column="1">
+ <property name="name">
+ <cstring>spacer9</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Fixed</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>21</width>
+ <height>21</height>
+ </size>
+ </property>
+ </spacer>
+ <spacer row="1" column="0">
+ <property name="name">
+ <cstring>spacer10</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Fixed</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>21</width>
+ <height>21</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QLabel" row="1" column="1" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>textLabel2</cstring>
+ </property>
+ <property name="text">
+ <string>Server:</string>
+ </property>
+ </widget>
+ <widget class="QRadioButton" row="2" column="0" rowspan="1" colspan="6">
+ <property name="name">
+ <cstring>radioButton8</cstring>
+ </property>
+ <property name="text">
+ <string>SMTP (Email)</string>
+ </property>
+ <property name="buttonGroupId">
+ <number>1</number>
+ </property>
+ </widget>
+ <spacer row="3" column="0" rowspan="5" colspan="1">
+ <property name="name">
+ <cstring>spacer7</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Fixed</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>140</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QRadioButton" row="0" column="0" rowspan="1" colspan="4">
+ <property name="name">
+ <cstring>radioButton6</cstring>
+ </property>
+ <property name="text">
+ <string>HTTP</string>
+ </property>
+ <property name="buttonGroupId">
+ <number>0</number>
+ </property>
+ </widget>
+ <widget class="KLineEdit" row="1" column="4" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>kcfg_httpSubmitServer</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="1" column="6">
+ <property name="name">
+ <cstring>textLabel1_2</cstring>
+ </property>
+ <property name="text">
+ <string>Port:</string>
+ </property>
+ <property name="alignment">
+ <set>AlignVCenter|AlignRight</set>
+ </property>
+ </widget>
+ <widget class="QSpinBox" row="1" column="7">
+ <property name="name">
+ <cstring>kcfg_httpSubmitPort</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="3" column="1" rowspan="1" colspan="4">
+ <property name="name">
+ <cstring>textLabel9_2</cstring>
+ </property>
+ <property name="text">
+ <string>Reply-To:</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="4" column="1" rowspan="1" colspan="4">
+ <property name="name">
+ <cstring>textLabel2_2</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>4</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>SMTP server:</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="5" column="1" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>textLabel3</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Port:</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="3" column="5" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>kcfg_replyTo</cstring>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="6" column="1" rowspan="1" colspan="7">
+ <property name="name">
+ <cstring>needsAuthenticationBox</cstring>
+ </property>
+ <property name="text">
+ <string>Server needs authentication</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="4" column="5" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>kcfg_smtpHostname</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="7" column="2" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>textLabel4</cstring>
+ </property>
+ <property name="text">
+ <string>Username:</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="7" column="5" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>kcfg_smtpUsername</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ <widget class="QSpinBox" row="5" column="3" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>kcfg_smtpPort</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>4</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maxValue">
+ <number>65535</number>
+ </property>
+ <property name="value">
+ <number>25</number>
+ </property>
+ </widget>
+ <spacer row="5" column="5" rowspan="1" colspan="3">
+ <property name="name">
+ <cstring>spacer6</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>260</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </grid>
+ </widget>
+ </grid>
+ </widget>
+ </widget>
+ </vbox>
+</widget>
+<customwidgets>
+</customwidgets>
+<connections>
+ <connection>
+ <sender>cacheOnly</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>serverBox</receiver>
+ <slot>setDisabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>cacheAndRemote</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>serverBox</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>remoteOnly</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>serverBox</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>needsAuthenticationBox</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>CDDBConfigWidgetBase</receiver>
+ <slot>needAuthenticationChanged(bool)</slot>
+ </connection>
+ <connection>
+ <sender>kcfg_lookupTransport</sender>
+ <signal>activated(int)</signal>
+ <receiver>CDDBConfigWidgetBase</receiver>
+ <slot>protocolChanged()</slot>
+ </connection>
+ <connection>
+ <sender>mirrorListButton</sender>
+ <signal>clicked()</signal>
+ <receiver>CDDBConfigWidgetBase</receiver>
+ <slot>showMirrorList()</slot>
+ </connection>
+</connections>
+<tabstops>
+ <tabstop>tabWidget2</tabstop>
+ <tabstop>cacheOnly</tabstop>
+ <tabstop>cacheAndRemote</tabstop>
+ <tabstop>remoteOnly</tabstop>
+ <tabstop>kcfg_hostname</tabstop>
+ <tabstop>kcfg_port</tabstop>
+ <tabstop>kcfg_lookupTransport</tabstop>
+</tabstops>
+<slots>
+ <slot access="protected">protocolChanged()</slot>
+ <slot access="protected">showMirrorList()</slot>
+ <slot access="protected">needAuthenticationChanged(bool)</slot>
+</slots>
+<layoutdefaults spacing="11" margin="6"/>
+<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/>
+<includehints>
+ <includehint>kpushbutton.h</includehint>
+ <includehint>klineedit.h</includehint>
+</includehints>
+</UI>
diff --git a/libkcddb/kcmcddb/kcmcddb-emailsettings.upd b/libkcddb/kcmcddb/kcmcddb-emailsettings.upd
new file mode 100644
index 00000000..4fc6c111
--- /dev/null
+++ b/libkcddb/kcmcddb/kcmcddb-emailsettings.upd
@@ -0,0 +1,6 @@
+Id=kcmcddb_emailsettings
+File=kcmcddbrc
+Group=Submit
+Key=ownEmail,emailAddress
+Key=ownReplyTo,replyTo
+Key=ownSmtpHost,smtpHostname
diff --git a/libkcddb/kcmcddb/kcmcddb.cpp b/libkcddb/kcmcddb/kcmcddb.cpp
new file mode 100644
index 00000000..d5ca04a7
--- /dev/null
+++ b/libkcddb/kcmcddb/kcmcddb.cpp
@@ -0,0 +1,132 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include <qlayout.h>
+#include <qcheckbox.h>
+#include <qcombobox.h>
+#include <qspinbox.h>
+#include <qlineedit.h>
+#include <qradiobutton.h>
+#include <qlistbox.h>
+#include <qlabel.h>
+#include <qbuttongroup.h>
+
+#include <kconfig.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kgenericfactory.h>
+#include <kmessagebox.h>
+#include <kconfigdialogmanager.h>
+
+#include "cddbconfigwidget.h"
+
+#include "kcmcddb.h"
+#include "libkcddb/lookup.h"
+#include "libkcddb/cache.h"
+#include "libkcddb/submit.h"
+
+typedef KGenericFactory<CDDBModule, QWidget> KCDDBFactory;
+K_EXPORT_COMPONENT_FACTORY ( kcm_cddb, KCDDBFactory( "kcmcddb" ) )
+
+CDDBModule::CDDBModule(QWidget *parent, const char *name, const QStringList &)
+ : KCModule(parent, name)
+{
+ KGlobal::locale()->insertCatalogue("libkcddb");
+ setButtons(Default | Apply);
+
+ widget_ = new CDDBConfigWidget(this);
+
+ KCDDB::Config* cfg = new KCDDB::Config();
+ cfg->readConfig();
+
+ addConfig(cfg, widget_);
+
+ QVBoxLayout * layout = new QVBoxLayout(this, 0);
+
+ layout->addWidget(widget_);
+ layout->addStretch();
+
+ setQuickHelp(i18n("CDDB is used to get information like artist, title and song-names in CD's"));
+
+ load();
+}
+
+ void
+CDDBModule::defaults()
+{
+ KCModule::defaults();
+
+ updateWidgetsFromConfig(KCDDB::Config());
+}
+
+ void
+CDDBModule::checkSettings() const
+{
+ KCDDB::Config config;
+
+ config.readConfig();
+
+ if (config.smtpHostname().isEmpty() || config.emailAddress().isEmpty()
+ || !config.emailAddress().contains("@") ||
+ (!config.replyTo().isEmpty() && !config.replyTo().contains("@")))
+
+ {
+ if (config.submitTransport() == KCDDB::Submit::SMTP)
+ {
+ KMessageBox::sorry(widget_, i18n("freedb has been set to use HTTP for submissions "
+ "because the email details you have entered are "
+ "incomplete. Please review your email settings "
+ "and try again."), i18n("Incorrect Email Settings"));
+ config.setSubmitTransport(KCDDB::Submit::HTTP);
+
+ config.writeConfig();
+ }
+ }
+}
+
+ void
+CDDBModule::updateWidgetsFromConfig(const KCDDB::Config & config)
+{
+ bool smtpUserIsEmpty = config.smtpUsername().isEmpty();
+ widget_->needsAuthenticationBox->setChecked(!smtpUserIsEmpty);
+ widget_->kcfg_smtpUsername->setEnabled(!smtpUserIsEmpty);
+}
+
+ void
+CDDBModule::save()
+{
+ KCModule::save();
+
+ checkSettings();
+}
+
+ void
+CDDBModule::load()
+{
+ KCModule::load();
+
+ KCDDB::Config config;
+ config.readConfig();
+ updateWidgetsFromConfig(config);
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
+
+#include "kcmcddb.moc"
diff --git a/libkcddb/kcmcddb/kcmcddb.h b/libkcddb/kcmcddb/kcmcddb.h
new file mode 100644
index 00000000..dfb7c4ef
--- /dev/null
+++ b/libkcddb/kcmcddb/kcmcddb.h
@@ -0,0 +1,55 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCMCDDB_H
+#define KCMCDDB_H
+
+#include <kcmodule.h>
+
+#include "libkcddb/config.h"
+
+class CDDBConfigWidgetBase;
+class KConfigDialogManager;
+
+class CDDBModule : public KCModule
+{
+ Q_OBJECT
+
+ public:
+
+ CDDBModule(QWidget * parent, const char *name, const QStringList &);
+
+ public slots:
+
+ void defaults();
+ void save();
+ void load();
+
+ protected:
+
+ void checkSettings() const;
+ void updateWidgetsFromConfig(const KCDDB::Config &);
+
+ private:
+
+ CDDBConfigWidgetBase * widget_;
+};
+
+#endif // KCMCDDB_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/kcmcddb/libkcddb.desktop b/libkcddb/kcmcddb/libkcddb.desktop
new file mode 100644
index 00000000..0c6e659c
--- /dev/null
+++ b/libkcddb/kcmcddb/libkcddb.desktop
@@ -0,0 +1,187 @@
+[Desktop Entry]
+Exec=kcmshell libkcddb
+Icon=cdaudio_unmount
+Type=Application
+X-KDE-ModuleType=Library
+X-KDE-Library=cddb
+
+Name=CDDB Retrieval
+Name[bg]=Извличане от CDDB
+Name[bs]=CDDB dobavljanje
+Name[ca]=Recuperació CDDB
+Name[cs]=Získání CDDB
+Name[cy]=Cyrchu CDDB
+Name[da]=CDDB-Hentning
+Name[de]=CDDB-Abfrage
+Name[el]=Ανάκτηση CDDB
+Name[eo]=CDDB-serĉo
+Name[es]=Recuperador de CDDB
+Name[et]=CDDB ülekanded
+Name[eu]=CDDB berreskuraketa
+Name[fa]=بازیابی CDDB
+Name[fi]=CDDB-haku
+Name[fr]=Recherche CDDB
+Name[ga]=Aisghabháil CDDB
+Name[gl]=Obtención CDDB
+Name[he]=אחזור CDDB
+Name[hi]=सीडीडीबी रिट्राइवल
+Name[hr]=Dohvat iz CDDB
+Name[hu]=CDDB-lekérdezés
+Name[is]=CDDB stillingar
+Name[it]=Recupero CDDB
+Name[ja]=CDDB 検索
+Name[kk]=CDDB деректерді алу
+Name[ko]=CDDB 가져오기
+Name[lt]=CDDB įrašo atsisiuntimas
+Name[mk]=Пребарување на CDDB
+Name[ms]=Pembuka CDDB
+Name[nb]=CDDB-henting
+Name[nds]=CDDB-Affraag
+Name[ne]=CDDB पुनः प्राप्ति
+Name[nl]=CDDB-informatie
+Name[nn]=CDDB-henting
+Name[pa]=CDDB ਪਰਾਪਤੀ
+Name[pl]=Pobieranie z CDDB
+Name[pt]=Transferência de CDDB
+Name[pt_BR]=Recuperação do CDDB
+Name[ro]=Căutare CDDB
+Name[ru]=Доступ к CDDB
+Name[sk]=Informácie z CDDB
+Name[sl]=Pridobivanje CDDB
+Name[sr]=Добављање из CDDB-а
+Name[sr@Latn]=Dobavljanje iz CDDB-a
+Name[sv]=Hämta från CDDB
+Name[ta]=குறுந்தகடு தகவல்தளம் மீட்டெடுப்பு
+Name[tg]=Бозёбии CDDB
+Name[th]=ดึงข้อมูล CDDB
+Name[tr]=CDDB Erişimi
+Name[uk]=Звантаження CDDB
+Name[ven]=U humbula ha CDDB
+Name[xh]=CDDB Ukukangela
+Name[zh_CN]=CDDB 查询
+Name[zh_HK]=CDDB 資訊擷取
+Name[zh_TW]=CDDB 取得資訊
+
+GenericName=CDDB Configuration
+GenericName[ar]=اعدادت CDDB
+GenericName[bg]=Настройки на CDDB
+GenericName[br]=Kefluniadur CDDB
+GenericName[bs]=Podešavanje CDDBa
+GenericName[ca]=Configuració CDDB
+GenericName[cs]=Nastavení CDDB
+GenericName[cy]=Ffurfweddu CDDB
+GenericName[da]=CDDB-Indstilling
+GenericName[de]=CDDB-Einrichtung
+GenericName[el]=Ρύθμιση CDDB
+GenericName[eo]=LDDB-agordo
+GenericName[es]=Configuración de CDDB
+GenericName[et]=CDDB seadistamine
+GenericName[eu]=CDDB konfigurazioa
+GenericName[fa]=پیکربندی CDDB
+GenericName[fi]=CDDB-asetukset
+GenericName[fr]=Configuration CDDB
+GenericName[ga]=Cumraíocht CDDB
+GenericName[gl]=Configuración da CDDB
+GenericName[he]=הגדרות CDDB
+GenericName[hi]=सीडीडीबी कॉन्फ़िगरेशन
+GenericName[hr]=Podešavanje CDDB-a
+GenericName[hu]=CDDB-beállító
+GenericName[is]=Stillingar CDDB
+GenericName[it]=Configurazione CDDB
+GenericName[ja]=CDDB の設定
+GenericName[kk]=CDDB баптауы
+GenericName[km]=ការ​កំណត់​រចនាសម្ព័ន្ធ CDDB
+GenericName[ko]=CDDB 설정
+GenericName[lt]=CDDB konfigūravimas
+GenericName[lv]=CDDB Konfigurācija
+GenericName[mk]=Конфигурација на CDDB
+GenericName[ms]=Penyelarasan CDDB
+GenericName[nb]=CDDB-oppsett
+GenericName[nds]=CDDB-Instellen
+GenericName[ne]=CDDB कन्फिगरेसन
+GenericName[nl]=CDDB instellingen
+GenericName[nn]=CDDB-oppsett
+GenericName[pa]=CDDB ਸੰਰਚਨਾ
+GenericName[pl]=Konfiguracja CDDB
+GenericName[pt]=Configuração do CDDB
+GenericName[pt_BR]=Configuração do CDDB
+GenericName[ro]=Configurează CDDB
+GenericName[ru]=Настройка CDDB
+GenericName[sk]=Nastavenie CDDB
+GenericName[sl]=Nastavitve CDDB
+GenericName[sr]=Подешавање CDDB-а
+GenericName[sr@Latn]=Podešavanje CDDB-a
+GenericName[sv]=CDDB-inställning
+GenericName[ta]=குறுந்தகடு தகவல்தள வடிவமைப்பு
+GenericName[tg]=Батанзимдарории CDDB
+GenericName[th]=ปรับแต่ง CDDB
+GenericName[tr]=CDDB Yapılandırması
+GenericName[uk]=Налаштування CDDB
+GenericName[uz]=CDDB moslamasi
+GenericName[uz@cyrillic]=CDDB мосламаси
+GenericName[ven]=Nzudzanyo ya CDDB
+GenericName[wa]=Apontiaedje di CDDB
+GenericName[zh_CN]=CDDB 配置
+GenericName[zh_HK]=CDDB 設定
+GenericName[zh_TW]=CDDB 設定
+GenericName[zu]=Uhlanganiso lwe CDDB
+
+Comment=Configure the CDDB Retrieval
+Comment[bg]=Настройване на извличането от CDDB
+Comment[bs]=Podesite CDDB dobavljanje
+Comment[ca]=Configura la recuperació CDDB
+Comment[cs]=Nastavení stahování z CDDB
+Comment[cy]=Ffurfweddu Nôl o'r CDDB
+Comment[da]=Indstil at hente via CDDB
+Comment[de]=CDDB-Abfrage einrichten
+Comment[el]=Ρύθμιση της ανάκτησης CDDB
+Comment[eo]=Agordi la CDDB-serĉon
+Comment[es]=Configurar el recuperador de CDDB
+Comment[et]=CDDB ülekannete seadistamine
+Comment[eu]=Konfiguratu CDDB berreskuraketa
+Comment[fa]=پیکربندی بازیابی CDDB
+Comment[fi]=Aseta CDDB-haku
+Comment[fr]=Configurer la recherche CDDB
+Comment[ga]=Cumraigh aisghabháil CDDB
+Comment[gl]=Configurar as solicitudes á CDDB
+Comment[he]=הגדר אחזור של CDDB
+Comment[hu]=A CDDB-lekérdezés beállításai
+Comment[is]=Stilling CDDB
+Comment[it]=Configura il recupero CDDB
+Comment[ja]=CDDB 検索の設定
+Comment[kk]=CDDB деректер алуды баптау
+Comment[km]=កំណត់​រចនាសម្ព័ន្ធ CDDB Retrieval
+Comment[ko]=CDDB 가져오기 설정
+Comment[lt]=Čia galite konfigūruoti CDDB įrašų atsisiuntimą
+Comment[mk]=Конфигурирање на пребарувањето на CDDB
+Comment[nb]=Oppsett av CDDB-henting
+Comment[nds]=CDDB-Affraag instellen
+Comment[ne]=CDDB पुनः प्राप्ति कन्फिगर गर्नुहोस्
+Comment[nl]=Ophalen van CDDB-informatie instellen
+Comment[nn]=Oppsett av CDDB-henting
+Comment[pa]=CDDB ਪਰਾਪਤੀ ਦੀ ਸੰਰਚਨਾ
+Comment[pl]=Konfiguracja pobierania danych z CDDB
+Comment[pt]=Configurar a Transferência de CDDB
+Comment[pt_BR]=Configurar a recuperação do CDDB
+Comment[ru]=Настройка CDDB
+Comment[sk]=Nastavenie CDDB
+Comment[sl]=Nastavi pridobivanje CDDB
+Comment[sr]=Подешавање добављања CDDB-а
+Comment[sr@Latn]=Podešavanje dobavljanja CDDB-a
+Comment[sv]=Anpassa hämtning från CDDB
+Comment[ta]=CDDB மீட்டெடுப்பை உள்ளமை
+Comment[tg]=Танзими Бозёбии CDDB
+Comment[th]=ปรับแต่งการดึงข้อมูลจาก CDDB
+Comment[tr]=CDDB Erişimini Yapılandır
+Comment[uk]=Налаштування звантаження CDDB
+Comment[zh_CN]=配置 CDDB 获取
+Comment[zh_HK]=設定 CDDB 資訊擷取
+Comment[zh_TW]=CDDB 取得資訊設定
+
+Keywords=cddb
+Keywords[bg]=компактдиск, диск, извличане, информация, песен, база, данни, cddb
+Keywords[hi]=सीडीडीबी
+Keywords[nds]=CDDB
+Keywords[ta]=குறுந்தகடு தகவல்தளம்
+
+Categories=Qt;KDE;Settings;X-KDE-settings-sound;
diff --git a/libkcddb/libkcddb.kcfg b/libkcddb/libkcddb.kcfg
new file mode 100644
index 00000000..cbd123c7
--- /dev/null
+++ b/libkcddb/libkcddb.kcfg
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+ <include>qdir.h</include>
+ <kcfgfile name="kcmcddbrc"/>
+ <group name="Lookup">
+ <entry name="hostname" type="String">
+ <default>freedb.freedb.org</default>
+ </entry>
+ <entry name="port" type="Int">
+ <default>80</default>
+ </entry>
+ <entry name="cachePolicy" type="Enum">
+ <choices>
+ <choice name="OnlyCache"></choice>
+ <choice name="UseCache"></choice>
+ <choice name="IgnoreCache"></choice>
+ </choices>
+ <default>UseCache</default>
+ </entry>
+ <entry name="lookupTransport" type="Enum">
+ <choices>
+ <choice name="CDDBP"></choice>
+ <choice name="HTTP"></choice>
+ </choices>
+ <default>HTTP</default>
+ </entry>
+ <entry name="cacheLocations" type="PathList">
+ <default code="true">QDir::homeDirPath()+"/.cddb/"</default>
+ </entry>
+ </group>
+ <group name="Submit">
+ <entry name="submitTransport" type="Enum">
+ <choices>
+ <choice name="HTTP"></choice>
+ <choice name="SMTP"></choice>
+ </choices>
+ <default>HTTP</default>
+ </entry>
+ <entry name="emailAddress" type="String">
+ </entry>
+ <entry name="httpSubmitServer" type="String">
+ <default>freedb.freedb.org</default>
+ </entry>
+ <entry name="httpSubmitPort" type="Int">
+ <default>80</default>
+ </entry>
+ <entry name="smtpPort" type="Int">
+ <default>25</default>
+ </entry>
+ <entry name="smtpUsername" type="String">
+ </entry>
+ <entry name="useGlobalEmail" type="Bool">
+ <default>true</default>
+ </entry>
+ <entry name="replyTo" type="String">
+ </entry>
+ <entry name="smtpHostname" type="String">
+ </entry>
+ <entry name="submitAddress" type="String">
+ <default>freedb-submit@freedb.org</default>
+ </entry>
+ </group>
+</kcfg>
diff --git a/libkcddb/lookup.cpp b/libkcddb/lookup.cpp
new file mode 100644
index 00000000..fb1858a3
--- /dev/null
+++ b/libkcddb/lookup.cpp
@@ -0,0 +1,87 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ CopyRight (C) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kdebug.h>
+
+#include "lookup.h"
+
+namespace KCDDB
+{
+ Lookup::Lookup()
+ : CDDB()
+ {
+ }
+
+ Lookup::~Lookup()
+ {
+ // Empty.
+ }
+
+ CDDB::Result
+ Lookup::parseQuery( const QString & line )
+ {
+ uint serverStatus = statusCode( line );
+
+ if ( 200 == serverStatus )
+ {
+ QStringList tokenList = QStringList::split( ' ', line );
+ matchList_.append( qMakePair( tokenList[ 1 ], tokenList[ 2 ] ) );
+ return Success;
+ }
+ else if ( ( 211 == serverStatus ) || ( 210 == serverStatus ) )
+ {
+ return MultipleRecordFound;
+ }
+ else if ( 202 == serverStatus )
+ {
+ return NoRecordFound;
+ }
+
+ return ServerError;
+ }
+
+ void
+ Lookup::parseExtraMatch( const QString & line )
+ {
+ QStringList tokenList = QStringList::split( ' ', line );
+ matchList_.append( qMakePair( tokenList[ 0 ], tokenList[ 1 ] ) );
+ }
+
+ CDDB::Result
+ Lookup::parseRead( const QString & line )
+ {
+ uint serverStatus = statusCode( line );
+
+ if ( 210 != serverStatus )
+ return ServerError;
+
+ return Success;
+ }
+
+ CDInfoList
+ Lookup::lookupResponse() const
+ {
+ return cdInfoList_;
+ }
+
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/lookup.h b/libkcddb/lookup.h
new file mode 100644
index 00000000..03761a55
--- /dev/null
+++ b/libkcddb/lookup.h
@@ -0,0 +1,65 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ CopyRight (C) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_LOOKUP_H
+#define KCDDB_LOOKUP_H
+
+#include "cddb.h"
+#include "cdinfo.h"
+#include <qobject.h>
+
+namespace KCDDB
+{
+ typedef QPair<QString, QString> CDDBMatch;
+ typedef QValueList<CDDBMatch> CDDBMatchList;
+
+ class Lookup : public CDDB, public QObject
+ {
+ public:
+
+ enum Transport
+ {
+ CDDBP,
+ HTTP
+ };
+
+
+ Lookup();
+ virtual ~Lookup();
+
+ virtual Result lookup( const QString &, uint, const TrackOffsetList & ) = 0;
+
+ CDInfoList lookupResponse() const;
+
+ protected:
+
+ void parseExtraMatch( const QString & );
+ Result parseQuery( const QString & );
+ Result parseRead( const QString & );
+
+ CDInfoList cdInfoList_;
+ CDDBMatchList matchList_;
+ QString category_;
+ };
+}
+
+#endif // KCDDB_LOOKUP_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/sites.cpp b/libkcddb/sites.cpp
new file mode 100644
index 00000000..56eba65a
--- /dev/null
+++ b/libkcddb/sites.cpp
@@ -0,0 +1,119 @@
+/*
+ Copyright ( C ) 2004 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or ( at your option ) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "sites.h"
+#include <kurl.h>
+#include <kio/netaccess.h>
+#include <qfile.h>
+#include <kdebug.h>
+#include <qregexp.h>
+
+namespace KCDDB
+{
+ Sites::Sites()
+ : CDDB()
+ {
+
+ }
+
+ QValueList<Mirror>
+ Sites::siteList()
+ {
+ KURL url;
+ url.setProtocol( "http" );
+ url.setHost( "freedb.freedb.org" );
+ url.setPort( 80 );
+ url.setPath( "/~cddb/cddb.cgi" );
+
+ url.setQuery( QString::null );
+
+ QString hello = QString("%1 %2 %3 %4")
+ .arg(user_, localHostName_, clientName(), clientVersion());
+
+ url.addQueryItem( "cmd", "sites" );
+ url.addQueryItem( "hello", hello );
+ url.addQueryItem( "proto", "5" );
+
+ QValueList<Mirror> result;
+
+ QString tmpFile;
+ if( KIO::NetAccess::download( url, tmpFile, 0 ) )
+ {
+ result = readFile( tmpFile );
+ KIO::NetAccess::removeTempFile( tmpFile );
+ }
+
+ return result;
+ }
+
+ QValueList<Mirror>
+ Sites::readFile(const QString& fileName)
+ {
+ QValueList<Mirror> result;
+
+ QFile f(fileName);
+ if (!f.open(IO_ReadOnly))
+ {
+ kdDebug(60010) << "Couldn't read: " << fileName << endl;
+ return result;
+ }
+
+ QTextStream ts(&f);
+
+ if (statusCode(ts.readLine()) != 210)
+ return result;
+
+ while (!ts.atEnd())
+ {
+ QString line = ts.readLine();
+ if (line == ".")
+ break;
+ result << parseLine(line);
+ }
+
+ return result;
+ }
+
+ Mirror
+ Sites::parseLine(const QString& line)
+ {
+ Mirror m;
+
+ QRegExp rexp("([^ ]+) (cddbp|http) (\\d+) ([^ ]+) [N|S]\\d{3}.\\d{2} [E|W]\\d{3}.\\d{2} (.*)");
+
+ if (rexp.search(line) != -1)
+ {
+ m.address = rexp.cap(1);
+
+ if (rexp.cap(2) == "cddbp")
+ m.transport = Lookup::CDDBP;
+ else
+ m.transport = Lookup::HTTP;
+
+ m.port = rexp.cap(3).toUInt();
+
+ if (m.transport == Lookup::HTTP && rexp.cap(4) != "/~cddb/cddb.cgi")
+ kdWarning() << "Non default urls are not supported for http" << endl;
+
+ m.description = rexp.cap(5);
+ }
+
+ return m;
+ }
+}
diff --git a/libkcddb/sites.h b/libkcddb/sites.h
new file mode 100644
index 00000000..3ef8ea05
--- /dev/null
+++ b/libkcddb/sites.h
@@ -0,0 +1,53 @@
+/*
+ Copyright ( C ) 2004 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or ( at your option ) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_SITES_H
+#define KCDDB_SITES_H
+
+#include <qvaluelist.h>
+#include "cddb.h"
+#include "lookup.h"
+#include <kdelibs_export.h>
+
+namespace KCDDB
+{
+ class Mirror
+ {
+ public:
+ QString address;
+ Lookup::Transport transport;
+ uint port;
+ QString description;
+ } ;
+
+ class KDE_EXPORT Sites : public CDDB
+ {
+ public:
+ Sites();
+
+ QValueList<Mirror> siteList();
+ private:
+ QValueList<Mirror> readFile(const QString& fileName);
+ Mirror parseLine(const QString& line);
+ } ;
+}
+
+#endif
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/smtpsubmit.cpp b/libkcddb/smtpsubmit.cpp
new file mode 100644
index 00000000..463e53ee
--- /dev/null
+++ b/libkcddb/smtpsubmit.cpp
@@ -0,0 +1,60 @@
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "smtpsubmit.h"
+#include <kdebug.h>
+#include <kio/job.h>
+
+namespace KCDDB
+{
+ SMTPSubmit::SMTPSubmit(const QString& hostname, uint port, const QString& username,
+ const QString& from, const QString& to)
+ : Submit(), from_(from), to_(to)
+ {
+ url_.setProtocol("smtp");
+ url_.setHost(hostname);
+ url_.setPort(port);
+ if (!username.isEmpty())
+ url_.setUser(username);
+ url_.setPath("/send");
+ }
+
+ SMTPSubmit::~SMTPSubmit()
+ {
+
+ }
+
+ KIO::Job* SMTPSubmit::createJob(const CDInfo& cdInfo)
+ {
+ url_.setQuery(QString("to=%1&subject=cddb %2 %3&from=%4")
+ .arg(to_, cdInfo.category, cdInfo.id, from_));
+ kdDebug(60010) << "Url is: " << url_.prettyURL() << endl;
+
+ return KIO::storedPut(diskData_.utf8(), url_, -1, false, false, false);
+ }
+
+ void SMTPSubmit::makeDiskData( const CDInfo& cdInfo, const TrackOffsetList& offsetList )
+ {
+ diskData_ = "Content-Type: text/plain; charset=\"utf-8\";";
+ diskData_ += "\n\n";
+
+ Submit::makeDiskData(cdInfo, offsetList);
+ }
+}
+
diff --git a/libkcddb/smtpsubmit.h b/libkcddb/smtpsubmit.h
new file mode 100644
index 00000000..ce126bbf
--- /dev/null
+++ b/libkcddb/smtpsubmit.h
@@ -0,0 +1,43 @@
+#ifndef SMTPSUBMIT_H
+#define SMTPSUBMIT_H
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "submit.h"
+#include <kurl.h>
+
+namespace KCDDB
+{
+ class SMTPSubmit : public Submit
+ {
+ public:
+ SMTPSubmit(const QString& hostname, uint port, const QString& username, const QString& from, const QString& to);
+ virtual ~SMTPSubmit();
+
+ protected:
+ virtual void makeDiskData( const CDInfo&, const TrackOffsetList& );
+
+ virtual KIO::Job* createJob(const CDInfo& cdInfo);
+
+ KURL url_;
+ QString from_, to_;
+ } ;
+}
+
+#endif // SMTPSUBMIT_H
diff --git a/libkcddb/submit.cpp b/libkcddb/submit.cpp
new file mode 100644
index 00000000..8e5f38f0
--- /dev/null
+++ b/libkcddb/submit.cpp
@@ -0,0 +1,101 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2003-2005 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "submit.h"
+#include <kdebug.h>
+
+namespace KCDDB
+{
+ Submit::Submit()
+ : CDDB()
+ {
+ // Empty.
+ }
+
+ Submit::~Submit()
+ {
+ // Empty.
+ }
+
+ CDDB::Result Submit::submit( CDInfo cdInfo, const TrackOffsetList& offsetList)
+ {
+ // If it was an inexact math from the server the discid might
+ // be different, so recalculate it
+ cdInfo.id = trackOffsetListToId(offsetList);
+
+ makeDiskData( cdInfo, offsetList );
+
+ if (!validCategory(cdInfo.category))
+ return InvalidCategory;
+
+ KIO::Job* job = createJob(cdInfo);
+
+ if (!job)
+ return UnknownError;
+
+ return runJob(job);
+ }
+
+ CDDB::Result
+ Submit::parseWrite( const QString & line )
+ {
+ uint serverStatus = statusCode( line );
+
+ if ( 320 != serverStatus )
+ return ServerError;
+
+ return Success;
+ }
+
+ void Submit::makeDiskData( const CDInfo& cdInfo, const TrackOffsetList& offsetList )
+ {
+ unsigned numTracks = cdInfo.trackInfoList.count();
+
+ diskData_ += "# xmcd\n";
+ diskData_ += "#\n";
+ diskData_ += "# Track frame offsets:\n";
+
+ for (uint i=0; i < numTracks; i++)
+ diskData_ += QString("#\t%1\n").arg(offsetList[i]);
+
+ int l = offsetList[numTracks+1]/75;
+ diskData_ += QString("# Disc length: %1 seconds\n").arg(l);
+
+ diskData_ += cdInfo.toString(true);
+
+ kdDebug(60010) << "diskData_ == " << diskData_ << endl;
+ }
+
+ bool Submit::validCategory( const QString& c )
+ {
+ QStringList validCategories;
+ validCategories << "blues" << "classical" << "country"
+ << "data" << "folk" << "jazz" << "misc" << "newage" << "reggae"
+ << "rock" << "soundtrack";
+
+ if (validCategories.contains(c))
+ return true;
+ else
+ return false;
+ }
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/submit.h b/libkcddb/submit.h
new file mode 100644
index 00000000..8ec51056
--- /dev/null
+++ b/libkcddb/submit.h
@@ -0,0 +1,65 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+ Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>e>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_SUBMIT_H
+#define KCDDB_SUBMIT_H
+
+#include "cddb.h"
+#include "cdinfo.h"
+#include <qobject.h>
+
+namespace KIO
+{
+ class Job;
+}
+
+namespace KCDDB
+{
+ class Submit : public CDDB, public QObject
+ {
+ public:
+
+ enum Transport
+ {
+ HTTP,
+ SMTP
+ };
+
+ Submit();
+ virtual ~Submit();
+
+ Result submit( CDInfo cdInfo, const TrackOffsetList &offsetList);
+
+ protected:
+ virtual KIO::Job* createJob(const CDInfo& cdInfo) = 0;
+ virtual Result runJob(KIO::Job* job) = 0;
+
+ bool validCategory(const QString&);
+
+ Result parseWrite( const QString & );
+ virtual void makeDiskData( const CDInfo&, const TrackOffsetList& );
+ QString diskData_;
+ };
+}
+
+#endif // KCDDB_SUBMIT_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/synccddbplookup.cpp b/libkcddb/synccddbplookup.cpp
new file mode 100644
index 00000000..30d28a87
--- /dev/null
+++ b/libkcddb/synccddbplookup.cpp
@@ -0,0 +1,222 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2005 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <qstringlist.h>
+#include <kdebug.h>
+
+#include "synccddbplookup.h"
+
+namespace KCDDB
+{
+ SyncCDDBPLookup::SyncCDDBPLookup()
+ : CDDBPLookup()
+ {
+ }
+
+ SyncCDDBPLookup::~SyncCDDBPLookup()
+ {
+ // Empty.
+ }
+
+ CDDB::Result
+ SyncCDDBPLookup::lookup
+ (
+ const QString & hostName,
+ uint port,
+ const TrackOffsetList & trackOffsetList
+ )
+ {
+ if ( trackOffsetList.count() < 3 )
+ return UnknownError;
+
+ trackOffsetList_ = trackOffsetList;
+
+ socket_ = new KNetwork::KBufferedSocket(hostName, QString::number(port));
+ socket_->setTimeout( 30000 );
+ socket_->setOutputBuffering(false);
+
+ Result result;
+
+ // Connect to server.
+ result = connect();
+ if ( Success != result )
+ return result;
+
+ // Try a handshake.
+ result = shakeHands();
+ if ( Success != result )
+ return result;
+
+ // Run a query.
+ result = runQuery();
+ if ( Success != result )
+ return result;
+
+ if (matchList_.isEmpty())
+ return NoRecordFound;
+
+ kdDebug(60010) << matchList_.count() << " matches found." << endl;
+
+ // For each match, read the cd info from the server and save it to
+ // cdInfoList.
+ CDDBMatchList::ConstIterator matchIt = matchList_.begin();
+
+ while ( matchIt != matchList_.end() )
+ {
+ CDDBMatch match( *matchIt );
+ result = matchToCDInfo( match );
+ ++matchIt;
+ }
+
+ sendQuit();
+
+ close();
+
+ return Success;
+ }
+
+ CDDB::Result
+ SyncCDDBPLookup::connect()
+ {
+ kdDebug(60010) << "Trying to connect to " << endl;
+
+ if ( !socket_->lookup() )
+ return HostNotFound;
+
+ socket_->peerResolver().wait();
+
+ if ( socket_->state() != KNetwork::KClientSocketBase::HostFound )
+ return HostNotFound;
+
+ if ( !socket_->connect() )
+ return ServerError;
+
+ socket_->waitForConnect();
+
+ return isConnected() ? Success : ServerError;
+ }
+
+ CDDB::Result
+ SyncCDDBPLookup::shakeHands()
+ {
+ QString line = readLine();
+
+ if ( !parseGreeting( line ) )
+ return ServerError;
+
+ sendHandshake();
+
+ line = readLine();
+
+ if ( !parseHandshake( line ) )
+ return ServerError;
+
+ sendProto();
+
+ // Ignore the response for now
+ readLine();
+
+ return Success;
+ }
+
+ CDDB::Result
+ SyncCDDBPLookup::runQuery()
+ {
+ Result result;
+
+ sendQuery();
+
+ QString line = readLine();
+ result = parseQuery( line );
+
+ if ( ServerError == result )
+ return ServerError;
+
+ if ( MultipleRecordFound == result )
+ {
+ // We have multiple matches
+ line = readLine();
+
+ while (!line.startsWith(".") && !line.isNull() )
+ {
+ parseExtraMatch( line );
+ line = readLine();
+ }
+ }
+
+ return Success;
+ }
+
+ CDDB::Result
+ SyncCDDBPLookup::matchToCDInfo( const CDDBMatch & match )
+ {
+ sendRead( match );
+
+ QString line = readLine();
+
+ Result result = parseRead( line );
+ if ( Success != result )
+ return result;
+
+ QStringList lineList;
+ line = readLine();
+
+ while ( !line.startsWith(".") && !line.isNull() )
+ {
+ lineList.append( line );
+ line = readLine();
+ }
+
+ CDInfo info;
+
+ if ( info.load( lineList ) )
+ {
+ info.category = category_;
+ cdInfoList_.append( info );
+ }
+
+ return Success;
+ }
+
+ QString
+ SyncCDDBPLookup::readLine()
+ {
+ if ( !isConnected() )
+ {
+ kdDebug(60010) << "socket status: " << socket_->state() << endl;
+ return QString::null;
+ }
+
+ if (!socket_->canReadLine())
+ {
+ bool timeout;
+
+ socket_->waitForMore(-1,&timeout);
+
+ if (timeout)
+ return QString::null;
+ }
+
+ return QString::fromUtf8(socket_->readLine());
+ }
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/synccddbplookup.h b/libkcddb/synccddbplookup.h
new file mode 100644
index 00000000..cef5cec9
--- /dev/null
+++ b/libkcddb/synccddbplookup.h
@@ -0,0 +1,51 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+ Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_SYNC_CDDBP_LOOKUP_H
+#define KCDDB_SYNC_CDDBP_LOOKUP_H
+
+#include "cddbplookup.h"
+
+namespace KCDDB
+{
+ class SyncCDDBPLookup : public CDDBPLookup
+ {
+ public:
+
+ SyncCDDBPLookup();
+ virtual ~SyncCDDBPLookup();
+
+ Result lookup( const QString &, uint, const TrackOffsetList & );
+
+ CDInfoList lookupResponse() const;
+
+ protected:
+ Result connect();
+ Result shakeHands();
+ Result runQuery();
+ Result matchToCDInfo( const CDDBMatch & );
+
+ QString readLine();
+ };
+}
+
+#endif // KCDDB_SYNC_CDDBP_LOOKUP_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/synchttplookup.cpp b/libkcddb/synchttplookup.cpp
new file mode 100644
index 00000000..ff0de12a
--- /dev/null
+++ b/libkcddb/synchttplookup.cpp
@@ -0,0 +1,131 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <qstringlist.h>
+#include <qapplication.h>
+
+#include <kdebug.h>
+#include <kio/job.h>
+#include <kio/netaccess.h>
+
+#include "synchttplookup.h"
+
+namespace KCDDB
+{
+ SyncHTTPLookup::SyncHTTPLookup()
+ : HTTPLookup()
+ {
+ }
+
+ SyncHTTPLookup::~SyncHTTPLookup()
+ {
+ // Empty.
+ }
+
+ CDDB::Result
+ SyncHTTPLookup::lookup
+ (
+ const QString & hostName,
+ uint port,
+ const TrackOffsetList & trackOffsetList
+ )
+ {
+ if ( trackOffsetList.count() < 3 )
+ return UnknownError;
+
+ trackOffsetList_ = trackOffsetList;
+
+ initURL( hostName, port );
+
+ // Run a query.
+ result_ = runQuery();
+
+ if ( Success != result_ )
+ return result_;
+
+ kdDebug(60010) << matchList_.count() << " matches found." << endl;
+
+ if (matchList_.isEmpty())
+ return NoRecordFound;
+
+ // For each match, read the cd info from the server and save it to
+ // cdInfoList.
+ CDDBMatchList::ConstIterator matchIt = matchList_.begin();
+
+ while ( matchIt != matchList_.end() )
+ {
+ CDDBMatch match( *matchIt );
+ result_ = matchToCDInfo( match );
+ ++matchIt;
+ }
+
+ return result_;
+ }
+
+ CDDB::Result
+ SyncHTTPLookup::runQuery()
+ {
+ data_ = QByteArray();
+ state_ = WaitingForQueryResponse;
+
+ result_ = sendQuery();
+
+ if ( Success != result_ )
+ return result_;
+
+ kdDebug(60010) << "runQuery() Result: " << resultToString(result_) << endl;
+
+ return result_;
+ }
+
+ CDDB::Result
+ SyncHTTPLookup::matchToCDInfo( const CDDBMatch & match )
+ {
+ data_ = QByteArray();
+ state_ = WaitingForReadResponse;
+
+ result_ = sendRead( match );
+
+ if ( Success != result_ )
+ return result_;
+
+ return result_;
+ }
+
+ CDDB::Result
+ SyncHTTPLookup::fetchURL()
+ {
+ kdDebug(60010) << "About to fetch: " << cgiURL_.url() << endl;
+
+ KIO::TransferJob* job = KIO::get( cgiURL_, false, false );
+
+ if ( 0 == job )
+ return ServerError;
+
+ if (!KIO::NetAccess::synchronousRun(job, 0, &data_))
+ return ServerError;
+
+ jobFinished();
+
+ return Success;
+ }
+}
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/synchttplookup.h b/libkcddb/synchttplookup.h
new file mode 100644
index 00000000..730577e4
--- /dev/null
+++ b/libkcddb/synchttplookup.h
@@ -0,0 +1,50 @@
+/*
+ Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
+ Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KCDDB_SYNC_HTTP_LOOKUP_H
+#define KCDDB_SYNC_HTTP_LOOKUP_H
+
+#include "httplookup.h"
+
+namespace KCDDB
+{
+ class SyncHTTPLookup : public HTTPLookup
+ {
+ public:
+
+ SyncHTTPLookup();
+ virtual ~SyncHTTPLookup();
+
+ Result lookup( const QString &, uint, const TrackOffsetList & );
+
+ CDInfoList lookupResponse() const;
+
+ protected:
+
+ virtual Result fetchURL();
+
+ Result runQuery();
+ Result matchToCDInfo( const CDDBMatch & );
+ };
+}
+
+#endif // KCDDB_SYNC_HTTP_LOOKUP_H
+
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/synchttpsubmit.cpp b/libkcddb/synchttpsubmit.cpp
new file mode 100644
index 00000000..b6e347fe
--- /dev/null
+++ b/libkcddb/synchttpsubmit.cpp
@@ -0,0 +1,46 @@
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "synchttpsubmit.h"
+#include <kio/netaccess.h>
+#include <kio/job.h>
+
+namespace KCDDB
+{
+ SyncHTTPSubmit::SyncHTTPSubmit(const QString& from, const QString& hostname, uint port)
+ : HTTPSubmit(from, hostname, port)
+ {
+
+ }
+
+ SyncHTTPSubmit::~SyncHTTPSubmit()
+ {
+
+ }
+
+ CDDB::Result SyncHTTPSubmit::runJob(KIO::Job* job)
+ {
+ bool success = KIO::NetAccess::synchronousRun(job, 0);
+
+ if (success)
+ return CDDB::Success;
+ else
+ return CDDB::UnknownError;
+ }
+}
diff --git a/libkcddb/synchttpsubmit.h b/libkcddb/synchttpsubmit.h
new file mode 100644
index 00000000..5dbb992e
--- /dev/null
+++ b/libkcddb/synchttpsubmit.h
@@ -0,0 +1,37 @@
+#ifndef SYNCHTTPSUBMIT_H
+#define SYNCHTTPSUBMIT_H
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "httpsubmit.h"
+
+namespace KCDDB
+{
+ class SyncHTTPSubmit : public HTTPSubmit
+ {
+ public:
+ SyncHTTPSubmit(const QString& from, const QString& hostname, uint port);
+ virtual ~SyncHTTPSubmit();
+
+ protected:
+ virtual Result runJob(KIO::Job* job);
+ } ;
+}
+
+#endif // SYNCHTTPSUBMIT_H
diff --git a/libkcddb/syncsmtpsubmit.cpp b/libkcddb/syncsmtpsubmit.cpp
new file mode 100644
index 00000000..f5761277
--- /dev/null
+++ b/libkcddb/syncsmtpsubmit.cpp
@@ -0,0 +1,46 @@
+/*
+ Copyright (C) 2003-2004 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "syncsmtpsubmit.h"
+#include "cdinfo.h"
+#include <kio/netaccess.h>
+#include <kio/job.h>
+
+namespace KCDDB
+{
+ SyncSMTPSubmit::SyncSMTPSubmit(const QString& hostname, uint port,
+ const QString& username, const QString& from, const QString& to)
+ : SMTPSubmit( hostname, port, username, from, to )
+ {
+
+ }
+
+ SyncSMTPSubmit::~SyncSMTPSubmit()
+ {
+
+ }
+
+ CDDB::Result SyncSMTPSubmit::runJob(KIO::Job* job)
+ {
+ if ( KIO::NetAccess::synchronousRun(job, 0) )
+ return Success;
+
+ return UnknownError;
+ }
+}
diff --git a/libkcddb/syncsmtpsubmit.h b/libkcddb/syncsmtpsubmit.h
new file mode 100644
index 00000000..959d7d94
--- /dev/null
+++ b/libkcddb/syncsmtpsubmit.h
@@ -0,0 +1,38 @@
+#ifndef SYNCSMTPSUBMIT_H
+#define SYNCSMTPSUBMIT_H
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include "smtpsubmit.h"
+
+namespace KCDDB
+{
+ class SyncSMTPSubmit : public SMTPSubmit
+ {
+ public:
+ SyncSMTPSubmit(const QString& hostname, uint port, const QString& username,
+ const QString& from, const QString& to);
+ virtual ~SyncSMTPSubmit();
+ protected:
+ virtual Result runJob(KIO::Job* job);
+ } ;
+}
+
+#endif // SYNCSMTPSUBMIT_H
+// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
diff --git a/libkcddb/test/Makefile.am b/libkcddb/test/Makefile.am
new file mode 100644
index 00000000..ab814db4
--- /dev/null
+++ b/libkcddb/test/Makefile.am
@@ -0,0 +1,48 @@
+INCLUDES = -I$(top_srcdir) -I$(top_builddir)/libkcddb $(all_includes)
+
+check_PROGRAMS = syncsmtpsubmittest asyncsmtpsubmittest asynchttplookuptest \
+ asynccddblookuptest synccddblookuptest synchttplookuptest \
+ asynchttpsubmittest synchttpsubmittest sitestest utf8test
+
+syncsmtpsubmittest_SOURCES = syncsmtpsubmittest.cpp
+syncsmtpsubmittest_LDFLAGS = $(all_libraries)
+syncsmtpsubmittest_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+asyncsmtpsubmittest_SOURCES = asyncsmtpsubmittest.cpp
+asyncsmtpsubmittest_LDFLAGS = $(all_libraries)
+asyncsmtpsubmittest_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+asynchttplookuptest_SOURCES = asynchttplookuptest.cpp
+asynchttplookuptest_LDFLAGS = $(all_libraries)
+asynchttplookuptest_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+asynccddblookuptest_SOURCES = asynccddblookuptest.cpp
+asynccddblookuptest_LDFLAGS = $(all_libraries)
+asynccddblookuptest_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+synchttplookuptest_SOURCES = synchttplookuptest.cpp
+synchttplookuptest_LDFLAGS = $(all_libraries)
+synchttplookuptest_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+synccddblookuptest_SOURCES = synccddblookuptest.cpp
+synccddblookuptest_LDFLAGS = $(all_libraries)
+synccddblookuptest_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+synchttpsubmittest_SOURCES = synchttpsubmittest.cpp
+synchttpsubmittest_LDFLAGS = $(all_libraries)
+synchttpsubmittest_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+asynchttpsubmittest_SOURCES = asynchttpsubmittest.cpp
+asynchttpsubmittest_LDFLAGS = $(all_libraries)
+asynchttpsubmittest_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+utf8test_SOURCES = utf8test.cpp
+utf8test_LDFLAGS = $(all_libraries)
+utf8test_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+sitestest_SOURCES = sitestest.cpp
+sitestest_LDFLAGS = $(all_libraries)
+sitestest_LDADD = $(top_builddir)/libkcddb/libkcddb.la
+
+METASOURCES = AUTO
+
diff --git a/libkcddb/test/asynccddblookuptest.cpp b/libkcddb/test/asynccddblookuptest.cpp
new file mode 100644
index 00000000..afbd326a
--- /dev/null
+++ b/libkcddb/test/asynccddblookuptest.cpp
@@ -0,0 +1,113 @@
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+
+#include "asynccddblookuptest.h"
+
+#include "libkcddb/cache.h"
+#include "libkcddb/lookup.h"
+
+AsyncCDDBLookupTest::AsyncCDDBLookupTest()
+ : QObject()
+{
+ using namespace KCDDB;
+
+ client_ = new Client;
+ client_->config().setHostname("freedb.freedb.org");
+ client_->config().setPort(8880);
+ client_->config().setCachePolicy(Cache::Ignore);
+ client_->config().setLookupTransport(Lookup::CDDBP);
+ client_->setBlockingMode( false );
+
+ connect
+ (
+ client_,
+ SIGNAL(finished(CDDB::Result)),
+ SLOT(slotFinished(CDDB::Result))
+ );
+
+ TrackOffsetList list;
+
+ // a1107d0a - Kruder & Dorfmeister - The K&D Sessions - Disc One.
+ list
+ << 150 // First track start.
+ << 29462
+ << 66983
+ << 96785
+ << 135628
+ << 168676
+ << 194147
+ << 222158
+ << 247076
+ << 278203 // Last track start.
+ << 10 // Disc start.
+ << 316732; // Disc end.
+
+ client_->lookup(list);
+}
+
+AsyncCDDBLookupTest::~AsyncCDDBLookupTest()
+{
+ delete client_;
+}
+
+ void
+AsyncCDDBLookupTest::slotFinished(CDDB::Result r)
+{
+ kdDebug() << "AsyncCDDBLookupTest::slotResult: Got " << KCDDB::CDDB::resultToString(r) << endl;
+
+ CDInfoList l = client_->lookupResponse();
+
+ kdDebug() << "AsyncCDDBLookupTest::slotResult: Item count: " << l.count() << endl;
+
+ for (CDInfoList::ConstIterator it(l.begin()); it != l.end(); ++it)
+ {
+ CDInfo i(*it);
+
+ kdDebug() << "Disc artist: `" << i.artist << "'" << endl;
+ kdDebug() << "Disc title: `" << i.title << "'" << endl;
+ kdDebug() << "Disc revision: `" << i.revision << "'" << endl;
+ }
+
+ if (!l.isEmpty())
+ {
+ kdDebug() << "---------------------------------------" << endl;
+ kdDebug() << "Showing first item" << endl;
+
+ CDInfo i(l.first());
+
+ kdDebug() << "Disc artist: `" << i.artist << "'" << endl;
+ kdDebug() << "Disc title: `" << i.title << "'" << endl;
+ kdDebug() << "Disc genre: `" << i.genre << "'" << endl;
+ kdDebug() << "Disc year: `" << i.year << "'" << endl;
+ kdDebug() << "Disc length: `" << i.length << "'" << endl;
+ kdDebug() << "Disc id: `" << i.id << "'" << endl;
+ kdDebug() << "Tracks........" << endl;
+
+ for (TrackInfoList::ConstIterator it(i.trackInfoList.begin()); it != i.trackInfoList.end(); ++it)
+ {
+ kdDebug() << " Track: `" << (*it).title << "'" << endl;
+ }
+ kdDebug() << "---------------------------------------" << endl;
+ }
+
+ CDInfo i(client_->bestLookupResponse());
+
+ kdDebug() << "Best CDInfo had title: " << i.title << endl;
+ kdDebug() << "and revision: " << i.revision << endl;
+
+ kapp->quit();
+}
+
+int main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app(false /* No styles */, false /* No GUI */);
+
+ AsyncCDDBLookupTest test;
+
+ return app.exec();
+}
+
+#include "asynccddblookuptest.moc"
diff --git a/libkcddb/test/asynccddblookuptest.h b/libkcddb/test/asynccddblookuptest.h
new file mode 100644
index 00000000..5e0a3efb
--- /dev/null
+++ b/libkcddb/test/asynccddblookuptest.h
@@ -0,0 +1,27 @@
+#ifndef TEST_H
+#define TEST_H
+
+#include <qobject.h>
+#include <libkcddb/client.h>
+
+using namespace KCDDB;
+
+class AsyncCDDBLookupTest : public QObject
+{
+ Q_OBJECT
+
+ public:
+
+ AsyncCDDBLookupTest();
+ ~AsyncCDDBLookupTest();
+
+ public slots:
+
+ void slotFinished(CDDB::Result);
+
+ private:
+
+ KCDDB::Client * client_;
+};
+
+#endif
diff --git a/libkcddb/test/asynchttplookuptest.cpp b/libkcddb/test/asynchttplookuptest.cpp
new file mode 100644
index 00000000..610d9fab
--- /dev/null
+++ b/libkcddb/test/asynchttplookuptest.cpp
@@ -0,0 +1,111 @@
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+
+#include "asynchttplookuptest.h"
+#include "libkcddb/cache.h"
+#include "libkcddb/lookup.h"
+
+AsyncHTTPLookupTest::AsyncHTTPLookupTest()
+ : QObject()
+{
+ using namespace KCDDB;
+
+ client_ = new Client;
+ client_->config().setHostname("freedb.freedb.org");
+ client_->config().setPort(80);
+ client_->config().setCachePolicy(Cache::Ignore);
+ client_->config().setLookupTransport(Lookup::HTTP);
+ client_->setBlockingMode( false );
+
+ connect
+ (
+ client_,
+ SIGNAL(finished(CDDB::Result)),
+ SLOT(slotFinished(CDDB::Result))
+ );
+
+ TrackOffsetList list;
+
+ // a1107d0a - Kruder & Dorfmeister - The K&D Sessions - Disc One.
+ list
+ << 150 // First track start.
+ << 29462
+ << 66983
+ << 96785
+ << 135628
+ << 168676
+ << 194147
+ << 222158
+ << 247076
+ << 278203 // Last track start.
+ << 10 // Disc start.
+ << 316732; // Disc end.
+
+ client_->lookup(list);
+}
+
+AsyncHTTPLookupTest::~AsyncHTTPLookupTest()
+{
+ delete client_;
+}
+
+ void
+AsyncHTTPLookupTest::slotFinished(CDDB::Result r)
+{
+ kdDebug() << "AsyncHTTPLookupTest::slotFinished: Got " << KCDDB::CDDB::resultToString(r) << endl;
+
+ CDInfoList l = client_->lookupResponse();
+
+ kdDebug() << "AsyncHTTPLookupTest::slotFinished: Item count: " << l.count() << endl;
+
+ for (CDInfoList::ConstIterator it(l.begin()); it != l.end(); ++it)
+ {
+ CDInfo i(*it);
+
+ kdDebug() << "Disc artist: `" << i.artist << "'" << endl;
+ kdDebug() << "Disc title: `" << i.title << "'" << endl;
+ kdDebug() << "Disc revision: `" << i.revision << "'" << endl;
+ }
+
+ if (!l.isEmpty())
+ {
+ kdDebug() << "---------------------------------------" << endl;
+ kdDebug() << "Showing first item" << endl;
+
+ CDInfo i(l.first());
+
+ kdDebug() << "Disc artist: `" << i.artist << "'" << endl;
+ kdDebug() << "Disc title: `" << i.title << "'" << endl;
+ kdDebug() << "Disc genre: `" << i.genre << "'" << endl;
+ kdDebug() << "Disc year: `" << i.year << "'" << endl;
+ kdDebug() << "Disc length: `" << i.length << "'" << endl;
+ kdDebug() << "Disc id: `" << i.id << "'" << endl;
+ kdDebug() << "Tracks........" << endl;
+
+ for (TrackInfoList::ConstIterator it(i.trackInfoList.begin()); it != i.trackInfoList.end(); ++it)
+ {
+ kdDebug() << " Track: `" << (*it).title << "'" << endl;
+ }
+ kdDebug() << "---------------------------------------" << endl;
+ }
+ CDInfo i( client_->bestLookupResponse() );
+
+ kdDebug() << "Best CDInfo had title: " << i.title << endl;
+ kdDebug() << "and revision: " << i.revision << endl;
+
+ kapp->quit();
+}
+
+int main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app(false /* No styles */, false /* No GUI */);
+
+ AsyncHTTPLookupTest a;
+
+ return app.exec();
+}
+
+#include "asynchttplookuptest.moc"
diff --git a/libkcddb/test/asynchttplookuptest.h b/libkcddb/test/asynchttplookuptest.h
new file mode 100644
index 00000000..c8e3e86c
--- /dev/null
+++ b/libkcddb/test/asynchttplookuptest.h
@@ -0,0 +1,27 @@
+#ifndef TEST_H
+#define TEST_H
+
+#include <qobject.h>
+#include <libkcddb/client.h>
+
+using namespace KCDDB;
+
+class AsyncHTTPLookupTest : public QObject
+{
+ Q_OBJECT
+
+ public:
+
+ AsyncHTTPLookupTest();
+ ~AsyncHTTPLookupTest();
+
+ public slots:
+
+ void slotFinished(CDDB::Result);
+
+ private:
+
+ KCDDB::Client * client_;
+};
+
+#endif
diff --git a/libkcddb/test/asynchttpsubmittest.cpp b/libkcddb/test/asynchttpsubmittest.cpp
new file mode 100644
index 00000000..9981f8a7
--- /dev/null
+++ b/libkcddb/test/asynchttpsubmittest.cpp
@@ -0,0 +1,80 @@
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+
+#include "asynchttpsubmittest.h"
+#include "libkcddb/submit.h"
+
+AsyncHTTPSubmitTest::AsyncHTTPSubmitTest()
+ : QObject()
+{
+ using namespace KCDDB;
+
+ client_ = new Client;
+ client_->config().setSubmitTransport(Submit::HTTP);
+ client_->setBlockingMode( false );
+
+ TrackOffsetList list;
+
+ list
+ << 150 // First track start.
+ << 2592
+ << 35472
+ << 47891
+ << 123310
+ << 150 // Disc start.
+ << 133125; // Disc end.
+
+ CDInfo cdInfo;
+
+ cdInfo.id = "3606ed05";
+ cdInfo.revision = 4;
+ cdInfo.title = "Bamse och Bronto";
+ cdInfo.artist = "Musiksage";
+ cdInfo.year = 2001;
+ cdInfo.category = "misc";
+ cdInfo.genre = "Barnsaga";
+ cdInfo.extd = QString::fromUtf8("Berättare: Olof Thunberg");
+
+ TrackInfo info;
+ info.title = "Bamses signaturmelodi";
+ cdInfo.trackInfoList.append(info);
+ info.title = "*";
+ cdInfo.trackInfoList.append(info);
+ info.title = "Brummavisan";
+ cdInfo.trackInfoList.append(info);
+ info.title = "*";
+ cdInfo.trackInfoList.append(info);
+ info.title = QString::fromUtf8("Jätteödlan Bronto");
+ cdInfo.trackInfoList.append(info);
+
+ connect
+ (
+ client_,
+ SIGNAL(finished(CDDB::Result)),
+ SLOT(slotFinished(CDDB::Result))
+ );
+
+ client_->submit(cdInfo, list);
+}
+
+ void
+AsyncHTTPSubmitTest::slotFinished(CDDB::Result r)
+{
+ kdDebug() << "AsyncHTTPSubmitTest::slotFinished: Got " << KCDDB::CDDB::resultToString(r) << endl;
+
+ kapp->quit();
+}
+
+int main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app(false /* No styles */, false /* No GUI */);
+
+ new AsyncHTTPSubmitTest;
+
+ return app.exec();
+}
+
+#include "asynchttpsubmittest.moc"
diff --git a/libkcddb/test/asynchttpsubmittest.h b/libkcddb/test/asynchttpsubmittest.h
new file mode 100644
index 00000000..27053836
--- /dev/null
+++ b/libkcddb/test/asynchttpsubmittest.h
@@ -0,0 +1,25 @@
+#ifndef TEST_H
+#define TEST_H
+
+#include <qobject.h>
+#include <libkcddb/client.h>
+
+using namespace KCDDB;
+
+class AsyncHTTPSubmitTest : public QObject
+{
+ Q_OBJECT
+
+ public:
+ AsyncHTTPSubmitTest();
+
+ public slots:
+
+ void slotFinished(CDDB::Result);
+
+ private:
+
+ KCDDB::Client * client_;
+};
+
+#endif
diff --git a/libkcddb/test/asyncsmtpsubmittest.cpp b/libkcddb/test/asyncsmtpsubmittest.cpp
new file mode 100644
index 00000000..224288e3
--- /dev/null
+++ b/libkcddb/test/asyncsmtpsubmittest.cpp
@@ -0,0 +1,81 @@
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+
+#include "asyncsmtpsubmittest.h"
+#include "libkcddb/submit.h"
+
+AsyncSMTPSubmitTest::AsyncSMTPSubmitTest()
+ : QObject()
+{
+ using namespace KCDDB;
+
+ client_ = new Client;
+ client_->config().setSubmitTransport(Submit::SMTP);
+ client_->config().setSubmitAddress("test-submit@freedb.org");
+ client_->setBlockingMode( false );
+
+ TrackOffsetList list;
+
+ list
+ << 150 // First track start.
+ << 2592
+ << 35472
+ << 47891
+ << 123310
+ << 150 // Disc start.
+ << 133125; // Disc end.
+
+ CDInfo cdInfo;
+
+ cdInfo.id = "3606ed05";
+ cdInfo.revision = 4;
+ cdInfo.title = "Bamse och Bronto";
+ cdInfo.artist = "Musiksage";
+ cdInfo.year = 2001;
+ cdInfo.category = "misc";
+ cdInfo.genre = "Barnsaga";
+ cdInfo.extd = QString::fromUtf8("Berättare: Olof Thunberg");
+
+ TrackInfo info;
+ info.title = "Bamses signaturmelodi";
+ cdInfo.trackInfoList.append(info);
+ info.title = "*";
+ cdInfo.trackInfoList.append(info);
+ info.title = "Brummavisan";
+ cdInfo.trackInfoList.append(info);
+ info.title = "*";
+ cdInfo.trackInfoList.append(info);
+ info.title = QString::fromUtf8("Jätteödlan Bronto");
+ cdInfo.trackInfoList.append(info);
+
+ connect
+ (
+ client_,
+ SIGNAL(finished(CDDB::Result)),
+ SLOT(slotFinished(CDDB::Result))
+ );
+
+ client_->submit(cdInfo, list);
+}
+
+ void
+AsyncSMTPSubmitTest::slotFinished(CDDB::Result r)
+{
+ kdDebug() << "AsyncSMTPSubmitTest::slotFinished: Got " << KCDDB::CDDB::resultToString(r) << endl;
+
+ kapp->quit();
+}
+
+int main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app(false /* No styles */, false /* No GUI */);
+
+ new AsyncSMTPSubmitTest;
+
+ return app.exec();
+}
+
+#include "asyncsmtpsubmittest.moc"
diff --git a/libkcddb/test/asyncsmtpsubmittest.h b/libkcddb/test/asyncsmtpsubmittest.h
new file mode 100644
index 00000000..3528798d
--- /dev/null
+++ b/libkcddb/test/asyncsmtpsubmittest.h
@@ -0,0 +1,25 @@
+#ifndef TEST_H
+#define TEST_H
+
+#include <qobject.h>
+#include <libkcddb/client.h>
+
+using namespace KCDDB;
+
+class AsyncSMTPSubmitTest : public QObject
+{
+ Q_OBJECT
+
+ public:
+ AsyncSMTPSubmitTest();
+
+ public slots:
+
+ void slotFinished(CDDB::Result);
+
+ private:
+
+ KCDDB::Client * client_;
+};
+
+#endif
diff --git a/libkcddb/test/sitestest.cpp b/libkcddb/test/sitestest.cpp
new file mode 100644
index 00000000..3876ae2c
--- /dev/null
+++ b/libkcddb/test/sitestest.cpp
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+
+#include "libkcddb/sites.h"
+
+ int
+main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app(false /* No styles */);
+
+ using namespace KCDDB;
+
+ Sites s;
+
+ kdDebug() << "Sites: " << endl;
+
+ QValueList<Mirror> sites = s.siteList();
+ for (QValueList<Mirror>::Iterator it = sites.begin(); it != sites.end(); ++it)
+ if ((*it).transport == Lookup::CDDBP)
+ kdDebug() << (*it).address << " CDDBP " << (*it).port << " " << (*it).description << endl;
+ else
+ kdDebug() << (*it).address << " HTTP " << (*it).port << " " << (*it).description << endl;
+
+ return 0;
+}
diff --git a/libkcddb/test/synccddblookuptest.cpp b/libkcddb/test/synccddblookuptest.cpp
new file mode 100644
index 00000000..0b71e864
--- /dev/null
+++ b/libkcddb/test/synccddblookuptest.cpp
@@ -0,0 +1,84 @@
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kdebug.h>
+
+#include "libkcddb/client.h"
+#include "libkcddb/cache.h"
+#include "libkcddb/lookup.h"
+
+
+ int
+main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app(false /* No styles */, false /* No GUI */);
+
+ using namespace KCDDB;
+
+ Client c;
+ c.config().setHostname("freedb.freedb.org");
+ c.config().setPort(8880);
+ c.config().setCachePolicy(Cache::Ignore);
+ c.config().setLookupTransport(Lookup::CDDBP);
+
+ TrackOffsetList list;
+
+ // a1107d0a - Kruder & Dorfmeister - The K&D Sessions - Disc One.
+// list
+// << 150 // First track start.
+// << 29462
+// << 66983
+// << 96785
+// << 135628
+// << 168676
+// << 194147
+// << 222158
+// << 247076
+// << 278203 // Last track start.
+// << 10 // Disc start.
+// << 316732; // Disc end.
+ list
+ << 150
+ << 106965
+ << 127220
+ << 151925
+ << 176085
+ << 5
+ << 234500;
+
+ kdDebug() << "Stuff to send to server:" << endl;
+
+ kdDebug()
+ << CDDB::trackOffsetListToId(list)
+ << " "
+ //<< trackOffsetListToString(list)
+ << endl;
+
+ CDDB::Result r = c.lookup(list);
+
+ kdDebug() << "Client::lookup gave : " << CDDB::resultToString(r) << endl;
+
+ CDInfoList response = c.lookupResponse();
+
+ kdDebug() << "Client::lookup returned : " << response.count() << " entries"
+ << endl;
+
+ CDInfoList::ConstIterator it;
+
+ for (it = response.begin(); it != response.end(); ++it)
+ {
+ CDInfo i(*it);
+
+ kdDebug() << "Disc title: " << i.title << endl;
+ kdDebug() << "Total tracks: " << i.trackInfoList.count() << endl;
+ kdDebug() << "Disc revision: `" << i.revision << "'" << endl;
+ }
+
+ CDInfo i( c.bestLookupResponse() );
+
+ kdDebug() << "Best CDInfo had title: " << i.title << endl;
+ kdDebug() << "and revision: " << i.revision << endl;
+
+ return 0;
+}
diff --git a/libkcddb/test/synchttplookuptest.cpp b/libkcddb/test/synchttplookuptest.cpp
new file mode 100644
index 00000000..8bc05c18
--- /dev/null
+++ b/libkcddb/test/synchttplookuptest.cpp
@@ -0,0 +1,84 @@
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kdebug.h>
+
+#include "libkcddb/client.h"
+#include "libkcddb/cache.h"
+#include "libkcddb/lookup.h"
+
+ int
+main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app(false /* No styles */);
+
+ using namespace KCDDB;
+
+ Client c;
+ c.config().setHostname("freedb.freedb.org");
+ c.config().setPort(80);
+ c.config().setCachePolicy(Cache::Ignore);
+ c.config().setLookupTransport(Lookup::HTTP);
+
+
+ TrackOffsetList list;
+
+ // a1107d0a - Kruder & Dorfmeister - The K&D Sessions - Disc One.
+// list
+// << 150 // First track start.
+// << 29462
+// << 66983
+// << 96785
+// << 135628
+// << 168676
+// << 194147
+// << 222158
+// << 247076
+// << 278203 // Last track start.
+// << 10 // Disc start.
+// << 316732; // Disc end.
+ list
+ << 150
+ << 106965
+ << 127220
+ << 151925
+ << 176085
+ << 5
+ << 234500;
+
+ kdDebug() << "Stuff to send to server:" << endl;
+
+ kdDebug()
+ << CDDB::trackOffsetListToId(list)
+ << " "
+ //<< trackOffsetListToString(list)
+ << endl;
+
+ CDDB::Result r = c.lookup(list);
+
+ kdDebug() << "Client::lookup gave : " << CDDB::resultToString(r) << endl;
+
+ CDInfoList response = c.lookupResponse();
+
+ kdDebug() << "Client::lookup returned : " << response.count() << " entries"
+ << endl;
+
+ CDInfoList::ConstIterator it;
+
+ for (it = response.begin(); it != response.end(); ++it)
+ {
+ CDInfo i(*it);
+
+ kdDebug() << "Disc title: " << i.title << endl;
+ kdDebug() << "Total tracks: " << i.trackInfoList.count() << endl;
+ kdDebug() << "Disc revision: `" << i.revision << "'" << endl;
+ }
+
+ CDInfo i( c.bestLookupResponse() );
+
+ kdDebug() << "Best CDInfo had title: " << i.title << endl;
+ kdDebug() << "and revision: " << i.revision << endl;
+
+ return 0;
+}
diff --git a/libkcddb/test/synchttpsubmittest.cpp b/libkcddb/test/synchttpsubmittest.cpp
new file mode 100644
index 00000000..67c42dac
--- /dev/null
+++ b/libkcddb/test/synchttpsubmittest.cpp
@@ -0,0 +1,79 @@
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+
+#include "libkcddb/client.h"
+#include "libkcddb/config.h"
+#include "libkcddb/submit.h"
+
+ int
+main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app(false /* No styles */);
+
+ using namespace KCDDB;
+
+ TrackOffsetList list;
+
+ list
+ << 150 // First track start.
+ << 2592
+ << 35472
+ << 47891
+ << 123310
+ << 150 // Disc start.
+ << 133125; // Disc end.
+
+ CDInfo cdInfo;
+
+ cdInfo.id = "3606ed05";
+ cdInfo.revision = 4;
+ cdInfo.title = "Bamse och Bronto";
+ cdInfo.artist = "Musiksage";
+ cdInfo.year = 2001;
+ cdInfo.category = "misc";
+ cdInfo.genre = "Barnsaga";
+ cdInfo.extd = QString::fromUtf8("Berättare: Olof Thunberg");
+
+ TrackInfo info;
+ info.title = "Bamses signaturmelodi";
+ cdInfo.trackInfoList.append(info);
+ info.title = "*";
+ cdInfo.trackInfoList.append(info);
+ info.title = "Brummavisan";
+ cdInfo.trackInfoList.append(info);
+ info.title = "*";
+ cdInfo.trackInfoList.append(info);
+ info.title = QString::fromUtf8("Jätteödlan Bronto");
+ cdInfo.trackInfoList.append(info);
+
+ Client c;
+ c.config().setSubmitTransport(Submit::HTTP);
+ c.setBlockingMode( true );
+
+ CDDB::Result r = c.submit(cdInfo, list);
+
+ kdDebug() << "Result: " << CDDB::resultToString(r) << endl;
+}
+
diff --git a/libkcddb/test/syncsmtpsubmittest.cpp b/libkcddb/test/syncsmtpsubmittest.cpp
new file mode 100644
index 00000000..1d608dda
--- /dev/null
+++ b/libkcddb/test/syncsmtpsubmittest.cpp
@@ -0,0 +1,81 @@
+/*
+ Copyright (C) 2003 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
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+
+#include "libkcddb/client.h"
+#include "libkcddb/config.h"
+#include "libkcddb/submit.h"
+
+ int
+main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app(false /* No styles */);
+
+ using namespace KCDDB;
+
+ TrackOffsetList list;
+
+ list
+ << 150 // First track start.
+ << 2592
+ << 35472
+ << 47891
+ << 123310
+ << 150 // Disc start.
+ << 133125; // Disc end.
+
+ CDInfo cdInfo;
+
+ cdInfo.id = "3606ed05";
+ cdInfo.revision = 4;
+ cdInfo.title = "Bamse och Bronto";
+ cdInfo.artist = "Musiksage";
+ cdInfo.year = 2001;
+ cdInfo.category = "misc";
+ cdInfo.genre = "Barnsaga";
+ cdInfo.extd = QString::fromUtf8("Berättare: Olof Thunberg");
+
+ TrackInfo info;
+ info.title = "Bamses signaturmelodi";
+ cdInfo.trackInfoList.append(info);
+ info.title = "*";
+ cdInfo.trackInfoList.append(info);
+ info.title = "Brummavisan";
+ cdInfo.trackInfoList.append(info);
+ info.title = "*";
+ cdInfo.trackInfoList.append(info);
+ info.title = QString::fromUtf8("Jätteödlan Bronto");
+ cdInfo.trackInfoList.append(info);
+
+ Client c;
+ c.config().setSubmitTransport(Submit::SMTP);
+ c.config().setSubmitAddress("test-submit@freedb.org");
+
+ c.setBlockingMode( true );
+
+ CDDB::Result r = c.submit(cdInfo, list);
+
+ kdDebug() << "Result: " << CDDB::resultToString(r) << endl;
+}
+
diff --git a/libkcddb/test/utf8test.cpp b/libkcddb/test/utf8test.cpp
new file mode 100644
index 00000000..05d8b83e
--- /dev/null
+++ b/libkcddb/test/utf8test.cpp
@@ -0,0 +1,50 @@
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kdebug.h>
+
+#include "libkcddb/client.h"
+#include "libkcddb/cache.h"
+#include "libkcddb/lookup.h"
+
+ int
+main(int argc, char ** argv)
+{
+ KCmdLineArgs::init(argc, argv, "libkcddb_test", "", "", "");
+
+ KApplication app;
+
+ using namespace KCDDB;
+
+ Client c;
+
+ TrackOffsetList list;
+
+ list
+ << 150
+ << 61408
+ << 0
+ << 177675;
+
+ kdDebug() << "Stuff to send to server:" << endl;
+
+ kdDebug()
+ << CDDB::trackOffsetListToId(list)
+ << " "
+ //<< trackOffsetListToString(list)
+ << endl;
+
+ CDDB::Result r = c.lookup(list);
+
+ kdDebug() << "Client::lookup gave : " << CDDB::resultToString(r) << endl;
+
+ CDInfoList response = c.lookupResponse();
+
+ kdDebug() << "Client::lookup returned : " << response.count() << " entries"
+ << endl;
+
+ CDInfo i( c.bestLookupResponse() );
+
+ kdDebug() << "Best CDInfo had title: " << i.title << endl;
+
+ return 0;
+}