File indexing completed on 2024-05-12 05:36:09

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0003  *  SPDX-FileCopyrightText: 2021-2022 Devin Lin <devin@kde.org>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #pragma once
0009 
0010 #include <QObject>
0011 #include <QQuickItem>
0012 #include <qqmlregistration.h>
0013 
0014 #include <KConfigWatcher>
0015 #include <KIO/ApplicationLauncherJob>
0016 #include <KSharedConfig>
0017 
0018 /**
0019  * Miscellaneous class to put utility functions used in the shell.
0020  *
0021  * @author Devin Lin <devin@kde.org>
0022  **/
0023 class ShellUtil : public QObject
0024 {
0025     Q_OBJECT
0026     QML_ELEMENT
0027     QML_SINGLETON
0028     Q_PROPERTY(bool isSystem24HourFormat READ isSystem24HourFormat NOTIFY isSystem24HourFormatChanged)
0029 
0030 public:
0031     ShellUtil(QObject *parent = nullptr);
0032 
0033     /**
0034      * Change the stacking order to have the first item behind the second item.
0035      *
0036      * @param item1 The item to move behind.
0037      * @param item2 The item to move in front.
0038      */
0039     Q_INVOKABLE void stackItemBefore(QQuickItem *item1, QQuickItem *item2);
0040 
0041     /**
0042      * Change the stacking order to have the first item in front of the second item.
0043      *
0044      * @param item1 The item to move in front.
0045      * @param item2 The item to move behind.
0046      */
0047     Q_INVOKABLE void stackItemAfter(QQuickItem *item1, QQuickItem *item2);
0048 
0049     /**
0050      * Execute the command given.
0051      *
0052      * @param command The command to execute.
0053      */
0054     Q_INVOKABLE void executeCommand(const QString &command);
0055 
0056     /**
0057      * Launch an application by name.
0058      *
0059      * @param storageId The storage id of the application to launch.
0060      */
0061     Q_INVOKABLE void launchApp(const QString &storageId);
0062 
0063     /**
0064      * Whether the system is using 24 hour format.
0065      */
0066     Q_INVOKABLE bool isSystem24HourFormat();
0067 
0068 Q_SIGNALS:
0069     void isSystem24HourFormatChanged();
0070 
0071 private:
0072     KConfigWatcher::Ptr m_localeConfigWatcher;
0073     KSharedConfig::Ptr m_localeConfig;
0074 };