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 #include <QList>
27 
28 #include "channelicon.h"
29 
30 #include "compat.h"
31 
32 #include "serviceUtil.h"
33 #include "mythdownloadmanager.h"
34 
36 //
38 
39 DTC::ChannelIconList* ChannelIcon::LookupChannelIcon ( const QString &Query,
40  const QString &FieldName )
41 {
42  DTC::ChannelIconList *pChannelIcons = new DTC::ChannelIconList();
43  LOG(VB_GENERAL, LOG_ERR,
44  QString("ChannelIcon::LookupChannelIcon - Unexpected FieldName '%1'").arg(FieldName));
45  // check the FieldName is valid
46  if (FieldName != "callsign" || FieldName != "xmltv")
47  {
48  //throw( QString("FieldName appears invalid."));
49  return pChannelIcons;
50  }
51 
52  // query http://services.mythtv.org/channel-icon/lookup
53  QByteArray data;
54  QString lookupUrl = QString("http://services.mythtv.org/channel-icon/lookup?%1=%2").arg(FieldName).arg(Query);
55  if (!GetMythDownloadManager()->download(lookupUrl, &data))
56  {
57  //throw( QString("Download from services.mythtv.org failed."));
58  return pChannelIcons;
59  }
60 
61  // ----------------------------------------------------------------------
62  // Build Response
63  // ----------------------------------------------------------------------
64 
65  QString response = QString(data.constData());
66  QStringList lines = response.split('\n');
67 
68  for (int x = 0; x < lines.count(); x++)
69  {
70  QString line = lines.at(x);
71  QStringList fields = line.split(',');
72 
73  if (fields.size() >= 4)
74  {
75  QString id = fields.at(2);
76  QString name = fields.at(3);
77  QString url = fields.at(1);
78 
79  DTC::ChannelIcon *pChannelIcon = pChannelIcons->AddNewChannelIcon();
80  pChannelIcon->setChannelIconId(id.toUInt());
81  pChannelIcon->setIconName(name);
82  pChannelIcon->setURL(url);
83  }
84  }
85 
86  return pChannelIcons;
87 }
88 
90 //
92 
93 
94 DTC::ChannelIconList* ChannelIcon::SearchChannelIcon ( const QString &Query )
95 {
96  DTC::ChannelIconList *pChannelIcons = new DTC::ChannelIconList();
97 
98  // query http://services.mythtv.org/channel-icon/search
99  QByteArray data;
100  QString searchUrl = QString("http://services.mythtv.org/channel-icon/search?s=%1").arg(Query);
101  if (!GetMythDownloadManager()->download(searchUrl, &data))
102  return pChannelIcons;
103 
104  // ----------------------------------------------------------------------
105  // Build Response
106  // ----------------------------------------------------------------------
107 
108  QString response = QString(data.constData());
109  QStringList lines = response.split('\n');
110 
111  for (int x = 0; x < lines.count(); x++)
112  {
113  QString line = lines.at(x);
114  QStringList fields = line.split(',');
115 
116  if (fields.size() >= 3)
117  {
118  QString id = fields.at(0);
119  QString name = fields.at(1);
120  QString url = fields.at(2);
121 
122  DTC::ChannelIcon *pChannelIcon = pChannelIcons->AddNewChannelIcon();
123  pChannelIcon->setChannelIconId(id.toUInt());
124  pChannelIcon->setIconName(name);
125  pChannelIcon->setURL(url);
126  }
127  }
128 
129  return pChannelIcons;
130 }
DTC::ChannelIconList * SearchChannelIcon(const QString &Query)
Definition: channelicon.cpp:94
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
const char * name
Definition: ParseText.cpp:328
DTC::ChannelIconList * LookupChannelIcon(const QString &Query, const QString &FieldName)
Definition: channelicon.cpp:39
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41