KRun

Search for usage in LXR

#include <KRun>

Inheritance diagram for KRun:

Public Types

enum  RunFlag { DeleteTemporaryFiles = 0x1, RunExecutables = 0x2 }
 
typedef QFlags< RunFlagRunFlags
 

Signals

void error ()
 
void finished ()
 

Public Member Functions

 KRun (const QUrl &url, QWidget *window, bool showProgressInfo=true, const QByteArray &asn=QByteArray())
 
 ~KRun () override
 
void abort ()
 
bool autoDelete () const
 
bool hasError () const
 
bool hasFinished () const
 
void setAutoDelete (bool b)
 
void setEnableExternalBrowser (bool b)
 
void setFollowRedirections (bool b)
 
void setPreferredService (const QString &desktopEntryName)
 
void setRunExecutables (bool b)
 
void setShowScriptExecutionPrompt (bool showPrompt)
 
void setSuggestedFileName (const QString &fileName)
 
QString suggestedFileName () const
 
QWidgetwindow () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const 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 QList< QUrl > &lst, QWidget *window, bool tempFiles=false, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
 
static bool isExecutable (const QString &mimeType)
 
static bool isExecutableFile (const QUrl &url, const QString &mimetype)
 
static QStringList processDesktopExec (const KService &_service, const QList< QUrl > &_urls, bool tempFiles=false, const QString &suggestedFileName=QString())
 
