]> git.0d.be Git - empathy.git/commitdiff
To know if an account is connected, use
authorXavier Claessens <xclaesse@gmail.com>
Sat, 20 Oct 2007 22:07:28 +0000 (22:07 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Sat, 20 Oct 2007 22:07:28 +0000 (22:07 +0000)
2007-10-21  Xavier Claessens  <xclaesse@gmail.com>

* libempathy-gtk/empathy-account-chooser.c:
* libempathy-gtk/empathy-contact-dialogs.c:
* libempathy-gtk/empathy-contact-widget.c:
* libempathy-gtk/empathy-contact-widget.h:
* libempathy-gtk/empathy-accounts-dialog.c: To know if an account is
connected, use mission_control_get_connection_status() instead of
mission_control_get_connection(). Update account chooser if an account's
status changes or if it get removed.
Move account chooser filter func for add-contact's window from
EmpathyContactWidget to EmpathyContactDialogs.

svn path=/trunk/; revision=384

ChangeLog
libempathy-gtk/empathy-account-chooser.c
libempathy-gtk/empathy-accounts-dialog.c
libempathy-gtk/empathy-contact-dialogs.c
libempathy-gtk/empathy-contact-widget.c
libempathy-gtk/empathy-contact-widget.h

index 823686e9f725685d5eef81e3ce792bb9fe2eccce..09a897d97b34305a78bee8f180e6035a508db556 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-10-21  Xavier Claessens  <xclaesse@gmail.com>
+
+       * libempathy-gtk/empathy-account-chooser.c:
+       * libempathy-gtk/empathy-contact-dialogs.c:
+       * libempathy-gtk/empathy-contact-widget.c:
+       * libempathy-gtk/empathy-contact-widget.h:
+       * libempathy-gtk/empathy-accounts-dialog.c: To know if an account is
+       connected, use mission_control_get_connection_status() instead of
+       mission_control_get_connection(). Update account chooser if an account's
+       status changes or if it get removed.
+       Move account chooser filter func for add-contact's window from
+       EmpathyContactWidget to EmpathyContactDialogs.
+
 2007-10-19  Xavier Claessens  <xclaesse@gmail.com>
 
        * libempathy-gtk/empathy-accounts-dialog.c: Update Enable/Disable
index 6d3aea6a61934762a4025e30c3cb7bd91d8ef24b..de6d55177a3ceb67602a4fe417dbae96f0ad2dbc 100644 (file)
@@ -83,14 +83,13 @@ static void     account_chooser_account_deleted_cb     (McAccountMonitor
 static void     account_chooser_account_remove_foreach (McAccount                       *account,
                                                        EmpathyAccountChooser            *chooser);
 static void     account_chooser_update_iter            (EmpathyAccountChooser            *chooser,
-                                                       GtkTreeIter                     *iter,
-                                                       McAccount                       *account);
+                                                       GtkTreeIter                     *iter);
 static void     account_chooser_status_changed_cb      (MissionControl                  *mc,
                                                        TelepathyConnectionStatus        status,
                                                        McPresence                       presence,
                                                        TelepathyConnectionStatusReason  reason,
                                                        const gchar                     *unique_name,
-                                                       EmpathyAccountChooser            *chooser);
+                                                       EmpathyAccountChooser           *chooser);
 static gboolean account_chooser_separator_func         (GtkTreeModel                    *model,
                                                        GtkTreeIter                     *iter,
                                                        EmpathyAccountChooser            *chooser);
