diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c189cce..9ba191a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,180 +1,181 @@ add_subdirectory(lib) add_subdirectory(gstreamer) if(BUILD_PLUGINS) add_subdirectory(plugins) endif() if(NOT BUILD_APP) return() endif() if(ANDROID) kirigami_package_breeze_icons(ICONS arrow-down arrow-up battery-000 battery-010 battery-020 battery-030 battery-040 battery-050 battery-060 battery-070 battery-080 battery-100 battery-missing chronometer-reset clock computer-symbolic configure documentinfo edit-redo edit-undo emblem-default-symbolic emblem-important-symbolic emblem-photos-symbolic emblem-videos-symbolic format-align-vertical-bottom go-down go-home-symbolic go-next go-previous go-up gps help-about input-gamepad-symbolic kruler-south kruler-west map-flat media-record-symbolic network-wireless-acquiring network-wireless-connected-00 network-wireless-connected-100 network-wireless-connected-25 network-wireless-connected-50 network-wireless-connected-75 network-wireless-disconnected phone-symbolic question speedometer transform-move uav uav-quadcopter window ) endif() if(ANDROID) set(ANDROID_HEADERS "gstreamer/gstreamer_android.h" ) set(ANDROID_SOURCES "gstreamer/gstreamer_android-1.0.c" "gstreamer/qt_gstreamer_android-1.0.cpp" ) endif() set(kirogi_SRCS main.cpp permissions.cpp + autosettingshandler.cpp ${ANDROID_HEADERS} ${ANDROID_SOURCES} ) ecm_qt_declare_logging_category(kirogi_SRCS HEADER debug.h IDENTIFIER KIROGI_APP CATEGORY_NAME "kirogi.app" ) kconfig_add_kcfg_files(kirogi_SRCS GENERATE_MOC settings.kcfgc) file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../data/icons/*apps-kirogi.svg") ecm_add_app_icon(kirogi_SRCS ICONS ${ICONS_SRCS}) # FIXME In lieu of `ecm_add_app_icon` having Android support. if(ANDROID) install(FILES ${ICONS_SRCS} DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kirigami.2/icons/ RENAME "kirogi.svg") endif() if(COMPILE_QML) qtquick_compiler_add_resources(RESOURCES resources.qrc) else() qt5_add_resources(RESOURCES resources.qrc) endif() add_executable(kirogi ${kirogi_SRCS} ${RESOURCES}) target_compile_definitions(kirogi PRIVATE -DUSE_QRC) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") target_compile_options(kirogi PRIVATE -pedantic -Woverloaded-virtual -Wunused -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast ) if(CMAKE_COMPILER_IS_GNUCXX) target_compile_options(kirogi PRIVATE -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wnull-dereference -fsanitize=leak ) endif() endif() target_link_libraries(kirogi Qt5::Core Qt5::Positioning Qt5::Qml Qt5::Quick KF5::ConfigWidgets KF5::CoreAddons KF5::I18n gstreamer ${GSTREAMER_LIBRARIES} ) if(NOT ANDROID) target_link_libraries(kirogi Qt5::Widgets KF5::Crash ${GSTREAMER_LIBRARIES} ) else() target_link_libraries(kirogi Qt5::AndroidExtras # The Material style requires QtSvg. Qt5::Svg # GStreamer plugins gstcoreelements gsttypefindfunctions gstplayback gstvideotestsrc gstvideoparsersbad gstx264 gstudp gstrtpmanager gstrtp gstqmlgl gstopengl gstlibav x264 # Optional gstandroidmedia gstphotography-1.0 ${GSTREAMER_STATIC_LIBRARIES} ) endif() install(FILES kirogi.kcfg DESTINATION ${KCFG_INSTALL_DIR}) install(TARGETS kirogi ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/src/autosettingshandler.cpp b/src/autosettingshandler.cpp new file mode 100644 index 0000000..72a9045 --- /dev/null +++ b/src/autosettingshandler.cpp @@ -0,0 +1,62 @@ +/* + * Copyright 2019 Kevin Ottens + * Copyright 2019 Tomaz Canabrava + * + * 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 "autosettingshandler.h" + +#include +#include +#include + +void AutoSettingsHandler::addSettings(KCoreConfigSkeleton* setting) +{ + m_settings.append(setting); + auto settingsChangedSlotIndex = metaObject()->indexOfMethod("triggerSave()"); + auto settingsChangedSlot = metaObject()->method(settingsChangedSlotIndex); + + for (auto item : setting->items()) { + auto signallingItem = dynamic_cast(item); + + if (!signallingItem) { + continue; + } + + QString name = signallingItem->name(); + name[0] = name[0].toLower(); + + const auto metaObject = setting->metaObject(); + const auto propertyIndex = metaObject->indexOfProperty(name.toUtf8().constData()); + + const auto property = metaObject->property(propertyIndex); + if (!property.hasNotifySignal()) { + continue; + } + + const auto changedSignal = property.notifySignal(); + QObject::connect(setting, changedSignal, this, settingsChangedSlot); + } +} + +void AutoSettingsHandler::triggerSave() +{ + for(auto setting : qAsConst(m_settings)) { + setting->save(); + } +} diff --git a/src/autosettingshandler.h b/src/autosettingshandler.h new file mode 100644 index 0000000..6b03535 --- /dev/null +++ b/src/autosettingshandler.h @@ -0,0 +1,44 @@ +/* + * Copyright 2019 Tomaz Canabrava + * + * 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 . + */ + +#pragma once + +#include + +class KCoreConfigSkeleton; + +/* This class is a complete hack and should be removed when +* kconfig fixes the `settingsChanged` signal. +* it iterates over all the notify signals created by the +* kconfig compiler, and connects to the save() call. +* This code is based on the ManagedConfigModule of the KDeclarative. +*/ + +class AutoSettingsHandler : public QObject +{ + Q_OBJECT +public: + AutoSettingsHandler() = default; + void addSettings(KCoreConfigSkeleton* settings); + Q_SLOT void triggerSave(); + +private: + QList m_settings; +};