blob: 544c3e45562be7d36ed36400f8889136618d1fcb (
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
|
/*
kopetenotifyevent.h - Kopete Notifications for a given event
Copyright (c) 2004 by Will Stephenson <lists@stevello.free-online.co.uk>
Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* 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 "kopetenotifyevent.h"
#include "kopeteeventpresentation.h"
Kopete::NotifyEvent::NotifyEvent( const bool suppressCommon )
{
m_suppressCommon = suppressCommon;
m_message = 0;
m_chat = 0;
m_sound = 0;
}
Kopete::NotifyEvent::~NotifyEvent()
{
delete m_sound;
delete m_message;
delete m_chat;
}
bool Kopete::NotifyEvent::suppressCommon() const
{
return m_suppressCommon;
}
Kopete::EventPresentation *Kopete::NotifyEvent::presentation( const Kopete::EventPresentation::PresentationType type ) const
{
switch ( type )
{
case Kopete::EventPresentation::Sound:
return m_sound;
case Kopete::EventPresentation::Message:
return m_message;
case Kopete::EventPresentation::Chat:
return m_chat;
default:
return 0;
}
}
void Kopete::NotifyEvent::removePresentation( const Kopete::EventPresentation::PresentationType type )
{
Kopete::EventPresentation **presToChange;
switch ( type )
{
case Kopete::EventPresentation::Sound:
presToChange = &m_sound;
break;
case Kopete::EventPresentation::Message:
presToChange = &m_message;
break;
case Kopete::EventPresentation::Chat:
presToChange = &m_chat;
break;
default:
kdDebug( 14010 ) << k_funcinfo << " Someone tried to set an unrecognised type of presentation!" << endl;
return;
}
if ( *presToChange )
{
delete *presToChange;
*presToChange = 0;
}
}
void Kopete::NotifyEvent::setPresentation( const Kopete::EventPresentation::PresentationType type, Kopete::EventPresentation * notification )
{
Kopete::EventPresentation **presToChange;
switch ( type )
{
case Kopete::EventPresentation::Sound:
presToChange = &m_sound;
break;
case Kopete::EventPresentation::Message:
presToChange = &m_message;
break;
case Kopete::EventPresentation::Chat:
presToChange = &m_chat;
break;
default:
kdDebug( 14010 ) << k_funcinfo << " Someone tried to set an unrecognised type of presentation!" << endl;
return;
}
if ( *presToChange )
delete *presToChange;
*presToChange = notification;
}
bool Kopete::NotifyEvent::firePresentation( const Kopete::EventPresentation::PresentationType type )
{
kdDebug( 14010 ) << k_funcinfo << endl;
Kopete::EventPresentation **presToChange;
switch ( type )
{
case Kopete::EventPresentation::Sound:
presToChange = &m_sound;
break;
case Kopete::EventPresentation::Message:
presToChange = &m_message;
break;
case Kopete::EventPresentation::Chat:
presToChange = &m_chat;
break;
default:
return false;
}
kdDebug( 14010 ) << toString() << endl;
if ( *presToChange && (*presToChange)->singleShot() )
{
kdDebug( 14010 ) << " removing singleshot!" << endl;
delete *presToChange;
*presToChange = 0;
kdDebug( 14010 ) << toString() << endl;
return true;
}
return false;
}
void Kopete::NotifyEvent::setSuppressCommon( const bool suppress )
{
m_suppressCommon = suppress;
}
const TQValueList<TQDomElement> Kopete::NotifyEvent::toXML() const
{
TQDomDocument eventData;
TQValueList<TQDomElement> eventNodes;
if ( m_sound && !m_sound->content().isEmpty() )
{
TQDomElement soundElmt = eventData.createElement( TQString::fromLatin1( "sound-presentation" ) );
soundElmt.setAttribute( TQString::fromLatin1( "enabled" ), TQString::fromLatin1( m_sound->enabled() ? "true" : "false" ) );
soundElmt.setAttribute( TQString::fromLatin1( "single-shot" ), TQString::fromLatin1( m_sound->singleShot() ? "true" : "false" ) );
soundElmt.setAttribute( TQString::fromLatin1( "src" ), m_sound->content() );
eventNodes.append( soundElmt );
}
if ( m_message && !m_message->content().isEmpty() )
{
TQDomElement msgElmt = eventData.createElement( TQString::fromLatin1( "message-presentation" ) );
msgElmt.setAttribute( TQString::fromLatin1( "enabled" ), TQString::fromLatin1( m_message->enabled() ? "true" : "false" ) );
msgElmt.setAttribute( TQString::fromLatin1( "single-shot" ), TQString::fromLatin1( m_message->singleShot() ? "true" : "false" ) );
msgElmt.setAttribute( TQString::fromLatin1( "src" ), m_message->content() );
eventNodes.append( msgElmt );
}
if ( m_chat && m_chat->enabled() )
{
TQDomElement chatElmt = eventData.createElement( TQString::fromLatin1( "chat-presentation" ) );
chatElmt.setAttribute( TQString::fromLatin1( "enabled" ), TQString::fromLatin1( "true" ) );
chatElmt.setAttribute( TQString::fromLatin1( "single-shot" ), TQString::fromLatin1( m_chat->singleShot() ? "true" : "false" ) );
eventNodes.append( chatElmt );
}
return eventNodes;
}
TQString Kopete::NotifyEvent::toString()
{
TQString stringRep = TQString::fromLatin1("Event; Suppress common=%1").tqarg( TQString::fromLatin1( suppressCommon() ? "true" : "false" ) );
if ( m_sound)
stringRep += m_sound->toString();
if ( m_message)
stringRep += m_message->toString();
if ( m_chat)
stringRep += m_chat->toString();
return stringRep;
}
|