@@ -254,7 +253,7 @@ empathy_account_chooser_get_account (EmpathyAccountChooser *chooser)
 
 gboolean
 empathy_account_chooser_set_account (EmpathyAccountChooser *chooser,
-                                   McAccount            *account)
+                                    McAccount             *account)
 {
        GtkComboBox    *combobox;
        GtkTreeModel   *model;
@@ -371,7 +370,7 @@ account_chooser_setup (EmpathyAccountChooser *chooser)
        gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
 
        store = gtk_list_store_new (COL_ACCOUNT_COUNT,
-                                   G_TYPE_STRING,
+                                   G_TYPE_STRING,    /* Image */
                                    G_TYPE_STRING,    /* Name */
                                    G_TYPE_BOOLEAN,   /* Enabled */
                                    MC_TYPE_ACCOUNT);
@@ -416,21 +415,22 @@ account_chooser_account_created_cb (McAccountMonitor     *monitor,
 }
 
 static void
-account_chooser_account_add_foreach (McAccount            *account,
+account_chooser_account_add_foreach (McAccount             *account,
                                     EmpathyAccountChooser *chooser)
 {
-       EmpathyAccountChooserPriv *priv;
-       GtkListStore             *store;
-       GtkComboBox              *combobox;
-       GtkTreeIter               iter;
-
-       priv = GET_PRIV (chooser);
+       GtkListStore *store;
+       GtkComboBox  *combobox;
+       GtkTreeIter   iter;
+       gint          position;
 
        combobox = GTK_COMBO_BOX (chooser);
        store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
 
-       gtk_list_store_append (store, &iter);
-       account_chooser_update_iter (chooser, &iter, account);
+       position = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
+       gtk_list_store_insert_with_values (store, &iter, position,
+                                          COL_ACCOUNT_POINTER, account,
+                                          -1);
+       account_chooser_update_iter (chooser, &iter);
 }
 
 static void
@@ -445,21 +445,81 @@ account_chooser_account_deleted_cb (McAccountMonitor     *monitor,
        g_object_unref (account);
 }
 
+typedef struct {
+       McAccount   *account;
+       GtkTreeIter *iter;
+       gboolean     found;
+} FindAccountData;
+
+static gboolean
+account_chooser_find_account_foreach (GtkTreeModel *model,
+                                     GtkTreePath  *path,
+                                     GtkTreeIter  *iter,
+                                     gpointer      user_data)
+{
+       FindAccountData *data = user_data;
+       McAccount       *account;
+
+       gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
+
+       if (empathy_account_equal (account, data->account)) {
+               data->found = TRUE;
+               *(data->iter) = *iter;
+               g_object_unref (account);
+
+               return TRUE;
+       }
+
+       g_object_unref (account);
+
+       return FALSE;
+}
+
+static gboolean
+account_chooser_find_account (EmpathyAccountChooser *chooser,
+                             McAccount             *account,
+                             GtkTreeIter           *iter)
+{
+       GtkListStore    *store;
+       GtkComboBox     *combobox;
+       FindAccountData  data;
+
+       combobox = GTK_COMBO_BOX (chooser);
+       store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
+
+       data.account = account;
+       data.iter = iter;
+       gtk_tree_model_foreach (GTK_TREE_MODEL (store),
+                               account_chooser_find_account_foreach,
+                               &data);
+
+       return data.found;
+}
+
 static void
 account_chooser_account_remove_foreach (McAccount            *account,
                                        EmpathyAccountChooser *chooser)
 {
-       /* Fixme: TODO */
+       GtkListStore *store;
+       GtkComboBox  *combobox;
+       GtkTreeIter   iter;
+
+       combobox = GTK_COMBO_BOX (chooser);
+       store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
+
+       if (account_chooser_find_account (chooser, account, &iter)) {
+               gtk_list_store_remove (store, &iter);
+       }
 }
 
 static void
 account_chooser_update_iter (EmpathyAccountChooser *chooser,
-                            GtkTreeIter           *iter,
-                            McAccount             *account)
+                            GtkTreeIter           *iter)
 {
        EmpathyAccountChooserPriv *priv;
        GtkListStore              *store;
        GtkComboBox               *combobox;
+       McAccount                 *account;
        const gchar               *icon_name;
        gboolean                   is_enabled = TRUE;
 
@@ -468,6 +528,10 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser,
        combobox = GTK_COMBO_BOX (chooser);
        store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
 
+       gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
+                           COL_ACCOUNT_POINTER, &account,
+                           -1);
+
        icon_name = empathy_icon_name_from_account (account);
        if (priv->filter) {
                is_enabled = priv->filter (account, priv->filter_data);
@@ -477,7 +541,6 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser,
                            COL_ACCOUNT_IMAGE, icon_name,
                            COL_ACCOUNT_TEXT, mc_account_get_display_name (account),
                            COL_ACCOUNT_ENABLED, is_enabled,
-                           COL_ACCOUNT_POINTER, account,
                            -1);
 
        /* set first connected account as active account */
@@ -485,6 +548,8 @@ account_chooser_update_iter (EmpathyAccountChooser *chooser,
                priv->set_active_item = TRUE;
                gtk_combo_box_set_active_iter (combobox, iter);
        }
+
+       g_object_unref (account);
 }
 
 static void
