KApplication Class Reference

#include <kapplication.h>

Inheritance diagram for KApplication:

QApplication KInstance KUniqueApplication List of all members.

Detailed Description

Controls and provides information to all KDE applications.Controls and provides information to all KDE applications.

Only one object of this class can be instantiated in a single app. This instance is always accessible via the 'kapp' global variable. See cut() for an example.

This class provides the following services to all KDE applications.

  • It controls the event queue (see QApplication ).
  • It provides the application with KDE resources such as accelerators, common menu entries, a KConfig object. session management events, help invocation etc.
  • Installs a signal handler for the SIGCHLD signal in order to avoid zombie children. If you want to catch this signal yourself or don't want it to be caught at all, you have set a new signal handler (or SIG_IGN) after KApplication's constructor has run.
  • Installs an empty signal handler for the SIGPIPE signal using installSigpipeHandler(). If you want to catch this signal yourself, you have set a new signal handler after KApplication's constructor has run.
  • It can start new services
The way a service gets started depends on the 'X-DCOP-ServiceType' entry in the desktop file of the service:

There are three possibilities:

  • X-DCOP-ServiceType=None (default) Always start a new service, don't wait till the service registers with dcop.
  • X-DCOP-ServiceType=Multi Always start a new service, wait until the service has registered with dcop.
  • X-DCOP-ServiceType=Unique Only start the service if it isn't already running, wait until the service has registered with dcop.
Author:
Matthias Kalle Dalheimer <kalle@kde.org>

Definition at line 94 of file kapplication.h.


Public Types

 CaptionAppLast = 1
 CaptionAppFirst
 CaptionNoApp
 ShutdownConfirmDefault = -1
 ShutdownConfirmNo = 0
 ShutdownConfirmYes = 1
 ShutdownTypeDefault = -1
 ShutdownTypeNone = 0
 ShutdownTypeReboot = 1
 ShutdownTypeHalt = 2
 ShutdownModeDefault = -1
 ShutdownModeSchedule = 0
 ShutdownModeTryNow = 1
 ShutdownModeForceNow = 2
 ShutdownModeInteractive = 3
 ShiftModifier = 1<<0
 LockModifier = 1<<1
 ControlModifier = 1<<2
 Modifier1 = 1<<3
 Modifier2 = 1<<4
 Modifier3 = 1<<5
 Modifier4 = 1<<6
 Modifier5 = 1<<7
 Button1Pressed = 1<<8
 Button2Pressed = 1<<9
 Button3Pressed = 1<<10
 Button4Pressed = 1<<11
 Button5Pressed = 1<<12
 SETTINGS_MOUSE
 SETTINGS_COMPLETION
 SETTINGS_PATHS
 SETTINGS_POPUPMENU
 SETTINGS_QT
 SETTINGS_SHORTCUTS
enum  CaptionLayout { CaptionAppLast = 1, CaptionAppFirst, CaptionNoApp }
enum  ShutdownConfirm { ShutdownConfirmDefault = -1, ShutdownConfirmNo = 0, ShutdownConfirmYes = 1 }
enum  ShutdownType { ShutdownTypeDefault = -1, ShutdownTypeNone = 0, ShutdownTypeReboot = 1, ShutdownTypeHalt = 2 }
enum  ShutdownMode {
  ShutdownModeDefault = -1, ShutdownModeSchedule = 0, ShutdownModeTryNow = 1, ShutdownModeForceNow = 2,
  ShutdownModeInteractive = 3
}
enum  {
  ShiftModifier = 1<<0, LockModifier = 1<<1, ControlModifier = 1<<2, Modifier1 = 1<<3,
  Modifier2 = 1<<4, Modifier3 = 1<<5, Modifier4 = 1<<6, Modifier5 = 1<<7
}
enum  {
  Button1Pressed = 1<<8, Button2Pressed = 1<<9, Button3Pressed = 1<<10, Button4Pressed = 1<<11,
  Button5Pressed = 1<<12
}
enum  SettingsCategory {
  SETTINGS_MOUSE, SETTINGS_COMPLETION, SETTINGS_PATHS, SETTINGS_POPUPMENU,
  SETTINGS_QT, SETTINGS_SHORTCUTS
}

