Commit ecd15152 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

Add a Record QuickSetting

Allows to record the current output conveniently from the drop-down.
parent b0e2065a
......@@ -9,6 +9,7 @@
#include "shellutil.h"
#include <KConfigGroup>
#include <KFileUtils>
#include <KIO/ApplicationLauncherJob>
#include <KLocalizedString>
#include <KNotification>
......@@ -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();
}
......@@ -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();
......
......@@ -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)
......
// SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
// 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 : ""
}
}
# SPDX-FileCopyrightText: 2022 Aleix Pol <aleixpol@kde.org>
# 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+
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment