summaryrefslogtreecommitdiff
path: root/src/plugins/peace
diff options
context:
space:
mode:
authorMatthew Fennell <matthew@fennell.dev>2025-12-27 12:40:20 +0000
committerMatthew Fennell <matthew@fennell.dev>2025-12-27 12:40:20 +0000
commit5d8e439bc597159e3c9f0a8b65c0ae869dead3a8 (patch)
treeed28aefed8add0da1c55c08fdf80b23c4346e0dc /src/plugins/peace
Import Upstream version 43.0upstream/latest
Diffstat (limited to 'src/plugins/peace')
-rw-r--r--src/plugins/peace/gtd-peace-omni-area-addin.c209
-rw-r--r--src/plugins/peace/gtd-peace-omni-area-addin.h30
-rw-r--r--src/plugins/peace/meson.build12
-rw-r--r--src/plugins/peace/peace-plugin.c31
-rw-r--r--src/plugins/peace/peace.gresource.xml6
-rw-r--r--src/plugins/peace/peace.plugin12
6 files changed, 300 insertions, 0 deletions
diff --git a/src/plugins/peace/gtd-peace-omni-area-addin.c b/src/plugins/peace/gtd-peace-omni-area-addin.c
new file mode 100644
index 0000000..77c4e25
--- /dev/null
+++ b/src/plugins/peace/gtd-peace-omni-area-addin.c
@@ -0,0 +1,209 @@
+/* gtd-peace-omni-area-addin.c
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "gtd-peace-omni-area-addin.h"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#define MESSAGE_ID "peace-message-id"
+
+#define SWITCH_MESSAGE_TIMEOUT 20 * 60
+#define REMOVE_MESSAGE_TIMEOUT 1 * 60
+
+struct _GtdPeaceOmniAreaAddin
+{
+ GObject parent;
+
+ GtdOmniArea *omni_area;
+
+ guint timeout_id;
+};
+
+static gboolean switch_message_cb (gpointer user_data);
+
+static void gtd_omni_area_addin_iface_init (GtdOmniAreaAddinInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtdPeaceOmniAreaAddin, gtd_peace_omni_area_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (GTD_TYPE_OMNI_AREA_ADDIN, gtd_omni_area_addin_iface_init))
+
+typedef struct
+{
+ const gchar *text;
+ const gchar *icon_name;
+} str_pair;
+
+const str_pair mindful_questions[] =
+{
+ { N_("Did you drink some water today?"), NULL },
+ { N_("What are your goals for today?"), NULL },
+ { N_("Can you let your creativity flow?"), NULL },
+ { N_("How are you feeling right now?"), NULL },
+ { N_("At what point is it good enough?"), NULL },
+};
+
+const str_pair reminders[] =
+{
+ { N_("Remember to breathe. Good. Don't stop."), NULL },
+ { N_("Don't forget to drink some water"), NULL },
+ { N_("Remember to take some time off"), NULL },
+ { N_("Eat fruits if you can 🍐️"), NULL },
+ { N_("Take care of yourself"), NULL },
+ { N_("Remember to have some fun"), NULL },
+ { N_("You're doing great"), NULL },
+};
+
+const str_pair inspiring_quotes[] =
+{
+ { N_("Smile, breathe and go slowly"), NULL },
+ { N_("Wherever you go, there you are"), NULL },
+ { N_("Working hard is always rewarded"), NULL },
+ { N_("Keep calm"), NULL },
+ { N_("You can do it"), NULL },
+ { N_("Meanwhile, spread the love ♥️"), NULL },
+};
+
+
+/*
+ * Callbacks
+ */
+
+static gboolean
+remove_message_cb (gpointer user_data)
+{
+ GtdPeaceOmniAreaAddin *self = GTD_PEACE_OMNI_AREA_ADDIN (user_data);
+ gint factor = g_random_int_range (2, 6);
+
+ gtd_omni_area_withdraw_message (self->omni_area, MESSAGE_ID);
+
+ self->timeout_id = g_timeout_add_seconds (SWITCH_MESSAGE_TIMEOUT * factor, switch_message_cb, self);
+
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean
+switch_message_cb (gpointer user_data)
+{
+ GtdPeaceOmniAreaAddin *self;
+ g_autoptr (GIcon) icon = NULL;
+ const gchar *message;
+ const gchar *icon_name;
+ gint source;
+
+ self = GTD_PEACE_OMNI_AREA_ADDIN (user_data);
+ source = g_random_int_range (0, 3);
+
+ if (source == 0)
+ {
+ gint i = g_random_int_range (0, G_N_ELEMENTS (mindful_questions));
+
+ message = gettext (mindful_questions[i].text);
+ icon_name = mindful_questions[i].icon_name;
+ }
+ else if (source == 1)
+ {
+ gint i = g_random_int_range (0, G_N_ELEMENTS (reminders));
+
+ message = gettext (reminders[i].text);
+ icon_name = reminders[i].icon_name;
+ }
+ else
+ {
+ gint i = g_random_int_range (0, G_N_ELEMENTS (inspiring_quotes));
+
+ message = gettext (inspiring_quotes[i].text);
+ icon_name = inspiring_quotes[i].icon_name;
+ }
+
+ if (icon_name)
+ icon = g_themed_icon_new (icon_name);
+
+ gtd_omni_area_withdraw_message (self->omni_area, MESSAGE_ID);
+ gtd_omni_area_push_message (self->omni_area, MESSAGE_ID, message, NULL);
+
+ self->timeout_id = g_timeout_add_seconds (REMOVE_MESSAGE_TIMEOUT, remove_message_cb, self);
+
+ return G_SOURCE_REMOVE;
+}
+
+
+/*
+ * GtdOmniAreaAddin iface
+ */
+
+static void
+gtd_today_omni_area_addin_omni_area_addin_load (GtdOmniAreaAddin *addin,
+ GtdOmniArea *omni_area)
+{
+ GtdPeaceOmniAreaAddin *self = GTD_PEACE_OMNI_AREA_ADDIN (addin);
+
+ self->omni_area = omni_area;
+
+ g_clear_handle_id (&self->timeout_id, g_source_remove);
+ self->timeout_id = g_timeout_add_seconds (SWITCH_MESSAGE_TIMEOUT, switch_message_cb, self);
+}
+
+static void
+gtd_today_omni_area_addin_omni_area_addin_unload (GtdOmniAreaAddin *addin,
+ GtdOmniArea *omni_area)
+{
+ GtdPeaceOmniAreaAddin *self = GTD_PEACE_OMNI_AREA_ADDIN (addin);
+
+ gtd_omni_area_withdraw_message (omni_area, MESSAGE_ID);
+
+ g_clear_handle_id (&self->timeout_id, g_source_remove);
+ self->omni_area = NULL;
+}
+
+static void
+gtd_omni_area_addin_iface_init (GtdOmniAreaAddinInterface *iface)
+{
+ iface->load = gtd_today_omni_area_addin_omni_area_addin_load;
+ iface->unload = gtd_today_omni_area_addin_omni_area_addin_unload;
+}
+
+
+/*
+ * GObject overrides
+ */
+
+static void
+gtd_peace_omni_area_addin_finalize (GObject *object)
+{
+ GtdPeaceOmniAreaAddin *self = (GtdPeaceOmniAreaAddin *)object;
+
+ g_clear_handle_id (&self->timeout_id, g_source_remove);
+
+ G_OBJECT_CLASS (gtd_peace_omni_area_addin_parent_class)->finalize (object);
+}
+
+static void
+gtd_peace_omni_area_addin_class_init (GtdPeaceOmniAreaAddinClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gtd_peace_omni_area_addin_finalize;
+}
+
+static void
+gtd_peace_omni_area_addin_init (GtdPeaceOmniAreaAddin *self)
+{
+}
diff --git a/src/plugins/peace/gtd-peace-omni-area-addin.h b/src/plugins/peace/gtd-peace-omni-area-addin.h
new file mode 100644
index 0000000..8b83653
--- /dev/null
+++ b/src/plugins/peace/gtd-peace-omni-area-addin.h
@@ -0,0 +1,30 @@
+/* gtd-peace-omni-area-addin.h
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "endeavour.h"
+
+G_BEGIN_DECLS
+
+#define GTD_TYPE_PEACE_OMNI_AREA_ADDIN (gtd_peace_omni_area_addin_get_type())
+G_DECLARE_FINAL_TYPE (GtdPeaceOmniAreaAddin, gtd_peace_omni_area_addin, GTD, PEACE_OMNI_AREA_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/peace/meson.build b/src/plugins/peace/meson.build
new file mode 100644
index 0000000..3cba81b
--- /dev/null
+++ b/src/plugins/peace/meson.build
@@ -0,0 +1,12 @@
+plugins_ldflags += ['-Wl,--undefined=peace_plugin_register_types']
+
+plugins_sources += files(
+ 'gtd-peace-omni-area-addin.c',
+ 'peace-plugin.c',
+)
+
+plugins_sources += gnome.compile_resources(
+ 'peace-resources',
+ 'peace.gresource.xml',
+ c_name: 'peace_plugin',
+)
diff --git a/src/plugins/peace/peace-plugin.c b/src/plugins/peace/peace-plugin.c
new file mode 100644
index 0000000..5ece6fa
--- /dev/null
+++ b/src/plugins/peace/peace-plugin.c
@@ -0,0 +1,31 @@
+/* zen-plugin.c
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <libpeas/peas.h>
+
+#include "gtd-peace-omni-area-addin.h"
+
+G_MODULE_EXPORT void
+peace_plugin_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module,
+ GTD_TYPE_OMNI_AREA_ADDIN,
+ GTD_TYPE_PEACE_OMNI_AREA_ADDIN);
+}
diff --git a/src/plugins/peace/peace.gresource.xml b/src/plugins/peace/peace.gresource.xml
new file mode 100644
index 0000000..13132ed
--- /dev/null
+++ b/src/plugins/peace/peace.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/todo/plugins/peace">
+ <file>peace.plugin</file>
+ </gresource>
+</gresources>
diff --git a/src/plugins/peace/peace.plugin b/src/plugins/peace/peace.plugin
new file mode 100644
index 0000000..d7e85ea
--- /dev/null
+++ b/src/plugins/peace/peace.plugin
@@ -0,0 +1,12 @@
+[Plugin]
+Name = Peace
+Module = peace
+Description = Smile, breathe and go slowly
+Authors = Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
+Copyright = Copyleft © The Endeavour maintainers
+Website = https://wiki.gnome.org/Apps/Todo
+Builtin = true
+License = GPL
+Loader = C
+Embedded = peace_plugin_register_types
+Depends =