21 #include "knotifyclient.h"
23 #include <tqdatastream.h>
24 #include <tqptrstack.h>
26 #include <kapplication.h>
27 #include <kstandarddirs.h>
28 #include <kapplication.h>
30 #include <dcopclient.h>
32 #include <kstaticdeleter.h>
34 static const char daemonName[] =
"knotify";
36 static bool canAvoidStartupEvent(
const TQString& event,
const TQString& appname,
int present )
38 static bool checkAvoid =
true;
41 if(( appname !=
"kwin" && appname !=
"ksmserver" ) || present > 0 ) {
46 static KConfig* configfile = appname !=
"ksmserver"
47 ?
new KConfig( appname +
".eventsrc",
true,
false )
48 : new
KConfig(
"knotify.eventsrc", true, false );
49 static KConfig* eventsfile = appname !=
"ksmserver"
50 ?
new KConfig( appname +
"/eventsrc",
true,
false,
"data" )
51 : new
KConfig(
"knotify/eventsrc", true, false,
"data" );
54 int ev1 = configfile->
readNumEntry(
"presentation", -2 );
55 int ev2 = eventsfile->
readNumEntry(
"default_presentation", -2 );
56 if(( ev1 == -2 && ev2 == -2 )
58 || ( ev1 == -2 && ev2 > 0 )) {
65 static int sendNotifyEvent(
const TQString &message,
const TQString &text,
66 int present,
int level,
const TQString &sound,
67 const TQString &file,
int winId )
81 if( canAvoidStartupEvent( message, appname, present ))
84 int uniqueId = kMax( 1, kapp->random() );
87 TQWidget* widget = TQT_TQWIDGET(TQWidget::find( (WId)winId ));
89 winId = (int)widget->topLevelWidget()->winId();
92 TQDataStream ds(data, IO_WriteOnly);
93 ds << message << appname << text << sound << file << present << level
99 if ( client->
send(daemonName,
"Notify",
"notify(TQString,TQString,TQString,TQString,TQString,int,int,int,int)", data) )
109 return event( 0, type, text );
114 return event(0, message, text);
118 const TQString &sound,
const TQString &file)
120 return userEvent( 0, text, present, level, sound, file );
129 message = TQString::fromLatin1(
"cannotopenfile");
132 message = TQString::fromLatin1(
"warning");
135 message = TQString::fromLatin1(
"fatalerror");
138 message = TQString::fromLatin1(
"catastrophe");
142 message = TQString::fromLatin1(
"notification");
146 return sendNotifyEvent( message, text, Default, Default,
147 TQString::null, TQString::null, winId );
151 const TQString &text)
153 return sendNotifyEvent(message, text, Default, Default, TQString::null, TQString::null, winId);
158 const TQString &sound,
const TQString &file)
160 return sendNotifyEvent(TQString::null, text, present, level, sound, file, winId);
166 if (eventname.isEmpty())
return Default;
178 if (eventname.isEmpty())
return TQString::null;
191 return TQString::null;
197 if (eventname.isEmpty())
return Default;
202 present=eventsfile.
readNumEntry(
"default_presentation", -1);
209 if (eventname.isEmpty())
return TQString::null;
222 return TQString::null;
227 static bool firstTry =
true;
228 if (!kapp->dcopClient()->isApplicationRegistered(daemonName)) {
242 TQApplication::beep();
252 TQApplication::beep();
259 TQApplication::beep();
272 class KNotifyClient::InstanceStack
275 InstanceStack() { m_defaultInstance = 0; }
276 virtual ~InstanceStack() {
delete m_defaultInstance; }
277 void push(Instance *
instance) { m_instances.push(instance); }
279 void pop(Instance *instance)
283 else if (!m_instances.isEmpty())
285 kdWarning(160) <<
"Tried to remove an Instance that is not the current," <<
endl;
286 kdWarning(160) <<
"Resetting to the main KApplication." <<
endl;
290 kdWarning(160) <<
"Tried to remove an Instance, but the stack was empty." <<
endl;
293 Instance *currentInstance()
295 if (m_instances.isEmpty())
297 m_defaultInstance =
new Instance(kapp);
299 return m_instances.top();
303 TQPtrStack<Instance> m_instances;
304 Instance *m_defaultInstance;
307 KNotifyClient::InstanceStack * KNotifyClient::Instance::s_instances = 0L;
310 struct KNotifyClient::InstancePrivate
318 d =
new InstancePrivate;
320 instances()->push(
this);
324 d->useSystemBell = config->
readBoolEntry(
"UseSystemBell",
false );
330 s_instances->pop(
this);
334 KNotifyClient::InstanceStack *KNotifyClient::Instance::instances()
337 instancesDeleter.
setObject(s_instances,
new InstanceStack);
343 return d->useSystemBell;
362 return currentInstance()->d->instance;