[gnome-todo/wip/gbsneto/plugins: 8/10] manager: load panels
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo/wip/gbsneto/plugins: 8/10] manager: load panels
- Date: Mon, 28 Dec 2015 01:58:45 +0000 (UTC)
commit 6c315fe7f9a36a8ecdd6b252529bf627e576fe7b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Dec 27 22:59:43 2015 -0200
manager: load panels
src/gtd-manager.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++
src/gtd-manager.h | 2 +
src/gtd-plugin-manager.c | 37 +++++++++++++++++++
src/gtd-window.c | 50 ++++++++++++++++++++++++++
4 files changed, 177 insertions(+), 0 deletions(-)
---
diff --git a/src/gtd-manager.c b/src/gtd-manager.c
index 96ce806..d110ed1 100644
--- a/src/gtd-manager.c
+++ b/src/gtd-manager.c
@@ -17,6 +17,7 @@
*/
#include "interfaces/gtd-provider.h"
+#include "interfaces/gtd-panel.h"
#include "gtd-manager.h"
#include "gtd-plugin-manager.h"
#include "gtd-task.h"
@@ -31,6 +32,7 @@ typedef struct
GList *tasklists;
GList *providers;
+ GList *panels;
GtdProvider *default_provider;
} GtdManagerPrivate;
@@ -54,6 +56,8 @@ enum
LIST_CHANGED,
LIST_REMOVED,
SHOW_ERROR_MESSAGE,
+ PANEL_ADDED,
+ PANEL_REMOVED,
PROVIDER_ADDED,
PROVIDER_REMOVED,
NUM_SIGNALS
@@ -265,6 +269,40 @@ gtd_manager_class_init (GtdManagerClass *klass)
G_TYPE_STRING);
/**
+ * GtdManager::panel-added:
+ *
+ * The ::panel-added signal is emmited after a #GtdPanel
+ * is added.
+ */
+ signals[PANEL_ADDED] = g_signal_new ("panel-added",
+ GTD_TYPE_MANAGER,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 1,
+ GTD_TYPE_PANEL);
+
+ /**
+ * GtdManager::panel-removed:
+ *
+ * The ::panel-removed signal is emmited after a #GtdPanel
+ * is removed from the list.
+ */
+ signals[PANEL_REMOVED] = g_signal_new ("panel-removed",
+ GTD_TYPE_MANAGER,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 1,
+ GTD_TYPE_PANEL);
+
+ /**
* GtdManager::provider-added:
*
* The ::provider-added signal is emmited after a #GtdProvider
@@ -300,6 +338,30 @@ gtd_manager_class_init (GtdManagerClass *klass)
}
static void
+gtd_manager__panel_added (GtdPluginManager *plugin_manager,
+ GtdPanel *panel,
+ GtdManager *self)
+{
+ GtdManagerPrivate *priv = gtd_manager_get_instance_private (self);
+
+ priv->panels = g_list_append (priv->panels, panel);
+
+ g_signal_emit (self, signals[PANEL_ADDED], 0, panel);
+}
+
+static void
+gtd_manager__panel_removed (GtdPluginManager *plugin_manager,
+ GtdPanel *panel,
+ GtdManager *self)
+{
+ GtdManagerPrivate *priv = gtd_manager_get_instance_private (self);
+
+ priv->panels = g_list_remove (priv->panels, panel);
+
+ g_signal_emit (self, signals[PANEL_REMOVED], 0, panel);
+}
+
+static void
gtd_manager__list_added (GtdProvider *provider,
GtdTaskList *list,
GtdManager *self)
@@ -395,6 +457,16 @@ gtd_manager_init (GtdManager *self)
self->priv->plugin_manager = gtd_plugin_manager_new ();
g_signal_connect (self->priv->plugin_manager,
+ "panel-registered",
+ G_CALLBACK (gtd_manager__panel_added),
+ self);
+
+ g_signal_connect (self->priv->plugin_manager,
+ "panel-unregistered",
+ G_CALLBACK (gtd_manager__panel_removed),
+ self);
+
+ g_signal_connect (self->priv->plugin_manager,
"provider-registered",
G_CALLBACK (gtd_manager__provider_added),
self);
@@ -609,6 +681,22 @@ gtd_manager_get_providers (GtdManager *manager)
}
/**
+ * gtd_manager_get_panels:
+ *
+ * Retrieves the list of currently loaded #GtdPanel
+ * instances.
+ *
+ * Returns: (transger full): a #GList of #GtdPanel
+ */
+GList*
+gtd_manager_get_panels (GtdManager *manager)
+{
+ g_return_val_if_fail (GTD_IS_MANAGER (manager), NULL);
+
+ return g_list_copy (manager->priv->panels);
+}
+
+/**
* gtd_manager_get_default_provider:
* @manager: a #GtdManager
*
diff --git a/src/gtd-manager.h b/src/gtd-manager.h
index 0742fc6..6062d8c 100644
--- a/src/gtd-manager.h
+++ b/src/gtd-manager.h
@@ -38,6 +38,8 @@ GList* gtd_manager_get_task_lists (GtdManager
GList* gtd_manager_get_providers (GtdManager *manager);
+GList* gtd_manager_get_panels (GtdManager *manager);
+
/* Task lists */
void gtd_manager_create_task_list (GtdManager *manager,
GtdTaskList *list);
diff --git a/src/gtd-plugin-manager.c b/src/gtd-plugin-manager.c
index 04340e4..df7a6ad 100644
--- a/src/gtd-plugin-manager.c
+++ b/src/gtd-plugin-manager.c
@@ -112,6 +112,22 @@ gtd_plugin_manager_class_init (GtdPluginManagerClass *klass)
}
static void
+on_panel_added (GtdActivatable *activatable,
+ GtdPanel *panel,
+ GtdPluginManager *self)
+{
+ g_signal_emit_by_name (self, "panel-registered", panel);
+}
+
+static void
+on_panel_removed (GtdActivatable *activatable,
+ GtdPanel *panel,
+ GtdPluginManager *self)
+{
+ g_signal_emit_by_name (self, "panel-unregistered", panel);
+}
+
+static void
on_provider_added (GtdActivatable *activatable,
GtdProvider *provider,
GtdPluginManager *self)
@@ -134,6 +150,7 @@ on_plugin_unloaded (PeasEngine *engine,
{
GtdActivatable *activatable;
GList *extension_providers;
+ GList *extension_panels;
GList *l;
activatable = g_hash_table_lookup (self->info_to_extension, info);
@@ -141,6 +158,12 @@ on_plugin_unloaded (PeasEngine *engine,
if (!activatable)
return;
+ /* Remove all panels */
+ extension_panels = gtd_activatable_get_panels (activatable);
+
+ for (l = extension_panels; l != NULL; l = l->next)
+ on_panel_removed (activatable, l->data, self);
+
/* Remove all registered providers */
extension_providers = gtd_activatable_get_providers (activatable);
@@ -186,6 +209,10 @@ on_plugin_loaded (PeasEngine *engine,
for (l = gtd_activatable_get_providers (activatable); l != NULL; l = l->next)
on_provider_added (activatable, l->data, self);
+ /* Load all panels */
+ for (l = gtd_activatable_get_panels (activatable); l != NULL; l = l->next)
+ on_panel_added (activatable, l->data, self);
+
g_signal_connect (activatable,
"provider-added",
G_CALLBACK (on_provider_added),
@@ -195,6 +222,16 @@ on_plugin_loaded (PeasEngine *engine,
"provider-removed",
G_CALLBACK (on_provider_removed),
self);
+
+ g_signal_connect (activatable,
+ "panel-added",
+ G_CALLBACK (on_panel_added),
+ self);
+
+ g_signal_connect (activatable,
+ "panel-removed",
+ G_CALLBACK (on_panel_removed),
+ self);
}
}
diff --git a/src/gtd-window.c b/src/gtd-window.c
index 633a2ae..c0746d9 100644
--- a/src/gtd-window.c
+++ b/src/gtd-window.c
@@ -17,6 +17,7 @@
*/
#include "interfaces/gtd-provider.h"
+#include "interfaces/gtd-panel.h"
#include "gtd-application.h"
#include "gtd-enum-types.h"
#include "gtd-task-list-view.h"
@@ -111,6 +112,47 @@ typedef struct
} ErrorData;
static void
+gtd_window__panel_title_changed (GObject *object,
+ GParamSpec *pspec,
+ GtdWindow *window)
+{
+ GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
+
+ gtk_container_child_set (GTK_CONTAINER (priv->stack),
+ GTK_WIDGET (object),
+ "title", gtd_panel_get_title (GTD_PANEL (object)),
+ NULL);
+}
+
+static void
+gtd_window__panel_added (GtdManager *manager,
+ GtdPanel *panel,
+ GtdWindow *window)
+{
+ GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
+
+ gtk_stack_add_titled (priv->stack,
+ GTK_WIDGET (panel),
+ gtd_panel_get_name (panel),
+ gtd_panel_get_title (panel));
+
+ g_signal_connect (panel,
+ "notify::title",
+ G_CALLBACK (gtd_window__panel_title_changed),
+ window);
+}
+
+static void
+gtd_window__panel_removed (GtdManager *manager,
+ GtdPanel *panel,
+ GtdWindow *window)
+{
+ GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
+
+ gtk_container_remove (GTK_CONTAINER (priv->stack), GTK_WIDGET (panel));
+}
+
+static void
error_data_free (ErrorData *error_data)
{
g_free (error_data->primary_text);
@@ -927,6 +969,14 @@ gtd_window_set_property (GObject *object,
G_CALLBACK (gtd_window__list_removed),
self);
g_signal_connect (self->priv->manager,
+ "panel-added",
+ G_CALLBACK (gtd_window__panel_added),
+ self);
+ g_signal_connect (self->priv->manager,
+ "panel-removed",
+ G_CALLBACK (gtd_window__panel_removed),
+ self);
+ g_signal_connect (self->priv->manager,
"show-error-message",
G_CALLBACK (gtd_window__show_error_message),
self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]