3 xtrazxawayservice.cpp - Xtraz XAwayService
5 Copyright (c) 2007 Roman Jarosz <kedgedev@centrum.cz>
7 Kopete (c) 2007 by the Kopete developers <kopete-devel@kde.org>
9 *************************************************************************
11 * This library is free software; you can redistribute it and/or *
12 * modify it under the terms of the GNU Lesser General Public *
13 * License as published by the Free Software Foundation; either *
14 * version 2 of the License, or (at your option) any later version. *
16 *************************************************************************
19 #include "xtrazxawayservice.h"
24 XAwayService::XAwayService()
30 void XAwayService::setSenderId( const QString
& uni
)
35 QString
XAwayService::senderId() const
40 void XAwayService::setIconIndex( int index
)
42 m_iconIndex
= index
+ 1;
45 int XAwayService::iconIndex() const
47 return m_iconIndex
- 1;
50 void XAwayService::setTitle( const QString
& title
)
55 QString
XAwayService::title() const
60 void XAwayService::setDescription( const QString
& desc
)
65 QString
XAwayService::description() const
70 QString
XAwayService::serviceId() const
72 return QString::fromUtf8( "cAwaySrv" );
75 void XAwayService::createRequest( QDomDocument
& doc
, QDomElement
&e
) const
77 QDomElement eId
= doc
.createElement( "id" );
78 eId
.appendChild( doc
.createTextNode( "AwayStat" ) );
81 QDomElement eTrans
= doc
.createElement( "trans" );
82 eTrans
.appendChild( doc
.createTextNode( "1" ) );
83 e
.appendChild( eTrans
);
85 QDomElement eSenderId
= doc
.createElement( "senderId" );
86 eSenderId
.appendChild( doc
.createTextNode( m_senderId
) );
87 e
.appendChild( eSenderId
);
91 void XAwayService::createResponse( QDomDocument
& doc
, QDomElement
&e
) const
93 QDomElement eRoot
= doc
.createElement( "Root" );
95 eRoot
.appendChild( doc
.createElement( "CASXtraSetAwayMessage" ) );
97 QDomElement eSenderId
= doc
.createElement( "uin" );
98 eSenderId
.appendChild( doc
.createTextNode( m_senderId
) );
99 eRoot
.appendChild( eSenderId
);
101 QDomElement eIndex
= doc
.createElement( "index" );
102 eIndex
.appendChild( doc
.createTextNode( QString::number( m_iconIndex
) ) );
103 eRoot
.appendChild( eIndex
);
105 QDomElement eTitle
= doc
.createElement( "title" );
106 eTitle
.appendChild( doc
.createTextNode( m_title
) );
107 eRoot
.appendChild( eTitle
);
109 QDomElement eDesc
= doc
.createElement( "desc" );
110 eDesc
.appendChild( doc
.createTextNode( m_desc
) );
111 eRoot
.appendChild( eDesc
);
113 e
.appendChild( eRoot
);
116 void XAwayService::handleRequest( QDomElement
& eRoot
)
119 for ( childNode
= eRoot
.firstChild(); !childNode
.isNull(); childNode
= childNode
.nextSibling() )
121 QDomElement e
= childNode
.toElement();
124 if ( e
.tagName() == "id" )
125 Q_ASSERT( e
.text() == "AwayStat" );
126 // else if ( e.tagName() == "trans" )
127 else if ( e
.tagName() == "senderId" )
128 m_senderId
= e
.text();
133 void XAwayService::handleResponse( QDomElement
& eRoot
)
135 QDomElement rootElement
= eRoot
.firstChild().toElement();
136 if ( !rootElement
.isNull() && rootElement
.tagName() == "Root" )
139 for ( childNode
= rootElement
.firstChild(); !childNode
.isNull(); childNode
= childNode
.nextSibling() )
141 QDomElement e
= childNode
.toElement();
144 if ( e
.tagName() == "title" )
146 else if ( e
.tagName() == "desc" )
148 else if ( e
.tagName() == "index" )
149 m_iconIndex
= e
.text().toInt();
150 else if ( e
.tagName() == "uin" )
151 m_senderId
= e
.text();