• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | List of all members
KRun Class Reference

#include <krun.h>

Inherits TQObject.

Signals

void finished ()
 
void error ()
 

Public Member Functions

 KRun (const KURL &url, mode_t mode=0, bool isLocalFile=false, bool showProgressInfo=true)
 
 KRun (const KURL &url, TQWidget *window, mode_t mode=0, bool isLocalFile=false, bool showProgressInfo=true)
 
 KRun (const KURL &url, TQWidget *window, const TQCString &asn, mode_t mode=0, bool isLocalFile=false, bool showProgressInfo=true)
 
virtual ~KRun ()
 
void abort ()
 
bool hasError () const
 
bool hasFinished () const
 
bool autoDelete () const
 
void setAutoDelete (bool b)
 
void setPreferredService (const TQString &desktopEntryName)
 
void setRunExecutables (bool b)
 
void setEnableExternalBrowser (bool b)
 
void setSuggestedFileName (const TQString &fileName)
 

Static Public Member Functions

static pid_t run (const KService &_service, const KURL::List &_urls, TQWidget *window, bool tempFiles=false)
 
static pid_t run (const KService &_service, const KURL::List &_urls, TQWidget *window, const TQCString &asn, bool tempFiles=false)
 
static pid_t run (const KService &_service, const KURL::List &_urls, bool tempFiles)
 
static pid_t run (const KService &_service, const KURL::List &_urls)
 
static pid_t run (const KService &_service, const KURL::List &_urls, TQWidget *window, bool tempFiles, const TQString &suggestedFileName)
 
static pid_t run (const KService &_service, const KURL::List &_urls, TQWidget *window, const TQCString &asn, bool tempFiles, const TQString &suggestedFileName)
 
static pid_t run (const TQString &_exec, const KURL::List &_urls, const TQString &_name=TQString::null, const TQString &_icon=TQString::null, const TQString &_obsolete1=TQString::null, const TQString &_obsolete2=TQString::null)
 
static pid_t runURL (const KURL &_url, const TQString &_mimetype, bool tempFile, bool runExecutables)
 
static pid_t runURL (const KURL &_url, const TQString &_mimetype, bool tempFile)
 
static pid_t runURL (const KURL &_url, const TQString &_mimetype)
 
static pid_t runURL (const KURL &_url, const TQString &_mimetype, TQWidget *window, const TQCString &asn, bool tempFile, bool runExecutables, const TQString &suggestedFileName)
 
static pid_t runURL (const KURL &_url, const TQString &_mimetype, bool tempFile, bool runExecutables, const TQString &suggestedFileName)
 
static pid_t runCommand (TQString cmd)
 
static pid_t runCommand (const TQString &cmd, const TQString &execName, const TQString &icon)
 
static pid_t runCommand (const TQString &cmd, const TQString &execName, const TQString &icon, TQWidget *window, const TQCString &asn)
 
static bool displayOpenWithDialog (const KURL::List &lst, bool tempFiles)
 
static bool displayOpenWithDialog (const KURL::List &lst)
 
static bool displayOpenWithDialog (const KURL::List &lst, bool tempFiles, const TQString &suggestedFileName)
 
static void shellQuote (TQString &_str)
 
static TQStringList processDesktopExec (const KService &_service, const KURL::List &_urls, bool has_shell, bool tempFiles)
 
static TQStringList processDesktopExec (const KService &_service, const KURL::List &_urls, bool has_shell)
 
static TQStringList processDesktopExec (const KService &_service, const KURL::List &_urls, bool has_shell, bool tempFiles, const TQString &suggestedFileName)
 
static TQString binaryName (const TQString &execLine, bool removePath)
 
static bool isExecutable (const TQString &serviceType)
 
static bool isExecutableFile (const KURL &url, const TQString &mimetype)
 
static bool checkStartupNotify (const TQString &binName, const KService *service, bool *silent_arg, TQCString *wmclass_arg)
 

Protected Slots

void slotTimeout ()
 
void slotScanFinished (TDEIO::Job *)
 
void slotScanMimeType (TDEIO::Job *, const TQString &type)
 
virtual void slotStatResult (TDEIO::Job *)
 

Protected Member Functions

virtual void init ()
 
virtual void scanFile ()
 
virtual void foundMimeType (const TQString &_type)
 
virtual void killJob ()
 
virtual void virtual_hook (int id, void *data)
 

Protected Attributes

KURL m_strURL
 
bool m_bFault
 
bool m_bAutoDelete
 
bool m_bProgressInfo
 
bool m_bFinished
 
TDEIO::Job * m_job
 
TQTimer m_timer
 
bool m_bScanFile
 
bool m_bIsDirectory
 
bool m_bInit
 
bool m_bIsLocalFile
 
mode_t m_mode
 

Detailed Description

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.

