aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy/empathy-chatroom-manager.c18
-rw-r--r--src/empathy.c95
2 files changed, 113 insertions, 0 deletions
diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c
index c6318abd3..7d80b9441 100644
--- a/libempathy/empathy-chatroom-manager.c
+++ b/libempathy/empathy-chatroom-manager.c
@@ -55,6 +55,7 @@ typedef struct
gulong account_manager_ready_handler_id;
/* source id of the autosave timer */
gint save_timer_id;
+ gboolean ready;
} EmpathyChatroomManagerPriv;
enum {
@@ -69,6 +70,7 @@ static guint signals[LAST_SIGNAL];
enum
{
PROP_FILE = 1,
+ PROP_READY,
LAST_PROPERTY
};
@@ -304,6 +306,9 @@ chatroom_manager_get_all (EmpathyChatroomManager *manager)
return FALSE;
}
+ priv->ready = TRUE;
+ g_object_notify (G_OBJECT (manager), "ready");
+
return TRUE;
}
@@ -321,6 +326,9 @@ empathy_chatroom_manager_get_property (GObject *object,
case PROP_FILE:
g_value_set_string (value, priv->file);
break;
+ case PROP_READY:
+ g_value_set_boolean (value, priv->ready);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -423,6 +431,8 @@ empathy_chatroom_manager_constructor (GType type,
self = EMPATHY_CHATROOM_MANAGER (obj);
priv = GET_PRIV (self);
+ priv->ready = FALSE;
+
chatroom_manager_singleton = self;
g_object_add_weak_pointer (obj, (gpointer) &chatroom_manager_singleton);
@@ -476,6 +486,14 @@ empathy_chatroom_manager_class_init (EmpathyChatroomManagerClass *klass)
G_PARAM_STATIC_BLURB);
g_object_class_install_property (object_class, PROP_FILE, param_spec);
+ param_spec = g_param_spec_boolean (
+ "ready",
+ "whether the manager is ready yet",
+ "whether the manager is ready yet",
+ FALSE,
+ G_PARAM_READABLE);
+ g_object_class_install_property (object_class, PROP_READY, param_spec);
+
signals[CHATROOM_ADDED] = g_signal_new ("chatroom-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
diff --git a/src/empathy.c b/src/empathy.c
index ed90cb5e1..8a2f107b7 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -627,6 +627,89 @@ setup_dispatcher (void)
return d;
}
+static void
+account_connection_notify_cb (EmpathyAccount *account,
+ GParamSpec *pspec,
+ EmpathyChatroom *room)
+{
+ TpConnection *conn;
+
+ conn = empathy_account_get_connection (account);
+
+ if (conn == NULL)
+ return;
+
+ empathy_dispatcher_join_muc (conn,
+ empathy_chatroom_get_room (room), NULL, NULL);
+}
+
+static void
+account_manager_chatroom_ready_cb (EmpathyAccountManager *account_manager,
+ GParamSpec *pspec,
+ EmpathyChatroomManager *chatroom_manager)
+{
+ GList *accounts, *l;
+
+ accounts = empathy_account_manager_dup_accounts (account_manager);
+
+ for (l = accounts; l != NULL; l = g_list_next (l))
+ {
+ EmpathyAccount *account = EMPATHY_ACCOUNT (l->data);
+ TpConnection *conn;
+ GList *chatrooms, *p;
+
+ conn = empathy_account_get_connection (account);
+
+ chatrooms = empathy_chatroom_manager_get_chatrooms (
+ chatroom_manager, account);
+
+ for (p = chatrooms; p != NULL; p = p->next)
+ {
+ EmpathyChatroom *room = EMPATHY_CHATROOM (p->data);
+
+ if (!empathy_chatroom_get_auto_connect (room))
+ continue;
+
+ if (conn == NULL)
+ {
+ g_signal_connect (G_OBJECT (account), "notify::connection",
+ G_CALLBACK (account_connection_notify_cb), room);
+ }
+ else
+ {
+ empathy_dispatcher_join_muc (conn,
+ empathy_chatroom_get_room (room), NULL, NULL);
+ }
+ }
+
+ g_list_free (chatrooms);
+ }
+
+ g_list_foreach (accounts, (GFunc) g_object_unref, NULL);
+ g_list_free (accounts);
+}
+
+static void
+chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager,
+ GParamSpec *pspec,
+ EmpathyAccountManager *account_manager)
+{
+ gboolean ready;
+
+ g_object_get (G_OBJECT (account_manager), "ready", &ready, NULL);
+
+ if (ready)
+ {
+ account_manager_chatroom_ready_cb (account_manager, NULL,
+ chatroom_manager);
+ }
+ else
+ {
+ g_signal_connect (account_manager, "notify::ready",
+ G_CALLBACK (account_manager_chatroom_ready_cb), chatroom_manager);
+ }
+}
+
int
main (int argc, char *argv[])
{
@@ -650,6 +733,7 @@ main (int argc, char *argv[])
GError *error = NULL;
TpDBusDaemon *dbus_daemon;
UniqueApp *unique_app;
+ gboolean chatroom_manager_ready;
GOptionContext *optcontext;
GOptionEntry options[] = {
@@ -794,6 +878,17 @@ main (int argc, char *argv[])
chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
+ g_object_get (chatroom_manager, "ready", &chatroom_manager_ready, NULL);
+ if (!chatroom_manager_ready)
+ {
+ g_signal_connect (G_OBJECT (chatroom_manager), "notify::ready",
+ G_CALLBACK (chatroom_manager_ready_cb), account_manager);
+ }
+ else
+ {
+ chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager);
+ }
+
notify_init (_(PACKAGE_NAME));
/* Create the call factory */
call_factory = empathy_call_factory_initialise ();