Public Slots

void invokeBrowser (const QString &url, const QCString &startup_id)
void invokeBrowser (const QString &url)
void cut ()
void copy ()
void paste ()
void clear ()
void selectAll ()
void ref ()
void deref ()

Signals

void kdisplayPaletteChanged ()
void kdisplayStyleChanged ()
void kdisplayFontChanged ()
void appearanceChanged ()
void toolbarAppearanceChanged (int)
void backgroundChanged (int desk)
void settingsChanged (int category)
void iconChanged (int group)
void kipcMessage (int id, int data)
void saveYourself ()
void shutDown ()
void updateIconLoaders ()

Public Member Functions

 KApplication (bool allowStyles=true, bool GUIenabled=true)
 KApplication (int &argc, char **argv, const QCString &rAppName, bool allowStyles=true, bool GUIenabled=true) KDE_DEPRECATED
virtual ~KApplication ()
KConfigsessionConfig ()
bool isRestored () const
void disableSessionManagement ()
void enableSessionManagement ()
bool requestShutDown (ShutdownConfirm confirm=ShutdownConfirmDefault, ShutdownType sdtype=ShutdownTypeDefault, ShutdownMode sdmode=ShutdownModeDefault)
void propagateSessionManager ()
void commitData (QSessionManager &sm)
void saveState (QSessionManager &sm)
bool sessionSaving () const
QPixmap icon () const
QString iconName () const
QPixmap miniIcon () const
QString miniIconName () const
void setTopWidget (QWidget *topWidget)
void invokeHelp (const QString &anchor, const QString &appname, const QCString &startup_id) const
void invokeHelp (const QString &anchor=QString::null, const QString &appname=QString::null) const
void invokeHTMLHelp (const QString &aFilename, const QString &aTopic=QString::null) const KDE_DEPRECATED
void invokeMailer (const QString &address, const QString &subject, const QCString &startup_id)
void invokeMailer (const QString &address, const QString &subject)
void invokeMailer (const KURL &mailtoURL, const QCString &startup_id, bool allowAttachments)
void invokeMailer (const KURL &mailtoURL, const QCString &startup_id)
void invokeMailer (const KURL &mailtoURL)
void invokeMailer (const QString &to, const QString &cc, const QString &bcc, const QString &subject, const QString &body, const QString &messageFile, const QStringList &attachURLs, const QCString &startup_id)
void invokeMailer (const QString &to, const QString &cc, const QString &bcc, const QString &subject, const QString &body, const QString &messageFile=QString::null, const QStringList &attachURLs=QStringList())
QString caption () const
KDE_DEPRECATED KStyle * kstyle () const
QString makeStdCaption (const QString &userCaption, bool withAppName=true, bool modified=false) const
QString tempSaveName (const QString &pFilename) const
QString checkRecoverFile (const QString &pFilename, bool &bRecover) const
void enableStyles ()
void disableStyles ()
void installX11EventFilter (QWidget *filter)
void removeX11EventFilter (const QWidget *filter)
void addKipcEventMask (int id)
void removeKipcEventMask (int id)
QCString startupId () const
void setStartupId (const QCString &startup_id)
void updateUserTimestamp (unsigned long time=0)
unsigned long userTimestamp () const
void updateRemoteUserTimestamp (const QCString &dcopId, unsigned long time=0)
QString geometryArgument () const
void installKDEPropertyMap ()
bool authorize (const QString &genericAction)
bool authorizeKAction (const char *action)
bool authorizeURLAction (const QString &action, const KURL &baseURL, const KURL &destURL)
void allowURLAction (const QString &action, const KURL &_baseURL, const KURL &_destURL)
bool authorizeControlModule (const QString &menuId)
QStringList authorizeControlModules (const QStringList &menuIds)
bool notify (QObject *receiver, QEvent *event)
int xErrhandler (Display *, void *)
int xioErrhandler (Display *)
void iceIOErrorHandler (_IceConn *conn)

