[empathy] remember last account



commit 0a2d4299c996e583867d5028bc247ac86ace4b0b
Author: Juan R. Garcia Blanco <jgblanco mail gmail com>
Date:   Wed Sep 21 11:43:44 2011 +0200

    remember last account
    
    https://bugzilla.gnome.org/show_bug.cgi?id=574879

 data/org.gnome.Empathy.gschema.xml.in |    5 ++
 libempathy/empathy-gsettings.h        |    1 +
 src/empathy-new-chatroom-dialog.c     |   70 +++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.Empathy.gschema.xml.in b/data/org.gnome.Empathy.gschema.xml.in
index 6f8f146..972d734 100644
--- a/data/org.gnome.Empathy.gschema.xml.in
+++ b/data/org.gnome.Empathy.gschema.xml.in
@@ -231,6 +231,11 @@ present them to the user immediately.</_description>
       <_summary>Empathy should use the avatar of the contact as the chat window icon</_summary>
       <_description>Whether Empathy should use the avatar of the contact as the chat window icon.</_description>
     </key>
+    <key name="room-last-account" type="o">
+      <default>"/"</default>
+      <_summary>Last account selected in Join Room dialog</_summary>
+      <_description>D-Bus object path of the last account selected to join a room.</_description>
+    </key>
   </schema>
   <schema id="org.gnome.Empathy.call" path="/org/gnome/empathy/call/">
     <key name="volume" type="d">
diff --git a/libempathy/empathy-gsettings.h b/libempathy/empathy-gsettings.h
index d326981..995eaaa 100644
--- a/libempathy/empathy-gsettings.h
+++ b/libempathy/empathy-gsettings.h
@@ -67,6 +67,7 @@ G_BEGIN_DECLS
 #define EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR    "nick-completion-char"
 #define EMPATHY_PREFS_CHAT_AVATAR_IN_ICON          "avatar-in-icon"
 #define EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS  "enable-webkit-developer-tools"
+#define EMPATHY_PREFS_CHAT_ROOM_LAST_ACCOUNT       "room-last-account"
 
 #define EMPATHY_PREFS_UI_SCHEMA EMPATHY_PREFS_SCHEMA ".ui"
 #define EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS     "separate-chat-windows"
diff --git a/src/empathy-new-chatroom-dialog.c b/src/empathy-new-chatroom-dialog.c
index a09a5f7..29c8865 100644
--- a/src/empathy-new-chatroom-dialog.c
+++ b/src/empathy-new-chatroom-dialog.c
@@ -37,6 +37,7 @@
 #include <libempathy/empathy-chatroom.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-request-util.h>
+#include <libempathy/empathy-gsettings.h>
 
 #include <libempathy-gtk/empathy-account-chooser.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
@@ -71,6 +72,8 @@ typedef struct {
 	GtkWidget         *button_join;
 	GtkWidget         *label_error_message;
 	GtkWidget         *viewport_error;
+
+	GSettings         *gsettings;
 } EmpathyNewChatroomDialog;
 
 enum {
@@ -94,6 +97,8 @@ static void     new_chatroom_dialog_model_add_columns               (EmpathyNewC
 static void     new_chatroom_dialog_update_widgets                  (EmpathyNewChatroomDialog *dialog);
 static void     new_chatroom_dialog_account_changed_cb              (GtkComboBox              *combobox,
 								     EmpathyNewChatroomDialog *dialog);
+static void     new_chatroom_dialog_account_ready_cb                (EmpathyAccountChooser   *combobox,
+                                                                     EmpathyNewChatroomDialog  *dialog);
 static void     new_chatroom_dialog_roomlist_destroy_cb             (EmpathyTpRoomlist        *room_list,
 								     EmpathyNewChatroomDialog *dialog);
 static void     new_chatroom_dialog_new_room_cb                     (EmpathyTpRoomlist        *room_list,
@@ -198,6 +203,8 @@ empathy_new_chatroom_dialog_show (GtkWindow *parent)
 	gtk_box_pack_start (GTK_BOX (dialog->hbox_expander), dialog->throbber,
 		TRUE, TRUE, 0);
 
+	dialog->gsettings = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
+
 	/* Account chooser for custom */
 	dialog->account_chooser = empathy_account_chooser_new ();
 	empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser),
@@ -208,6 +215,9 @@ empathy_new_chatroom_dialog_show (GtkWindow *parent)
 				   1, 2, 0, 1);
 	gtk_widget_show (dialog->account_chooser);
 
+	g_signal_connect (EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser), "ready",
+			  G_CALLBACK (new_chatroom_dialog_account_ready_cb),
+			  dialog);
 	g_signal_connect (GTK_COMBO_BOX (dialog->account_chooser), "changed",
 			  G_CALLBACK (new_chatroom_dialog_account_changed_cb),
 			  dialog);
