Commit 70f1c41f authored by Richard Lärkäng's avatar Richard Lärkäng
Browse files

Add non-blocking access to MusicBrainz too

svn path=/trunk/KDE/kdemultimedia/libkcddb/; revision=572310
parent 733c38ee
......@@ -7,7 +7,10 @@ macro_optional_find_package(MusicBrainz)
if(MUSICBRAINZ_FOUND)
set(HAVE_MUSICBRAINZ 1)
set(libmusicbrainz_SRCS ${libmusicbrainz_SRCS} musicbrainz/musicbrainzlookup.cpp musicbrainz/sha1.c)
set(libmusicbrainz_SRCS ${libmusicbrainz_SRCS}
musicbrainz/musicbrainzlookup.cpp
musicbrainz/asyncmusicbrainzlookup.cpp
musicbrainz/sha1.c )
else(MUSICBRAINZ_FOUND)
set(HAVE_MUSICBRAINZ 0)
set(libmusicbrainz_SRCS)
......
......@@ -34,6 +34,7 @@
#include "config-musicbrainz.h"
#ifdef HAVE_MUSICBRAINZ
#include "musicbrainz/musicbrainzlookup.h"
#include "musicbrainz/asyncmusicbrainzlookup.h"
#endif
#include <kdebug.h>
......@@ -185,9 +186,9 @@ namespace KCDDB
else
{
#ifdef HAVE_MUSICBRAINZ
cdInfoLookup = new MusicBrainzLookup();
cdInfoLookup = new AsyncMusicBrainzLookup();
connect( static_cast<MusicBrainzLookup *>( cdInfoLookup ),
connect( static_cast<AsyncMusicBrainzLookup *>( cdInfoLookup ),
SIGNAL( finished( CDDB::Result ) ),
SLOT( slotFinished( CDDB::Result ) ) );
#else
......
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "asyncmusicbrainzlookup.h"
#include "musicbrainzlookup.h"
#include <QtCore/QThread>
#include <kdebug.h>
namespace KCDDB
{
class LookupThread : public QThread
{
public:
void run()
{
MusicBrainzLookup lookup;
m_result = lookup.lookup("", 0, m_offsetList);
if (m_result == CDDB::Success)
m_lookupResponse = lookup.lookupResponse();
}
TrackOffsetList m_offsetList;
CDDB::Result m_result;
CDInfoList m_lookupResponse;
} ;
AsyncMusicBrainzLookup::AsyncMusicBrainzLookup()
{
}
AsyncMusicBrainzLookup::~AsyncMusicBrainzLookup()
{
delete m_lookupThread;
}
CDDB::Result AsyncMusicBrainzLookup::lookup( const QString &, uint, const TrackOffsetList & trackOffsetList )
{
m_lookupThread = new LookupThread();
m_lookupThread->m_offsetList = trackOffsetList;
connect(m_lookupThread, SIGNAL(finished()), SLOT(lookupFinished()));
m_lookupThread->start();
return Success;
}
void AsyncMusicBrainzLookup::lookupFinished()
{
kDebug() << k_funcinfo << endl;
cdInfoList_ = m_lookupThread->m_lookupResponse;
emit finished(m_lookupThread->m_result);
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
#include "asyncmusicbrainzlookup.moc"
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef ASYNCMUSICBRAINZLOOKUP_H
#define ASYNCMUSICBRAINZLOOKUP_H
#include "lookup.h"
namespace KCDDB
{
class LookupThread;
class AsyncMusicBrainzLookup : public Lookup
{
Q_OBJECT
public:
AsyncMusicBrainzLookup();
virtual ~AsyncMusicBrainzLookup();
Result lookup( const QString &, uint, const TrackOffsetList & );
CDInfoList lookupResponse() const;
signals:
void finished( CDDB::Result );
protected slots:
void lookupFinished( );
private:
LookupThread* m_lookupThread;
};
}
#endif // ASYNCMUSICBRAINZLOOKUP_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
......@@ -36,11 +36,6 @@ namespace KCDDB
// FIXME Only freedb lookup needs the first two arguments (host/port)
virtual Result lookup( const QString &, uint, const TrackOffsetList & );
CDInfoList lookupResponse() const;
signals:
void finished( CDDB::Result );
private:
QString calculateDiscId(const TrackOffsetList & );
......
......@@ -71,6 +71,13 @@ if(KDE4_BUILD_TESTS)
add_test(musicbrainztest ${EXECUTABLE_OUTPUT_PATH}/musicbrainztest)
set(asyncmusicbrainztest_SRCS asyncmusicbrainztest.cpp )
kde4_automoc(${asyncmusicbrainztest_SRCS})
kde4_add_executable(asyncmusicbrainztest RUN_UNINSTALLED ${asyncmusicbrainztest_SRCS})
target_link_libraries(asyncmusicbrainztest ${KDE4_KDECORE_LIBS} kcddb QtTest_debug )
add_test(asyncmusicbrainztest ${EXECUTABLE_OUTPUT_PATH}/asyncmusicbrainztest)
set(cdinfotest_SRCS cdinfotest.cpp )
kde4_automoc(${cdinfotest_SRCS})
kde4_add_executable(cdinfotest RUN_UNINSTALLED ${cdinfotest_SRCS})
......
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>
#include "asyncmusicbrainztest.h"
#include "libkcddb/cache.h"
#include "libkcddb/lookup.h"
void AsyncMusicBrainzTest::testLookup()
{
using namespace KCDDB;
client_ = new Client;
client_->config().setCachePolicy(Cache::Ignore);
client_->config().setLookupTransport(Lookup::MusicBrainz);
client_->setBlockingMode( false );
connect
(
client_,
SIGNAL(finished(CDDB::Result)),
SLOT(slotFinished(CDDB::Result))
);
TrackOffsetList list;
// Various Artists / Definitivt 50 Spänn 10
list
<< 150
<< 17130
<< 26340
<< 44855
<< 60530
<< 75800
<< 90182
<< 106605
<< 122995
<< 139005
<< 153317
<< 167967
<< 179012
<< 190190
<< 202162
<< 211312
<< 229037
<< 240035;
client_->lookup(list);
m_eventLoop.exec(QEventLoop::ExcludeUserInput);
// See http://musicbrainz.org/release/dbb3e39a-4bea-4e32-a546-456654f30ca6.html for changes
QCOMPARE(m_info.numberOfTracks(),17);
QCOMPARE(m_info.get(Artist).toString(),QString("Various Artists"));
QCOMPARE(m_info.get(Title).toString(),QString::fromUtf8("Definitivt 50 Spänn 10"));
// genre and year not really supported for musicbrainz
QCOMPARE(m_info.get(Genre).toString(),QString());
QCOMPARE(m_info.get(Year).toInt(),0);
QCOMPARE(m_info.track(0).get(Title).toString(),QString::fromUtf8("Uphill Struggle"));
QCOMPARE(m_info.track(1).get(Title).toString(),QString::fromUtf8("Vill du bli miljonär?"));
QCOMPARE(m_info.track(2).get(Title).toString(),QString::fromUtf8("Här är jag"));
QCOMPARE(m_info.track(3).get(Title).toString(),QString::fromUtf8("Århundradets fest"));
QCOMPARE(m_info.track(4).get(Title).toString(),QString::fromUtf8("Vem valde mittemellan"));
QCOMPARE(m_info.track(5).get(Title).toString(),QString::fromUtf8("Hippieambulansen"));
QCOMPARE(m_info.track(6).get(Title).toString(),QString::fromUtf8("Jonsson"));
QCOMPARE(m_info.track(7).get(Title).toString(),QString::fromUtf8("Jag lämnar filmen"));
QCOMPARE(m_info.track(8).get(Title).toString(),QString::fromUtf8("39 Steg"));
QCOMPARE(m_info.track(9).get(Title).toString(),QString::fromUtf8("Lyckliga land"));
QCOMPARE(m_info.track(10).get(Title).toString(),QString::fromUtf8("Helpless"));
QCOMPARE(m_info.track(11).get(Title).toString(),QString::fromUtf8("Tunna skivor"));
QCOMPARE(m_info.track(12).get(Title).toString(),QString::fromUtf8("God läskeblask"));
QCOMPARE(m_info.track(13).get(Title).toString(),QString::fromUtf8("Hur snygg é du då?"));
QCOMPARE(m_info.track(14).get(Title).toString(),QString::fromUtf8("Självupptagen"));
QCOMPARE(m_info.track(15).get(Title).toString(),QString::fromUtf8("Sound Is Compressed; Words Rebel and Hiss"));
QCOMPARE(m_info.track(16).get(Title).toString(),QString::fromUtf8("Vi är på väg"));
QCOMPARE(m_info.track(0).get(Artist).toString(),QString::fromUtf8("Adhesive"));
QCOMPARE(m_info.track(1).get(Artist).toString(),QString::fromUtf8("Troublemakers"));
QCOMPARE(m_info.track(2).get(Artist).toString(),QString::fromUtf8("Mimikry"));
QCOMPARE(m_info.track(3).get(Artist).toString(),QString::fromUtf8("Lundberg & Dellamorte"));
QCOMPARE(m_info.track(4).get(Artist).toString(),QString::fromUtf8("Charta 77"));
QCOMPARE(m_info.track(5).get(Artist).toString(),QString::fromUtf8("Ubba"));
QCOMPARE(m_info.track(6).get(Artist).toString(),QString::fromUtf8("Coca Carola"));
QCOMPARE(m_info.track(7).get(Artist).toString(),QString::fromUtf8("Spoiler"));
QCOMPARE(m_info.track(8).get(Artist).toString(),QString::fromUtf8("Strebers"));
QCOMPARE(m_info.track(9).get(Artist).toString(),QString::fromUtf8("Iguana Party"));
QCOMPARE(m_info.track(10).get(Artist).toString(),QString::fromUtf8("Stoned"));
QCOMPARE(m_info.track(11).get(Artist).toString(),QString::fromUtf8("Per Bertil Birgers orkester"));
QCOMPARE(m_info.track(12).get(Artist).toString(),QString::fromUtf8("Slutstation Tjernobyl"));
QCOMPARE(m_info.track(13).get(Artist).toString(),QString::fromUtf8("SBD"));
QCOMPARE(m_info.track(14).get(Artist).toString(),QString::fromUtf8("Skumdum"));
QCOMPARE(m_info.track(15).get(Artist).toString(),QString::fromUtf8("Text"));
QCOMPARE(m_info.track(16).get(Artist).toString(),QString::fromUtf8("Ohlson har semester production"));
// comments not supported in a simple way
for (int j=0; j < 17; j++)
QCOMPARE(m_info.track(j).get(Comment).toString(),QString());
// Make sure it's the same when loaded from the cache again
client_->config().setCachePolicy(Cache::Only);
client_->setBlockingMode(true);
client_->lookup(list);
CDInfoList response = client_->lookupResponse();
QEXPECT_FAIL("", "Cache doesn't work yet", Continue);
QVERIFY(response.count() > 0);
// FIXME
return;
CDInfo cacheInfo(response.first());
QCOMPARE(m_info.get(Artist).toString(),cacheInfo.get(Artist).toString());
QCOMPARE(m_info.get(Title).toString(),cacheInfo.get(Title).toString());
QCOMPARE(m_info.get(Genre).toString(),cacheInfo.get(Genre).toString());
QCOMPARE(m_info.get(Year).toInt(),cacheInfo.get(Year).toInt());
for (int j=0; j < 17; j++)
{
QCOMPARE(m_info.track(j).get(Title).toString(),cacheInfo.get(Title).toString());
QCOMPARE(m_info.track(j).get(Comment).toString(),cacheInfo.get(Comment).toString());
}
}
void
AsyncMusicBrainzTest::slotFinished(CDDB::Result r)
{
kDebug() << k_funcinfo << ": Got " << KCDDB::CDDB::resultToString(r) << endl;
CDInfoList l = client_->lookupResponse();
kDebug() << k_funcinfo << ": Item count: " << l.count() << endl;
QVERIFY(l.count() > 0);
m_info = l.first();
m_eventLoop.quit();
}
QTEST_KDEMAIN(AsyncMusicBrainzTest, NoGUI);
#include "asyncmusicbrainztest.moc"
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef TEST_H
#define TEST_H
#include <QEventLoop>
#include <QObject>
#include <libkcddb/client.h>
using namespace KCDDB;
class AsyncMusicBrainzTest : public QObject
{
Q_OBJECT
private slots:
void testLookup();
void slotFinished(CDDB::Result);
private:
QEventLoop m_eventLoop;
KCDDB::Client * client_;
CDInfo m_info;
};
#endif
......@@ -96,7 +96,10 @@ void MusicBrainzTest::testLookup()
c.lookup(list);
response = c.lookupResponse();
QEXPECT_FAIL("", "Cache doesn't work yet", Continue);
QVERIFY(response.count() > 0);
// FIXME
return;
CDInfo cacheInfo(response.first());
QCOMPARE(i.get(Artist).toString(),cacheInfo.get(Artist).toString());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment