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
|
/*
kopetenotifydataobject.cpp - Container for notification events
Copyright (c) 2004 by Will Stephenson <[email protected]>
Kopete (c) 2002-2004 by the Kopete developers <[email protected]>
*************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#include <tqdom.h>
#include <kdebug.h>
#include "kopetenotifydataobject.h"
#include "kopetenotifyevent.h"
class Kopete::NotifyDataObject::Private
{
public:
TQDict<Kopete::NotifyEvent> events;
};
Kopete::NotifyDataObject::NotifyDataObject()
{
d = new Private();
d->events.setAutoDelete( true );
}
Kopete::NotifyDataObject::~NotifyDataObject()
{
delete d;
}
Kopete::NotifyEvent * Kopete::NotifyDataObject::notifyEvent( const TQString &event ) const
{
Kopete::NotifyEvent *evt = d->events.find( event );
return evt;
}
void Kopete::NotifyDataObject::setNotifyEvent( const TQString& event, Kopete::NotifyEvent *notifyEvent )
{
d->events.replace( event, notifyEvent );
}
bool Kopete::NotifyDataObject::removeNotifyEvent( const TQString &event )
{
return d->events.remove( event );
}
TQDomElement Kopete::NotifyDataObject::notifyDataToXML()
{
TQDomDocument notify;
TQDomElement notifications;
if ( !d->events.isEmpty() )
{
//<custom-notifications>
notifications = notify.createElement( TQString::fromLatin1( "custom-notifications" ) );
TQDictIterator<Kopete::NotifyEvent> it( d->events );
for ( ; it.current(); ++it )
{
//<event name="..." suppress-common="true|false">
TQDomElement event = notify.createElement( TQString::fromLatin1( "event" ) );
event.setAttribute( TQString::fromLatin1( "name" ), it.currentKey() );
event.setAttribute( TQString::fromLatin1( "suppress-common" ), TQString::fromLatin1( it.current()->suppressCommon() ? "true" : "false" ) );
TQValueList<TQDomElement> presentations = it.current()->toXML();
//<sound-notification enabled="true|false" src="..." single-shot="">
for ( TQValueList<TQDomElement>::Iterator it = presentations.begin(); it != presentations.end(); ++it )
event.appendChild( notify.importNode( *it, true ) );
notifications.appendChild( event );
}
}
return notifications;
}
bool Kopete::NotifyDataObject::notifyDataFromXML( const TQDomElement& element )
{
if ( element.tagName() == TQString::fromLatin1( "custom-notifications" ) )
{
TQDomNode field = element.firstChild();
while( !field.isNull() )
{
//read an event
TQDomElement fieldElement = field.toElement();
if ( fieldElement.tagName() == TQString::fromLatin1( "event" ) )
{
// get its attributes
TQString name = fieldElement.attribute( TQString::fromLatin1( "name" ), TQString() );
TQString suppress = fieldElement.attribute( TQString::fromLatin1( "suppress-common" ), TQString() );
Kopete::NotifyEvent *evt = new Kopete::NotifyEvent( suppress == TQString::fromLatin1( "true" ) );
// get its children
TQDomNode child = fieldElement.firstChild();
while( !child.isNull() )
{
TQDomElement childElement = child.toElement();
if ( childElement.tagName() == TQString::fromLatin1( "sound-presentation" ) )
{
// kdDebug(14010) << k_funcinfo << "read: sound" << endl;
TQString src = childElement.attribute( TQString::fromLatin1( "src" ) );
TQString enabled = childElement.attribute( TQString::fromLatin1( "enabled" ) );
TQString singleShot = childElement.attribute( TQString::fromLatin1( "single-shot" ) );
Kopete::EventPresentation *pres = new Kopete::EventPresentation( Kopete::EventPresentation::Sound, src,
( singleShot == TQString::fromLatin1( "true" ) ),
( enabled == TQString::fromLatin1( "true" ) ) );
evt->setPresentation( Kopete::EventPresentation::Sound, pres );
// kdDebug(14010) << k_funcinfo << "after sound: " << evt->toString() << endl;
}
if ( childElement.tagName() == TQString::fromLatin1( "message-presentation" ) )
{
// kdDebug(14010) << k_funcinfo << "read: msg" << endl;
TQString src = childElement.attribute( TQString::fromLatin1( "src" ) );
TQString enabled = childElement.attribute( TQString::fromLatin1( "enabled" ) );
TQString singleShot = childElement.attribute( TQString::fromLatin1( "single-shot" ) );
Kopete::EventPresentation *pres = new Kopete::EventPresentation( Kopete::EventPresentation::Message, src,
( singleShot == TQString::fromLatin1( "true" ) ),
( enabled == TQString::fromLatin1( "true" ) ) );
evt->setPresentation( Kopete::EventPresentation::Message, pres );
// kdDebug(14010) << k_funcinfo << "after message: " << evt->toString() << endl;
}
if ( childElement.tagName() == TQString::fromLatin1( "chat-presentation" ) )
{
// kdDebug(14010) << k_funcinfo << "read: chat" << endl;
TQString enabled = childElement.attribute( TQString::fromLatin1( "enabled" ) );
TQString singleShot = childElement.attribute( TQString::fromLatin1( "single-shot" ) );
Kopete::EventPresentation *pres = new Kopete::EventPresentation( Kopete::EventPresentation::Chat, TQString(),
( singleShot == TQString::fromLatin1( "true" ) ),
( enabled == TQString::fromLatin1( "true" ) ) );
evt->setPresentation( Kopete::EventPresentation::Chat, pres );
// kdDebug(14010) << k_funcinfo << "after chat: " << evt->toString() << endl;
}
child = child.nextSibling();
}
// kdDebug(14010) << k_funcinfo << "read: " << evt->toString() << endl;
setNotifyEvent( name, evt );
}
field = field.nextSibling();
}
return true;
}
else
{
kdDebug( 14010 ) << "element wasn't custom-notifications" << endl;
return false;
}
}
|