21 #include "knotifyclient.h"
23 #include <tqdatastream.h>
24 #include <tqptrstack.h>
26 #include <tdeapplication.h>
27 #include <kstandarddirs.h>
28 #include <tdeapplication.h>
29 #include <tdeconfig.h>
30 #include <dcopclient.h>
32 #include <kstaticdeleter.h>
37 #include <X11/XKBlib.h>
38 #include <X11/keysym.h>
42 static const char daemonName[] =
"knotify";
44 static bool canAvoidStartupEvent(
const TQString& event,
const TQString& appname,
int present )
46 static bool checkAvoid =
true;
49 if(( appname !=
"twin" && appname !=
"ksmserver" ) || present > 0 ) {
54 static TDEConfig* configfile = appname !=
"ksmserver"
55 ?
new TDEConfig( appname +
".eventsrc",
true,
false )
56 : new
TDEConfig(
"knotify.eventsrc", true, false );
57 static TDEConfig* eventsfile = appname !=
"ksmserver"
58 ?
new TDEConfig( appname +
"/eventsrc",
true,
false,
"data" )
59 : new
TDEConfig(
"knotify/eventsrc", true, false,
"data" );
62 int ev1 = configfile->
readNumEntry(
"presentation", -2 );
63 int ev2 = eventsfile->
readNumEntry(
"default_presentation", -2 );
64 if(( ev1 == -2 && ev2 == -2 )
66 || ( ev1 == -2 && ev2 > 0 )) {
73 static int sendNotifyEvent(
const TQString &message,
const TQString &text,
74 int present,
int level,
const TQString &sound,
75 const TQString &file,
int winId )
81 XFlush(tqt_xdisplay());
94 if( canAvoidStartupEvent( message, appname, present ))
97 int uniqueId = kMax( 1, kapp->random() );
100 TQWidget* widget = TQT_TQWIDGET(TQWidget::find( (WId)winId ));
102 winId = (int)widget->topLevelWidget()->winId();
105 TQDataStream ds(data, IO_WriteOnly);
106 ds << message << appname << text << sound << file << present << level
107 << winId << uniqueId;
112 if ( client->
send(daemonName,
"Notify",
"notify(TQString,TQString,TQString,TQString,TQString,int,int,int,int)", data) )
122 return event( 0, type, text );
127 return event(0, message, text);
131 const TQString &sound,
const TQString &file)
133 return userEvent( 0, text, present, level, sound, file );
142 message = TQString::fromLatin1(
"cannotopenfile");
145 message = TQString::fromLatin1(
"warning");
148 message = TQString::fromLatin1(
"fatalerror");
151 message = TQString::fromLatin1(
"catastrophe");
155 message = TQString::fromLatin1(
"notification");
159 return sendNotifyEvent( message, text, Default, Default,
160 TQString::null, TQString::null, winId );
164 const TQString &text)
166 return sendNotifyEvent(message, text, Default, Default, TQString::null, TQString::null, winId);
171 const TQString &sound,
const TQString &file)
173 return sendNotifyEvent(TQString::null, text, present, level, sound, file, winId);
179 if (eventname.isEmpty())
return Default;
191 if (eventname.isEmpty())
return TQString::null;
204 return TQString::null;
210 if (eventname.isEmpty())
return Default;
215 present=eventsfile.
readNumEntry(
"default_presentation", -1);
222 if (eventname.isEmpty())
return TQString::null;
235 return TQString::null;
240 static bool firstTry =
true;
241 if (!kapp->dcopClient()->isApplicationRegistered(daemonName)) {
255 TQApplication::beep();
265 TQApplication::beep();
272 TQApplication::beep();
285 class KNotifyClient::InstanceStack
288 InstanceStack() { m_defaultInstance = 0; }
289 virtual ~InstanceStack() {
delete m_defaultInstance; }
290 void push(Instance *
instance) { m_instances.push(instance); }
292 void pop(Instance *instance)
296 else if (!m_instances.isEmpty())
298 kdWarning(160) <<
"Tried to remove an Instance that is not the current," <<
endl;
299 kdWarning(160) <<
"Resetting to the main TDEApplication." <<
endl;
303 kdWarning(160) <<
"Tried to remove an Instance, but the stack was empty." <<
endl;
306 Instance *currentInstance()
308 if (m_instances.isEmpty())
310 m_defaultInstance =
new Instance(kapp);
312 return m_instances.top();
316 TQPtrStack<Instance> m_instances;
317 Instance *m_defaultInstance;
320 KNotifyClient::InstanceStack * KNotifyClient::Instance::s_instances = 0L;
323 struct KNotifyClient::InstancePrivate
331 d =
new InstancePrivate;
333 instances()->push(
this);
337 d->useSystemBell = config->
readBoolEntry(
"UseSystemBell",
false );
343 s_instances->pop(
this);
347 KNotifyClient::InstanceStack *KNotifyClient::Instance::instances()
350 instancesDeleter.
setObject(s_instances,
new InstanceStack);
356 return d->useSystemBell;
375 return currentInstance()->d->instance;