/soc/2013/ankitkv/gobjectification: 13a650a1dba6: Avoid code dup...

Ankit Vani a at nevitus.org
Sun Sep 1 18:23:17 EDT 2013


Changeset: 13a650a1dba67017291c99ccbd351fcb96f8fd1f
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-02 03:45 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/13a650a1dba6

Description:

Avoid code duplication this way

diffstat:

 libpurple/protocols/oscar/libaim.c |  35 +--------------------------------
 libpurple/protocols/oscar/libicq.c |  35 +--------------------------------
 libpurple/protocols/oscar/oscar.c  |  40 ++++++++++++++++++++++++++++++++++++++
 libpurple/protocols/oscar/oscar.h  |   2 +
 4 files changed, 44 insertions(+), 68 deletions(-)

diffs (160 lines):

diff --git a/libpurple/protocols/oscar/libaim.c b/libpurple/protocols/oscar/libaim.c
--- a/libpurple/protocols/oscar/libaim.c
+++ b/libpurple/protocols/oscar/libaim.c
@@ -38,44 +38,11 @@ aim_protocol_base_init(AIMProtocolClass 
 {
 	PurpleProtocolClass *proto_class = PURPLE_PROTOCOL_CLASS(klass);
 	PurpleAccountOption *option;
-	static const gchar *encryption_keys[] = {
-		N_("Use encryption if available"),
-		N_("Require encryption"),
-		N_("Don't use encryption"),
-		NULL
-	};
-	static const gchar *encryption_values[] = {
-		OSCAR_OPPORTUNISTIC_ENCRYPTION,
-		OSCAR_REQUIRE_ENCRYPTION,
-		OSCAR_NO_ENCRYPTION,
-		NULL
-	};
-	GList *encryption_options = NULL;
-	int i;
 
 	proto_class->id        = "aim";
 	proto_class->name      = "AIM";
 
-	option = purple_account_option_int_new(_("Port"), "port", OSCAR_DEFAULT_LOGIN_PORT);
-	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
-
-	for (i = 0; encryption_keys[i]; i++) {
-		PurpleKeyValuePair *kvp = g_new0(PurpleKeyValuePair, 1);
-		kvp->key = g_strdup(_(encryption_keys[i]));
-		kvp->value = g_strdup(encryption_values[i]);
-		encryption_options = g_list_append(encryption_options, kvp);
-	}
-	option = purple_account_option_list_new(_("Connection security"), "encryption", encryption_options);
-	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
-
-	option = purple_account_option_bool_new(_("Use clientLogin"), "use_clientlogin",
-			OSCAR_DEFAULT_USE_CLIENTLOGIN);
-	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
-
-	option = purple_account_option_bool_new(
-		_("Always use AIM proxy server for\nfile transfers and direct IM (slower,\nbut does not reveal your IP address)"), "always_use_rv_proxy",
-		OSCAR_DEFAULT_ALWAYS_USE_RV_PROXY);
-	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
+	oscar_init_protocol_options(proto_class);
 
 	option = purple_account_option_bool_new(_("Allow multiple simultaneous logins"), "allow_multiple_logins",
 											OSCAR_DEFAULT_ALLOW_MULTIPLE_LOGINS);
diff --git a/libpurple/protocols/oscar/libicq.c b/libpurple/protocols/oscar/libicq.c
--- a/libpurple/protocols/oscar/libicq.c
+++ b/libpurple/protocols/oscar/libicq.c
@@ -54,44 +54,11 @@ icq_protocol_base_init(ICQProtocolClass 
 {
 	PurpleProtocolClass *proto_class = PURPLE_PROTOCOL_CLASS(klass);
 	PurpleAccountOption *option;
-	static const gchar *encryption_keys[] = {
-		N_("Use encryption if available"),
-		N_("Require encryption"),
-		N_("Don't use encryption"),
-		NULL
-	};
-	static const gchar *encryption_values[] = {
-		OSCAR_OPPORTUNISTIC_ENCRYPTION,
-		OSCAR_REQUIRE_ENCRYPTION,
-		OSCAR_NO_ENCRYPTION,
-		NULL
-	};
-	GList *encryption_options = NULL;
-	int i;
 
 	proto_class->id        = "icq";
 	proto_class->name      = "ICQ";
 
-	option = purple_account_option_int_new(_("Port"), "port", OSCAR_DEFAULT_LOGIN_PORT);
-	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
-
-	for (i = 0; encryption_keys[i]; i++) {
-		PurpleKeyValuePair *kvp = g_new0(PurpleKeyValuePair, 1);
-		kvp->key = g_strdup(_(encryption_keys[i]));
-		kvp->value = g_strdup(encryption_values[i]);
-		encryption_options = g_list_append(encryption_options, kvp);
-	}
-	option = purple_account_option_list_new(_("Connection security"), "encryption", encryption_options);
-	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
-
-	option = purple_account_option_bool_new(_("Use clientLogin"), "use_clientlogin",
-			OSCAR_DEFAULT_USE_CLIENTLOGIN);
-	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
-
-	option = purple_account_option_bool_new(
-		_("Always use ICQ proxy server for\nfile transfers and direct IM (slower,\nbut does not reveal your IP address)"), "always_use_rv_proxy",
-		OSCAR_DEFAULT_ALWAYS_USE_RV_PROXY);
-	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
+	oscar_init_protocol_options(proto_class);
 
 	option = purple_account_option_string_new(_("Server"), "server", oscar_get_login_server(TRUE, TRUE));
 	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
diff --git a/libpurple/protocols/oscar/oscar.c b/libpurple/protocols/oscar/oscar.c
--- a/libpurple/protocols/oscar/oscar.c
+++ b/libpurple/protocols/oscar/oscar.c
@@ -5532,6 +5532,46 @@ gboolean oscar_uri_handler(const char *p
 	return FALSE;
 }
 
+void oscar_init_protocol_options(PurpleProtocolClass *proto_class)
+{
+	PurpleAccountOption *option;
+	static const gchar *encryption_keys[] = {
+		N_("Use encryption if available"),
+		N_("Require encryption"),
+		N_("Don't use encryption"),
+		NULL
+	};
+	static const gchar *encryption_values[] = {
+		OSCAR_OPPORTUNISTIC_ENCRYPTION,
+		OSCAR_REQUIRE_ENCRYPTION,
+		OSCAR_NO_ENCRYPTION,
+		NULL
+	};
+	GList *encryption_options = NULL;
+	int i;
+
+	option = purple_account_option_int_new(_("Port"), "port", OSCAR_DEFAULT_LOGIN_PORT);
+	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
+
+	for (i = 0; encryption_keys[i]; i++) {
+		PurpleKeyValuePair *kvp = g_new0(PurpleKeyValuePair, 1);
+		kvp->key = g_strdup(_(encryption_keys[i]));
+		kvp->value = g_strdup(encryption_values[i]);
+		encryption_options = g_list_append(encryption_options, kvp);
+	}
+	option = purple_account_option_list_new(_("Connection security"), "encryption", encryption_options);
+	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
+
+	option = purple_account_option_bool_new(_("Use clientLogin"), "use_clientlogin",
+			OSCAR_DEFAULT_USE_CLIENTLOGIN);
+	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
+
+	option = purple_account_option_bool_new(
+		_("Always use AIM/ICQ proxy server for\nfile transfers and direct IM (slower,\nbut does not reveal your IP address)"), "always_use_rv_proxy",
+		OSCAR_DEFAULT_ALWAYS_USE_RV_PROXY);
+	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
+}
+
 static void
 oscar_protocol_base_init(OscarProtocolClass *klass)
 {
diff --git a/libpurple/protocols/oscar/oscar.h b/libpurple/protocols/oscar/oscar.h
--- a/libpurple/protocols/oscar/oscar.h
+++ b/libpurple/protocols/oscar/oscar.h
@@ -1368,6 +1368,8 @@ struct name_data
 
 void oscar_free_name_data(struct name_data *data);
 
+void oscar_init_protocol_options(PurpleProtocolClass *proto_class);
+
 #ifdef __cplusplus
 }
 #endif



More information about the Commits mailing list