Static Public Member Functions

static void addCmdLineOptions ()
static KApplicationkApplication ()
static DCOPClientdcopClient ()
static void disableAutoDcopRegistration ()
static QCString launcher ()
static int startServiceByName (const QString &_name, const QString &URL, QString *error=0, QCString *dcopService=0, int *pid=0, const QCString &startup_id="", bool noWait=false)
static int startServiceByName (const QString &_name, const QStringList &URLs=QStringList(), QString *error=0, QCString *dcopService=0, int *pid=0, const QCString &startup_id="", bool noWait=false)
static int startServiceByDesktopPath (const QString &_name, const QString &URL, QString *error=0, QCString *dcopService=0, int *pid=0, const QCString &startup_id="", bool noWait=false)
static int startServiceByDesktopPath (const QString &_name, const QStringList &URLs=QStringList(), QString *error=0, QCString *dcopService=0, int *pid=0, const QCString &startup_id="", bool noWait=false)
static int startServiceByDesktopName (const QString &_name, const QString &URL, QString *error=0, QCString *dcopService=0, int *pid=0, const QCString &startup_id="", bool noWait=false)
static int startServiceByDesktopName (const QString &_name, const QStringList &URLs=QStringList(), QString *error=0, QCString *dcopService=0, int *pid=0, const QCString &startup_id="", bool noWait=false)
static int kdeinitExec (const QString &name, const QStringList &args, QString *error, int *pid, const QCString &startup_id)
static int kdeinitExec (const QString &name, const QStringList &args=QStringList(), QString *error=0, int *pid=0)
static int kdeinitExecWait (const QString &name, const QStringList &args, QString *error, int *pid, const QCString &startup_id)
static int kdeinitExecWait (const QString &name, const QStringList &args=QStringList(), QString *error=0, int *pid=0)
static int random ()
static QString randomString (int length)
static ButtonState keyboardMouseState ()
static uint keyboardModifiers () KDE_DEPRECATED
static uint mouseState () KDE_DEPRECATED
static void startKdeinit ()
static QPalette createApplicationPalette ()
static QPalette createApplicationPalette (KConfig *config, int contrast)
static void installSigpipeHandler ()
static bool guiEnabled ()

Static Public Attributes

static bool loadedByKdeinit = false

Protected Member Functions

 KApplication (bool allowStyles, bool GUIenabled, KInstance *_instance)
void invokeEditSlot (const char *slot)
virtual void virtual_hook (int id, void *data)

Protected Attributes

Atom kipcCommAtom
int kipcEventMask
int pArgc

Static Protected Attributes

static KApplicationKApp = 0L

Member Enumeration Documentation

anonymous enum

Deprecated:
Same values as Button1Mask etc. in X.h

Definition at line 1072 of file kapplication.h.

