/soc/2013/ankitkv/gobjectification: aebc4dd321bf: Use GObject co...
Ankit Vani
a at nevitus.org
Sun Jun 30 11:13:32 EDT 2013
Changeset: aebc4dd321bf6795ec448c7a0be88c08e2414360
Author: Ankit Vani <a at nevitus.org>
Date: 2013-06-30 20:43 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/aebc4dd321bf
Description:
Use GObject constructed for PurpleConversation, PurpleIMConversation and PurpleChatConversation
diffstat:
libpurple/conversation.c | 44 +++++++++++-
libpurple/conversationtypes.c | 147 +++++++++++++++++++----------------------
2 files changed, 108 insertions(+), 83 deletions(-)
diffs (truncated from 329 to 300 lines):
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -967,6 +967,42 @@ purple_conversation_init(GTypeInstance *
PURPLE_DBUS_REGISTER_POINTER(PURPLE_CONVERSATION(instance), PurpleConversation);
}
+/* Called when done constructing */
+static void
+purple_conversation_constructed(GObject *object)
+{
+ PurpleConversation *conv = PURPLE_CONVERSATION(object);
+ PurpleAccount *account;
+ PurpleConnection *gc;
+ PurpleConversationUiOps *ops;
+
+ parent_class->constructed(object);
+
+ g_object_get(object, PROP_ACCOUNT_S, &account, NULL);
+ gc = purple_account_get_connection(account);
+
+ /* copy features from the connection. */
+ purple_conversation_set_features(conv, purple_connection_get_flags(gc));
+
+ /* add the conversation to the appropriate lists */
+ purple_conversations_add(conv);
+
+ /* Auto-set the title. */
+ purple_conversation_autoset_title(conv);
+
+ /* Don't move this.. it needs to be one of the last things done otherwise
+ * it causes mysterious crashes on my system.
+ * -- Gary
+ */
+ ops = purple_conversations_get_ui_ops();
+ purple_conversation_set_ui_ops(conv, ops);
+ if (ops != NULL && ops->create_conversation != NULL)
+ ops->create_conversation(conv);
+
+ purple_signal_emit(purple_conversations_get_handle(),
+ "conversation-created", conv);
+}
+
/* GObject dispose function */
static void
purple_conversation_dispose(GObject *object)
@@ -1012,7 +1048,8 @@ purple_conversation_finalize(GObject *ob
}
/* Class initializer function */
-static void purple_conversation_class_init(PurpleConversationClass *klass)
+static void
+purple_conversation_class_init(PurpleConversationClass *klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS(klass);
@@ -1020,6 +1057,7 @@ static void purple_conversation_class_in
obj_class->dispose = purple_conversation_dispose;
obj_class->finalize = purple_conversation_finalize;
+ obj_class->constructed = purple_conversation_constructed;
/* Setup properties */
obj_class->get_property = purple_conversation_get_property;
@@ -1034,13 +1072,13 @@ static void purple_conversation_class_in
g_object_class_install_property(obj_class, PROP_NAME,
g_param_spec_string(PROP_NAME_S, _("Name"),
_("The name of the conversation."), NULL,
- G_PARAM_READWRITE)
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
);
g_object_class_install_property(obj_class, PROP_TITLE,
g_param_spec_string(PROP_TITLE_S, _("Title"),
_("The title of the conversation."), NULL,
- G_PARAM_READWRITE)
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
);
g_object_class_install_property(obj_class, PROP_LOGGING,
diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -421,6 +421,33 @@ purple_im_conversation_get_property(GObj
}
}
+/* Called when done constructing */
+static void
+purple_im_conversation_constructed(GObject *object)
+{
+ PurpleIMConversation *im = PURPLE_IM_CONVERSATION(object);
+ PurpleAccount *account;
+ PurpleBuddyIcon *icon;
+ gchar *name;
+
+ G_OBJECT_CLASS(parent_class)->constructed(object);
+
+ g_object_get(object,
+ "account", &account,
+ "name", &name,
+ NULL);
+
+ if ((icon = purple_buddy_icons_find(account, name)))
+ {
+ purple_im_conversation_set_icon(im, icon);
+ /* purple_im_conversation_set_icon refs the icon. */
+ purple_buddy_icon_unref(icon);
+ }
+
+ if (purple_prefs_get_bool("/purple/logging/log_ims"))
+ purple_conversation_set_logging(PURPLE_CONVERSATION(im), TRUE);
+}
+
/* GObject dispose function */
static void
purple_im_conversation_dispose(GObject *object)
@@ -470,6 +497,7 @@ static void purple_im_conversation_class
obj_class->dispose = purple_im_conversation_dispose;
obj_class->finalize = purple_im_conversation_finalize;
+ obj_class->constructed = purple_im_conversation_constructed;
/* Setup properties */
obj_class->get_property = purple_im_conversation_get_property;
@@ -525,10 +553,7 @@ PurpleIMConversation *
purple_im_conversation_new(PurpleAccount *account, const char *name)
{
PurpleIMConversation *im;
- PurpleConversation *conv;
PurpleConnection *gc;
- PurpleConversationUiOps *ops;
- PurpleBuddyIcon *icon;
g_return_val_if_fail(account != NULL, NULL);
g_return_val_if_fail(name != NULL, NULL);
@@ -546,38 +571,6 @@ purple_im_conversation_new(PurpleAccount
"title", name,
NULL);
- conv = PURPLE_CONVERSATION(im);
-
- /* copy features from the connection. */
- purple_conversation_set_features(conv,
- purple_connection_get_flags(gc));
-
- purple_conversations_add(conv);
- if ((icon = purple_buddy_icons_find(account, name)))
- {
- purple_im_conversation_set_icon(im, icon);
- /* purple_im_conversation_set_icon refs the icon. */
- purple_buddy_icon_unref(icon);
- }
-
- if (purple_prefs_get_bool("/purple/logging/log_ims"))
- purple_conversation_set_logging(conv, TRUE);
-
- /* Auto-set the title. */
- purple_conversation_autoset_title(conv);
-
- /* Don't move this.. it needs to be one of the last things done otherwise
- * it causes mysterious crashes on my system.
- * -- Gary
- */
- ops = purple_conversations_get_ui_ops();
- purple_conversation_set_ui_ops(conv, ops);
- if (ops != NULL && ops->create_conversation != NULL)
- ops->create_conversation(conv);
-
- purple_signal_emit(purple_conversations_get_handle(),
- "conversation-created", im);
-
return im;
}
@@ -1411,6 +1404,28 @@ static void purple_chat_conversation_ini
_purple_conversation_user_equal, g_free, NULL);
}
+/* Called when done constructing */
+static void
+purple_chat_conversation_constructed(GObject *object)
+{
+ PurpleChatConversation *chat = PURPLE_CHAT_CONVERSATION(object);
+ PurpleAccount *account;
+ const char *disp;
+
+ G_OBJECT_CLASS(parent_class)->constructed(object);
+
+ g_object_get(object, "account", &account, NULL);
+
+ if ((disp = purple_connection_get_display_name(purple_account_get_connection(account))))
+ purple_chat_conversation_set_nick(chat, disp);
+ else
+ purple_chat_conversation_set_nick(chat,
+ purple_account_get_username(account));
+
+ if (purple_prefs_get_bool("/purple/logging/log_chats"))
+ purple_conversation_set_logging(PURPLE_CONVERSATION(chat), TRUE);
+}
+
/* GObject dispose function */
static void
purple_chat_conversation_dispose(GObject *object)
@@ -1499,6 +1514,7 @@ static void purple_chat_conversation_cla
obj_class->dispose = purple_chat_conversation_dispose;
obj_class->finalize = purple_chat_conversation_finalize;
+ obj_class->constructed = purple_chat_conversation_constructed;
/* Setup properties */
obj_class->get_property = purple_chat_conversation_get_property;
@@ -1570,10 +1586,7 @@ PurpleChatConversation *
purple_chat_conversation_new(PurpleAccount *account, const char *name)
{
PurpleChatConversation *chat;
- PurpleConversation *conv;
PurpleConnection *gc;
- PurpleConversationUiOps *ops;
- const char *disp;
g_return_val_if_fail(account != NULL, NULL);
g_return_val_if_fail(name != NULL, NULL);
@@ -1609,38 +1622,6 @@ purple_chat_conversation_new(PurpleAccou
"title", name,
NULL);
- conv = PURPLE_CONVERSATION(chat);
-
- /* copy features from the connection. */
- purple_conversation_set_features(conv,
- purple_connection_get_flags(gc));
-
- purple_conversations_add(conv);
-
- if ((disp = purple_connection_get_display_name(purple_account_get_connection(account))))
- purple_chat_conversation_set_nick(chat, disp);
- else
- purple_chat_conversation_set_nick(chat,
- purple_account_get_username(account));
-
- if (purple_prefs_get_bool("/purple/logging/log_chats"))
- purple_conversation_set_logging(conv, TRUE);
-
- /* Auto-set the title. */
- purple_conversation_autoset_title(conv);
-
- /* Don't move this.. it needs to be one of the last things done otherwise
- * it causes mysterious crashes on my system.
- * -- Gary
- */
- ops = purple_conversations_get_ui_ops();
- purple_conversation_set_ui_ops(PURPLE_CONVERSATION(chat), ops);
- if (ops != NULL && ops->create_conversation != NULL)
- ops->create_conversation(conv);
-
- purple_signal_emit(purple_conversations_get_handle(),
- "conversation-created", chat);
-
return chat;
}
@@ -1882,6 +1863,13 @@ purple_chat_user_get_property(GObject *o
}
}
+/* GObject initialization function */
+static void
+purple_chat_user_init(GTypeInstance *instance, gpointer klass)
+{
+ PURPLE_DBUS_REGISTER_POINTER(PURPLE_CHAT_USER(instance), PurpleChatUser);
+}
+
/* GObject dispose function */
static void
purple_chat_user_dispose(GObject *object)
@@ -1932,13 +1920,13 @@ static void purple_chat_user_class_init(
g_object_class_install_property(obj_class, CU_PROP_NAME,
g_param_spec_string(CU_PROP_NAME_S, _("Name"),
_("Name of the chat user."), NULL,
- G_PARAM_READWRITE)
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
);
g_object_class_install_property(obj_class, CU_PROP_ALIAS,
g_param_spec_string(CU_PROP_ALIAS_S, _("Alias"),
_("Alias of the chat user."), NULL,
- G_PARAM_READWRITE)
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
);
g_object_class_install_property(obj_class, CU_PROP_BUDDY,
@@ -1950,8 +1938,8 @@ static void purple_chat_user_class_init(
g_object_class_install_property(obj_class, CU_PROP_FLAGS,
g_param_spec_flags(CU_PROP_FLAGS_S, _("Buddy flags"),
_("The flags for the chat user."),
- PURPLE_TYPE_CHAT_USER_FLAGS,
- PURPLE_CHAT_USER_NONE, G_PARAM_READWRITE)
+ PURPLE_TYPE_CHAT_USER_FLAGS, PURPLE_CHAT_USER_NONE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT)
More information about the Commits
mailing list