diff --git a/components/mobileshell/shellutil.cpp b/components/mobileshell/shellutil.cpp index 4438f99a..dfdffe4e 100644 --- a/components/mobileshell/shellutil.cpp +++ b/components/mobileshell/shellutil.cpp @@ -9,6 +9,7 @@ #include "shellutil.h" #include +#include #include #include #include @@ -86,3 +87,23 @@ 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 5ee3cf4e..3efa593a 100644 --- a/components/mobileshell/shellutil.h +++ b/components/mobileshell/shellutil.h @@ -62,6 +62,19 @@ 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 e4be4649..9cc20d54 100644 --- a/quicksettings/CMakeLists.txt +++ b/quicksettings/CMakeLists.txt @@ -9,6 +9,7 @@ plasma_install_package(caffeine org.kde.plasma.quicksetting.caffeine quicksettin 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) diff --git a/quicksettings/record/contents/ui/main.qml b/quicksettings/record/contents/ui/main.qml new file mode 100644 index 00000000..04913221 --- /dev/null +++ b/quicksettings/record/contents/ui/main.qml @@ -0,0 +1,52 @@ +// SPDX-FileCopyrightText: 2022 Devin Lin +// SPDX-License-Identifier: LGPL-2.0-or-later + +import QtQuick 2.15 +import QtQuick.Window 2.15 + +import org.kde.plasma.private.mobileshell 1.0 as MobileShell +import org.kde.pipewire 0.1 as PipeWire +import org.kde.pipewire.record 0.1 as PWRec + +MobileShell.QuickSetting { + id: root + text: switch(record.state) { + case PWRec.PipeWireRecord.Idle: + return i18n("Record") + case PWRec.PipeWireRecord.Recording: + return i18n("Recording...") + case PWRec.PipeWireRecord.Rendering: + i18n("Writing...") + } + status: switch(record.state) { + case PWRec.PipeWireRecord.Idle: + return i18n("Start Recording") + case PWRec.PipeWireRecord.Recording: + return i18n("Action! 📽️") + case PWRec.PipeWireRecord.Rendering: + i18n("Please wait...") + } + icon: "media-record" + enabled: false + + function toggle() { + if (!record.active) { + record.output = MobileShell.ShellUtil.videoLocation("screen-recording.mp4") + } else { + MobileShell.ShellUtil.showNotification(i18n("New Screen Recording"), i18n("New Screen Recording saved in %1", record.output), record.output); + } + enabled = !enabled + MobileShell.TopPanelControls.closeActionDrawer(); + } + + PWRec.PipeWireRecord { + id: record + nodeId: waylandItem.nodeId + active: root.enabled + + } + PipeWire.ScreencastingRequest { + id: waylandItem + outputName: root.enabled ? Screen.name : "" + } +} diff --git a/quicksettings/record/metadata.desktop b/quicksettings/record/metadata.desktop new file mode 100644 index 00000000..625014a9 --- /dev/null +++ b/quicksettings/record/metadata.desktop @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2022 Aleix Pol +# SPDX-License-Identifier: GPL-2.0-or-later + +[Desktop Entry] +Name=Screenshot +Icon=spectacle + +Type=Service +X-KDE-ServiceTypes=KPackage/GenericQML + +X-KDE-PluginInfo-Author=Aleix Pol i Gonzalez +X-KDE-PluginInfo-Email=aleixpol@kde.org +X-KDE-PluginInfo-Name=org.kde.plasma.quicksetting.record +X-KDE-PluginInfo-Version=0.1 +X-KDE-PluginInfo-Website=https://kde.org +X-KDE-PluginInfo-License=GPL-2.0+