From 8c885bc699510df53955dd4b5dd0babaa73359cd Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Wed, 12 Oct 2022 12:00:12 -0400 Subject: [PATCH] quicksettings/record: Move record functions out of shellutil --- components/mobileshell/shellutil.cpp | 20 ----------- components/mobileshell/shellutil.h | 16 ++------- quicksettings/CMakeLists.txt | 2 +- quicksettings/record/CMakeLists.txt | 35 +++++++++++++++++++ .../{ => package/contents}/metadata.json | 0 .../record/{ => package}/contents/ui/main.qml | 7 ++-- quicksettings/record/qmldir | 7 ++++ quicksettings/record/recordplugin.cpp | 23 ++++++++++++ quicksettings/record/recordplugin.h | 21 +++++++++++ quicksettings/record/recordutil.cpp | 29 +++++++++++++++ quicksettings/record/recordutil.h | 31 ++++++++++++++++ 11 files changed, 153 insertions(+), 38 deletions(-) create mode 100644 quicksettings/record/CMakeLists.txt rename quicksettings/record/{ => package/contents}/metadata.json (100%) rename quicksettings/record/{ => package}/contents/ui/main.qml (81%) create mode 100644 quicksettings/record/qmldir create mode 100644 quicksettings/record/recordplugin.cpp create mode 100644 quicksettings/record/recordplugin.h create mode 100644 quicksettings/record/recordutil.cpp create mode 100644 quicksettings/record/recordutil.h diff --git a/components/mobileshell/shellutil.cpp b/components/mobileshell/shellutil.cpp index dfdffe4e..ccbe2a0f 100644 --- a/components/mobileshell/shellutil.cpp +++ b/components/mobileshell/shellutil.cpp @@ -87,23 +87,3 @@ void ShellUtil::launchApp(const QString &app) auto job = new KIO::ApplicationLauncherJob(appService, this); job->start(); } - -QString ShellUtil::videoLocation(const QString &name) -{ - QString path = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation); - QString newPath(path + '/' + name); - if (QFile::exists(newPath)) { - newPath = path + '/' + KFileUtils::suggestName(QUrl::fromLocalFile(newPath), name); - } - return newPath; -} - -void ShellUtil::showNotification(const QString &title, const QString &text, const QString &filePath) -{ - KNotification *notif = new KNotification("captured"); - notif->setComponentName(QStringLiteral("plasma_phone_components")); - notif->setTitle(title); - notif->setUrls({QUrl::fromLocalFile(filePath)}); - notif->setText(text); - notif->sendEvent(); -} diff --git a/components/mobileshell/shellutil.h b/components/mobileshell/shellutil.h index 3efa593a..af4a676e 100644 --- a/components/mobileshell/shellutil.h +++ b/components/mobileshell/shellutil.h @@ -21,7 +21,8 @@ class ShellUtil : public QObject { Q_OBJECT - Q_PROPERTY(bool isSystem24HourFormat READ isSystem24HourFormat NOTIFY isSystem24HourFormatChanged); + Q_PROPERTY(bool isSystem24HourFormat READ isSystem24HourFormat NOTIFY isSystem24HourFormatChanged) + Q_PROPERTY(bool launchingApp READ isLaunchingApp NOTIFY isLaunchingAppChanged) public: ShellUtil(QObject *parent = nullptr); @@ -62,19 +63,6 @@ public: */ Q_INVOKABLE bool isSystem24HourFormat(); - /** - * Allows us to get a filename in the standard videos directory (~/Videos by default) - * with a name that starts with @p name - * - * @returns a non-existing path that can be written into - * - * @see QStandardPaths::writableLocation() - * @see KFileUtil::suggestName() - */ - Q_INVOKABLE QString videoLocation(const QString &name); - - Q_INVOKABLE void showNotification(const QString &title, const QString &text, const QString &filePath); - Q_SIGNALS: void isSystem24HourFormatChanged(); diff --git a/quicksettings/CMakeLists.txt b/quicksettings/CMakeLists.txt index fb4adf88..6970e9a5 100644 --- a/quicksettings/CMakeLists.txt +++ b/quicksettings/CMakeLists.txt @@ -10,11 +10,11 @@ plasma_install_package(donotdisturb org.kde.plasma.quicksetting.donotdisturb qui plasma_install_package(keyboardtoggle org.kde.plasma.quicksetting.keyboardtoggle quicksettings) plasma_install_package(location org.kde.plasma.quicksetting.location quicksettings) plasma_install_package(mobiledata org.kde.plasma.quicksetting.mobiledata quicksettings) -plasma_install_package(record org.kde.plasma.quicksetting.record quicksettings) plasma_install_package(settingsapp org.kde.plasma.quicksetting.settingsapp quicksettings) plasma_install_package(wifi org.kde.plasma.quicksetting.wifi quicksettings) add_subdirectory(flashlight) add_subdirectory(nightcolor) add_subdirectory(powermenu) +add_subdirectory(record) add_subdirectory(screenshot) add_subdirectory(screenrotation) diff --git a/quicksettings/record/CMakeLists.txt b/quicksettings/record/CMakeLists.txt new file mode 100644 index 00000000..4024d392 --- /dev/null +++ b/quicksettings/record/CMakeLists.txt @@ -0,0 +1,35 @@ +# SPDX-FileCopyrightText: 2022 Devin Lin +# SPDX-License-Identifier: GPL-2.0-or-later + +set(recordplugin_SRCS + recordplugin.cpp + recordutil.cpp +) + +add_library(recordplugin ${recordplugin_SRCS}) + +find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS + Declarative + Notifications +) + +target_link_libraries(recordplugin + PUBLIC + Qt::Core + PRIVATE + Qt::DBus + KF5::CoreAddons + KF5::QuickAddons + KF5::ConfigCore + KF5::ConfigGui + KF5::I18n + KF5::Notifications +) + +set_property(TARGET recordplugin PROPERTY LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/quicksetting/record) +file(COPY qmldir DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/quicksetting/record) + +install(TARGETS recordplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/quicksetting/record) +install(FILES qmldir ${qml_SRC} DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/quicksetting/record) + +plasma_install_package(package org.kde.plasma.quicksetting.record quicksettings) diff --git a/quicksettings/record/metadata.json b/quicksettings/record/package/contents/metadata.json similarity index 100% rename from quicksettings/record/metadata.json rename to quicksettings/record/package/contents/metadata.json diff --git a/quicksettings/record/contents/ui/main.qml b/quicksettings/record/package/contents/ui/main.qml similarity index 81% rename from quicksettings/record/contents/ui/main.qml rename to quicksettings/record/package/contents/ui/main.qml index 787ef660..7ae65274 100644 --- a/quicksettings/record/contents/ui/main.qml +++ b/quicksettings/record/package/contents/ui/main.qml @@ -7,10 +7,11 @@ import QtQuick.Window 2.15 import org.kde.plasma.private.mobileshell 1.0 as MobileShell import org.kde.pipewire.record 0.1 as PWRec import org.kde.taskmanager 0.1 as TaskManager +import org.kde.plasma.quicksetting.record 1.0 MobileShell.QuickSetting { id: root - text: switch(record.state) { + text: switch (record.state) { case PWRec.PipeWireRecord.Idle: return i18n("Record Screen") case PWRec.PipeWireRecord.Recording: @@ -31,9 +32,9 @@ MobileShell.QuickSetting { function toggle() { if (!record.active) { - record.output = MobileShell.ShellUtil.videoLocation("screen-recording.mp4"); + record.output = RecordUtil.videoLocation("screen-recording.mp4"); } else { - MobileShell.ShellUtil.showNotification(i18n("New Screen Recording"), i18n("New Screen Recording saved in %1", record.output), record.output); + RecordUtil.showNotification(i18n("New Screen Recording"), i18n("New Screen Recording saved in %1", record.output), record.output); } enabled = !enabled diff --git a/quicksettings/record/qmldir b/quicksettings/record/qmldir new file mode 100644 index 00000000..955e8753 --- /dev/null +++ b/quicksettings/record/qmldir @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: 2022 Devin Lin +# SPDX-License-Identifier: GPL-2.0-or-later + +module org.kde.plasma.quicksetting.record +plugin recordplugin +classname RecordPlugin + diff --git a/quicksettings/record/recordplugin.cpp b/quicksettings/record/recordplugin.cpp new file mode 100644 index 00000000..92fccd66 --- /dev/null +++ b/quicksettings/record/recordplugin.cpp @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2022 by Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "recordplugin.h" + +#include +#include + +#include "recordutil.h" + +void RecordPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.quicksetting.record")); + + qmlRegisterSingletonType(uri, 1, 0, "RecordUtil", [](QQmlEngine *, QJSEngine *) { + return new RecordUtil; + }); +} + +//#include "moc_screenshotplugin.cpp" diff --git a/quicksettings/record/recordplugin.h b/quicksettings/record/recordplugin.h new file mode 100644 index 00000000..1892cd2f --- /dev/null +++ b/quicksettings/record/recordplugin.h @@ -0,0 +1,21 @@ +/* + * SPDX-FileCopyrightText: 2022 by Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#pragma once + +#include + +#include +#include + +class RecordPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) override; +}; diff --git a/quicksettings/record/recordutil.cpp b/quicksettings/record/recordutil.cpp new file mode 100644 index 00000000..f911327a --- /dev/null +++ b/quicksettings/record/recordutil.cpp @@ -0,0 +1,29 @@ +/* + * SPDX-FileCopyrightText: 2022 by Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "recordutil.h" + +#include + +QString RecordUtil::videoLocation(const QString &name) +{ + QString path = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation); + QString newPath(path + '/' + name); + if (QFile::exists(newPath)) { + newPath = path + '/' + KFileUtils::suggestName(QUrl::fromLocalFile(newPath), name); + } + return newPath; +} + +void RecordUtil::showNotification(const QString &title, const QString &text, const QString &filePath) +{ + KNotification *notif = new KNotification("captured"); + notif->setComponentName(QStringLiteral("plasma_phone_components")); + notif->setTitle(title); + notif->setUrls({QUrl::fromLocalFile(filePath)}); + notif->setText(text); + notif->sendEvent(); +} diff --git a/quicksettings/record/recordutil.h b/quicksettings/record/recordutil.h new file mode 100644 index 00000000..c29b956c --- /dev/null +++ b/quicksettings/record/recordutil.h @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2022 by Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#pragma once + +#include +#include + +class RecordUtil : public QObject +{ + Q_OBJECT + +public: + ScreenShotUtil(QObject *parent = nullptr); + + /** + * Allows us to get a filename in the standard videos directory (~/Videos by default) + * with a name that starts with @p name + * + * @returns a non-existing path that can be written into + * + * @see QStandardPaths::writableLocation() + * @see KFileUtil::suggestName() + */ + Q_INVOKABLE QString videoLocation(const QString &name); + + Q_INVOKABLE void showNotification(const QString &title, const QString &text, const QString &filePath); +};