~ubuntu-branches/ubuntu/intrepid/kid3/intrepid

« back to all changes in this revision

Viewing changes to kid3/musicbrainzclient.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michele Angrisano
  • Date: 2008-01-09 23:20:54 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080109232054-gtcjxz4ahdnzbt01
Tags: 0.10-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - debian/rules:
    + Use dh_icons instead dh_iconcache.
  - debian/control:
    + Update maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * \b Project: Kid3
6
6
 * \author Urs Fleisch
7
7
 * \date 15 Sep 2005
 
8
 *
 
9
 * Copyright (C) 2005-2007  Urs Fleisch
 
10
 *
 
11
 * This file is part of Kid3.
 
12
 *
 
13
 * Kid3 is free software; you can redistribute it and/or modify
 
14
 * it under the terms of the GNU General Public License as published by
 
15
 * the Free Software Foundation; either version 2 of the License, or
 
16
 * (at your option) any later version.
 
17
 *
 
18
 * Kid3 is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 * GNU General Public License for more details.
 
22
 *
 
23
 * You should have received a copy of the GNU General Public License
 
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
8
25
 */
9
26
 
10
27
#include "musicbrainzclient.h"
12
29
 
13
30
#include <qfile.h>
14
31
#if QT_VERSION >= 0x040000
15
 
#include <Q3Socket>
16
 
#include <Q3CString>
17
 
#else
18
 
#include <qsocket.h>
 
32
#include <QByteArray>
19
33
#endif
20
34
#if HAVE_TUNEPIMP >= 5
21
35
#include <qdom.h>
34
48
 * @param proxyPort  proxy port
35
49
 */
36
50
LookupQuery::LookupQuery(int numFiles,
37
 
                                                                                                 const QString& serverName, Q_UINT16 serverPort,
38
 
                                                                                                 const QString& proxyName, Q_UINT16 proxyPort) :
 
51
                                                                                                 const QString& serverName, unsigned short serverPort,
 
52
                                                                                                 const QString& proxyName, unsigned short proxyPort) :
39
53
        m_numFiles(numFiles), m_serverName(serverName), m_serverPort(serverPort),
40
54
        m_proxyName(proxyName), m_proxyPort(proxyPort),
41
55
        m_currentFile(-1), m_fileQueries(new FileQuery[numFiles]),
42
 
        m_sock(new Q3Socket)
 
56
#if QT_VERSION >= 0x040000
 
57
        m_sock(new QTcpSocket)
 
58
#else
 
59
        m_sock(new QSocket)
 
60
#endif
43
61
{
44
62
        for (int i = 0; i < m_numFiles; ++i) {
45
63
                m_fileQueries[i].requested = false;
47
65
        }
48
66
        connect(m_sock, SIGNAL(connected()),
49
67
                        this, SLOT(socketConnected()));
 
68
#if QT_VERSION >= 0x040000
 
69
        connect(m_sock, SIGNAL(error(QAbstractSocket::SocketError)),
 
70
                        this, SLOT(socketError(QAbstractSocket::SocketError)));
 
71
        connect(m_sock, SIGNAL(disconnected()),
 
72
                        this, SLOT(socketConnectionClosed()));
 
73
#else
50
74
        connect(m_sock, SIGNAL(error(int)),
51
 
                        this, SLOT(socketError()));
 
75
                        this, SLOT(socketError(int)));
52
76
        connect(m_sock, SIGNAL(connectionClosed()),
53
77
                        this, SLOT(socketConnectionClosed()));
 
78
#endif
54
79
}
55
80
 
56
81
/**
71
96
{
72
97
        if (m_currentFile >= 0 && m_currentFile < m_numFiles) {
73
98
                QString  destName = m_proxyName.isEmpty() ? m_serverName : m_proxyName;
74
 
                Q_UINT16 destPort = m_proxyName.isEmpty() ? m_serverPort : m_proxyPort;
 
99
                unsigned short destPort = m_proxyName.isEmpty() ? m_serverPort : m_proxyPort;
75
100
                m_request = "GET http://";
76
101
                m_request += m_serverName;
77
102
                if (m_serverPort != 80) {
128
153
 */
