aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--libempathy-gtk/empathy-account-chooser.c159
-rw-r--r--libempathy-gtk/empathy-accounts-dialog.c27
-rw-r--r--libempathy-gtk/empathy-contact-dialogs.c42
-rw-r--r--libempathy-gtk/empathy-contact-widget.c57
-rw-r--r--libempathy-gtk/empathy-contact-widget.h10
6 files changed, 195 insertions, 113 deletions
diff --git a/ChangeLog b/ChangeLog
index 823686e9f..09a897d97 100644
--- 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
diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c
index 6d3aea6a6..de6d55177 100644
--- a/libempathy-gtk/empathy-account-chooser.c
+++ b/libempathy-gtk/empathy-account-chooser.c
@@ -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;
}
+
diff --git a/libempathy-gtk/empathy-accounts-dialog.c b/libempathy-gtk/empathy-accounts-dialog.c
index e5635836e..f171664b3 100644
--- a/libempathy-gtk/empathy-accounts-dialog.c
+++ b/libempathy-gtk/empathy-accounts-dialog.c
@@ -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
diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c
index d032eab5a..96895cc2f 100644
--- a/libempathy-gtk/empathy-contact-dialogs.c
+++ b/libempathy-gtk/empathy-contact-dialogs.c
@@ -29,8 +29,11 @@
#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;
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index 34a8023fe..cde5acd61 100644
--- a/libempathy-gtk/empathy-contact-widget.c
+++ b/libempathy-gtk/empathy-contact-widget.c
@@ -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,
@@ -282,38 +303,6 @@ contact_widget_set_contact (EmpathyContactWidget *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)
{
contact_widget_change_contact (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),
diff --git a/libempathy-gtk/empathy-contact-widget.h b/libempathy-gtk/empathy-contact-widget.h
index 3a2aed996..e35cf0d9b 100644
--- a/libempathy-gtk/empathy-contact-widget.h
+++ b/libempathy-gtk/empathy-contact-widget.h
@@ -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