KCDDB

asyncmusicbrainzlookup.cpp
1/*
2 SPDX-FileCopyrightText: 2006 Richard Lärkäng <nouseforaname@home.se>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "asyncmusicbrainzlookup.h"
8
9#include "musicbrainzlookup.h"
10
11#include <QDebug>
12#include <QThread>
13
14namespace KCDDB
15{
16 class LookupThread : public QThread
17 {
18
20
21 public:
22 void run() override
23 {
24 Result result;
25 CDInfoList lookupResponse;
26 MusicBrainzLookup lookup;
27
28 result = lookup.lookup(QString(), 0, m_offsetList);
29
30 if (result == Success)
31 lookupResponse = lookup.lookupResponse();
32
33 Q_EMIT lookupFinished(result, lookupResponse);
34 }
35
36 TrackOffsetList m_offsetList;
37
39 void lookupFinished( KCDDB::Result, KCDDB::CDInfoList );
40 };
41
42 AsyncMusicBrainzLookup::AsyncMusicBrainzLookup()
43 {
44 // Register custom data types for the signal-slot connection with the lookup thread:
45 qRegisterMetaType<KCDDB::Result>("KCDDB::Result");
46 qRegisterMetaType<KCDDB::CDInfoList>("KCDDB::CDInfoList");
47 }
48
49 AsyncMusicBrainzLookup::~AsyncMusicBrainzLookup()
50 {
51
52 }
53
54 Result AsyncMusicBrainzLookup::lookup( const QString &, uint, const TrackOffsetList & trackOffsetList )
55 {
56 LookupThread* lookupThread = new LookupThread();
57 lookupThread->m_offsetList = trackOffsetList;
58 connect(lookupThread, &LookupThread::lookupFinished, this, &AsyncMusicBrainzLookup::processLookupResult); // queued connection
59
60 // Make the thread object "self-destructive"; allows us to keep the destructor non-blocking
61 connect(lookupThread, &LookupThread::finished, lookupThread, &LookupThread::deleteLater);
62 // NOTE: the memory automatically gets cleared after the thread has finished
63
64 lookupThread->start();
65
66 return Success;
67 }
68
69 void AsyncMusicBrainzLookup::processLookupResult( KCDDB::Result result, KCDDB::CDInfoList lookupResponse )
70 {
71 qDebug();
72
73 cdInfoList_ = lookupResponse;
74
75 Q_EMIT finished(result);
76 }
77}
78
79#include "asyncmusicbrainzlookup.moc"
80#include "moc_asyncmusicbrainzlookup.cpp"
81
82// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
Q_EMITQ_EMIT
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
void finished()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.