Add a property to have or not groups on EmpathyContactListStore
authorXavier Claessens <xclaesse@src.gnome.org>
Sun, 20 Jan 2008 21:42:01 +0000 (21:42 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Sun, 20 Jan 2008 21:42:01 +0000 (21:42 +0000)
svn path=/trunk/; revision=586

libempathy-gtk/empathy-contact-list-store.c
libempathy-gtk/empathy-contact-list-store.h
libempathy-gtk/empathy-group-chat.c
libempathy-gtk/empathy-main-window.c
libempathy/empathy-contact-list.c
megaphone/src/megaphone-applet.c
python/pyempathygtk/pyempathygtk.defs

index 5cc0aa8875fc6559549d6d2ed8ba50486be92302..b430addd8aa1528a7e91581c0c38e22b1cf1b665 100644 (file)
@@ -54,6 +54,7 @@ typedef struct {
        EmpathyContactList         *list;
        gboolean                    show_offline;
        gboolean                    show_avatars;
+       gboolean                    show_groups;
        gboolean                    is_compact;
        gboolean                    show_active;
        EmpathyContactListStoreSort sort_criterium;
@@ -155,14 +156,63 @@ static gboolean         contact_list_store_update_list_mode_foreach  (GtkTreeMod
 
 enum {
        PROP_0,
+       PROP_CONTACT_LIST,
        PROP_SHOW_OFFLINE,
        PROP_SHOW_AVATARS,
+       PROP_SHOW_GROUPS,
        PROP_IS_COMPACT,
        PROP_SORT_CRITERIUM
 };
 
 G_DEFINE_TYPE (EmpathyContactListStore, empathy_contact_list_store, GTK_TYPE_TREE_STORE);
 
+
+static gboolean
+contact_list_store_iface_setup (gpointer user_data)
+{
+       EmpathyContactListStore     *store = user_data;
+       EmpathyContactListStorePriv *priv = GET_PRIV (store);
+       GList                       *contacts, *l;
+
+       /* Signal connection. */
+       g_signal_connect (priv->list,
+                         "members-changed",
+                         G_CALLBACK (contact_list_store_members_changed_cb),
+                         store);
+       g_signal_connect (priv->list,
+                         "groups-changed",
+                         G_CALLBACK (contact_list_store_groups_changed_cb),
+                         store);
+
+       /* Add contacts already created. */
+       contacts = empathy_contact_list_get_members (priv->list);
+       for (l = contacts; l; l = l->next) {
+               contact_list_store_members_changed_cb (priv->list, l->data,
+                                                      NULL, 0, NULL,
+                                                      TRUE,
+                                                      store);
+
+               g_object_unref (l->data);
+       }
+       g_list_free (contacts);
+
+       return FALSE;
+}
+
+
+static void
+contact_list_store_set_contact_list (EmpathyContactListStore *store,
+                                    EmpathyContactList      *list_iface)
+{
+       EmpathyContactListStorePriv *priv = GET_PRIV (store);
+
+       priv->list = g_object_ref (list_iface);
+
+       /* Let a chance to have all properties set before populating */
+       g_idle_add (contact_list_store_iface_setup,
+                   store);
+}
+
 static void
 empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass)
 {
@@ -172,6 +222,14 @@ empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass)
        object_class->get_property = contact_list_store_get_property;
        object_class->set_property = contact_list_store_set_property;
 
+       g_object_class_install_property (object_class,
+                                        PROP_CONTACT_LIST,
+                                        g_param_spec_object ("contact-list",
+                                                             "The contact list iface",
+                                                             "The contact list iface",
+                                                             EMPATHY_TYPE_CONTACT_LIST,
+                                                             G_PARAM_CONSTRUCT_ONLY |
+                                                             G_PARAM_READWRITE));
        g_object_class_install_property (object_class,
                                         PROP_SHOW_OFFLINE,
                                         g_param_spec_boolean ("show-offline",
@@ -188,6 +246,14 @@ empathy_contact_list_store_class_init (EmpathyContactListStoreClass *klass)
                                                                "avatars for contacts",
                                                                TRUE,
                                                                G_PARAM_READWRITE));
+        g_object_class_install_property (object_class,
+                                         PROP_SHOW_GROUPS,
+                                         g_param_spec_boolean ("show-groups",
+                                                               "Show Groups",
+                                                               "Whether contact list should display "
+                                                               "contact groups",
+                                                               TRUE,
+                                                               G_PARAM_READWRITE));
        g_object_class_install_property (object_class,
                                         PROP_IS_COMPACT,
                                         g_param_spec_boolean ("is-compact",
@@ -216,9 +282,11 @@ empathy_contact_list_store_init (EmpathyContactListStore *store)
        priv = GET_PRIV (store);
 
        priv->show_avatars = TRUE;
+       priv->show_groups = TRUE;
        priv->inhibit_active = g_timeout_add_seconds (ACTIVE_USER_WAIT_TO_ENABLE_TIME,
                                                      (GSourceFunc) contact_list_store_inibit_active_cb,
                                                      store);
+       contact_list_store_setup (store);
 }
 
 static void
@@ -260,12 +328,18 @@ contact_list_store_get_property (GObject    *object,
        priv = GET_PRIV (object);
 
        switch (param_id) {
+       case PROP_CONTACT_LIST:
+               g_value_set_object (value, priv->list);
+               break;
        case PROP_SHOW_OFFLINE:
                g_value_set_boolean (value, priv->show_offline);
                break;
        case PROP_SHOW_AVATARS:
                g_value_set_boolean (value, priv->show_avatars);
                break;
+       case PROP_SHOW_GROUPS:
+               g_value_set_boolean (value, priv->show_groups);
+               break;
        case PROP_IS_COMPACT:
                g_value_set_boolean (value, priv->is_compact);
                break;
@@ -289,6 +363,10 @@ contact_list_store_set_property (GObject      *object,
        priv = GET_PRIV (object);
 
        switch (param_id) {
+       case PROP_CONTACT_LIST:
+               contact_list_store_set_contact_list (EMPATHY_CONTACT_LIST_STORE (object),
+                                                    g_value_get_object (value));
+               break;
        case PROP_SHOW_OFFLINE:
                empathy_contact_list_store_set_show_offline (EMPATHY_CONTACT_LIST_STORE (object),
                                                            g_value_get_boolean (value));
@@ -297,6 +375,10 @@ contact_list_store_set_property (GObject      *object,
                empathy_contact_list_store_set_show_avatars (EMPATHY_CONTACT_LIST_STORE (object),
                                                            g_value_get_boolean (value));
                break;
+       case PROP_SHOW_GROUPS:
+               empathy_contact_list_store_set_show_groups (EMPATHY_CONTACT_LIST_STORE (object),
+                                                           g_value_get_boolean (value));
+               break;
        case PROP_IS_COMPACT:
                empathy_contact_list_store_set_is_compact (EMPATHY_CONTACT_LIST_STORE (object),
                                                          g_value_get_boolean (value));
@@ -312,43 +394,15 @@ contact_list_store_set_property (GObject      *object,
 }
 
 EmpathyContactListStore *
-empathy_contact_list_store_new (EmpathyContactList *list_iface)
+empathy_contact_list_store_new (EmpathyContactList *list_iface,
+                               gboolean            show_groups)
 {
-       EmpathyContactListStore     *store;
-       EmpathyContactListStorePriv *priv;
-       GList                      *contacts, *l;
-
        g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST (list_iface), NULL);
 
-       store = g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE, NULL);
-       priv = GET_PRIV (store);
-
-       contact_list_store_setup (store);
-       priv->list = g_object_ref (list_iface);
-
-       /* Signal connection. */
-       g_signal_connect (priv->list,
-                         "members-changed",
-                         G_CALLBACK (contact_list_store_members_changed_cb),
-                         store);
-       g_signal_connect (priv->list,
-                         "groups-changed",
-                         G_CALLBACK (contact_list_store_groups_changed_cb),
-                         store);
-
-       /* Add contacts already created. */
-       contacts = empathy_contact_list_get_members (priv->list);
-       for (l = contacts; l; l = l->next) {
-               contact_list_store_members_changed_cb (priv->list, l->data,
-                                                      NULL, 0, NULL,
-                                                      TRUE,
-                                                      store);
-
-               g_object_unref (l->data);
-       }
-       g_list_free (contacts);
-
-       return store;
+       return g_object_new (EMPATHY_TYPE_CONTACT_LIST_STORE,
+                            "contact-list", list_iface,
+                            "show-groups", show_groups,
+                            NULL);
 }
 
 EmpathyContactList *
@@ -403,6 +457,8 @@ empathy_contact_list_store_set_show_offline (EmpathyContactListStore *store,
 
        /* Restore to original setting. */
        priv->show_active = show_active;
+
+       g_object_notify (G_OBJECT (store), "show-offline");
 }
 
 gboolean
@@ -436,6 +492,54 @@ empathy_contact_list_store_set_show_avatars (EmpathyContactListStore *store,
                                (GtkTreeModelForeachFunc)
                                contact_list_store_update_list_mode_foreach,
                                store);
+
+       g_object_notify (G_OBJECT (store), "show-avatars");
+}
+
+gboolean
+empathy_contact_list_store_get_show_groups (EmpathyContactListStore *store)
+{
+       EmpathyContactListStorePriv *priv;
+
+       g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), TRUE);
+
+       priv = GET_PRIV (store);
+
+       return priv->show_groups;
+}
+
+void
+empathy_contact_list_store_set_show_groups (EmpathyContactListStore *store,
+                                           gboolean                 show_groups)
+{
+       EmpathyContactListStorePriv *priv;
+       GList                       *contacts, *l;
+
+       g_return_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store));
+
+       priv = GET_PRIV (store);
+
+       if (priv->show_groups == show_groups) {
+               return;
+       }
+
+       priv->show_groups = show_groups;
+
+       /* Remove all contacts and add them back, not optimized but that's the
+        * easy way :) */
+       gtk_tree_store_clear (GTK_TREE_STORE (store));
+       contacts = empathy_contact_list_get_members (priv->list);
+       for (l = contacts; l; l = l->next) {
+               contact_list_store_members_changed_cb (priv->list, l->data,
+                                                      NULL, 0, NULL,
+                                                      TRUE,
+                                                      store);
+
+               g_object_unref (l->data);
+       }
+       g_list_free (contacts);
+
+       g_object_notify (G_OBJECT (store), "show-groups");
 }
 
 gboolean
@@ -469,6 +573,8 @@ empathy_contact_list_store_set_is_compact (EmpathyContactListStore *store,
                                (GtkTreeModelForeachFunc)
                                contact_list_store_update_list_mode_foreach,
                                store);
+
+       g_object_notify (G_OBJECT (store), "is-compact");
 }
 
 EmpathyContactListStoreSort
