1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 Notification Action constants and utility functions.
4 Copyright : (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
6 Original author: Gary Cramblitt <garycramblitt@comcast.net>
7 Current Maintainer: 2004 by Gary Cramblitt <garycramblitt@comcast.net>
8 ******************************************************************************/
10 /***************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; version 2 of the License. *
16 ***************************************************************************/
22 #include <QStringList>
27 #include <kstaticdeleter.h>
32 static QStringList
* s_actionNames
= 0;
33 static KStaticDeleter
<QStringList
> s_actionNames_sd
;
35 static QStringList
* s_actionDisplayNames
= 0;
36 static KStaticDeleter
<QStringList
> s_actionDisplayNames_sd
;
38 static void notifyaction_init()
42 s_actionNames_sd
.setObject(s_actionNames
, new QStringList
);
43 s_actionNames
->append( "SpeakEventName" );
44 s_actionNames
->append( "SpeakMsg" );
45 s_actionNames
->append( "DoNotSpeak" );
46 s_actionNames
->append( "SpeakCustom" );
48 s_actionDisplayNames_sd
.setObject(s_actionDisplayNames
, new QStringList
);
49 s_actionDisplayNames
->append( i18n("Speak event name") );
50 s_actionDisplayNames
->append( i18n("Speak the notification message") );
51 s_actionDisplayNames
->append( i18n("Do not speak the notification") );
52 s_actionDisplayNames
->append( i18n("Speak custom text:") );
56 /*static*/ int NotifyAction::count()
59 return s_actionNames
->count();
62 /*static*/ QString
NotifyAction::actionName( const int action
)
65 return (*s_actionNames
)[ action
];
68 /*static*/ int NotifyAction::action( const QString
& actionName
)
71 return s_actionNames
->findIndex( actionName
);
74 /*static*/ QString
NotifyAction::actionDisplayName( const int action
)
77 return (*s_actionDisplayNames
)[ action
];
80 /*static*/ QString
NotifyAction::actionDisplayName( const QString
& actionName
)
83 return (*s_actionDisplayNames
)[ action( actionName
) ];
86 // --------------------------------------------------------------------
88 static QStringList
* s_presentNames
= 0;
89 static KStaticDeleter
<QStringList
> s_presentNames_sd
;
91 static QStringList
* s_presentDisplayNames
= 0;
92 static KStaticDeleter
<QStringList
> s_presentDisplayNames_sd
;
94 static void notifypresent_init()
96 if ( !s_presentNames
)
98 s_presentNames_sd
.setObject( s_presentNames
, new QStringList
);
99 s_presentNames
->append( "None" );
100 s_presentNames
->append( "Dialog" );
101 s_presentNames
->append( "Passive" );
102 s_presentNames
->append( "DialogAndPassive" );
103 s_presentNames
->append( "All" );
105 s_presentDisplayNames_sd
.setObject( s_presentDisplayNames
, new QStringList
);
106 s_presentDisplayNames
->append( i18n("none") );
107 s_presentDisplayNames
->append( i18n("notification dialogs") );
108 s_presentDisplayNames
->append( i18n("passive popups") );
109 s_presentDisplayNames
->append( i18n("notification dialogs and passive popups") );
110 s_presentDisplayNames
->append( i18n("all notifications" ) );
114 /*static*/ int NotifyPresent::count()
116 notifypresent_init();
117 return s_presentNames
->count();
120 /*static*/ QString
NotifyPresent::presentName( const int present
)
122 notifypresent_init();
123 return (*s_presentNames
)[ present
];
126 /*static*/ int NotifyPresent::present( const QString
& presentName
)
128 notifypresent_init();
129 return s_presentNames
->findIndex( presentName
);
132 /*static*/ QString
NotifyPresent::presentDisplayName( const int present
)
134 notifypresent_init();
135 return (*s_presentDisplayNames
)[ present
];
138 /*static*/ QString
NotifyPresent::presentDisplayName( const QString
& presentName
)
140 notifypresent_init();
141 return (*s_presentDisplayNames
)[ present( presentName
) ];
144 // --------------------------------------------------------------------
147 * Retrieves the displayable name for an event source.
149 /*static*/ QString
NotifyEvent::getEventSrcName(const QString
& eventSrc
, QString
& iconName
)
151 QString configFilename
= eventSrc
+ QString::fromLatin1( "/eventsrc" );
152 KConfig
* config
= new KConfig( configFilename
, true, false, "data" );
153 config
->setGroup( QString::fromLatin1( "!Global!" ) );
154 QString appDesc
= config
->readEntry( "Comment", i18n("No description available") );
155 iconName
= config
->readEntry( "IconName" );
161 * Retrieves the displayable name for an event from an event source.
163 /*static*/ QString
NotifyEvent::getEventName(const QString
& eventSrc
, const QString
& event
)
166 QString configFilename
= eventSrc
+ QString::fromLatin1( "/eventsrc" );
167 KConfig
* config
= new KConfig( configFilename
, true, false, "data" );
168 if ( config
->hasGroup( event
) )
170 config
->setGroup( event
);
171 eventName
= config
->readEntry( QString::fromLatin1( "Comment" ),
172 config
->readEntry( QString::fromLatin1( "Name" ),QString()));