9#include "asynccddbplookup.h"
14 AsyncCDDBPLookup::AsyncCDDBPLookup()
21 AsyncCDDBPLookup::~AsyncCDDBPLookup()
26 AsyncCDDBPLookup::lookup
30 const TrackOffsetList & trackOffsetList
39 this, &AsyncCDDBPLookup::slotConnectionSuccess );
43 trackOffsetList_ = trackOffsetList;
45 state_ = WaitingForConnection;
56 Q_EMIT finished( HostNotFound );
58 Q_EMIT finished( NoResponse );
60 Q_EMIT finished( UnknownError );
64 AsyncCDDBPLookup::slotConnectionSuccess()
66 qCDebug(LIBKCDDB) <<
"Connection successful";
67 state_ = WaitingForGreeting;
71 AsyncCDDBPLookup::slotReadyRead()
73 qCDebug(LIBKCDDB) <<
"Ready to read. State: " << stateToString();
75 while ( Idle != state_ && isConnected() && socket_->canReadLine() )
80 AsyncCDDBPLookup::read()
84 case WaitingForGreeting:
86 if ( !parseGreeting( readLine() ) )
88 result_ = ServerError;
97 case WaitingForHandshake:
99 if ( !parseHandshake( readLine() ) )
101 result_ = ServerError;
110 case WaitingForProtoResponse:
119 case WaitingForQueryResponse:
120 result_ = parseQuery( readLine() );
125 requestCDInfoForMatch();
128 case MultipleRecordFound:
129 state_ = WaitingForMoreMatches;
139 case WaitingForMoreMatches:
144 requestCDInfoForMatch();
146 parseExtraMatch( line );
151 case WaitingForCDInfoResponse:
153 Result result = parseRead( readLine() );
155 if ( Success != result )
162 state_ = WaitingForCDInfoData;
167 case WaitingForCDInfoData:
174 requestCDInfoForMatch();
177 cdInfoBuffer_ << line;
182 case WaitingForQuitResponse:
187 while ( socket_->bytesAvailable() )
188 socket_->getChar(&c);
192 Q_EMIT finished( result_ );
203 AsyncCDDBPLookup::readLine()
209 AsyncCDDBPLookup::doHandshake()
213 state_ = WaitingForHandshake;
217 AsyncCDDBPLookup::doProto()
221 state_ = WaitingForProtoResponse;
225 AsyncCDDBPLookup::doQuery()
229 state_ = WaitingForQueryResponse;
233 AsyncCDDBPLookup::requestCDInfoForMatch()
235 if (matchList_.isEmpty())
237 result_ = cdInfoList_.isEmpty()? NoRecordFound :
Success;
242 CDDBMatch
match = matchList_.takeFirst();
246 state_ = WaitingForCDInfoResponse;
250 AsyncCDDBPLookup::parseCDInfoData()
254 if (info.load( cdInfoBuffer_ ))
259 cdInfoList_.append( info );
262 cdInfoBuffer_.clear();
266 AsyncCDDBPLookup::doQuit()
268 state_ = WaitingForQuitResponse;
274 AsyncCDDBPLookup::stateToString()
const
282 case WaitingForConnection:
286 case WaitingForGreeting:
290 case WaitingForProtoResponse:
294 case WaitingForHandshake:
298 case WaitingForQueryResponse:
302 case WaitingForMoreMatches:
306 case WaitingForCDInfoResponse:
310 case WaitingForCDInfoData:
314 case WaitingForQuitResponse:
325#include "moc_asynccddbplookup.cpp"
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
QVariant read(const QByteArray &data, int versionOverride=0)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
const QList< QKeySequence > & close()
void connectToHost(const QHostAddress &address, quint16 port, OpenMode openMode)
QString fromUtf8(QByteArrayView str)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)