[evolution] eds-I#297 - CalDAV: Support calendar-order property
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] eds-I#297 - CalDAV: Support calendar-order property
- Date: Wed, 10 Feb 2021 14:07:57 +0000 (UTC)
commit 61b7c1916fa069d6941ca33764866dd86950cd26
Author: Milan Crha <mcrha redhat com>
Date: Wed Feb 10 15:06:36 2021 +0100
eds-I#297 - CalDAV: Support calendar-order property
Adapt to the API changes and use the property in the ESourceSelector.
Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/297
src/e-util/e-source-selector.c | 115 ++++++++++++++++++++-
.../evolution-book-config-carddav.c | 11 +-
.../evolution-cal-config-caldav.c | 48 ++++-----
.../cal-config-google/e-google-chooser-button.c | 48 ++++-----
.../evolution-cal-config-webdav-notes.c | 36 ++++---
5 files changed, 192 insertions(+), 66 deletions(-)
---
diff --git a/src/e-util/e-source-selector.c b/src/e-util/e-source-selector.c
index 3dcb67ac70..efc72fdf20 100644
--- a/src/e-util/e-source-selector.c
+++ b/src/e-util/e-source-selector.c
@@ -102,6 +102,7 @@ enum {
COLUMN_TOOLTIP,
COLUMN_IS_BUSY,
COLUMN_CONNECTION_STATUS,
+ COLUMN_SORT_ORDER,
NUM_COLUMNS
};
@@ -1922,7 +1923,8 @@ e_source_selector_init (ESourceSelector *selector)
E_TYPE_SOURCE, /* COLUMN_SOURCE */
G_TYPE_STRING, /* COLUMN_TOOLTIP */
G_TYPE_BOOLEAN, /* COLUMN_IS_BUSY */
- G_TYPE_UINT); /* COLUMN_CONNECTION_STATUS */
+ G_TYPE_UINT, /* COLUMN_CONNECTION_STATUS */
+ G_TYPE_UINT); /* COLUMN_SORT_ORDER */
gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (tree_store));
@@ -2851,6 +2853,96 @@ e_source_selector_queue_write (ESourceSelector *selector,
g_source_unref (idle_source);
}
+static void
+source_selector_sort_sibling (ESourceSelector *selector,
+ GtkTreeModel *model,
+ GtkTreeIter *changed_child)
+{
+ GtkTreeIter iter, dest_iter;
+ ESource *child_source = NULL;
+ gboolean changed = FALSE, insert_before;
+
+ gtk_tree_model_get (model, changed_child, COLUMN_SOURCE, &child_source, -1);
+
+ if (!child_source)
+ return;
+
+ insert_before = TRUE;
+ iter = *changed_child;
+
+ while (gtk_tree_model_iter_previous (model, &iter)) {
+ ESource *source = NULL;
+ gint cmp_value;
+
+ gtk_tree_model_get (model, &iter, COLUMN_SOURCE, &source, -1);
+
+ cmp_value = e_util_source_compare_for_sort (source, child_source);
+
+ g_clear_object (&source);
+
+ if (cmp_value <= 0)
+ break;
+
+ dest_iter = iter;
+ changed = TRUE;
+ }
+
+ if (!changed) {
+ insert_before = FALSE;
+ iter = *changed_child;
+
+ while (gtk_tree_model_iter_next (model, &iter)) {
+ ESource *source = NULL;
+ gint cmp_value;
+
+ gtk_tree_model_get (model, &iter, COLUMN_SOURCE, &source, -1);
+
+ cmp_value = e_util_source_compare_for_sort (child_source, source);
+
+ g_clear_object (&source);
+
+ if (cmp_value <= 0)
+ break;
+
+ dest_iter = iter;
+ changed = TRUE;
+ }
+ }
+
+ if (changed) {
+ GtkTreeStore *tree_store = GTK_TREE_STORE (model);
+ GtkTreeSelection *selection;
+ GtkTreeRowReference *reference;
+ GtkTreeIter new_child;
+ GtkTreePath *path;
+ gboolean been_selected;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (selector));
+ been_selected = gtk_tree_selection_iter_is_selected (selection, changed_child);
+
+ gtk_tree_store_remove (tree_store, changed_child);
+
+ if (insert_before)
+ gtk_tree_store_insert_before (tree_store, &new_child, NULL, &dest_iter);
+ else
+ gtk_tree_store_insert_after (tree_store, &new_child, NULL, &dest_iter);
+
+ g_hash_table_remove (selector->priv->source_index, child_source);
+
+ path = gtk_tree_model_get_path (model, &new_child);
+ reference = gtk_tree_row_reference_new (model, path);
+ g_hash_table_insert (selector->priv->source_index, g_object_ref (child_source), reference);
+ gtk_tree_path_free (path);
+
+ e_source_selector_update_row (selector, child_source);
+
+ if (been_selected)
+ gtk_tree_selection_select_iter (selection, &new_child);
+ }
+
+ g_object_unref (child_source);
+}
+
/**
* e_source_selector_update_row:
* @selector: an #ESourceSelector
@@ -2905,12 +2997,14 @@ e_source_selector_update_row (ESourceSelector *selector,
extension = e_source_get_extension (source, extension_name);
if (extension != NULL) {
+ ESource *current_source = NULL;
GdkRGBA rgba;
const gchar *color_spec = NULL;
const gchar *icon_name;
gboolean show_color;
gboolean show_icons;
gboolean show_toggle;
+ guint old_sort_order = 0, new_sort_order = 0;
show_color =
E_IS_SOURCE_SELECTABLE (extension) &&
@@ -2928,6 +3022,18 @@ e_source_selector_update_row (ESourceSelector *selector,
show_toggle = e_source_selector_get_show_toggles (selector);
+ gtk_tree_model_get (model, &iter,
+ COLUMN_SORT_ORDER, &old_sort_order,
+ COLUMN_SOURCE, ¤t_source,
+ -1);
+
+ if (E_IS_SOURCE_SELECTABLE (extension))
+ new_sort_order = e_source_selectable_get_order (E_SOURCE_SELECTABLE (extension));
+ else if (E_IS_SOURCE_ADDRESS_BOOK (extension))
+ new_sort_order = e_source_address_book_get_order (E_SOURCE_ADDRESS_BOOK (extension));
+ else
+ new_sort_order = old_sort_order;
+
gtk_tree_store_set (
GTK_TREE_STORE (model), &iter,
COLUMN_NAME, display_name,
@@ -2939,7 +3045,14 @@ e_source_selector_update_row (ESourceSelector *selector,
COLUMN_SHOW_TOGGLE, show_toggle,
COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL,
COLUMN_SOURCE, source,
+ COLUMN_SORT_ORDER, new_sort_order,
-1);
+
+ /* The 'current_source' is NULL on newly added rows and non-NULL when refreshing existing row
*/
+ if (new_sort_order != old_sort_order && current_source != NULL)
+ source_selector_sort_sibling (selector, model, &iter);
+
+ g_clear_object (¤t_source);
} else {
gtk_tree_store_set (
GTK_TREE_STORE (model), &iter,
diff --git a/src/modules/book-config-carddav/evolution-book-config-carddav.c
b/src/modules/book-config-carddav/evolution-book-config-carddav.c
index 97731b9190..7acd37c4a0 100644
--- a/src/modules/book-config-carddav/evolution-book-config-carddav.c
+++ b/src/modules/book-config-carddav/evolution-book-config-carddav.c
@@ -115,20 +115,27 @@ book_config_carddav_run_dialog (GtkButton *button,
if (gtk_dialog_run (dialog) == GTK_RESPONSE_ACCEPT) {
gchar *href = NULL, *display_name = NULL, *color = NULL, *email;
- guint supports = 0;
+ guint supports = 0, order = 0;
GtkWidget *content;
content = e_webdav_discover_dialog_get_content (dialog);
- if (e_webdav_discover_content_get_selected (content, 0, &href, &supports, &display_name,
&color)) {
+ if (e_webdav_discover_content_get_selected (content, 0, &href, &supports, &display_name,
&color, &order)) {
soup_uri_free (uri);
uri = soup_uri_new (href);
if (uri) {
+ ESourceAddressBook *addressbook_extension;
+
+ addressbook_extension = e_source_get_extension (context->scratch_source,
E_SOURCE_EXTENSION_ADDRESS_BOOK);
+
e_source_set_display_name (context->scratch_source, display_name);
e_source_webdav_set_display_name (webdav_extension, display_name);
e_source_webdav_set_soup_uri (webdav_extension, uri);
+ e_source_webdav_set_order (webdav_extension, order);
+
+ e_source_address_book_set_order (addressbook_extension, order);
}
g_free (href);
diff --git a/src/modules/cal-config-caldav/evolution-cal-config-caldav.c
b/src/modules/cal-config-caldav/evolution-cal-config-caldav.c
index ca865813d4..a6514bc8bc 100644
--- a/src/modules/cal-config-caldav/evolution-cal-config-caldav.c
+++ b/src/modules/cal-config-caldav/evolution-cal-config-caldav.c
@@ -146,46 +146,48 @@ cal_config_caldav_run_dialog (GtkButton *button,
if (gtk_dialog_run (dialog) == GTK_RESPONSE_ACCEPT) {
gchar *href = NULL, *display_name = NULL, *color = NULL, *email;
- guint supports = 0;
+ guint supports = 0, order = 0;
GtkWidget *content;
content = e_webdav_discover_dialog_get_content (dialog);
- if (e_webdav_discover_content_get_selected (content, 0, &href, &supports, &display_name,
&color)) {
+ if (e_webdav_discover_content_get_selected (content, 0, &href, &supports, &display_name,
&color, &order)) {
soup_uri_free (uri);
uri = soup_uri_new (href);
if (uri) {
+ ESourceSelectable *selectable_extension;
+ const gchar *extension_name;
+
+ switch (source_type) {
+ case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
+ extension_name = E_SOURCE_EXTENSION_CALENDAR;
+ break;
+ case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
+ extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+ break;
+ case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
+ extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+ break;
+ default:
+ g_return_if_reached ();
+ }
+
+ selectable_extension = e_source_get_extension (context->scratch_source,
extension_name);
+
e_source_set_display_name (context->scratch_source, display_name);
e_source_webdav_set_display_name (webdav_extension, display_name);
e_source_webdav_set_soup_uri (webdav_extension, uri);
+ e_source_webdav_set_order (webdav_extension, order);
if (source_type != E_CAL_CLIENT_SOURCE_TYPE_MEMOS)
e_source_webdav_set_calendar_auto_schedule (webdav_extension,
(supports & E_WEBDAV_DISCOVER_SUPPORTS_CALENDAR_AUTO_SCHEDULE) != 0);
- if (color && *color) {
- ESourceSelectable *selectable_extension;
- const gchar *extension_name;
-
- switch (source_type) {
- case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
- extension_name = E_SOURCE_EXTENSION_CALENDAR;
- break;
- case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
- extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
- break;
- case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
- extension_name = E_SOURCE_EXTENSION_TASK_LIST;
- break;
- default:
- g_return_if_reached ();
- }
-
- selectable_extension = e_source_get_extension
(context->scratch_source, extension_name);
-
+ if (color && *color)
e_source_selectable_set_color (selectable_extension, color);
- }
+
+ e_source_selectable_set_order (selectable_extension, order);
}
g_free (href);
diff --git a/src/modules/cal-config-google/e-google-chooser-button.c
b/src/modules/cal-config-google/e-google-chooser-button.c
index 7c2852bcbe..80978d572c 100644
--- a/src/modules/cal-config-google/e-google-chooser-button.c
+++ b/src/modules/cal-config-google/e-google-chooser-button.c
@@ -257,43 +257,45 @@ google_chooser_button_clicked (GtkButton *button)
if (gtk_dialog_run (dialog) == GTK_RESPONSE_ACCEPT) {
gchar *href = NULL, *display_name = NULL, *color = NULL, *email;
- guint supports = 0;
+ guint supports = 0, order = 0;
GtkWidget *content;
content = e_webdav_discover_dialog_get_content (dialog);
- if (e_webdav_discover_content_get_selected (content, 0, &href, &supports, &display_name,
&color)) {
+ if (e_webdav_discover_content_get_selected (content, 0, &href, &supports, &display_name,
&color, &order)) {
soup_uri_free (uri);
uri = soup_uri_new (href);
if (uri) {
+ ESourceSelectable *selectable_extension;
+ const gchar *extension_name;
+
+ switch (e_cal_source_config_get_source_type (E_CAL_SOURCE_CONFIG
(priv->config))) {
+ case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
+ extension_name = E_SOURCE_EXTENSION_CALENDAR;
+ break;
+ case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
+ extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+ break;
+ case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
+ extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+ break;
+ default:
+ g_return_if_reached ();
+ }
+
+ selectable_extension = e_source_get_extension (priv->source, extension_name);
+
e_source_set_display_name (priv->source, display_name);
e_source_webdav_set_display_name (webdav_extension, display_name);
e_source_webdav_set_soup_uri (webdav_extension, uri);
+ e_source_webdav_set_order (webdav_extension, order);
- if (color && *color) {
- ESourceSelectable *selectable_extension;
- const gchar *extension_name;
-
- switch (e_cal_source_config_get_source_type (E_CAL_SOURCE_CONFIG
(priv->config))) {
- case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
- extension_name = E_SOURCE_EXTENSION_CALENDAR;
- break;
- case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
- extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
- break;
- case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
- extension_name = E_SOURCE_EXTENSION_TASK_LIST;
- break;
- default:
- g_return_if_reached ();
- }
-
- selectable_extension = e_source_get_extension (priv->source,
extension_name);
-
+ if (color && *color)
e_source_selectable_set_color (selectable_extension, color);
- }
+
+ e_source_selectable_set_order (selectable_extension, order);
}
g_free (href);
diff --git a/src/modules/cal-config-webdav-notes/evolution-cal-config-webdav-notes.c
b/src/modules/cal-config-webdav-notes/evolution-cal-config-webdav-notes.c
index 5229dc3c67..7301ae29e8 100644
--- a/src/modules/cal-config-webdav-notes/evolution-cal-config-webdav-notes.c
+++ b/src/modules/cal-config-webdav-notes/evolution-cal-config-webdav-notes.c
@@ -132,37 +132,39 @@ cal_config_webdav_notes_run_dialog (GtkButton *button,
if (gtk_dialog_run (dialog) == GTK_RESPONSE_ACCEPT) {
gchar *href = NULL, *display_name = NULL, *color = NULL, *email;
- guint supports = 0;
+ guint supports = 0, order = 0;
GtkWidget *content;
content = e_webdav_discover_dialog_get_content (dialog);
- if (e_webdav_discover_content_get_selected (content, 0, &href, &supports, &display_name,
&color)) {
+ if (e_webdav_discover_content_get_selected (content, 0, &href, &supports, &display_name,
&color, &order)) {
soup_uri_free (uri);
uri = soup_uri_new (href);
if (uri) {
+ ESourceSelectable *selectable_extension;
+ const gchar *extension_name;
+
+ switch (source_type) {
+ case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
+ extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+ break;
+ default:
+ g_return_if_reached ();
+ }
+
+ selectable_extension = e_source_get_extension (context->scratch_source,
extension_name);
+
e_source_set_display_name (context->scratch_source, display_name);
e_source_webdav_set_display_name (webdav_extension, display_name);
e_source_webdav_set_soup_uri (webdav_extension, uri);
+ e_source_webdav_set_order (webdav_extension, order);
- if (color && *color) {
- ESourceSelectable *selectable_extension;
- const gchar *extension_name;
-
- switch (source_type) {
- case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
- extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
- break;
- default:
- g_return_if_reached ();
- }
-
- selectable_extension = e_source_get_extension
(context->scratch_source, extension_name);
-
+ if (color && *color)
e_source_selectable_set_color (selectable_extension, color);
- }
+
+ e_source_selectable_set_order (selectable_extension, order);
}
g_free (href);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]