MythTV  master
channelicon.cpp
Go to the documentation of this file.
1 // Program Name: channelicon.cpp
3 // Created : Jun. 22, 2014
4 //
5 // Copyright (c) 2014 The MythTV Developers
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //
25 
26 // Qt
27 #include <QList>
28 
29 // MythTV
30 #include "libmythbase/compat.h"
32 
33 // MythBackend
34 #include "channelicon.h"
35 #include "serviceUtil.h"
36 
38 //
40 
41 DTC::ChannelIconList* ChannelIcon::LookupChannelIcon ( const QString &Query,
42  const QString &FieldName )
43 {
44  DTC::ChannelIconList *pChannelIcons = new DTC::ChannelIconList();
45  LOG(VB_GENERAL, LOG_ERR,
46  QString("ChannelIcon::LookupChannelIcon - Unexpected FieldName '%1'").arg(FieldName));
47  // check the FieldName is valid
48  if (FieldName != "callsign" || FieldName != "xmltv")
49  {
50  //throw( QString("FieldName appears invalid."));
51  return pChannelIcons;
52  }
53 
54  // query http://services.mythtv.org/channel-icon/lookup
55  QByteArray data;
56  QString lookupUrl = QString("http://services.mythtv.org/channel-icon/lookup?%1=%2").arg(FieldName).arg(Query);
57  if (!GetMythDownloadManager()->download(lookupUrl, &data))
58  {
59  //throw( QString("Download from services.mythtv.org failed."));
60  return pChannelIcons;
61  }
62 
63  // ----------------------------------------------------------------------
64  // Build Response
65  // ----------------------------------------------------------------------
66 
67  QString response = QString(data.constData());
68  QStringList lines = response.split('\n');
69 
70  for (int x = 0; x < lines.count(); x++)
71  {
72  QString line = lines.at(x);
73  QStringList fields = line.split(',');
74 
75  if (fields.size() >= 4)
76  {
77  QString id = fields.at(2);
78  QString name = fields.at(3);
79  QString url = fields.at(1);
80 
81  DTC::ChannelIcon *pChannelIcon = pChannelIcons->AddNewChannelIcon();
82  pChannelIcon->setChannelIconId(id.toUInt());
83  pChannelIcon->setIconName(name);
84  pChannelIcon->setURL(url);
85  }
86  }
87 
88  return pChannelIcons;
89 }
90 
92 //
94 
95 
96 DTC::ChannelIconList* ChannelIcon::SearchChannelIcon ( const QString &Query )
97 {
98  DTC::ChannelIconList *pChannelIcons = new DTC::ChannelIconList();
99 
100  // query http://services.mythtv.org/channel-icon/search
101  QByteArray data;
102  QString searchUrl = QString("http://services.mythtv.org/channel-icon/search?s=%1").arg(Query);
103  if (!GetMythDownloadManager()->download(searchUrl, &data))
104  return pChannelIcons;
105 
106  // ----------------------------------------------------------------------
107  // Build Response
108  // ----------------------------------------------------------------------
109 
110  QString response = QString(data.constData());
111  QStringList lines = response.split('\n');
112 
113  for (int x = 0; x < lines.count(); x++)
114  {
115  QString line = lines.at(x);
116  QStringList fields = line.split(',');
117 
118  if (fields.size() >= 3)
119  {
120  QString id = fields.at(0);
121  QString name = fields.at(1);
122  QString url = fields.at(2);
123 
124  DTC::ChannelIcon *pChannelIcon = pChannelIcons->AddNewChannelIcon();
125  pChannelIcon->setChannelIconId(id.toUInt());
126  pChannelIcon->setIconName(name);
127  pChannelIcon->setURL(url);
128  }
129  }
130 
131  return pChannelIcons;
132 }
serviceUtil.h
ChannelIcon::SearchChannelIcon
DTC::ChannelIconList * SearchChannelIcon(const QString &Query)
Definition: channelicon.cpp:96
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
compat.h
ChannelIcon::LookupChannelIcon
DTC::ChannelIconList * LookupChannelIcon(const QString &Query, const QString &FieldName)
Definition: channelicon.cpp:41
channelicon.h
mythdownloadmanager.h
GetMythDownloadManager
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
Definition: mythdownloadmanager.cpp:145