|
|
Maintain 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.
See also: KApplication, DCOPObject
KUniqueApplication ( bool allowStyles,
bool GUIenabled,
bool configUnique)
| KUniqueApplication |
Constructor. Takes command line arguments from KCmdLineArgs
Parameters : See KApplication constructor.
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.
KUniqueApplication ( bool allowStyles=true,
bool GUIenabled=true)
| KUniqueApplication |
void addCmdLineOptions ()
| addCmdLineOptions |
[static]
Add command line options specific for KUniqueApplication
Should be called before calling KUniqueApplication constructor and / or start().
Reimplemented from KApplication.
bool start ()
| start |
[static]
Fork and register 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(); } |
or
int main(int argc, char **argv) { KAboutData about("myappname", "myAppName", .....); KCmdLineArgs::init(argc, argv, &about); KCmdLineArgs::addCmdLineOptions( myCmdOptions ); KUniqueApplication::addCmdLineOptions(); if (!KUniqueApplication::start()) exit(0); KUniqueApplication a; a.exec(); } |
Although it is not necassery to call start() before creating a KUniqueApplication it is adviced to so because it is about 40% faster if the application was already running: If you use start() the KApplication constructor will not be called if this isn't necessary.
Returns: true
if registration is succesful.
false
if another process was already running.
~KUniqueApplication ()
| ~KUniqueApplication |
[virtual]
DCOPClient * dcopClient ()
| dcopClient |
[virtual]
Retrieve the DCOP client object.
Reimplemented from KApplication.
bool process (const QCString &fun, const QByteArray &data,
QCString &replyType, QByteArray &replyData)
| process |
Dispatch any incoming DCOP message for a new instance.
If it is not a request for a new instance, return false
.
Reimplemented from DCOPObject.
int newInstance ()
| newInstance |
[virtual]
Create 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.
Returns: An exit value. The calling process will exit with this value.