• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

Public Types | Public Member Functions | Static Public Member Functions | List of all members
KUniqueApplication Class Reference

#include <kuniqueapplication.h>

Inheritance diagram for KUniqueApplication:
Inheritance graph
[legend]

Public Types

enum  StartFlag { NonUniqueInstance = 0x1 }
 

Public Member Functions

 KUniqueApplication (bool GUIenabled=true, bool configUnique=false)
 
 KUniqueApplication (Display *display, Qt::HANDLE visual=0, Qt::HANDLE colormap=0, bool configUnique=false)
 
virtual ~KUniqueApplication ()
 
virtual int newInstance ()
 
bool restoringSession ()
 
- Public Member Functions inherited from KApplication
 KApplication (bool GUIenabled=true)
 
 KApplication (Display *display, Qt::HANDLE visual=0, Qt::HANDLE colormap=0)
 
 KApplication (Display *display, int &argc, char **argv, const QByteArray &rAppName, bool GUIenabled=true)
 
virtual ~KApplication ()
 
void clearStartupId ()
 
void commitData (QSessionManager &sm)
 
void disableSessionManagement ()
 
void enableSessionManagement ()
 
void iceIOErrorHandler (_IceConn *conn)
 
void installX11EventFilter (QWidget *filter)
 
bool notify (QObject *receiver, QEvent *event)
 
void removeX11EventFilter (const QWidget *filter)
 
void saveState (QSessionManager &sm)
 
KConfig * sessionConfig ()
 
bool sessionSaving () const
 
void setStartupId (const QByteArray &startup_id)
 
void setSynchronizeClipboard (bool synchronize)
 
void setTopWidget (QWidget *topWidget)
 
QByteArray startupId () const
 
void updateRemoteUserTimestamp (const QString &service, int time=0)
 
unsigned long userTimestamp () const
 
int xErrhandler (Display *, void *)
 
int xioErrhandler (Display *)
 
- Public Member Functions inherited from QApplication
 QApplication (int &argc, char **argv)
 
 QApplication (int &argc, char **argv, Type type)
 
 QApplication (Display *display, Qt::HANDLE visual, Qt::HANDLE colormap)
 
 QApplication (Display *display, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE colormap)
 
 QApplication (QApplication::QS60MainApplicationFactory factory, int &argc, char **argv)
 
 QApplication (int &argc, char **argv, bool GUIenabled)
 
virtual  ~QApplication ()
 
void aboutToReleaseGpuResources ()
 
void aboutToUseGpuResources ()
 
int autoMaximizeThreshold () const
 
bool autoSipEnabled () const
 
void commitDataRequest (QSessionManager &manager)
 
void focusChanged (QWidget *old, QWidget *now)
 
void fontDatabaseChanged ()
 
QInputContext * inputContext () const
 
bool isSessionRestored () const
 
void lastWindowClosed ()
 
virtual bool macEventFilter (EventHandlerCallRef caller, EventRef event)
 
virtual bool qwsEventFilter (QWSEvent *event)
 
void qwsSetCustomColors (QRgb *colorTable, int start, int numColors)
 
void saveStateRequest (QSessionManager &manager)
 
QString sessionId () const
 
QString sessionKey () const
 
void setAutoMaximizeThreshold (const int threshold)
 
void setAutoSipEnabled (const bool enabled)
 
void setInputContext (QInputContext *inputContext)
 
void setStyleSheet (const QString &sheet)
 
QString styleSheet () const
 
virtual bool symbianEventFilter (const QSymbianEvent *event)
 
int symbianProcessEvent (const QSymbianEvent *event)
 
int x11ProcessEvent (XEvent *event)
 
- Public Member Functions inherited from QCoreApplication
 QCoreApplication (int &argc, char **argv)
 
 ~QCoreApplication ()
 
void aboutToQuit ()
 
bool filterEvent (void *message, long *result)
 
void lock ()
 
bool locked ()
 
EventFilter setEventFilter (EventFilter filter)
 
bool tryLock ()
 
void unlock (bool wakeUpGui)
 
virtual bool winEventFilter (MSG *msg, long *result)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual  ~QObject ()
 
bool blockSignals (bool block)
 