@@ -223,12 +233,32 @@ empathy_new_chatroom_dialog_show (GtkWindow *parent)
 }
 
 static void
+new_chatroom_dialog_store_last_account (GSettings             *gsettings,
+                                        EmpathyAccountChooser *account_chooser)
+{
+	TpAccount   *account;
+	const char *account_path;
+
+	account = empathy_account_chooser_get_account (account_chooser);
+	if (account == NULL)
+		return;
+
+	account_path = tp_proxy_get_object_path (account);
+	DEBUG ("Storing account path '%s'", account_path);
+
+	g_settings_set (gsettings, EMPATHY_PREFS_CHAT_ROOM_LAST_ACCOUNT,
+	                "o", account_path);
+}
+
+static void
 new_chatroom_dialog_response_cb (GtkWidget               *widget,
 				 gint                     response,
 				 EmpathyNewChatroomDialog *dialog)
 {
 	if (response == GTK_RESPONSE_OK) {
 		new_chatroom_dialog_join (dialog);
+		new_chatroom_dialog_store_last_account (dialog->gsettings,
+		                                        EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser));
 	}
 
 	gtk_widget_destroy (widget);
@@ -248,6 +278,8 @@ new_chatroom_dialog_destroy_cb (GtkWidget               *widget,
 		g_object_unref (dialog->account);
 	}
 
+	g_clear_object (&dialog->gsettings);
+
 	g_free (dialog);
 }
 
@@ -428,6 +460,44 @@ account_status_changed_cb (TpAccount *account,
 }
 
 static void
+new_chatroom_dialog_select_last_account (GSettings             *gsettings,
+                                         EmpathyAccountChooser *account_chooser)
+{
+	const gchar          *account_path;
+	TpAccountManager      *manager;
+	TpSimpleClientFactory *factory;
+	TpAccount             *account;
+	TpConnectionStatus    status;
+
+	account_path = g_settings_get_string (gsettings, EMPATHY_PREFS_CHAT_ROOM_LAST_ACCOUNT);
+	DEBUG ("Selecting account path '%s'", account_path);
+
+	manager =  tp_account_manager_dup ();
+	factory = tp_proxy_get_factory (manager);
+	account = tp_simple_client_factory_ensure_account (factory,
+	                                                   account_path,
+	                                                   NULL,
+	                                                   NULL);
+
+	if (account != NULL) {
+		status = tp_account_get_connection_status (account, NULL);
+		if (status == TP_CONNECTION_STATUS_CONNECTED) {
+			empathy_account_chooser_set_account (account_chooser,
+			                                     account);
+		}
+		g_object_unref (account);
+	}
+	g_object_unref (manager);
+}
+
+static void
+new_chatroom_dialog_account_ready_cb (EmpathyAccountChooser    *combobox,
+                                      EmpathyNewChatroomDialog *dialog)
+{
+	new_chatroom_dialog_select_last_account (dialog->gsettings, combobox);
+}
+
+static void
 new_chatroom_dialog_account_changed_cb (GtkComboBox             *combobox,
 					EmpathyNewChatroomDialog *dialog)
 {



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