changeset 31350:64b362d1c49e

Gadu-Gadu: Allow showing your status only to people on your buddy list. Fixes #13358. committer: John Bailey <rekkanoryo@rekkanoryo.org>
author mateuszpiekos@gmail.com
date Sun, 13 Mar 2011 16:10:16 +0000
parents c9244d8303ce
children e31163acae07
files libpurple/protocols/gg/gg.c libpurple/protocols/gg/gg.h
diffstat 2 files changed, 74 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/gg/gg.c	Sun Mar 13 09:05:46 2011 +0000
+++ b/libpurple/protocols/gg/gg.c	Sun Mar 13 16:10:16 2011 +0000
@@ -49,6 +49,10 @@
 
 static PurplePlugin *my_protocol = NULL;
 
+/* Prototypes */
+static void ggp_set_status(PurpleAccount *account, PurpleStatus *status);
+static int ggp_to_gg_status(PurpleStatus *status, char **msg);
+
 /* ---------------------------------------------------------------------- */
 /* ----- EXTERNAL CALLBACKS --------------------------------------------- */
 /* ---------------------------------------------------------------------- */
@@ -755,6 +759,61 @@
 	ggp_token_request(gc, ggp_change_passwd_dialog);
 }
 
+/* ----- CHANGE STATUS BROADCASTING ------------------------------------------------ */
+
+static void ggp_action_change_status_broadcasting_ok(PurpleConnection *gc, PurpleRequestFields *fields)
+{
+	GGPInfo *info = gc->proto_data;
+	int selected_field;
+	PurpleAccount *account = purple_connection_get_account(gc);
+	PurpleStatus *status;
+
+	selected_field = purple_request_fields_get_choice(fields, "status_broadcasting");
+	
+	if (selected_field == 0)
+		info->status_broadcasting = TRUE;
+	else
+		info->status_broadcasting = FALSE;
+	
+	status = purple_account_get_active_status(account);
+	
+	ggp_set_status(account, status);
+}
+
+static void ggp_action_change_status_broadcasting(PurplePluginAction *action)
+{
+	PurpleConnection *gc = (PurpleConnection *)action->context;
+	GGPInfo *info = gc->proto_data;
+	
+	PurpleRequestFields *fields;
+	PurpleRequestFieldGroup *group;
+	PurpleRequestField *field;
+
+	fields = purple_request_fields_new();
+	group = purple_request_field_group_new(NULL);
+	purple_request_fields_add_group(fields, group);
+	
+	field = purple_request_field_choice_new("status_broadcasting", _("Show status to:"), 0);
+	purple_request_field_choice_add(field, _("All people"));
+	purple_request_field_choice_add(field, _("Only friends"));
+	purple_request_field_group_add_field(group, field);
+
+	if (info->status_broadcasting)
+		purple_request_field_choice_set_default_value(field, 0);
+	else
+		purple_request_field_choice_set_default_value(field, 1);
+
+	purple_request_fields(gc,
+		_("Change status broadcasting"),
+		_("Change status broadcasting"),
+		_("Please, select who can see your status"),
+		fields,
+		_("OK"), G_CALLBACK(ggp_action_change_status_broadcasting_ok),
+		_("Cancel"), NULL,
+		purple_connection_get_account(gc), NULL, NULL,
+		gc);
+}
+
 /* ----- CONFERENCES ---------------------------------------------------- */
 
 static void ggp_callback_add_to_chat_ok(PurpleBuddy *buddy, PurpleRequestFields *fields)
@@ -856,10 +915,6 @@
 /* ----- INTERNAL CALLBACKS --------------------------------------------- */
 /* ---------------------------------------------------------------------- */
 
-/* Prototypes */
-static void ggp_set_status(PurpleAccount *account, PurpleStatus *status);
-static int ggp_to_gg_status(PurpleStatus *status, char **msg);
-
 struct gg_fetch_avatar_data
 {
 	PurpleConnection *gc;
@@ -1948,7 +2003,8 @@
 	info->searches = ggp_search_new();
 	info->pending_richtext_messages = NULL;
 	info->pending_images = g_hash_table_new(g_int_hash, g_int_equal);
-
+	info->status_broadcasting = purple_account_get_bool(account, "status_broadcasting", TRUE);
+	
 	gc->proto_data = info;
 
 	glp->uin = ggp_get_uin(account);
@@ -1965,6 +2021,9 @@
 	glp->status = ggp_to_gg_status(status, &glp->status_descr);
 	glp->tls = 0;
 
+	if (!info->status_broadcasting)
+		glp->status = glp->status|GG_STATUS_FRIENDS_MASK;
+	
 	address = purple_account_get_string(account, "gg_server", "");
 	if (address && *address) {
 		/* TODO: Make this non-blocking */
@@ -2021,6 +2080,8 @@
 			gg_free_session(info->session);
 		}
 
+		purple_account_set_bool(account, "status_broadcasting", info->status_broadcasting);
+
 		/* Immediately close any notifications on this handle since that process depends
 		 * upon the contents of info->searches, which we are about to destroy.
 		 */
@@ -2243,6 +2304,9 @@
 
 	new_status = ggp_to_gg_status(status, &new_msg);
 
+	if (!info->status_broadcasting)
+		new_status = new_status|GG_STATUS_FRIENDS_MASK;
+	
 	if (new_msg == NULL) {
 		gg_change_status(info->session, new_status);
 	} else {
@@ -2431,6 +2495,10 @@
 				     ggp_action_buddylist_load);
 	m = g_list_append(m, act);
 
+	act = purple_plugin_action_new(_("Change status broadcasting"),
+				     ggp_action_change_status_broadcasting);
+	m = g_list_append(m, act);
+	
 	return m;
 }
 
--- a/libpurple/protocols/gg/gg.h	Sun Mar 13 09:05:46 2011 +0000
+++ b/libpurple/protocols/gg/gg.h	Sun Mar 13 16:10:16 2011 +0000
@@ -64,6 +64,7 @@
 	int chats_count;
 	GList *pending_richtext_messages;
 	GHashTable *pending_images;
+	gboolean status_broadcasting; //When TRUE status is visible to all, when FALSE status is visible only to friends.
 } GGPInfo;
 
 #endif /* _PURPLE_GG_H */