summaryrefslogtreecommitdiffstats
path: root/kresources/tvanytime/service.cpp
blob: 9c92f4f2be4251e3fb179319e0c74ec3804a85ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/***************************************************************************
 *   Copyright (C) 2005 by Will Stephenson   *
 *   wstephenson@kde.org   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#include "service.h"

Service::Service() : mActive( true )
{

}

Service::Service( bool active, const QString & name, const QString & owner, const KURL & serviceUrl, const KURL & logo, const QStringList & genres )
: mActive( active ), mName( name ), mOwner( owner ), mServiceUrl( serviceUrl ), mLogo( logo ), mGenres( genres )
{
}

void Service::setActive( bool active )
{
  mActive = active;
}

void Service::setName( const QString & name )
{
  mName = name;
}

void Service::setProgramInformation( const ProgramInformationMap & map )
{
  mProgInfo = map;
}

bool Service::active() const
{
  return mActive;
}

QString Service::name() const
{
  return mName;
}

bool Service::loadXML( const QDomElement & top )
{
  if ( top.tagName() != "ServiceInformation" ) {
    qWarning( "XML error: Top tag was %s instead of the expected service information",
              top.tagName().ascii() );
    return false;
  }

  setId( top.attribute( "serviceId" ) );

  for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    if ( n.isComment() )
      continue;
    if ( n.isElement() ) {
      QDomElement e = n.toElement();
      loadAttribute( e );
    } else
      qWarning( "Node is not a comment or an element???" );
  }
  return true;
}

bool Service::loadAttribute( const QDomElement& element )
{
  QString tagName = element.tagName();
  if ( tagName == "Name" ) {
    QDomNode cn = element.firstChild();
    QDomText t = cn.toText();
    mName = t.data();
  }
  else if ( tagName == "Owner" ) {
    QDomNode cn = element.firstChild();
    QDomText t = cn.toText();
    mOwner =  t.data();
  }
  else if ( tagName == "ServiceURL" ) {
    QDomNode cn = element.firstChild();
    QDomText t = cn.toText();
    mServiceUrl = t.data();
  }
  // TODO: parse logo data
  // TODO: parse genre data
  return true;
}

QRegExp ScheduleEvent::sRegExp( "PT(\\d{2})H(\\d{2})M(\\d{2})S" );

bool ScheduleEvent::loadXML( const QDomElement & top )
{
  if ( top.tagName() != "ScheduleEvent" ) {
    qWarning( "XML error: Top tag was %s instead of the expected event",
              top.tagName().ascii() );
    return false;
  }

  mCrid = top.attribute( "serviceId" );

  for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    if ( n.isComment() )
      continue;
    if ( n.isElement() ) {
      QDomElement e = n.toElement();
      loadAttribute( e );
    } else
      qWarning( "Node is not a comment or an element???" );
  }
  return true;
}

bool ScheduleEvent::loadAttribute( const QDomElement& element )
{
  QString tagName = element.tagName();
  if ( tagName == "ProgramURL" ) {
    QDomNode cn = element.firstChild();
    QDomText t = cn.toText();
    mUrl = t.data();
  }
  else if ( tagName == "Program" ) {
    mCrid = element.attribute( "crid" );
  }
  else if ( tagName == "PublishedStartTime" ) {
    QDomNode cn = element.firstChild();
    QDomText t = cn.toText();
    mStartTime = QDateTime::fromString( t.data(), Qt::ISODate );
  }
  else if ( tagName == "PublishedDuration" ) {
    QDomNode cn = element.firstChild();
    QDomText t = cn.toText();
    QString duration = t.data();
    if ( sRegExp.search( duration ) != -1 )
    {
      mDuration = 0;
      mDuration += 60 * 60 * sRegExp.cap( 1 ).toUInt();
      mDuration += 60 * sRegExp.cap( 2 ).toUInt();
      mDuration += sRegExp.cap( 3 ).toUInt();
    }
  }
  return true;
}

ProgramInformationMap Service::programmeInformation() const
{
  return mProgInfo;
}

ProgramInformation::ProgramInformation( const QString & title, const QString &synopsis )
: mTitle( title ), mSynopsis( synopsis )
{

}

bool ProgramInformation::loadXML( const QDomElement & top )
{
  if ( top.tagName() != "ProgramInformation" ) {
    qWarning( "XML error: Top tag was %s instead of the expected program information",
              top.tagName().ascii() );
    return false;
  }

  setId( top.attribute( "programId" ) );

  for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    if ( n.isComment() )
      continue;
    if ( n.isElement() ) {
      QDomElement e = n.toElement();
      if ( e.tagName() == "BasicDescription" )
      {
        for ( QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling() ) {
          if ( n.isComment() )
            continue;
          if ( n.isElement() ) {
            QDomElement e = n.toElement();    
            loadAttribute( e );
          }
        }
      }
    } else
      qWarning( "Node is not a comment or an element???" );
  }
  return true;
}

bool ProgramInformation::loadAttribute( const QDomElement& element )
{
  QString tagName = element.tagName();
  if ( tagName == "Title" ) {
    QDomNode cn = element.firstChild();
    QDomText t = cn.toText();
    mTitle = t.data();
  }
  else if ( tagName == "Synopsis" ) {
    QDomNode cn = element.firstChild();
    QDomText t = cn.toText();
    mSynopsis =  t.data();
  }
  else if ( tagName == "Genre" ) {
    QDomNode name = element.firstChild();
    QDomElement nameElem = name.toElement();
    if ( nameElem.tagName() == "Name" ) {
      QDomNode cn = nameElem.firstChild();
      QDomText t = cn.toText();
      mGenres.append( t.data() );
    }
  }
  return true;
}