KIO

krun.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2000 Torben Weis <[email protected]>
4  SPDX-FileCopyrightText: 2006 David Faure <[email protected]>
5  SPDX-FileCopyrightText: 2009 Michael Pyne <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "krun.h"
11 
12 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71)
13 #include "krun_p.h"
14 #include "kio_widgets_debug.h"
15 
16 #include <assert.h>
17 #include <string.h>
18 #include <typeinfo>
19 #include <qplatformdefs.h>
20 
21 #include <QDialog>
22 #include <QDialogButtonBox>
23 #include <QWidget>
24 #include <QApplication>
25 #include <QDesktopWidget>
26 #include <QMimeDatabase>
27 #include <QDebug>
28 #include <QHostInfo>
29 #include <QDesktopServices>
30 
31 #include <KIconLoader>
32 #include <KJobUiDelegate>
33 #include <KApplicationTrader>
34 #include "kio/job.h"
35 #include "kio/global.h"
36 #include "kio/scheduler.h"
37 #include "kopenwithdialog.h"
38 #include "krecentdocument.h"
39 #include "kdesktopfileactions.h"
40 #include <kio/desktopexecparser.h>
41 #include "kprocessrunner_p.h" // for KIOGuiPrivate::checkStartupNotify
42 #include "applicationlauncherjob.h"
43 #include "jobuidelegate.h"
44 #include "widgetsuntrustedprogramhandler.h"
45 
46 #include <kurlauthorized.h>
47 #include <KMessageBox>
48 #include <KLocalizedString>
49 #include <kprotocolmanager.h>
50 #include <KProcess>
51 #include <KJobWidgets>
52 #include <KSharedConfig>
53 #include <commandlauncherjob.h>
54 
55 #include <QFile>
56 #include <QFileInfo>
57 #include <KDesktopFile>
58 #include <KShell>
59 #include <KConfigGroup>
60 #include <KStandardGuiItem>
61 #include <KGuiItem>
62 
63 #include <KIO/OpenUrlJob>
64 #include <QStandardPaths>
65 #include <KIO/JobUiDelegate>
66 
67 #ifdef Q_OS_WIN
68 #include "widgetsopenwithhandler_win.cpp" // displayNativeOpenWithDialog
69 #endif
70 
71 KRunPrivate::KRunPrivate(KRun *parent)
72  : q(parent),
73  m_showingDialog(false)
74 {
75 }
76 
77 void KRunPrivate::startTimer()
78 {
79  m_timer->start(0);
80 }
81 
82 // ---------------------------------------------------------------------------
83 
84 
85 static KService::Ptr schemeService(const QString &protocol)
86 {
87  return KApplicationTrader::preferredService(QLatin1String("x-scheme-handler/") + protocol);
88 }
89 
90 static bool checkNeedPortalSupport()
91 {
93  QLatin1String("flatpak-info")).isEmpty() ||
94  qEnvironmentVariableIsSet("SNAP");
95 }
96 
97 qint64 KRunPrivate::runCommandLauncherJob(KIO::CommandLauncherJob *job, QWidget *widget)
98 {
99  QObject *receiver = widget ? static_cast<QObject *>(widget) : static_cast<QObject *>(qApp);
100  QObject::connect(job, &KJob::result, receiver, [widget](KJob *job) {
101  if (job->error()) {
102  QEventLoopLocker locker;
103  KMessageBox::sorry(widget, job->errorString());
104  }
105  });
106  job->start();
107  job->waitForStarted();
108  return job->error() ? 0 : job->pid();
109 }
110 
111 // ---------------------------------------------------------------------------
112 
113 // Helper function that returns whether a file has the execute bit set or not.
114 static bool hasExecuteBit(const QString &fileName)
115 {
116  QFileInfo file(fileName);
117  return file.isExecutable();
118 }
119 
120 bool KRun::isExecutableFile(const QUrl &url, const QString &mimetype)
121 {
122  if (!url.isLocalFile()) {
123  return false;
124  }
125 
126  // While isExecutable performs similar check to this one, some users depend on
127  // this method not returning true for application/x-desktop
128  QMimeDatabase db;
129  QMimeType mimeType = db.mimeTypeForName(mimetype);
130  if (!mimeType.inherits(QStringLiteral("application/x-executable"))
131  && !mimeType.inherits(QStringLiteral("application/x-ms-dos-executable"))
132  && !mimeType.inherits(QStringLiteral("application/x-executable-script"))
133  && !mimeType.inherits(QStringLiteral("application/x-sharedlib"))) {
134  return false;
135  }
136 
137  if (!hasExecuteBit(url.toLocalFile()) && !mimeType.inherits(QStringLiteral("application/x-ms-dos-executable"))) {
138  return false;
139  }
140 
141  return true;
142 }
143 
144 void KRun::handleInitError(int kioErrorCode, const QString &errorMsg)
145 {
146  Q_UNUSED(kioErrorCode);
147  d->m_showingDialog = true;
148  KMessageBox::error(d->m_window, errorMsg);
149  d->m_showingDialog = false;
150 }
151 
153 {
154  Q_ASSERT(job);
155  if (job) {
156  d->m_showingDialog = true;
157  job->uiDelegate()->showErrorMessage();
158  d->m_showingDialog = false;
159  }
160 }
161 
162 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 31)
163 bool KRun::runUrl(const QUrl &url, const QString &mimetype, QWidget *window, bool tempFile, bool runExecutables, const QString &suggestedFileName, const QByteArray &asn)
164 {
165  RunFlags flags = tempFile ? KRun::DeleteTemporaryFiles : RunFlags();
166  if (runExecutables) {
167  flags |= KRun::RunExecutables;
168  }
169 
170  return runUrl(url, mimetype, window, flags, suggestedFileName, asn);
171 }
172 #endif
173 
174 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71)
175 // This is called by foundMimeType, since it knows the mimetype of the URL
176 bool KRun::runUrl(const QUrl &u, const QString &_mimetype, QWidget *window, RunFlags flags, const QString &suggestedFileName, const QByteArray &asn)
177 {
178  const bool runExecutables = flags.testFlag(KRun::RunExecutables);
179  const bool tempFile = flags.testFlag(KRun::DeleteTemporaryFiles);
180 
181  KIO::OpenUrlJob *job = new KIO::OpenUrlJob(u, _mimetype);
182  job->setSuggestedFileName(suggestedFileName);
183  job->setStartupId(asn);
185  job->setDeleteTemporaryFile(tempFile);
186  job->setRunExecutables(runExecutables);
187  job->start();
188  return true;
189 }
190 #endif
191 
192 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71)
193 bool KRun::displayOpenWithDialog(const QList<QUrl> &lst, QWidget *window, bool tempFiles,
194  const QString &suggestedFileName, const QByteArray &asn)
195 {
196  if (!KAuthorized::authorizeAction(QStringLiteral("openwith"))) {
197  KMessageBox::sorry(window,
198  i18n("You are not authorized to select an application to open this file."));
199  return false;
200  }
201 
202 #ifdef Q_OS_WIN
203  KConfigGroup cfgGroup(KSharedConfig::openConfig(), QStringLiteral("KOpenWithDialog Settings"));
204  if (cfgGroup.readEntry("Native", true)) {
205  return displayNativeOpenWithDialog(lst, window);
206  }
207 #endif
208 
209  // TODO : pass the mimetype as a parameter, to show it (comment field) in the dialog !
210  // Note KOpenWithDialog::setMimeTypeFromUrls already guesses the mimetype if lst.size() == 1
211  KOpenWithDialog dialog(lst, QString(), QString(), window);
213  if (dialog.exec()) {
214  KService::Ptr service = dialog.service();
215  if (!service) {
216  //qDebug() << "No service set, running " << dialog.text();
217  service = KService::Ptr(new KService(QString() /*name*/, dialog.text(), QString() /*icon*/));
218  }
219  const RunFlags flags = tempFiles ? KRun::DeleteTemporaryFiles : RunFlags();
220  return KRun::runApplication(*service, lst, window, flags, suggestedFileName, asn);
221  }
222  return false;
223 }
224 #endif
225 
226 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 0)
228 {
229  // Credits to Walter, says Bernd G. :)
230  if (_str.isEmpty()) { // Don't create an explicit empty parameter
231  return;
232  }
233  const QChar q = QLatin1Char('\'');
234  _str.replace(q, QLatin1String("'\\''")).prepend(q).append(q);
235 }
236 #endif
237 
238 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 0)
239 QStringList KRun::processDesktopExec(const KService &_service, const QList<QUrl> &_urls, bool tempFiles, const QString &suggestedFileName)
240 {
241  KIO::DesktopExecParser parser(_service, _urls);
242  parser.setUrlsAreTempFiles(tempFiles);
243  parser.setSuggestedFileName(suggestedFileName);
244  return parser.resultingArguments();
245 }
246 #endif
247 
248 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 0)
249 QString KRun::binaryName(const QString &execLine, bool removePath)
250 {
251  return removePath ? KIO::DesktopExecParser::executableName(execLine) : KIO::DesktopExecParser::executablePath(execLine);
252 }
253 #endif
254 
255 // This code is also used in klauncher.
256 // TODO: port klauncher to KIOGuiPrivate::checkStartupNotify once this lands
257 // TODO: then deprecate this method, and remove in KF6
258 bool KRun::checkStartupNotify(const QString & /*binName*/, const KService *service, bool *silent_arg, QByteArray *wmclass_arg)
259 {
260  return KIOGuiPrivate::checkStartupNotify(service, silent_arg, wmclass_arg);
261 }
262 
263 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 6)
264 bool KRun::run(const KService &_service, const QList<QUrl> &_urls, QWidget *window,
265  bool tempFiles, const QString &suggestedFileName, const QByteArray &asn)
266 {
267  const RunFlags flags = tempFiles ? KRun::DeleteTemporaryFiles : RunFlags();
268  return runApplication(_service, _urls, window, flags, suggestedFileName, asn) != 0;
269 }
270 #endif
271 
272 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71)
273 qint64 KRun::runApplication(const KService &service, const QList<QUrl> &urls, QWidget *window,
274  RunFlags flags, const QString &suggestedFileName,
275  const QByteArray &asn)
276 {
277  KService::Ptr servicePtr(new KService(service)); // clone
278  // QTBUG-59017 Calling winId() on an embedded widget will break interaction
279  // with it on high-dpi multi-screen setups (cf. also Bug 363548), hence using
280  // its parent window instead
281  if (window) {
282  window = window->window();
283  }
284 
286  job->setUrls(urls);
287  if (flags & DeleteTemporaryFiles) {
289  }
290  job->setSuggestedFileName(suggestedFileName);
291  job->setStartupId(asn);
293  job->start();
294  job->waitForStarted();
295  return job->error() ? 0 : job->pid();
296 }
297 #endif
298 
299 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71)
300 qint64 KRun::runService(const KService &_service, const QList<QUrl> &_urls, QWidget *window,
301  bool tempFiles, const QString &suggestedFileName, const QByteArray &asn)
302 {
303  return runApplication(_service,
304  _urls,
305  window,
306  tempFiles ? RunFlags(DeleteTemporaryFiles) : RunFlags(),
307  suggestedFileName,
308  asn);
309 }
310 #endif
311 
312 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71)
313 bool KRun::run(const QString &_exec, const QList<QUrl> &_urls, QWidget *window, const QString &_name,
314  const QString &_icon, const QByteArray &asn)
315 {
316  KService::Ptr service(new KService(_name, _exec, _icon));
317 
318  return runApplication(*service, _urls, window, RunFlags{}, QString(), asn);
319 }
320 #endif
321 
322 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71)
323 bool KRun::runCommand(const QString &cmd, QWidget *window, const QString &workingDirectory)
324 {
325  if (cmd.isEmpty()) {
326  qCWarning(KIO_WIDGETS) << "Command was empty, nothing to run";
327  return false;
328  }
329 
330  const QStringList args = KShell::splitArgs(cmd);
331  if (args.isEmpty()) {
332  qCWarning(KIO_WIDGETS) << "Command could not be parsed.";
333  return false;
334  }
335 
336  const QString &bin = args.first();
337  return KRun::runCommand(cmd, bin, bin /*iconName*/, window, QByteArray(), workingDirectory);
338 }
339 #endif
340 
341 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71)
342 bool KRun::runCommand(const QString &cmd, const QString &execName, const QString &iconName, QWidget *window, const QByteArray &asn)
343 {
344  return runCommand(cmd, execName, iconName, window, asn, QString());
345 }
346 #endif
347 
348 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(5, 71)
349 bool KRun::runCommand(const QString &cmd, const QString &execName, const QString &iconName,
350  QWidget *window, const QByteArray &asn, const QString &workingDirectory)
351 {
352  auto *job = new KIO::CommandLauncherJob(cmd);
353  job->setExecutable(execName);
354  job->setIcon(iconName);
355  job->setStartupId(asn);
356  job->setWorkingDirectory(workingDirectory);
357 
358  if (window) {
359  window = window->window();
360  }
361  return KRunPrivate::runCommandLauncherJob(job, window);
362 }
363 #endif
364 
365 KRun::KRun(const QUrl &url, QWidget *window,
366  bool showProgressInfo, const QByteArray &asn)
367  : d(new KRunPrivate(this))
368 {
369  d->m_timer = new QTimer(this);
370  d->m_timer->setObjectName(QStringLiteral("KRun::timer"));
371  d->m_timer->setSingleShot(true);
372  d->init(url, window, showProgressInfo, asn);
373 }
374 
375 void KRunPrivate::init(const QUrl &url, QWidget *window,
376  bool showProgressInfo, const QByteArray &asn)
377 {
378  m_bFault = false;
379  m_bAutoDelete = true;
380  m_bProgressInfo = showProgressInfo;
381  m_bFinished = false;
382  m_job = nullptr;
383  m_strURL = url;
384  m_bScanFile = false;
385  m_bIsDirectory = false;
386  m_runExecutables = true;
387  m_followRedirections = true;
388  m_window = window;
389  m_asn = asn;
390  q->setEnableExternalBrowser(true);
391 
392  // Start the timer. This means we will return to the event
393  // loop and do initialization afterwards.
394  // Reason: We must complete the constructor before we do anything else.
395  m_bCheckPrompt = false;
396  m_bInit = true;
397  q->connect(m_timer, &QTimer::timeout, q, &KRun::slotTimeout);
398  startTimer();
399  //qDebug() << "new KRun" << q << url << "timer=" << m_timer;
400 }
401 
403 {
404  //qDebug() << "INIT called";
405  if (!d->m_strURL.isValid() || d->m_strURL.scheme().isEmpty()) {
406  const QString error = !d->m_strURL.isValid() ? d->m_strURL.errorString() : d->m_strURL.toString();
407  handleInitError(KIO::ERR_MALFORMED_URL, i18n("Malformed URL\n%1", error));
408  qCWarning(KIO_WIDGETS) << "Malformed URL:" << error;
409  d->m_bFault = true;
410  d->m_bFinished = true;
411  d->startTimer();
412  return;
413  }
414  if (!KUrlAuthorized::authorizeUrlAction(QStringLiteral("open"), QUrl(), d->m_strURL)) {
415  QString msg = KIO::buildErrorString(KIO::ERR_ACCESS_DENIED, d->m_strURL.toDisplayString());
416  handleInitError(KIO::ERR_ACCESS_DENIED, msg);
417  d->m_bFault = true;
418  d->m_bFinished = true;
419  d->startTimer();
420  return;
421  }
422 
423  if (d->m_externalBrowserEnabled && checkNeedPortalSupport()) {
424  // use the function from QDesktopServices as it handles portals correctly
425  d->m_bFault = !QDesktopServices::openUrl(d->m_strURL);
426  d->m_bFinished = true;
427  d->startTimer();
428  return;
429  }
430 
431  if (!d->m_externalBrowser.isEmpty() && d->m_strURL.scheme().startsWith(QLatin1String("http"))) {
432  if (d->runExternalBrowser(d->m_externalBrowser)) {
433  return;
434  }
435  } else if (d->m_strURL.isLocalFile() &&
436  (d->m_strURL.host().isEmpty() ||
437  (d->m_strURL.host() == QLatin1String("localhost")) ||
438  (d->m_strURL.host().compare(QHostInfo::localHostName(), Qt::CaseInsensitive) == 0))) {
439  const QString localPath = d->m_strURL.toLocalFile();
440  if (!QFile::exists(localPath)) {
441  handleInitError(KIO::ERR_DOES_NOT_EXIST,
442  i18n("<qt>Unable to run the command specified. "
443  "The file or folder <b>%1</b> does not exist.</qt>",
444  localPath.toHtmlEscaped()));
445  d->m_bFault = true;
446  d->m_bFinished = true;
447  d->startTimer();
448  return;
449  }
450 
451  QMimeDatabase db;
452  QMimeType mime = db.mimeTypeForUrl(d->m_strURL);
453  //qDebug() << "MIME TYPE is " << mime.name();
454  if (mime.isDefault() && !QFileInfo(localPath).isReadable()) {
455  // Unknown mimetype because the file is unreadable, no point in showing an open-with dialog (#261002)
456  const QString msg = KIO::buildErrorString(KIO::ERR_ACCESS_DENIED, localPath);
457  handleInitError(KIO::ERR_ACCESS_DENIED, msg);
458  d->m_bFault = true;
459  d->m_bFinished = true;
460  d->startTimer();
461  return;
462  } else {
463  mimeTypeDetermined(mime.name());
464  return;
465  }
466  } else if (KIO::DesktopExecParser::hasSchemeHandler(d->m_strURL)) {
467  // looks for an application associated with x-scheme-handler/<protocol>
468  const KService::Ptr service = schemeService(d->m_strURL.scheme());
469  if (service) {
470  // if there's one...
471  if (runApplication(*service, QList<QUrl>() << d->m_strURL, d->m_window, RunFlags{}, QString(), d->m_asn)) {
472  d->m_bFinished = true;
473  d->startTimer();
474  return;
475  }
476  } else {
477  // fallback, look for associated helper protocol
478  Q_ASSERT(KProtocolInfo::isHelperProtocol(d->m_strURL.scheme()));
479  const auto exec = KProtocolInfo::exec(d->m_strURL.scheme());
480  if (exec.isEmpty()) {
481  // use default mimetype opener for file
483  return;
484  } else {
485  if (run(exec, QList<QUrl>() << d->m_strURL, d->m_window, QString(), QString(), d->m_asn)) {
486  d->m_bFinished = true;
487  d->startTimer();
488  return;
489  }
490  }
491  }
492 
493  }
494 
495 #if 0 // removed for KF5 (for portability). Reintroduce a bool or flag if useful.
496  // Did we already get the information that it is a directory ?
497  if ((d->m_mode & QT_STAT_MASK) == QT_STAT_DIR) {
498  mimeTypeDetermined("inode/directory");
499  return;
500  }
501 #endif
502 
503  // Let's see whether it is a directory
504 
505  if (!KProtocolManager::supportsListing(d->m_strURL)) {
506  // No support for listing => it can't be a directory (example: http)
507 
508  if (!KProtocolManager::supportsReading(d->m_strURL)) {
509  // No support for reading files either => we can't do anything (example: mailto URL, with no associated app)
510  handleInitError(KIO::ERR_UNSUPPORTED_ACTION, i18n("Could not find any application or handler for %1", d->m_strURL.toDisplayString()));
511  d->m_bFault = true;
512  d->m_bFinished = true;
513  d->startTimer();
514  return;
515  }
516  scanFile();
517  return;
518  }
519 
520  //qDebug() << "Testing directory (stating)";
521 
522  // It may be a directory or a file, let's stat
523  KIO::JobFlags flags = d->m_bProgressInfo ? KIO::DefaultFlags : KIO::HideProgressInfo;
524  KIO::StatJob *job = KIO::statDetails(d->m_strURL, KIO::StatJob::SourceSide, KIO::StatBasic, flags);
525  KJobWidgets::setWindow(job, d->m_window);
526  connect(job, &KJob::result,
527  this, &KRun::slotStatResult);
528  d->m_job = job;
529  //qDebug() << "Job" << job << "is about stating" << d->m_strURL;
530 }
531 
533 {
534  //qDebug() << this;
535  d->m_timer->stop();
536  killJob();
537  //qDebug() << this << "done";
538  delete d;
539 }
540 
541 bool KRunPrivate::runExternalBrowser(const QString &_exec)
542 {
543  QList<QUrl> urls;
544  urls.append(m_strURL);
545  if (_exec.startsWith(QLatin1Char('!'))) {
546  // Literal command
547  const QString exec = _exec.midRef(1) + QLatin1String(" %u");
548  if (KRun::run(exec, urls, m_window, QString(), QString(), m_asn)) {
549  m_bFinished = true;
550  startTimer();
551  return true;
552  }
553  } else {
555  if (service && KRun::runApplication(*service, urls, m_window, KRun::RunFlags{}, QString(), m_asn)) {
556  m_bFinished = true;
557  startTimer();
558  return true;
559  }
560  }
561  return false;
562 }
563 
564 void KRunPrivate::showPrompt()
565 {
566  ExecutableFileOpenDialog *dialog = new ExecutableFileOpenDialog(promptMode(), q->window());
567  dialog->setAttribute(Qt::WA_DeleteOnClose);
568  QObject::connect(dialog, &ExecutableFileOpenDialog::finished, q, [this, dialog](int result){
569  onDialogFinished(result, dialog->isDontAskAgainChecked());
570  });
571  dialog->show();
572 }
573 
574 bool KRunPrivate::isPromptNeeded()
575 {
576  if (m_strURL == QUrl(QStringLiteral("remote:/x-wizard_service.desktop"))) {
577  return false;
578  }
579  const QMimeDatabase db;
580  const QMimeType mime = db.mimeTypeForUrl(m_strURL);
581 
582  const bool isFileExecutable = (KRun::isExecutableFile(m_strURL, mime.name()) ||
583  mime.inherits(QStringLiteral("application/x-desktop")));
584 
585  if (isFileExecutable) {
586  KConfigGroup cfgGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), "Executable scripts");
587  const QString value = cfgGroup.readEntry("behaviourOnLaunch", "alwaysAsk");
588 
589  if (value == QLatin1String("alwaysAsk")) {
590  return true;
591  } else {
592  q->setRunExecutables(value == QLatin1String("execute"));
593  }
594  }
595 
596  return false;
597 }
598 
599 ExecutableFileOpenDialog::Mode KRunPrivate::promptMode()
600 {
601  const QMimeDatabase db;
602  const QMimeType mime = db.mimeTypeForUrl(m_strURL);
603 
604  if (mime.inherits(QStringLiteral("text/plain"))) {
605  return ExecutableFileOpenDialog::OpenOrExecute;
606  }
607 #ifndef Q_OS_WIN
608  if (mime.inherits(QStringLiteral("application/x-ms-dos-executable"))) {
609  return ExecutableFileOpenDialog::OpenAsExecute;
610  }
611 #endif
612  return ExecutableFileOpenDialog::OnlyExecute;
613 }
614 
615 void KRunPrivate::onDialogFinished(int result, bool isDontAskAgainSet)
616 {
617  if (result == ExecutableFileOpenDialog::Rejected) {
618  m_bFinished = true;
619  m_bInit = false;
620  startTimer();
621  return;
622  }
623  q->setRunExecutables(result == ExecutableFileOpenDialog::ExecuteFile);
624 
625  if (isDontAskAgainSet) {
626  QString output = result == ExecutableFileOpenDialog::OpenFile ? QStringLiteral("open") : QStringLiteral("execute");
627  KConfigGroup cfgGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), "Executable scripts");
628  cfgGroup.writeEntry("behaviourOnLaunch", output);
629  }
630  startTimer();
631 }
632 
634 {
635  //qDebug() << d->m_strURL;
636  // First, let's check for well-known extensions
637  // Not when there is a query in the URL, in any case.
638  if (!d->m_strURL.hasQuery()) {
639  QMimeDatabase db;
640  QMimeType mime = db.mimeTypeForUrl(d->m_strURL);
641  if (!mime.isDefault() || d->m_strURL.isLocalFile()) {
642  //qDebug() << "Scanfile: MIME TYPE is " << mime.name();
643  mimeTypeDetermined(mime.name());
644  return;
645  }
646  }
647 
648  // No mimetype found, and the URL is not local (or fast mode not allowed).
649  // We need to apply the 'KIO' method, i.e. either asking the server or
650  // getting some data out of the file, to know what mimetype it is.
651 
652  if (!KProtocolManager::supportsReading(d->m_strURL)) {
653  qCWarning(KIO_WIDGETS) << "#### NO SUPPORT FOR READING!";
654  d->m_bFault = true;
655  d->m_bFinished = true;
656  d->startTimer();
657  return;
658  }
659  //qDebug() << this << "Scanning file" << d->m_strURL;
660 
661  KIO::JobFlags flags = d->m_bProgressInfo ? KIO::DefaultFlags : KIO::HideProgressInfo;
662  KIO::TransferJob *job = KIO::get(d->m_strURL, KIO::NoReload /*reload*/, flags);
663  KJobWidgets::setWindow(job, d->m_window);
664  connect(job, &KJob::result,
665  this, &KRun::slotScanFinished);
666  connect(job, QOverload<KIO::Job*,const QString&>::of(&KIO::TransferJob::mimetype),
667  this, &KRun::slotScanMimeType);
668  d->m_job = job;
669  //qDebug() << "Job" << job << "is about getting from" << d->m_strURL;
670 }
671 
672 // When arriving in that method there are 6 possible states:
673 // must_show_prompt, must_init, must_scan_file, found_dir, done+error or done+success.
675 {
676  if (d->m_bCheckPrompt) {
677  d->m_bCheckPrompt = false;
678  if (d->isPromptNeeded()) {
679  d->showPrompt();
680  return;
681  }
682  }
683  if (d->m_bInit) {
684  d->m_bInit = false;
685  init();
686  return;
687  }
688 
689  if (d->m_bFault) {
690  emit error();
691  }
692  if (d->m_bFinished) {
693  emit finished();
694  } else {
695  if (d->m_bScanFile) {
696  d->m_bScanFile = false;
697  scanFile();
698  return;
699  } else if (d->m_bIsDirectory) {
700  d->m_bIsDirectory = false;
701  mimeTypeDetermined(QStringLiteral("inode/directory"));
702  return;
703  }
704  }
705 
706  if (d->m_bAutoDelete) {
707  deleteLater();
708  return;
709  }
710 }
711 
713 {
714  d->m_job = nullptr;
715  const int errCode = job->error();
716  if (errCode) {
717  // ERR_NO_CONTENT is not an error, but an indication no further
718  // actions needs to be taken.
719  if (errCode != KIO::ERR_NO_CONTENT) {
720  qCWarning(KIO_WIDGETS) << this << "ERROR" << job->error() << job->errorString();
721  handleError(job);
722  //qDebug() << this << " KRun returning from showErrorDialog, starting timer to delete us";
723  d->m_bFault = true;
724  }
725 
726  d->m_bFinished = true;
727 
728  // will emit the error and autodelete this
729  d->startTimer();
730  } else {
731  //qDebug() << "Finished";
732 
733  KIO::StatJob *statJob = qobject_cast<KIO::StatJob *>(job);
734  if (!statJob) {
735  qFatal("Fatal Error: job is a %s, should be a StatJob", typeid(*job).name());
736  }
737 
738  // Update our URL in case of a redirection
739  setUrl(statJob->url());
740 
741  const KIO::UDSEntry entry = statJob->statResult();
742  const mode_t mode = entry.numberValue(KIO::UDSEntry::UDS_FILE_TYPE);
743  if ((mode & QT_STAT_MASK) == QT_STAT_DIR) {
744  d->m_bIsDirectory = true; // it's a dir
745  } else {
746  d->m_bScanFile = true; // it's a file
747  }
748 
749  d->m_localPath = entry.stringValue(KIO::UDSEntry::UDS_LOCAL_PATH);
750 
751  // mimetype already known? (e.g. print:/manager)
752  const QString knownMimeType = entry.stringValue(KIO::UDSEntry::UDS_MIME_TYPE);
753 
754  if (!knownMimeType.isEmpty()) {
755  mimeTypeDetermined(knownMimeType);
756  d->m_bFinished = true;
757  }
758 
759  // We should have found something
760  assert(d->m_bScanFile || d->m_bIsDirectory);
761 
762  // Start the timer. Once we get the timer event this
763  // protocol server is back in the pool and we can reuse it.
764  // This gives better performance than starting a new slave
765  d->startTimer();
766  }
767 }
768 
769 void KRun::slotScanMimeType(KIO::Job *, const QString &mimetype)
770 {
771  if (mimetype.isEmpty()) {
772  qCWarning(KIO_WIDGETS) << "get() didn't emit a mimetype! Probably a kioslave bug, please check the implementation of" << url().scheme();
773  }
774  mimeTypeDetermined(mimetype);
775  d->m_job = nullptr;
776 }
777 
779 {
780  d->m_job = nullptr;
781  const int errCode = job->error();
782  if (errCode) {
783  // ERR_NO_CONTENT is not an error, but an indication no further
784  // actions needs to be taken.
785  if (errCode != KIO::ERR_NO_CONTENT) {
786  qCWarning(KIO_WIDGETS) << this << "ERROR (stat):" << job->error() << ' ' << job->errorString();
787  handleError(job);
788 
789  d->m_bFault = true;
790  }
791 
792  d->m_bFinished = true;
793  // will emit the error and autodelete this
794  d->startTimer();
795  }
796 }
797 
798 void KRun::mimeTypeDetermined(const QString &mimeType)
799 {
800  // foundMimeType reimplementations might show a dialog box;
801  // make sure some timer doesn't kill us meanwhile (#137678, #156447)
802  Q_ASSERT(!d->m_showingDialog);
803  d->m_showingDialog = true;
804 
805  foundMimeType(mimeType);
806 
807  d->m_showingDialog = false;
808 
809  // We cannot assume that we're finished here. Some reimplementations
810  // start a KIO job and call setFinished only later.
811 }
812 
813 void KRun::foundMimeType(const QString &type)
814 {
815  //qDebug() << "Resulting mime type is " << type;
816 
817  QMimeDatabase db;
818 
819  KIO::TransferJob *job = qobject_cast<KIO::TransferJob *>(d->m_job);
820  if (job) {
821  // Update our URL in case of a redirection
822  if (d->m_followRedirections) {
823  setUrl(job->url());
824  }
825 
826  job->putOnHold();
828  d->m_job = nullptr;
829  }
830 
831  Q_ASSERT(!d->m_bFinished);
832 
833  // Support for preferred service setting, see setPreferredService
834  if (!d->m_preferredService.isEmpty()) {
835  //qDebug() << "Attempting to open with preferred service: " << d->m_preferredService;
836  KService::Ptr serv = KService::serviceByDesktopName(d->m_preferredService);
837  if (serv && serv->hasMimeType(type)) {
838  QList<QUrl> lst;
839  lst.append(d->m_strURL);
840  if (KRun::runApplication(*serv, lst, d->m_window, RunFlags{}, QString(), d->m_asn)) {
841  setFinished(true);
842  return;
843  }
848  }
849  }
850 
851  // Resolve .desktop files from media:/, remote:/, applications:/ etc.
852  QMimeType mime = db.mimeTypeForName(type);
853  if (!mime.isValid()) {
854  qCWarning(KIO_WIDGETS) << "Unknown mimetype" << type;
855  } else if (mime.inherits(QStringLiteral("application/x-desktop")) && !d->m_localPath.isEmpty()) {
856  d->m_strURL = QUrl::fromLocalFile(d->m_localPath);
857  }
858 
859  KRun::RunFlags runFlags;
860  if (d->m_runExecutables) {
861  runFlags |= KRun::RunExecutables;
862  }
863  if (!KRun::runUrl(d->m_strURL, type, d->m_window, runFlags, d->m_suggestedFileName, d->m_asn)) {
864  d->m_bFault = true;
865  }
866  setFinished(true);
867 }
868 
870 {
871  if (d->m_job) {
872  //qDebug() << this << "m_job=" << d->m_job;
873  d->m_job->kill();
874  d->m_job = nullptr;
875  }
876 }
877 
879 {
880  if (d->m_bFinished) {
881  return;
882  }
883  //qDebug() << this << "m_showingDialog=" << d->m_showingDialog;
884  killJob();
885  // If we're showing an error message box, the rest will be done
886  // after closing the msgbox -> don't autodelete nor emit signals now.
887  if (d->m_showingDialog) {
888  return;
889  }
890  d->m_bFault = true;
891  d->m_bFinished = true;
892  d->m_bInit = false;
893  d->m_bScanFile = false;
894 
895  // will emit the error and autodelete this
896  d->startTimer();
897 }
898 
900 {
901  return d->m_window;
902 }
903 
904 bool KRun::hasError() const
905 {
906  return d->m_bFault;
907 }
908 
909 bool KRun::hasFinished() const
910 {
911  return d->m_bFinished;
912 }
913 
914 bool KRun::autoDelete() const
915 {
916  return d->m_bAutoDelete;
917 }
918 
920 {
921  d->m_bAutoDelete = b;
922 }
923 
925 {
926  d->m_externalBrowserEnabled = b;
927  if (d->m_externalBrowserEnabled) {
928  d->m_externalBrowser = KConfigGroup(KSharedConfig::openConfig(), "General").readEntry("BrowserApplication");
929 
930  // If a default browser isn't set in kdeglobals, fall back to mimeapps.list
931  if (!d->m_externalBrowser.isEmpty()) {
932  return;
933  }
934 
935  KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation);
936  KConfigGroup defaultApps(profile, "Default Applications");
937 
938  d->m_externalBrowser = defaultApps.readEntry("x-scheme-handler/https");
939  if (d->m_externalBrowser.isEmpty()) {
940  d->m_externalBrowser = defaultApps.readEntry("x-scheme-handler/http");
941  }
942  } else {
943  d->m_externalBrowser.clear();
944  }
945 }
946 
947 void KRun::setPreferredService(const QString &desktopEntryName)
948 {
949  d->m_preferredService = desktopEntryName;
950 }
951 
953 {
954  d->m_runExecutables = b;
955 }
956 
957 void KRun::setSuggestedFileName(const QString &fileName)
958 {
959  d->m_suggestedFileName = fileName;
960 }
961 
963 {
964  d->m_bCheckPrompt = showPrompt;
965 }
966 
967 void KRun::setFollowRedirections(bool followRedirections)
968 {
969  d->m_followRedirections = followRedirections;
970 }
971 
973 {
974  return d->m_suggestedFileName;
975 }
976 
977 bool KRun::isExecutable(const QString &mimeTypeName)
978 {
979  QMimeDatabase db;
980  QMimeType mimeType = db.mimeTypeForName(mimeTypeName);
981  return (mimeType.inherits(QStringLiteral("application/x-desktop")) ||
982  mimeType.inherits(QStringLiteral("application/x-executable")) ||
983  /* See https://bugs.freedesktop.org/show_bug.cgi?id=97226 */
984  mimeType.inherits(QStringLiteral("application/x-sharedlib")) ||
985  mimeType.inherits(QStringLiteral("application/x-ms-dos-executable")) ||
986  mimeType.inherits(QStringLiteral("application/x-shellscript")));
987 }
988 
989 void KRun::setUrl(const QUrl &url)
990 {
991  d->m_strURL = url;
992 }
993 
995 {
996  return d->m_strURL;
997 }
998 
1000 {
1001  d->m_bFault = error;
1002 }
1003 
1005 {
1006  d->m_bProgressInfo = progressInfo;
1007 }
1008 
1010 {
1011  return d->m_bProgressInfo;
1012 }
1013 
1015 {
1016  d->m_bFinished = finished;
1017  if (finished) {
1018  d->startTimer();
1019  }
1020 }
1021 
1023 {
1024  d->m_job = job;
1025 }
1026 
1028 {
1029  return d->m_job;
1030 }
1031 
1032 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 4)
1034 {
1035  return *d->m_timer;
1036 }
1037 #endif
1038 
1039 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1)
1041 {
1042  d->m_bScanFile = scanFile;
1043 }
1044 #endif
1045 
1046 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1)
1047 bool KRun::doScanFile() const
1048 {
1049  return d->m_bScanFile;
1050 }
1051 #endif
1052 
1053 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1)
1055 {
1056  d->m_bIsDirectory = isDirectory;
1057 }
1058 #endif
1059 
1060 bool KRun::isDirectory() const
1061 {
1062  return d->m_bIsDirectory;
1063 }
1064 
1065 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1)
1066 void KRun::setInitializeNextAction(bool initialize)
1067 {
1068  d->m_bInit = initialize;
1069 }
1070 #endif
1071 
1072 #if KIOWIDGETS_BUILD_DEPRECATED_SINCE(4, 1)
1074 {
1075  return d->m_bInit;
1076 }
1077 #endif
1078 
1079 bool KRun::isLocalFile() const
1080 {
1081  return d->m_strURL.isLocalFile();
1082 }
1083 
1084 #include "moc_krun.cpp"
1085 #endif
KJOBWIDGETS_EXPORT void setWindow(KJob *job, QWidget *widget)
bool isReadable() const const
QByteArray fileName(const QUrl &url) const
Converts the given URL into 8-bit form and retrieve the filename.
static 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:264
void setEnableExternalBrowser(bool b)
Sets whether the external webbrowser setting should be honoured.
Definition: krun.cpp:924
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:193
KSERVICE_EXPORT KService::Ptr preferredService(const QString &mimeType)
QString & append(QChar ch)
static bool supportsReading(const QUrl &url)
Returns whether the protocol can retrieve data from URLs.
void slotTimeout()
All following protected slots are used by subclasses of KRun!
Definition: krun.cpp:674
virtual void foundMimeType(const QString &type)
Called if the mimetype has been detected.
Definition: krun.cpp:813
void abort()
Abort this KRun.
Definition: krun.cpp:878
void setDoScanFile(bool scanFile)
Indicate that the next action is to scan the file.
Definition: krun.cpp:1040
bool progressInfo() const
Returns whether progress information are shown.
Definition: krun.cpp:1009
OpenUrlJob finds out the right way to "open" a URL.
Definition: openurljob.h:38
void setIsDirecory(bool isDirectory)
Sets whether it is a directory.
Definition: krun.cpp:1054
void setUiDelegate(KJobUiDelegate *delegate)
QWidget * window() const const
const QUrl & url() const
Returns the SimpleJob&#39;s URL.
Definition: simplejob.cpp:70
Universal Directory Service.
Definition: udsentry.h:77
static Ptr serviceByDesktopName(const QString &_name)
void setWindowModality(Qt::WindowModality windowModality)
void start() override
Starts the job.
Definition: openurljob.cpp:150
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:952
Hide progress information dialog, i.e.
Definition: job_base.h:275
static bool isExecutableFile(const QUrl &url, const QString &mimetype)
Returns whether the url of mimetype is executable.
Definition: krun.cpp:120
void setUrl(const QUrl &url)
Sets the url.
Definition: krun.cpp:989
File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...
Definition: udsentry.h:268
QUrl url() const
Returns the url.
Definition: krun.cpp:994
bool isDirectory() const
Returns whether it is a directory.
Definition: krun.cpp:1060
bool inherits(const QString &mimeTypeName) const const
virtual int exec()
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
A KIO job that retrieves information about a file or directory.
Definition: statjob.h:26
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:300
A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...
Definition: udsentry.h:253
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())
Open the given URL.
Definition: krun.cpp:163
bool hasError() const
Returns true if the KRun instance has an error.
Definition: krun.cpp:904
QExplicitlySharedDataPointer< KService > Ptr
bool exists() const 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...
bool initializeNextAction() const
Definition: krun.cpp:1073
virtual void scanFile()
Start scanning a file.
Definition: krun.cpp:633
static bool checkStartupNotify(const QString &binName, const KService *service, bool *silent_arg, QByteArray *wmclass_arg)
Definition: krun.cpp:258
void start() override
Starts the job.
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...
To open files with their associated applications in KDE, use KRun.
Definition: krun.h:52
void slotScanMimeType(KIO::Job *, const QString &type)
This slot is called when the scan job has found out the mime type.
Definition: krun.cpp:769
static 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:239
Show the progress info GUI, no Resume and no Overwrite.
Definition: job_base.h:270
void timeout()
void setError(bool error)
Sets whether an error has occurred.
Definition: krun.cpp:999
QString mimetype() const
Call this in the slot connected to result, and only after making sure no error happened.
QStringList resultingArguments() 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:273
void finished()
Emitted when the operation finished.
long long numberValue(uint field, long long defaultValue=0) const
Definition: udsentry.cpp:358
void setStartupId(const QByteArray &startupId)
Sets the startup notification id of the application launch.
QMimeType mimeTypeForUrl(const QUrl &url) const const
static QString defaultMimetype(const QUrl &url)
Returns default mimetype for this URL based on the protocol.
bool hasMimeType(const QString &mimeType) const
A UI delegate tuned to be used with KIO Jobs.
Definition: jobuidelegate.h:30
CaseInsensitive
QWidget * window() const
Associated window, as passed to the constructor.
Definition: krun.cpp:899
Filename, access, type, size, linkdest.
Definition: global.h:314
bool isEmpty() const const
virtual void killJob()
Kills the file scanning job.
Definition: krun.cpp:869
static bool supportsListing(const QUrl &url)
Returns whether the protocol can list files/objects.
bool isEmpty() const const
virtual void slotStatResult(KJob *)
This slot is called when the &#39;stat&#39; job has finished.
Definition: krun.cpp:712
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const 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:27
bool autoDelete() const
Checks whether auto delete is activated.
Definition: krun.cpp:914
KIO::Job * job()
Returns the job.
Definition: krun.cpp:1027
virtual void handleInitError(int kioErrorCode, const QString &errorMsg)
Called when KRun detects an error during the init phase.
Definition: krun.cpp:144
"Open With" dialog box.
bool doScanFile() const
Returns whether the file shall be scanned.
Definition: krun.cpp:1047
void setRunExecutables(bool allow)
Set this to true if this class should allow the user to run executables.
Definition: openurljob.cpp:124
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:957
void deleteLater()
T & first()
void slotScanFinished(KJob *)
This slot is called when the scan job is finished.
Definition: krun.cpp:778
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.
KCOREADDONS_EXPORT QStringList splitArgs(const QString &cmd, Options flags=NoOptions, Errors *err=nullptr)
KJobUiDelegate * uiDelegate() const
QString scheme() const const
QMimeType mimeTypeForName(const QString &nameOrAlias) const const
QString toLocalFile() const const
void setRunFlags(RunFlags runFlags)
Specifies various flags.
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
Get (means: read).
void mimeTypeDetermined(const QString &mimeType)
Call this from subclasses when you have determined the mimetype.
Definition: krun.cpp:798
QString toHtmlEscaped() const const
bool isValid() const const
QStringRef midRef(int position, int n) const const
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.
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
the URLs passed to the service will be deleted when it exits (if the URLs are local files) ...
WA_DeleteOnClose
QString text() const
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:274
virtual void handleError(KJob *job)
Called when a KIO job started by KRun gives an error.
Definition: krun.cpp:152
int startTimer(int interval, Qt::TimerType timerType)
void setStartupId(const QByteArray &startupId)
Sets the startup notification id of the application launch.
Definition: openurljob.cpp:119
void setInitializeNextAction(bool initialize)
Definition: krun.cpp:1066
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:947
bool isLocalFile() const
Returns whether it is a local file.
Definition: krun.cpp:1079
QString suggestedFileName() const
Suggested file name given by the server (e.g.
Definition: krun.cpp:972
void setAutoDelete(bool b)
Enables or disabled auto deletion.
Definition: krun.cpp:919
virtual void showErrorMessage()
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:273
void setUrls(const QList< QUrl > &urls)
Specifies the URLs to be passed to the application.
static QString executablePath(const QString &execLine)
Given a full command line (e.g.
static bool isHelperProtocol(const QUrl &url)
Returns whether the protocol can act as a helper protocol.
void error()
Emitted when the operation had an error.
void setJob(KIO::Job *job)
Sets the job.
Definition: krun.cpp:1022
QTimer & timer()
Returns the timer object.
Definition: krun.cpp:1033
virtual Q_SCRIPTABLE void start()=0
void setFinished(bool finished)
Marks this &#39;KRun&#39; instance as finished.
Definition: krun.cpp:1014
The base class for all jobs.
Definition: job_base.h:45
void setFollowRedirections(bool b)
Sets whether KRun should follow URLs redirections.
Definition: krun.cpp:967
Action succeeded but no content will follow.
Definition: global.h:250
virtual void init()
All following protected methods are used by subclasses of KRun!
Definition: krun.cpp:402
QString localHostName()
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 it to a...
Definition: openurljob.cpp:114
CommandLauncherJob runs a command and watches it while running.
virtual void putOnHold()
Abort job.
Definition: simplejob.cpp:75
virtual ~KRun()
Destructor.
Definition: krun.cpp:532
A mime type; the slave should set it if it&#39;s known.
Definition: udsentry.h:279
void result(KJob *job)
Parses the Exec= line from a .desktop file, and process all the &#39;%&#39; placeholders, e...
KRun(const QUrl &url, QWidget *window, bool showProgressInfo=true, const QByteArray &asn=QByteArray())
Definition: krun.cpp:365
The transfer job pumps data into and/or out of a Slave.
Definition: transferjob.h:26
void setProgressInfo(bool progressInfo)
Sets whether progress information shall be shown.
Definition: krun.cpp:1004
bool openUrl(const QUrl &url)
static void publishSlaveOnHold()
Send the slave that was put on hold back to KLauncher.
Definition: scheduler.cpp:836
WindowModal
const UDSEntry & statResult() const
Result of the stat operation.
Definition: statjob.cpp:111
ApplicationLauncherJob runs an application and watches it while running.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
void setDeleteTemporaryFile(bool b)
Specifies that the URL passed to the application will be deleted when it exits (if the URL is a local...
Definition: openurljob.cpp:109
bool testFlag(Enum flag) const const
T readEntry(const QString &key, const T &aDefault) const
static QString binaryName(const QString &execLine, bool removePath)
Given a full command line (e.g.
Definition: krun.cpp:249
static void shellQuote(QString &str)
Quotes a string for the shell.
Definition: krun.cpp:227
KIOCORE_EXPORT StatJob * statDetails(const QUrl &url, KIO::StatJob::StatSide side, KIO::StatDetails details=KIO::StatDefaultDetails, JobFlags flags=DefaultFlags)
Find all details for one file or directory.
Definition: statjob.cpp:257
void setShowScriptExecutionPrompt(bool showPrompt)
Sets whether a prompt should be shown before executing scripts or desktop files.
Definition: krun.cpp:962
static bool hasSchemeHandler(const QUrl &url)
Returns true if protocol should be opened by a "handler" application, i.e.
QUrl fromLocalFile(const QString &localFile)
KService::Ptr service() const
static bool isExecutable(const QString &mimeType)
Returns whether mimeType refers to an executable program instead of a data file.
Definition: krun.cpp:977
QString locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options)
static QString executableName(const QString &execLine)
Given a full command line (e.g.
bool authorizeUrlAction(const QString &action, const QUrl &baseURL, const QUrl &destURL)
Returns whether a certain URL related action is authorized.
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:323
bool hasFinished() const
Returns true if the KRun instance has finished.
Definition: krun.cpp:909
bool isLocalFile() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Oct 22 2020 23:05:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.