Position of the caption (presumably in the application window's title bar).

This enum appears to be unused.

Todo:
Find out if this is used anywhere.
Enumerator:
CaptionAppLast  Display the application name last (before document name).
CaptionAppFirst  Display the application name first.
CaptionNoApp  Do not display application name at all.

Definition at line 104 of file kapplication.h.

Valid values for the settingsChanged signal.

Definition at line 1228 of file kapplication.h.

The possible values for the confirm parameter of requestShutDown().

Enumerator:
ShutdownConfirmDefault  Obey the user's confirmation setting.
ShutdownConfirmNo  Don't confirm, shutdown without asking.
ShutdownConfirmYes  Always confirm, ask even if the user turned it off.

Definition at line 264 of file kapplication.h.

The possible values for the sdmode parameter of requestShutDown().

Enumerator:
ShutdownModeDefault  Select previous mode or the default if it's the first time.
ShutdownModeSchedule  Schedule a shutdown (halt or reboot) for the time all active sessions have exited.
ShutdownModeTryNow  Shut down, if no sessions are active.

Otherwise do nothing.

ShutdownModeForceNow  Force shutdown.

Kill any possibly active sessions.

ShutdownModeInteractive  Pop up a dialog asking the user what to do if sessions are still active.

Definition at line 304 of file kapplication.h.

The possible values for the sdtype parameter of requestShutDown().

Enumerator:
ShutdownTypeDefault  Select previous action or the default if it's the first time.
ShutdownTypeNone  Only log out.
ShutdownTypeReboot  Log out and reboot the machine.
ShutdownTypeHalt  Log out and halt the machine.

Definition at line 282 of file kapplication.h.


Constructor & Destructor Documentation

KApplication::KApplication ( bool  allowStyles = true,
bool  GUIenabled = true 
)

This constructor takes aboutData and command line arguments from KCmdLineArgs.

Parameters:
allowStyles Set to false to disable the loading on plugin based styles. This is only useful to applications that do not display a GUI normally. If you do create an application with allowStyles set to false it normally runs in the background but under special circumstances displays widgets. Call enableStyles() before displaying any widgets.
GUIenabled Set to false to disable all GUI stuff. This implies no styles either.

Definition at line 615 of file kapplication.cpp.

KApplication::KApplication ( int &  argc,
char **  argv,
const QCString rAppName,
bool  allowStyles = true,
bool  GUIenabled = true 
)

Deprecated:
do not use it at all, it will make your application crash, use KCmdLineArgs
Constructor. Parses command-line arguments.

Parameters:
argc command line argument count
argv command line argument value(s)
rAppName application name. Will be used for finding the associated message files and icon files, and as the default registration name for DCOP. This is a mandatory parameter.
allowStyles Set to false to disable the loading on plugin based styles. This is only useful to applications that do not display a GUI normally. If you do create an application with allowStyles set to false that normally runs in the background but under special circumstances displays widgets call enableStyles() before displaying any widgets.
GUIenabled Set to false to disable all GUI stuff. This implies no styles either.

Definition at line 591 of file kapplication.cpp.


Member Function Documentation

void KApplication::addCmdLineOptions (  )  [static]

Add Qt and KDE command line options to KCmdLineArgs.

Reimplemented in KUniqueApplication.

Definition at line 1446 of file kapplication.cpp.

void KApplication::addKipcEventMask ( int  id  ) 

Adds a message type to the KIPC event mask.

You can only add "system messages" to the event mask. These are the messages with id < 32. Messages with id >= 32 are user messages.

Parameters:
id The message id. See KIPC::Message.
See also:
KIPC

removeKipcEventMask()

kipcMessage()

Definition at line 1853 of file kapplication.cpp.

void KApplication::allowURLAction ( const QString action,
const KURL _baseURL,
const KURL _destURL 
)

Allow a certain URL action.

This can be useful if your application needs to ensure access to an application specific directory that may otherwise be subject to KIOSK restrictions.

Parameters:
action The name of the action.
_baseURL The url where the action originates from
_destURL The object of the action
Since:
3.2

Definition at line 3064 of file kapplication.cpp.

void KApplication::appearanceChanged (  )  [signal]

Emitted when KApplication has changed either its GUI style, its font or its palette in response to a kdisplay request.

Normally, widgets will update their styles automatically, but you should connect to this to program special behavior.

bool KApplication::authorize ( const QString genericAction  ) 

Returns whether a certain action is authorized.

Parameters:
genericAction The name of a generic action
Returns:
true if the action is authorized

Definition at line 2944 of file kapplication.cpp.

bool KApplication::authorizeControlModule ( const QString menuId  ) 

Returns whether access to a certain control module is authorized.

Parameters:
menuId identifying the control module, e.g. kde-mouse.desktop
Returns:
true if access to the module is authorized, false otherwise.
Since:
3.2

Definition at line 2964 of file kapplication.cpp.

QStringList KApplication::authorizeControlModules ( const QStringList menuIds  ) 

Returns whether access to a certain control modules is authorized.

Parameters:
menuIds list of menu-ids of control module, an example of a menu-id is kde-mouse.desktop.
Returns:
Those control modules for which access has been authorized.
Since:
3.2

Definition at line 2973 of file kapplication.cpp.

bool KApplication::authorizeKAction ( const char *  action  ) 

Returns whether a certain KAction is authorized.

Parameters:
action The name of a KAction action. The name is prepended with "action/" before being passed to authorize()
Returns:
true if the KAction is authorized

Definition at line 2954 of file kapplication.cpp.

bool KApplication::authorizeURLAction ( const QString action,
const KURL baseURL,
const KURL destURL 
)

Returns whether a certain URL related action is authorized.

Parameters:
action The name of the action. Known actions are list (may be listed (e.g. in file selection dialog)), link (may be linked to), open (may open) and redirect (may be redirected to)
baseURL The url where the action originates from
destURL The object of the action
Returns:
true when the action is authorized, false otherwise.
Since:
3.1

Definition at line 3074 of file kapplication.cpp.

void KApplication::backgroundChanged ( int  desk  )  [signal]

Emitted when the desktop background has been changed by kcmdisplay.

Parameters:
desk The desktop whose background has changed.

QString KApplication::caption (  )  const

Returns a text for the window caption.

This may be set by "-caption", otherwise it will be equivalent to the name of the executable.

Returns:
the text for the window caption

Definition at line 1914 of file kapplication.cpp.

QString KApplication::checkRecoverFile ( const QString pFilename,
bool &  bRecover 
) const

Check whether an auto-save file exists for the document you want to open.

Parameters:
pFilename The full path to the document you want to open.
bRecover This gets set to true if there was a recover file.
Returns:
The full path of the file to open.

Definition at line 2775 of file kapplication.cpp.

void KApplication::clear (  )  [slot]

If the widget with focus provides a clear() slot, call that slot.

Thus for a simple application clear() can be implemented as:

 new KAction( i18n( "Clear" ), "editclear", 0, kapp, SLOT( clear() ), actionCollection(), "clear" );

Note that for some widgets, this may not provide the intended bahavior. For example if you make use of the code above and a KListView has the focus, clear() will clear all of the items in the list. If this is not the intened behavior and you want to make use of this slot, you can subclass KListView and reimplement this slot. For example the following code would implement a KListView without this behavior:

 class MyListView : public KListView {
   Q_OBJECT
 public:
   MyListView( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ) : KListView( parent, name, f ) {}
   virtual ~MyListView() {}
 public slots:
   virtual void clear() {}
 };

Definition at line 2558 of file kapplication.cpp.

void KApplication::commitData ( QSessionManager sm  ) 

Reimplemented for internal purposes, mainly the highlevel handling of session management with KSessionManaged.

Reimplemented from QApplication.

Definition at line 1203 of file kapplication.cpp.

void KApplication::copy (  )  [slot]

If the widget with focus provides a copy() slot, call that slot.

Thus for a simple application copy can be implemented as:

 KStdAction::copy( kapp, SLOT( copy() ), actionCollection() );

Definition at line 2548 of file kapplication.cpp.

QPalette KApplication::createApplicationPalette (  )  [static]

Used to obtain the QPalette that will be used to set the application palette.

This is only useful for configuration modules such as krdb and should not be used in normal circumstances.

Returns:
the QPalette
Since:
3.1

Definition at line 1952 of file kapplication.cpp.

void KApplication::cut (  )  [slot]

If the widget with focus provides a cut() slot, call that slot.

Thus for a simple application cut can be implemented as:

 KStdAction::cut( kapp, SLOT( cut() ), actionCollection() );

Definition at line 2543 of file kapplication.cpp.

DCOPClient * KApplication::dcopClient (  )  [static]

Returns a pointer to a DCOPClient for the application.

If a client does not exist yet, it is created when this function is called.

Returns:
the DCOPClient for the application

Definition at line 981 of file kapplication.cpp.

void KApplication::deref (  )  [slot]

Tells KApplication that one operation such as those described in ref() just finished.

The application exits if the counter is back to 0.

Definition at line 1047 of file kapplication.cpp.

void KApplication::disableAutoDcopRegistration (  )  [static]

Disable automatic dcop registration Must be called before creating a KApplication instance to have an effect.

Definition at line 1026 of file kapplication.cpp.

void KApplication::disableSessionManagement (  ) 

Disables session management for this application.

Useful in case your application is started by the initial "startkde" script.

Definition at line 1077 of file kapplication.cpp.

void KApplication::disableStyles (  ) 

Disables style plugins.

Current style plugins do not get unloaded.

This is only useful when used in combination with enableStyles().

Definition at line 1882 of file kapplication.cpp.

void KApplication::enableSessionManagement (  ) 

Enables again session management for this application, formerly disabled by calling disableSessionManagement().

You usually shouldn't call this function, as the session management is enabled by default.

Definition at line 1081 of file kapplication.cpp.

void KApplication::enableStyles (  ) 

Enables style plugins.

This is useful only to applications that normally do not display a GUI and create the KApplication with allowStyles set to false.

Definition at line 1873 of file kapplication.cpp.

QString KApplication::geometryArgument (  )  const

Returns the argument to --geometry if any, so the geometry can be set wherever necessary.

Returns:
the geometry argument, or QString::null if there is none

Definition at line 1558 of file kapplication.cpp.

QPixmap KApplication::icon (  )  const

Returns a QPixmap with the application icon.

Returns:
the application icon

void KApplication::iconChanged ( int  group  )  [signal]

Emitted when the global icon settings have been changed.

Parameters:
group the new group

QString KApplication::iconName (  )  const

Returns the name of the application icon.

Returns:
the icon's name

Definition at line 1574 of file kapplication.cpp.

void KApplication::installKDEPropertyMap (  ) 

Install a Qt SQL property map with entries for all KDE widgets Call this in any application using KDE widgets in QSqlForm or QDataView.

If you are adding a widget that was missing please make sure to also add it to KConfigDialogManager's retrieveSettings() function. Thanks.

Definition at line 2133 of file kapplication.cpp.

void KApplication::installSigpipeHandler (  )  [static]

Installs a handler for the SIGPIPE signal.

It is thrown when you write to a pipe or socket that has been closed. The handler is installed automatically in the constructor, but you may need it if your application or component does not have a KApplication instance.

Definition at line 3195 of file kapplication.cpp.

void KApplication::installX11EventFilter ( QWidget filter  ) 

Installs widget filter as global X11 event filter.

The widget filter receives XEvents in its standard QWidget::x11Event() function.

Warning: Only do this when absolutely necessary. An installed X11 filter can slow things down.

Definition at line 409 of file kapplication.cpp.

void KApplication::invokeBrowser ( const QString url  )  [slot]

Invoke the standard browser.

Uses a startup_id of "" (empty) and is otherwise the same as the above function.

Definition at line 2519 of file kapplication.cpp.

void KApplication::invokeBrowser ( const QString url,
const QCString startup_id 
) [slot]

Invokes the standard browser.

Note that you should only do this when you know for sure that the browser can handle the URL (i.e. its mimetype). In doubt, if the URL can point to an image or anything else than directory or HTML, prefer to use new KRun( ur