[evolution] I#528 - Calendar's List View changes forgotten next run
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] I#528 - Calendar's List View changes forgotten next run
- Date: Wed, 28 Aug 2019 17:04:12 +0000 (UTC)
commit 412dff2f8e798eb24a202576ea21a609baa1b380
Author: Milan Crha <mcrha redhat com>
Date: Wed Aug 28 19:00:29 2019 +0200
I#528 - Calendar's List View changes forgotten next run
Closes https://gitlab.gnome.org/GNOME/evolution/issues/528
src/modules/calendar/e-cal-shell-content.c | 13 +++
src/modules/calendar/e-cal-shell-content.h | 1 +
src/modules/calendar/e-cal-shell-view-private.c | 114 +++++++++++++++++++++++-
3 files changed, 125 insertions(+), 3 deletions(-)
---
diff --git a/src/modules/calendar/e-cal-shell-content.c b/src/modules/calendar/e-cal-shell-content.c
index f845400a55..5cca6f5a0b 100644
--- a/src/modules/calendar/e-cal-shell-content.c
+++ b/src/modules/calendar/e-cal-shell-content.c
@@ -70,6 +70,8 @@ struct _ECalShellContentPrivate {
time_t previous_selected_end_time;
gulong current_view_id_changed_id;
+
+ gboolean initialized;
};
enum {
@@ -1451,6 +1453,8 @@ cal_shell_content_view_created (ECalBaseShellContent *cal_base_shell_content)
e_signal_connect_notify (
model, "notify::week-start-day",
G_CALLBACK (cal_shell_content_notify_week_start_day_cb), cal_shell_content);
+
+ cal_shell_content->priv->initialized = TRUE;
}
static void
@@ -1920,6 +1924,7 @@ e_cal_shell_content_init (ECalShellContent *cal_shell_content)
cal_shell_content->priv->view_start_range_day_offset = (guint32) -1;
cal_shell_content->priv->previous_selected_start_time = -1;
cal_shell_content->priv->previous_selected_end_time = -1;
+ cal_shell_content->priv->initialized = FALSE;
}
void
@@ -1941,6 +1946,14 @@ e_cal_shell_content_new (EShellView *shell_view)
"shell-view", shell_view, NULL);
}
+gboolean
+e_cal_shell_content_get_initialized (ECalShellContent *cal_shell_content)
+{
+ g_return_val_if_fail (E_IS_CAL_SHELL_CONTENT (cal_shell_content), FALSE);
+
+ return cal_shell_content->priv->initialized;
+}
+
GtkNotebook *
e_cal_shell_content_get_calendar_notebook (ECalShellContent *cal_shell_content)
{
diff --git a/src/modules/calendar/e-cal-shell-content.h b/src/modules/calendar/e-cal-shell-content.h
index 571b65b8cc..21a9d2e403 100644
--- a/src/modules/calendar/e-cal-shell-content.h
+++ b/src/modules/calendar/e-cal-shell-content.h
@@ -75,6 +75,7 @@ GType e_cal_shell_content_get_type (void);
void e_cal_shell_content_type_register (GTypeModule *type_module);
GtkWidget * e_cal_shell_content_new (EShellView *shell_view);
+gboolean e_cal_shell_content_get_initialized (ECalShellContent *cal_shell_content);
GtkNotebook * e_cal_shell_content_get_calendar_notebook
(ECalShellContent *cal_shell_content);
EMemoTable * e_cal_shell_content_get_memo_table (ECalShellContent *cal_shell_content);
diff --git a/src/modules/calendar/e-cal-shell-view-private.c b/src/modules/calendar/e-cal-shell-view-private.c
index 45154c7a4b..f9b7c52eea 100644
--- a/src/modules/calendar/e-cal-shell-view-private.c
+++ b/src/modules/calendar/e-cal-shell-view-private.c
@@ -144,24 +144,132 @@ cal_shell_view_backend_error_cb (EClientCache *client_cache,
}
}
+static void
+cal_shell_view_save_last_list_view (EShellView *shell_view,
+ const gchar *view_id)
+{
+ GKeyFile *state_key_file;
+ gchar *saved_view_id;
+
+ state_key_file = e_shell_view_get_state_key_file (shell_view);
+ saved_view_id = g_key_file_get_string (state_key_file, "Calendar", "LastListView", NULL);
+
+ if (!view_id)
+ view_id = "";
+
+ if (g_strcmp0 (saved_view_id, view_id) != 0) {
+ g_key_file_set_string (state_key_file, "Calendar", "LastListView", view_id);
+ e_shell_view_set_state_dirty (shell_view);
+ }
+
+ g_free (saved_view_id);
+}
+
+static void
+cal_shell_view_set_custom_view (GalViewInstance *view_instance)
+{
+ gint ii, count;
+
+ g_return_if_fail (view_instance != NULL);
+
+ count = gal_view_collection_get_count (view_instance->collection);
+
+ for (ii = 0; ii < count; ii++) {
+ GalViewCollectionItem *item;
+
+ item = gal_view_collection_get_view_item (view_instance->collection, ii);
+
+ if (item && g_strcmp0 (item->id, "List_View") == 0) {
+ GalView *view;
+
+ view = gal_view_clone (item->view);
+ gal_view_load (view, view_instance->custom_filename);
+ gal_view_instance_set_custom_view (view_instance, view);
+ g_clear_object (&view);
+ break;
+ }
+ }
+}
+
static void
cal_shell_view_notify_view_id_cb (EShellView *shell_view)
{
+ static gboolean inside = FALSE;
+ ECalShellContent *cal_shell_content;
GalViewInstance *view_instance;
+ GKeyFile *state_key_file;
+ gchar *last_list_view = NULL;
+ gboolean was_list_view, content_initialized;
+ gchar *was_view_id = NULL;
const gchar *view_id;
+ /* Avoid recursion */
+ if (inside)
+ return;
+
+ inside = TRUE;
+
view_id = e_shell_view_get_view_id (shell_view);
- view_instance = e_shell_view_get_view_instance (shell_view);
/* A NULL view ID implies we're in a custom view. But you can
* only get to a custom view via the "Define Views" dialog, which
* would have already modified the view instance appropriately.
* Furthermore, there's no way to refer to a custom view by ID
* anyway, since custom views have no IDs. */
- if (view_id == NULL)
+ if (view_id == NULL) {
+ /* Custom view is always List_View */
+ cal_shell_view_save_last_list_view (shell_view, "");
+ inside = FALSE;
return;
+ }
+
+ view_instance = e_shell_view_get_view_instance (shell_view);
+ state_key_file = e_shell_view_get_state_key_file (shell_view);
+
+ was_list_view = g_strcmp0 (view_instance->current_type, "etable") == 0;
+ if (was_list_view)
+ was_view_id = g_strdup (view_instance->current_id);
+
+ cal_shell_content = E_CAL_SHELL_CONTENT (e_shell_view_get_shell_content (shell_view));
+ content_initialized = e_cal_shell_content_get_initialized (cal_shell_content);
+
+ if ((!content_initialized || !was_list_view) && g_strcmp0 (view_id, "List_View") == 0) {
+ GError *local_error = NULL;
+
+ last_list_view = g_key_file_get_string (state_key_file, "Calendar", "LastListView",
&local_error);
+
+ if (!g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND) &&
+ !g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
+ if (last_list_view && !*last_list_view) {
+ g_clear_pointer (&last_list_view, g_free);
+ }
+
+ if (!last_list_view ||
+ gal_view_collection_get_view_index_by_id (view_instance->collection,
last_list_view) >= 0) {
+ view_id = last_list_view;
+ }
+ }
+
+ g_clear_error (&local_error);
+ }
+
+ if (view_id && g_strcmp0 (view_id, e_shell_view_get_view_id (shell_view)) != 0)
+ e_shell_view_set_view_id (shell_view, view_id);
+ else if (view_id)
+ gal_view_instance_set_current_view_id (view_instance, view_id);
+ else
+ cal_shell_view_set_custom_view (view_instance);
+
+ if (g_strcmp0 (view_instance->current_type, "etable") == 0) {
+ cal_shell_view_save_last_list_view (shell_view, view_instance->current_id);
+ } else if (was_list_view) {
+ cal_shell_view_save_last_list_view (shell_view, was_view_id);
+ }
+
+ g_free (last_list_view);
+ g_free (was_view_id);
- gal_view_instance_set_current_view_id (view_instance, view_id);
+ inside = FALSE;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]