summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/toaster.hpp
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-09-21 17:34:55 +1000
committerGitHub <noreply@github.com>2025-09-21 17:34:55 +1000
commit37b61cb0d923bc8ab988a0ba4174cd55de458bdc (patch)
treeee4808009110c6e85540b4b6d0f0b947b3f80d25 /plugin/src/Caelestia/toaster.hpp
parentsidebar/notifs: add link support (diff)
parentfeat: add battery warnings (diff)
downloadcaelestia-shell-37b61cb0d923bc8ab988a0ba4174cd55de458bdc.tar.gz
caelestia-shell-37b61cb0d923bc8ab988a0ba4174cd55de458bdc.tar.bz2
caelestia-shell-37b61cb0d923bc8ab988a0ba4174cd55de458bdc.zip
Merge pull request #662 from caelestia-dots/toasts
utilities: add toasts & battery warnings
Diffstat (limited to 'plugin/src/Caelestia/toaster.hpp')
-rw-r--r--plugin/src/Caelestia/toaster.hpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/plugin/src/Caelestia/toaster.hpp b/plugin/src/Caelestia/toaster.hpp
new file mode 100644
index 0000000..22da212
--- /dev/null
+++ b/plugin/src/Caelestia/toaster.hpp
@@ -0,0 +1,81 @@
+#pragma once
+
+#include <qobject.h>
+#include <qqmlintegration.h>
+#include <qset.h>
+
+namespace caelestia {
+
+class Toast : public QObject {
+ Q_OBJECT
+ QML_ELEMENT
+ QML_UNCREATABLE("Toast instances can only be retrieved from a Toaster")
+
+ Q_PROPERTY(bool closed READ closed NOTIFY closedChanged)
+ Q_PROPERTY(QString title READ title CONSTANT)
+ Q_PROPERTY(QString message READ message CONSTANT)
+ Q_PROPERTY(QString icon READ icon CONSTANT)
+ Q_PROPERTY(int timeout READ timeout CONSTANT)
+ Q_PROPERTY(Type type READ type CONSTANT)
+
+public:
+ enum class Type {
+ Info = 0,
+ Success,
+ Warning,
+ Error
+ };
+ Q_ENUM(Type)
+
+ explicit Toast(const QString& title, const QString& message, const QString& icon, Type type, int timeout,
+ QObject* parent = nullptr);
+
+ [[nodiscard]] bool closed() const;
+ [[nodiscard]] QString title() const;
+ [[nodiscard]] QString message() const;
+ [[nodiscard]] QString icon() const;
+ [[nodiscard]] int timeout() const;
+ [[nodiscard]] Type type() const;
+
+ Q_INVOKABLE void close();
+ Q_INVOKABLE void lock(QObject* sender);
+ Q_INVOKABLE void unlock(QObject* sender);
+
+signals:
+ void closedChanged();
+ void finishedClose();
+
+private:
+ QSet<QObject*> m_locks;
+
+ bool m_closed;
+ QString m_title;
+ QString m_message;
+ QString m_icon;
+ Type m_type;
+ int m_timeout;
+};
+
+class Toaster : public QObject {
+ Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+
+ Q_PROPERTY(QList<Toast*> toasts READ toasts NOTIFY toastsChanged)
+
+public:
+ explicit Toaster(QObject* parent = nullptr);
+
+ [[nodiscard]] QList<Toast*> toasts() const;
+
+ Q_INVOKABLE void toast(const QString& title, const QString& message, const QString& icon = QString(),
+ Toast::Type type = Toast::Type::Info, int timeout = 5000);
+
+signals:
+ void toastsChanged();
+
+private:
+ QList<Toast*> m_toasts;
+};
+
+} // namespace caelestia