2
* \file importclient.cpp
3
* Client to connect to server with import data.
9
* Copyright (C) 2006-2011 Urs Fleisch
11
* This file is part of Kid3.
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.
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.
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/>.
27
#include "importclient.h"
32
#include "serverimporterconfig.h"
37
* @param parent parent object
39
ImportClient::ImportClient(QObject* parent) :
40
HttpClient(parent), m_requestType(RT_None)
42
setObjectName("ImportClient");
43
connect(this, SIGNAL(bytesReceived(const QByteArray&)),
44
this, SLOT(requestFinished(const QByteArray&)));
50
ImportClient::~ImportClient()
55
* Find keyword on server.
57
* @param cfg import source configuration
58
* @param artist artist to search
59
* @param album album to search
61
void ImportClient::find(const ServerImporterConfig* cfg,
62
const QString& artist, const QString& album)
64
sendFindQuery(cfg, artist, album);
65
m_requestType = RT_Find;
69
* Handle response when request is finished.
70
* The data is sent to other objects via signals.
72
* @param rcvStr received data
74
void ImportClient::requestFinished(const QByteArray& rcvStr)
76
switch (m_requestType) {
78
emit albumFinished(rcvStr);
81
emit findFinished(rcvStr);
84
qWarning("Unknown import request type");
89
* Request track list from server.
91
* @param cfg import source configuration
95
void ImportClient::getTrackList(const ServerImporterConfig* cfg, QString cat, QString id)
97
sendTrackListQuery(cfg, cat, id);
98
m_requestType = RT_Album;
102
* Encode a query in an URL.
103
* The query is percent-encoded with spaces collapsed and replaced by '+'.
105
* @param query query to encode
107
* @return encoded query.
109
QString ImportClient::encodeUrlQuery(const QString& query)
111
QString result(query);
112
result.replace(QRegExp(" +"), " "); // collapse spaces
113
result = QUrl::toPercentEncoding(result);
114
result.replace("%20", "+"); // replace spaces by '+'