[evolution] I#1109 - CompEditor: Hide known read only groups for new events



commit d4d1ed8db0bc8913911d77bc1a1579a5efeea60f
Author: Milan Crha <mcrha redhat com>
Date:   Wed Sep 23 09:42:14 2020 +0200

    I#1109 - CompEditor: Hide known read only groups for new events
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1109

 src/calendar/gui/e-comp-editor-page-general.c |  8 +++
 src/calendar/gui/e-comp-editor-page-general.h |  2 +
 src/calendar/gui/e-comp-editor.c              | 28 +++++++++
 src/e-util/e-source-combo-box.c               | 91 ++++++++++++++++++++++++---
 src/e-util/e-source-combo-box.h               |  2 +
 5 files changed, 122 insertions(+), 9 deletions(-)
---
diff --git a/src/calendar/gui/e-comp-editor-page-general.c b/src/calendar/gui/e-comp-editor-page-general.c
index 852119c47c..d8eecc0554 100644
--- a/src/calendar/gui/e-comp-editor-page-general.c
+++ b/src/calendar/gui/e-comp-editor-page-general.c
@@ -2027,3 +2027,11 @@ e_comp_editor_page_general_get_removed_attendees (ECompEditorPageGeneral *page_g
 
        return g_slist_reverse (removed_attendees);
 }
+
+GtkWidget *
+e_comp_editor_page_general_get_source_combo_box (ECompEditorPageGeneral *page_general)
+{
+       g_return_val_if_fail (E_IS_COMP_EDITOR_PAGE_GENERAL (page_general), NULL);
+
+       return page_general->priv->source_combo_box;
+}
diff --git a/src/calendar/gui/e-comp-editor-page-general.h b/src/calendar/gui/e-comp-editor-page-general.h
index fa0f0d4ab3..4173cd91e3 100644
--- a/src/calendar/gui/e-comp-editor-page-general.h
+++ b/src/calendar/gui/e-comp-editor-page-general.h
@@ -113,6 +113,8 @@ GSList *    e_comp_editor_page_general_get_added_attendees
                                                        (ECompEditorPageGeneral *page_general);
 GSList *       e_comp_editor_page_general_get_removed_attendees
                                                        (ECompEditorPageGeneral *page_general);
+GtkWidget *    e_comp_editor_page_general_get_source_combo_box
+                                                       (ECompEditorPageGeneral *page_general);
 
 G_END_DECLS
 
diff --git a/src/calendar/gui/e-comp-editor.c b/src/calendar/gui/e-comp-editor.c
index 295e137a2f..c67001e39f 100644
--- a/src/calendar/gui/e-comp-editor.c
+++ b/src/calendar/gui/e-comp-editor.c
@@ -1599,6 +1599,31 @@ ece_connect_time_parts (ECompEditor *comp_editor,
 #undef update_part
 }
 
+static void
+ece_update_source_combo_box_by_flags (ECompEditor *comp_editor)
+{
+       ECompEditorPage *page;
+
+       page = e_comp_editor_get_page (comp_editor, E_TYPE_COMP_EDITOR_PAGE_GENERAL);
+
+       if (page) {
+               GtkWidget *source_combo_box;
+
+               source_combo_box = e_comp_editor_page_general_get_source_combo_box 
(E_COMP_EDITOR_PAGE_GENERAL (page));
+
+               if (source_combo_box) {
+                       if ((comp_editor->priv->flags & E_COMP_EDITOR_FLAG_IS_NEW) != 0) {
+                               e_source_combo_box_hide_sources (E_SOURCE_COMBO_BOX (source_combo_box),
+                                       "webcal-stub", "weather-stub", "contacts-stub",
+                                       "webcal", "weather", "contacts", "birthdays",
+                                       NULL);
+                       } else {
+                               e_source_combo_box_hide_sources (E_SOURCE_COMBO_BOX (source_combo_box), NULL);
+                       }
+               }
+       }
+}
+
 static void
 ece_sensitize_widgets (ECompEditor *comp_editor,
                       gboolean force_insensitive)
@@ -1681,6 +1706,7 @@ comp_editor_realize_cb (ECompEditor *comp_editor)
 
        e_comp_editor_update_window_title (comp_editor);
        e_comp_editor_sensitize_widgets (comp_editor);
