summaryrefslogtreecommitdiffstats
path: root/kttsd/libkttsd/notify.cpp
blob: fd285871f0487ef4b4cfb65fe9496745ac466b5d (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
/***************************************************** vim:set ts=4 sw=4 sts=4:
  Notification Action constants and utility functions.
  -------------------
  Copyright : (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
  -------------------
  Original author: Gary Cramblitt <garycramblitt@comcast.net>
  Current Maintainer: 2004 by Gary Cramblitt <garycramblitt@comcast.net>
 ******************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; version 2 of the License.               *
 *                                                                         *
 ***************************************************************************/

// Qt includes.

// Qt includes.
#include <qstring.h>
#include <qstringlist.h>

// KDE includes.
#include <kconfig.h>
#include <klocale.h>
#include <kstaticdeleter.h>

// KTTS includes.
#include "notify.h"

static QStringList* s_actionNames = 0;
static KStaticDeleter<QStringList> s_actionNames_sd;

static QStringList* s_actionDisplayNames = 0;
static KStaticDeleter<QStringList> s_actionDisplayNames_sd;

static void notifyaction_init()
{
    if ( !s_actionNames )
    {
        s_actionNames_sd.setObject(s_actionNames, new QStringList);
        s_actionNames->append( "SpeakEventName" );
        s_actionNames->append( "SpeakMsg" );
        s_actionNames->append( "DoNotSpeak" );
        s_actionNames->append( "SpeakCustom" );

        s_actionDisplayNames_sd.setObject(s_actionDisplayNames, new QStringList);
        s_actionDisplayNames->append( i18n("Speak event name") );
        s_actionDisplayNames->append( i18n("Speak the notification message") );
        s_actionDisplayNames->append( i18n("Do not speak the notification") );
        s_actionDisplayNames->append( i18n("Speak custom text:") );
    }
}

/*static*/ int NotifyAction::count()
{
    notifyaction_init();
    return s_actionNames->count();
}

/*static*/ QString NotifyAction::actionName( const int action )
{
    notifyaction_init();
    return (*s_actionNames)[ action ];
}

/*static*/ int NotifyAction::action( const QString& actionName )
{
    notifyaction_init();
    return s_actionNames->findIndex( actionName );
}

/*static*/ QString NotifyAction::actionDisplayName( const int action )
{
    notifyaction_init();
    return (*s_actionDisplayNames)[ action ];
}

/*static*/ QString NotifyAction::actionDisplayName( const QString& actionName )
{
    notifyaction_init();
    return (*s_actionDisplayNames)[ action( actionName ) ];
}

// --------------------------------------------------------------------

static QStringList* s_presentNames = 0;
static KStaticDeleter<QStringList> s_presentNames_sd;

static QStringList* s_presentDisplayNames = 0;
static KStaticDeleter<QStringList> s_presentDisplayNames_sd;

static void notifypresent_init()
{
    if ( !s_presentNames )
    {
        s_presentNames_sd.setObject( s_presentNames, new QStringList );
        s_presentNames->append( "None" );
        s_presentNames->append( "Dialog" );
        s_presentNames->append( "Passive" );
        s_presentNames->append( "DialogAndPassive" );
        s_presentNames->append( "All" );

        s_presentDisplayNames_sd.setObject( s_presentDisplayNames, new QStringList );
        s_presentDisplayNames->append( i18n("none") );
        s_presentDisplayNames->append( i18n("notification dialogs") );
        s_presentDisplayNames->append( i18n("passive popups") );
        s_presentDisplayNames->append( i18n("notification dialogs and passive popups") );
        s_presentDisplayNames->append( i18n("all notifications" ) );
    }
}

/*static*/ int NotifyPresent::count()
{
    notifypresent_init();
    return s_presentNames->count();
}

/*static*/ QString NotifyPresent::presentName( const int present )
{
    notifypresent_init();
    return (*s_presentNames)[ present ];
}

/*static*/ int NotifyPresent::present( const QString& presentName )
{
    notifypresent_init();
    return s_presentNames->findIndex( presentName );
}

/*static*/ QString NotifyPresent::presentDisplayName( const int present )
{
    notifypresent_init();
    return (*s_presentDisplayNames)[ present ];
}

/*static*/ QString NotifyPresent::presentDisplayName( const QString& presentName )
{
    notifypresent_init();
    return (*s_presentDisplayNames)[ present( presentName ) ];
}

// --------------------------------------------------------------------

/**
 * Retrieves the displayable name for an event source.
 */
/*static*/ QString NotifyEvent::getEventSrcName(const QString& eventSrc, QString& iconName)
{
    QString configFilename = eventSrc + QString::fromLatin1( "/eventsrc" );
    KConfig* config = new KConfig( configFilename, true, false, "data" );
    config->setGroup( QString::fromLatin1( "!Global!" ) );
    QString appDesc = config->readEntry( "Comment", i18n("No description available") );
    iconName = config->readEntry( "IconName" );
    delete config;
    return appDesc;
}

/**
 * Retrieves the displayable name for an event from an event source.
 */
/*static*/ QString NotifyEvent::getEventName(const QString& eventSrc, const QString& event)
{
    QString eventName;
    QString configFilename = eventSrc + QString::fromLatin1( "/eventsrc" );
    KConfig* config = new KConfig( configFilename, true, false, "data" );
    if ( config->hasGroup( event ) )
    {
        config->setGroup( event );
        eventName = config->readEntry( QString::fromLatin1( "Comment" ),
            config->readEntry( QString::fromLatin1( "Name" )));
    }
    delete config;
    return eventName;
}