krun.cpp
108 // We have up to two sources of data, for protocols not handled by kioslaves (so called "helper") :
113 // A) if the .protocol file says "launch an application", then the new-style handler-app has priority
119 const KService::Ptr service = KMimeTypeTrader::self()->preferredService(QLatin1String("x-scheme-handler/") + protocol);
121 return service->exec(); // for helper protocols, the handler app has priority over the hardcoded one (see A above)
170 bool KRun::runUrl(const QUrl &url, const QString &mimetype, QWidget *window, bool tempFile, bool runExecutables, const QString &suggestedFileName, const QByteArray &asn)
182 bool KRun::runUrl(const QUrl &u, const QString &_mimetype, QWidget *window, RunFlags flags, const QString &suggestedFileName, const QByteArray &asn)
190 i18n("<qt>Unable to enter <b>%1</b>.\nYou do not have access rights to this location.</qt>", u.toDisplayString().toHtmlEscaped()));
200 window, asn, u.adjusted(QUrl::RemoveFilename).toLocalFile())); // just execute the url as a command
226 i18n("<qt>You do not have permission to run <b>%1</b>.</qt>", u.toDisplayString().toHtmlEscaped()));
237 // As KDE on windows doesnt know about the windows default applications offers will be empty in nearly all cases.
243 // Hmm, in fact KOpenWithDialog::setServiceType already guesses the mimetype from the first URL of the list...
292 QStringList KRun::processDesktopExec(const KService &_service, const QList<QUrl> &_urls, bool tempFiles, const QString &suggestedFileName)
303 return removePath ? KIO::DesktopExecParser::executableName(execLine) : KIO::DesktopExecParser::executablePath(execLine);
307 static qint64 runCommandInternal(KProcess *proc, const KService *service, const QString &executable,
323 #if HAVE_X11 // Startup notification doesn't work with QT/E, service isn't needed without Startup notification
329 bool startup_notify = (asn != "0" && KRun::checkStartupNotify(QString() /*unused*/, service, &silent, &wmclass));
382 bool KRun::checkStartupNotify(const QString & /*binName*/, const KService *service, bool *silent_arg, QByteArray *wmclass_arg)
421 static qint64 runApplicationImpl(const KService &_service, const QList<QUrl> &_urls, QWidget *window,
484 return runCommandInternal(proc, &_service, KIO::DesktopExecParser::executablePath(_service.exec()),
597 qCWarning(KIO_WIDGETS) << "Unable to open replacement file for" << fileName << saveFile.errorString();
603 qCWarning(KIO_WIDGETS) << "Error occurred adding header for" << fileName << saveFile.errorString();
624 qCWarning(KIO_WIDGETS) << "Error committing changes to service" << fileName << saveFile.errorString();
637 qCWarning(KIO_WIDGETS) << "Unable to change permissions for" << fileName << desktopFile.errorString();
668 QPixmap warningIcon(KIconLoader::global()->loadIcon(QStringLiteral("dialog-warning"), KIconLoader::NoGroup, KIconLoader::SizeHuge));
786 bool useKToolInvocation = !(tempFiles || _service.entryPath().isEmpty() || !suggestedFileName.isEmpty());
802 return runApplicationImpl(_service, _urls, window, tempFiles ? RunFlags(DeleteTemporaryFiles) : RunFlags(), suggestedFileName, asn);
847 bool KRun::run(const QString &_exec, const QList<QUrl> &_urls, QWidget *window, const QString &_name,
872 bool KRun::runCommand(const QString &cmd, const QString &execName, const QString &iconName, QWidget *window, const QByteArray &asn)
934 const QString error = !d->m_strURL.isValid() ? d->m_strURL.errorString() : d->m_strURL.toString();
951 if (!d->m_externalBrowser.isEmpty() && d->m_strURL.scheme().startsWith(QLatin1String("http"))) {
981 // Unknown mimetype because the file is unreadable, no point in showing an open-with dialog (#261002)
1021 // No support for reading files either => we can't do anything (example: mailto URL, with no associated app)
1022 handleInitError(KIO::ERR_UNSUPPORTED_ACTION, i18n("Could not find any application or handler for %1", d->m_strURL.toDisplayString()));
1036 KIO::StatJob *job = KIO::stat(d->m_strURL, KIO::StatJob::SourceSide, 0 /* no details */, flags);
1096 KConfigGroup cfgGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), "Executable scripts");
1120 QString output = result == ExecutableFileOpenDialog::OpenFile ? QStringLiteral("open") : QStringLiteral("execute");
1121 KConfigGroup cfgGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), "Executable scripts");
1266 qCWarning(KIO_WIDGETS) << "get() didn't emit a mimetype! Probably a kioslave bug, please check the implementation of" << url().scheme();
1280 qCWarning(KIO_WIDGETS) << this << "ERROR (stat):" << job->error() << ' ' << job->errorString();
1347 } else if (mime.inherits(QStringLiteral("application/x-desktop")) && !d->m_localPath.isEmpty()) {
1351 if (!KRun::runUrl(d->m_strURL, type, d->m_window, false /*tempfile*/, d->m_runExecutables, d->m_suggestedFileName, d->m_asn)) {
1415 d->m_externalBrowser = KConfigGroup(KSharedConfig::openConfig(), "General").readEntry("BrowserApplication");
1558 KProcessRunner::KProcessRunner(KProcess *p, const QString &executable, const KStartupInfoId &id) :
static void resetStartupEnv()
KJOBWIDGETS_EXPORT void setWindow(KJob *job, QWidget *widget)
void setShellCommand(const QString &cmd)
void clear()
bool isReadable() const
QByteArray fileName(const QUrl &url) const
Converts the given URL into 8-bit form and retrieve the filename.
Definition: kremoteencoding.cpp:90
static KIOWIDGETS_DEPRECATED bool run(const KService &service, const QList< QUrl > &urls, QWidget *window, bool tempFiles=false, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
Open a list of URLs with a certain service (application).
Definition: krun.cpp:743
void setEnableExternalBrowser(bool b)
Sets whether the external webbrowser setting should be honoured.
Definition: krun.cpp:1412
static bool displayOpenWithDialog(const QList< QUrl > &lst, QWidget *window, bool tempFiles=false, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
Display the Open-With dialog for those URLs, and run the chosen application.
Definition: krun.cpp:251
QString & append(QChar ch)
QString toDisplayString(QFlags< QUrl::UrlFormattingOption > options) const
int width() const
static bool supportsReading(const QUrl &url)
Returns whether the protocol can retrieve data from URLs.
Definition: kprotocolmanager.cpp:1166
void slotTimeout()
All following protected slots are used by subclasses of KRun!
Definition: krun.cpp:1168
virtual void foundMimeType(const QString &type)
Called if the mimetype has been detected.
Definition: krun.cpp:1307
KIOWIDGETS_DEPRECATED void setDoScanFile(bool scanFile)
Indicate that the next action is to scan the file.
Definition: krun.cpp:1507
bool runOnDiscreteGpu() const
KIOWIDGETS_DEPRECATED void setIsDirecory(bool isDirectory)
Sets whether it is a directory.
Definition: krun.cpp:1521
QWidget * window() const
KIOWIDGETS_EXPORT bool runWithStartup(const QUrl &_url, bool _is_local, const QByteArray &asn)
Invokes the default action for the desktop entry.
Definition: kdesktopfileactions.cpp:65
static Ptr serviceByDesktopName(const QString &_name)
void setWindowModality(Qt::WindowModality windowModality)
QString errorString() const
QString & prepend(QChar ch)
virtual QString errorString() const
void setRunExecutables(bool b)
Sets whether executables, .desktop files or shell scripts should be run by KRun.
Definition: krun.cpp:1426
bool isValid() const
QStringList toStringList(const QList< QUrl > &urls, QFlags< QUrl::UrlFormattingOption > options)
void setPixmap(const QPixmap &)
static bool isExecutableFile(const QUrl &url, const QString &mimetype)
Returns whether the url of mimetype is executable.
Definition: krun.cpp:129
QVariant property(const QString &_name, QVariant::Type t) const
bool exec()
File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...
Definition: udsentry.h:211
static bool isProtocolInSupportedList(const QUrl &url, const QStringList &supportedProtocols)
Returns true if protocol is in the list of protocols returned by supportedProtocols().
Definition: desktopexecparser.cpp:203
bool contains(const QString &str, Qt::CaseSensitivity cs) const
bool isEmpty() const
bool isDefault() const
QString findExecutable(const QString &executableName, const QStringList &paths)
bool inherits(const QString &mimeTypeName) const
virtual int exec()
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
QString genericName() const
A KIO job that retrieves information about a file or directory.
Definition: statjob.h:37
static qint64 runService(const KService &service, const QList< QUrl > &urls, QWidget *window, bool tempFiles=false, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
Open a list of URLs with a certain service (application).
Definition: krun.cpp:770
A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...
Definition: udsentry.h:196
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
static bool KIOWIDGETS_DEPRECATED runUrl(const QUrl &url, const QString &mimetype, QWidget *window, bool tempFile=false, bool runExecutables=true, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
Open the given URL.
Definition: krun.cpp:170
virtual bool setPermissions(QFlags< QFileDevice::Permission > permissions)
bool exists() const
KGuiItem cont()
NoGroup
KIOWIDGETS_DEPRECATED bool initializeNextAction() const
Definition: krun.cpp:1540
void setBin(const QString &bin)
static bool checkStartupNotify(const QString &binName, const KService *service, bool *silent_arg, QByteArray *wmclass_arg)
Definition: krun.cpp:382
void setName(const QString &name)
bool isApplication() const
void setSuggestedFileName(const QString &suggestedFileName)
Sets the file name to use in the case of downloading the file to a tempfile in order to give to a non...
Definition: desktopexecparser.cpp:252
QString exec() const
void slotScanMimeType(KIO::Job *, const QString &type)
This slot is called when the scan job has found out the mime type.
Definition: krun.cpp:1263
static void add(const QUrl &url)
Add a new item to the Recent Document menu.
Definition: krecentdocument.cpp:87
static KIOWIDGETS_DEPRECATED QStringList processDesktopExec(const KService &_service, const QList< QUrl > &_urls, bool tempFiles=false, const QString &suggestedFileName=QString())
Processes a Exec= line as found in .desktop files.
Definition: krun.cpp:292
static bool isAuthorizedDesktopFile(const QString &path)
QString path() const
qint64 peek(char *data, qint64 maxSize)
size
static bool sendChange(const KStartupInfoId &id, const KStartupInfoData &data)
QStringList resultingArguments() const
Definition: desktopexecparser.cpp:266
static int currentDesktop()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
int count(const T &value) const
void append(const T &value)
the URLs passed to the service will be deleted when it exits (if the URLs are local files) ...
Definition: krun.h:236
void setDescription(const QString &descr)
static bool sendStartup(const KStartupInfoId &id, const KStartupInfoData &data)
QString entryPath() const
static bool isExecutable(const QString &serviceType)
Returns whether serviceType refers to an executable program instead of a data file.
Definition: krun.cpp:1446
QWidget * topLevelWidget() const
bool commit()
long long numberValue(uint field, long long defaultValue=0) const
Definition: udsentry.cpp:119
QMimeType mimeTypeForUrl(const QUrl &url) const
void setIcon(const QString &icon)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setEnv(const QString &name, const QString &value, bool overwrite=true)
void setFocus()
static QString defaultMimetype(const QUrl &url)
Returns default mimetype for this URL based on the protocol.
Definition: kprotocolmanager.cpp:1296
bool isEmpty() const
static bool supportsListing(const QUrl &url)
Returns whether the protocol can list files/objects.
Definition: kprotocolmanager.cpp:1146
const QString & name() const
bool isEmpty() const
void setSilent(TriState state)
KService::Ptr preferredService(const QString &mimeType, const QString &genericServiceType=QStringLiteral("Application"))
virtual void slotStatResult(KJob *)
This slot is called when the 'stat' job has finished.
Definition: krun.cpp:1206
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KIOCORE_EXPORT QString buildErrorString(int errorCode, const QString &errorText)
Returns a translated error message for errorCode using the additional error information provided by e...
Definition: job_error.cpp:33
QByteArray readAll()
void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
QUrl mostLocalUrl() const
most local URL Call this in the slot connected to result, and only after making sure no error happene...
Definition: statjob.cpp:98
virtual void handleInitError(int kioErrorCode, const QString &errorMsg)
Called when KRun detects an error during the init phase.
Definition: krun.cpp:151
static KMimeTypeTrader * self()
KIOWIDGETS_DEPRECATED bool doScanFile() const
Returns whether the file shall be scanned.
Definition: krun.cpp:1514
static QStringList supportedProtocols(const KService &service)
Returns the list of protocols which the application supports.
Definition: desktopexecparser.cpp:174
void 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...
Definition: krun.cpp:1431
WId winId() const
void deleteLater()
void setHostname(const QByteArray &hostname=QByteArray())
T & first()
void slotScanFinished(KJob *)
This slot is called when the scan job is finished.
Definition: krun.cpp:1272
static QString protocolClass(const QString &protocol)
Returns the protocol class for the specified protocol.
Definition: kprotocolinfo.cpp:329
void setUrlsAreTempFiles(bool tempFiles)
If tempFiles is set to true and the urls given to the constructor are local files, they will be deleted when the application exits.
Definition: desktopexecparser.cpp:247
static int startServiceByDesktopPath(const QString &_name, const QString &URL, QString *error=nullptr, QString *serviceName=nullptr, int *pid=nullptr, const QByteArray &startup_id=QByteArray(), bool noWait=false)
KCOREADDONS_EXPORT QStringList splitArgs(const QString &cmd, Options flags=NoOptions, Errors *err=nullptr)
KJobUiDelegate * uiDelegate() const
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QString scheme() const
static KIconLoader * global()
QMimeType mimeTypeForName(const QString &nameOrAlias) const
void setApplicationId(const QString &desktop)
bool allowMultipleFiles() const
static void ensureKdeinitRunning()
QString toLocalFile() const
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
Get (means: read).
Definition: transferjob.cpp:485
iterator end()
void mimeTypeDetermined(const QString &mimeType)
Call this from subclasses when you have determined the mimetype.
Definition: krun.cpp:1292
QWidget * screen(int screen)
KCOREADDONS_EXPORT QString quoteArg(const QString &arg)
QString icon() const
QString toHtmlEscaped() const
void setWorkingDirectory(const QString &dir)
static bool sendFinish(const KStartupInfoId &id)
static QString exec(const QString &protocol)
Returns the library / executable to open for the protocol protocol Example : "kio_ftp", meaning either the executable "kio_ftp" or the library "kio_ftp.la" (recommended), whichever is available.
Definition: kprotocolinfo.cpp:300
SizeHuge
QString i18n(const char *text, const TYPE &arg...)
QString & replace(int position, int n, QChar after)
Whether to run URLs that are executable scripts or binaries.
Definition: krun.h:237
virtual void handleError(KJob *job)
Called when a KIO job started by KRun gives an error.
Definition: krun.cpp:159
int startTimer(int interval, Qt::TimerType timerType)
void setReadOnly(bool ro)
void cancelWriting()
KIOWIDGETS_DEPRECATED void setInitializeNextAction(bool initialize)
Definition: krun.cpp:1533
void setPreferredService(const QString &desktopEntryName)
Set the preferred service for opening this URL, after its mimetype will have been found by KRun...
Definition: krun.cpp:1421
void setWMClass(const QByteArray &wmclass)
QByteArray toLatin1() const
QString mid(int position, int n) const
QString suggestedFileName() const
Suggested file name given by the server (e.g.
Definition: krun.cpp:1441
virtual void showErrorMessage()
QUrl adjusted(QFlags< QUrl::UrlFormattingOption > options) const
static QByteArray createNewStartupId()
void setStandardButtons(QFlags< QDialogButtonBox::StandardButton > buttons)
QDesktopWidget * desktop()
QString desktopEntryName() const
static qint64 runApplication(const KService &service, const QList< QUrl > &urls, QWidget *window, RunFlags flags=RunFlags(), const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
Run an application (known from its .desktop file, i.e.
Definition: krun.cpp:749
void addStretch(int stretch)
static QString executablePath(const QString &execLine)
Given a full command line (e.g.
Definition: desktopexecparser.cpp:440
static bool isHelperProtocol(const QUrl &url)
Returns whether the protocol can act as a helper protocol.
Definition: kprotocolinfo.cpp:393
virtual void close()
void setFinished(bool finished)
Marks this 'KRun' instance as finished.
Definition: krun.cpp:1481
int height() const
virtual void init()
All following protected methods are used by subclasses of KRun!
Definition: krun.cpp:930
bool toBool() const
virtual void showEvent(QShowEvent *event)
QString localHostName()
qint64 write(const char *data, qint64 maxSize)
bool isValid() const
QPushButton * button(StandardButton which) const
KIOCORE_EXPORT StatJob * mostLocalUrl(const QUrl &url, JobFlags flags=DefaultFlags)
Tries to map a local URL for the given URL, using a KIO job.
Definition: statjob.cpp:183
A mime type; the slave should set it if it's known.
Definition: udsentry.h:222
KIOCORE_EXPORT StatJob * stat(const QUrl &url, JobFlags flags=DefaultFlags)
Find all details for one file or directory.
Definition: statjob.cpp:177
Parses the Exec= line from a .desktop file, and process all the '%' placeholders, e...
Definition: desktopexecparser.h:48
KRun(const QUrl &url, QWidget *window, bool showProgressInfo=true, const QByteArray &asn=QByteArray())
Definition: krun.cpp:894
The transfer job pumps data into and/or out of a Slave.
Definition: transferjob.h:38
void setProgressInfo(bool progressInfo)
Sets whether progress information shall be shown.
Definition: krun.cpp:1471
virtual Permissions permissions() const
bool openUrl(const QUrl &url)
static void publishSlaveOnHold()
Send the slave that was put on hold back to KLauncher.
Definition: scheduler.cpp:836
int size() const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setPlainText(const QString &text)
void setDesktop(int desktop)
void initId(const QByteArray &id="")
QString name() const
void setDefault(bool)
QString toString() const
T readEntry(const QString &key, const T &aDefault) const
QString name() const
QString platformName()
void addPid(pid_t pid)
static QString binaryName(const QString &execLine, bool removePath)
Given a full command line (e.g.
Definition: krun.cpp:301
iterator begin()
static KIOWIDGETS_DEPRECATED void shellQuote(QString &str)
Quotes a string for the shell.
Definition: krun.cpp:281
void setShowScriptExecutionPrompt(bool showPrompt)
Sets whether a prompt should be shown before executing scripts or desktop files.
Definition: krun.cpp:1436
static bool hasSchemeHandler(const QUrl &url)
Returns true if protocol should be opened by a "handler" application, i.e.
Definition: desktopexecparser.cpp:211
QUrl fromLocalFile(const QString &localFile)
void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
void addLayout(QLayout *layout, int stretch)
static QString executableName(const QString &execLine)
Given a full command line (e.g.
Definition: desktopexecparser.cpp:433
void setLaunchedBy(WId window)
bool authorizeUrlAction(const QString &action, const QUrl &baseURL, const QUrl &destURL)
Returns whether a certain URL related action is authorized.
Definition: kurlauthorized.cpp:37
int error() const
static Ptr serviceByStorageId(const QString &_storageId)
static bool runCommand(const QString &cmd, QWidget *window, const QString &workingDirectory=QString())
Run the given shell command and notifies KDE of the starting of the application.
Definition: krun.cpp:855
void setFileName(const QString &name)
bool isLocalFile() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2018 The KDE developers.
Generated on Sat Jan 6 2018 05:28:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2018 The KDE developers.
Generated on Sat Jan 6 2018 05:28:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.