org.kde.koala

Class KRun

public class KRun extends QObject

To open files with their associated applications in KDE, use KRun. It can execute any desktop entry, as well as any file, using the default application or another application "bound" to the file type (or URL protocol). In that example, the mimetype of the file is not known by the application, so a KRun instance must be created. It will determine the mimetype by itself. If the mimetype is known, or if you even know the service (application) to use for this file, use one of the static methods. By default KRun uses auto deletion. It causes the KRun instance to delete itself when the it finished its task. If you allocate the KRun object on the stack you must disable auto deletion, otherwise it will crash. See KRunSignals for signals emitted by KRun

UNKNOWN: Opens files with their associated applications in KDE.

Constructor Summary
protected KRun(Class dummy)
KRun(KURL url, long mode, boolean isLocalFile, boolean showProgressInfo)
Create a KRun object to run the preferred application for a file/URL.
KRun(KURL url, long mode, boolean isLocalFile)
KRun(KURL url, long mode)
KRun(KURL url)
KRun(KURL url, QWidget window, long mode, boolean isLocalFile, boolean showProgressInfo)
BIC: Combine with the above ctor for KDE 4.0.
KRun(KURL url, QWidget window, long mode, boolean isLocalFile)
KRun(KURL url, QWidget window, long mode)
KRun(KURL url, QWidget window)
Method Summary
voidabort()
Abort this KRun.
booleanautoDelete()
Checks whether auto delete is activated.
static StringbinaryName(String execLine, boolean removePath)
Given a full command line (e.g. the Exec= line from a .desktop file), extract the name of the binary being run.
static booleancheckStartupNotify(String binName, KService service, boolean[] silent_arg, StringBuffer wmclass_arg)
StringclassName()
static booleandisplayOpenWithDialog(ArrayList lst, boolean tempFiles)
Display the Open-With dialog for those URLs, and run the chosen application.
static booleandisplayOpenWithDialog(ArrayList lst)
voiddispose()
Delete the wrapped C++ instance ahead of finalize()
protected voidfinalize()
Deletes the wrapped C++ instance
protected voidfoundMimeType(String _type)
Called if the mimetype has been detected.
booleanhasError()
Returns true if the KRun instance has an error.
booleanhasFinished()
Returns true if the KRun instance has finished.
protected voidinit()
booleanisDisposed()
Has the wrapped C++ instance been deleted?
static booleanisExecutable(String serviceType)
Returns whether serviceType refers to an executable program instead of a data file.
static booleanisExecutableFile(KURL url, String mimetype)
Returns wether the url of mimetype is executable.
protected voidkillJob()
QMetaObjectmetaObject()
static ArrayListprocessDesktopExec(KService _service, ArrayList _urls, boolean has_shell, boolean tempFiles)
Processes a Exec= line as found in .desktop files.
static ArrayListprocessDesktopExec(KService _service, ArrayList _urls, boolean has_shell)
static intrun(KService _service, ArrayList _urls, boolean tempFiles)
Open a list of URLs with a certain service (application).
static intrun(KService _service, ArrayList _urls)
static intrun(String _exec, ArrayList _urls, String _name, String _icon, String _obsolete1, String _obsolete2)
Open a list of URLs with.
static intrun(String _exec, ArrayList _urls, String _name, String _icon, String _obsolete1)
static intrun(String _exec, ArrayList _urls, String _name, String _icon)
static intrun(String _exec, ArrayList _urls, String _name)
static intrun(String _exec, ArrayList _urls)
static intrunCommand(String cmd)
Run the given shell command and notifies kicker of the starting of the application.
static intrunCommand(String cmd, String execName, String icon)
Same as the other runCommand(), but it also takes the name of the binary, to display an error message in case it couldn't find it.
static intrunURL(KURL _url, String _mimetype, boolean tempFile, boolean runExecutables)
Open the given URL.
static intrunURL(KURL _url, String _mimetype, boolean tempFile)
static intrunURL(KURL _url, String _mimetype)
protected voidscanFile()
voidsetAutoDelete(boolean b)
Enables or disabled auto deletion.
voidsetEnableExternalBrowser(boolean b)
Sets whether the external webbrowser setting should be honoured.
voidsetPreferredService(String desktopEntryName)
Set the preferred service for opening this URL, after its mimetype will have been found by KRun.
voidsetRunExecutables(boolean b)
Sets whether executables, .desktop files or shell scripts should be run by KRun.
static voidshellQuote(StringBuffer _str)
Quotes a string for the shell.
protected voidslotScanFinished(Job arg1)
protected voidslotScanMimeType(Job arg1, String type)
protected voidslotStatResult(Job arg1)
protected voidslotTimeout()

Constructor Detail

KRun

protected KRun(Class dummy)

KRun

public KRun(KURL url, long mode, boolean isLocalFile, boolean showProgressInfo)
Create a KRun object to run the preferred application for a file/URL. KRun will first determine the type of the file, and will then run the associated application.

