org.kde.koala

Class KUniqueApplication

public class KUniqueApplication extends KApplication implements DCOPObjectInterface

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.

Author: Preston Brown

See Also: KApplication DCOPObject

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

Constructor Summary
protected KUniqueApplication(Class dummy)
KUniqueApplication(boolean allowStyles, boolean GUIenabled, boolean configUnique)
Constructor.
KUniqueApplication(boolean allowStyles, boolean GUIenabled)
KUniqueApplication(boolean allowStyles)
KUniqueApplication()
Method Summary
static voidaddCmdLineOptions()
Adds command line options specific for KUniqueApplication.
DCOPClientcallingDcopClient()
Returns the DCOPClient responsible for making the call.
StringclassName()
booleanconnectDCOPSignal(String sender, String senderObj, String signal, String slot, boolean Volatile)
Connects to a DCOP signal.
booleandisconnectDCOPSignal(String sender, String senderObj, String signal, String slot)
Disconnects a DCOP signal.
voiddispose()
Delete the wrapped C++ instance ahead of finalize()
voidemitDCOPSignal(String signal, byte[] data)
Emit signal as DCOP signal from this object with data as arguments
protected voidfinalize()
Deletes the wrapped C++ instance
static DCOPObjectInterfacefind(String objId)
Try to find a dcop object with the given id.
ArrayListfunctions()
Returns the list of functions understood by the object.
ArrayListfunctionsDynamic()
This function is of interest when you used an IDL compiler to generate the implementation for functions() but you still want to list some functions dynamically.
static booleanhasObject(String objId)
Checks whether an object with the given id is known in this process.
ArrayListinterfaces()
Returns the names of the interfaces, specific ones last.
ArrayListinterfacesDynamic()
This function is of interest when you used an IDL compiler to generate the implementation for interfaces() but you still want to list some interfaces dynamically.
booleanisDisposed()
Has the wrapped C++ instance been deleted?
QMetaObjectmetaObject()
intnewInstance()
Creates a new "instance" of the application.
static StringobjectName(QObject arg1)
Creates an object id for the QObject obj. This is done using the QObject.name() function.
StringobjId()
Returns the object id of the DCOPObject.
booleanprocess(String fun, byte[] data, StringBuffer replyType, byte[] replyData)
Dispatches any incoming DCOP message for a new instance.
booleanprocessDynamic(String fun, byte[] data, StringBuffer replyType, byte[] replyData)
This function is of interest when you used an IDL compiler to generate the implementation for process() but you still want to dispatch some functions dynamically.
booleanrestoringSession()
Returns whether newInstance() is being called while session restoration is in progress.
voidsetCallingDcopClient(DCOPClient arg1)
static voidsetHandleAutoStarted()
booleansetObjId(String objId)
Renames a dcop object, if no other with the same name exists Use with care, all dcop signals are disconnected
static booleanstart()
Forks and registers with dcop.

Constructor Detail

KUniqueApplication

protected KUniqueApplication(Class dummy)

KUniqueApplication

public KUniqueApplication(boolean allowStyles, boolean GUIenabled, boolean configUnique)
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.

UNKNOWN: Constructor.

KUniqueApplication

public KUniqueApplication(boolean allowStyles, boolean GUIenabled)

KUniqueApplication

public KUniqueApplication(boolean allowStyles)

KUniqueApplication

public KUniqueApplication()

Method Detail

addCmdLineOptions

public static void addCmdLineOptions()
Adds command line options specific for KUniqueApplication. Should be called before calling KUniqueApplication constructor and / or start().

UNKNOWN: Adds command line options specific for KUniqueApplication.

callingDcopClient

public DCOPClient callingDcopClient()
Returns the DCOPClient responsible for making the call. Only call this function while you are handling a DCOP call.

Returns: the DCOPClient responsible for making the call. This information is only guaranteed to be correct when entering your DCOP function.

UNKNOWN: Returns the DCOPClient responsible for making the call.

className

public String className()

connectDCOPSignal

public boolean connectDCOPSignal(String sender, String senderObj, String signal, String slot, boolean Volatile)
Connects to a DCOP signal.

Parameters: sender the name of the client that emits the signal. When empty the signal will be passed from any client. senderObj the name of the sending object that emits the signal. signal the name of the signal. The arguments should match with slot. slot The name of the slot to call. Its arguments should match with signal. Volatile If true, the connection will not be reestablished when sender unregisters and reregisters with DCOP. In this case the sender must be registered when the connection is made. If false, the connection will be reestablished when sender reregisters. In this case the connection can be made even if sender is not registered at that time.

  • Volatile is true and sender does not exist.
  • signal and slot do not have matching arguments.
  • @return false if a connection could not be established. This will be the case when

    UNKNOWN: Connects to a DCOP signal.

    disconnectDCOPSignal

    public boolean disconnectDCOPSignal(String sender, String senderObj, String signal, String slot)
    Disconnects a DCOP signal. A special case is when both sender & signal are empty. In this case all connections related to this object in the current client are disconnected. (Both connections from as well as to this object!)

    Parameters: sender the name of the client that emits the signal. senderObj the name of the object that emits the signal. If empty all objects will be disconnected. signal the name of the signal. The arguments should match with slot. If empty all objects will be disconnected. slot The name of the slot the signal is connected to. If empty all slots will be disconnected.

    Returns: false if no connection(s) where removed.

    UNKNOWN: Disconnects a DCOP signal.

    dispose

    public void dispose()
    Delete the wrapped C++ instance ahead of finalize()

    emitDCOPSignal

    public void emitDCOPSignal(String signal, byte[] data)
    Emit signal as DCOP signal from this object with data as arguments

    Parameters: signal the signal to emit data the data to send

    UNKNOWN: Emit signal as DCOP signal from this object with data as arguments

    finalize

    protected void finalize()
    Deletes the wrapped C++ instance

    find

    public static DCOPObjectInterface find(String objId)
    Try to find a dcop object with the given id. This function does not query the DCOPObjectProxy.

    Parameters: objId the object id to search

    Returns: the DCOPObject for the id objId.

    UNKNOWN: Try to find a dcop object with the given id.

    functions

    public ArrayList functions()
    Returns the list of functions understood by the object. It gets reimplemented by the IDL compiler. If you don't use the IDL compiler, consider implementing this function manually if you want your object to be easily scriptable. Rationale: functions() allows an interpreter to do client-side type-casting properly. Note to implementators: remember to call the baseclasses implementation.

    Returns: a list of functions

    See Also: KUniqueApplication KUniqueApplication KUniqueApplication DCOPClient

    UNKNOWN: Returns the list of functions understood by the object.

    functionsDynamic

    public ArrayList functionsDynamic()
    This function is of interest when you used an IDL compiler to generate the implementation for functions() but you still want to list some functions dynamically. Dynamically means that the methods may appear and vanish during runtime.

    Returns: A list of the additional functions, default is an empty list.

    See Also: KUniqueApplication

    UNKNOWN: This function is of interest when you used an IDL compiler to generate the implementation for functions() but you still want to list some functions dynamically.

    hasObject

    public static boolean hasObject(String objId)
    Checks whether an object with the given id is known in this process. DCOPObjectProxy

    Returns: true if an object with the questionable objId is known in this process. This query does not ask proxies.

    UNKNOWN: Checks whether an object with the given id is known in this process.

    interfaces

    public ArrayList interfaces()
    Returns the names of the interfaces, specific ones last. The functions gets reimplemented by the IDL compiler. If you don't use the IDL compiler, consider implementing this function manually if you want your object to be easily explorable.

    Returns: a list of interfaces

    See Also: KUniqueApplication

    UNKNOWN: Returns the names of the interfaces, specific ones last.

    interfacesDynamic

    public ArrayList interfacesDynamic()
    This function is of interest when you used an IDL compiler to generate the implementation for interfaces() but you still want to list some interfaces dynamically. Dynamically means that they may appear and vanish during runtime.

    Returns: A list of the additional interfaces, default is an empty list.

    See Also: KUniqueApplication

    UNKNOWN: This function is of interest when you used an IDL compiler to generate the implementation for interfaces() but you still want to list some interfaces dynamically.

    isDisposed

    public boolean isDisposed()
    Has the wrapped C++ instance been deleted?

    metaObject

    public QMetaObject metaObject()

    newInstance

    public int newInstance()
    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.

    UNKNOWN: Creates a new "instance" of the application.

    objectName

    public static String objectName(QObject arg1)
    Creates an object id for the QObject obj. This is done using the QObject.name() function.

    Parameters: obj the object whose name will be used

    Returns: the created object id

    UNKNOWN: Creates an object id for the QObject obj.

    objId

    public String objId()
    Returns the object id of the DCOPObject.

    Returns: the object's id

    UNKNOWN: Returns the object id of the DCOPObject.

    process

    public boolean process(String fun, byte[] data, StringBuffer replyType, byte[] replyData)
    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

    UNKNOWN: Dispatches any incoming DCOP message for a new instance.

    processDynamic

    public boolean processDynamic(String fun, byte[] data, StringBuffer replyType, byte[] replyData)
    This function is of interest when you used an IDL compiler to generate the implementation for process() but you still want to dispatch some functions dynamically. Dynamically means that methods may appear and vanish during runtime.

    Parameters: fun is the normalized function signature. Such a signature usually looks like foobar(String,int). The return type, qualifiers like "const" etc. are not part of the signature. data the received data replyType write the reply type in this string replyData write the reply data in this array

    Returns: true if successful, false otherwise. The default implementation returns always false.

    See Also: KUniqueApplication DCOPClient KUniqueApplication DCOPClient

    UNKNOWN: This function is of interest when you used an IDL compiler to generate the implementation for process() but you still want to dispatch some functions dynamically.

    restoringSession

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

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

    setCallingDcopClient

    public void setCallingDcopClient(DCOPClient arg1)

    UNKNOWN:

    setHandleAutoStarted

    public static void setHandleAutoStarted()

    UNKNOWN:

    setObjId

    public boolean setObjId(String objId)
    Renames a dcop object, if no other with the same name exists Use with care, all dcop signals are disconnected

    Parameters: objId the new object id

    UNKNOWN: Renames a dcop object, if no other with the same name exists Use with care, all dcop signals are disconnected

    start

    public static boolean start()
    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(String[] args) {
    		    KAboutData about("myappname", "myAppName", .....);
    		    KCmdLineArgs.init(args, &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.

    UNKNOWN: Forks and registers with dcop.