diff --git a/kcms/activities/CMakeLists.txt b/kcms/activities/CMakeLists.txt index b06ce2643..70a423e27 100644 --- a/kcms/activities/CMakeLists.txt +++ b/kcms/activities/CMakeLists.txt @@ -1,94 +1,92 @@ # vim:set softtabstop=3 shiftwidth=3 tabstop=3 expandtab: project (KCMActivities) add_definitions(-DTRANSLATION_DOMAIN=\"kcm_activities5\") find_package (Qt5 REQUIRED NO_MODULE COMPONENTS Core Quick Sql Qml DBus) find_package (KF5KCMUtils ${KF5_DEP_VERSION} CONFIG REQUIRED) find_package (KF5Declarative ${KF5_DEP_VERSION} CONFIG REQUIRED) find_package (KF5XmlGui ${KF5_DEP_VERSION} CONFIG REQUIRED) find_package (KF5GlobalAccel ${KF5_DEP_VERSION} CONFIG REQUIRED) find_package (KF5Activities ${KF5_DEP_VERSION} CONFIG REQUIRED) set (KAMD_KCM_DATADIR ${KDE_INSTALL_DATADIR_KF5}/kactivitymanagerd/workspace/settings/ ) if (NOT IS_ABSOLUTE "${KDE_INSTALL_DATADIR_KF5}") set (KAMD_KCM_DATADIR "${CMAKE_INSTALL_PREFIX}/${KAMD_KCM_DATADIR}") endif () configure_file (kactivities-kcm-features.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/kactivities-kcm-features.h) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(imports) set (KAMD_KCM_SRCS kcm_activities.cpp MainConfigurationWidget.cpp ActivitiesTab.cpp SwitchingTab.cpp PrivacyTab.cpp BlacklistedApplicationsModel.cpp ExtraActivitiesInterface.cpp - - utils/dbusfuture_p.cpp ) ki18n_wrap_ui ( KAMD_KCM_SRCS ui/MainConfigurationWidgetBase.ui ui/PrivacyTabBase.ui ui/SwitchingTabBase.ui ) qt5_add_dbus_interface ( KAMD_KCM_SRCS common/dbus/org.kde.ActivityManager.Features.xml features_interface ) kconfig_add_kcfg_files(KAMD_KCM_SRCS kactivitymanagerd_settings.kcfgc GENERATE_MOC) kconfig_add_kcfg_files(KAMD_KCM_SRCS kactivitymanagerd_plugins_settings.kcfgc GENERATE_MOC) add_library (kcm_activities MODULE ${KAMD_KCM_SRCS}) target_link_libraries (kcm_activities Qt5::Quick Qt5::Core Qt5::Sql Qt5::Qml Qt5::DBus KF5::KCMUtils KF5::I18n KF5::Service KF5::Declarative KF5::XmlGui KF5::GlobalAccel KF5::Activities ) install ( TARGETS kcm_activities DESTINATION ${KDE_INSTALL_PLUGINDIR} ) install ( FILES kcm_activities.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) install ( DIRECTORY qml/activitiesTab qml/privacyTab DESTINATION ${KAMD_KCM_DATADIR}/qml ) install(FILES kactivitymanagerd_settings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) install(FILES kactivitymanagerd_plugins_settings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) diff --git a/kcms/activities/ExtraActivitiesInterface.cpp b/kcms/activities/ExtraActivitiesInterface.cpp index 65a4b0be8..90160bbcc 100644 --- a/kcms/activities/ExtraActivitiesInterface.cpp +++ b/kcms/activities/ExtraActivitiesInterface.cpp @@ -1,136 +1,135 @@ /* * Copyright (C) 2015 - 2016 by Ivan Cukic * * 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 . */ #include "ExtraActivitiesInterface.h" #include #include #include #include #include #include #include -#include "utils/dbusfuture_p.h" #include "features_interface.h" #include "common/dbus/common.h" #define ENABLE_QJSVALUE_CONTINUATION #include "utils/continue_with.h" class ExtraActivitiesInterface::Private { public: Private(ExtraActivitiesInterface *q) : features(new KAMD_DBUS_CLASS_INTERFACE(Features, Features, q)) , activitiesActionCollection(new KActionCollection(q, QStringLiteral("ActivityManager"))) { activitiesActionCollection->setComponentDisplayName(i18n("Activities")); activitiesActionCollection->setConfigGlobal(true); } ~Private() { } QAction *actionForActivity(const QString &activity) { if (!activityActions.contains(activity)) { auto action = activitiesActionCollection->addAction( QStringLiteral("switch-to-activity-") + activity); activityActions[activity] = action; action->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setShortcut(action, {}); } return activityActions[activity]; } std::unique_ptr features; std::unique_ptr activitiesActionCollection; QHash activityActions; }; ExtraActivitiesInterface::ExtraActivitiesInterface(QObject *parent) : QObject(parent) , d(this) { } ExtraActivitiesInterface::~ExtraActivitiesInterface() { } void ExtraActivitiesInterface::setIsPrivate(const QString &activity, bool isPrivate, QJSValue callback) { auto result = d->features->SetValue( QStringLiteral("org.kde.ActivityManager.Resources.Scoring/isOTR/") + activity, QDBusVariant(isPrivate)); auto *watcher = new QDBusPendingCallWatcher(result, this); QObject::connect( watcher, &QDBusPendingCallWatcher::finished, this, [callback] (QDBusPendingCallWatcher* watcher) mutable { callback.call(); watcher->deleteLater(); } ); } void ExtraActivitiesInterface::getIsPrivate(const QString &activity, QJSValue callback) { auto result = d->features->GetValue( QStringLiteral("org.kde.ActivityManager.Resources.Scoring/isOTR/") + activity); auto *watcher = new QDBusPendingCallWatcher(result, this); QObject::connect( watcher, &QDBusPendingCallWatcher::finished, this, [callback,result] (QDBusPendingCallWatcher* watcher) mutable { QDBusPendingReply reply = *watcher; callback.call({reply.value().variant().toBool()}); watcher->deleteLater(); } ); } void ExtraActivitiesInterface::setShortcut(const QString &activity, const QKeySequence &keySequence) { auto action = d->actionForActivity(activity); KGlobalAccel::self()->setShortcut(action, { keySequence }, KGlobalAccel::NoAutoloading); } QKeySequence ExtraActivitiesInterface::shortcut(const QString &activity) { auto action = d->actionForActivity(activity); const auto shortcuts = KGlobalAccel::self()->shortcut(action); return (shortcuts.isEmpty()) ? QKeySequence() : shortcuts.first(); } diff --git a/kcms/activities/utils/dbusfuture_p.cpp b/kcms/activities/utils/dbusfuture_p.cpp deleted file mode 100644 index a63a3340f..000000000 --- a/kcms/activities/utils/dbusfuture_p.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2013 - 2016 by Ivan Cukic - * - * 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 . - */ - -#include "dbusfuture_p.h" - -namespace DBusFuture { - -namespace detail { //_ - -template <> -void DBusCallFutureInterface::callFinished() -{ - deleteLater(); - - // qDebug() << "This is call end"; - - this->reportFinished(); -} - -ValueFutureInterface::ValueFutureInterface() -{ -} - -QFuture ValueFutureInterface::start() -{ - auto future = this->future(); - - this->reportFinished(); - - deleteLater(); - - return future; -} - -} //^ namespace detail - -QFuture fromVoid() -{ - using namespace detail; - - auto valueFutureInterface = new ValueFutureInterface(); - - return valueFutureInterface->start(); -} - -} // namespace DBusFuture - diff --git a/kcms/activities/utils/dbusfuture_p.h b/kcms/activities/utils/dbusfuture_p.h deleted file mode 100644 index 520600b40..000000000 --- a/kcms/activities/utils/dbusfuture_p.h +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (C) 2013 - 2016 by Ivan Cukic - * - * 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 . - */ - -#ifndef ACTIVITIES_DBUSFUTURE_P_H -#define ACTIVITIES_DBUSFUTURE_P_H - -#include -#include -#include -#include -#include -#include -#include - -namespace DBusFuture { - -namespace detail { //_ - -template -class DBusCallFutureInterface : public QObject, - public QFutureInterface<_Result> { -public: - DBusCallFutureInterface(QDBusPendingReply<_Result> reply) - : reply(reply), - replyWatcher(nullptr) - { - } - - ~DBusCallFutureInterface() override - { - delete replyWatcher; - } - - void callFinished(); - - QFuture<_Result> start() - { - replyWatcher = new QDBusPendingCallWatcher(reply); - - QObject::connect(replyWatcher, - &QDBusPendingCallWatcher::finished, - [this] () { callFinished(); }); - - this->reportStarted(); - - if (reply.isFinished()) { - this->callFinished(); - } - - return this->future(); - } - -private: - QDBusPendingReply<_Result> reply; - QDBusPendingCallWatcher * replyWatcher; -}; - -template -void DBusCallFutureInterface<_Result>::callFinished() -{ - deleteLater(); - - if (!reply.isError()) { - this->reportResult(reply.value()); - } - - this->reportFinished(); -} - -template <> -void DBusCallFutureInterface::callFinished(); - -template -class ValueFutureInterface : public QObject, QFutureInterface<_Result> { -public: - ValueFutureInterface(const _Result & value) - : value(value) - { - } - - QFuture<_Result> start() - { - auto future = this->future(); - - this->reportResult(value); - this->reportFinished(); - - deleteLater(); - - return future; - } - -private: - _Result value; - -}; - -template <> -class ValueFutureInterface : public QObject, QFutureInterface { -public: - ValueFutureInterface(); - - QFuture start(); - // { - // auto future = this->future(); - // this->reportFinished(); - // deleteLater(); - // return future; - // } -}; - -} //^ namespace detail - -template -QFuture<_Result> -asyncCall(QDBusAbstractInterface *interface, const QString &method, - const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), - const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), - const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), - const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant()) -{ - using namespace detail; - - auto callFutureInterface = new DBusCallFutureInterface - <_Result>(interface->asyncCall(method, arg1, arg2, arg3, arg4, arg5, - arg6, arg7, arg8)); - - return callFutureInterface->start(); -} - -template -QFuture<_Result> -fromValue(const _Result & value) -{ - using namespace detail; - - auto valueFutureInterface = new ValueFutureInterface<_Result>(value); - - return valueFutureInterface->start(); -} - -template -QFuture<_Result> -fromReply(const QDBusPendingReply<_Result> &reply) -{ - using namespace detail; - - auto callFutureInterface = new DBusCallFutureInterface<_Result>(reply); - - return callFutureInterface->start(); -} - -QFuture fromVoid(); - -} // namespace DBusFuture - -#endif /* DBUSFUTURE_P_H */ -