@@ -508,6 +614,8 @@ empathy_contact_list_store_set_sort_criterium (EmpathyContactListStore     *stor
                                                      GTK_SORT_ASCENDING);
                break;
        }
+
+       g_object_notify (G_OBJECT (store), "sort-criterium");
 }
 
 gboolean
@@ -767,7 +875,7 @@ contact_list_store_add_contact (EmpathyContactListStore *store,
 {
        EmpathyContactListStorePriv *priv;
        GtkTreeIter                 iter;
-       GList                      *groups, *l;
+       GList                      *groups = NULL, *l;
 
        priv = GET_PRIV (store);
        
@@ -775,7 +883,9 @@ contact_list_store_add_contact (EmpathyContactListStore *store,
                return;
        }
 
-       groups = empathy_contact_list_get_groups (priv->list, contact);
+       if (priv->show_groups) {
+               groups = empathy_contact_list_get_groups (priv->list, contact);
+       }
 
        /* If no groups just add it at the top level. */
        if (!groups) {
index 214f5be603ed2efff60239847b1e390cb9d575b6..0dd6e43ac96ecd6c22b33932b8495c29f06969a4 100644 (file)
@@ -73,7 +73,8 @@ struct _EmpathyContactListStoreClass {
 };
 
 GType                      empathy_contact_list_store_get_type           (void) G_GNUC_CONST;
-EmpathyContactListStore *  empathy_contact_list_store_new                (EmpathyContactList         *list_iface);
+EmpathyContactListStore *  empathy_contact_list_store_new                (EmpathyContactList         *list_iface,
+                                                                         gboolean                    show_groups);
 EmpathyContactList *       empathy_contact_list_store_get_list_iface     (EmpathyContactListStore     *store);
 gboolean                   empathy_contact_list_store_get_show_offline   (EmpathyContactListStore     *store);
 void                       empathy_contact_list_store_set_show_offline   (EmpathyContactListStore     *store,
@@ -81,6 +82,9 @@ void                       empathy_contact_list_store_set_show_offline   (Empath
 gboolean                   empathy_contact_list_store_get_show_avatars   (EmpathyContactListStore     *store);
 void                       empathy_contact_list_store_set_show_avatars   (EmpathyContactListStore     *store,
                                                                         gboolean                    show_avatars);
+gboolean                   empathy_contact_list_store_get_show_groups   (EmpathyContactListStore     *store);
+void                       empathy_contact_list_store_set_show_groups   (EmpathyContactListStore     *store,
+                                                                        gboolean                    show_groups);
 gboolean                   empathy_contact_list_store_get_is_compact     (EmpathyContactListStore     *store);
 void                       empathy_contact_list_store_set_is_compact     (EmpathyContactListStore     *store,
                                                                         gboolean                    is_compact);
index 534f66c272534ac2103346c47bf3af1417efb510..8f361237a7590265a2db1b1ff76a38e2fcde1771 100644 (file)
@@ -526,7 +526,7 @@ group_chat_set_tp_chat (EmpathyChat    *chat,
        }
 
        /* Create contact list */
-       priv->store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
+       priv->store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat), TRUE);
        priv->view = empathy_contact_list_view_new (priv->store,
                                                    EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT |
                                                    EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL |
index d0353419a6dd27beeef379feac9891648c857068..03f11e58c80e32a299e379cab90677da3ea9e2e4 100644 (file)
@@ -284,7 +284,7 @@ empathy_main_window_show (void)
        empathy_status_presets_get_all ();
 
        list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
-       window->list_store = empathy_contact_list_store_new (list_iface);
+       window->list_store = empathy_contact_list_store_new (list_iface, TRUE);
        window->list_view = empathy_contact_list_view_new (window->list_store,
                                                           EMPATHY_CONTACT_LIST_FEATURE_ALL);
        g_object_unref (list_iface);
index 5164ccf1a5ad1b7adb890c60338982c91defa526..510e419570f58de68841fe50c1ecb3ce156dd181 100644 (file)
@@ -41,6 +41,8 @@ empathy_contact_list_get_type (void)
                type = g_type_register_static (G_TYPE_INTERFACE,
                                               "EmpathyContactList",
                                               &type_info, 0);
+
+               g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
        }
 
        return type;
index 17ae2c50b508afe6a2ebb9082ab18fe9070d63a7..5c499ac269b858922b6c3be4773a3f756f557326 100644 (file)
@@ -358,7 +358,7 @@ megaphone_applet_show_preferences (MegaphoneApplet *applet)
 
        /* Show all contacts, even offline and sort alphabetically */
        contact_manager = empathy_contact_manager_new ();
-       contact_store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (contact_manager));
+       contact_store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (contact_manager), TRUE);
        g_object_set (contact_store,
                      "is-compact", TRUE,
                      "show-avatars", TRUE,
index e3a9b637046ebf25a42fc73cd0b08e008625b56d..f168800d6d5bdfc37d9237d5206e91ed442c6fcf 100644 (file)
   (c-name "EmpathyContactListFeatures")
   (gtype-id "EMPATHY_TYPE_CONTACT_LIST_FEATURES")
   (values
-    '("groups-show" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SHOW")
-    '("groups-modify" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_MODIFY")
+    '("none" "EMPATHY_CONTACT_LIST_FEATURE_NONE")
+    '("groups-save" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE")
+    '("groups-rename" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME")
+    '("groups-remove" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE")
     '("contact-chat" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT")
     '("contact-call" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL")
     '("contact-log" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG")
     '("contact-edit" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT")
     '("contact-info" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO")
     '("contact-remove" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE")
+    '("contact-drop" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP")
+    '("contact-drag" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG")
+    '("all" "EMPATHY_CONTACT_LIST_FEATURE_ALL")
   )
 )
 
   (of-object "EmpathyContactList")
   (c-name "empathy_contact_list_store_new")
   (return-type "EmpathyContactListStore*")
+  (parameters
+    '("gboolean" "show_groups")
+  )
 )
 
 (define-method get_list_iface
   )
 )
 
+(define-method get_show_groups
+  (of-object "EmpathyContactListStore")
+  (c-name "empathy_contact_list_store_get_show_groups")
+  (return-type "gboolean")
+)
+
+(define-method set_show_groups
+  (of-object "EmpathyContactListStore")
+  (c-name "empathy_contact_list_store_set_show_groups")
+  (return-type "none")
+  (parameters
+    '("gboolean" "show_groups")
+  )
+)
+
 (define-method get_is_compact
   (of-object "EmpathyContactListStore")
   (c-name "empathy_contact_list_store_get_is_compact")