KUniqueApplication Class Reference

`#include <kuniqueapplication.h>`

Inheritance diagram for KUniqueApplication:

## Public Member Functions

| KUniqueApplication (bool allowStyles=true, bool GUIenabled=true, bool configUnique=false)
virtual | ~KUniqueApplication ()
bool | process (const QCString &fun, const QByteArray &data, QCString &replyType, QByteArray &replyData)
virtual int | newInstance ()
bool | restoringSession ()
Public Member Functions inherited from KApplication
| KApplication (bool allowStyles=true, bool GUIenabled=true)
| KApplication (int &argc, char **argv, const QCString &rAppName, bool allowStyles=true, bool GUIenabled=true) KDE_DEPRECATED
KConfig * | sessionConfig ()
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)
Public Member Functions inherited from KInstance
| KInstance (const QCString &instanceName)
| KInstance (const KAboutData *aboutData)
| KInstance (KInstance *src)
virtual | ~KInstance ()
KStandardDirs * | dirs () const
KConfig * | config () const
KSharedConfig * | sharedConfig () const
KIconLoader * | iconLoader () const
void | newIconLoader () const
const KAboutData * | aboutData () const
QCString | instanceName () const
KMimeSourceFactory * | mimeSourceFactory () const
Public Member Functions inherited from DCOPObject
| DCOPObject (QObject *obj)
| DCOPObject (const QCString &objId)
QCString | objId () const
bool | setObjId (const QCString &objId)
virtual bool | processDynamic (const QCString &fun, const QByteArray &data, QCString &replyType, QByteArray &replyData)
virtual QCStringList | functionsDynamic ()
virtual QCStringList | interfacesDynamic ()
virtual QCStringList | interfaces ()
virtual QCStringList | functions ()
void | emitDCOPSignal (const QCString &signal, const QByteArray &data)
bool | connectDCOPSignal (const QCString &sender, const QCString &senderObj, const QCString &signal, const QCString &slot, bool Volatile)
bool | disconnectDCOPSignal (const QCString &sender, const QCString &senderObj, const QCString &signal, const QCString &slot)
DCOPClient * | callingDcopClient ()

## Static Public Member Functions

static void | addCmdLineOptions ()
static bool | start ()
static void | setHandleAutoStarted ()
Static Public Member Functions inherited from KApplication
static void | addCmdLineOptions ()
static KApplication * | kApplication ()
static DCOPClient * | dcopClient ()
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 Member Functions inherited from DCOPObject
static bool | hasObject (const QCString &objId)
static DCOPObject * | find (const QCString &objId)
static QPtrList< DCOPObject > | match (const QCString &partialId)
static QCString | objectName (QObject *obj)

## Protected Member Functions

virtual void | virtual_hook (int id, void *data)
Protected Member Functions inherited from KApplication
| KApplication (bool allowStyles, bool GUIenabled, KInstance *_instance)
void | invokeEditSlot (const char *slot)
Protected Member Functions inherited from KInstance
| KInstance (const KInstance &)
void | setConfigName (const QString &name)

## Additional Inherited Members

Public Types inherited from KApplication
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 inherited from KApplication
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 inherited from KApplication
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 ()
Static Public Attributes inherited from KApplication
static bool | loadedByKdeinit = false
Protected Attributes inherited from KApplication
Atom | kipcCommAtom
int | kipcEventMask
int | pArgc
Static Protected Attributes inherited from KApplication
static KApplication * | KApp = 0L

## Detailed Description

Maintains only a single instance of a running application at a time.

If another instance is started, it will determine (via DCOP) whether it is the first instance or a second instance. If it is a second instance, it will forward on the information to the first instance and then quit.

The .desktop file for the application should state X-DCOP-ServiceType=Unique, see kapplication.h

If your application is used to open files, it should also support the –tempfile option (see KCmdLineArgs::addTempFileOption()), to delete tempfiles after use. Add X-KDE-HasTempFileOption=true to the .desktop file to indicate this.

See also
  KApplication DCOPObject

Author
  Preston Brown pbrow.nosp@m.n@kd.nosp@m.e.org

Definition at line 48 of file kuniqueapplication.h.

## Constructor & Destructor Documentation

KUniqueApplication::KUniqueApplication | ( | bool | allowStyles = `true`,
|  | bool | GUIenabled = `true`,
|  | bool | configUnique = `false`
| ) |  |

Constructor.

Takes 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 KApplication::enableStyles() before displaying any widgets.
  GUIenabled | Set to false to disable all GUI stuff. This implies no styles either.
  configUnique | If true, the uniqueness of the application will depend on the value of the "MultipleInstances" key in the "KDE" group of the application config file.

Definition at line 317 of file kuniqueapplication.cpp.

KUniqueApplication::~KUniqueApplication | ( |  | ) |

virtual

Destructor.

Definition at line 348 of file kuniqueapplication.cpp.

## Member Function Documentation

void KUniqueApplication::addCmdLineOptions | ( |  | ) |

static

Adds command line options specific for KUniqueApplication.

Should be called before calling KUniqueApplication constructor and / or start().

Definition at line 87 of file kuniqueapplication.cpp.

int KUniqueApplication::newInstance | ( |  | ) |

virtual

Creates a new "instance" of the application.

Usually this will involve making some calls into the GUI portion of your application asking for a new window to be created, possibly with some data already loaded based on the arguments received.

Command line arguments have been passed to KCmdLineArgs before this function is called and can be checked in the usual way.

The default implementation ensures the mainwindow of the already running instance is shown and activated if necessary. You should prefer using it from your overridden method instead of doing it directly.

Note that newInstance() is called also in the first started application process.

Returns
  An exit value. The calling process will exit with this value.

Definition at line 466 of file kuniqueapplication.cpp.

bool KUniqueApplication::process | ( | const QCString & | fun,
|  | const QByteArray & | data,
|  | QCString & | replyType,
|  | QByteArray & | replyData
| ) |  |

virtual

Dispatches any incoming DCOP message for a new instance.

If it is not a request for a new instance, return false. Overloaded from DCOPObject to make sure that the application stays unique.

Parameters

  fun | DCOP function signature
  data | the data for the arguments
  replyType | the type of the reply value
  replyData | the reply

See also
  DCOPObject

Reimplemented from DCOPObject.

Definition at line 393 of file kuniqueapplication.cpp.

bool KUniqueApplication::restoringSession | ( |  | ) |

Returns whether newInstance() is being called while session restoration is in progress.

Since
  KDE 3.3

Definition at line 461 of file kuniqueapplication.cpp.

bool KUniqueApplication::start | ( |  | ) |

static

Forks and registers with dcop.

The command line arguments are being sent via DCOP to newInstance() and will be received once the application enters the event loop.

Typically this is used like:

int main(int argc, char **argv) {
KAboutData about("myappname", "myAppName", .....);
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions( myCmdOptions );
KUniqueApplication::addCmdLineOptions();
if (!KUniqueApplication::start()) {
fprintf(stderr, "myAppName is already running!\n");
exit(0);
}
KUniqueApplication a;
a.exec();
}

Note that it's not necessary to call start() explicitly. It will be called automatically before creating KUniqueApplication if it hasn't been called yet, without any performance impact.

Returns
  true if registration is successful. false if another process was already running.

Definition at line 93 of file kuniqueapplication.cpp.

The documentation for this class was generated from the following files:

- kuniqueapplication.h
- kuniqueapplication.cpp

KDE Home | KDE Accessibility Home | Description of Access Keys