~ubuntu-branches/ubuntu/wily/kid3/wily-proposed

« back to all changes in this revision

Viewing changes to src/core/import/importclient.cpp

  • Committer: Package Import Robot
  • Author(s): Ana Beatriz Guerrero Lopez, Patrick Matthäi, Ana Beatriz Guerrero Lopez
  • Date: 2011-11-13 16:34:13 UTC
  • mfrom: (1.1.13) (2.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111113163413-5y0anlc4dqf511uh
Tags: 2.0.1-1
* New upstream release.

[ Patrick Matthäi ]
* Adjust build system.
* Add build dependency xsltproc.

[ Ana Beatriz Guerrero Lopez ]
* Some more adjustments to the build system taken from upstream's deb/
* directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file importclient.cpp
 
3
 * Client to connect to server with import data.
 
4
 *
 
5
 * \b Project: Kid3
 
6
 * \author Urs Fleisch
 
7
 * \date 09 Oct 2006
 
8
 *
 
9
 * Copyright (C) 2006-2011  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/>.
 
25
 */
 
26
 
 
27
#include "importclient.h"
 
28
#include <QRegExp>
 
29
#include <QStatusBar>
 
30
#include <QUrl>
 
31
 
 
32
#include "serverimporterconfig.h"
 
33
 
 
34
/**
 
35
 * Constructor.
 
36
 *
 
37
 * @param parent  parent object
 
38
 */
 
39
ImportClient::ImportClient(QObject* parent) :
 
40
  HttpClient(parent), m_requestType(RT_None)
 
41
{
 
42
  setObjectName("ImportClient");
 
43
  connect(this, SIGNAL(bytesReceived(const QByteArray&)),
 
44
          this, SLOT(requestFinished(const QByteArray&)));
 
45
}
 
46
 
 
47
/**
 
48
 * Destructor.
 
49
 */
 
50
ImportClient::~ImportClient()
 
51
{
 
52
}
 
53
 
 
54
/**
 
55
 * Find keyword on server.
 
56
 *
 
57
 * @param cfg    import source configuration
 
58
 * @param artist artist to search
 
59
 * @param album  album to search
 
60
 */
 
61
void ImportClient::find(const ServerImporterConfig* cfg,
 
62
                              const QString& artist, const QString& album)
 
63
{
 
64
  sendFindQuery(cfg, artist, album);
 
65
  m_requestType = RT_Find;
 
66
}
 
67
 
 
68
/**
 
69
 * Handle response when request is finished.
 
70
 * The data is sent to other objects via signals.
 
71
 *
 
72
 * @param rcvStr received data
 
73
 */
 
74
void ImportClient::requestFinished(const QByteArray& rcvStr)
 
75
{
 
76
  switch (m_requestType) {
 
77
    case RT_Album:
 
78
      emit albumFinished(rcvStr);
 
79
      break;
 
80
    case RT_Find:
 
81
      emit findFinished(rcvStr);
 
82
      break;
 
83
    default:
 
84
      qWarning("Unknown import request type");
 
85
  }
 
86
}
 
87
 
 
88
/**
 
89
 * Request track list from server.
 
90
 *
 
91
 * @param cfg import source configuration
 
92
 * @param cat category
 
93
 * @param id  ID
 
94
 */
 
95
void ImportClient::getTrackList(const ServerImporterConfig* cfg, QString cat, QString id)
 
96
{
 
97
  sendTrackListQuery(cfg, cat, id);
 
98
  m_requestType = RT_Album;
 
99
}
 
100
 
 
101
/**
 
102
 * Encode a query in an URL.
 
103
 * The query is percent-encoded with spaces collapsed and replaced by '+'.
 
104
 *
 
105
 * @param query query to encode
 
106
 *
 
107
 * @return encoded query.
 
108
 */
 
109
QString ImportClient::encodeUrlQuery(const QString& query)
 
110
{
 
111
  QString result(query);
 
112
  result.replace(QRegExp(" +"), " "); // collapse spaces
 
113
  result = QUrl::toPercentEncoding(result);
 
114
  result.replace("%20", "+"); // replace spaces by '+'
 
115
  return result;
 
116
}