@@ -493,9 +558,16 @@ account_chooser_status_changed_cb (MissionControl                  *mc,
                                   McPresence                       presence,
                                   TelepathyConnectionStatusReason  reason,
                                   const gchar                     *unique_name,
-                                  EmpathyAccountChooser            *chooser)
+                                  EmpathyAccountChooser           *chooser)
 {
-       /* FIXME: implement */
+       McAccount   *account;
+       GtkTreeIter  iter;
+
+       account = mc_account_lookup (unique_name);
+       if (account_chooser_find_account (chooser, account, &iter)) {
+               account_chooser_update_iter (chooser, &iter);
+       }
+       g_object_unref (account);
 }
 
 static gboolean
@@ -555,35 +627,12 @@ account_chooser_set_account_foreach (GtkTreeModel   *model,
 }
 
 static gboolean
-account_chooser_filter_foreach (GtkTreeModel          *model,
-                               GtkTreePath           *path,
-                               GtkTreeIter           *iter,
-                               gpointer               chooser)
+account_chooser_filter_foreach (GtkTreeModel *model,
+                               GtkTreePath  *path,
+                               GtkTreeIter  *iter,
+                               gpointer      chooser)
 {
-       EmpathyAccountChooserPriv *priv;
-       McAccount                 *account;
-       gboolean                   is_enabled = TRUE;
-
-       priv = GET_PRIV (chooser);
-
-       gtk_tree_model_get (model, iter, COL_ACCOUNT_POINTER, &account, -1);
-
-       if (priv->filter) {
-               is_enabled = priv->filter (account, priv->filter_data);
-       }
-
-       gtk_list_store_set (GTK_LIST_STORE (model), iter,
-                           COL_ACCOUNT_ENABLED, is_enabled,
-                           -1);
-
-       /* set first connected account as active account */
-       if (!priv->set_active_item && is_enabled) {
-               priv->set_active_item = TRUE;
-               gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), iter);
-       }
-
-       g_object_unref (account);
-
+       account_chooser_update_iter (chooser, iter);
        return FALSE;
 }
 
@@ -612,19 +661,15 @@ gboolean
 empathy_account_chooser_filter_is_connected (McAccount *account,
                                             gpointer   user_data)
 {
-       MissionControl *mc;
-       TpConn         *tp_conn;
+       MissionControl            *mc;
+       TelepathyConnectionStatus  status;
 
        g_return_val_if_fail (MC_IS_ACCOUNT (account), FALSE);
 
        mc = empathy_mission_control_new ();
-       tp_conn = mission_control_get_connection (mc, account, NULL);
+       status = mission_control_get_connection_status (mc, account, NULL);
        g_object_unref (mc);
 
-       if (tp_conn == NULL) {
-               return FALSE;
-       }
-
-       g_object_unref (tp_conn);
-       return TRUE;
+       return status == TP_CONN_STATUS_CONNECTED;
 }
+
index e5635836e8417f77c1cc7f6448554a14fae50412..f171664b35f3678fe1160fb2b67917f6b807c1e8 100644 (file)
@@ -755,28 +755,18 @@ accounts_dialog_status_changed_cb (MissionControl                  *mc,
                        break;
                }
        }
