1
/****************************************************************************
3
Copyright (C) 2001-2003 Lubos Lunak <l.lunak@kde.org>
5
Permission is hereby granted, free of charge, to any person obtaining a
6
copy of this software and associated documentation files (the "Software"),
7
to deal in the Software without restriction, including without limitation
8
the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
and/or sell copies of the Software, and to permit persons to whom the
10
Software is furnished to do so, subject to the following conditions:
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
DEALINGS IN THE SOFTWARE.
23
****************************************************************************/
25
#ifndef KSTARTUPINFO_H
26
#define KSTARTUPINFO_H
28
#include <sys/types.h>
32
#include <qcoreevent.h>
33
#include <qwindowdefs.h>
34
#include <kdelibs_export.h>
36
#if !defined(Q_WS_X11)
41
class KStartupInfoData;
44
* Class for manipulating the application startup notification.
46
* This class can be used to send information about started application,
47
* change the information and receive this information. For detailed
48
* description, see kdelibs/kdecore/README.kstartupinfo.
50
* You usually don't need to use this class for sending the notification
51
* information, as KDE libraries should do this when an application is
52
* started (e.g. KRun class).
54
* For receiving the startup notification info, create an instance and connect
55
* to its slots. It will automatically detect started applications and when
59
* @see KStartupInfoData
61
* @author Lubos Lunak <l.lunak@kde.org>
63
class KDECORE_EXPORT KStartupInfo
69
* By default, the startup notification is ended for the application
70
* after it shows its first toplevel window. If you app e.g. has
71
* several toplevel windows after its startup, you can disable
72
* the automatic handling, and call appStarted() manually after
73
* all toplevel windows have been shown.
75
static void disableAutoAppStartedSending( bool disable = true );
78
* Manual notification that the application has started.
79
* If you do not map a (toplevel) window, then startup
80
* notification will not disappear for the application
81
* until a timeout. You can use this as an alternative
82
* method in this case.
84
static void appStarted();
87
* Sends explicit notification that the startup notification
88
* with id startup_id should end.
90
static void appStarted( const QByteArray& startup_id );
93
* Use this function if the application got a request with startup
94
* notification from outside (for example, when KUniqueApplication::newInstance()
95
* is called, or e.g. when khelpcenter opens new URL in its window).
96
* The window can be either an already existing and visible window,
97
* or a new one, before being shown. Note that this function is usually
98
* needed only when a window is reused.
100
static void setNewStartupId( QWidget* window, const QByteArray& startup_id );
103
* If your application shows temporarily some window during its startup,
104
* for example a dialog, and only after closing it shows the main window,
105
* startup notification would normally be shown while the dialog is visible.
106
* To temporarily suspend and resume the notification, use this function.
107
* Note that this is cumulative, i.e. after suspending twice, you have to
110
static void silenceStartup( bool silence );
113
* Creates and returns new startup id. The id includes properly setup
116
static QByteArray createNewStartupId();
121
CleanOnCantDetect = 1 << 0,
122
DisableKWinModule = 1 << 1,
123
AnnounceSilenceChanges = 1 << 2
127
* Creates an instance that will receive the startup notifications.
128
* The various flags passed may be
129
* @li CleanOnCantDetect - when a new unknown window appears, all startup
130
* notifications for applications that are not compliant with
131
* the startup protocol are removed
132
* @li DisableKWinModule - KWinModule, which is normally used to detect
133
* new windows, is disabled. With this flag, checkStartup() must be
134
* called in order to check newly mapped windows.
135
* @li AnnounceSilenceChanges - normally, startup notifications are
136
* "removed" when they're silenced, and "recreated" when they're resumed.
137
* With this flag, the change is normally announced with gotStartupChange().
139
* @param flags OR-ed combination of flags
140
* @param parent the parent of this QObject (can be 0 for no parent)
143
KStartupInfo( int flags, QObject* parent = NULL );
145
* Creates an instance that will receive the startup notifications.
147
* @param clean_on_cantdetect if true, and a new unknown window appears,
148
* removes all notification for applications that are not compliant
149
* with the app startup protocol
150
* @param parent the parent of this QObject (can be 0 for no parent)
154
KStartupInfo( bool clean_on_cantdetect, QObject* parent = 0 );
155
virtual ~KStartupInfo();
157
* Sends given notification data about started application
158
* with the given startup identification. If no notification for this identification
159
* exists yet, it is created, otherwise it's updated. Note that the name field
160
* in data is required.
162
* @param id the id of the application
163
* @param data the application's data
164
* @return true if successful, false otherwise
165
* @see KStartupInfoId
166
* @see KStartupInfoData
168
static bool sendStartup( const KStartupInfoId& id, const KStartupInfoData& data );
171
* Like sendStartup , uses dpy instead of qt_x11display() for sending the info.
172
* @param dpy the display of the application. Note that the name field
173
* in data is required.
174
* @param id the id of the application
175
* @param data the application's data
176
* @return true if successful, false otherwise
178
static bool sendStartupX( Display* dpy, const KStartupInfoId& id,
179
const KStartupInfoData& data );
182
* Sends given notification data about started application
183
* with the given startup identification. This is used for updating the notification
184
* info, if no notification for this identification exists, it's ignored.
185
* @param id the id of the application
186
* @param data the application's data
187
* @return true if successful, false otherwise
188
* @see KStartupInfoId
189
* @see KStartupInfoData
191
static bool sendChange( const KStartupInfoId& id, const KStartupInfoData& data );
194
* Like sendChange , uses dpy instead of qt_x11display() for sending the info.
195
* @param dpy the display of the application.
196
* @param id the id of the application
197
* @param data the application's data
198
* @return true if successful, false otherwise
200
static bool sendChangeX( Display* dpy, const KStartupInfoId& id,
201
const KStartupInfoData& data );
204
* Ends startup notification with the given identification.
205
* @param id the id of the application
206
* @return true if successful, false otherwise
208
static bool sendFinish( const KStartupInfoId& id );
211
* Like sendFinish , uses dpy instead of qt_x11display() for sending the info.
212
* @param dpy the display of the application.
213
* @param id the id of the application
214
* @return true if successful, false otherwise
216
static bool sendFinishX( Display* dpy, const KStartupInfoId& id );
219
* Ends startup notification with the given identification and the given data ( e.g.
220
* PIDs of processes for this startup notification that exited ).
221
* @param id the id of the application
222
* @param data the application's data
223
* @return true if successful, false otherwise
225
static bool sendFinish( const KStartupInfoId& id, const KStartupInfoData& data );
228
* Like sendFinish , uses dpy instead of qt_x11display() for sending the info.
229
* @param dpy the display of the application.
230
* @param id the id of the application
231
* @param data the application's data
232
* @return true if successful, false otherwise
234
static bool sendFinishX( Display* dpy, const KStartupInfoId& id,
235
const KStartupInfoData& data );
238
* Returns the current startup notification identification for the current
239
* startup notification environment variable. Note that KApplication constructor
240
* unsets the variable and you have to use KApplication::startupId .
241
* @return the current startup notification identification
243
static KStartupInfoId currentStartupIdEnv();
245
* Unsets the startup notification environment variable.
247
static void resetStartupEnv();
249
* @li NoMatch - the window doesn't match any existing startup notification
250
* @li Match - the window matches an existing startup notification
251
* @li CantDetect - unable to detect if the window matches any existing
252
* startup notification
254
enum startup_t { NoMatch, Match, CantDetect };
256
* Checks if the given windows matches any existing startup notification.
257
* @param w the window id to check
258
* @return the result of the operation
260
startup_t checkStartup( WId w );
262
* Checks if the given windows matches any existing startup notification, and
263
* if yes, returns the identification in id.
264
* @param w the window id to check
265
* @param id if found, the id of the startup notification will be written here
266
* @return the result of the operation
268
startup_t checkStartup( WId w, KStartupInfoId& id );
270
* Checks if the given windows matches any existing startup notification, and
271
* if yes, returns the notification data in data.
272
* @param w the window id to check
273
* @param data if found, the data of the startup notification will be written here
274
* @return the result of the operation
276
startup_t checkStartup( WId w, KStartupInfoData& data );
278
* Checks if the given windows matches any existing startup notification, and
279
* if yes, returns the identification in id and notification data in data.
280
* @param w the window id to check
281
* @param id if found, the id of the startup notification will be written here
282
* @param data if found, the data of the startup notification will be written here
283
* @return the result of the operation
285
startup_t checkStartup( WId w, KStartupInfoId& id, KStartupInfoData& data );
287
* Sets the timeout for notifications, after this timeout a notification is removed.
288
* @param secs the new timeout in seconds
290
void setTimeout( unsigned int secs );
292
* Sets the startup notification window property on the given window.
293
* @param window the id of the window
294
* @param id the startup notification id
296
static void setWindowStartupId( WId window, const QByteArray& id );
298
* Returns startup notification identification of the given window.
299
* @param w the id of the window
300
* @return the startup notification id. Can be null if not found.
302
static QByteArray windowStartupId( WId w );
306
static void handleAutoAppStartedSending();
313
* Emitted when a new startup notification is created (i.e. a new application is
315
* @param id the notification identification
316
* @param data the notification data
318
void gotNewStartup( const KStartupInfoId& id, const KStartupInfoData& data );
320
* Emitted when a startup notification changes.
321
* @param id the notification identification
322
* @param data the notification data
324
void gotStartupChange( const KStartupInfoId& id, const KStartupInfoData& data );
326
* Emitted when a startup notification is removed (either because it was detected
327
* that the application is ready or because of a timeout).
328
* @param id the notification identification
329
* @param data the notification data
331
void gotRemoveStartup( const KStartupInfoId& id, const KStartupInfoData& data );
336
virtual void customEvent( QEvent* e_P );
338
void startups_cleanup();
339
void startups_cleanup_no_age();
340
void got_message( const QString& msg );
341
void window_added( WId w );
342
void slot_window_added( WId w );
344
void init( int flags );
345
friend class KStartupInfoPrivate;
346
void got_startup_info( const QString& msg_P, bool update_only_P );
347
void got_remove_startup_info( const QString& msg_P );
348
void new_startup_info_internal( const KStartupInfoId& id_P,
349
Data& data_P, bool update_only_P );
350
void remove_startup_info_internal( const KStartupInfoId& id_P );
351
void remove_startup_pids( const KStartupInfoId& id, const KStartupInfoData& data );
352
void remove_startup_pids( const KStartupInfoData& data );
353
startup_t check_startup_internal( WId w, KStartupInfoId* id, KStartupInfoData* data );
354
bool find_id( const QByteArray& id_P, KStartupInfoId* id_O,
355
KStartupInfoData* data_O );
356
bool find_pid( pid_t pid_P, const QByteArray& hostname, KStartupInfoId* id_O,
357
KStartupInfoData* data_O );
358
bool find_wclass( QByteArray res_name_P, QByteArray res_class_P,
359
KStartupInfoId* id_O, KStartupInfoData* data_O );
360
static QByteArray get_window_hostname( WId w_P );
361
void startups_cleanup_internal( bool age_P );
362
void clean_all_noncompliant();
363
static QString check_required_startup_fields( const QString& msg,
364
const KStartupInfoData& data, int screen );
365
unsigned int timeout;
371
* Class representing an identification of application startup notification.
373
* Every existing notification about a starting application has its own unique
374
* identification, that's used to identify and manipulate the notification.
377
* @see KStartupInfoData
379
* @author Lubos Lunak <l.lunak@kde.org>
381
class KDECORE_EXPORT KStartupInfoId
385
* Overloaded operator.
386
* @return true if the notification identifications are the same
388
bool operator==( const KStartupInfoId& id ) const;
390
* Overloaded operator.
391
* @return true if the notification identifications are different
393
bool operator!=( const KStartupInfoId& id ) const;
395
* Checks whether the identifier is valid.
396
* @return true if this object doesn't represent a valid notification identification
400
* Initializes this object with the given identification ( which may be also "0"
401
* for no notification ), or if "" is given, tries to read it from the startup
402
* notification environment variable, and if it's not set, creates a new one.
403
* @param id the new identification, "0" for no notification or "" to read
404
* the environment variable
406
void initId( const QByteArray& id = "" );
408
* Returns the notification identifier as string.
409
* @return the identification string for the notification
411
const QByteArray& id() const;
413
* Return the user timestamp for the startup notification, or 0 if no timestamp
416
unsigned long timestamp() const;
418
* Sets the startup notification environment variable to this identification.
419
* @return true if successful, false otherwise
421
bool setupStartupEnv() const;
423
* Creates an empty identification
429
KStartupInfoId( const KStartupInfoId& data );
431
KStartupInfoId& operator=( const KStartupInfoId& data );
432
bool operator<( const KStartupInfoId& id ) const;
434
KStartupInfoId( const QString& txt );
435
QString to_text() const;
436
friend class KStartupInfo;
442
* Class representing data about an application startup notification.
444
* Such data include the icon of the starting application, the desktop on which
445
* the application should start, the binary name of the application, etc.
448
* @see KStartupInfoId
450
* @author Lubos Lunak <l.lunak@kde.org>
452
class KDECORE_EXPORT KStartupInfoData
456
* Sets the binary name of the application ( e.g. 'kcontrol' ).
457
* @param bin the new binary name of the application
459
void setBin( const QString& bin );
461
* Returns the binary name of the starting application
462
* @return the new binary name of the application
464
const QString& bin() const;
466
* Sets the name for the notification (e.g. 'Control Center')
468
void setName( const QString& name );
470
* Returns the name of the startup notification. If it's not available,
471
* it tries to use other information (binary name).
472
* @return the name of the startup notification
474
const QString& findName() const;
476
* Returns the name of the startup notification, or empty if not available.
477
* @return the name of the startup notification, or an empty string
480
const QString& name() const;
482
* Sets the description for the notification (e.g. 'Launching Control Center').
483
* I.e. name() describes what is being started, while description() is
484
* the actual action performed by the starting.
486
void setDescription( const QString& descr );
488
* Returns the description of the startup notification. If it's not available,
490
* @return the description of the startup notification
492
const QString& findDescription() const;
494
* Returns the name of the startup notification, or empty if not available.
495
* @return the name of the startup notificaiton, or an empty string
498
const QString& description() const;
500
* Sets the icon for the startup notification ( e.g. 'kcontrol' )
501
* @param icon the name of the icon
503
void setIcon( const QString& icon );
505
* Returns the icon of the startup notification, and if it's not available,
506
* tries to get it from the binary name.
507
* @return the name of the startup notification's icon, or the name of
508
* the binary if not set
510
const QString& findIcon() const;
512
* Returns the icon of the startup notification, or empty if not available.
513
* @return the name of the icon, or an empty string if not set.
515
const QString& icon() const;
517
* Sets the desktop for the startup notification ( i.e. the desktop on which
518
* the starting application should appear ).
519
* @param desktop the desktop for the startup notification
521
void setDesktop( int desktop );
523
* Returns the desktop for the startup notification.
524
* @return the desktop for the startup notification
528
* Sets a WM_CLASS value for the startup notification, it may be used for increasing
529
* the chance that the windows created by the starting application will be
530
* detected correctly.
531
* @param wmclass the WM_CLASS value for the startup notification
533
void setWMClass( const QByteArray& wmclass );
535
* Returns the WM_CLASS value for the startup notification, or binary name if not
537
* @return the WM_CLASS value for the startup notification, or the binary name
540
const QByteArray findWMClass() const;
542
* Returns the WM_CLASS value for the startup notification, or empty if not available.
543
* @return the WM_CLASS value for the startup notification, or empty
546
const QByteArray& WMClass() const;
548
* Adds a PID to the list of processes that belong to the startup notification. It
549
* may be used to increase the chance that the windows created by the starting
550
* application will be detected correctly, and also for detecting if the application
551
* has quit without creating any window.
552
* @param pid the PID to add
554
void addPid( pid_t pid );
556
* Returns all PIDs for the startup notification.
557
* @return the list of all PIDs
559
const QList< pid_t >& pids() const;
561
* Checks whether the given @p pid is in the list of PIDs for starup
563
* @return true if the given @p pid is in the list of PIDs for the startup notification
565
bool is_pid( pid_t pid ) const;
567
* Sets the hostname on which the application is starting. It's necessary to set
568
* it if PIDs are set.
569
* @param hostname the application's hostname. If it's a null string, the current hostname is used
571
void setHostname( const QByteArray& hostname = QByteArray());
573
* Returns the hostname for the startup notification.
574
* @return the hostname
576
const QByteArray& hostname() const;
581
enum TriState { Yes, No, Unknown };
584
* Sets whether the visual feedback for this startup notification
585
* should be silenced (temporarily suspended).
587
void setSilent( TriState state );
590
* Return the silence status for the startup notification.
591
* @return KStartupInfoData::Yes if visual feedback is silenced
593
TriState silent() const;
596
* @obsolete Timestamp is already assigned in KStartupInfoId::initId().
597
* Sets timestamp for the startup notification. The timestamp is expressed
598
* as XServer time, and is used to prevent activation of the matching
599
* window if user interaction took place after this timestamp.
600
* Value -1 means no timestamp set, value 0 means that the window should
603
void setTimestamp( unsigned long time );
606
* @obsolete Use KStartupInfoId::timestamp().
607
* Return the timestamp for the startup notification, or -1 if no timestamp
610
unsigned long timestamp() const;
613
* The X11 screen on which the startup notification is happening, -1 if unknown.
618
* Sets the X11 screen on which the startup notification should happen.
619
* This is usually not necessary to set, as it's set by default to QX11Info::screen().
621
void setScreen( int screen );
624
* Updates the notification data from the given data. Some data, such as the desktop
625
* or the name, won't be rewritten if already set.
626
* @param data the data to update
628
void update( const KStartupInfoData& data );
631
* Constructor. Initializes all the data to their default empty values.
638
KStartupInfoData( const KStartupInfoData& data );
640
KStartupInfoData& operator=( const KStartupInfoData& data );
642
KStartupInfoData( const QString& txt );
643
QString to_text() const;
644
void remove_pid( pid_t pid );
645
friend class KStartupInfo;
646
friend class KStartupInfo::Data;