Git commit 3e7dd188f9d0e452bdcba583ac46ef992a918e01 by Aleix Pol. Committed on 22/11/2016 at 15:15. Pushed by apol into branch 'Plasma/5.8'.
Expose software-properties-kde if present As requested by santa, expose an action for software-properties-kde into Discover so that kubuntu users can access this system-specific tool to manage their repositories. This opens the possibility for other platforms to offer their tooling there as well. CCMAIL: [email protected] M +4 -0 libdiscover/backends/PackageKitBackend/CMakeLists.txt M +27 -0 libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp M +1 -0 libdiscover/backends/PackageKitBackend/PackageKitBackend.h A +1 -0 libdiscover/backends/PackageKitBackend/config-paths.h.cmake A +3 -0 libdiscover/backends/PackageKitBackend/runservice/CMakeLists.txt A +43 -0 libdiscover/backends/PackageKitBackend/runservice/main.cpp [License: GPL (v2/3)] http://commits.kde.org/discover/3e7dd188f9d0e452bdcba583ac46ef992a918e01 diff --git a/libdiscover/backends/PackageKitBackend/CMakeLists.txt b/libdiscover/backends/PackageKitBackend/CMakeLists.txt index 8267715..bb39561 100644 --- a/libdiscover/backends/PackageKitBackend/CMakeLists.txt +++ b/libdiscover/backends/PackageKitBackend/CMakeLists.txt @@ -1,6 +1,10 @@ find_package(KF5KIO REQUIRED) find_package(KF5Archive REQUIRED) +add_subdirectory(runservice) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-paths.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-paths.h) + add_library(packagekit-backend MODULE PackageKitBackend.cpp PackageKitResource.cpp AppPackageKitResource.cpp diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index 3f180e5..3421cd1 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -31,22 +31,31 @@ #include <resources/SourcesModel.h> #include <Transaction/TransactionModel.h> +#include <QProcess> #include <QStringList> #include <QDebug> #include <QTimer> #include <QTimerEvent> +#include <QStandardPaths> #include <PackageKit/Transaction> #include <PackageKit/Daemon> #include <PackageKit/Details> +#include <KDesktopFile> #include <KLocalizedString> #include <QAction> #include "utils.h" +#include "config-paths.h" MUON_BACKEND_PLUGIN(PackageKitBackend) +static QString locateService(const QString &filename) +{ + return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("applications/")+filename); +} + PackageKitBackend::PackageKitBackend(QObject* parent) : AbstractResourcesBackend(parent) , m_updater(new PackageKitUpdater(this)) @@ -90,6 +99,10 @@ PackageKitBackend::PackageKitBackend(QObject* parent) connect(updateAction, &QAction::triggered, this, &PackageKitBackend::refreshDatabase); m_messageActions += updateAction; + const auto service = locateService(QStringLiteral("software-properties-kde.desktop")); + if (!service.isEmpty()) + m_messageActions += createActionForService(service); + connect(PackageKit::Daemon::global(), &PackageKit::Daemon::updatesChanged, this, &PackageKitBackend::fetchUpdates); connect(PackageKit::Daemon::global(), &PackageKit::Daemon::isRunningChanged, this, &PackageKitBackend::checkDaemonRunning); connect(m_reviews, &AppstreamReviews::ratingsReady, this, &AbstractResourcesBackend::emitRatingsReady); @@ -101,6 +114,20 @@ PackageKitBackend::~PackageKitBackend() { } +QAction* PackageKitBackend::createActionForService(const QString &servicePath) +{ + QAction* action = new QAction(this); + KDesktopFile parser(servicePath); + action->setIcon(QIcon::fromTheme(parser.readIcon())); + action->setText(parser.readName()); + connect(action, &QAction::triggered, action, [servicePath, this](){ + bool b = QProcess::startDetached(QStringLiteral(CMAKE_INSTALL_FULL_LIBEXECDIR_KF5 "/discover/runservice"), {servicePath}); + if (!b) + qWarning() << "Could not start" << servicePath; + }); + return action; +} + bool PackageKitBackend::isFetching() const { return m_isFetching; diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h index 562099e..6d10448 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h @@ -106,6 +106,7 @@ class DISCOVERCOMMON_EXPORT PackageKitBackend : public AbstractResourcesBackend void acquireFetching(bool f); void includePackagesToAdd(); void performDetailsFetch(); + QAction* createActionForService(const QString &filename); Appstream::Database m_appdata; QList<Transaction*> m_transactions; diff --git a/libdiscover/backends/PackageKitBackend/config-paths.h.cmake b/libdiscover/backends/PackageKitBackend/config-paths.h.cmake new file mode 100644 index 0000000..92f4926 --- /dev/null +++ b/libdiscover/backends/PackageKitBackend/config-paths.h.cmake @@ -0,0 +1 @@ +#define CMAKE_INSTALL_FULL_LIBEXECDIR_KF5 "@CMAKE_INSTALL_FULL_LIBEXECDIR_KF5@" diff --git a/libdiscover/backends/PackageKitBackend/runservice/CMakeLists.txt b/libdiscover/backends/PackageKitBackend/runservice/CMakeLists.txt new file mode 100644 index 0000000..7e8b96f --- /dev/null +++ b/libdiscover/backends/PackageKitBackend/runservice/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(runservice main.cpp) +target_link_libraries(runservice KF5::Service KF5::KIOCore) +install(TARGETS runservice DESTINATION ${KDE_INSTALL_LIBEXECDIR_KF5}/discover) diff --git a/libdiscover/backends/PackageKitBackend/runservice/main.cpp b/libdiscover/backends/PackageKitBackend/runservice/main.cpp new file mode 100644 index 0000000..b56917a --- /dev/null +++ b/libdiscover/backends/PackageKitBackend/runservice/main.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright © 2016 Aleix Pol Gonzalez <[email protected]> * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License or (at your option) version 3 or any later version * + * accepted by the membership of KDE e.V. (or its successor approved * + * by the membership of KDE e.V.), which shall act as a proxy * + * defined in Section 14 of version 3 of the license. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QCoreApplication> +#include <QFile> +#include <QTextStream> +#include <QUrl> +#include <QProcess> +#include <KService> +#include <KIO/DesktopExecParser> + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + if (app.arguments().size() != 2) + return 1; + + KService _service(app.arguments().last()); + if (!_service.isValid()) + return 2; + + QTextStream cerr(stderr); + KIO::DesktopExecParser execParser(_service, {}); + + return !QProcess::startDetached(KIO::DesktopExecParser::executableName(_service.exec()), execParser.resultingArguments()); +} -- kubuntu-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-devel