-
        g_object_unref (account);
 
-       /* Start to flash account if status is connecting */
-       if (status == TP_CONN_STATUS_CONNECTING) {
-               if (!dialog->connecting_id) {
-                       dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
-                                                              (GSourceFunc) accounts_dialog_flash_connecting_cb,
-                                                              dialog);
-               }
-
-               return;
-       }
-
-       /* Stop to flash if no account is connecting */
+       /* Check if there is still accounts in CONNECTING state */
        accounts = mc_accounts_list ();
        for (l = accounts; l; l = l->next) {
-               McAccount *this_account;
+               McAccount                 *this_account;
+               TelepathyConnectionStatus  status;
 
                this_account = l->data;
 
-               if (mission_control_get_connection_status (mc, this_account, NULL) == TP_CONN_STATUS_CONNECTING) {
+               status = mission_control_get_connection_status (mc, this_account, NULL);
+               if (status == TP_CONN_STATUS_CONNECTING) {
                        found = TRUE;
                        break;
                }
@@ -789,8 +779,11 @@ accounts_dialog_status_changed_cb (MissionControl                  *mc,
                g_source_remove (dialog->connecting_id);
                dialog->connecting_id = 0;
        }
-
-       gtk_widget_show (dialog->window);
+       if (found && !dialog->connecting_id) {
+               dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
+                                                      (GSourceFunc) accounts_dialog_flash_connecting_cb,
+                                                      dialog);
+       }
 }
 
 static void
index d032eab5a146a0eb21ed22dec9302afe29306e21..96895cc2ff8f4bbbfb4886e17995a65e7cd795ba 100644 (file)
 #include <glade/glade.h>
 #include <glib/gi18n.h>
 
+#include <libmissioncontrol/mission-control.h>
+
 #include <libempathy/empathy-contact-manager.h>
 #include <libempathy/empathy-contact-list.h>
+#include <libempathy/empathy-utils.h>
 
 #include "empathy-contact-dialogs.h"
 #include "empathy-contact-widget.h"
@@ -195,6 +198,11 @@ empathy_contact_information_dialog_show (EmpathyContact *contact,
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
                            contact_widget,
                            TRUE, TRUE, 0);
+       if (flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
+               empathy_contact_widget_set_account_filter (contact_widget,
+                                                          empathy_account_chooser_filter_is_connected,
+                                                          NULL);
+       }
 
        g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget);
        information_dialogs = g_list_prepend (information_dialogs, dialog);
@@ -214,6 +222,37 @@ empathy_contact_information_dialog_show (EmpathyContact *contact,
  *  New contact dialog
  */
 
+static gboolean
+can_add_contact_to_account (McAccount *account,
+                           gpointer   user_data)
+{
+       MissionControl            *mc;
+       TelepathyConnectionStatus  status;
+       McProfile                 *profile;
+       const gchar               *protocol_name;
+
+       mc = empathy_mission_control_new ();
+       status = mission_control_get_connection_status (mc, account, NULL);
+       g_object_unref (mc);
+       if (status != TP_CONN_STATUS_CONNECTED) {
+               /* Account is disconnected */
+               return FALSE;
+       }
+
+       profile = mc_account_get_profile (account);
+       protocol_name = mc_profile_get_protocol_name (profile);
+       if (strcmp (protocol_name, "local-xmpp") == 0) {
+               /* We can't add accounts to a XMPP LL connection
+                * FIXME: We should inspect the flags of the contact list group interface
+                */
+               g_object_unref (profile);
+               return FALSE;
+       }
+
+       g_object_unref (profile);
+       return TRUE;
+}
+
 static void
 new_contact_response_cb (GtkDialog *dialog,
                         gint       response,
@@ -279,6 +318,9 @@ empathy_new_contact_dialog_show (GtkWindow *parent)
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
                            contact_widget,
                            TRUE, TRUE, 0);
+       empathy_contact_widget_set_account_filter (contact_widget,
+                                                  can_add_contact_to_account,
+                                                  NULL);
 
        new_contact_dialog = dialog;
 
index 34a8023fe74967efb6a715945873f7a7e25993b5..cde5acd612907583a8635a0a203463282ee4dff1 100644 (file)
@@ -223,6 +223,27 @@ empathy_contact_widget_get_contact (GtkWidget *widget)
 
        return information->contact;
 }
