quicksettings/record: Move record functions out of shellutil

This commit is contained in:
Devin Lin 2022-10-12 12:00:12 -04:00
parent af1b947d52
commit 8c885bc699
11 changed files with 153 additions and 38 deletions

View file

@ -87,23 +87,3 @@ void ShellUtil::launchApp(const QString &app)
auto job = new KIO::ApplicationLauncherJob(appService, this); auto job = new KIO::ApplicationLauncherJob(appService, this);
job->start(); 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();
}

View file

@ -21,7 +21,8 @@
class ShellUtil : public QObject class ShellUtil : public QObject
{ {
Q_OBJECT 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: public:
ShellUtil(QObject *parent = nullptr); ShellUtil(QObject *parent = nullptr);
@ -62,19 +63,6 @@ public:
*/ */
Q_INVOKABLE bool isSystem24HourFormat(); 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: Q_SIGNALS:
void isSystem24HourFormatChanged(); void isSystem24HourFormatChanged();

View file

@ -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(keyboardtoggle org.kde.plasma.quicksetting.keyboardtoggle quicksettings)
plasma_install_package(location org.kde.plasma.quicksetting.location quicksettings) plasma_install_package(location org.kde.plasma.quicksetting.location quicksettings)
plasma_install_package(mobiledata org.kde.plasma.quicksetting.mobiledata 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(settingsapp org.kde.plasma.quicksetting.settingsapp quicksettings)
plasma_install_package(wifi org.kde.plasma.quicksetting.wifi quicksettings) plasma_install_package(wifi org.kde.plasma.quicksetting.wifi quicksettings)
add_subdirectory(flashlight) add_subdirectory(flashlight)
add_subdirectory(nightcolor) add_subdirectory(nightcolor)
add_subdirectory(powermenu) add_subdirectory(powermenu)
add_subdirectory(record)
add_subdirectory(screenshot) add_subdirectory(screenshot)
add_subdirectory(screenrotation) add_subdirectory(screenrotation)

View file

@ -0,0 +1,35 @@
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# 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)

View file

@ -7,10 +7,11 @@ import QtQuick.Window 2.15
import org.kde.plasma.private.mobileshell 1.0 as MobileShell import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import org.kde.pipewire.record 0.1 as PWRec import org.kde.pipewire.record 0.1 as PWRec
import org.kde.taskmanager 0.1 as TaskManager import org.kde.taskmanager 0.1 as TaskManager
import org.kde.plasma.quicksetting.record 1.0
MobileShell.QuickSetting { MobileShell.QuickSetting {
id: root id: root
text: switch(record.state) { text: switch (record.state) {
case PWRec.PipeWireRecord.Idle: case PWRec.PipeWireRecord.Idle:
return i18n("Record Screen") return i18n("Record Screen")
case PWRec.PipeWireRecord.Recording: case PWRec.PipeWireRecord.Recording:
@ -31,9 +32,9 @@ MobileShell.QuickSetting {
function toggle() { function toggle() {
if (!record.active) { if (!record.active) {
record.output = MobileShell.ShellUtil.videoLocation("screen-recording.mp4"); record.output = RecordUtil.videoLocation("screen-recording.mp4");
} else { } 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 enabled = !enabled

View file

@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later
module org.kde.plasma.quicksetting.record
plugin recordplugin
classname RecordPlugin

View file

@ -0,0 +1,23 @@
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "recordplugin.h"
#include <QQmlContext>
#include <QQuickItem>
#include "recordutil.h"
void RecordPlugin::registerTypes(const char *uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.quicksetting.record"));
qmlRegisterSingletonType<RecordUtil>(uri, 1, 0, "RecordUtil", [](QQmlEngine *, QJSEngine *) {
return new RecordUtil;
});
}
//#include "moc_screenshotplugin.cpp"

View file

@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QUrl>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
class RecordPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char *uri) override;
};

View file

@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "recordutil.h"
#include <KNotification>
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();
}

View file

@ -0,0 +1,31 @@
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QObject>
#include <QVariantMap>
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);
};