Parameters: url the URL of the file or directory to 'run' mode The st_mode field of struct stat. If you don't know this set it to 0. isLocalFile If this parameter is set to false then url is examined to find out whether it is a local URL or not. This flag is just used to improve speed, since the function KURL.isLocalFile is a bit slow. showProgressInfo Whether to show progress information when determining the type of the file (i.e. when using KIO.stat and KIO.mimetype) Before you set this to false to avoid a dialog box, think about a very slow FTP server... It is always better to provide progress info in such cases.

UNKNOWN: Create a KRun object to run the preferred application for a file/URL.

KRun

public KRun(KURL url, long mode, boolean isLocalFile)

KRun

public KRun(KURL url, long mode)

KRun

public KRun(KURL url)

KRun

public KRun(KURL url, QWidget window, long mode, boolean isLocalFile, boolean showProgressInfo)
BIC: Combine with the above ctor for KDE 4.0.

Parameters: window The top-level widget of the app that invoked this object. It is used to make sure private information like passwords are properly handled per application. url the URL of the file or directory to 'run' mode The st_mode field of struct stat. If you don't know this set it to 0. isLocalFile If this parameter is set to false then url is examined to find out whether it is a local URL or not. This flag is just used to improve speed, since the function KURL.isLocalFile is a bit slow. showProgressInfo Whether to show progress information when determining the type of the file (i.e. when using KIO.stat and KIO.mimetype) Before you set this to false to avoid a dialog box, think about a very slow FTP server... It is always better to provide progress info in such cases.

UNKNOWN: BIC: Combine with the above ctor for KDE 4.

KRun

public KRun(KURL url, QWidget window, long mode, boolean isLocalFile)

KRun

public KRun(KURL url, QWidget window, long mode)

KRun

public KRun(KURL url, QWidget window)

Method Detail

abort