+
+void
+empathy_contact_widget_set_account_filter (GtkWidget                       *widget,
+                                          EmpathyAccountChooserFilterFunc  filter,
+                                          gpointer                         user_data)
+{
+       EmpathyContactWidget  *information;
+       EmpathyAccountChooser *chooser;
+
+       g_return_if_fail (GTK_IS_WIDGET (widget));
+
+       information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
+       if (!information) {
+               return;
+       }
+
+       chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
+       if (chooser) {
+               empathy_account_chooser_set_filter (chooser, filter, user_data);
+       }
+}
        
 static void
 contact_widget_destroy_cb (GtkWidget            *widget,
@@ -281,38 +302,6 @@ contact_widget_set_contact (EmpathyContactWidget *information,
        contact_widget_client_update (information);
 }
 
-static gboolean
-contact_widget_can_add_contact_to_account (McAccount *account,
-                                          gpointer   user_data)
-{
-       MissionControl *mc;
-       TpConn         *tp_conn;
-       McProfile      *profile;
-       const gchar    *protocol_name;
-
-       mc = empathy_mission_control_new ();
-       tp_conn = mission_control_get_connection (mc, account, NULL);
-       g_object_unref (mc);
-       if (tp_conn == NULL) {
-               /* Account is disconnected */
-               return FALSE;
-       }
-       g_object_unref (tp_conn);
-
-       profile = mc_account_get_profile (account);
-       protocol_name = mc_profile_get_protocol_name (profile);
-       if (strcmp (protocol_name, "local-xmpp") == 0) {
-               /* We can't add accounts to a XMPP LL connection
-                * FIXME: We should inspect the flags of the contact list group interface
-                */
-               g_object_unref (profile);
-               return FALSE;
-       }
-
-       g_object_unref (profile);
-       return TRUE;
-}
-
 static gboolean
 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
 {
@@ -354,10 +343,6 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
        /* Setup account label/chooser */
        if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
                information->widget_account = empathy_account_chooser_new ();
-               empathy_account_chooser_set_filter (
-                       EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
-                       contact_widget_can_add_contact_to_account,
-                       NULL);
 
                g_signal_connect (information->widget_account, "changed",
                                  G_CALLBACK (contact_widget_account_changed_cb),
index 3a2aed996dbdcdb7ae6cabee30a0ff3ae5e4c428..e35cf0d9b71bee1331011567c263b59534c398c7 100644 (file)
@@ -26,6 +26,7 @@
 #include <gtk/gtk.h>
 
 #include <libempathy/empathy-contact.h>
+#include "empathy-account-chooser.h"
 
 G_BEGIN_DECLS
 
@@ -37,9 +38,12 @@ typedef enum {
        EMPATHY_CONTACT_WIDGET_EDIT_GROUPS  = 1 << 4,
 } EmpathyContactWidgetFlags;
 
-GtkWidget *     empathy_contact_widget_new         (EmpathyContact            *contact,
-                                                   EmpathyContactWidgetFlags  flags);
-EmpathyContact *empathy_contact_widget_get_contact (GtkWidget                 *widget);
+GtkWidget *     empathy_contact_widget_new                (EmpathyContact                  *contact,
+                                                          EmpathyContactWidgetFlags        flags);
+EmpathyContact *empathy_contact_widget_get_contact        (GtkWidget                       *widget);
+void            empathy_contact_widget_set_account_filter (GtkWidget                       *widget,
+                                                          EmpathyAccountChooserFilterFunc  filter,
+                                                          gpointer                         user_data);
 
 G_END_DECLS