+       ece_update_source_combo_box_by_flags (comp_editor);
 
        if (comp_editor->priv->page_general && comp_editor->priv->origin_source) {
                e_comp_editor_page_general_set_selected_source (
@@ -2831,6 +2857,8 @@ e_comp_editor_set_flags (ECompEditor *comp_editor,
 
        comp_editor->priv->flags = flags;
 
+       ece_update_source_combo_box_by_flags (comp_editor);
+
        g_object_notify (G_OBJECT (comp_editor), "flags");
 }
 
diff --git a/src/e-util/e-source-combo-box.c b/src/e-util/e-source-combo-box.c
index 93bbc535f3..443092c9c8 100644
--- a/src/e-util/e-source-combo-box.c
+++ b/src/e-util/e-source-combo-box.c
@@ -29,6 +29,7 @@
 struct _ESourceComboBoxPrivate {
        ESourceRegistry *registry;
        gchar *extension_name;
+       GHashTable *hide_sources;
 
        gulong source_added_handler_id;
        gulong source_removed_handler_id;
@@ -78,13 +79,30 @@ source_combo_box_traverse (GNode *node,
 
        ext_name = e_source_combo_box_get_extension_name (combo_box);
 
-       model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
-       gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-
        source = E_SOURCE (node->data);
+
+       if (ext_name != NULL && e_source_has_extension (source, ext_name)) {
+               extension = e_source_get_extension (source, ext_name);
+               sensitive = TRUE;
+
+               if (g_hash_table_size (combo_box->priv->hide_sources) && E_IS_SOURCE_BACKEND (extension) &&
+                   g_hash_table_contains (combo_box->priv->hide_sources, e_source_backend_get_backend_name 
(E_SOURCE_BACKEND (extension)))) {
+                       return FALSE;
+               }
+       }
+
        uid = e_source_get_uid (source);
+
+       if (g_hash_table_contains (combo_box->priv->hide_sources, uid) || (e_source_get_parent (source) &&
+           g_hash_table_contains (combo_box->priv->hide_sources, e_source_get_parent (source)))) {
+               return FALSE;
+       }
+
        display_name = e_source_get_display_name (source);
 
+       model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
+       gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+
        indented = g_string_new (NULL);
 
        depth = g_node_depth (node);
@@ -93,11 +111,6 @@ source_combo_box_traverse (GNode *node,
                g_string_append (indented, "    ");
        g_string_append (indented, display_name);
 
-       if (ext_name != NULL && e_source_has_extension (source, ext_name)) {
-               extension = e_source_get_extension (source, ext_name);
-               sensitive = TRUE;
-       }
-
        if (E_IS_SOURCE_SELECTABLE (extension)) {
                const gchar *color_spec;
 
@@ -174,6 +187,32 @@ source_combo_box_build_model (ESourceComboBox *combo_box)
                        g_object_unref (source);
                }
        }
+
+       if (!gtk_combo_box_get_active_id (gtk_combo_box)) {
+               GtkTreeIter iter;
+
+               if (gtk_tree_model_get_iter_first (model, &iter)) {
+                       do {
+                               gboolean sensitive = FALSE;
+
+                               gtk_tree_model_get (model, &iter, COLUMN_SENSITIVE, &sensitive, -1);
+
+                               if (sensitive) {
+                                       gchar *uid = NULL;
+
+                                       gtk_tree_model_get (model, &iter, COLUMN_UID, &uid, -1);
+
+                                       if (uid) {
+                                               gtk_combo_box_set_active_id (gtk_combo_box, uid);
+                                               g_free (uid);
+                                               break;
+                                       } else {
+                                               g_free (uid);
+                                       }
+                               }
+                       } while (gtk_tree_model_iter_next (model, &iter));
+               }
+       }
 }
 
 static void
@@ -305,6 +344,7 @@ source_combo_box_finalize (GObject *object)
        priv = E_SOURCE_COMBO_BOX_GET_PRIVATE (object);
 
        g_free (priv->extension_name);
+       g_hash_table_destroy (priv->hide_sources);
 
        /* Chain up to parent's "finalize" method. */
        G_OBJECT_CLASS (e_source_combo_box_parent_class)->finalize (object);
@@ -419,7 +459,7 @@ static void
 e_source_combo_box_init (ESourceComboBox *combo_box)
 {
        combo_box->priv = E_SOURCE_COMBO_BOX_GET_PRIVATE (combo_box);
-
+       combo_box->priv->hide_sources = g_hash_table_new_full (camel_strcase_hash, camel_strcase_equal, 
g_free, NULL);
 }
 
 /**
@@ -696,3 +736,36 @@ e_source_combo_box_set_active (ESourceComboBox *combo_box,
        gtk_combo_box_set_active_id (gtk_combo_box, uid);
 }
 
+/**
+ * e_source_combo_box_hide_sources:
+ * @combo_box: an #ESourceComboBox
+ * @...: a NULL-terminated list of UID-s of the sources to hide
+ *
+ * The UID-s can be also backend names. Apart of that, these are checked
+ * for both the ESource::uid and the ESource::parent.
+ *
+ * The next call replaces the list of source UID-s to be hidden.
+ *
+ * Since: 3.40
+ **/
+void
+e_source_combo_box_hide_sources (ESourceComboBox *combo_box,
+                                 ...)
+{
+       const gchar *backend_name;
+       va_list va;
+
+       g_return_if_fail (E_IS_SOURCE_COMBO_BOX (combo_box));
+
+       g_hash_table_remove_all (combo_box->priv->hide_sources);
+
+       va_start (va, combo_box);
+
+       while (backend_name = va_arg (va, const gchar *), backend_name) {
+               g_hash_table_insert (combo_box->priv->hide_sources, g_strdup (backend_name), NULL);
+       }
+
+       va_end (va);
+
+       source_combo_box_build_model (combo_box);
+}
diff --git a/src/e-util/e-source-combo-box.h b/src/e-util/e-source-combo-box.h
index 67f8f223ab..7a45b00154 100644
--- a/src/e-util/e-source-combo-box.h
+++ b/src/e-util/e-source-combo-box.h
@@ -82,6 +82,8 @@ void          e_source_combo_box_set_show_colors
 ESource *      e_source_combo_box_ref_active   (ESourceComboBox *combo_box);
 void           e_source_combo_box_set_active   (ESourceComboBox *combo_box,
                                                 ESource *source);
+void           e_source_combo_box_hide_sources (ESourceComboBox *combo_box,
+                                                ...) G_GNUC_NULL_TERMINATED;
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]