[gnome-todo] Move workspace handling to extension set
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] Move workspace handling to extension set
- Date: Sat, 2 May 2020 02:11:50 +0000 (UTC)
commit a79bf98d0bbd269e7967d044072b33d17fc0f7ba
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri May 1 10:44:54 2020 -0300
Move workspace handling to extension set
.../gtd-plugin-task-lists-workspace.c | 25 +----
.../gtd-task-lists-workspace.c | 6 +-
src/engine/gtd-manager.c | 110 ---------------------
src/engine/gtd-manager.h | 8 --
src/gtd-window.c | 57 +++++++----
5 files changed, 47 insertions(+), 159 deletions(-)
---
diff --git a/plugins/task-lists-workspace/gtd-plugin-task-lists-workspace.c
b/plugins/task-lists-workspace/gtd-plugin-task-lists-workspace.c
index 8443424..0361793 100644
--- a/plugins/task-lists-workspace/gtd-plugin-task-lists-workspace.c
+++ b/plugins/task-lists-workspace/gtd-plugin-task-lists-workspace.c
@@ -31,8 +31,6 @@
struct _GtdPluginTaskListsWorkspace
{
PeasExtensionBase parent;
-
- GtdWorkspace *task_list_workspaces;
};
static void gtd_activatable_iface_init (GtdActivatableInterface *iface);
@@ -59,17 +57,11 @@ enum
static void
gtd_plugin_task_lists_workspace_activate (GtdActivatable *activatable)
{
- GtdPluginTaskListsWorkspace *self = GTD_PLUGIN_TASK_LISTS_WORKSPACE (activatable);
-
- gtd_manager_add_workspace (gtd_manager_get_default (), self->task_list_workspaces);
}
static void
gtd_plugin_task_lists_workspace_deactivate (GtdActivatable *activatable)
{
- GtdPluginTaskListsWorkspace *self = GTD_PLUGIN_TASK_LISTS_WORKSPACE (activatable);
-
- gtd_manager_remove_workspace (gtd_manager_get_default (), self->task_list_workspaces);
}
static GList*
@@ -100,16 +92,6 @@ gtd_activatable_iface_init (GtdActivatableInterface *iface)
iface->get_providers = gtd_plugin_task_lists_workspace_get_providers;
}
-static void
-gtd_plugin_task_lists_workspace_finalize (GObject *object)
-{
- GtdPluginTaskListsWorkspace *self = (GtdPluginTaskListsWorkspace *)object;
-
- g_clear_object (&self->task_list_workspaces);
-
- G_OBJECT_CLASS (gtd_plugin_task_lists_workspace_parent_class)->finalize (object);
-}
-
static void
gtd_plugin_task_lists_workspace_get_property (GObject *object,
guint prop_id,
@@ -132,7 +114,6 @@ gtd_plugin_task_lists_workspace_class_init (GtdPluginTaskListsWorkspaceClass *kl
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = gtd_plugin_task_lists_workspace_finalize;
object_class->get_property = gtd_plugin_task_lists_workspace_get_property;
g_object_class_override_property (object_class, PROP_PREFERENCES_PANEL, "preferences-panel");
@@ -142,8 +123,6 @@ static void
gtd_plugin_task_lists_workspace_init (GtdPluginTaskListsWorkspace *self)
{
g_resources_register (task_lists_workspace_get_resource ());
-
- self->task_list_workspaces = gtd_task_lists_workspace_new ();
}
static void
@@ -160,4 +139,8 @@ gtd_plugin_task_lists_workspace_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
GTD_TYPE_ACTIVATABLE,
GTD_TYPE_PLUGIN_TASK_LISTS_WORKSPACE);
+
+ peas_object_module_register_extension_type (module,
+ GTD_TYPE_WORKSPACE,
+ GTD_TYPE_TASK_LISTS_WORKSPACE);
}
diff --git a/plugins/task-lists-workspace/gtd-task-lists-workspace.c
b/plugins/task-lists-workspace/gtd-task-lists-workspace.c
index b6e3aa5..f073a7d 100644
--- a/plugins/task-lists-workspace/gtd-task-lists-workspace.c
+++ b/plugins/task-lists-workspace/gtd-task-lists-workspace.c
@@ -347,9 +347,11 @@ gtd_task_lists_workspace_destroy (GtkWidget *widget)
{
GtdTaskListsWorkspace *self = (GtdTaskListsWorkspace *)widget;
- g_clear_object (&self->panels_set);
-
GTK_WIDGET_CLASS (gtd_task_lists_workspace_parent_class)->destroy (widget);
+
+ g_signal_handlers_disconnect_by_func (self->panels_set, on_panel_added_cb, self);
+ g_signal_handlers_disconnect_by_func (self->panels_set, on_panel_removed_cb, self);
+ g_clear_object (&self->panels_set);
}
diff --git a/src/engine/gtd-manager.c b/src/engine/gtd-manager.c
index 4bed2f0..2fe2423 100644
--- a/src/engine/gtd-manager.c
+++ b/src/engine/gtd-manager.c
@@ -61,7 +61,6 @@ struct _GtdManager
GListModel *tasks_model;
GListModel *unarchived_tasks_model;
- GHashTable *workspaces;
GList *providers;
GtdProvider *default_provider;
GtdClock *clock;
@@ -83,8 +82,6 @@ enum
SHOW_NOTIFICATION,
PROVIDER_ADDED,
PROVIDER_REMOVED,
- WORKSPACE_ADDED,
- WORKSPACE_REMOVED,
NUM_SIGNALS
};
@@ -317,8 +314,6 @@ gtd_manager_finalize (GObject *object)
g_clear_object (&self->unarchived_tasks_model);
g_clear_object (&self->lists_model);
- g_clear_pointer (&self->workspaces, g_hash_table_destroy);
-
G_OBJECT_CLASS (gtd_manager_parent_class)->finalize (object);
}
@@ -557,49 +552,12 @@ gtd_manager_class_init (GtdManagerClass *klass)
G_TYPE_NONE,
1,
GTD_TYPE_PROVIDER);
-
- /**
- * GtdManager::workspace-added:
- * @manager: a #GtdManager
- * @workspace: a #GtdWorkspace
- *
- * Emitted after @workspace is ADDED.
- */
- signals[WORKSPACE_ADDED] = g_signal_new ("workspace-added",
- GTD_TYPE_MANAGER,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- NULL,
- G_TYPE_NONE,
- 1,
- GTD_TYPE_WORKSPACE);
-
- /**
- * GtdManager::workspace-removed:
- * @manager: a #GtdManager
- * @workspace: a #GtdWorkspace
- *
- * Emitted after @workspace is removed.
- */
- signals[WORKSPACE_REMOVED] = g_signal_new ("workspace-removed",
- GTD_TYPE_MANAGER,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- NULL,
- G_TYPE_NONE,
- 1,
- GTD_TYPE_WORKSPACE);
}
static void
gtd_manager_init (GtdManager *self)
{
- self->workspaces = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL);
self->settings = g_settings_new ("org.gnome.todo");
self->plugin_manager = gtd_plugin_manager_new ();
self->clock = gtd_clock_new ();
@@ -889,74 +847,6 @@ gtd_manager_get_tasks_model (GtdManager *self)
return self->unarchived_tasks_model;
}
-/**
- * gtd_manager_get_workspaces:
- * @self: a #GtdManager
- *
- * Retrieves the current list of workspaces.
- *
- * Returns: (transfer full): a #GPtrArray
- */
-GPtrArray*
-gtd_manager_get_workspaces (GtdManager *self)
-{
- g_autoptr (GPtrArray) workspaces = NULL;
- g_autoptr (GList) keys = NULL;
- GList *l;
-
- g_return_val_if_fail (GTD_IS_MANAGER (self), NULL);
-
- workspaces = g_ptr_array_new_with_free_func (g_object_unref);
- keys = g_hash_table_get_keys (self->workspaces);
-
- for (l = keys; l; l = l->next)
- g_ptr_array_add (workspaces, g_object_ref (l->data));
-
- return g_steal_pointer (&workspaces);
-}
-
-/**
- * gtd_manager_add_workspace:
- * @self: a #GtdManager
- * @workspace: a #GtdWorkspace
- *
- * Adds @workspace to the list of workspace. If @workspace
- * is already added, does nothing.
- */
-void
-gtd_manager_add_workspace (GtdManager *self,
- GtdWorkspace *workspace)
-{
- g_return_if_fail (GTD_IS_MANAGER (self));
- g_return_if_fail (GTD_IS_WORKSPACE (workspace));
-
- if (g_hash_table_add (self->workspaces, g_object_ref (workspace)))
- g_signal_emit (self, signals[WORKSPACE_ADDED], 0, workspace);
-}
-
-/**
- * gtd_manager_remove_workspace:
- * @self: a #GtdManager
- * @workspace: a #GtdWorkspace
- *
- * Removes @workspace from the list of workspace. If @workspace
- * is not added, does nothing.
- */
-void
-gtd_manager_remove_workspace (GtdManager *self,
- GtdWorkspace *workspace)
-{
- g_return_if_fail (GTD_IS_MANAGER (self));
- g_return_if_fail (GTD_IS_WORKSPACE (workspace));
-
- g_object_ref (workspace);
-
- if (g_hash_table_remove (self->workspaces, workspace))
- g_signal_emit (self, signals[WORKSPACE_REMOVED], 0, workspace);
-
- g_object_unref (workspace);
-}
-
void
gtd_manager_load_plugins (GtdManager *self)
{
diff --git a/src/engine/gtd-manager.h b/src/engine/gtd-manager.h
index 5214325..6294cbf 100644
--- a/src/engine/gtd-manager.h
+++ b/src/engine/gtd-manager.h
@@ -73,12 +73,4 @@ GListModel* gtd_manager_get_all_tasks_model (GtdManager
GListModel* gtd_manager_get_tasks_model (GtdManager *self);
-GPtrArray* gtd_manager_get_workspaces (GtdManager *self);
-
-void gtd_manager_add_workspace (GtdManager *self,
- GtdWorkspace *workspace);
-
-void gtd_manager_remove_workspace (GtdManager *self,
- GtdWorkspace *workspace);
-
G_END_DECLS
diff --git a/src/gtd-window.c b/src/gtd-window.c
index bfa2ad4..9d08267 100644
--- a/src/gtd-window.c
+++ b/src/gtd-window.c
@@ -41,6 +41,7 @@
#include "gtd-window-private.h"
#include <glib/gi18n.h>
+#include <libpeas/peas.h>
/**
* SECTION:gtd-window
@@ -77,6 +78,8 @@ struct _GtdWindow
GtdWorkspace *current_workspace;
GListStore *workspaces;
+ PeasExtensionSet *workspaces_set;
+
guint toggle_headerbar_revealer_id;
};
@@ -367,9 +370,11 @@ on_stack_visible_child_cb (GtkStack *stack,
gtd_workspace_deactivate (self->current_workspace);
new_workspace = GTD_WORKSPACE (gtk_stack_get_visible_child (stack));
- g_assert (new_workspace != NULL);
-
self->current_workspace = new_workspace;
+
+ if (!new_workspace)
+ GTD_RETURN ();
+
gtd_workspace_activate (new_workspace);
workspace_icon = gtd_workspace_get_icon (new_workspace);
@@ -425,9 +430,10 @@ on_show_notification_cb (GtdManager *manager,
}
static void
-on_manager_workspace_added_cb (GtdManager *manager,
- GtdWorkspace *workspace,
- GtdWindow *self)
+on_workspace_added_cb (PeasExtensionSet *extension_set,
+ PeasPluginInfo *plugin_info,
+ GtdWorkspace *workspace,
+ GtdWindow *self)
{
GTD_ENTRY;
@@ -437,9 +443,10 @@ on_manager_workspace_added_cb (GtdManager *manager,
}
static void
-on_manager_workspace_removed_cb (GtdManager *manager,
- GtdWorkspace *workspace,
- GtdWindow *self)
+on_workspace_removed_cb (PeasExtensionSet *extension_set,
+ PeasPluginInfo *plugin_info,
+ GtdWorkspace *workspace,
+ GtdWindow *self)
{
GTD_ENTRY;
@@ -496,6 +503,16 @@ create_workspace_row_func (gpointer item,
* GtkWindow overrides
*/
+static void
+gtd_window_destroy (GtkWidget *widget)
+{
+ GtdWindow *self = GTD_WINDOW (widget);
+
+ g_clear_object (&self->workspaces_set);
+
+ GTK_WIDGET_CLASS (gtd_window_parent_class)->destroy (widget);
+}
+
static void
gtd_window_unmap (GtkWidget *widget)
{
@@ -526,23 +543,21 @@ gtd_window_unmap (GtkWidget *widget)
*/
static void
-gtd_window_dispose (GObject *object)
+gtd_window_finalize (GObject *object)
{
GtdWindow *self = GTD_WINDOW (object);
g_clear_handle_id (&self->toggle_headerbar_revealer_id, g_source_remove);
g_clear_object (&self->workspaces);
- G_OBJECT_CLASS (gtd_window_parent_class)->dispose (object);
+ G_OBJECT_CLASS (gtd_window_parent_class)->finalize (object);
}
static void
gtd_window_constructed (GObject *object)
{
- g_autoptr (GPtrArray) workspaces = NULL;
GtdManager *manager;
GtdWindow *self;
- guint i;
self = GTD_WINDOW (object);
@@ -556,13 +571,18 @@ gtd_window_constructed (GObject *object)
g_signal_connect (manager, "show-notification", G_CALLBACK (on_show_notification_cb), self);
/* Workspaces */
- workspaces = gtd_manager_get_workspaces (manager);
+ self->workspaces_set = peas_extension_set_new (peas_engine_get_default (),
+ GTD_TYPE_WORKSPACE,
+ NULL);
- for (i = 0; i < workspaces->len; i++)
- add_workspace (self, g_ptr_array_index (workspaces, i));
+ peas_extension_set_foreach (self->workspaces_set,
+ (PeasExtensionSetForeachFunc) on_workspace_added_cb,
+ self);
- g_signal_connect (manager, "workspace-added", G_CALLBACK (on_manager_workspace_added_cb), self);
- g_signal_connect (manager, "workspace-removed", G_CALLBACK (on_manager_workspace_removed_cb), self);
+ g_object_connect (self->workspaces_set,
+ "signal::extension-added", G_CALLBACK (on_workspace_added_cb), self,
+ "signal::extension-removed", G_CALLBACK (on_workspace_removed_cb), self,
+ NULL);
}
static void
@@ -571,9 +591,10 @@ gtd_window_class_init (GtdWindowClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->dispose = gtd_window_dispose;
+ object_class->finalize = gtd_window_finalize;
object_class->constructed = gtd_window_constructed;
+ widget_class->destroy = gtd_window_destroy;
widget_class->unmap = gtd_window_unmap;
g_type_ensure (GTD_TYPE_MENU_BUTTON);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]