changeset 17681:5e8c02259c81

Add option to sign on as hidden, or as not (previously, always signed on as hidden, which was confusing). Split part of msim_process into msim_we_are_logged_on()
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Tue, 03 Jul 2007 05:14:56 +0000
parents d87916bd1d73
children 32959ccd8066
files libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h
diffstat 2 files changed, 57 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Tue Jul 03 03:19:16 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Tue Jul 03 05:14:56 2007 +0000
@@ -702,6 +702,8 @@
 	return rc;
 }
 
+
+#ifdef MSIM_FONT_SIZE_WORKS
 /** Convert a msim markup font height to points. */
 static guint 
 msim_font_height_to_point(guint height)
@@ -724,6 +726,7 @@
 	default: return 12;
 	}
 }
+#endif
 
 /** Convert the msim markup <f> (font) tag into HTML. */
 static void msim_markup_f_to_html(xmlnode *root, gchar **begin, gchar **end)
@@ -1285,20 +1288,27 @@
 	g_free(user_to_lookup); 
 }
 
-/* Set your status. */
-/* TODO: set status to online, when go online, if not invisible? */
+/** Set your status - callback for when user manually sets it. */
 void
 msim_set_status(PurpleAccount *account, PurpleStatus *status)
 {
 	PurpleStatusType *type;
-	guint status_code;
 	MsimSession *session;
 
 	session = (MsimSession *)account->gc->proto_data;
 
 	type = purple_status_get_type(status);
 
-	switch (purple_status_type_get_primitive(type))
+    msim_set_status_primitive(session, purple_status_type_get_primitive(type));
+}
+
+/** Set status using a status primitive type. */
+void 
+msim_set_status_primitive(MsimSession *session, guint code)
+{
+    guint status_code;
+
+	switch (code)
 	{
 		case PURPLE_STATUS_AVAILABLE:
 			status_code = MSIM_STATUS_CODE_ONLINE;
@@ -1522,6 +1532,42 @@
 	}
 }
 
+/** Called when the session key arrives. */
+gboolean
+msim_we_are_logged_on(MsimSession *session, MsimMessage *msg)
+{
+    purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
+
+    session->sesskey = msim_msg_get_integer(msg, "sesskey");
+    purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey);
+
+    /* Comes with: proof,profileid,userid,uniquenick -- all same values
+     * some of the time, but can vary. This is our own user ID. */
+    session->userid = msim_msg_get_integer(msg, "userid");
+
+
+    purple_connection_set_state(session->gc, PURPLE_CONNECTED);
+
+
+    /* We now know are our own username, only after we're logged in..
+     * which is weird, but happens because you login with your email
+     * address and not username. Will be freed in msim_session_destroy(). */
+    session->username = msim_msg_get_string(msg, "uniquenick");
+
+#ifdef MSIM_FAKE_SELF_ONLINE
+    /* Fake our self coming online. */
+    purple_prpl_got_user_status(session->account, session->username, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);
+#endif
+
+    /* Set status depending on preference. */
+    msim_set_status_primitive(session, 
+            purple_account_get_bool(session->account, "hidden", FALSE) 
+            ?  PURPLE_STATUS_INVISIBLE
+            : PURPLE_STATUS_AVAILABLE);
+
+    return TRUE;
+}
+
 /**
  * Process a message. 
  *
@@ -1546,30 +1592,7 @@
     {
         return msim_login_challenge(session, msg);
     } else if (msim_msg_get(msg, "sesskey")) {
-        purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
-
-        session->sesskey = msim_msg_get_integer(msg, "sesskey");
-        purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey);
-
-        /* Comes with: proof,profileid,userid,uniquenick -- all same values
-		 * some of the time, but can vary. This is our own user ID. */
-        session->userid = msim_msg_get_integer(msg, "userid");
-
-
-        purple_connection_set_state(session->gc, PURPLE_CONNECTED);
-	
-
-		/* We now know are our own username, only after we're logged in..
-		 * which is weird, but happens because you login with your email
-		 * address and not username. Will be freed in msim_session_destroy(). */
-		session->username = msim_msg_get_string(msg, "uniquenick");
-
-#ifdef MSIM_FAKE_SELF_ONLINE
-		/* Fake our self coming online. */
-		purple_prpl_got_user_status(session->account, session->username, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);
-#endif
-
-        return TRUE;
+        return msim_we_are_logged_on(session, msg);
     } else if (msim_msg_get(msg, "bm"))  {
         guint bm;
        
@@ -3013,6 +3036,9 @@
 	option = purple_account_option_int_new(_("Connect port"), "port", MSIM_PORT);
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
 
+	option = purple_account_option_bool_new(_("Sign on as hidden"), "hidden", FALSE);
+	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
+
 	option = purple_account_option_bool_new(_("Show display name in status text"), "show_display_name", TRUE);
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
 
--- a/libpurple/protocols/myspace/myspace.h	Tue Jul 03 03:19:16 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.h	Tue Jul 03 05:14:56 2007 +0000
@@ -204,6 +204,7 @@
 void msim_get_info(PurpleConnection *gc, const gchar *name);
 
 void msim_set_status(PurpleAccount *account, PurpleStatus *status);
+void msim_set_status_primitive(MsimSession *session, guint code);
 
 void msim_store_buddy_info_each(gpointer key, gpointer value, gpointer user_data);
 gboolean msim_store_buddy_info(MsimSession *session, MsimMessage *msg);
@@ -211,6 +212,8 @@
 
 gboolean msim_preprocess_incoming(MsimSession *session, MsimMessage *msg);
 
+gboolean msim_we_are_logged_on(MsimSession *session, MsimMessage *msg);
+
 gboolean msim_process(MsimSession *session, MsimMessage *msg);
 
 MsimMessage *msim_do_postprocessing(MsimMessage *msg, const gchar *uid_field_name, const gchar *uid_before, guint uid);