[gnome-todo] window: Update code style
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] window: Update code style
- Date: Mon, 5 Mar 2018 14:38:39 +0000 (UTC)
commit 606bce5a30ddfd33e1634a3d70e4f8b08dbcfe13
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Mar 5 01:50:26 2018 -0300
window: Update code style
data/ui/window.ui | 4 +-
src/gtd-window.c | 661 +++++++++++++++++++++---------------------------------
2 files changed, 256 insertions(+), 409 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index 464075b..a19443e 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -29,7 +29,7 @@
<property name="vexpand">True</property>
<property name="transition_duration">250</property>
<property name="transition_type">crossfade</property>
- <signal name="notify::visible-child" handler="gtd_window__stack_visible_child_cb"
object="GtdWindow" swapped="yes" />
+ <signal name="notify::visible-child" handler="on_stack_visible_child_cb" object="GtdWindow"
swapped="yes" />
<style>
<class name="background" />
</style>
@@ -76,7 +76,7 @@
<property name="visible">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="gtd_window__cancel_selection_button_clicked" object="GtdWindow"
swapped="no" />
+ <signal name="clicked" handler="on_cancel_selection_button_clicked" object="GtdWindow"
swapped="no" />
</object>
<packing>
<property name="pack_type">end</property>
diff --git a/src/gtd-window.c b/src/gtd-window.c
index ad409df..485fa73 100644
--- a/src/gtd-window.c
+++ b/src/gtd-window.c
@@ -49,123 +49,107 @@
* and fine-tune the headerbar.
*/
-typedef struct
+struct _GtdWindow
{
- GtkWidget *cancel_selection_button;
- GtkWidget *gear_menu_button;
- GtkHeaderBar *headerbar;
- GtdNotificationWidget *notification_widget;
- GtkStack *stack;
- GtkStackSwitcher *stack_switcher;
+ GtkApplicationWindow application;
+
+ GtkWidget *cancel_selection_button;
+ GtkWidget *gear_menu_button;
+ GtkHeaderBar *headerbar;
+ GtkStack *stack;
+ GtkStackSwitcher *stack_switcher;
+
+ GtdNotificationWidget *notification_widget;
/* boxes */
- GtkWidget *extension_box_end;
- GtkWidget *extension_box_start;
- GtkWidget *panel_box_end;
- GtkWidget *panel_box_start;
+ GtkWidget *extension_box_end;
+ GtkWidget *extension_box_start;
+ GtkWidget *panel_box_end;
+ GtkWidget *panel_box_start;
- GtdPanel *active_panel;
+ GtdPanel *active_panel;
/* mode */
- GtdWindowMode mode;
+ GtdWindowMode mode;
/* loading notification */
- GtdNotification *loading_notification;
+ GtdNotification *loading_notification;
- guint save_geometry_timeout_id;
- GtdManager *manager;
-} GtdWindowPrivate;
+ guint save_geometry_timeout_id;
+};
-struct _GtdWindow
+typedef struct
{
- GtkApplicationWindow application;
+ GtdWindow *window;
+ gchar *primary_text;
+ gchar *secondary_text;
+} ErrorData;
- /*< private >*/
- GtdWindowPrivate *priv;
-};
#define SAVE_GEOMETRY_ID_TIMEOUT 100 /* ms */
-G_DEFINE_TYPE_WITH_PRIVATE (GtdWindow, gtd_window, GTK_TYPE_APPLICATION_WINDOW)
-enum {
+G_DEFINE_TYPE (GtdWindow, gtd_window, GTK_TYPE_APPLICATION_WINDOW)
+
+
+enum
+{
PROP_0,
- PROP_MANAGER,
PROP_MODE,
LAST_PROP
};
-/* GtdManager's error notifications */
-typedef struct
-{
- GtdWindow *window;
- gchar *primary_text;
- gchar *secondary_text;
-} ErrorData;
+
static void
-add_widgets (GtdWindow *window,
+add_widgets (GtdWindow *self,
GtkWidget *container_start,
GtkWidget *container_end,
GList *widgets)
{
- GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
GList *l;
- for (l = widgets; l != NULL; l = l->next)
+ for (l = widgets; l; l = l->next)
{
switch (gtk_widget_get_halign (l->data))
{
case GTK_ALIGN_START:
- gtk_box_pack_start (GTK_BOX (container_start),
- l->data,
- FALSE,
- FALSE,
- 0);
+ gtk_box_pack_start (GTK_BOX (container_start), l->data, FALSE, FALSE, 0);
break;
case GTK_ALIGN_CENTER:
- gtk_header_bar_set_custom_title (priv->headerbar, l->data);
+ gtk_header_bar_set_custom_title (self->headerbar, l->data);
break;
case GTK_ALIGN_END:
- gtk_box_pack_end (GTK_BOX (container_end),
- l->data,
- FALSE,
- FALSE,
- 0);
+ gtk_box_pack_end (GTK_BOX (container_end), l->data, FALSE, FALSE, 0);
break;
case GTK_ALIGN_BASELINE:
case GTK_ALIGN_FILL:
default:
- gtk_box_pack_start (GTK_BOX (container_start),
- l->data,
- FALSE,
- FALSE,
- 0);
+ gtk_box_pack_start (GTK_BOX (container_start), l->data, FALSE, FALSE, 0);
break;
}
}
}
static void
-remove_widgets (GtdWindow *window,
+remove_widgets (GtdWindow *self,
GtkWidget *container_start,
GtkWidget *container_end,
GList *widgets)
{
- GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
GList *l;
- for (l = widgets; l != NULL; l = l->next)
+ for (l = widgets; l; l = l->next)
{
GtkWidget *container;
if (gtk_widget_get_halign (l->data) == GTK_ALIGN_END)
container = container_end;
else if (gtk_widget_get_halign (l->data) == GTK_ALIGN_CENTER)
- container = GTK_WIDGET (priv->headerbar);
+ container = GTK_WIDGET (self->headerbar);
else
container = container_start;
@@ -175,86 +159,67 @@ remove_widgets (GtdWindow *window,
}
static void
-plugin_loaded (GtdWindow *window,
- gpointer unused_field,
- GtdActivatable *activatable)
+on_plugin_loaded_cb (GtdWindow *self,
+ gpointer unused_field,
+ GtdActivatable *activatable)
{
- GtdWindowPrivate *priv;
- GList *header_widgets;
-
- priv = gtd_window_get_instance_private (window);
- header_widgets = gtd_activatable_get_header_widgets (activatable);
+ g_autoptr (GList) header_widgets = gtd_activatable_get_header_widgets (activatable);
- add_widgets (window,
- priv->extension_box_start,
- priv->extension_box_end,
+ add_widgets (self,
+ self->extension_box_start,
+ self->extension_box_end,
header_widgets);
-
- g_list_free (header_widgets);
}
static void
-plugin_unloaded (GtdWindow *window,
- gpointer unused_field,
- GtdActivatable *activatable)
+on_plugin_unloaded_cb (GtdWindow *self,
+ gpointer unused_field,
+ GtdActivatable *activatable)
{
- GtdWindowPrivate *priv;
- GList *header_widgets;
-
- priv = gtd_window_get_instance_private (window);
- header_widgets = gtd_activatable_get_header_widgets (activatable);
+ GList *header_widgets = gtd_activatable_get_header_widgets (activatable);
- remove_widgets (window,
- priv->extension_box_start,
- priv->extension_box_end,
+ remove_widgets (self,
+ self->extension_box_start,
+ self->extension_box_end,
header_widgets);
}
static void
-update_panel_menu (GtdWindow *window)
+update_panel_menu (GtdWindow *self)
{
- GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
- const GMenu *menu;
+ const GMenu *menu = gtd_panel_get_menu (self->active_panel);
- menu = gtd_panel_get_menu (priv->active_panel);
-
- gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->gear_menu_button), G_MENU_MODEL (menu));
+ gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (self->gear_menu_button), G_MENU_MODEL (menu));
}
static void
gtd_window__panel_menu_changed (GObject *object,
GParamSpec *pspec,
- GtdWindow *window)
+ GtdWindow *self)
{
- GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
-
- if (GTD_PANEL (object) != priv->active_panel)
+ if (GTD_PANEL (object) != self->active_panel)
return;
- update_panel_menu (window);
+ update_panel_menu (self);
}
static void
gtd_window__panel_title_changed (GObject *object,
GParamSpec *pspec,
- GtdWindow *window)
+ GtdWindow *self)
{
- GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
-
- gtk_container_child_set (GTK_CONTAINER (priv->stack),
+ gtk_container_child_set (GTK_CONTAINER (self->stack),
GTK_WIDGET (object),
"title", gtd_panel_get_panel_title (GTD_PANEL (object)),
NULL);
}
static void
-gtd_window__panel_added (GtdManager *manager,
- GtdPanel *panel,
- GtdWindow *window)
+on_panel_added_cb (GtdManager *manager,
+ GtdPanel *panel,
+ GtdWindow *self)
{
- GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
-
- gtk_stack_add_titled (priv->stack,
+ gtk_stack_add_titled (self->stack,
GTK_WIDGET (panel),
gtd_panel_get_panel_name (panel),
gtd_panel_get_panel_title (panel));
@@ -262,17 +227,15 @@ gtd_window__panel_added (GtdManager *manager,
g_signal_connect (panel,
"notify::title",
G_CALLBACK (gtd_window__panel_title_changed),
- window);
+ self);
}
static void
-gtd_window__panel_removed (GtdManager *manager,
- GtdPanel *panel,
- GtdWindow *window)
+on_panel_removed_cb (GtdManager *manager,
+ GtdPanel *panel,
+ GtdWindow *self)
{
- GtdWindowPrivate *priv = gtd_window_get_instance_private (window);
-
- gtk_container_remove (GTK_CONTAINER (priv->stack), GTK_WIDGET (panel));
+ gtk_container_remove (GTK_CONTAINER (self->stack), GTK_WIDGET (panel));
}
static void
@@ -320,145 +283,119 @@ error_message_notification_secondary_action (GtdNotification *notification,
}
static void
-gtd_window__load_geometry (GtdWindow *window)
+load_geometry (GtdWindow *self)
{
+ g_autoptr (GVariant) position_variant = NULL;
+ g_autoptr (GVariant) size_variant = NULL;
GSettings *settings;
- GVariant *variant;
gboolean maximized;
const gint32 *position;
const gint32 *size;
gsize n_elements;
- settings = gtd_manager_get_settings (window->priv->manager);
+ settings = gtd_manager_get_settings (gtd_manager_get_default ());
/* load window settings: size */
- variant = g_settings_get_value (settings,
- "window-size");
- size = g_variant_get_fixed_array (variant,
- &n_elements,
- sizeof (gint32));
+ size_variant = g_settings_get_value (settings, "window-size");
+ size = g_variant_get_fixed_array (size_variant, &n_elements, sizeof (gint32));
+
if (n_elements == 2)
- gtk_window_set_default_size (GTK_WINDOW (window),
- size[0],
- size[1]);
- g_variant_unref (variant);
+ gtk_window_set_default_size (GTK_WINDOW (self), size[0], size[1]);
/* load window settings: position */
- variant = g_settings_get_value (settings,
- "window-position");
- position = g_variant_get_fixed_array (variant,
- &n_elements,
- sizeof (gint32));
- if (n_elements == 2)
- gtk_window_move (GTK_WINDOW (window),
- position[0],
- position[1]);
+ position_variant = g_settings_get_value (settings, "window-position");
+ position = g_variant_get_fixed_array (position_variant, &n_elements, sizeof (gint32));
- g_variant_unref (variant);
+ if (n_elements == 2)
+ gtk_window_move (GTK_WINDOW (self), position[0], position[1]);
/* load window settings: state */
- maximized = g_settings_get_boolean (settings,
- "window-maximized");
+ maximized = g_settings_get_boolean (settings, "window-maximized");
+
if (maximized)
- gtk_window_maximize (GTK_WINDOW (window));
+ gtk_window_maximize (GTK_WINDOW (self));
}
static gboolean
-gtd_window__save_geometry (gpointer user_data)
+save_geometry (gpointer user_data)
{
- GtdWindowPrivate *priv;
GdkWindowState state;
- GdkWindow *window;
- GtkWindow *self;
+ GtdWindow *self;
+ GdkWindow *gdk_window;
+ GtkWindow *window;
GSettings *settings;
gboolean maximized;
GVariant *variant;
gint32 size[2];
gint32 position[2];
- self = GTK_WINDOW (user_data);
-
- window = gtk_widget_get_window (GTK_WIDGET (self));
- state = gdk_window_get_state (window);
- priv = GTD_WINDOW (self)->priv;
+ self = GTD_WINDOW (user_data);
+ window = GTK_WINDOW (user_data);
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (self));
+ state = gdk_window_get_state (gdk_window);
- settings = gtd_manager_get_settings (priv->manager);
+ settings = gtd_manager_get_settings (gtd_manager_get_default ());
/* save window's state */
maximized = state & GDK_WINDOW_STATE_MAXIMIZED;
- g_settings_set_boolean (settings,
- "window-maximized",
- maximized);
+
+ g_settings_set_boolean (settings, "window-maximized", maximized);
if (maximized)
{
- priv->save_geometry_timeout_id = 0;
+ self->save_geometry_timeout_id = 0;
return FALSE;
}
/* save window's size */
- gtk_window_get_size (self,
- (gint *) &size[0],
- (gint *) &size[1]);
- variant = g_variant_new_fixed_array (G_VARIANT_TYPE_INT32,
- size,
- 2,
- sizeof (size[0]));
- g_settings_set_value (settings,
- "window-size",
- variant);
+ gtk_window_get_size (window, (gint*) &size[0], (gint*) &size[1]);
+
+ variant = g_variant_new_fixed_array (G_VARIANT_TYPE_INT32, size, 2, sizeof (size[0]));
+ g_settings_set_value (settings, "window-size", variant);
/* save windows's position */
- gtk_window_get_position (self,
- (gint *) &position[0],
- (gint *) &position[1]);
- variant = g_variant_new_fixed_array (G_VARIANT_TYPE_INT32,
- position,
- 2,
- sizeof (position[0]));
- g_settings_set_value (settings,
- "window-position",
- variant);
-
- priv->save_geometry_timeout_id = 0;
+ gtk_window_get_position (window, (gint *) &position[0], (gint *) &position[1]);
+
+ variant = g_variant_new_fixed_array (G_VARIANT_TYPE_INT32, position, 2, sizeof (position[0]));
+ g_settings_set_value (settings, "window-position", variant);
+
+ self->save_geometry_timeout_id = 0;
return FALSE;
}
static void
-gtd_window__cancel_selection_button_clicked (GtkWidget *button,
- GtdWindow *window)
+on_cancel_selection_button_clicked (GtkWidget *button,
+ GtdWindow *self)
{
- gtd_window_set_mode (window, GTD_WINDOW_MODE_NORMAL);
+ gtd_window_set_mode (self, GTD_WINDOW_MODE_NORMAL);
}
static void
-gtd_window__stack_visible_child_cb (GtdWindow *window,
- GParamSpec *pspec,
- GtkStack *stack)
+on_stack_visible_child_cb (GtdWindow *self,
+ GParamSpec *pspec,
+ GtkStack *stack)
{
- GtdWindowPrivate *priv;
GtkWidget *visible_child;
GtdPanel *panel;
GList *header_widgets;
- priv = gtd_window_get_instance_private (window);
visible_child = gtk_stack_get_visible_child (stack);
panel = GTD_PANEL (visible_child);
/* Remove previous panel's widgets */
- if (priv->active_panel)
+ if (self->active_panel)
{
- header_widgets = gtd_panel_get_header_widgets (priv->active_panel);
+ header_widgets = gtd_panel_get_header_widgets (self->active_panel);
/* Disconnect signals */
- g_signal_handlers_disconnect_by_func (priv->active_panel,
+ g_signal_handlers_disconnect_by_func (self->active_panel,
gtd_window__panel_menu_changed,
- window);
+ self);
- remove_widgets (window,
- priv->panel_box_start,
- priv->panel_box_end,
+ remove_widgets (self,
+ self->panel_box_start,
+ self->panel_box_end,
header_widgets);
g_list_free (header_widgets);
@@ -467,9 +404,9 @@ gtd_window__stack_visible_child_cb (GtdWindow *window,
/* Add current panel's header widgets */
header_widgets = gtd_panel_get_header_widgets (panel);
- add_widgets (window,
- priv->panel_box_start,
- priv->panel_box_end,
+ add_widgets (self,
+ self->panel_box_start,
+ self->panel_box_end,
header_widgets);
g_list_free (header_widgets);
@@ -477,39 +414,35 @@ gtd_window__stack_visible_child_cb (GtdWindow *window,
g_signal_connect (panel,
"notify::menu",
G_CALLBACK (gtd_window__panel_menu_changed),
- window);
+ self);
/* Set panel as the new active panel */
- g_set_object (&priv->active_panel, panel);
+ g_set_object (&self->active_panel, panel);
/* Setup the panel's menu */
- update_panel_menu (window);
+ update_panel_menu (self);
}
static void
on_loading_changed_cb (GObject *source,
GParamSpec *spec,
- gpointer user_data)
+ GtdWindow *self)
{
- GtdWindowPrivate *priv;
-
- g_assert (GTD_IS_WINDOW (user_data));
-
- priv = GTD_WINDOW (user_data)->priv;
+ g_assert (GTD_IS_WINDOW (self));
if (gtd_object_get_loading (GTD_OBJECT (source)))
- gtd_notification_widget_notify (priv->notification_widget, priv->loading_notification);
+ gtd_notification_widget_notify (self->notification_widget, self->loading_notification);
else
- gtd_notification_widget_cancel (priv->notification_widget, priv->loading_notification);
+ gtd_notification_widget_cancel (self->notification_widget, self->loading_notification);
}
static void
-gtd_window__show_error_message (GtdManager *manager,
- const gchar *primary_text,
- const gchar *secondary_text,
- GtdNotificationActionFunc function,
- gpointer user_data,
- GtdWindow *window)
+on_show_error_message_cb (GtdManager *manager,
+ const gchar *primary_text,
+ const gchar *secondary_text,
+ GtdNotificationActionFunc function,
+ gpointer user_data,
+ GtdWindow *self)
{
GtdNotification *notification;
ErrorData *error_data;
@@ -517,7 +450,7 @@ gtd_window__show_error_message (GtdManager *manager,
error_data = g_new0 (ErrorData, 1);
notification = gtd_notification_new (primary_text, 7500);
- error_data->window = window;
+ error_data->window = self;
error_data->primary_text = g_strdup (primary_text);
error_data->secondary_text = g_strdup (secondary_text);
@@ -525,41 +458,43 @@ gtd_window__show_error_message (GtdManager *manager,
error_message_notification_primary_action,
error_data);
- if (function == NULL)
- gtd_notification_set_secondary_action (notification,
- _("Details"),
- error_message_notification_secondary_action,
- error_data);
+ if (!function)
+ {
+ gtd_notification_set_secondary_action (notification,
+ _("Details"),
+ error_message_notification_secondary_action,
+ error_data);
+ }
else
- gtd_notification_set_secondary_action (notification,
- secondary_text,
- function,
- user_data);
+ {
+ gtd_notification_set_secondary_action (notification, secondary_text, function, user_data);
+ }
- gtd_window_notify (window, notification);
+ gtd_window_notify (self, notification);
}
+
+/*
+ * GtkWindow overrides
+ */
+
static gboolean
gtd_window_configure_event (GtkWidget *widget,
GdkEventConfigure *event)
{
- GtdWindowPrivate *priv;
- GtdWindow *window;
+ GtdWindow *self;
gboolean retval;
- window = GTD_WINDOW (widget);
- priv = window->priv;
+ self = GTD_WINDOW (widget);
- if (priv->save_geometry_timeout_id != 0)
+ if (self->save_geometry_timeout_id != 0)
{
- g_source_remove (priv->save_geometry_timeout_id);
- priv->save_geometry_timeout_id = 0;
+ g_source_remove (self->save_geometry_timeout_id);
+ self->save_geometry_timeout_id = 0;
}
- priv->save_geometry_timeout_id = g_timeout_add (SAVE_GEOMETRY_ID_TIMEOUT,
- gtd_window__save_geometry,
- window);
+ self->save_geometry_timeout_id = g_timeout_add (SAVE_GEOMETRY_ID_TIMEOUT, save_geometry, self);
retval = GTK_WIDGET_CLASS (gtd_window_parent_class)->configure_event (widget, event);
@@ -570,61 +505,80 @@ static gboolean
gtd_window_state_event (GtkWidget *widget,
GdkEventWindowState *event)
{
- GtdWindowPrivate *priv;
- GtdWindow *window;
+ GtdWindow *self;
gboolean retval;
- window = GTD_WINDOW (widget);
- priv = window->priv;
+ self = GTD_WINDOW (widget);
- if (priv->save_geometry_timeout_id != 0)
+ if (self->save_geometry_timeout_id != 0)
{
- g_source_remove (priv->save_geometry_timeout_id);
- priv->save_geometry_timeout_id = 0;
+ g_source_remove (self->save_geometry_timeout_id);
+ self->save_geometry_timeout_id = 0;
}
- priv->save_geometry_timeout_id = g_timeout_add (SAVE_GEOMETRY_ID_TIMEOUT,
- gtd_window__save_geometry,
- window);
+ self->save_geometry_timeout_id = g_timeout_add (SAVE_GEOMETRY_ID_TIMEOUT, save_geometry, self);
retval = GTK_WIDGET_CLASS (gtd_window_parent_class)->window_state_event (widget, event);
return retval;
}
+
+/*
+ * GObject overrides
+ */
+
static void
gtd_window_constructed (GObject *object)
{
- GtdWindowPrivate *priv = GTD_WINDOW (object)->priv;
+ g_autoptr (GList) plugins = NULL;
+ g_autoptr (GList) lists = NULL;
+ g_autoptr (GList) l = NULL;
+ GtdPluginManager *plugin_manager;
GtkApplication *app;
+ GtdWindow *self;
GMenu *menu;
+ self = GTD_WINDOW (object);
+
G_OBJECT_CLASS (gtd_window_parent_class)->constructed (object);
- /* load stored size */
- gtd_window__load_geometry (GTD_WINDOW (object));
+ /* Load stored size */
+ load_geometry (GTD_WINDOW (object));
- /* gear menu */
+ /* Gear menu */
app = GTK_APPLICATION (g_application_get_default ());
menu = gtk_application_get_menu_by_id (app, "gear-menu");
- gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->gear_menu_button), G_MENU_MODEL (menu));
-}
+ gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (self->gear_menu_button), G_MENU_MODEL (menu));
-GtkWidget*
-gtd_window_new (GtdApplication *application)
-{
- return g_object_new (GTD_TYPE_WINDOW,
- "application", application,
- "manager", gtd_manager_get_default (),
- NULL);
+ /* Add plugins' header widgets, and setup for new plugins */
+ plugin_manager = gtd_manager_get_plugin_manager (gtd_manager_get_default ());
+ plugins = gtd_plugin_manager_get_loaded_plugins (plugin_manager);
+
+ for (l = plugins; l; l = l->next)
+ on_plugin_loaded_cb (self, NULL, l->data);
+
+ g_signal_connect_swapped (plugin_manager, "plugin-loaded", G_CALLBACK (on_plugin_loaded_cb), self);
+ g_signal_connect_swapped (plugin_manager, "plugin-unloaded", G_CALLBACK (on_plugin_unloaded_cb), self);
+
+ /* Add loaded panels */
+ lists = gtd_manager_get_panels (gtd_manager_get_default ());
+
+ for (l = lists; l; l = l->next)
+ on_panel_added_cb (NULL, l->data, self);
+
+ g_signal_connect (gtd_manager_get_default (), "notify::loading", G_CALLBACK (on_loading_changed_cb), self);
+ g_signal_connect (gtd_manager_get_default (), "panel-added", G_CALLBACK (on_panel_added_cb), self);
+ g_signal_connect (gtd_manager_get_default (), "panel-removed", G_CALLBACK (on_panel_removed_cb), self);
+ g_signal_connect (gtd_manager_get_default (), "show-error-message", G_CALLBACK (on_show_error_message_cb),
self);
}
static void
gtd_window_finalize (GObject *object)
{
- GtdWindowPrivate *priv = GTD_WINDOW (object)->priv;
+ GtdWindow *self = GTD_WINDOW (object);
- g_clear_object (&priv->loading_notification);
+ g_clear_object (&self->loading_notification);
G_OBJECT_CLASS (gtd_window_parent_class)->finalize (object);
}
@@ -638,12 +592,8 @@ gtd_window_get_property (GObject *object,
switch (prop_id)
{
- case PROP_MANAGER:
- g_value_set_object (value, self->priv->manager);
- break;
-
case PROP_MODE:
- g_value_set_enum (value, self->priv->mode);
+ g_value_set_enum (value, self->mode);
break;
default:
@@ -658,70 +608,9 @@ gtd_window_set_property (GObject *object,
GParamSpec *pspec)
{
GtdWindow *self = GTD_WINDOW (object);
- GList *lists;
- GList *l;
switch (prop_id)
{
- case PROP_MANAGER:
- self->priv->manager = g_value_get_object (value);
-
- /* Add plugins' header widgets, and setup for new plugins */
- {
- GtdPluginManager *plugin_manager;
- GList *plugins;
-
- plugin_manager = gtd_manager_get_plugin_manager (self->priv->manager);
- plugins = gtd_plugin_manager_get_loaded_plugins (plugin_manager);
-
- for (l = plugins; l != NULL; l = l->next)
- plugin_loaded (self, NULL, l->data);
-
- g_signal_connect_swapped (plugin_manager,
- "plugin-loaded",
- G_CALLBACK (plugin_loaded),
- self);
-
- g_signal_connect_swapped (plugin_manager,
- "plugin-unloaded",
- G_CALLBACK (plugin_unloaded),
- self);
-
- g_list_free (plugins);
- }
-
- g_signal_connect (self->priv->manager,
- "notify::loading",
- G_CALLBACK (on_loading_changed_cb),
- 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);
-
- /* Add loaded panels */
- lists = gtd_manager_get_panels (self->priv->manager);
-
- for (l = lists; l != NULL; l = l->next)
- {
- gtd_window__panel_added (self->priv->manager,
- l->data,
- GTD_WINDOW (object));
- }
-
- g_list_free (lists);
-
- g_object_notify (object, "manager");
- break;
-
case PROP_MODE:
gtd_window_set_mode (self, g_value_get_enum (value));
break;
@@ -745,20 +634,6 @@ gtd_window_class_init (GtdWindowClass *klass)
widget_class->configure_event = gtd_window_configure_event;
widget_class->window_state_event = gtd_window_state_event;
- /**
- * GtdWindow::manager:
- *
- * A weak reference to the application's #GtdManager instance.
- */
- g_object_class_install_property (
- object_class,
- PROP_MANAGER,
- g_param_spec_object ("manager",
- "Manager of this window's application",
- "The manager of the window's application",
- GTD_TYPE_MANAGER,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
/**
* GtdWindow::mode:
*
@@ -778,20 +653,20 @@ gtd_window_class_init (GtdWindowClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/todo/ui/window.ui");
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, cancel_selection_button);
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, gear_menu_button);
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, headerbar);
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, notification_widget);
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, stack);
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, stack_switcher);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, cancel_selection_button);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, gear_menu_button);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, headerbar);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, notification_widget);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, stack);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, stack_switcher);
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, extension_box_end);
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, extension_box_start);
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, panel_box_end);
- gtk_widget_class_bind_template_child_private (widget_class, GtdWindow, panel_box_start);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, extension_box_end);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, extension_box_start);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, panel_box_end);
+ gtk_widget_class_bind_template_child (widget_class, GtdWindow, panel_box_start);
- gtk_widget_class_bind_template_callback (widget_class, gtd_window__cancel_selection_button_clicked);
- gtk_widget_class_bind_template_callback (widget_class, gtd_window__stack_visible_child_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_cancel_selection_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_stack_visible_child_cb);
}
static void
@@ -799,19 +674,15 @@ gtd_window_init (GtdWindow *self)
{
GtkWidget *panel;
- self->priv = gtd_window_get_instance_private (self);
-
- self->priv->loading_notification = gtd_notification_new (_("Loading your task lists…"), 0);
- gtd_object_push_loading (GTD_OBJECT (self->priv->loading_notification));
+ self->loading_notification = gtd_notification_new (_("Loading your task lists…"), 0);
+ gtd_object_push_loading (GTD_OBJECT (self->loading_notification));
gtk_widget_init_template (GTK_WIDGET (self));
/* Add the default 'Lists' panel before everything else */
panel = gtd_list_selector_panel_new ();
- gtd_window__panel_added (gtd_manager_get_default (),
- GTD_PANEL (panel),
- self);
+ on_panel_added_cb (gtd_manager_get_default (), GTD_PANEL (panel), self);
g_object_bind_property (self,
"mode",
@@ -820,20 +691,12 @@ gtd_window_init (GtdWindow *self)
G_BINDING_BIDIRECTIONAL);
}
-/**
- * gtd_window_get_manager:
- * @window: a #GtdWindow
- *
- * Retrieves a weak reference for the @window's #GtdManager.
- *
- * Returns: (transfer none): the #GtdManager of @window.
- */
-GtdManager*
-gtd_window_get_manager (GtdWindow *window)
+GtkWidget*
+gtd_window_new (GtdApplication *application)
{
- g_return_val_if_fail (GTD_IS_WINDOW (window), NULL);
-
- return window->priv->manager;
+ return g_object_new (GTD_TYPE_WINDOW,
+ "application", application,
+ NULL);
}
/**
@@ -844,16 +707,12 @@ gtd_window_get_manager (GtdWindow *window)
* Shows a notification on the top of the main window.
*/
void
-gtd_window_notify (GtdWindow *window,
+gtd_window_notify (GtdWindow *self,
GtdNotification *notification)
{
- GtdWindowPrivate *priv;
-
- g_return_if_fail (GTD_IS_WINDOW (window));
-
- priv = window->priv;
+ g_return_if_fail (GTD_IS_WINDOW (self));
- gtd_notification_widget_notify (priv->notification_widget, notification);
+ gtd_notification_widget_notify (self->notification_widget, notification);
}
/**
@@ -864,16 +723,12 @@ gtd_window_notify (GtdWindow *window,
* Cancels @notification.
*/
void
-gtd_window_cancel_notification (GtdWindow *window,
+gtd_window_cancel_notification (GtdWindow *self,
GtdNotification *notification)
{
- GtdWindowPrivate *priv;
+ g_return_if_fail (GTD_IS_WINDOW (self));
- g_return_if_fail (GTD_IS_WINDOW (window));
-
- priv = window->priv;
-
- gtd_notification_widget_cancel (priv->notification_widget, notification);
+ gtd_notification_widget_cancel (self->notification_widget, notification);
}
/**
@@ -885,11 +740,11 @@ gtd_window_cancel_notification (GtdWindow *window,
* Returns: the #GtdWindow::mode property value
*/
GtdWindowMode
-gtd_window_get_mode (GtdWindow *window)
+gtd_window_get_mode (GtdWindow *self)
{
- g_return_val_if_fail (GTD_IS_WINDOW (window), GTD_WINDOW_MODE_NORMAL);
+ g_return_val_if_fail (GTD_IS_WINDOW (self), GTD_WINDOW_MODE_NORMAL);
- return window->priv->mode;
+ return self->mode;
}
/**
@@ -900,43 +755,39 @@ gtd_window_get_mode (GtdWindow *window)
* Sets the current window mode to @mode.
*/
void
-gtd_window_set_mode (GtdWindow *window,
+gtd_window_set_mode (GtdWindow *self,
GtdWindowMode mode)
{
- GtdWindowPrivate *priv;
-
- g_return_if_fail (GTD_IS_WINDOW (window));
+ g_return_if_fail (GTD_IS_WINDOW (self));
- priv = window->priv;
-
- if (priv->mode != mode)
+ if (self->mode != mode)
{
GtkStyleContext *context;
gboolean is_selection_mode;
- priv->mode = mode;
- context = gtk_widget_get_style_context (GTK_WIDGET (priv->headerbar));
+ self->mode = mode;
+ context = gtk_widget_get_style_context (GTK_WIDGET (self->headerbar));
is_selection_mode = (mode == GTD_WINDOW_MODE_SELECTION);
- gtk_widget_set_visible (priv->gear_menu_button, !is_selection_mode);
- gtk_widget_set_visible (priv->cancel_selection_button, is_selection_mode);
- gtk_header_bar_set_show_close_button (priv->headerbar, !is_selection_mode);
- gtk_header_bar_set_subtitle (priv->headerbar, NULL);
+ gtk_widget_set_visible (self->gear_menu_button, !is_selection_mode);
+ gtk_widget_set_visible (self->cancel_selection_button, is_selection_mode);
+ gtk_header_bar_set_show_close_button (self->headerbar, !is_selection_mode);
+ gtk_header_bar_set_subtitle (self->headerbar, NULL);
if (is_selection_mode)
{
gtk_style_context_add_class (context, "selection-mode");
- gtk_header_bar_set_custom_title (priv->headerbar, NULL);
- gtk_header_bar_set_title (priv->headerbar, _("Click a task list to select"));
+ gtk_header_bar_set_custom_title (self->headerbar, NULL);
+ gtk_header_bar_set_title (self->headerbar, _("Click a task list to select"));
}
else
{
gtk_style_context_remove_class (context, "selection-mode");
- gtk_header_bar_set_custom_title (priv->headerbar, GTK_WIDGET (priv->stack_switcher));
- gtk_header_bar_set_title (priv->headerbar, _("To Do"));
+ gtk_header_bar_set_custom_title (self->headerbar, GTK_WIDGET (self->stack_switcher));
+ gtk_header_bar_set_title (self->headerbar, _("To Do"));
}
- g_object_notify (G_OBJECT (window), "mode");
+ g_object_notify (G_OBJECT (self), "mode");
}
}
@@ -950,25 +801,21 @@ gtd_window_set_mode (GtdWindow *window,
* the header will be set to the stack switcher.
*/
void
-gtd_window_set_custom_title (GtdWindow *window,
+gtd_window_set_custom_title (GtdWindow *self,
const gchar *title,
const gchar *subtitle)
{
- GtdWindowPrivate *priv;
-
- g_return_if_fail (GTD_IS_WINDOW (window));
-
- priv = window->priv;
+ g_return_if_fail (GTD_IS_WINDOW (self));
if (title)
{
- gtk_header_bar_set_custom_title (priv->headerbar, NULL);
- gtk_header_bar_set_title (priv->headerbar, title);
- gtk_header_bar_set_subtitle (window->priv->headerbar, subtitle);
+ gtk_header_bar_set_custom_title (self->headerbar, NULL);
+ gtk_header_bar_set_title (self->headerbar, title);
+ gtk_header_bar_set_subtitle (self->headerbar, subtitle);
}
else
{
- gtk_header_bar_set_title (priv->headerbar, _("To Do"));
- gtk_header_bar_set_custom_title (priv->headerbar, GTK_WIDGET (priv->stack_switcher));
+ gtk_header_bar_set_title (self->headerbar, _("To Do"));
+ gtk_header_bar_set_custom_title (self->headerbar, GTK_WIDGET (self->stack_switcher));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]