Lines 21-26
Link Here
|
21 |
#include <qregexp.h> |
21 |
#include <qregexp.h> |
22 |
#include <qsocket.h> |
22 |
#include <qsocket.h> |
23 |
#include <qstatusbar.h> |
23 |
#include <qstatusbar.h> |
|
|
24 |
#include <qurl.h> |
24 |
#include "freedbconfig.h" |
25 |
#include "freedbconfig.h" |
25 |
#include "freedbclient.h" |
26 |
#include "freedbclient.h" |
26 |
|
27 |
|
Lines 34-40
Link Here
|
34 |
* |
35 |
* |
35 |
* @param sb status bar to display progress information. |
36 |
* @param sb status bar to display progress information. |
36 |
*/ |
37 |
*/ |
37 |
FreedbClient::FreedbClient(QStatusBar *sb) : statusBar(sb) |
38 |
FreedbClient::FreedbClient(QStatusBar *sb) : |
|
|
39 |
statusBar(sb), m_requestType(RT_None) |
38 |
{ |
40 |
{ |
39 |
sock = new QSocket(); |
41 |
sock = new QSocket(); |
40 |
connect(sock, SIGNAL(hostFound()), |
42 |
connect(sock, SIGNAL(hostFound()), |
Lines 158-164
Link Here
|
158 |
} |
160 |
} |
159 |
#endif |
161 |
#endif |
160 |
sock->connectToHost(dest, destPort); |
162 |
sock->connectToHost(dest, destPort); |
161 |
isAlbumRequest = false; |
163 |
m_requestType = RT_FindFreedbSearch; |
|
|
164 |
|
165 |
statusBar->message(i18n("Connecting...")); |
166 |
} |
167 |
|
168 |
/** |
169 |
* Find keyword in freedb with "cddb album" command of freedb2.org. |
170 |
* |
171 |
* @param cfg freedb configuration |
172 |
* @param what string with words to search |
173 |
*/ |
174 |
void FreedbClient::findCddbAlbum(const FreedbConfig *cfg, QString what) |
175 |
{ |
176 |
QString destNamePort(getProxyOrDest(cfg, cfg->server)); |
177 |
QString dest; |
178 |
int destPort; |
179 |
splitNamePort(destNamePort, dest, destPort); |
180 |
what.replace(QRegExp(" +"), " "); // collapse spaces |
181 |
QUrl::encode(what); |
182 |
what.replace("%20", "+"); // replace spaces by '+' |
183 |
request = "GET http://" + cfg->server + cfg->cgiPath + |
184 |
"?cmd=cddb+album+" + what + "&hello=noname+localhost+" + |
185 |
"Kid3+" VERSION "&proto=1 HTTP/1.1\r\nHost: " + cfg->server + |
186 |
"\r\nConnection: close\r\n\r\n"; |
187 |
#if defined WIN32 && QT_VERSION < 300 |
188 |
int err = hostnameToAddress(dest); |
189 |
if (err) { |
190 |
statusBar->message(QString("WinSock error %1").arg(err)); |
191 |
return; |
192 |
} |
193 |
#endif |
194 |
sock->connectToHost(dest, destPort); |
195 |
m_requestType = RT_FindCddbAlbum; |
162 |
|
196 |
|
163 |
statusBar->message(i18n("Connecting...")); |
197 |
statusBar->message(i18n("Connecting...")); |
164 |
} |
198 |
} |
Lines 186-199
Link Here
|
186 |
*/ |
220 |
*/ |
187 |
void FreedbClient::slotConnectionClosed() |
221 |
void FreedbClient::slotConnectionClosed() |
188 |
{ |
222 |
{ |
189 |
rcvStr = ""; |
223 |
Q_ULONG len = sock->bytesAvailable(); |
190 |
while (sock->canReadLine()) { |
224 |
QCString s; |
191 |
rcvStr += sock->readLine(); |
225 |
s.resize(len + 1); |
192 |
} |
226 |
sock->readBlock(s.data(), len); |
193 |
if (isAlbumRequest) { |
227 |
rcvStr = QString::fromUtf8(s.data()); |
194 |
emit albumFinished(rcvStr); |
228 |
switch (m_requestType) { |
195 |
} else { |
229 |
case RT_Album: |
196 |
emit findFinished(rcvStr); |
230 |
emit albumFinished(rcvStr); |
|
|
231 |
break; |
232 |
case RT_FindFreedbSearch: |
233 |
emit findFinished(rcvStr); |
234 |
break; |
235 |
case RT_FindCddbAlbum: |
236 |
emit findCddbAlbumFinished(rcvStr); |
237 |
break; |
238 |
default: |
239 |
qWarning("Unknown freedb request type"); |
197 |
} |
240 |
} |
198 |
sock->close(); |
241 |
sock->close(); |
199 |
statusBar->message(i18n("Ready.")); |
242 |
statusBar->message(i18n("Ready.")); |
Lines 256-261
Link Here
|
256 |
} |
299 |
} |
257 |
#endif |
300 |
#endif |
258 |
sock->connectToHost(dest, destPort); |
301 |
sock->connectToHost(dest, destPort); |
259 |
isAlbumRequest = true; |
302 |
m_requestType = RT_Album; |
260 |
statusBar->message(i18n("Connecting...")); |
303 |
statusBar->message(i18n("Connecting...")); |
261 |
} |
304 |
} |