/soc/2013/ankitkv/gobjectification: db04fa580c4b: Redesigned the...
Ankit Vani
a at nevitus.org
Tue Jul 9 14:13:38 EDT 2013
Changeset: db04fa580c4b16e503526cdb151d3b32ef2e3e34
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-09 23:43 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/db04fa580c4b
Description:
Redesigned the finch grouping plugin to use the GObject BList node API
diffstat:
finch/plugins/grouping.c | 149 +++++++++++++++++++++++++++-------------------
1 files changed, 88 insertions(+), 61 deletions(-)
diffs (232 lines):
diff --git a/finch/plugins/grouping.c b/finch/plugins/grouping.c
--- a/finch/plugins/grouping.c
+++ b/finch/plugins/grouping.c
@@ -28,78 +28,107 @@
#include "gnttree.h"
+#define FINCH_TYPE_GROUPING_NODE (finch_grouping_node_get_type())
+#define FINCH_GROUPING_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), FINCH_TYPE_GROUPING_NODE, FinchGroupingNode))
+#define FINCH_GROUPING_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), FINCH_TYPE_GROUPING_NODE, FinchGroupingNodeClass))
+#define FINCH_IS_GROUPING_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), FINCH_TYPE_GROUPING_NODE))
+#define FINCH_IS_GROUPING_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), FINCH_TYPE_GROUPING_NODE))
+#define FINCH_GROUPING_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), FINCH_TYPE_GROUPING_NODE, FinchGroupingNodeClass))
+
+typedef struct {
+ PurpleBListNode node;
+} FinchGroupingNode;
+
+typedef struct {
+ PurpleBListNodeClass node_class;
+} FinchGroupingNodeClass;
+
static FinchBlistManager *default_manager;
/**
+ * GObject code
+ */
+static GType
+finch_grouping_node_get_type(void)
+{
+ static GType type = 0;
+
+ if(type == 0) {
+ static const GTypeInfo info = {
+ sizeof(FinchGroupingNodeClass),
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ sizeof(FinchGroupingNode),
+ 0,
+ NULL,
+ NULL,
+ };
+
+ type = g_type_register_static(PURPLE_TYPE_BLIST_NODE,
+ "FinchGroupingNode",
+ &info, 0);
+ }
+
+ return type;
+}
+
+/**
* Online/Offline
*/
-static PurpleBListNode online = {.type = PURPLE_BLIST_OTHER_NODE},
- offline = {.type = PURPLE_BLIST_OTHER_NODE};
+static FinchGroupingNode *online, *offline;
static gboolean on_offline_init()
{
GntTree *tree = finch_blist_get_tree();
- gnt_tree_add_row_after(tree, &online,
+ gnt_tree_add_row_after(tree, online,
gnt_tree_create_row(tree, _("Online")), NULL, NULL);
- gnt_tree_add_row_after(tree, &offline,
- gnt_tree_create_row(tree, _("Offline")), NULL, &online);
+ gnt_tree_add_row_after(tree, offline,
+ gnt_tree_create_row(tree, _("Offline")), NULL, online);
return TRUE;
}
static gboolean on_offline_can_add_node(PurpleBListNode *node)
{
- switch (purple_blist_node_get_type(node)) {
- case PURPLE_BLIST_CONTACT_NODE:
- {
- PurpleContact *contact = (PurpleContact*)node;
- if (purple_contact_get_contact_size(contact, FALSE) > 0)
- return TRUE;
- return FALSE;
- }
- break;
- case PURPLE_BLIST_BUDDY_NODE:
- {
- PurpleBuddy *buddy = (PurpleBuddy*)node;
- if (PURPLE_IS_BUDDY_ONLINE(buddy))
- return TRUE;
- if (purple_prefs_get_bool("/finch/blist/showoffline") &&
- purple_account_is_connected(purple_buddy_get_account(buddy)))
- return TRUE;
- return FALSE;
- }
- break;
- case PURPLE_BLIST_CHAT_NODE:
- {
- PurpleChat *chat = (PurpleChat*)node;
- return purple_account_is_connected(purple_chat_get_account(chat));
- }
- break;
- default:
- return FALSE;
+ if (PURPLE_IS_CONTACT(node)) {
+ PurpleContact *contact = (PurpleContact*)node;
+ if (purple_counting_node_get_current_size(PURPLE_COUNTING_NODE(contact)) > 0)
+ return TRUE;
+ return FALSE;
+ } else if (PURPLE_IS_BUDDY(node)) {
+ PurpleBuddy *buddy = (PurpleBuddy*)node;
+ if (PURPLE_IS_BUDDY_ONLINE(buddy))
+ return TRUE;
+ if (purple_prefs_get_bool("/finch/blist/showoffline") &&
+ purple_account_is_connected(purple_buddy_get_account(buddy)))
+ return TRUE;
+ return FALSE;
+ } else if (PURPLE_IS_CHAT(node)) {
+ PurpleChat *chat = (PurpleChat*)node;
+ return purple_account_is_connected(purple_chat_get_account(chat));
}
+
+ return FALSE;
}
static gpointer on_offline_find_parent(PurpleBListNode *node)
{
gpointer ret = NULL;
- switch (purple_blist_node_get_type(node)) {
- case PURPLE_BLIST_CONTACT_NODE:
- node = PURPLE_BLIST_NODE(purple_contact_get_priority_buddy(PURPLE_CONTACT(node)));
- ret = PURPLE_IS_BUDDY_ONLINE((PurpleBuddy*)node) ? &online : &offline;
- break;
- case PURPLE_BLIST_BUDDY_NODE:
- ret = purple_blist_node_get_parent(node);
- finch_blist_manager_add_node(ret);
- break;
- case PURPLE_BLIST_CHAT_NODE:
- ret = &online;
- break;
- default:
- break;
+ if (PURPLE_IS_CONTACT(node)) {
+ node = PURPLE_BLIST_NODE(purple_contact_get_priority_buddy(PURPLE_CONTACT(node)));
+ ret = PURPLE_IS_BUDDY_ONLINE((PurpleBuddy*)node) ? online : offline;
+ } else if (PURPLE_IS_BUDDY(node)) {
+ ret = purple_blist_node_get_parent(node);
+ finch_blist_manager_add_node(ret);
+ } else if (PURPLE_IS_CHAT(node)) {
+ ret = online;
}
+
return ret;
}
@@ -107,12 +136,13 @@ static gboolean on_offline_create_toolti
{
PurpleBListNode *node = selected_row;
- if (purple_blist_node_get_type(node) == PURPLE_BLIST_OTHER_NODE) {
+ if (FINCH_IS_GROUPING_NODE(node)) {
/* There should be some easy way of getting the total online count,
* or total number of chats. Doing a loop here will probably be pretty
* expensive. */
if (body)
- *body = g_string_new(node == &online ? _("Online Buddies") : _("Offline Buddies"));
+ *body = g_string_new(FINCH_GROUPING_NODE(node) == online ?
+ _("Online Buddies") : _("Offline Buddies"));
return TRUE;
} else {
return default_manager ? default_manager->create_tooltip(selected_row, body, tool_title) : FALSE;
@@ -134,7 +164,7 @@ static FinchBlistManager on_offline =
/**
* Meebo-like Grouping.
*/
-static PurpleBListNode meebo = {.type = PURPLE_BLIST_OTHER_NODE};
+static FinchGroupingNode meebo;
static gboolean meebo_init()
{
GntTree *tree = finch_blist_get_tree();
@@ -194,14 +224,11 @@ static gpointer no_group_find_parent(Pur
{
gpointer ret = NULL;
- switch (purple_blist_node_get_type(node)) {
- case PURPLE_BLIST_BUDDY_NODE:
- ret = purple_blist_node_get_parent(node);
- finch_blist_manager_add_node(ret);
- break;
- default:
- break;
+ if (PURPLE_IS_BUDDY(node)) {
+ ret = purple_blist_node_get_parent(node);
+ finch_blist_manager_add_node(ret);
}
+
return ret;
}
@@ -266,9 +293,8 @@ nested_group_find_parent(PurpleBListNode
finch_blist_manager_add_node(ret);
parent = ret;
} else if (!(ret = g_hash_table_lookup(groups, name))) {
- ret = g_new0(PurpleBListNode, 1);
+ ret = g_object_new(FINCH_TYPE_GROUPING_NODE, NULL);
g_hash_table_insert(groups, g_strdup(name), ret);
- ret->type = PURPLE_BLIST_OTHER_NODE;
gnt_tree_add_row_last(tree, ret,
gnt_tree_create_row(tree, name), parent);
parent = ret;
@@ -285,8 +311,7 @@ static gboolean
nested_group_create_tooltip(gpointer selected_row, GString **body, char **title)
{
PurpleBListNode *node = selected_row;
- if (!node ||
- purple_blist_node_get_type(node) != PURPLE_BLIST_OTHER_NODE)
+ if (!node || !FINCH_IS_GROUPING_NODE(node))
return default_manager->create_tooltip(selected_row, body, title);
if (body)
*body = g_string_new(_("Nested Subgroup")); /* Perhaps list the child groups/subgroups? */
@@ -381,6 +406,8 @@ static PurplePluginInfo info =
static void
init_plugin(PurplePlugin *plugin)
{
+ online = g_object_new(FINCH_TYPE_GROUPING_NODE, NULL);
+ offline = g_object_new(FINCH_TYPE_GROUPING_NODE, NULL);
}
PURPLE_INIT_PLUGIN(grouping, init_plugin, info)
More information about the Commits
mailing list