/soc/2013/ankitkv/gobjectification: 1690f822fbdd: Use purple_acc...

Ankit Vani a at nevitus.org
Sun Jun 30 10:30:17 EDT 2013


Changeset: 1690f822fbdd55b7771902f027b7db1ef078266d
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-30 19:59 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/1690f822fbdd

Description:

Use purple_account_constructed as a GObject constructed method to initialize account by parameters
instead of purple_account_new().

diffstat:

 libpurple/account.c |  253 +++++++++++++++++++++++++++------------------------
 1 files changed, 134 insertions(+), 119 deletions(-)

diffs (286 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -2970,141 +2970,36 @@ purple_account_finalize(GObject *object)
 	parent_class->finalize(object);
 }
 
-/* Class initializer function */
-static void purple_account_class_init(PurpleAccountClass *klass)
+/* Called when done constructing */
+static void
+purple_account_constructed(GObject *object)
 {
-	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
-
-	parent_class = g_type_class_peek_parent(klass);
-
-	obj_class->dispose = purple_account_dispose;
-	obj_class->finalize = purple_account_finalize;
-
-	/* Setup properties */
-	obj_class->get_property = purple_account_get_property;
-	obj_class->set_property = purple_account_set_property;
-
-	g_object_class_install_property(obj_class, PROP_USERNAME,
-			g_param_spec_string(PROP_USERNAME_S, _("Username"),
-				_("The username for the account."), NULL,
-				G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
-			);
-
-	g_object_class_install_property(obj_class, PROP_PRIVATE_ALIAS,
-			g_param_spec_string(PROP_PRIVATE_ALIAS_S, _("Private Alias"),
-				_("The private alias for the account."), NULL,
-				G_PARAM_READWRITE)
-			);
-
-	g_object_class_install_property(obj_class, PROP_USER_INFO,
-			g_param_spec_string(PROP_USER_INFO_S, _("User information"),
-				_("Detailed user information for the account."), NULL,
-				G_PARAM_READWRITE)
-			);
-
-	g_object_class_install_property(obj_class, PROP_BUDDY_ICON_PATH,
-			g_param_spec_string(PROP_BUDDY_ICON_PATH_S, _("Buddy icon path"),
-				_("Path to the buddyicon for the account."), NULL,
-				G_PARAM_READWRITE)
-			);
-
-	g_object_class_install_property(obj_class, PROP_ENABLED,
-			g_param_spec_boolean(PROP_ENABLED_S, _("Enabled"),
-				_("Whether the account is enabled or not."), FALSE,
-				G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
-			);
-
-	g_object_class_install_property(obj_class, PROP_REMEMBER_PASSWORD,
-			g_param_spec_boolean(PROP_REMEMBER_PASSWORD_S, _("Remember password"),
-				_("Whether to remember and store the password for this account."), FALSE,
-				G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
-			);
-
-	g_object_class_install_property(obj_class, PROP_CHECK_MAIL,
-			g_param_spec_boolean(PROP_CHECK_MAIL_S, _("Check mail"),
-				_("Whether to check mails for this account."), FALSE,
-				G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
-			);
-
-#warning TODO: change spec_pointer to spec_object when PurpleConnection is a GObject
-	g_object_class_install_property(obj_class, PROP_CONNECTION,
-			g_param_spec_pointer(PROP_CONNECTION_S, _("Connection"),
-				_("The PurpleConnection object for the account."),
-				G_PARAM_READWRITE)
-			);
-
-	g_object_class_install_property(obj_class, PROP_PROTOCOL_ID,
-			g_param_spec_string(PROP_PROTOCOL_ID_S, _("Protocol ID"),
-				_("ID of the protocol that is responsible for the account."), NULL,
-				G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)
-			);
-
-	g_type_class_add_private(klass, sizeof(PurpleAccountPrivate));
-}
-
-GType
-purple_account_get_type(void)
-{
-	static GType type = 0;
-
-	if(type == 0) {
-		static const GTypeInfo info = {
-			sizeof(PurpleAccountClass),
-			NULL,
-			NULL,
-			(GClassInitFunc)purple_account_class_init,
-			NULL,
-			NULL,
-			sizeof(PurpleAccount),
-			0,
-			(GInstanceInitFunc)purple_account_init,
-			NULL,
-		};
-
-		type = g_type_register_static(G_TYPE_OBJECT,
-				"PurpleAccount",
-				&info, 0);
-	}
-
-	return type;
-}
-
-PurpleAccount *
-purple_account_new(const char *username, const char *protocol_id)
-{
-	PurpleAccount *account = NULL;
+	PurpleAccount *account = PURPLE_ACCOUNT(object);
+	PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+	gchar *username, *protocol_id;
 	PurplePlugin *prpl = NULL;
 	PurplePluginProtocolInfo *prpl_info = NULL;
 	PurpleStatusType *status_type;
-	PurpleAccountPrivate *priv;
-
-	g_return_val_if_fail(username != NULL, NULL);
-	g_return_val_if_fail(protocol_id != NULL, NULL);
-
-	account = purple_accounts_find(username, protocol_id);
-
-	if (account != NULL)
-		return account;
-
-	account = g_object_new(PURPLE_TYPE_ACCOUNT,
-					PROP_USERNAME_S, username,
-					PROP_PROTOCOL_ID_S, protocol_id,
-					NULL);
+
+	parent_class->constructed(object);
+
+	g_object_get(object,
+			PROP_USERNAME_S,    &username,
+			PROP_PROTOCOL_ID_S, &protocol_id,
+			NULL);
 
 	purple_signal_emit(purple_accounts_get_handle(), "account-created",
 			account);
 
 	prpl = purple_find_prpl(protocol_id);
 	if (prpl == NULL)
-		return account;
+		return;
 
 	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
 	if (prpl_info != NULL && prpl_info->status_types != NULL)
 		purple_account_set_status_types(account,
 				prpl_info->status_types(account));
 
-	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
-
 	priv->presence = purple_presence_new_for_account(account);
 
 	status_type = purple_account_get_status_type_with_primitive(account,
@@ -3117,6 +3012,126 @@ purple_account_new(const char *username,
 		purple_presence_set_status_active(priv->presence,
 										"offline",
 										TRUE);
+}
+
+/* Class initializer function */
+static void
+purple_account_class_init(PurpleAccountClass *klass)
+{
+	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+
+	parent_class = g_type_class_peek_parent(klass);
+
+	obj_class->dispose = purple_account_dispose;
+	obj_class->finalize = purple_account_finalize;
+	obj_class->constructed = purple_account_constructed;
+
+	/* Setup properties */
+	obj_class->get_property = purple_account_get_property;
+	obj_class->set_property = purple_account_set_property;
+
+	g_object_class_install_property(obj_class, PROP_USERNAME,
+			g_param_spec_string(PROP_USERNAME_S, _("Username"),
+				_("The username for the account."), NULL,
+				G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
+			);
+
+	g_object_class_install_property(obj_class, PROP_PRIVATE_ALIAS,
+			g_param_spec_string(PROP_PRIVATE_ALIAS_S, _("Private Alias"),
+				_("The private alias for the account."), NULL,
+				G_PARAM_READWRITE)
+			);
+
+	g_object_class_install_property(obj_class, PROP_USER_INFO,
+			g_param_spec_string(PROP_USER_INFO_S, _("User information"),
+				_("Detailed user information for the account."), NULL,
+				G_PARAM_READWRITE)
+			);
+
+	g_object_class_install_property(obj_class, PROP_BUDDY_ICON_PATH,
+			g_param_spec_string(PROP_BUDDY_ICON_PATH_S, _("Buddy icon path"),
+				_("Path to the buddyicon for the account."), NULL,
+				G_PARAM_READWRITE)
+			);
+
+	g_object_class_install_property(obj_class, PROP_ENABLED,
+			g_param_spec_boolean(PROP_ENABLED_S, _("Enabled"),
+				_("Whether the account is enabled or not."), FALSE,
+				G_PARAM_READWRITE)
+			);
+
+	g_object_class_install_property(obj_class, PROP_REMEMBER_PASSWORD,
+			g_param_spec_boolean(PROP_REMEMBER_PASSWORD_S, _("Remember password"),
+				_("Whether to remember and store the password for this account."), FALSE,
+				G_PARAM_READWRITE)
+			);
+
+	g_object_class_install_property(obj_class, PROP_CHECK_MAIL,
+			g_param_spec_boolean(PROP_CHECK_MAIL_S, _("Check mail"),
+				_("Whether to check mails for this account."), FALSE,
+				G_PARAM_READWRITE)
+			);
+
+#warning TODO: change spec_pointer to spec_object when PurpleConnection is a GObject
+	g_object_class_install_property(obj_class, PROP_CONNECTION,
+			g_param_spec_pointer(PROP_CONNECTION_S, _("Connection"),
+				_("The PurpleConnection object for the account."),
+				G_PARAM_READWRITE)
+			);
+
+	g_object_class_install_property(obj_class, PROP_PROTOCOL_ID,
+			g_param_spec_string(PROP_PROTOCOL_ID_S, _("Protocol ID"),
+				_("ID of the protocol that is responsible for the account."), NULL,
+				G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)
+			);
+
+	g_type_class_add_private(klass, sizeof(PurpleAccountPrivate));
+}
+
+GType
+purple_account_get_type(void)
+{
+	static GType type = 0;
+
+	if(type == 0) {
+		static const GTypeInfo info = {
+			sizeof(PurpleAccountClass),
+			NULL,
+			NULL,
+			(GClassInitFunc)purple_account_class_init,
+			NULL,
+			NULL,
+			sizeof(PurpleAccount),
+			0,
+			(GInstanceInitFunc)purple_account_init,
+			NULL,
+		};
+
+		type = g_type_register_static(G_TYPE_OBJECT,
+				"PurpleAccount",
+				&info, 0);
+	}
+
+	return type;
+}
+
+PurpleAccount *
+purple_account_new(const char *username, const char *protocol_id)
+{
+	PurpleAccount *account;
+
+	g_return_val_if_fail(username != NULL, NULL);
+	g_return_val_if_fail(protocol_id != NULL, NULL);
+
+	account = purple_accounts_find(username, protocol_id);
+
+	if (account != NULL)
+		return account;
+
+	account = g_object_new(PURPLE_TYPE_ACCOUNT,
+					PROP_USERNAME_S,    username,
+					PROP_PROTOCOL_ID_S, protocol_id,
+					NULL);
 
 	return account;
 }



More information about the Commits mailing list