static bool run (const KService &service, const QList< QUrl > &urls, QWidget *window, bool tempFiles=false, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
 
static bool run (const QString &exec, const QList< QUrl > &urls, QWidget *window, const QString &name=QString(), const QString &icon=QString(), const QByteArray &asn=QByteArray())
 
static qint64 runApplication (const KService &service, const QList< QUrl > &urls, QWidget *window, RunFlags flags=RunFlags(), const QString &suggestedFileName=QString(), 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 runCommand (const QString &cmd, const QString &execName, const QString &icon, QWidget *window, const QByteArray &asn=QByteArray())
 
static bool runCommand (const QString &cmd, QWidget *window, const QString &workingDirectory=QString())
 
static qint64 runService (const KService &service, const QList< QUrl > &urls, QWidget *window, bool tempFiles=false, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
 
static bool runUrl (const QUrl &url, const QString &mimetype, QWidget *window, bool tempFile=false, bool runExecutables=true, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
 
static bool runUrl (const QUrl &url, const QString &mimetype, QWidget *window, RunFlags flags, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
 
static void shellQuote (QString &str)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
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)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction 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 handleError (KJob *job)
 
virtual void handleInitError (int kioErrorCode, const QString &errorMsg)
 
virtual void init ()
 
bool initializeNextAction () const
 
bool isDirectory () const
 
bool isLocalFile () const
 
KIO::Jobjob ()
 
virtual void killJob ()
 
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 setJob (KIO::Job *job)
 
void setProgressInfo (bool progressInfo)
 
void setUrl (const QUrl &url)
 
QTimertimer ()
 
QUrl url () const
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

Opens files with their associated applications in KDE.

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 MIME type of the file is not known by the application, so a KRun instance must be created. It will determine the MIME type by itself. If the MIME type 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.

This respects the "shell_access", "openwith" and "run_desktop_files" Kiosk action restrictions (see KAuthorized::authorize()).

Definition at line 54 of file krun.h.

Member Typedef Documentation

◆ RunFlags

Stores a combination of RunFlag values.

Deprecated:
since 5.71, see porting instructions in the respective methods

Definition at line 286 of file krun.h.

Member Enumeration Documentation

◆ RunFlag

See also
RunFlags
Enumerator
DeleteTemporaryFiles 

the URLs passed to the service will be deleted when it exits (if the URLs are local files)

RunExecutables 

Whether to run URLs that are executable scripts or binaries.

See also
isExecutableFile()
Since
5.31

Definition at line 278 of file krun.h.

Constructor & Destructor Documentation

◆ KRun()

KRun::KRun ( const QUrl url,
QWidget window,
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.
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 "").
Deprecated:
since 5.71, use KIO::OpenUrlJob(url) (except for KRun subclasses, for now)
auto *job = new KIO::OpenUrlJob(url);
job->setStartupId(asn);
// methods like setRunExecutables, setSuggestedFilename, setEnableExternalBrowser, setFollowRedirections
// exist in both classes
job->start();

Definition at line 359 of file krun.cpp.

◆ ~KRun()

KRun::~KRun ( )
override

Destructor.

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

Definition at line 513 of file krun.cpp.

Member Function Documentation

◆ abort()

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

◆ autoDelete()

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

◆ binaryName()

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 executable to run
Deprecated:
since 5.0, use KIO::DesktopExecParser::executableName if removePath was true, or KIO::DesktopExecParser::executablePath if removePath was false.

Definition at line 247 of file krun.cpp.

◆ checkStartupNotify()

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

Definition at line 256 of file krun.cpp.

◆ displayOpenWithDialog()

bool KRun::displayOpenWithDialog ( const QList< QUrl > &  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 URLs to open
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
Deprecated:
since 5.71, use KIO::ApplicationLauncherJob with no service argument (or a null service)
job->setUrls(urls);
if (tempFiles) {
}
job->setSuggestedFileName(suggestedFileName);
job->setStartupId(asn);
job->start();

Definition at line 193 of file krun.cpp.

◆ doScanFile()

bool KRun::doScanFile ( ) const
protected

Returns whether the file shall be scanned.

Deprecated:
Since 4.1. Not useful in public API

Definition at line 1021 of file krun.cpp.

◆ error

void KRun::error ( )
signal

Emitted when the operation had an error.

See also
hasError()

◆ finished

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()

◆ foundMimeType()

void KRun::foundMimeType ( const QString type)
protectedvirtual

Called if the MIME type has been detected.

The function runs the application associated with this MIME type. 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 790 of file krun.cpp.

◆ handleError()

void KRun::handleError ( KJob job)
protectedvirtual

Called when a KIO job started by KRun gives an error.

The default implementation shows a message box.

Reimplemented in KParts::BrowserRun.

Definition at line 146 of file krun.cpp.

◆ handleInitError()

void KRun::handleInitError ( int  kioErrorCode,
const QString errorMsg 
)
protectedvirtual

Called when KRun detects an error during the init phase.

The default implementation shows a message box.

Since
5.0

Definition at line 138 of file krun.cpp.

◆ hasError()

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

◆ hasFinished()

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

◆ init()

void KRun::init ( )
protectedvirtual

All following protected methods are used by subclasses of KRun!

Initializes the krun object.

Reimplemented in KParts::BrowserRun.

Definition at line 394 of file krun.cpp.

◆ initializeNextAction()

bool KRun::initializeNextAction ( ) const
protected
Deprecated:
Since 4.1.

Not useful in public API

Definition at line 1047 of file krun.cpp.

◆ isDirectory()

bool KRun::isDirectory ( ) const
protected

Returns whether it is a directory.

Definition at line 1034 of file krun.cpp.

◆ isExecutable()

bool KRun::isExecutable ( const QString mimeType)
static

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

Definition at line 953 of file krun.cpp.

◆ isExecutableFile()

bool KRun::isExecutableFile ( const QUrl 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, application/x-executable-script or application/x-sharedlib. To allow a script to run when the above rules are satisfied add the entry
    X-KDE-IsAlso=application/x-executable-script
    to the MIME type's desktop file.

Definition at line 114 of file krun.cpp.

◆ isLocalFile()

bool KRun::isLocalFile ( ) const
protected

Returns whether it is a local file.

Definition at line 1053 of file krun.cpp.

◆ job()

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

Returns the job.

Definition at line 1001 of file krun.cpp.

◆ killJob()

void KRun::killJob ( )
protectedvirtual

Kills the file scanning job.

Definition at line 845 of file krun.cpp.

◆ mimeTypeDetermined

void KRun::mimeTypeDetermined ( const QString mimeType)
protectedslot

Call this from subclasses when you have determined the MIME type.

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

Since
4.0.2

Definition at line 775 of file krun.cpp.

◆ processDesktopExec()

QStringList KRun::processDesktopExec ( const KService _service,
const QList< QUrl > &  _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 QProcess.
Deprecated:
since 5.0, use KIO::DesktopExecParser

Definition at line 237 of file krun.cpp.

◆ progressInfo()

bool KRun::progressInfo ( ) const
protected

Returns whether progress information are shown.

Definition at line 983 of file krun.cpp.

◆ run() [1/2]

bool KRun::run ( const KService service,
const QList< QUrl > &  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
Deprecated:
since 5.6. Since 5.71 use ApplicationLauncherJob, otherwise runApplication instead.
auto *job = new KIO::ApplicationLauncherJob(service);
job->setUrls(urls);
if (tempFiles) {
}
job->setSuggestedFileName(suggestedFileName);
job->setStartupId(asn);
job->start();

Definition at line 262 of file krun.cpp.

◆ run() [2/2]

bool KRun::run ( const QString exec,
const QList< QUrl > &  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
Deprecated:
since 5.71, use KIO::ApplicationLauncherJob with a temporary KService
KService::Ptr service(new KService(name, exec, icon));
auto *job = new KIO::ApplicationLauncherJob(service);
job->setUrls(urls);
job->setStartupId(asn);
job->start();

Definition at line 304 of file krun.cpp.

◆ runApplication()

qint64 KRun::runApplication ( const KService service,
const QList< QUrl > &  urls,
QWidget window,
RunFlags  flags = RunFlags(),
const QString suggestedFileName = QString(),
const QByteArray asn = QByteArray() 
)
static

Run an application (known from its .desktop file, i.e. as a KService).

If you need to wait for the application to register to D-Bus, use D-Bus activation instead.

If you don't need the prompt for asking the user whether to add the executable bit for desktop files or binaries that don't have it, you can use KIO::ApplicationLauncherJob from KIOGui directly.

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.
flagsvarious flags
suggestedFileNamesee setSuggestedFileName
asnApplication startup notification id, if any (otherwise "").
Returns
0 on error, the process ID on success
Since
5.24
Deprecated:
since 5.71, use ApplicationLauncherJob instead.
auto *job = new KIO::ApplicationLauncherJob(service);
job->setUrls(urls);
job->setSuggestedFileName(suggestedFileName);
job->setRunFlags(flags);
job->setStartupId(asn);
job->start();

Definition at line 271 of file krun.cpp.

◆ runCommand() [1/3]

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
Deprecated:
since 5.71, use KIO::CommandLauncherJob instead
auto *job = new KIO::CommandLauncherJob(cmd);
job->setWorkingDirectory(workingDirectory);
job->setExecutable(execName);
job->setIcon(icon);
job->setStartupId(asn);
job->start();

Definition at line 339 of file krun.cpp.

◆ runCommand() [2/3]

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
Deprecated:
since 5.71, use KIO::CommandLauncherJob
auto *job = new KIO::CommandLauncherJob(cmd);
job->setWorkingDirectory(workingDirectory);
job->setExecutable(execName);
job->setIcon(icon);
job->setStartupId(asn);
job->start();

Definition at line 332 of file krun.cpp.

◆ runCommand() [3/3]

bool KRun::runCommand ( const QString cmd,
QWidget window,
const QString workingDirectory = QString() 
)
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.

Parameters
cmdmust be a shell command. You must not append "&" to it, since the function will do that for you.
windowThe top-level widget of the app that invoked this object.
workingDirectorydirectory to use for relative paths, so that a command like "kwrite file.txt" finds file.txt from the right place
Returns
true on success, false on error
Deprecated:
since 5.71, use KIO::CommandLauncherJob
auto *job = new KIO::CommandLauncherJob(cmd);
job->setWorkingDirectory(workingDirectory);
job->start();

Definition at line 313 of file krun.cpp.

◆ runService()

qint64 KRun::runService ( const KService service,
const QList< QUrl > &  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).

Prefer runApplication(), unless you need to wait for the application to register to D-Bus before this method returns (but that should rather be done with D-Bus activation).

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
0 on error, the process ID on success
Since
5.6
Deprecated:
since 5.71, use ApplicationLauncherJob instead.
auto *job = new KIO::ApplicationLauncherJob(service);
job->setUrls(urls);
if (tempFiles) {
}
job->setSuggestedFileName(suggestedFileName);
job->setStartupId(asn);
job->start();

Definition at line 297 of file krun.cpp.

◆ runUrl() [1/2]

bool KRun::runUrl ( const QUrl 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
Deprecated:
since 5.31. Since 5.71 use OpenUrlJob, otherwise runUrl() with RunFlags.
auto *job = new KIO::OpenUrlJob(url, mimetype);
job->setSuggestedFileName(suggestedFileName);
job->setRunExecutables(runExecutables);
job->setDeleteTemporaryFile(...); // depending on the old RunFlags
job->setStartupId(asn);
job->start();

Definition at line 157 of file krun.cpp.

◆ runUrl() [2/2]

bool KRun::runUrl ( const QUrl url,
const QString mimetype,
QWidget window,
RunFlags  flags,
const QString suggestedFileName = QString(),
const QByteArray asn = QByteArray() 
)
static

Open the given URL.

This function can be used after the MIME type has been 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.
flagsVarious run flags.
suggestedFileNameSee setSuggestedFileName()
asnApplication startup notification id, if any (otherwise "").
Returns
true on success, false on error
Since
5.31
Deprecated:
since 5.71, use KIO::OpenUrlJob:
auto *job = new KIO::OpenUrlJob(url, mimetype);
job->setRunExecutables(runExecutables);
job->setDeleteTemporaryFile(...); // depending on the old RunFlags
job->setSuggestedFileName(suggestedFileName);
job->setStartupId(asn);
job->start();

Definition at line 176 of file krun.cpp.

◆ scanFile()

void KRun::scanFile ( )
protectedvirtual

Start scanning a file.

Reimplemented in KParts::BrowserRun.

Definition at line 612 of file krun.cpp.

◆ setAutoDelete()

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

◆ setDoScanFile()

void KRun::setDoScanFile ( bool  scanFile)
protected

Indicate that the next action is to scan the file.

Deprecated:
Since 4.1. Not useful in public API

Definition at line 1014 of file krun.cpp.

◆ setEnableExternalBrowser()

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

◆ setError()

void KRun::setError ( bool  error)
protected

Sets whether an error has occurred.

Definition at line 973 of file krun.cpp.

◆ setFinished()

void KRun::setFinished ( bool  finished)
protected

Marks this 'KRun' instance as finished.

Definition at line 988 of file krun.cpp.

◆ setFollowRedirections()

void KRun::setFollowRedirections ( bool  b)

Sets whether KRun should follow URLs redirections.

This is enabled by default

Parameters
bwhether to follow redirections or not.
Since
5.55

Definition at line 943 of file krun.cpp.

◆ setInitializeNextAction()

void KRun::setInitializeNextAction ( bool  initialize)
protected
Deprecated:
Since 4.1.

Not useful in public API

Definition at line 1040 of file krun.cpp.

◆ setIsDirecory()

void KRun::setIsDirecory ( bool  isDirectory)
protected

Sets whether it is a directory.

Deprecated:
Since 4.1. Typo in the name, and not useful as a public method

Definition at line 1028 of file krun.cpp.

◆ setJob()

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

Sets the job.

Definition at line 996 of file krun.cpp.

◆ setPreferredService()

void KRun::setPreferredService ( const QString desktopEntryName)

Set the preferred service for opening this URL, after its MIME type will have been found by KRun.

IMPORTANT: the service is only used if its configuration says it can handle this MIME type. 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 923 of file krun.cpp.

◆ setProgressInfo()

void KRun::setProgressInfo ( bool  progressInfo)
protected

Sets whether progress information shall be shown.

Definition at line 978 of file krun.cpp.

◆ setRunExecutables()

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

◆ setShowScriptExecutionPrompt()

void KRun::setShowScriptExecutionPrompt ( bool  showPrompt)

Sets whether a prompt should be shown before executing scripts or desktop files.

If enabled, KRun uses the "kiorc" configuration file to decide whether to open the file, execute it or show a prompt.

Since
5.4

Definition at line 938 of file krun.cpp.

◆ setSuggestedFileName()

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 MIME type 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 933 of file krun.cpp.

◆ setUrl()

void KRun::setUrl ( const QUrl url)
protected

Sets the url.

Definition at line 963 of file krun.cpp.

◆ shellQuote()

void KRun::shellQuote ( QString str)
static

Quotes a string for the shell.

An empty string will not be quoted.

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

Definition at line 225 of file krun.cpp.

◆ slotScanFinished

void KRun::slotScanFinished ( KJob job)
protectedslot

This slot is called when the scan job is finished.

Definition at line 755 of file krun.cpp.

◆ slotScanMimeType

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

◆ slotStatResult

void KRun::slotStatResult ( KJob job)
protectedvirtualslot

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

Definition at line 689 of file krun.cpp.

◆ slotTimeout

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

◆ suggestedFileName()

QString KRun::suggestedFileName ( ) const

Suggested file name given by the server (e.g. HTTP content-disposition)

Definition at line 948 of file krun.cpp.

◆ timer()

QTimer & KRun::timer ( )
protected

Returns the timer object.

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

Definition at line 1007 of file krun.cpp.

◆ url()

QUrl KRun::url ( ) const
protected

Returns the url.

Definition at line 968 of file krun.cpp.

◆ window()

QWidget * KRun::window ( ) const

Associated window, as passed to the constructor.

Since
4.9.3

Definition at line 875 of file krun.cpp.


The documentation for this class was generated from the following files:
KIO::Job * job()
Returns the job.
Definition: krun.cpp:1001
QString suggestedFileName() const
Suggested file name given by the server (e.g. HTTP content-disposition)
Definition: krun.cpp:948
QUrl url() const
Returns the url.
Definition: krun.cpp:968
ApplicationLauncherJob runs an application and watches it while running.
OpenUrlJob finds out the right way to "open" a URL. This includes finding out its MIME type,...
Definition: openurljob.h:41
QWidget * window() const
Associated window, as passed to the constructor.
Definition: krun.cpp:875
CommandLauncherJob runs a command and watches it while running.
void setUiDelegate(KJobUiDelegate *delegate)
@ DeleteTemporaryFiles
the URLs passed to the service will be deleted when it exits (if the URLs are local files)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Nov 28 2023 03:55:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.