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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
/*
Copyright (C) 2000,2002 Carsten Pfeiffer <[email protected]>
Copyright (C) 2002 Neil Stevens <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation;
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library, If not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KNOTIFYDIALOG_H
#define KNOTIFYDIALOG_H
#include <klistview.h>
#include <kdialogbase.h>
#include <kinstance.h>
#include <kglobal.h>
#include "knotifywidgetbase.h"
class QShowEvent;
namespace KNotify
{
class KNotifyWidget;
}
/**
* KNotifyDialog presents an interface for configuring an application's
* KNotify events.
*
* Rather than requiring the user to wade through the entire list of
* applications' events in KControl, your application can make the list
* of its own notifications available here.
*
* Typical usage is calling the static configure() method:
* \code
* (void) KNotifyDialog::configure( someParentWidget );
* \endcode
*
* @since 3.1
* @author Carsten Pfeiffer <[email protected]>
*/
class KIO_EXPORT KNotifyDialog : public KDialogBase
{
Q_OBJECT
public:
/**
* If you want a non-modal dialog, you need to instantiate KNotifyDialog
* yourself instead of using the configure() method.
*
* KDE4.0 modal default will be false.
*
* @param parent The parent widget for the dialog
* @param name The widget name
* @param modal If true, this will be a modal dialog, otherwise non-modal.
* @param aboutData A pointer to a KAboutData object. KAboutData::appName()
* will be used to find the KNotify events (in the eventsrc file).
* Set this to 0L if you want to add all events yourself with
* addApplicationEvents().
*/
KNotifyDialog( QWidget *parent = 0, const char *name = 0,
bool modal = true,
const KAboutData *aboutData =
KGlobal::instance()->aboutData() );
/**
* Destroys the KNotifyDialog
*/
virtual ~KNotifyDialog();
/**
* Convenience method to create exec() a modal KNotifyDialog.
*
* @param parent The parent widget for the dialog
* @param name The widget name
* @param aboutData A pointer to a KAboutData object. KAboutData::appName()
* will be used to find the KNotify events (in the eventsrc file).
* @see exec for the return values.
* @return The value of QDialog::exec()
*/
static int configure( QWidget *parent = 0, const char *name = 0,
const KAboutData *aboutData = KGlobal::instance()->aboutData() );
/**
* With this method, you can add the KNotify events of one eventsrc
* files to the view.
* KNotifyDialog can handle events for multiple applications (i.e. eventsrc files).
* Successive calls with a different @p appName will add them.
* @param appName The application's name, i.e. the name passed to the
* KApplication constructor or KAboutData.
* @see clearApplicationEvents()
*/
virtual void addApplicationEvents( const char *appName );
/**
* With this method, you can add the KNotify events of one eventsrc
* files to the view.
* KNotifyDialog can handle events for multiple applications (i.e. eventsrc files).
* Successive calls with a different @p path will add them.
* @param path The absolute or relative path to the eventsrc file to be configured.
* A relative path would be e.g. "kwin/eventsrc".
* @see clearApplicationEvents()
*/
virtual void addApplicationEvents( const QString& path );
/**
* Removes all the events added with addApplicationEvents()
* @see addApplicationEvents()
*/
virtual void clearApplicationEvents();
private slots:
void slotDefault();
private:
enum
{
COL_FILENAME = 1
};
void updateView();
KNotify::KNotifyWidget * m_notifyWidget;
class Private;
Private *d;
};
namespace KNotify
{
class Application;
class Event;
class ListViewItem;
typedef QPtrList<Event> EventList;
typedef QPtrListIterator<Application> ApplicationListIterator;
typedef QPtrListIterator<Event> EventListIterator;
/**
* @internal
*/
class KIO_EXPORT Application
{
public:
Application( const QString &path );
~Application();
QString text() const { return m_description; }
QString icon() const { return m_icon; }
const EventList& eventList();
void reloadEvents( bool revertToDefaults = false );
void save();
QString appName() const { return m_appname; }
private:
QString m_icon;
QString m_description;
QString m_appname;
EventList *m_events;
KConfig *kc; // The file that defines the events.
KConfig *config; // The file that contains the settings for the events
};
class KIO_EXPORT ApplicationList : public QPtrList<Application>
{
virtual int compareItems ( QPtrCollection::Item item1,
QPtrCollection::Item item2 )
{
return (static_cast<Application*>( item1 )->text() >=
static_cast<Application*>( item2 )->text()) ? 1 : -1;
}
};
/**
* @internal
*/
class KIO_EXPORT KNotifyWidget : public KNotifyWidgetBase
{
Q_OBJECT
public:
KNotifyWidget( QWidget* parent = 0, const char* name = 0,
bool handleAllApps = false );
~KNotifyWidget();
KListView * eventsView() {
return m_listview;
}
void addVisibleApp( Application *app );
ApplicationList& visibleApps() { return m_visibleApps; }
ApplicationList& allApps() { return m_allApps; }
/**
* Returns 0L if no application events could be found
* The returned pointer must be freed by the caller (easiest done
* by putting it into an ApplicationList with setAutoDelete( true )).
*/
Application * addApplicationEvents( const QString& path );
void resetDefaults( bool ask );
void sort( bool ascending = true );
public slots:
/**
* Clears the view and all the Application events.
*/
virtual void clear();
/**
* Clears only the view and the visible Application events.
* E.g. useful if you want to set new visible events with
* addVisibleApp()
*/
virtual void clearVisible();
virtual void save();
virtual void showAdvanced( bool show );
void toggleAdvanced();
signals:
void changed( bool hasChanges );
protected:
/**
* May return 0L, if there is no current event selected.
*/
Event * currentEvent();
virtual void showEvent( QShowEvent * );
virtual void enableAll( int what, bool enable );
void reload( bool revertToDefaults = false );
protected slots:
void playSound();
private slots:
void slotItemClicked( QListViewItem *item, const QPoint& point,
int col );
void slotEventChanged( QListViewItem * );
void soundToggled( bool on );
void loggingToggled( bool on );
void executeToggled( bool on );
void messageBoxChanged();
void stderrToggled( bool on );
void taskbarToggled( bool on );
void soundFileChanged( const QString& text );
void logfileChanged( const QString& text );
void commandlineChanged( const QString& text );
void openSoundDialog( KURLRequester * );
void openLogDialog( KURLRequester * );
void openExecDialog( KURLRequester * );
void enableAll();
private:
void updateWidgets( ListViewItem *item );
void updatePixmaps( ListViewItem *item );
static QString makeRelative( const QString& );
void addToView( const EventList& events );
void widgetChanged( QListViewItem *item,
int what, bool on, QWidget *buddy = 0L );
void selectItem( QListViewItem *item );
ApplicationList m_visibleApps;
ApplicationList m_allApps;
class Private;
Private *d;
};
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
/**
* @internal
*/
class Event
{
friend class Application;
public:
QString text() const { return description; }
int presentation;
int dontShow;
QString logfile;
QString soundfile;
QString commandline;
const Application *application() const { return m_app; }
private:
Event( const Application *app ) {
presentation = 0;
dontShow = 0;
m_app = app;
}
QString name;
QString description;
QString configGroup;
const Application *m_app;
};
/**
* @internal
*/
class ListViewItem : public QListViewItem
{
public:
ListViewItem( QListView *view, Event *event );
Event& event() { return *m_event; }
virtual int compare (QListViewItem * i, int col, bool ascending) const;
private:
Event * m_event;
};
}
#endif
|