Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 150808
Collapse All | Expand All

(-)kid3-0.7/kid3/freedbclient.cpp (-11 / +54 lines)
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
}
(-)kid3-0.7/kid3/freedbclient.h (-2 / +19 lines)
Lines 44-49 Link Here
44
	 */
44
	 */
45
	void find(const FreedbConfig *cfg, QString what);
45
	void find(const FreedbConfig *cfg, QString what);
46
	/**
46
	/**
47
	 * Find keyword in freedb with "cddb album" command of freedb2.org.
48
	 *
49
	 * @param cfg  freedb configuration
50
	 * @param what string with words to search
51
	 */
52
	void findCddbAlbum(const FreedbConfig *cfg, QString what);
53
	/**
47
	 * Request track list from freedb server.
54
	 * Request track list from freedb server.
48
	 *
55
	 *
49
	 * @param cfg freedb configuration
56
	 * @param cfg freedb configuration
Lines 92-97 Link Here
92
	 */
99
	 */
93
	void findFinished(QString);
100
	void findFinished(QString);
94
	/**
101
	/**
102
	 * Emitted when findCddbAlbum request finished.
103
	 * Parameter: text containing result of findCddbAlbum request
104
	 */
105
	void findCddbAlbumFinished(QString);
106
	/**
95
	 * Emitted when album track data request finished.
107
	 * Emitted when album track data request finished.
96
	 * Parameter: text containing result of album request
108
	 * Parameter: text containing result of album request
97
	 */
109
	 */
Lines 105-112 Link Here
105
	QString request;
117
	QString request;
106
	/** buffer for received data */
118
	/** buffer for received data */
107
	QString rcvStr;
119
	QString rcvStr;
108
	/** true if last request was album track data request */
120
	/** type of current request */
109
	bool isAlbumRequest;
121
	enum RequestType {
122
		RT_None,
123
		RT_FindFreedbSearch,
124
		RT_FindCddbAlbum,
125
		RT_Album
126
	} m_requestType;
110
};
127
};
111
128
112
#endif
129
#endif
(-)kid3-0.7/kid3/freedbdialog.cpp (-1 / +58 lines)
Lines 24-29 Link Here
24
#include <qlistbox.h>
24
#include <qlistbox.h>
25
#include <qlabel.h>
25
#include <qlabel.h>
26
#include <qstatusbar.h>
26
#include <qstatusbar.h>
27
#include <qregexp.h>
27
#include "freedbconfig.h"
28
#include "freedbconfig.h"
28
#include "freedbclient.h"
29
#include "freedbclient.h"
29
#include "freedbdialog.h"
30
#include "freedbdialog.h"
Lines 109-114 Link Here
109
	if (serverLayout && serverLabel && serverComboBox &&
110
	if (serverLayout && serverLabel && serverComboBox &&
110
		cgiLabel && cgiLineEdit) {
111
		cgiLabel && cgiLineEdit) {
111
		static const char *serverList[] = {
112
		static const char *serverList[] = {
113
			"freedb2.org:80",
112
			"freedb.freedb.org:80",
114
			"freedb.freedb.org:80",
113
			"at.freedb.org:80",
115
			"at.freedb.org:80",
114
			"au.freedb.org:80",
116
			"au.freedb.org:80",
Lines 155-160 Link Here
155
		client = new FreedbClient(statusBar);
157
		client = new FreedbClient(statusBar);
156
		connect(client, SIGNAL(findFinished(QString)),
158
		connect(client, SIGNAL(findFinished(QString)),
157
				this, SLOT(slotFindFinished(QString)));
159
				this, SLOT(slotFindFinished(QString)));
160
		connect(client, SIGNAL(findCddbAlbumFinished(QString)),
161
				this, SLOT(slotFindCddbAlbumFinished(QString)));
158
		connect(client, SIGNAL(albumFinished(QString)),
162
		connect(client, SIGNAL(albumFinished(QString)),
159
				this, SLOT(slotAlbumFinished(QString)));
163
				this, SLOT(slotAlbumFinished(QString)));
160
	}
164
	}
Lines 315-321 Link Here
315
{
319
{
316
	FreedbConfig cfg;
320
	FreedbConfig cfg;
317
	getFreedbConfig(&cfg);
321
	getFreedbConfig(&cfg);
318
	client->find(&cfg, findLineEdit->currentText());
322
//	client->find(&cfg, findLineEdit->currentText());
323
	client->findCddbAlbum(&cfg, findLineEdit->currentText());
319
}
324
}
320
325
321
/**
326
/**
Lines 364-369 Link Here
364
}
369
}
365
370
366
/**
371
/**
372
 * Process finished findCddbAlbum request.
373
 *
374
 * @param searchStr search data received
375
 */
376
void FreedbDialog::slotFindCddbAlbumFinished(QString searchStr)
377
{
378
/*
379
210 exact matches found
380
categ discid dtitle
381
(more matches...)
382
.
383
or
384
211 close matches found
385
rock 920b810c Catharsis / Imago
386
.
387
theoretically, but never seen
388
200	categ discid dtitle
389
*/
390
	QRegExp catIdTitleRe("([a-z]+)\\s+([0-9a-f]+)\\s+([^/]+ / .+)");
391
	QStringList lines = QStringList::split(QRegExp("[\\r\\n]+"), searchStr);
392
	bool inEntries = false;
393
	albumListBox->clear();
394
	for (QStringList::const_iterator it = lines.begin(); it != lines.end(); ++it) {
395
		if (*it == ".") {
396
			break;
397
		}
398
		if (inEntries) {
399
			if (catIdTitleRe.exactMatch(*it)) {
400
				new AlbumListItem(
401
					albumListBox,
402
					catIdTitleRe.cap(3),
403
					catIdTitleRe.cap(1),
404
					catIdTitleRe.cap(2));
405
			}
406
		} else {
407
			if ((*it).startsWith("21") && (*it).find(" match") != -1) {
408
				inEntries = true;
409
			} else if ((*it).startsWith("200 ")) {
410
				if (catIdTitleRe.exactMatch((*it).mid(4))) {
411
					new AlbumListItem(
412
						albumListBox,
413
						catIdTitleRe.cap(3),
414
						catIdTitleRe.cap(1),
415
						catIdTitleRe.cap(2));
416
				}
417
			}
418
		}
419
	}
420
	albumListBox->setFocus();
421
}
422
423
/**
367
 * Process finished album data.
424
 * Process finished album data.
368
 *
425
 *
369
 * @param albumStr album track data received
426
 * @param albumStr album track data received
(-)kid3-0.7/kid3/freedbdialog.h (+6 lines)
Lines 117-122 Link Here
117
	 */
117
	 */
118
	void slotFindFinished(QString searchStr);
118
	void slotFindFinished(QString searchStr);
119
	/**
119
	/**
120
	 * Process finished findCddbAlbum request.
121
	 *
122
	 * @param searchStr search data received
123
	 */
124
	void slotFindCddbAlbumFinished(QString searchStr);
125
	/**
120
	 * Process finished album data.
126
	 * Process finished album data.
121
	 *
127
	 *
122
	 * @param albumStr album track data received
128
	 * @param albumStr album track data received

Return to bug 150808