You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
222 lines
7.5 KiB
222 lines
7.5 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (c) 1999 Preston Brown <pbrown@kde.org>
|
||
|
Copyright (c) 2000-2001 Waldo Bastian <bastian@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
3 weeks ago
|
#ifndef _TDEUNIQUEAPP_H
|
||
|
#define _TDEUNIQUEAPP_H
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <dcopobject.h>
|
||
|
|
||
3 weeks ago
|
class TDEUniqueApplicationPrivate;
|
||
15 years ago
|
|
||
|
/**
|
||
|
* 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,
|
||
12 years ago
|
* see tdeapplication.h
|
||
15 years ago
|
*
|
||
|
* If your application is used to open files, it should also support the --tempfile
|
||
12 years ago
|
* option (see TDECmdLineArgs::addTempFileOption()), to delete tempfiles after use.
|
||
13 years ago
|
* Add X-TDE-HasTempFileOption=true to the .desktop file to indicate this.
|
||
15 years ago
|
*
|
||
12 years ago
|
* @see TDEApplication DCOPObject
|
||
15 years ago
|
* @author Preston Brown <pbrown@kde.org>
|
||
|
*/
|
||
3 weeks ago
|
class TDECORE_EXPORT TDEUniqueApplication : public TDEApplication, public DCOPObject
|
||
15 years ago
|
{
|
||
1 year ago
|
TQ_OBJECT
|
||
15 years ago
|
public:
|
||
|
/**
|
||
12 years ago
|
* Constructor. Takes command line arguments from TDECmdLineArgs
|
||
15 years ago
|
*
|
||
|
* @param 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 @p allowStyles set to false
|
||
|
* it normally runs in the background but under special circumstances
|
||
12 years ago
|
* displays widgets. Call TDEApplication::enableStyles() before
|
||
15 years ago
|
* displaying any widgets.
|
||
|
* @param GUIenabled Set to false to disable all GUI stuff. This implies
|
||
|
* no styles either.
|
||
|
* @param 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.
|
||
|
*/
|
||
3 weeks ago
|
TDEUniqueApplication( bool allowStyles=true,
|
||
15 years ago
|
bool GUIenabled=true,
|
||
|
bool configUnique=false);
|
||
|
|
||
10 months ago
|
#ifdef TQ_WS_X11
|
||
15 years ago
|
/**
|
||
12 years ago
|
* Constructor. Takes command line arguments from TDECmdLineArgs
|
||
15 years ago
|
*
|
||
|
* @param display Will be passed to Qt as the X display. The display
|
||
|
* must be valid and already opened.
|
||
|
* @param visual Pointer to the X11 visual that should be used by the
|
||
|
* application. If NULL, the default visual will be used instead.
|
||
|
* @param colormap The colormap that should be used by the application.
|
||
|
* If 0, the default colormap will be used instead.
|
||
|
* @param 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 @p allowStyles set to false
|
||
|
* it normally runs in the background but under special circumstances
|
||
12 years ago
|
* displays widgets. Call TDEApplication::enableStyles() before
|
||
15 years ago
|
* displaying any widgets.
|
||
|
* @param 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.
|
||
|
* @since KDE 3.3
|
||
|
*/
|
||
3 weeks ago
|
TDEUniqueApplication( Display *display,
|
||
1 year ago
|
TQt::HANDLE visual=0,
|
||
|
TQt::HANDLE colormap=0,
|
||
15 years ago
|
bool allowStyles=true,
|
||
|
bool configUnique=false);
|
||
|
#endif
|
||
|
|
||
|
/**
|
||
3 weeks ago
|
* Adds command line options specific for TDEUniqueApplication.
|
||
15 years ago
|
*
|
||
3 weeks ago
|
* Should be called before calling TDEUniqueApplication constructor
|
||
15 years ago
|
* and / or start().
|
||
|
*/
|
||
|
static void addCmdLineOptions();
|
||
|
|
||
|
/**
|
||
|
* 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:
|
||
|
* \code
|
||
|
* int main(int argc, char **argv) {
|
||
12 years ago
|
* TDEAboutData about("myappname", "myAppName", .....);
|
||
12 years ago
|
* TDECmdLineArgs::init(argc, argv, &about);
|
||
|
* TDECmdLineArgs::addCmdLineOptions( myCmdOptions );
|
||
3 weeks ago
|
* TDEUniqueApplication::addCmdLineOptions();
|
||
15 years ago
|
*
|
||
3 weeks ago
|
* if (!TDEUniqueApplication::start()) {
|
||
15 years ago
|
* fprintf(stderr, "myAppName is already running!\n");
|
||
|
* exit(0);
|
||
|
* }
|
||
3 weeks ago
|
* TDEUniqueApplication a;
|
||
15 years ago
|
* a.exec();
|
||
|
* }
|
||
|
* \endcode
|
||
|
* Note that it's not necessary to call start() explicitly. It will be
|
||
3 weeks ago
|
* called automatically before creating TDEUniqueApplication if it hasn't
|
||
15 years ago
|
* been called yet, without any performance impact.
|
||
|
*
|
||
|
* @return true if registration is successful.
|
||
|
* false if another process was already running.
|
||
|
*/
|
||
|
static bool start();
|
||
|
|
||
|
/**
|
||
|
* Destructor
|
||
|
*/
|
||
3 weeks ago
|
virtual ~TDEUniqueApplication();
|
||
15 years ago
|
|
||
|
/**
|
||
|
* 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.
|
||
|
* @param fun DCOP function signature
|
||
|
* @param data the data for the arguments
|
||
|
* @param replyType the type of the reply value
|
||
|
* @param replyData the reply
|
||
|
* @see DCOPObject
|
||
|
*/
|
||
15 years ago
|
bool process(const TQCString &fun, const TQByteArray &data,
|
||
|
TQCString &replyType, TQByteArray &replyData);
|
||
15 years ago
|
|
||
|
/**
|
||
|
* 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.
|
||
|
*
|
||
12 years ago
|
* Command line arguments have been passed to TDECmdLineArgs before this
|
||
15 years ago
|
* 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.
|
||
|
*
|
||
|
* @return An exit value. The calling process will exit with this value.
|
||
|
*/
|
||
|
virtual int newInstance();
|
||
|
|
||
|
/**
|
||
|
* Returns whether newInstance() is being called while session
|
||
|
* restoration is in progress.
|
||
|
*
|
||
|
* @since KDE 3.3
|
||
|
*/
|
||
|
bool restoringSession();
|
||
|
|
||
|
/**
|
||
|
* @internal
|
||
|
*/
|
||
|
static void setHandleAutoStarted();
|
||
|
|
||
|
private:
|
||
|
/**
|
||
|
* Delays the processing of a DCOP request.
|
||
|
*/
|
||
15 years ago
|
void delayRequest(const TQCString &fun, const TQByteArray &data);
|
||
15 years ago
|
|
||
|
private slots:
|
||
|
/**
|
||
|
* Delayed processing of DCOP requests.
|
||
|
*/
|
||
|
void processDelayed();
|
||
|
|
||
|
void newInstanceNoFork();
|
||
|
|
||
12 years ago
|
static TDEInstance* initHack( bool configUnique );
|
||
15 years ago
|
|
||
|
private:
|
||
|
static bool s_nofork;
|
||
|
static bool s_multipleInstances;
|
||
|
static bool s_uniqueTestDone;
|
||
|
static bool s_handleAutoStarted;
|
||
|
|
||
|
protected:
|
||
|
virtual void virtual_hook( int id, void* data );
|
||
|
private:
|
||
3 weeks ago
|
TDEUniqueApplicationPrivate *d;
|
||
15 years ago
|
};
|
||
|
|
||
|
#endif
|