[evolution] EMFolderTree: Add 'folder-custom-icon' and 'compare-folders' signals



commit fcddfd27c9c0cddf3b9d3ef8cc993946358c12b7
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 5 20:26:10 2022 +0200

    EMFolderTree: Add 'folder-custom-icon' and 'compare-folders' signals
    
    Also make it extensible, thus anything can influence folder icon and change
    default folder order. The folder icon could be changed through the EPlugin API,
    thus this pairs the functionality with extensions.

 src/mail/em-folder-tree-model.c | 39 ++++++++++++++++++++++++++++++++++++++-
 src/mail/em-folder-tree-model.h |  8 ++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)
---
diff --git a/src/mail/em-folder-tree-model.c b/src/mail/em-folder-tree-model.c
index 63d8ffa795..26641870e8 100644
--- a/src/mail/em-folder-tree-model.c
+++ b/src/mail/em-folder-tree-model.c
@@ -117,6 +117,8 @@ enum {
 enum {
        LOADING_ROW,
        LOADED_ROW,
+       FOLDER_CUSTOM_ICON,
+       COMPARE_FOLDERS,
        LAST_SIGNAL
 };
 
@@ -152,7 +154,8 @@ static void folder_tree_model_status_notify_cb
 
 static guint signals[LAST_SIGNAL];
 
-G_DEFINE_TYPE (EMFolderTreeModel, em_folder_tree_model, GTK_TYPE_TREE_STORE)
+G_DEFINE_TYPE_WITH_CODE (EMFolderTreeModel, em_folder_tree_model, GTK_TYPE_TREE_STORE,
+       G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL))
 
 static StoreInfo *
 store_info_ref (StoreInfo *si)
@@ -470,6 +473,9 @@ folder_tree_model_sort (GtkTreeModel *model,
                        rv = 1;
        }
 
+       if (rv == -2 && !a_is_store && !b_is_store)
+               g_signal_emit (model, signals[COMPARE_FOLDERS], 0, store_uid, a, b, &rv);
+
        if (rv == -2) {
                if (aname != NULL && bname != NULL)
                        rv = g_utf8_collate (aname, bname);
@@ -847,6 +853,9 @@ em_folder_tree_model_update_folder_icon (EMFolderTreeModel *model,
                e_event_emit (
                        (EEvent *) em_event_peek (), "folder.customicon",
                        (EEventTarget *) target);
+
+               g_signal_emit (model, signals[FOLDER_CUSTOM_ICON], 0,
+                       &iter, store, full_name);
        }
 
        g_clear_object (&store);
@@ -1021,6 +1030,8 @@ folder_tree_model_constructed (GObject *object)
 
        /* Chain up to parent's constructed() method. */
        G_OBJECT_CLASS (em_folder_tree_model_parent_class)->constructed (object);
+
+       e_extensible_load_extensions (E_EXTENSIBLE (object));
 }
 
 static void
@@ -1078,6 +1089,29 @@ em_folder_tree_model_class_init (EMFolderTreeModelClass *class)
                G_TYPE_NONE, 2,
                G_TYPE_POINTER,
                G_TYPE_POINTER);
+
+       signals[FOLDER_CUSTOM_ICON] = g_signal_new (
+               "folder-custom-icon",
+               G_OBJECT_CLASS_TYPE (object_class),
+               G_SIGNAL_RUN_FIRST,
+               G_STRUCT_OFFSET (EMFolderTreeModelClass, folder_custom_icon),
+               NULL, NULL, NULL,
+               G_TYPE_NONE, 3,
+               G_TYPE_POINTER,
+               CAMEL_TYPE_STORE,
+               G_TYPE_STRING);
+
+       /* Return -2 for "default sort order", otherwise expects only -1, 0 or 1. */
+       signals[COMPARE_FOLDERS] = g_signal_new (
+               "compare-folders",
+               G_OBJECT_CLASS_TYPE (object_class),
+               G_SIGNAL_RUN_FIRST,
+               G_STRUCT_OFFSET (EMFolderTreeModelClass, compare_folders),
+               NULL, NULL, NULL,
+               G_TYPE_INT, 3,
+               G_TYPE_STRING,
+               G_TYPE_POINTER,
+               G_TYPE_POINTER);
 }
 
 static void
@@ -1580,6 +1614,9 @@ em_folder_tree_model_set_folder_info (EMFolderTreeModel *model,
                (EEvent *) em_event_peek (), "folder.customicon",
                (EEventTarget *) target);
 
+       g_signal_emit (model, signals[FOLDER_CUSTOM_ICON], 0,
+               iter, store, fi->full_name);
+
        if (unread != ~0)
                gtk_tree_store_set (
                        tree_store, iter, COL_UINT_UNREAD, unread,
diff --git a/src/mail/em-folder-tree-model.h b/src/mail/em-folder-tree-model.h
index 0a6151850f..aec76ca04f 100644
--- a/src/mail/em-folder-tree-model.h
+++ b/src/mail/em-folder-tree-model.h
@@ -111,6 +111,14 @@ struct _EMFolderTreeModelClass {
        void            (*loaded_row)           (EMFolderTreeModel *model,
                                                 GtkTreePath *path,
                                                 GtkTreeIter *iter);
+       void            (*folder_custom_icon)   (EMFolderTreeModel *model,
+                                                GtkTreeIter *iter,
+                                                CamelStore *store,
+                                                const gchar *full_name);
+       gint            (*compare_folders)      (EMFolderTreeModel *model,
+                                                const gchar *store_uid,
+                                                GtkTreeIter *iter1,
+                                                GtkTreeIter *iter2);
 };
 
 GType          em_folder_tree_model_get_type   (void);


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