~ubuntu-branches/ubuntu/karmic/kid3/karmic

« back to all changes in this revision

Viewing changes to kid3/freedbclient.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2009-05-20 16:12:30 UTC
  • mfrom: (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20090520161230-qetp532r8ydujkz2
Tags: upstream-1.2
Import upstream version 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * \author Urs Fleisch
7
7
 * \date 18 Jan 2004
8
8
 *
9
 
 * Copyright (C) 2004-2007  Urs Fleisch
 
9
 * Copyright (C) 2004-2009  Urs Fleisch
10
10
 *
11
11
 * This file is part of Kid3.
12
12
 *
26
26
 
27
27
#include "freedbclient.h"
28
28
#include "importsourceconfig.h"
29
 
#include <qregexp.h>
30
 
#include <qurl.h>
31
29
 
32
30
static const char gnudbServer[] = "www.gnudb.org:80";
33
31
 
46
44
}
47
45
 
48
46
/**
49
 
 * Construct a query command in m_request to search on the server.
 
47
 * Send a query command in to search on the server.
50
48
 *
51
49
 * @param cfg      import source configuration
52
50
 * @param artist   artist to search
53
51
 * @param album    album to search
54
 
 * @param dest     the server to connect to is returned here
55
 
 * @param destPort the port of the server is returned here
56
52
 */
57
 
void FreedbClient::constructFindQuery(
 
53
void FreedbClient::sendFindQuery(
58
54
        const ImportSourceConfig*,
59
 
        const QString& artist, const QString& album,
60
 
        QString& dest, int& destPort)
 
55
        const QString& artist, const QString& album)
61
56
{
62
57
        // At the moment, only www.gnudb.org has a working search
63
58
        // so we always use this server for find queries.
64
 
        QString server(gnudbServer);
65
 
        QString what = artist + " " + album;
66
 
        QString destNamePort(getProxyOrDest(server));
67
 
        splitNamePort(destNamePort, dest, destPort);
68
 
        QString serverName;
69
 
        int serverPort;
70
 
        splitNamePort(server, serverName, serverPort);
71
 
        what.replace(QRegExp(" +"), " "); // collapse spaces
72
 
        QCM_QUrl_encode(what);
73
 
        what.replace("%20", "+"); // replace spaces by '+'
74
 
        m_request = "GET ";
75
 
        if (dest != serverName) {
76
 
                m_request += "http://";
77
 
                m_request += serverName;
78
 
                if (serverPort != 80) {
79
 
                        m_request += ':';
80
 
                        m_request += QString::number(serverPort);
81
 
                }
82
 
        }
83
 
        m_request += "/search/";
84
 
        m_request += what;
85
 
        m_request += " HTTP/1.0\r\nUser-Agent: Kid3/" VERSION "\r\nHost: ";
86
 
        m_request += serverName;
87
 
        m_request += "\r\nConnection: close\r\n\r\n";
 
59
        sendRequest(gnudbServer, QString("/search/") +
 
60
                                                        encodeUrlQuery(artist + " " + album));
88
61
}
89
62
 
90
63
/**
91
 
 * Construct a query command in m_request to fetch the track list
 
64
 * Send a query command to fetch the track list
92
65
 * from the server.
93
66
 *
94
67
 * @param cfg      import source configuration
95
68
 * @param cat      category
96
69
 * @param id       ID
97
 
 * @param dest     the server to connect to is returned here
98
 
 * @param destPort the port of the server is returned here
99
70
 */
100
 
void FreedbClient::constructTrackListQuery(
101
 
        const ImportSourceConfig* cfg, const QString& cat, const QString& id,
102
 
        QString& dest, int& destPort)
 
71
void FreedbClient::sendTrackListQuery(
 
72
        const ImportSourceConfig* cfg, const QString& cat, const QString& id)
103
73
{
104
 
        QString destNamePort(getProxyOrDest(cfg->m_server));
105
 
        splitNamePort(destNamePort, dest, destPort);
106
 
        QString serverName;
107
 
        int serverPort;
108
 
        splitNamePort(cfg->m_server, serverName, serverPort);
109
 
        m_request = "GET ";
110
 
        if (dest != serverName) {
111
 
                m_request += "http://";
112
 
                m_request += serverName;
113
 
                if (serverPort != 80) {
114
 
                        m_request += ':';
115
 
                        m_request += QString::number(serverPort);
116
 
                }
117
 
        }
118
 
        m_request += cfg->m_cgiPath;
119
 
        m_request += "?cmd=cddb+read+";
120
 
        m_request += cat;
121
 
        m_request += "+";
122
 
        m_request += id;
123
 
        m_request += "&hello=noname+localhost+";
124
 
        m_request += "Kid3+" VERSION "&proto=1 HTTP/1.1\r\nHost: ";
125
 
        m_request += serverName;
126
 
        m_request += "\r\nConnection: close\r\n\r\n";
 
74
        sendRequest(cfg->m_server,
 
75
                                                        cfg->m_cgiPath + "?cmd=cddb+read+" + cat + "+" + id +
 
76
                                                        "&hello=noname+localhost+Kid3+" VERSION "&proto=6");
127
77
}