Opens files with their associated applications in KDE

Definition at line 58 of file krun.h.

Constructor & Destructor Documentation

KRun::KRun ( const KURL &  url,
mode_t  mode = 0,
bool  isLocalFile = false,
bool  showProgressInfo = true 
)

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
urlthe URL of the file or directory to 'run'
modeThe st_mode field of struct stat. If you don't know this set it to 0.
isLocalFileIf 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.
showProgressInfoWhether to show progress information when determining the type of the file (i.e. when using TDEIO::stat and TDEIO::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.

Definition at line 874 of file krun.cpp.

KRun::KRun ( const KURL &  url,
TQWidget *  window,
mode_t  mode = 0,
bool  isLocalFile = false,
bool  showProgressInfo = true 
)

BIC: Combine with the above ctor for KDE 4.0.

Parameters
windowThe 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.
urlthe URL of the file or directory to 'run'
modeThe st_mode field of struct stat. If you don't know this set it to 0.
isLocalFileIf 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.
showProgressInfoWhether to show progress information when determining the type of the file (i.e. when using TDEIO::stat and TDEIO::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.

Definition at line 880 of file krun.cpp.

KRun::~KRun ( )
virtual

Destructor.

Don't call it yourself, since a KRun object auto-deletes itself.

Definition at line 1114 of file krun.cpp.

Member Function Documentation

void KRun::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)

Definition at line 1407 of file krun.cpp.

bool KRun::autoDelete ( ) const
inline

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

Definition at line 152 of file krun.h.

TQString KRun::binaryName ( const TQString &  execLine,
bool  removePath 
)
static

Given a full command line (e.g.

the Exec= line from a .desktop file), extract the name of the binary being run.

Parameters
execLinethe full command line
removePathif true, remove a (relative or absolute) path. E.g. /usr/bin/ls becomes ls.
Returns
the name of the binary to run
Since
3.1

Definition at line 543 of file krun.cpp.

bool KRun::displayOpenWithDialog ( const KURL::List &  lst,
bool  tempFiles 
)
static

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

Parameters
lstthe list of applications to run
tempFilesif true and lst are local files, they will be deleted when the application exits.
Returns
false if the dialog was canceled

Definition at line 209 of file krun.cpp.

bool KRun::displayOpenWithDialog ( const KURL::List &  lst,
bool  tempFiles,
const TQString &  suggestedFileName 
)
static
Since
3.5.3

Definition at line 214 of file krun.cpp.

void KRun::error ( )
signal

Emitted when the operation had an error.

See also
hasError()
void KRun::finished ( )
signal

Emitted when the operation finished.

See also
hasFinished()
void KRun::foundMimeType ( const TQString &  _type)
protectedvirtual

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.

Note: the line above means that if that service failed, we'll go to runURL to maybe find another service, even though a dialog box was displayed. That's good if runURL tries another service, but it's not good if it tries the same one :}

Definition at line 1291 of file krun.cpp.

bool KRun::hasError ( ) const
inline

Returns true if the KRun instance has an error.

Returns
true when an error occurred
See also
error()

Definition at line 136 of file krun.h.

bool KRun::hasFinished ( ) const
inline

Returns true if the KRun instance has finished.

Returns
true if the KRun instance has finished
See also
finished()

Definition at line 143 of file krun.h.

bool KRun::isExecutable ( const TQString &  serviceType)
static

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

Since
3.2

Definition at line 1447 of file krun.cpp.

bool KRun::isExecutableFile ( const KURL &  url,
const TQString &  mimetype 
)
static

Returns wether the url of mimetype is executable.

To be executable the file must pass the following rules:

  1. Must reside on the local filesystem.
  2. Must be marked as executable for the user by the filesystem.
  3. 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
    X-TDE-IsAlso=application/x-executable-script
    to the mimetype's desktop file.
    Since
    3.3

Definition at line 99 of file krun.cpp.

TQStringList KRun::processDesktopExec ( const KService &  _service,
const KURL::List &  _urls,
bool  has_shell,
bool  tempFiles 
)
static

Processes a Exec= line as found in .desktop files.

Parameters
_servicethe service to extract information from.
_urlsThe urls the service should open.
has_shellIf 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.
tempFilesif 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().

Definition at line 374 of file krun.cpp.

TQStringList KRun::processDesktopExec ( const KService &  _service,
const KURL::List &  _urls,
bool  has_shell,
bool  tempFiles,
const TQString &  suggestedFileName 
)
static
Since
3.5.3

compatibility hack – KDE 4: remove

Definition at line 379 of file krun.cpp.

pid_t KRun::run ( const KService &  _service,
const KURL::List &  _urls,
TQWidget *  window,
bool  tempFiles = false 
)
static

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

Parameters
_servicethe service to run
_urlsthe list of URLs, can be empty (app launched without argument)
windowThe top-level widget of the app that invoked this object.
tempFilesif true and _urls are local files, they will be deleted when the application exits.
Returns
the process id, or 0 on error
Since
3.5.2

Definition at line 755 of file krun.cpp.

pid_t KRun::run ( const KService &  _service,
const KURL::List &  _urls,
bool  tempFiles 
)
static

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

Parameters
_servicethe service to run
_urlsthe list of URLs, can be empty (app launched without argument)
tempFilesif true and _urls are local files, they will be deleted when the application exits.
Returns
the process id, or 0 on error

Definition at line 750 of file krun.cpp.

pid_t KRun::run ( const KService &  _service,
const KURL::List &  _urls,
TQWidget *  window,
bool  tempFiles,
const TQString &  suggestedFileName 
)
static
Since
3.5.3

Definition at line 765 of file krun.cpp.

pid_t KRun::run ( const TQString &  _exec,
const KURL::List &  _urls,
const TQString &  _name = TQString::null,
const TQString &  _icon = TQString::null,
const TQString &  _obsolete1 = TQString::null,
const TQString &  _obsolete2 = TQString::null 
)
static

Open a list of URLs with.

Parameters
_execthe name of the executable, for example "/usr/bin/netscape".
_urlsthe list of URLs to open, can be empty (app launched without argument)
_namethe logical name of the application, for example "Netscape 4.06".
_iconthe icon which should be used by the application.
_obsolete1Do not use!
_obsolete2Do not use!
Returns
the process id, or 0 on error

Definition at line 840 of file krun.cpp.

pid_t KRun::runCommand ( TQString  cmd)
static

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.

Definition at line 848 of file krun.cpp.

pid_t KRun::runCommand ( const TQString &  cmd,
const TQString &  execName,
const TQString &  icon 
)
static

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
cmdmust be a shell command. You must not append "&" to it, since the function will do that for you.
execNamethe name of the executable
iconicon 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.

Definition at line 853 of file krun.cpp.

pid_t KRun::runURL ( const KURL &  _url,
const TQString &  _mimetype,
bool  tempFile,
bool  runExecutables 
)
static

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
_urlthe URL to open
_mimetypethe mime type of the resource
tempFileif true and _url is a local file, it will be deleted when the launched application exits.
runExecutablesif false then local .desktop files, executables and shell scripts will not be run. See also isExecutable().
Returns
the process id, or 0 on error

Definition at line 94 of file krun.cpp.

pid_t KRun::runURL ( const KURL &  _url,
const TQString &  _mimetype,
TQWidget *  window,
const TQCString &  asn,
bool  tempFile,
bool  runExecutables,
const TQString &  suggestedFileName 
)
static
Since
3.5.3

Definition at line 120 of file krun.cpp.

void KRun::setAutoDelete ( bool  b)
inline

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
btrue to enable auto deletion, false to disable

Definition at line 162 of file krun.h.

void KRun::setEnableExternalBrowser ( bool  b)

Sets whether the external webbrowser setting should be honoured.

This is enabled by default. This should only be disabled in webbrowser applications.

Parameters
bwhether to enable the external browser or not.
Since
3.4

Definition at line 1424 of file krun.cpp.

void KRun::setPreferredService ( const TQString &  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-TDE-LastOpenedWith key, for the recent documents list.

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

Definition at line 1432 of file krun.cpp.

void KRun::setRunExecutables ( bool  b)

Sets whether executables, .desktop files or shell scripts should be run by KRun.

This is enabled by default.

Parameters
bwhether to run executable files or not.
See also
isExecutable()
Since
3.2

Definition at line 1437 of file krun.cpp.

void KRun::setSuggestedFileName ( const TQString &  fileName)

Sets the file name to use in the case of downloading the file to a tempfile in order to give to a non-url-aware application.

Some apps rely on the extension to determine the mimetype of the file. Usually the file name comes from the URL, but in the case of the HTTP Content-Disposition header, we need to override the file name.

Since
3.5.3

Definition at line 1442 of file krun.cpp.

void KRun::shellQuote ( TQString &  _str)
static

Quotes a string for the shell.

Parameters
_strthe string to quote. The quoted string will be written here

Definition at line 236 of file krun.cpp.

Member Data Documentation

bool KRun::m_bInit
protected

USed to indicate that the next action is to initialize.

This action is invoked from slotTimeout

Definition at line 441 of file krun.h.

bool KRun::m_bScanFile
protected

Used to indicate that the next action is to scan the file.

This action is invoked from slotTimeout.

Definition at line 434 of file krun.h.


The documentation for this class was generated from the following files:
  • krun.h
  • krun.cpp

tdeio/tdeio

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

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.8.8
This website is maintained by Timothy Pearson.