Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/krun.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
57 | #include "kio/scheduler.h" | 57 | #include "kio/scheduler.h" | ||
58 | #include "kopenwithdialog.h" | 58 | #include "kopenwithdialog.h" | ||
59 | #include "krecentdocument.h" | 59 | #include "krecentdocument.h" | ||
60 | #include "kdesktopfileactions.h" | 60 | #include "kdesktopfileactions.h" | ||
61 | #include <kio/desktopexecparser.h> | 61 | #include <kio/desktopexecparser.h> | ||
62 | 62 | | |||
63 | #include <kurlauthorized.h> | 63 | #include <kurlauthorized.h> | ||
64 | #include <kmessagebox.h> | 64 | #include <kmessagebox.h> | ||
65 | #include <ktoolinvocation.h> | | |||
66 | #include <klocalizedstring.h> | 65 | #include <klocalizedstring.h> | ||
67 | #include <kprotocolmanager.h> | 66 | #include <kprotocolmanager.h> | ||
68 | #include <kprocess.h> | 67 | #include <kprocess.h> | ||
69 | #include <kjobwidgets.h> | 68 | #include <kjobwidgets.h> | ||
70 | #include <ksharedconfig.h> | 69 | #include <ksharedconfig.h> | ||
71 | 70 | | |||
72 | #include <QFile> | 71 | #include <QFile> | ||
73 | #include <QFileInfo> | 72 | #include <QFileInfo> | ||
▲ Show 20 Lines • Show All 653 Lines • ▼ Show 20 Line(s) | 721 | { | |||
727 | } | 726 | } | ||
728 | 727 | | |||
729 | if (!tempFiles) { | 728 | if (!tempFiles) { | ||
730 | // Remember we opened those urls, for the "recent documents" menu in kicker | 729 | // Remember we opened those urls, for the "recent documents" menu in kicker | ||
731 | for (const QUrl &url : _urls) { | 730 | for (const QUrl &url : _urls) { | ||
732 | KRecentDocument::add(url, _service.desktopEntryName()); | 731 | KRecentDocument::add(url, _service.desktopEntryName()); | ||
733 | } | 732 | } | ||
734 | } | 733 | } | ||
735 | | ||||
736 | bool useKToolInvocation = !(tempFiles || _service.entryPath().isEmpty() || !suggestedFileName.isEmpty()); | | |||
737 | | ||||
738 | if (useKToolInvocation) { | | |||
739 | // Is klauncher installed? Let's try to start it, if it fails, then we won't use it. | | |||
740 | static int klauncherAvailable = -1; | | |||
741 | if (klauncherAvailable == -1) { | | |||
742 | KToolInvocation::ensureKdeinitRunning(); | | |||
743 | QDBusConnectionInterface *dbusDaemon = QDBusConnection::sessionBus().interface(); | | |||
744 | klauncherAvailable = dbusDaemon->isServiceRegistered(QStringLiteral("org.kde.klauncher5")); | | |||
745 | } | | |||
746 | if (klauncherAvailable == 0) { | | |||
747 | useKToolInvocation = false; | | |||
748 | } | | |||
749 | } | | |||
750 | | ||||
751 | if (!useKToolInvocation) { | | |||
752 | KService::Ptr servicePtr(new KService(_service)); // clone | 734 | KService::Ptr servicePtr(new KService(_service)); // clone | ||
753 | return runApplicationImpl(servicePtr, _urls, window, tempFiles ? RunFlags(DeleteTemporaryFiles) : RunFlags(), suggestedFileName, asn); | 735 | return runApplicationImpl(servicePtr, _urls, window, tempFiles ? RunFlags(DeleteTemporaryFiles) : RunFlags(), suggestedFileName, asn); | ||
754 | } | 736 | } | ||
755 | 737 | | |||
756 | // Resolve urls if needed, depending on what the app supports | | |||
757 | const QList<QUrl> urls = resolveURLs(_urls, _service); | | |||
kossebau: Compiler now complains nothing uses `resolveURLS()`after this.
Clean up proposed by D28537 | |||||
758 | | ||||
759 | //qDebug() << "Running" << _service.entryPath() << _urls << "using klauncher"; | | |||
760 | | ||||
761 | QString error; | | |||
762 | int pid = 0; //TODO KF6: change KToolInvokation to take a qint64* | | |||
763 | | ||||
764 | QByteArray myasn = asn; | | |||
765 | // startServiceByDesktopPath() doesn't take QWidget*, add it to the startup info now | | |||
766 | if (window) { | | |||
767 | if (myasn.isEmpty()) { | | |||
768 | myasn = KStartupInfo::createNewStartupId(); | | |||
769 | } | | |||
770 | if (myasn != "0") { | | |||
771 | KStartupInfoId id; | | |||
772 | id.initId(myasn); | | |||
773 | KStartupInfoData data; | | |||
774 | // QTBUG-59017 Calling winId() on an embedded widget will break interaction | | |||
775 | // with it on high-dpi multi-screen setups (cf. also Bug 363548), hence using | | |||
776 | // its parent window instead | | |||
777 | if (window->window()) { | | |||
778 | data.setLaunchedBy(window->window()->winId()); | | |||
779 | } | | |||
780 | KStartupInfo::sendChange(id, data); | | |||
781 | } | | |||
782 | } | | |||
783 | | ||||
784 | int i = KToolInvocation::startServiceByDesktopPath( | | |||
785 | _service.entryPath(), QUrl::toStringList(urls), &error, nullptr, &pid, myasn | | |||
786 | ); | | |||
787 | | ||||
788 | if (i != 0) { | | |||
789 | //qDebug() << error; | | |||
790 | KMessageBox::sorry(window, error); | | |||
791 | return 0; | | |||
792 | } | | |||
793 | | ||||
794 | //qDebug() << "startServiceByDesktopPath worked fine"; | | |||
795 | return pid; | | |||
796 | } | | |||
797 | | ||||
798 | bool KRun::run(const QString &_exec, const QList<QUrl> &_urls, QWidget *window, const QString &_name, | 738 | bool KRun::run(const QString &_exec, const QList<QUrl> &_urls, QWidget *window, const QString &_name, | ||
799 | const QString &_icon, const QByteArray &asn) | 739 | const QString &_icon, const QByteArray &asn) | ||
800 | { | 740 | { | ||
801 | KService::Ptr service(new KService(_name, _exec, _icon)); | 741 | KService::Ptr service(new KService(_name, _exec, _icon)); | ||
802 | 742 | | |||
803 | return runApplication(*service, _urls, window, RunFlags{}, QString(), asn); | 743 | return runApplication(*service, _urls, window, RunFlags{}, QString(), asn); | ||
804 | } | 744 | } | ||
805 | 745 | | |||
▲ Show 20 Lines • Show All 968 Lines • Show Last 20 Lines |
Compiler now complains nothing uses resolveURLS()after this.
Clean up proposed by D28537