11 #include "asynccddbplookup.h"
12 #include "asynchttplookup.h"
13 #include "asynchttpsubmit.h"
17 #include "synccddbplookup.h"
18 #include "synchttplookup.h"
19 #include "synchttpsubmit.h"
21 #include "config-musicbrainz.h"
22 #ifdef HAVE_MUSICBRAINZ5
23 #include "musicbrainz/musicbrainzlookup.h"
24 #include "musicbrainz/asyncmusicbrainzlookup.h"
34 : cdInfoLookup(nullptr),
35 cdInfoSubmit(nullptr),
43 qDeleteAll(pendingLookups);
47 Submit * cdInfoSubmit;
50 CDInfoList cdInfoList;
51 TrackOffsetList trackOffsetList;
68 Client::config()
const
74 Client::setBlockingMode(
bool enable )
80 Client::blockingMode()
const
94 d->cdInfoList.clear();
95 d->trackOffsetList = trackOffsetList;
97 if ( trackOffsetList.
count() <= 1 )
99 qCDebug(LIBKCDDB) <<
"Lookup called with empty offset list";
100 return NoRecordFound;
103 if ( d->config.cacheLookupEnabled() )
105 d->cdInfoList = Cache::lookup( trackOffsetList, config() );
107 qCDebug(LIBKCDDB) <<
"Found " << d->cdInfoList.count() <<
" hit(s)";
109 if ( !d->cdInfoList.isEmpty() )
111 if ( !blockingMode() )
121 delete d->cdInfoLookup;
122 d->cdInfoLookup =
nullptr;
123 qDeleteAll(d->pendingLookups);
124 d->pendingLookups.clear();
126 if ( blockingMode() )
128 #ifdef HAVE_MUSICBRAINZ5
129 if ( d->config.musicBrainzLookupEnabled() )
131 d->cdInfoLookup =
new MusicBrainzLookup();
133 r = d->cdInfoLookup->lookup( d->config.hostname(),
134 d->config.port(), trackOffsetList );
138 d->cdInfoList = d->cdInfoLookup->lookupResponse();
139 Cache::store( d->trackOffsetList, d->cdInfoList, config() );
144 delete d->cdInfoLookup;
145 d->cdInfoLookup =
nullptr;
149 if ( d->config.freedbLookupEnabled() )
151 Lookup::Transport t = ( Lookup::Transport )d->config.freedbLookupTransport();
152 if( Lookup::CDDBP == t )
153 d->cdInfoLookup =
new SyncCDDBPLookup();
155 d->cdInfoLookup =
new SyncHTTPLookup();
157 r = d->cdInfoLookup->lookup( d->config.hostname(),
158 d->config.port(), trackOffsetList );
162 d->cdInfoList = d->cdInfoLookup->lookupResponse();
163 Cache::store( d->trackOffsetList, d->cdInfoList, config() );
168 delete d->cdInfoLookup;
169 d->cdInfoLookup =
nullptr;
176 #ifdef HAVE_MUSICBRAINZ5
177 if ( d->config.musicBrainzLookupEnabled() )
179 AsyncMusicBrainzLookup*
lookup =
new AsyncMusicBrainzLookup();
183 d->pendingLookups.append(
lookup );
187 if ( d->config.freedbLookupEnabled() )
189 Lookup::Transport t = ( Lookup::Transport )d->config.freedbLookupTransport();
191 if( Lookup::CDDBP == t )
193 AsyncCDDBPLookup*
lookup =
new AsyncCDDBPLookup();
197 d->pendingLookups.append(
lookup );
201 AsyncHTTPLookup*
lookup =
new AsyncHTTPLookup();
205 d->pendingLookups.append(
lookup );
209 return runPendingLookups();
216 if ( d->cdInfoLookup && Success == r )
218 d->cdInfoList = d->cdInfoLookup->lookupResponse();
219 Cache::store( d->trackOffsetList, d->cdInfoList, config() );
222 d->cdInfoList.clear();
224 if ( d->cdInfoLookup )
226 d->cdInfoLookup->deleteLater();
227 d->cdInfoLookup =
nullptr;
233 qDeleteAll( d->pendingLookups );
234 d->pendingLookups.clear();
247 d->cdInfoSubmit->deleteLater();
248 d->cdInfoSubmit=
nullptr;
260 for (
int i=0; i < offsetList.
count(); i++)
262 if(last >= offsetList[i])
264 last = offsetList[i];
270 delete d->cdInfoSubmit;
272 QString from = d->config.emailAddress();
274 QString hostname = d->config.httpSubmitServer();
275 uint port = d->config.httpSubmitPort();
277 if ( blockingMode() )
278 d->cdInfoSubmit =
new SyncHTTPSubmit(from, hostname, port);
281 d->cdInfoSubmit =
new AsyncHTTPSubmit(from, hostname, port);
282 connect(
static_cast<AsyncHTTPSubmit *
>( d->cdInfoSubmit ),
283 &AsyncHTTPSubmit::finished,
287 Result r = d->cdInfoSubmit->submit( cdInfo, offsetList );
289 if ( blockingMode() )
291 delete d->cdInfoSubmit;
292 d->cdInfoSubmit =
nullptr;
299 Client::runPendingLookups()
301 if (!d->pendingLookups.empty())
303 d->cdInfoLookup = d->pendingLookups.takeFirst();
305 Result r = d->cdInfoLookup->lookup( d->config.hostname(),
306 d->config.port(), d->trackOffsetList );
310 delete d->cdInfoLookup;
311 d->cdInfoLookup =
nullptr;
319 return NoRecordFound;
326 Cache::store(offsetList, cdInfo, config());
330 #include "moc_client.cpp"