QObject * child (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArray > dynamicPropertyNames () const
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
T findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObject * metaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObject * parent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThread * thread () const
 

Static Public Member Functions

static void addCmdLineOptions ()
 
static void setHandleAutoStarted ()
 
static bool start (StartFlags flags)
 
static bool start ()
 
- Static Public Member Functions inherited from KApplication
static QString checkRecoverFile (const QString &pFilename, bool &bRecover)
 
static KApplication * kApplication ()
 
static QString tempSaveName (const QString &pFilename)
 
- Static Public Member Functions inherited from QApplication
void aboutQt ()
 
QWidget * activeModalWidget ()
 
QWidget * activePopupWidget ()
 
QWidget * activeWindow ()
 
void alert (QWidget *widget, int msec)
 
QWidgetList allWidgets ()
 
void beep ()
 
void changeOverrideCursor (const QCursor &cursor)
 
QClipboard * clipboard ()
 
void closeAllWindows ()
 
ColorMode colorMode ()
 
int colorSpec ()
 
int cursorFlashTime ()
 
QDesktopWidget * desktop ()
 
bool desktopSettingsAware ()
 
int doubleClickInterval ()
 
int exec ()
 
void flushX ()
 
QWidget * focusWidget ()
 
QFont font (const QWidget *widget)
 
QFont font ()
 
QFont font (const char *className)
 
QFontMetrics fontMetrics ()
 
QSize globalStrut ()
 
bool hasGlobalMouseTracking ()
 
Qt::Alignment horizontalAlignment (QFlags< Qt::AlignmentFlag > align)
 
bool isEffectEnabled (Qt::UIEffect effect)
 
bool isLeftToRight ()
 
bool isRightToLeft ()
 
Qt::LayoutDirection keyboardInputDirection ()
 
int keyboardInputInterval ()
 
QLocale keyboardInputLocale ()
 
Qt::KeyboardModifiers keyboardModifiers ()
 
bool keypadNavigationEnabled ()
 
Qt::LayoutDirection layoutDirection ()
 
Qt::MacintoshVersion macVersion ()
 
QWidget * mainWidget ()
 
Qt::MouseButtons mouseButtons ()
 
Qt::NavigationMode navigationMode ()
 
QCursor * overrideCursor ()
 
QPalette palette (const QWidget *widget)
 
QPalette palette ()
 
QPalette palette (const char *className)
 
Qt::KeyboardModifiers queryKeyboardModifiers ()
 
bool quitOnLastWindowClosed ()
 
QDecoration & qwsDecoration ()
 
void qwsSetDecoration (QDecoration *decoration)
 
QDecoration * qwsSetDecoration (const QString &decoration)
 
void restoreOverrideCursor ()
 
bool reverseLayout ()
 
void setActiveWindow (QWidget *active)
 
void setColorMode (ColorMode mode)
 
void setColorSpec (int spec)
 
void setCursorFlashTime (int)
 
void setDesktopSettingsAware (bool on)
 
void setDoubleClickInterval (int)
 
void setEffectEnabled (Qt::UIEffect effect, bool enable)
 
void setFont (const QFont &font, bool b, const char *className)
 
void setFont (const QFont &font, const char *className)
 
void setGlobalMouseTracking (bool dummy)
 
void setGlobalStrut (const QSize &)
 
void setGraphicsSystem (const QString &system)
 
void setKeyboardInputInterval (int)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setMainWidget (QWidget *mainWidget)
 
void setNavigationMode (Qt::NavigationMode mode)
 
void setOverrideCursor (const QCursor &cursor)
 
void setOverrideCursor (const QCursor &cursor, bool replace)
 
void setPalette (const QPalette &pal, bool b, const char *className)
 
void setPalette (const QPalette &palette, const char *className)
 
void setQuitOnLastWindowClosed (bool quit)
 
void setReverseLayout (bool reverse)
 
void setStartDragDistance (int l)
 
void setStartDragTime (int ms)
 
void setStyle (QStyle *style)
 
QStyle * setStyle (const QString &style)
 
void setWheelScrollLines (int)
 
void setWindowIcon (const QIcon &icon)
 
void setWinStyleHighlightColor (const QColor &c)
 
int startDragDistance ()
 
int startDragTime ()
 
QStyle * style ()
 
void syncX ()
 
QWidget * topLevelAt (const QPoint &point)
 
QWidget * topLevelAt (int x, int y)
 
QWidgetList topLevelWidgets ()
 
Type type ()
 
int wheelScrollLines ()
 
QWidget * widgetAt (const QPoint &point)
 
QWidget * widgetAt (int x, int y, bool child)
 
QWidget * widgetAt (const QPoint &point, bool child)
 
QWidget * widgetAt (int x, int y)
 
QIcon windowIcon ()
 
const QColor & winStyleHighlightColor ()
 
Qt::WindowsVersion winVersion ()
 
- Static Public Member Functions inherited from QCoreApplication
void addLibraryPath (const QString &path)
 
QString applicationDirPath ()
 
QString applicationFilePath ()
 
QString applicationName ()
 
qint64 applicationPid ()
 
QString applicationVersion ()
 
int argc ()
 
QStringList arguments ()
 
char ** argv ()
 
bool closingDown ()
 
int enter_loop ()
 
int exec ()
 
void exit (int returnCode)
 
void exit_loop ()
 
void flush ()
 
bool hasPendingEvents ()
 
void installTranslator (QTranslator *translationFile)
 
QCoreApplication * instance ()
 
QStringList libraryPaths ()
 
int loopLevel ()
 
QString organizationDomain ()
 
QString organizationName ()
 
void postEvent (QObject *receiver, QEvent *event)
 
void postEvent (QObject *receiver, QEvent *event, int priority)
 
void processEvents (QFlags< QEventLoop::ProcessEventsFlag > flags)
 
void processEvents (QFlags< QEventLoop::ProcessEventsFlag > flags, int maxtime)
 
void processOneEvent ()
 
void quit ()
 
void removeLibraryPath (const QString &path)
 
void removePostedEvents (QObject *receiver, int eventType)
 
void removePostedEvents (QObject *receiver)
 
void removeTranslator (QTranslator *translationFile)
 
bool sendEvent (QObject *receiver, QEvent *event)
 
void sendPostedEvents (QObject *receiver, int event_type)
 
void sendPostedEvents ()
 
void setApplicationName (const QString &application)
 
void setApplicationVersion (const QString &version)
 
void setAttribute (Qt::ApplicationAttribute attribute, bool on)
 
void setLibraryPaths (const QStringList &paths)
 
void setOrganizationDomain (const QString &orgDomain)
 
void setOrganizationName (const QString &orgName)
 
bool startingUp ()
 
bool testAttribute (Qt::ApplicationAttribute attribute)
 
QString translate (const char *context, const char *sourceText, const char *disambiguation, Encoding encoding, int n)
 
QString translate (const char *context, const char *sourceText, const char *disambiguation, Encoding encoding)
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Additional Inherited Members

- Public Slots inherited from KApplication
Q_SCRIPTABLE void quit ()
 
Q_SCRIPTABLE void reparseConfiguration ()
 
Q_SCRIPTABLE void updateUserTimestamp (int time=0)
 
- Signals inherited from KApplication
void saveYourself ()
 
- Public Attributes inherited from QApplication
typedef ColorMode
 
typedef QS60MainApplicationFactory
 
- Public Attributes inherited from QCoreApplication
typedef EventFilter
 
- Static Public Attributes inherited from KApplication
static bool loadedByKdeinit = false
 
- Protected Member Functions inherited from KApplication
 KApplication (bool GUIenabled, const KComponentData &cData)
 
 KApplication (Display *display, Qt::HANDLE visual, Qt::HANDLE colormap, const KComponentData &cData)
 
bool x11EventFilter (XEvent *)
 
- Protected Member Functions inherited from QApplication
virtual bool event (QEvent *e)
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Static Protected Attributes inherited from KApplication
static KApplication * KApp = 0L
 
- Properties inherited from QApplication
 autoMaximizeThreshold
 
 autoSipEnabled
 
 cursorFlashTime
 
 doubleClickInterval
 
 globalStrut
 
 keyboardInputInterval
 
 layoutDirection
 
 quitOnLastWindowClosed
 
 startDragDistance
 
 startDragTime
 
 styleSheet
 
 wheelScrollLines
 
 windowIcon
 
- Properties inherited from QCoreApplication
 applicationName
 
 applicationVersion
 
 organizationDomain
 
 organizationName
 
- Properties inherited from QObject
 objectName
 

Detailed Description

KUniqueApplication is a KApplication which only uses a single process.

When a KUniqueApplication is started, it attempts to contact an existing copy of the application. If successful, the program asks the existing process to create a new instance by calling its newInstance() method and then exits. If there is no existing process then the program forks and calls the newInstance() method. When newInstance() is called, the application will typically create a new window or activate an existing one.

Instances of KUniqueApplication can be made to behave like a normal application by passing the StartFlag::NonUniqueInstance flag to start().

Please note that this supports only one process per KDE session. If your application can only be opened once per user or once per host, you need to ensure this independently of KUniqueApplication.

The .desktop file for the application should state X-DBUS-StartupType=Unique, see ktoolinvocation.h

If you use command line options before start() is called, you MUST call addCmdLineOptions() so that the KUniqueApplication-specific command-line options can still work.

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
Author
Preston Brown pbrow.nosp@m.n@kd.nosp@m.e.org

Definition at line 55 of file kuniqueapplication.h.

Member Enumeration Documentation

enum KUniqueApplication::StartFlag

These flags can be used to specify how new instances of unique applications are created.

Enumerator
NonUniqueInstance 

Create a new instance of the application in a new process and do not attempt to re-use an existing process.

With this flag set, the new instance of the application will behave as if it were a plain KApplication rather than a KUniqueApplication.

This is useful if you have an application where all instances are typically run in a single process but under certain circumstances new instances may require their own process.

Definition at line 106 of file kuniqueapplication.h.

Constructor & Destructor Documentation

KUniqueApplication::KUniqueApplication ( bool  GUIenabled = true,
bool  configUnique = false 
)
explicit

Constructor.

Takes command line arguments from KCmdLineArgs

Parameters
GUIenabledSet to false to disable all GUI stuff. This implies no styles either.
configUniqueIf 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 312 of file kuniqueapplication.cpp.

KUniqueApplication::KUniqueApplication ( Display *  display,
Qt::HANDLE  visual = 0,
Qt::HANDLE  colormap = 0,
bool  configUnique = false 
)
explicit

Constructor.

Takes command line arguments from KCmdLineArgs

Parameters
displayWill be passed to Qt as the X display. The display must be valid and already opened.
visualPointer to the X11 visual that should be used by the application. If NULL, the default visual will be used instead.
colormapThe colormap that should be used by the application. If 0, the default colormap will be used instead.
configUniqueIf 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 329 of file kuniqueapplication.cpp.

KUniqueApplication::~KUniqueApplication ( )
virtual

Destructor.

Definition at line 347 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 85 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. If your application has only one mainwindow, you should call this default implementation and only add your special handling if needed.

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

For applications that share one process for several mainwindows, the reimplementation could be:

int MyApp::newInstance()
{
KCmdLineArgs::setCwd(QDir::currentPath().toUtf8());
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
static bool first = true;
if (args->count() > 0) {
for (int i = 0; i < args->count(); ++i) {
openWindow(args->url(i));
}
} else if( !first || !isSessionRestored()) {
openWindow(KUrl()); // create a new window
}
first = false;
args->clear();
return 0;
}
Returns
An exit value. The calling process will exit with this value.

Definition at line 390 of file kuniqueapplication.cpp.

bool KUniqueApplication::restoringSession ( )

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

Definition at line 385 of file kuniqueapplication.cpp.

void KUniqueApplication::setHandleAutoStarted ( )
static

Definition at line 418 of file kuniqueapplication.cpp.

bool KUniqueApplication::start ( StartFlags  flags)
static

Forks and registers with D-Bus.

The command line arguments are being sent via D-Bus 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", 0, ki18n("myAppName"), .....);
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions( myCmdOptions );
KUniqueApplication::addCmdLineOptions();
if (!KUniqueApplication::start()) {
fprintf(stderr, "myAppName is already running!\n");
return 0;
}
KUniqueApplication a;
return 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.

Also note that you MUST call KUniqueApplication::addCmdLineOptions(), if you use command line options before start() is called.

Parameters
flagsOptional flags which control how a new instance of the application is started.
Returns
true if registration is successful. false if another process was already running.

Definition at line 114 of file kuniqueapplication.cpp.

bool KUniqueApplication::start ( )
static

Definition at line 108 of file kuniqueapplication.cpp.


The documentation for this class was generated from the following files:
  • kuniqueapplication.h
  • kuniqueapplication.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal