[gnome-calendar/wip/gbsneto/sidebar: 5/5] window: store sidebar state
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/gbsneto/sidebar: 5/5] window: store sidebar state
- Date: Sat, 10 Jun 2017 15:51:27 +0000 (UTC)
commit b48acfe4ed867259d309d61cd64656746d159a61
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Jun 8 07:59:09 2017 -0300
window: store sidebar state
data/org.gnome.calendar.gschema.xml | 5 +
src/gcal-window.c | 163 ++++++++++++++++++++---------------
2 files changed, 99 insertions(+), 69 deletions(-)
---
diff --git a/data/org.gnome.calendar.gschema.xml b/data/org.gnome.calendar.gschema.xml
index e938690..8c9ad28 100644
--- a/data/org.gnome.calendar.gschema.xml
+++ b/data/org.gnome.calendar.gschema.xml
@@ -21,5 +21,10 @@
<summary>Type of the active view</summary>
<description>Type of the active window view, default value is: monthly view</description>
</key>
+ <key name="show-sidebar" type="b">
+ <default>false</default>
+ <summary>Whether the sidebar is visible</summary>
+ <description>Whether the sidebar is visible or not</description>
+ </key>
</schema>
</schemalist>
diff --git a/src/gcal-window.c b/src/gcal-window.c
index a507a83..405cabf 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -101,7 +101,7 @@ struct _GcalWindow
GtkApplicationWindow parent;
/* timeout ids */
- guint save_geometry_timeout_id;
+ guint save_settings_timeout_id;
guint notification_timeout;
/* upper level widgets */
@@ -180,7 +180,7 @@ enum
PROP_NEW_EVENT_MODE
};
-#define SAVE_GEOMETRY_ID_TIMEOUT 100 /* ms */
+#define SAVE_SETTINGS_ID_TIMEOUT 100 /* ms */
#define FAST_REFRESH_TIMEOUT 900000 /* ms */
#define SLOW_REFRESH_TIMEOUT 3600000 /* ms */
@@ -544,58 +544,8 @@ calendar_listbox_sort_func (GtkListBoxRow *row1,
return g_ascii_strcasecmp (e_source_get_display_name (source1), e_source_get_display_name (source2));
}
-static void
-load_geometry (GcalWindow *window)
-{
- GcalApplication *app;
- GSettings *settings;
- GVariant *variant;
- gboolean maximized;
- const gint32 *position;
- const gint32 *size;
- gsize n_elements;
-
- GCAL_ENTRY;
-
- app = GCAL_APPLICATION (gtk_window_get_application (GTK_WINDOW (window)));
- settings = gcal_application_get_settings (app);
-
- /* load window settings: size */
- variant = g_settings_get_value (settings,
- "window-size");
- size = g_variant_get_fixed_array (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);
-
- /* 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]);
-
- g_variant_unref (variant);
-
- /* load window settings: state */
- maximized = g_settings_get_boolean (settings,
- "window-maximized");
- if (maximized)
- gtk_window_maximize (GTK_WINDOW (window));
-
- GCAL_EXIT;
-}
-
static gboolean
-save_geometry (gpointer user_data)
+save_settings (gpointer user_data)
{
GcalWindow *window;
GtkWindow *self;
@@ -627,7 +577,7 @@ save_geometry (gpointer user_data)
if (maximized)
{
- window->save_geometry_timeout_id = 0;
+ window->save_settings_timeout_id = 0;
GCAL_RETURN (G_SOURCE_REMOVE);
}
@@ -655,11 +605,85 @@ save_geometry (gpointer user_data)
"window-position",
variant);
- window->save_geometry_timeout_id = 0;
+ /* Sidebar */
+ g_settings_set_boolean (settings,
+ "show-sidebar",
+ gtk_revealer_get_reveal_child (GTK_REVEALER (window->sidebar)));
+
+ window->save_settings_timeout_id = 0;
GCAL_RETURN (G_SOURCE_REMOVE);
}
+static void
+load_settings (GcalWindow *window)
+{
+ GcalApplication *app;
+ GSettings *settings;
+ GVariant *variant;
+ gboolean maximized;
+ gboolean show_sidebar;
+ const gint32 *position;
+ const gint32 *size;
+ gsize n_elements;
+
+ GCAL_ENTRY;
+
+ app = GCAL_APPLICATION (gtk_window_get_application (GTK_WINDOW (window)));
+ settings = gcal_application_get_settings (app);
+
+ /* load window settings: size */
+ variant = g_settings_get_value (settings,
+ "window-size");
+ size = g_variant_get_fixed_array (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);
+
+ /* 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]);
+
+ g_variant_unref (variant);
+
+ /* load window settings: state */
+ maximized = g_settings_get_boolean (settings,
+ "window-maximized");
+ if (maximized)
+ gtk_window_maximize (GTK_WINDOW (window));
+
+ /* Show the sidebar */
+ show_sidebar = g_settings_get_boolean (settings, "show-sidebar");
+
+ if (show_sidebar)
+ {
+ g_signal_handlers_block_by_func (window->sidebar, save_settings, window);
+
+ gtk_revealer_set_transition_type (GTK_REVEALER (window->sidebar),
+ GTK_REVEALER_TRANSITION_TYPE_NONE);
+
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->sidebar), TRUE);
+
+ gtk_revealer_set_transition_type (GTK_REVEALER (window->sidebar),
+ GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT);
+
+ g_signal_handlers_unblock_by_func (window->sidebar, save_settings, window);
+ }
+
+ GCAL_EXIT;
+}
+
/**
* view_changed:
* @object:
@@ -1293,10 +1317,10 @@ gcal_window_finalize (GObject *object)
GCAL_ENTRY;
- if (window->save_geometry_timeout_id > 0)
+ if (window->save_settings_timeout_id > 0)
{
- g_source_remove (window->save_geometry_timeout_id);
- window->save_geometry_timeout_id = 0;
+ g_source_remove (window->save_settings_timeout_id);
+ window->save_settings_timeout_id = 0;
}
if (window->open_edit_dialog_timeout_id > 0)
@@ -1439,14 +1463,14 @@ gcal_window_configure_event (GtkWidget *widget,
window = GCAL_WINDOW (widget);
- if (window->save_geometry_timeout_id != 0)
+ if (window->save_settings_timeout_id != 0)
{
- g_source_remove (window->save_geometry_timeout_id);
- window->save_geometry_timeout_id = 0;
+ g_source_remove (window->save_settings_timeout_id);
+ window->save_settings_timeout_id = 0;
}
- window->save_geometry_timeout_id = g_timeout_add (SAVE_GEOMETRY_ID_TIMEOUT,
- save_geometry,
+ window->save_settings_timeout_id = g_timeout_add (SAVE_SETTINGS_ID_TIMEOUT,
+ save_settings,
window);
retval = GTK_WIDGET_CLASS (gcal_window_parent_class)->configure_event (widget, event);
@@ -1463,14 +1487,14 @@ gcal_window_state_event (GtkWidget *widget,
window = GCAL_WINDOW (widget);
- if (window->save_geometry_timeout_id != 0)
+ if (window->save_settings_timeout_id != 0)
{
- g_source_remove (window->save_geometry_timeout_id);
- window->save_geometry_timeout_id = 0;
+ g_source_remove (window->save_settings_timeout_id);
+ window->save_settings_timeout_id = 0;
}
- window->save_geometry_timeout_id = g_timeout_add (SAVE_GEOMETRY_ID_TIMEOUT,
- save_geometry,
+ window->save_settings_timeout_id = g_timeout_add (SAVE_SETTINGS_ID_TIMEOUT,
+ save_settings,
window);
retval = GTK_WIDGET_CLASS (gcal_window_parent_class)->window_state_event (widget, event);
@@ -1586,6 +1610,7 @@ gcal_window_class_init(GcalWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, event_activated);
/* Syncronization related */
+ gtk_widget_class_bind_template_callback (widget_class, save_settings);
gtk_widget_class_bind_template_callback (widget_class, window_state_changed);
/* search related */
@@ -1719,7 +1744,7 @@ gcal_window_new_with_view_and_date (GcalApplication *app,
NULL);
/* loading size */
- load_geometry (win);
+ load_settings (win);
if (view_type == GCAL_WINDOW_VIEW_DAY)
view_changed (NULL, NULL, win);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]