Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/krun.cpp
Show All 40 Lines | |||||
41 | #include <QDesktopWidget> | 41 | #include <QDesktopWidget> | ||
42 | #include <qmimedatabase.h> | 42 | #include <qmimedatabase.h> | ||
43 | #include <QDebug> | 43 | #include <QDebug> | ||
44 | #include <QDBusConnection> | 44 | #include <QDBusConnection> | ||
45 | #include <QDBusConnectionInterface> | 45 | #include <QDBusConnectionInterface> | ||
46 | #include <QDBusInterface> | 46 | #include <QDBusInterface> | ||
47 | #include <QDBusReply> | 47 | #include <QDBusReply> | ||
48 | #include <QHostInfo> | 48 | #include <QHostInfo> | ||
49 | #include <QDesktopServices> | ||||
49 | 50 | | |||
50 | #include <kiconloader.h> | 51 | #include <kiconloader.h> | ||
51 | #include <kjobuidelegate.h> | 52 | #include <kjobuidelegate.h> | ||
52 | #include <kmimetypetrader.h> | 53 | #include <kmimetypetrader.h> | ||
53 | #include "kio/job.h" | 54 | #include "kio/job.h" | ||
54 | #include "kio/global.h" | 55 | #include "kio/global.h" | ||
55 | #include "kio/scheduler.h" | 56 | #include "kio/scheduler.h" | ||
56 | #include "kopenwithdialog.h" | 57 | #include "kopenwithdialog.h" | ||
Show All 21 Lines | |||||
78 | #include <kshell.h> | 79 | #include <kshell.h> | ||
79 | #include <kconfiggroup.h> | 80 | #include <kconfiggroup.h> | ||
80 | #include <kstandardguiitem.h> | 81 | #include <kstandardguiitem.h> | ||
81 | #include <kguiitem.h> | 82 | #include <kguiitem.h> | ||
82 | #include <qsavefile.h> | 83 | #include <qsavefile.h> | ||
83 | 84 | | |||
84 | #if HAVE_X11 | 85 | #if HAVE_X11 | ||
85 | #include <kwindowsystem.h> | 86 | #include <kwindowsystem.h> | ||
86 | #elif defined(Q_OS_WIN) | | |||
87 | #include <QDesktopServices> | | |||
88 | #endif | 87 | #endif | ||
89 | #include <qstandardpaths.h> | 88 | #include <qstandardpaths.h> | ||
90 | 89 | | |||
91 | KRun::KRunPrivate::KRunPrivate(KRun *parent) | 90 | KRun::KRunPrivate::KRunPrivate(KRun *parent) | ||
92 | : q(parent), | 91 | : q(parent), | ||
93 | m_showingDialog(false) | 92 | m_showingDialog(false) | ||
94 | { | 93 | { | ||
95 | } | 94 | } | ||
Show All 21 Lines | 104 | { | |||
117 | const KService::Ptr service = KMimeTypeTrader::self()->preferredService(QLatin1String("x-scheme-handler/") + protocol); | 116 | const KService::Ptr service = KMimeTypeTrader::self()->preferredService(QLatin1String("x-scheme-handler/") + protocol); | ||
118 | if (service) { | 117 | if (service) { | ||
119 | return service->exec(); // for helper protocols, the handler app has priority over the hardcoded one (see A above) | 118 | return service->exec(); // for helper protocols, the handler app has priority over the hardcoded one (see A above) | ||
120 | } | 119 | } | ||
121 | Q_ASSERT(KProtocolInfo::isHelperProtocol(protocol)); | 120 | Q_ASSERT(KProtocolInfo::isHelperProtocol(protocol)); | ||
122 | return KProtocolInfo::exec(protocol); | 121 | return KProtocolInfo::exec(protocol); | ||
123 | } | 122 | } | ||
124 | 123 | | |||
124 | static bool checkNeedPortalSupport() | ||||
125 | { | ||||
126 | return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, | ||||
127 | QLatin1String("flatpak-info")).isEmpty() || | ||||
128 | qEnvironmentVariableIsSet("SNAP"); | ||||
129 | } | ||||
130 | | ||||
125 | // --------------------------------------------------------------------------- | 131 | // --------------------------------------------------------------------------- | ||
126 | 132 | | |||
127 | bool KRun::isExecutableFile(const QUrl &url, const QString &mimetype) | 133 | bool KRun::isExecutableFile(const QUrl &url, const QString &mimetype) | ||
128 | { | 134 | { | ||
129 | if (!url.isLocalFile()) { | 135 | if (!url.isLocalFile()) { | ||
130 | return false; | 136 | return false; | ||
131 | } | 137 | } | ||
132 | QFileInfo file(url.toLocalFile()); | 138 | QFileInfo file(url.toLocalFile()); | ||
▲ Show 20 Lines • Show All 809 Lines • ▼ Show 20 Line(s) | 947 | if (!KUrlAuthorized::authorizeUrlAction(QStringLiteral("open"), QUrl(), d->m_strURL)) { | |||
942 | QString msg = KIO::buildErrorString(KIO::ERR_ACCESS_DENIED, d->m_strURL.toDisplayString()); | 948 | QString msg = KIO::buildErrorString(KIO::ERR_ACCESS_DENIED, d->m_strURL.toDisplayString()); | ||
943 | handleInitError(KIO::ERR_ACCESS_DENIED, msg); | 949 | handleInitError(KIO::ERR_ACCESS_DENIED, msg); | ||
944 | d->m_bFault = true; | 950 | d->m_bFault = true; | ||
945 | d->m_bFinished = true; | 951 | d->m_bFinished = true; | ||
946 | d->startTimer(); | 952 | d->startTimer(); | ||
947 | return; | 953 | return; | ||
948 | } | 954 | } | ||
949 | 955 | | |||
956 | if (d->m_externalBrowserEnabled && checkNeedPortalSupport()) { | ||||
apol: Maybe you can swap the condition so the function is only called when m_externalBrowserEnabled… | |||||
957 | // use the function from QDesktopServices as it handles portals correctly | ||||
958 | d->m_bFault = !QDesktopServices::openUrl(d->m_strURL); | ||||
959 | d->m_bFinished = true; | ||||
960 | d->startTimer(); | ||||
961 | return; | ||||
962 | } | ||||
963 | | ||||
950 | if (!d->m_externalBrowser.isEmpty() && d->m_strURL.scheme().startsWith(QLatin1String("http"))) { | 964 | if (!d->m_externalBrowser.isEmpty() && d->m_strURL.scheme().startsWith(QLatin1String("http"))) { | ||
951 | if (d->runExecutable(d->m_externalBrowser)) { | 965 | if (d->runExecutable(d->m_externalBrowser)) { | ||
952 | return; | 966 | return; | ||
953 | } | 967 | } | ||
954 | } else if (d->m_strURL.isLocalFile() && | 968 | } else if (d->m_strURL.isLocalFile() && | ||
955 | (d->m_strURL.host().isEmpty() || | 969 | (d->m_strURL.host().isEmpty() || | ||
956 | (d->m_strURL.host() == QLatin1String("localhost")) || | 970 | (d->m_strURL.host() == QLatin1String("localhost")) || | ||
957 | (d->m_strURL.host().compare(QHostInfo::localHostName(), Qt::CaseInsensitive) == 0))) { | 971 | (d->m_strURL.host().compare(QHostInfo::localHostName(), Qt::CaseInsensitive) == 0))) { | ||
▲ Show 20 Lines • Show All 456 Lines • ▼ Show 20 Line(s) | |||||
1414 | 1428 | | |||
1415 | void KRun::setAutoDelete(bool b) | 1429 | void KRun::setAutoDelete(bool b) | ||
1416 | { | 1430 | { | ||
1417 | d->m_bAutoDelete = b; | 1431 | d->m_bAutoDelete = b; | ||
1418 | } | 1432 | } | ||
1419 | 1433 | | |||
1420 | void KRun::setEnableExternalBrowser(bool b) | 1434 | void KRun::setEnableExternalBrowser(bool b) | ||
1421 | { | 1435 | { | ||
1422 | if (b) { | 1436 | d->m_externalBrowserEnabled = b; | ||
1437 | if (d->m_externalBrowserEnabled) { | ||||
1423 | d->m_externalBrowser = KConfigGroup(KSharedConfig::openConfig(), "General").readEntry("BrowserApplication"); | 1438 | d->m_externalBrowser = KConfigGroup(KSharedConfig::openConfig(), "General").readEntry("BrowserApplication"); | ||
1424 | 1439 | | |||
1425 | // If a default browser isn't set in kdeglobals, fall back to mimeapps.list | 1440 | // If a default browser isn't set in kdeglobals, fall back to mimeapps.list | ||
1426 | if (!d->m_externalBrowser.isEmpty()) { | 1441 | if (!d->m_externalBrowser.isEmpty()) { | ||
1427 | return; | 1442 | return; | ||
1428 | } | 1443 | } | ||
1429 | 1444 | | |||
1430 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); | 1445 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); | ||
▲ Show 20 Lines • Show All 233 Lines • Show Last 20 Lines |
Maybe you can swap the condition so the function is only called when m_externalBrowserEnabled is true.