129
154
void LookupQuery::socketConnected()
130
155
{
131
 
        m_sock->writeBlock(m_request.latin1(), m_request.length());
 
156
        m_sock->QCM_writeBlock(m_request.QCM_latin1(), m_request.length());
132
157
}
133
158
 
134
159
/**
135
160
 * Error on socket connection.
136
161
 */
137
 
void LookupQuery::socketError()
 
162
#if QT_VERSION >= 0x040000
 
163
void LookupQuery::socketError(QAbstractSocket::SocketError err)
 
164
{
 
165
        if (err != QAbstractSocket::RemoteHostClosedError) {
 
166
                qDebug("Socket Error: %s", m_sock->errorString().QCM_latin1());
 
167
                queryNext();
 
168
        }
 
169
}
 
170
#else
 
171
void LookupQuery::socketError(int)
138
172
{
139
173
        queryNext();
140
174
}
 
175
#endif
141
176
 
142
177
/**
143
178
 * Read received data when the server has closed the connection.
144
179
 */
145
180
void LookupQuery::socketConnectionClosed()
146
181
{
147
 
        Q_ULONG len = m_sock->bytesAvailable();
148
 
        Q3CString buf;
 
182
        unsigned long len = m_sock->bytesAvailable();
 
183
        QCM_QCString buf;
149
184
        buf.resize(len + 1 );
150
 
        m_sock->readBlock(buf.data(), len);
 
185
        m_sock->QCM_readBlock(buf.data(), len);
151
186
        m_sock->close();
152
187
 
153
 
        int xmlStart = buf.find("<?xml");
 
188
        int xmlStart = buf.QCM_indexOf("<?xml");
154
189
        if (xmlStart >= 0 &&
155
190
                        m_currentFile >= 0 && m_currentFile < m_numFiles &&
156
191
                        m_fileQueries[m_currentFile].requested) {
340
375
#endif
341
376
                                if (statusCode != eLastStatus) {
342
377
                                        const char* statusText = getFileStatusText(statusCode);
343
 
                                        emit statusChanged(index, i18n(statusText));
 
378
                                        emit statusChanged(index, QCM_translate(statusText));
344
379
                                        if (statusCode == eRecognized) {
345
380
                                                ImportTrackData trackData;
346
381
                                                getMetaData(id, trackData);
397
432
        int port;
398
433
        QString ip;
399
434
        FreedbClient::splitNamePort(server, ip, port);
400
 
        tp_SetServer(m_tp, ip.latin1(), port);
 
435
        tp_SetServer(m_tp, ip.QCM_latin1(), port);
401
436
 
402
437
        if (useProxy) {
403
438
                FreedbClient::splitNamePort(proxy, ip, port);
404
 
                tp_SetProxy(m_tp, ip.latin1(), port);
 
439
                tp_SetProxy(m_tp, ip.QCM_latin1(), port);
405
440
        }       else {
406
441
                tp_SetProxy(m_tp, "", 80);
407
442
        }
648
683
 
649
684
#endif // HAVE_TUNEPIMP
650
685
 
651
 
#if !(HAVE_TUNEPIMP >= 5)
 
686
#if !(defined HAVE_TUNEPIMP && HAVE_TUNEPIMP >= 5)
652
687
 
653
 
LookupQuery::LookupQuery(int, const QString&, Q_UINT16, const QString&, Q_UINT16) {}
 
688
LookupQuery::LookupQuery(int, const QString&, unsigned short, const QString&, unsigned short) {}
654
689
LookupQuery::~LookupQuery() {}
655
690
void LookupQuery::socketConnected() {}
656
 
void LookupQuery::socketError() {}
 
691
#if QT_VERSION >= 0x040000
 
692
void LookupQuery::socketError(QAbstractSocket::SocketError) {}
 
693
#else
 
694
void LookupQuery::socketError(int) {}
 
695
#endif
657
696
void LookupQuery::socketConnectionClosed() {}
658
697
void MusicBrainzClient::parseLookupResponse(int, const QByteArray&) {}
659
698