• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

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

#include <krun.h>

Inheritance diagram for KRun:
Inheritance graph
[legend]

Classes

class  KRunPrivate
 

Signals

void error ()
 
void finished ()
 

Public Member Functions

 KRun (const KUrl &url, QWidget *window, mode_t mode=0, bool isLocalFile=false, bool showProgressInfo=true, const QByteArray &asn=QByteArray())
 
virtual ~KRun ()
 
void abort ()
 
bool autoDelete () const
 
bool hasError () const
 
bool hasFinished () const
 
void setAutoDelete (bool b)
 
void setEnableExternalBrowser (bool b)
 
void setPreferredService (const QString &desktopEntryName)
 
void setRunExecutables (bool b)
 
void setSuggestedFileName (const QString &fileName)
 
QString suggestedFileName () const
 
QWidget * window () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual  ~QObject ()
 
bool blockSignals (bool block)
 
QObject * child (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArray > dynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
T findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObject * metaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObject * parent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThread * thread () const
 

Static Public Member Functions

static QString binaryName (const QString &execLine, bool removePath)
 
static bool checkStartupNotify (const QString &binName, const KService *service, bool *silent_arg, QByteArray *wmclass_arg)
 
static bool displayOpenWithDialog (const KUrl::List &lst, QWidget *window, bool tempFiles=false, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
 
static bool isExecutable (const QString &serviceType)
 
static bool isExecutableFile (const KUrl &url, const QString &mimetype)
 
static QStringList processDesktopExec (const KService &_service, const KUrl::List &_urls, bool tempFiles=false, const QString &suggestedFileName=QString())
 
static bool run (const KService &service, const KUrl::List &urls, QWidget *window, bool tempFiles=false, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
 
static bool run (const QString &exec, const KUrl::List &urls, QWidget *window, const QString &name=QString(), const QString &icon=QString(), const QByteArray &asn=QByteArray())
 
static bool runCommand (const QString &cmd, QWidget *window)
 
static bool runCommand (const QString &cmd, QWidget *window, const QString &workingDirectory)
 
static bool runCommand (const QString &cmd, const QString &execName, const QString &icon, QWidget *window, const QByteArray &asn=QByteArray())
 
static bool runCommand (const QString &cmd, const QString &execName, const QString &icon, QWidget *window, const QByteArray &asn, const QString &workingDirectory)
 
static bool runUrl (const KUrl &url, const QString &mimetype, QWidget *window, bool tempFile=false, bool runExecutables=true, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
 
static void shellQuote (QString &str)
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Slots

void mimeTypeDetermined (const QString &mimeType)
 
void slotScanFinished (KJob *)
 
void slotScanMimeType (KIO::Job *, const QString &type)
 
virtual void slotStatResult (KJob *)
 
void slotTimeout ()
 

Protected Member Functions

bool doScanFile () const
 
virtual void foundMimeType (const QString &type)
 
virtual void init ()
 
bool initializeNextAction () const
 
bool isDirectory () const
 
bool isLocalFile () const
 
KIO::Job * job ()
 
virtual void killJob ()
 
mode_t mode () const
 
bool progressInfo () const
 
virtual void scanFile ()
 
void setDoScanFile (bool scanFile)
 
void setError (bool error)
 
void setFinished (bool finished)
 
void setInitializeNextAction (bool initialize)
 
void setIsDirecory (bool isDirectory)
 
void setIsLocalFile (bool isLocalFile)
 
void setJob (KIO::Job *job)
 
void setMode (mode_t mode)
 
void setProgressInfo (bool progressInfo)
 
void setUrl (const KUrl &url)
 
QTimer & timer ()
 
KUrl url () const
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

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 59 of file krun.h.

Constructor & Destructor Documentation

KRun::KRun ( const KUrl &  url,
QWidget *  window,
mode_t  mode = 0,
bool  isLocalFile = false,
bool  showProgressInfo = true,
const QByteArray &  asn = QByteArray() 
)
Parameters
urlthe URL of the file or directory to 'run'
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.
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 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.
asnApplication startup notification id, if available (otherwise "").

Definition at line 1101 of file krun.cpp.

KRun::~KRun ( )
virtual

Destructor.

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

Definition at line 1255 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 1531 of file krun.cpp.

bool KRun::autoDelete ( ) const

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 1567 of file krun.cpp.

QString KRun::binaryName ( const QString &  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

Definition at line 568 of file krun.cpp.

bool KRun::checkStartupNotify ( const QString &  binName,
const KService *  service,
bool *  silent_arg,
QByteArray *  wmclass_arg 
)
static

Definition at line 651 of file krun.cpp.

bool KRun::displayOpenWithDialog ( const KUrl::List &  lst,
QWidget *  window,
bool  tempFiles = false,
const QString &  suggestedFileName = QString(),
const QByteArray &  asn = QByteArray() 
)
static

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

Parameters
lstthe list of applications to run
windowThe top-level widget of the app that invoked this object.
tempFilesif true and lst are local files, they will be deleted when the application exits.
suggestedFileNamesee setSuggestedFileName
asnApplication startup notification id, if any (otherwise "").
Returns
false if the dialog was canceled

Definition at line 193 of file krun.cpp.

bool KRun::doScanFile ( ) const
protected

Returns whether the file shall be scanned.

Deprecated:
not useful in public API

Definition at line 1672 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.

This signal is emitted in all cases of completion, whether successful or with error.

See also
hasFinished()
void KRun::foundMimeType ( const QString &  type)
protectedvirtual

Called if the mimetype has been detected.

The function runs the application associated with this mimetype. Reimplement this method to implement a different behavior, like opening the component for displaying the URL embedded.

Important: call setFinished(true) once you are done! Usually at the end of the foundMimeType reimplementation, but if the reimplementation is asynchronous (e.g. uses KIO jobs) then it can be called later instead.

Note: if that service failed, we'll go to runUrl below to maybe find another service, even though an error dialog box was already displayed. That's good if runUrl tries another service, but it's not good if it tries the same one :}

Definition at line 1472 of file krun.cpp.

bool KRun::hasError ( ) const

Returns true if the KRun instance has an error.

Returns
true when an error occurred
See also
error()

Definition at line 1557 of file krun.cpp.

bool KRun::hasFinished ( ) const

Returns true if the KRun instance has finished.

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

Definition at line 1562 of file krun.cpp.

void KRun::init ( )
protectedvirtual

All following protected methods are used by subclasses of KRun!

Initializes the krun object.

Definition at line 1139 of file krun.cpp.

bool KRun::initializeNextAction ( ) const
protected
Deprecated:
not useful in public API

Definition at line 1698 of file krun.cpp.

bool KRun::isDirectory ( ) const
protected

Returns whether it is a directory.

Definition at line 1685 of file krun.cpp.

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

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

Definition at line 1607 of file krun.cpp.

bool KRun::isExecutableFile ( const KUrl &  url,
const QString &  mimetype 
)
static

Returns whether 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-KDE-IsAlso=application/x-executable-script
    to the mimetype's desktop file.

Definition at line 100 of file krun.cpp.

bool KRun::isLocalFile ( ) const
protected

Returns whether it is a local file.

Definition at line 1709 of file krun.cpp.

KIO::Job * KRun::job ( )
protected

Returns the job.

Definition at line 1652 of file krun.cpp.

void KRun::killJob ( )
protectedvirtual

Kills the file scanning job.

Definition at line 1522 of file krun.cpp.

void KRun::mimeTypeDetermined ( const QString &  mimeType)
protectedslot

Call this from subclasses when you have determined the mimetype.

It will call foundMimeType, but also sets up protection against deletion during message boxes.

Since
4.0.2

Definition at line 1457 of file krun.cpp.

mode_t KRun::mode ( ) const
protected

Returns the file mode.

Definition at line 1719 of file krun.cpp.

QStringList KRun::processDesktopExec ( const KService &  _service,
const KUrl::List &  _urls,
bool  tempFiles = false,
const QString &  suggestedFileName = QString() 
)
static

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

Parameters
_servicethe service to extract information from.
_urlsThe urls the service should open.
tempFilesif true and urls are local files, they will be deleted when the application exits.
suggestedFileNamesee setSuggestedFileName
Returns
a list of arguments suitable for KProcess::setProgram().

Definition at line 407 of file krun.cpp.

bool KRun::progressInfo ( ) const
protected

Returns whether progress information are shown.

Definition at line 1635 of file krun.cpp.

bool KRun::run ( const KService &  service,
const KUrl::List &  urls,
QWidget *  window,
bool  tempFiles = false,
const QString &  suggestedFileName = QString(),
const QByteArray &  asn = QByteArray() 
)
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.
suggestedFileNamesee setSuggestedFileName
asnApplication startup notification id, if any (otherwise "").
Returns
true on success, false on error

Definition at line 984 of file krun.cpp.

bool KRun::run ( const QString &  exec,
const KUrl::List &  urls,
QWidget *  window,
const QString &  name = QString(),
const QString &  icon = QString(),
const QByteArray &  asn = QByteArray() 
)
static

Open a list of URLs with an executable.

Parameters
execthe name of the executable, for example "/usr/bin/netscape %u". Don't forget to include the u if you know that the applications supports URLs. Otherwise, non-local urls will first be downloaded to a temp file (using kioexec).
urlsthe list of URLs to open, can be empty (app launched without argument)
windowThe top-level widget of the app that invoked this object.
namethe logical name of the application, for example "Netscape 4.06".
iconthe icon which should be used by the application.
asnApplication startup notification id, if any (otherwise "").
Returns
true on success, false on error

Definition at line 1049 of file krun.cpp.

bool KRun::runCommand ( const QString &  cmd,
QWidget *  window 
)
static

Run the given shell command and notifies KDE 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.

Parameters
windowThe top-level widget of the app that invoked this object.
Returns
true on success, false on error

Definition at line 1057 of file krun.cpp.

bool KRun::runCommand ( const QString &  cmd,
QWidget *  window,
const QString &  workingDirectory 
)
static

Overload that also takes a working directory, so that a command like "kwrite file.txt" finds file.txt from the right place.

Since
4.4

Definition at line 1062 of file krun.cpp.

bool KRun::runCommand ( const QString &  cmd,
const QString &  execName,
const QString &  icon,
QWidget *  window,
const QByteArray &  asn = QByteArray() 
)
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
windowThe top-level widget of the app that invoked this object.
asnApplication startup notification id, if any (otherwise "").
Returns
true on success, false on error

Definition at line 1079 of file krun.cpp.

bool KRun::runCommand ( const QString &  cmd,
const QString &  execName,
const QString &  icon,
QWidget *  window,
const QByteArray &  asn,
const QString &  workingDirectory 
)
static

Overload that also takes a working directory, so that a command like "kwrite file.txt" finds file.txt from the right place.

Parameters
workingDirectorythe working directory for the started process. The default (if passing an empty string) is the user's document path.
Since
4.4

Definition at line 1084 of file krun.cpp.

bool KRun::runUrl ( const KUrl &  url,
const QString &  mimetype,
QWidget *  window,
bool  tempFile = false,
bool  runExecutables = true,
const QString &  suggestedFileName = QString(),
const QByteArray &  asn = QByteArray() 
)
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
windowThe top-level widget of the app that invoked this object.
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().
suggestedFileNamesee setSuggestedFileName
asnApplication startup notification id, if any (otherwise "").
Returns
true on success, false on error

Definition at line 122 of file krun.cpp.

void KRun::scanFile ( )
protectedvirtual

Start scanning a file.

Definition at line 1289 of file krun.cpp.

void KRun::setAutoDelete ( bool  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
btrue to enable auto deletion, false to disable

Definition at line 1572 of file krun.cpp.

void KRun::setDoScanFile ( bool  scanFile)
protected

Indicate that the next action is to scan the file.

Deprecated:
not useful in public API

Definition at line 1665 of file krun.cpp.

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.

Definition at line 1577 of file krun.cpp.

void KRun::setError ( bool  error)
protected

Sets whether an error has occurred.

Definition at line 1625 of file krun.cpp.

void KRun::setFinished ( bool  finished)
protected

Marks this 'KRun' instance as finished.

Definition at line 1640 of file krun.cpp.

void KRun::setInitializeNextAction ( bool  initialize)
protected
Deprecated:
not useful in public API

Definition at line 1691 of file krun.cpp.

void KRun::setIsDirecory ( bool  isDirectory)
protected

Sets whether it is a directory.

Deprecated:
typo in the name, and not useful as a public method

Definition at line 1679 of file krun.cpp.

void KRun::setIsLocalFile ( bool  isLocalFile)
protected

Sets whether it is a local file.

Definition at line 1704 of file krun.cpp.

void KRun::setJob ( KIO::Job *  job)
protected

Sets the job.

Definition at line 1647 of file krun.cpp.

void KRun::setMode ( mode_t  mode)
protected

Sets the file mode.

Definition at line 1714 of file krun.cpp.

void KRun::setPreferredService ( const QString &  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 in the recent documents list, or for the app selection in KParts::BrowserOpenOrSaveQuestion.

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

Definition at line 1587 of file krun.cpp.

void KRun::setProgressInfo ( bool  progressInfo)
protected

Sets whether progress information shall be shown.

Definition at line 1630 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()

Definition at line 1592 of file krun.cpp.

void KRun::setSuggestedFileName ( const QString &  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.

Definition at line 1597 of file krun.cpp.

void KRun::setUrl ( const KUrl &  url)
protected

Sets the url.

Definition at line 1615 of file krun.cpp.

void KRun::shellQuote ( QString &  str)
static

Quotes a string for the shell.

An empty string will not be quoted.

Deprecated:
Use KShell::quoteArg() instead. Note that this function behaves differently for empty arguments and returns the result differently.
Parameters
strthe string to quote. The quoted string will be written here

Definition at line 223 of file krun.cpp.

void KRun::slotScanFinished ( KJob *  job)
protectedslot

This slot is called when the scan job is finished.

Definition at line 1434 of file krun.cpp.

void KRun::slotScanMimeType ( KIO::Job *  ,
const QString &  type 
)
protectedslot

This slot is called when the scan job has found out the mime type.

Definition at line 1425 of file krun.cpp.

void KRun::slotStatResult ( KJob *  job)
protectedvirtualslot

This slot is called when the 'stat' job has finished.

Definition at line 1364 of file krun.cpp.

void KRun::slotTimeout ( )
protectedslot

All following protected slots are used by subclasses of KRun!

This slot is called whenever the internal timer fired, in order to move on to the next step.

Definition at line 1330 of file krun.cpp.

QString KRun::suggestedFileName ( ) const

Suggested file name given by the server (e.g.

HTTP content-disposition)

Definition at line 1602 of file krun.cpp.

QTimer & KRun::timer ( )
protected

Returns the timer object.

Deprecated:
setFinished(true) now takes care of the timer().start(0), so this can be removed.

Definition at line 1658 of file krun.cpp.

KUrl KRun::url ( ) const
protected

Returns the url.

Definition at line 1620 of file krun.cpp.

QWidget * KRun::window ( ) const

Associated window, as passed to the constructor.

Since
4.9.3

Definition at line 1552 of file krun.cpp.


The documentation for this class was generated from the following files:
  • krun.h
  • krun.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:55 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal