You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
6.5 KiB
225 lines
6.5 KiB
15 years ago
|
/***************************************************************************
|
||
|
* 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., *
|
||
15 years ago
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||
15 years ago
|
***************************************************************************/
|
||
|
|
||
|
#include "service.h"
|
||
|
|
||
|
Service::Service() : mActive( true )
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
14 years ago
|
Service::Service( bool active, const TQString & name, const TQString & owner, const KURL & serviceUrl, const KURL & logo, const TQStringList & genres )
|
||
15 years ago
|
: mActive( active ), mName( name ), mOwner( owner ), mServiceUrl( serviceUrl ), mLogo( logo ), mGenres( genres )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void Service::setActive( bool active )
|
||
|
{
|
||
|
mActive = active;
|
||
|
}
|
||
|
|
||
14 years ago
|
void Service::setName( const TQString & name )
|
||
15 years ago
|
{
|
||
|
mName = name;
|
||
|
}
|
||
|
|
||
|
void Service::setProgramInformation( const ProgramInformationMap & map )
|
||
|
{
|
||
|
mProgInfo = map;
|
||
|
}
|
||
|
|
||
|
bool Service::active() const
|
||
|
{
|
||
|
return mActive;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString Service::name() const
|
||
15 years ago
|
{
|
||
|
return mName;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool Service::loadXML( const TQDomElement & top )
|
||
15 years ago
|
{
|
||
|
if ( top.tagName() != "ServiceInformation" ) {
|
||
13 years ago
|
tqWarning( "XML error: Top tag was %s instead of the expected service information",
|
||
15 years ago
|
top.tagName().ascii() );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
setId( top.attribute( "serviceId" ) );
|
||
|
|
||
14 years ago
|
for ( TQDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||
15 years ago
|
if ( n.isComment() )
|
||
|
continue;
|
||
|
if ( n.isElement() ) {
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
loadAttribute( e );
|
||
|
} else
|
||
13 years ago
|
tqWarning( "Node is not a comment or an element???" );
|
||
15 years ago
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool Service::loadAttribute( const TQDomElement& element )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString tagName = element.tagName();
|
||
15 years ago
|
if ( tagName == "Name" ) {
|
||
14 years ago
|
TQDomNode cn = element.firstChild();
|
||
|
TQDomText t = cn.toText();
|
||
15 years ago
|
mName = t.data();
|
||
|
}
|
||
|
else if ( tagName == "Owner" ) {
|
||
14 years ago
|
TQDomNode cn = element.firstChild();
|
||
|
TQDomText t = cn.toText();
|
||
15 years ago
|
mOwner = t.data();
|
||
|
}
|
||
|
else if ( tagName == "ServiceURL" ) {
|
||
14 years ago
|
TQDomNode cn = element.firstChild();
|
||
|
TQDomText t = cn.toText();
|
||
15 years ago
|
mServiceUrl = t.data();
|
||
|
}
|
||
|
// TODO: parse logo data
|
||
|
// TODO: parse genre data
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQRegExp ScheduleEvent::sRegExp( "PT(\\d{2})H(\\d{2})M(\\d{2})S" );
|
||
15 years ago
|
|
||
14 years ago
|
bool ScheduleEvent::loadXML( const TQDomElement & top )
|
||
15 years ago
|
{
|
||
|
if ( top.tagName() != "ScheduleEvent" ) {
|
||
13 years ago
|
tqWarning( "XML error: Top tag was %s instead of the expected event",
|
||
15 years ago
|
top.tagName().ascii() );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
mCrid = top.attribute( "serviceId" );
|
||
|
|
||
14 years ago
|
for ( TQDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||
15 years ago
|
if ( n.isComment() )
|
||
|
continue;
|
||
|
if ( n.isElement() ) {
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
loadAttribute( e );
|
||
|
} else
|
||
13 years ago
|
tqWarning( "Node is not a comment or an element???" );
|
||
15 years ago
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool ScheduleEvent::loadAttribute( const TQDomElement& element )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString tagName = element.tagName();
|
||
15 years ago
|
if ( tagName == "ProgramURL" ) {
|
||
14 years ago
|
TQDomNode cn = element.firstChild();
|
||
|
TQDomText t = cn.toText();
|
||
15 years ago
|
mUrl = t.data();
|
||
|
}
|
||
|
else if ( tagName == "Program" ) {
|
||
|
mCrid = element.attribute( "crid" );
|
||
|
}
|
||
|
else if ( tagName == "PublishedStartTime" ) {
|
||
14 years ago
|
TQDomNode cn = element.firstChild();
|
||
|
TQDomText t = cn.toText();
|
||
14 years ago
|
mStartTime = TQDateTime::fromString( t.data(), TQt::ISODate );
|
||
15 years ago
|
}
|
||
|
else if ( tagName == "PublishedDuration" ) {
|
||
14 years ago
|
TQDomNode cn = element.firstChild();
|
||
|
TQDomText t = cn.toText();
|
||
|
TQString duration = t.data();
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
|
||
14 years ago
|
ProgramInformation::ProgramInformation( const TQString & title, const TQString &synopsis )
|
||
15 years ago
|
: mTitle( title ), mSynopsis( synopsis )
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
14 years ago
|
bool ProgramInformation::loadXML( const TQDomElement & top )
|
||
15 years ago
|
{
|
||
|
if ( top.tagName() != "ProgramInformation" ) {
|
||
13 years ago
|
tqWarning( "XML error: Top tag was %s instead of the expected program information",
|
||
15 years ago
|
top.tagName().ascii() );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
setId( top.attribute( "programId" ) );
|
||
|
|
||
14 years ago
|
for ( TQDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||
15 years ago
|
if ( n.isComment() )
|
||
|
continue;
|
||
|
if ( n.isElement() ) {
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
if ( e.tagName() == "BasicDescription" )
|
||
|
{
|
||
14 years ago
|
for ( TQDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||
15 years ago
|
if ( n.isComment() )
|
||
|
continue;
|
||
|
if ( n.isElement() ) {
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
loadAttribute( e );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
} else
|
||
13 years ago
|
tqWarning( "Node is not a comment or an element???" );
|
||
15 years ago
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool ProgramInformation::loadAttribute( const TQDomElement& element )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString tagName = element.tagName();
|
||
15 years ago
|
if ( tagName == "Title" ) {
|
||
14 years ago
|
TQDomNode cn = element.firstChild();
|
||
|
TQDomText t = cn.toText();
|
||
15 years ago
|
mTitle = t.data();
|
||
|
}
|
||
|
else if ( tagName == "Synopsis" ) {
|
||
14 years ago
|
TQDomNode cn = element.firstChild();
|
||
|
TQDomText t = cn.toText();
|
||
15 years ago
|
mSynopsis = t.data();
|
||
|
}
|
||
|
else if ( tagName == "Genre" ) {
|
||
14 years ago
|
TQDomNode name = element.firstChild();
|
||
|
TQDomElement nameElem = name.toElement();
|
||
15 years ago
|
if ( nameElem.tagName() == "Name" ) {
|
||
14 years ago
|
TQDomNode cn = nameElem.firstChild();
|
||
|
TQDomText t = cn.toText();
|
||
15 years ago
|
mGenres.append( t.data() );
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|