public void abort()
Abort this KRun. This kills any jobs launched by it, and leads to deletion if auto-deletion is on. This is much safer than deleting the KRun (in case it's currently showing an error dialog box, for instance)

UNKNOWN: Abort this KRun.

autoDelete

public boolean autoDelete()
Checks whether auto delete is activated. Auto-deletion causes the KRun instance to delete itself when it finished its task. By default auto deletion is on.

Returns: true if auto deletion is on, false otherwise

UNKNOWN: Checks whether auto delete is activated.

binaryName

public static String binaryName(String execLine, boolean removePath)
Given a full command line (e.g. the Exec= line from a .desktop file), extract the name of the binary being run.

Parameters: execLine the full command line removePath if true, remove a (relative or absolute) path. E.g. /usr/bin/ls becomes ls.

Returns: the name of the binary to run

UNKNOWN: Given a full command line (e.

checkStartupNotify

public static boolean checkStartupNotify(String binName, KService service, boolean[] silent_arg, StringBuffer wmclass_arg)

UNKNOWN:

className

public String className()

displayOpenWithDialog

public static boolean displayOpenWithDialog(ArrayList lst, boolean tempFiles)
Display the Open-With dialog for those URLs, and run the chosen application.

Parameters: lst the list of applications to run tempFiles if true and lst are local files, they will be deleted when the application exits.

Returns: false if the dialog was canceled

UNKNOWN: Display the Open-With dialog for those URLs, and run the chosen application.

displayOpenWithDialog

public static boolean displayOpenWithDialog(ArrayList lst)

dispose

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

finalize

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

foundMimeType

protected void foundMimeType(String _type)
Called if the mimetype has been detected. The function checks whether the document and appends the gzip protocol to the URL. Otherwise runURL is called to finish the job.

UNKNOWN: Called if the mimetype has been detected.

hasError

public boolean hasError()
Returns true if the KRun instance has an error.

Returns: true when an error occurred

See Also: KRun

UNKNOWN: Returns true if the KRun instance has an error.

hasFinished

public boolean hasFinished()
Returns true if the KRun instance has finished.

Returns: true if the KRun instance has finished

See Also: KRun

UNKNOWN: Returns true if the KRun instance has finished.

init

protected void init()

isDisposed

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

isExecutable

public static boolean isExecutable(String serviceType)
Returns whether serviceType refers to an executable program instead of a data file.

UNKNOWN: Returns whether serviceType refers to an executable program instead of a data file.

isExecutableFile

public static boolean isExecutableFile(KURL url, String mimetype)
Returns wether the url of mimetype is executable. To be executable the file must pass the following rules: -# Must reside on the local filesystem. -# Must be marked as executable for the user by the filesystem. -# The mime type must inherit application/x-executable or application/x-executable-script. To allow a script to run when the above rules are satisfied add the entry

UNKNOWN: X-KDE-IsAlso=application/x-executable-script to the mimetype's desktop file. Returns wether the url of mimetype is executable.

killJob

protected void killJob()

metaObject

public QMetaObject metaObject()

processDesktopExec

public static ArrayList processDesktopExec(KService _service, ArrayList _urls, boolean has_shell, boolean tempFiles)
Processes a Exec= line as found in .desktop files.

Parameters: _service the service to extract information from. _urls The urls the service should open. has_shell If true, the arguments are going to be fed into a shell e.g by using system(). If false, the arguments are going to be fed into a exec() kind call. If the arguments are intended for an exec() kind of call and the Exec line contains shell commands then "/bin/sh -c" is added. tempFiles if true and _urls are local files, they will be deleted when the application exits.

Returns: a list of arguments suitable for either system() or exec().

UNKNOWN: Processes a Exec= line as found in .

processDesktopExec

public static ArrayList processDesktopExec(KService _service, ArrayList _urls, boolean has_shell)

run

public static int run(KService _service, ArrayList _urls, boolean tempFiles)
Open a list of URLs with a certain service (application).

Parameters: _service the service to run _urls the list of URLs, can be empty (app launched without argument) tempFiles if true and _urls are local files, they will be deleted when the application exits.

Returns: the process id, or 0 on error

UNKNOWN: Open a list of URLs with a certain service (application).

run

public static int run(KService _service, ArrayList _urls)

run

public static int run(String _exec, ArrayList _urls, String _name, String _icon, String _obsolete1, String _obsolete2)
Open a list of URLs with.

Parameters: _exec the name of the executable, for example "/usr/bin/netscape". _urls the list of URLs to open, can be empty (app launched without argument) _name the logical name of the application, for example "Netscape 4.06". _icon the icon which should be used by the application. _obsolete1 Do not use! _obsolete2 Do not use!

Returns: the process id, or 0 on error

UNKNOWN: Open a list of URLs with.

run

public static int run(String _exec, ArrayList _urls, String _name, String _icon, String _obsolete1)

run

public static int run(String _exec, ArrayList _urls, String _name, String _icon)

run

public static int run(String _exec, ArrayList _urls, String _name)

run

public static int run(String _exec, ArrayList _urls)

runCommand

public static int runCommand(String cmd)
Run the given shell command and notifies kicker of the starting of the application. If the program to be called doesn't exist, an error box will be displayed. Use only when you know the full command line. Otherwise use the other static methods, or KRun's constructor. _cmd must be a shell command. You must not append "&" to it, since the function will do that for you.

Returns: PID of running command, 0 if it could not be started, 0 - (PID of running command) if command was unsafe for map notification.

UNKNOWN: Run the given shell command and notifies kicker of the starting of the application.

runCommand

public static int runCommand(String cmd, String execName, String icon)
Same as the other runCommand(), but it also takes the name of the binary, to display an error message in case it couldn't find it.

Parameters: cmd must be a shell command. You must not append "&" to it, since the function will do that for you. execName the name of the executable icon icon for app starting notification

Returns: PID of running command, 0 if it could not be started, 0 - (PID of running command) if command was unsafe for map notification.

UNKNOWN: Same as the other runCommand(), but it also takes the name of the binary, to display an error message in case it couldn't find it.

runURL

public static int runURL(KURL _url, String _mimetype, boolean tempFile, boolean runExecutables)
Open the given URL. This function is used after the mime type is found out. It will search for all services which can handle the mime type and call run() afterwards.

Parameters: _url the URL to open _mimetype the mime type of the resource tempFile if true and _url is a local file, it will be deleted when the launched application exits. runExecutables if false then local .desktop files, executables and shell scripts will not be run. See also isExecutable().

Returns: the process id, or 0 on error

UNKNOWN: Open the given URL.

runURL

public static int runURL(KURL _url, String _mimetype, boolean tempFile)

runURL

public static int runURL(KURL _url, String _mimetype)

scanFile

protected void scanFile()

setAutoDelete

public void setAutoDelete(boolean b)
Enables or disabled auto deletion. Auto deletion causes the KRun instance to delete itself when it finished its task. If you allocate the KRun object on the stack you must disable auto deletion. By default auto deletion is on.

Parameters: b true to enable auto deletion, false to disable

UNKNOWN: Enables or disabled auto deletion.

setEnableExternalBrowser

public void setEnableExternalBrowser(boolean b)
Sets whether the external webbrowser setting should be honoured. This is enabled by default. This should only be disabled in webbrowser applications.

Parameters: b whether to enable the external browser or not.

UNKNOWN: Sets whether the external webbrowser setting should be honoured.

setPreferredService

public void setPreferredService(String desktopEntryName)
Set the preferred service for opening this URL, after its mimetype will have been found by KRun. IMPORTANT: the service is only used if its configuration says it can handle this mimetype. This is used for instance for the X-KDE-LastOpenedWith key, for the recent documents list.

Parameters: desktopEntryName the desktopEntryName of the service, e.g. "kate".

UNKNOWN: Set the preferred service for opening this URL, after its mimetype will have been found by KRun.

setRunExecutables

public void setRunExecutables(boolean b)
Sets whether executables, .desktop files or shell scripts should be run by KRun. This is enabled by default.

Parameters: b whether to run executable files or not.

See Also: KRun

UNKNOWN: Sets whether executables, .

shellQuote

public static void shellQuote(StringBuffer _str)
Quotes a string for the shell.

Parameters: _str the string to quote. The quoted string will be written here

UNKNOWN: Quotes a string for the shell.

slotScanFinished

protected void slotScanFinished(Job arg1)

slotScanMimeType

protected void slotScanMimeType(Job arg1, String type)

slotStatResult

protected void slotStatResult(Job arg1)

slotTimeout

protected void slotTimeout()