diff --git a/src/qmlcontrols/kioplugin/krunproxy.cpp b/src/qmlcontrols/kioplugin/krunproxy.cpp index b276773..bae550b 100644 --- a/src/qmlcontrols/kioplugin/krunproxy.cpp +++ b/src/qmlcontrols/kioplugin/krunproxy.cpp @@ -1,60 +1,61 @@ /* * Copyright 2014 Antonis Tsiapaliokas * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "krunproxy.h" #include #include #include KRunProxy::KRunProxy(QObject* parent) : QObject(parent) { } -bool KRunProxy::openUrl(const QString &filePath) +bool KRunProxy::openUrl(const QString &file) { + QUrl fileUrl(file); QMimeDatabase db; - QMimeType mime = db.mimeTypeForFile(filePath); - const QString fileMymeType = mime.name(); + QMimeType mime = db.mimeTypeForFile(fileUrl.isLocalFile() ? fileUrl.toLocalFile() : fileUrl.path()); + const QString fileMimeType = mime.name(); - if (fileMymeType == QStringLiteral("application/x-executable") || !mime.isValid()) { + if (fileMimeType == QStringLiteral("application/x-executable") || !mime.isValid()) { //for security reasons we should not be able to execute applications. //We should use its desktop file to access it. return false; } - if (fileMymeType == QStringLiteral("application/x-desktop")) { + if (fileMimeType == QStringLiteral("application/x-desktop") && fileUrl.isLocalFile()) { // If our mimetype is a desktop file, then we don't want to open // the desktop file itself but the application in which it is associated // with. - KService::Ptr service = KService::serviceByDesktopPath(filePath); + KService::Ptr service = KService::serviceByDesktopPath(fileUrl.toLocalFile()); return KRun::runService(*service, QList(), nullptr) != 0; } else { - return KRun::runUrl(QUrl(filePath), fileMymeType, nullptr); + return KRun::runUrl(fileUrl, fileMimeType, nullptr); } } bool KRunProxy::openService(const QString &serviceName) { KService::Ptr service = KService::serviceByDesktopName(serviceName); if(service) return KRun::runApplication(*service, QList(), nullptr) != 0; return false; } diff --git a/src/qmlcontrols/kioplugin/krunproxy.h b/src/qmlcontrols/kioplugin/krunproxy.h index 40c5695..4a32d87 100644 --- a/src/qmlcontrols/kioplugin/krunproxy.h +++ b/src/qmlcontrols/kioplugin/krunproxy.h @@ -1,45 +1,45 @@ /* * Copyright 2014 Antonis Tsiapaliokas * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef KRUNPROXY_H #define KRUNPROXY_H #include class KRunProxy : public QObject { Q_OBJECT public: explicit KRunProxy (QObject* parent = nullptr); /** * opens the url from the existing file */ - Q_INVOKABLE bool openUrl(const QString &filePath); + Q_INVOKABLE bool openUrl(const QString &fileUrl); /** * Runs the service (application) * @param serviceName the name of the desktop file without extension * @return true on success */ Q_INVOKABLE bool openService(const QString &serviceName); }; #endif