diff --git a/CMakeLists.txt b/CMakeLists.txt index 99405d42..93009ac2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,11 @@ set_package_properties(KF5Wayland PROPERTIES TYPE REQUIRED PURPOSE "Required for interacting with the compositor") +# torch +find_package(GStreamer 1.1.90 REQUIRED) +find_package(GLIB2 REQUIRED) +find_package(GObject REQUIRED) + include(CheckIncludeFiles) plasma_install_package(look-and-feel org.kde.plasma.phone look-and-feel) diff --git a/cmake/FindGLIB2.cmake b/cmake/FindGLIB2.cmake new file mode 100644 index 00000000..ebd1c550 --- /dev/null +++ b/cmake/FindGLIB2.cmake @@ -0,0 +1,48 @@ +# - Try to find the GLIB2 libraries +# Once done this will define +# +# GLIB2_FOUND - system has glib2 +# GLIB2_INCLUDE_DIR - the glib2 include directory +# GLIB2_LIBRARIES - glib2 library + +# Copyright (c) 2008 Laurent Montel, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +if(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES) + # Already in cache, be silent + set(GLIB2_FIND_QUIETLY TRUE) +endif(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES) + +if (NOT WIN32) + find_package(PkgConfig REQUIRED) + pkg_check_modules(PKG_GLIB REQUIRED glib-2.0) +endif(NOT WIN32) + +find_path(GLIB2_MAIN_INCLUDE_DIR glib.h + PATH_SUFFIXES glib-2.0 + PATHS ${PKG_GLIB_INCLUDE_DIRS} ) + +# search the glibconfig.h include dir under the same root where the library is found +find_library(GLIB2_LIBRARIES + NAMES glib-2.0 + PATHS ${PKG_GLIB_LIBRARY_DIRS} ) + +find_path(GLIB2_INTERNAL_INCLUDE_DIR glibconfig.h + PATH_SUFFIXES glib-2.0/include ../lib/glib-2.0/include + PATHS ${PKG_GLIB_INCLUDE_DIRS} ${PKG_GLIB_LIBRARIES} ${CMAKE_SYSTEM_LIBRARY_PATH}) + +set(GLIB2_INCLUDE_DIR ${GLIB2_MAIN_INCLUDE_DIR}) + +# not sure if this include dir is optional or required +# for now it is optional +if(GLIB2_INTERNAL_INCLUDE_DIR) + set(GLIB2_INCLUDE_DIR ${GLIB2_INCLUDE_DIR} ${GLIB2_INTERNAL_INCLUDE_DIR}) +endif(GLIB2_INTERNAL_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GLIB2 DEFAULT_MSG GLIB2_LIBRARIES GLIB2_MAIN_INCLUDE_DIR) + +mark_as_advanced(GLIB2_INCLUDE_DIR GLIB2_LIBRARIES) diff --git a/cmake/FindGObject.cmake b/cmake/FindGObject.cmake new file mode 100644 index 00000000..af0c9f73 --- /dev/null +++ b/cmake/FindGObject.cmake @@ -0,0 +1,52 @@ +# - Try to find GObject +# Once done this will define +# +# GOBJECT_FOUND - system has GObject +# GOBJECT_INCLUDE_DIR - the GObject include directory +# GOBJECT_LIBRARIES - the libraries needed to use GObject +# GOBJECT_DEFINITIONS - Compiler switches required for using GObject + +# Copyright (c) 2011, Raphael Kubo da Costa +# Copyright (c) 2006, Tim Beaulen +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +FIND_PACKAGE(PkgConfig) +PKG_CHECK_MODULES(PC_GOBJECT gobject-2.0) +SET(GOBJECT_DEFINITIONS ${PC_GOBJECT_CFLAGS_OTHER}) + +FIND_PATH(GOBJECT_INCLUDE_DIR gobject.h + HINTS + ${PC_GOBJECT_INCLUDEDIR} + ${PC_GOBJECT_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0/gobject/ + ) + +FIND_LIBRARY(_GObjectLibs NAMES gobject-2.0 + HINTS + ${PC_GOBJECT_LIBDIR} + ${PC_GOBJECT_LIBRARY_DIRS} + ) +FIND_LIBRARY(_GModuleLibs NAMES gmodule-2.0 + HINTS + ${PC_GOBJECT_LIBDIR} + ${PC_GOBJECT_LIBRARY_DIRS} + ) +FIND_LIBRARY(_GThreadLibs NAMES gthread-2.0 + HINTS + ${PC_GOBJECT_LIBDIR} + ${PC_GOBJECT_LIBRARY_DIRS} + ) +FIND_LIBRARY(_GLibs NAMES glib-2.0 + HINTS + ${PC_GOBJECT_LIBDIR} + ${PC_GOBJECT_LIBRARY_DIRS} + ) + +SET( GOBJECT_LIBRARIES ${_GObjectLibs} ${_GModuleLibs} ${_GThreadLibs} ${_GLibs} ) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GOBJECT DEFAULT_MSG GOBJECT_LIBRARIES GOBJECT_INCLUDE_DIR) + +MARK_AS_ADVANCED(GOBJECT_INCLUDE_DIR _GObjectLibs _GModuleLibs _GThreadLibs _GLibs) diff --git a/cmake/FindGStreamer.cmake b/cmake/FindGStreamer.cmake new file mode 100644 index 00000000..83397fd1 --- /dev/null +++ b/cmake/FindGStreamer.cmake @@ -0,0 +1,72 @@ +# - Try to find GStreamer +# Once done this will define +# +# GSTREAMER_FOUND - system has GStreamer +# GSTREAMER_INCLUDE_DIR - the GStreamer include directory +# GSTREAMER_LIBRARY - the main GStreamer library +# GSTREAMER_PLUGIN_DIR - the GStreamer plugin directory +# +# And for all the plugin libraries specified in the COMPONENTS +# of find_package, this module will define: +# +# GSTREAMER__LIBRARY_FOUND - system has +# GSTREAMER__LIBRARY - the library +# GSTREAMER__INCLUDE_DIR - the include directory +# +# Copyright(c) 2010, Collabora Ltd. +# @author George Kiagiadakis +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +# TODO: Other versions --> GSTREAMER_X_Y_FOUND(Example: GSTREAMER_0_8_FOUND and GSTREAMER_0_10_FOUND etc) + +if(GSTREAMER_INCLUDE_DIR AND GSTREAMER_LIBRARIES AND GSTREAMER_BASE_LIBRARY) + # in cache already + set(GStreamer_FIND_QUIETLY TRUE) +else() + set(GStreamer_FIND_QUIETLY FALSE) +endif() + +set(GSTREAMER_API_VERSION 1.0) +if(NOT WIN32) + FIND_PACKAGE(PkgConfig REQUIRED) + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + # don't make this check required - otherwise you can't use macro_optional_find_package on this one + PKG_CHECK_MODULES(PKG_GSTREAMER gstreamer-${GSTREAMER_API_VERSION}) + set(GSTREAMER_VERSION ${PKG_GSTREAMER_VERSION}) + set(GSTREAMER_DEFINITIONS ${PKG_GSTREAMER_CFLAGS}) +endif() + +message(STATUS "Found GStreamer package: ${PKG_GSTREAMER_VERSION}") + +set(GSTREAMER_INCLUDE_DIR ${PKG_GSTREAMER_INCLUDE_DIRS}) + +find_library(GSTREAMER_LIBRARIES NAMES gstreamer-${GSTREAMER_API_VERSION} + PATHS + ${PKG_GSTREAMER_LIBRARY_DIRS} + ) + +find_library(GSTREAMER_BASE_LIBRARY NAMES gstbase-${GSTREAMER_API_VERSION} + PATHS + ${PKG_GSTREAMER_LIBRARY_DIRS} + ) + +find_library(GSTREAMER_VIDEO_LIBRARY NAMES gstvideo-${GSTREAMER_API_VERSION} + PATHS + ${PKG_GSTREAMER_LIBRARY_DIRS} + ) + +if(NOT GSTREAMER_INCLUDE_DIR) + message(STATUS "GStreamer: WARNING: include dir not found") +endif() + +if(NOT GSTREAMER_LIBRARIES) + message(STATUS "GStreamer: WARNING: library not found") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GStreamer DEFAULT_MSG GSTREAMER_LIBRARIES GSTREAMER_INCLUDE_DIR GSTREAMER_BASE_LIBRARY) + +mark_as_advanced(GSTREAMER_INCLUDE_DIR GSTREAMER_LIBRARIES GSTREAMER_BASE_LIBRARY) diff --git a/containments/panel/CMakeLists.txt b/containments/panel/CMakeLists.txt index c6a5a2e1..e3240305 100644 --- a/containments/panel/CMakeLists.txt +++ b/containments/panel/CMakeLists.txt @@ -9,8 +9,10 @@ kcoreaddons_desktop_to_json(plasma_applet_phonepanel package/metadata.desktop) target_link_libraries(plasma_applet_phonepanel Qt5::Gui KF5::Plasma - KF5::I18n) + KF5::I18n + ${GSTREAMER_LIBRARIES} ${GLIB2_LIBRARIES} ${GOBJECT_LIBRARIES}) +target_include_directories(plasma_applet_phonepanel PRIVATE "${GSTREAMER_INCLUDE_DIR}") install(TARGETS plasma_applet_phonepanel DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasma/applets) #install(FILES plasma-phonepanel-default.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/containments/panel/package/contents/ui/quicksettings/QuickSettings.qml b/containments/panel/package/contents/ui/quicksettings/QuickSettings.qml index d9cd6b97..f4fb50bf 100644 --- a/containments/panel/package/contents/ui/quicksettings/QuickSettings.qml +++ b/containments/panel/package/contents/ui/quicksettings/QuickSettings.qml @@ -29,13 +29,18 @@ Item { print("toggle airplane mode") } + function toggleTorch() { + plasmoid.nativeInterface.toggleTorch() + } + function addPlasmoid(applet, id) { settingsModel.append({"icon": applet.icon, "text": applet.title, "plasmoidId": id, "enabled": false, "applet": applet, - "settingsCommand": ""}) + "settingsCommand": "", + "toggleFunction": ""}); } signal plasmoidTriggered(var applet, var id) @@ -92,6 +97,7 @@ Item { "icon": "package_games_puzzle", "enabled": false, "settingsCommand": "", + "toggleFunction": "toggleTorch", "plasmoidId": -1, "applet": null }); diff --git a/containments/panel/phonepanel.cpp b/containments/panel/phonepanel.cpp index 9ba98d82..1a9c0e09 100644 --- a/containments/panel/phonepanel.cpp +++ b/containments/panel/phonepanel.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2015 Marco Martin * + * Copyright (C) 2018 Bhushan Shah * * * * 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 * @@ -38,6 +39,39 @@ void PhonePanel::executeCommand(const QString &command) QProcess::startDetached(command); } +void PhonePanel::toggleTorch() +{ + if (!m_running) { + gst_init(NULL, NULL); + // create elements + m_source = gst_element_factory_make("droidcamsrc", "source"); + m_sink = gst_element_factory_make("fakesink", "sink"); + m_pipeline = gst_pipeline_new("torch-pipeline"); + if (!m_pipeline || !m_source || !m_sink) { + qDebug() << "Failed to turn on torch: failed to create elements"; + return; + } + gst_bin_add_many(GST_BIN(m_pipeline), m_source, m_sink, NULL); + if (gst_element_link(m_source, m_sink) != TRUE) { + qDebug() << "Failed to turn on torch: failed to link source and sink"; + g_object_unref(m_pipeline); + return; + } + g_object_set(m_source, "mode", 2, NULL); + g_object_set(m_source, "video-torch", TRUE, NULL); + if (gst_element_set_state(m_pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { + qDebug() << "Failed to turn on torch: failed to start pipeline"; + g_object_unref(m_pipeline); + return; + } + m_running = true; + } else { + gst_element_set_state(m_pipeline, GST_STATE_NULL); + gst_object_unref(m_pipeline); + m_running = false; + } +} + K_EXPORT_PLASMA_APPLET_WITH_JSON(quicksettings, PhonePanel, "metadata.json") #include "phonepanel.moc" diff --git a/containments/panel/phonepanel.h b/containments/panel/phonepanel.h index 896b0054..f4d89ef5 100644 --- a/containments/panel/phonepanel.h +++ b/containments/panel/phonepanel.h @@ -24,6 +24,8 @@ #include +#include + class PhonePanel : public Plasma::Containment { @@ -35,9 +37,13 @@ public: public Q_SLOTS: void executeCommand(const QString &command); + void toggleTorch(); private: - + GstElement* m_pipeline; + GstElement* m_sink; + GstElement* m_source; + bool m_running = false; }; #endif