summaryrefslogtreecommitdiffstats
path: root/kttsd/libkttsd/notify.cpp
blob: 9b1cfd59b372b5ff8b34bc58e5782995601c7a47 (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
/*
  Notification Action constants and utility functions.
  -------------------
  Copyright : (C) 2005 by Gary Cramblitt <[email protected]>
  -------------------
  Original author: Gary Cramblitt <[email protected]>
  Current Maintainer: 2004 by Gary Cramblitt <[email protected]>
 ******************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.               *
 *                                                                         *
 ***************************************************************************/

// TQt includes.

// TQt includes.
#include <tqstring.h>
#include <tqstringlist.h>

// KDE includes.
#include <tdeconfig.h>
#include <tdelocale.h>
#include <kstaticdeleter.h>

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

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

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

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

        s_actionDisplayNames_sd.setObject(s_actionDisplayNames, new TQStringList);
        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*/ TQString NotifyAction::actionName( const int action )
{
    notifyaction_init();
    return (*s_actionNames)[ action ];
}

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

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

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

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

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

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

static void notifypresent_init()
{
    if ( !s_presentNames )
    {
        s_presentNames_sd.setObject( s_presentNames, new TQStringList );
        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 TQStringList );
        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*/ TQString NotifyPresent::presentName( const int present )
{
    notifypresent_init();
    return (*s_presentNames)[ present ];
}

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

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

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

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

/**
 * Retrieves the displayable name for an event source.
 */
/*static*/ TQString NotifyEvent::getEventSrcName(const TQString& eventSrc, TQString& iconName)
{
    TQString configFilename = eventSrc + TQString::fromLatin1( "/eventsrc" );
    TDEConfig* config = new TDEConfig( configFilename, true, false, "data" );
    config->setGroup( TQString::fromLatin1( "!Global!" ) );
    TQString 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*/ TQString NotifyEvent::getEventName(const TQString& eventSrc, const TQString& event)
{
    TQString eventName;
    TQString configFilename = eventSrc + TQString::fromLatin1( "/eventsrc" );
    TDEConfig* config = new TDEConfig( configFilename, true, false, "data" );
    if ( config->hasGroup( event ) )
    {
        config->setGroup( event );
        eventName = config->readEntry( TQString::fromLatin1( "Comment" ),
            config->readEntry( TQString::fromLatin1( "Name" )));
    }
    delete config;
    return eventName;
}