2
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
3
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
4
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
23
#include "synccddbplookup.h"
24
#include "asynccddbplookup.h"
25
#include "synchttplookup.h"
26
#include "asynchttplookup.h"
27
#include "syncsmtpsubmit.h"
28
#include "asyncsmtpsubmit.h"
29
#include "synchttpsubmit.h"
30
#include "asynchttpsubmit.h"
48
CDInfoList cdInfoList;
58
d->config.readConfig();
69
Client::config() const
75
Client::setBlockingMode( bool enable )
81
Client::blockingMode() const
87
Client::lookupResponse() const
93
Client::bestLookupResponse() const
99
for ( CDInfoList::Iterator it = d->cdInfoList.begin();
100
it != d->cdInfoList.end(); ++it )
102
if ( ( *it ).revision >= maxrev )
105
maxrev = info.revision;
113
Client::lookup(const TrackOffsetList & trackOffsetList)
115
d->cdInfoList.clear();
117
QString cddbId = Lookup::trackOffsetListToId( trackOffsetList );
119
if ( cddbId.isNull() )
121
kdDebug(60010) << "Can't create cddbid from offset list" << endl;
122
return Lookup::NoRecordFound;
125
if ( Cache::Ignore != d->config.cachePolicy() )
127
d->cdInfoList = Cache::lookup( cddbId );
129
kdDebug(60010) << "Found " << d->cdInfoList.count() << " hit(s)" << endl;
131
if ( !d->cdInfoList.isEmpty() )
133
if ( !blockingMode() )
134
emit finished( Lookup::Success );
136
return CDDB::Success;
140
if ( Cache::Only == d->config.cachePolicy() )
142
kdDebug(60010) << "Only trying cache. Give up now." << endl;
143
if ( !blockingMode() )
144
emit finished( Lookup::NoRecordFound );
145
return CDDB::NoRecordFound;
149
Lookup::Transport t = ( Lookup::Transport )d->config.lookupTransport();
151
// just in case we have an info lookup hanging around, prevent mem leakage
154
if ( blockingMode() )
157
if( Lookup::CDDBP == t )
158
cdInfoLookup = new SyncCDDBPLookup();
160
cdInfoLookup = new SyncHTTPLookup();
162
r = cdInfoLookup->lookup( d->config.hostname(),
163
d->config.port(), trackOffsetList );
165
if ( CDDB::Success == r )
167
d->cdInfoList = cdInfoLookup->lookupResponse();
168
Cache::store( d->cdInfoList );
176
if( Lookup::CDDBP == t )
178
cdInfoLookup = new AsyncCDDBPLookup();
180
connect( static_cast<AsyncCDDBPLookup *>( cdInfoLookup ),
181
SIGNAL( finished( CDDB::Result ) ),
182
SLOT( slotFinished( CDDB::Result ) ) );
186
cdInfoLookup = new AsyncHTTPLookup();
188
connect( static_cast<AsyncHTTPLookup *>( cdInfoLookup ),
189
SIGNAL( finished( CDDB::Result ) ),
190
SLOT( slotFinished( CDDB::Result ) ) );
193
r = cdInfoLookup->lookup( d->config.hostname(),
194
d->config.port(), trackOffsetList );
196
if ( Lookup::Success != r )
207
Client::slotFinished( CDDB::Result r )
209
if ( cdInfoLookup && CDDB::Success == r )
211
d->cdInfoList = cdInfoLookup->lookupResponse();
212
Cache::store( d->cdInfoList );
215
d->cdInfoList.clear();
224
Client::slotSubmitFinished( CDDB::Result r )
233
Client::submit(const CDInfo &cdInfo, const TrackOffsetList& offsetList)
235
// Check if it's valid
237
if (!cdInfo.isValid())
238
return CDDB::CannotSave;
241
for (uint i=0; i < (offsetList.count()-2); i++)
243
if(last >= offsetList[i])
244
return CDDB::CannotSave;
245
last = offsetList[i];
248
//TODO Check that it is edited
250
// just in case we have a cdInfoSubmit, prevent memory leakage
253
QString from = d->config.emailAddress();
255
switch (d->config.submitTransport())
259
QString hostname = d->config.httpSubmitServer();
260
uint port = d->config.httpSubmitPort();
262
if ( blockingMode() )
263
cdInfoSubmit = new SyncHTTPSubmit(from, hostname, port);
266
cdInfoSubmit = new AsyncHTTPSubmit(from, hostname, port);
267
connect( static_cast<AsyncHTTPSubmit *>( cdInfoSubmit ),
268
SIGNAL(finished( CDDB::Result ) ),
269
SLOT( slotSubmitFinished( CDDB::Result ) ) );
276
QString hostname = d->config.smtpHostname();
277
uint port = d->config.smtpPort();
278
QString username = d->config.smtpUsername();
280
if ( blockingMode() )
281
cdInfoSubmit = new SyncSMTPSubmit( hostname, port, username, from, d->config.submitAddress() );
284
cdInfoSubmit = new AsyncSMTPSubmit( hostname, port, username, from, d->config.submitAddress() );
285
connect( static_cast<AsyncSMTPSubmit *>( cdInfoSubmit ),
286
SIGNAL( finished( CDDB::Result ) ),
287
SLOT( slotSubmitFinished( CDDB::Result ) ) );
292
kdDebug(60010) << k_funcinfo << "Unsupported transport: " << endl;
293
// << CDDB::transportToString(d->config.submitTransport()) << endl;
294
return CDDB::UnknownError;
298
CDDB::Result r = cdInfoSubmit->submit( cdInfo, offsetList );
300
if ( blockingMode() )
310
#include "client.moc"
313
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1