im.pidgin.pidgin: b73801c0e9d8f1a9e70ebf820d9e072d00b2ad80

sadrul at pidgin.im sadrul at pidgin.im
Tue Jan 22 09:11:24 EST 2008


-----------------------------------------------------------------
Revision: b73801c0e9d8f1a9e70ebf820d9e072d00b2ad80
Ancestor: 0cc698d207320d5a1852fd9a5160feea42cf187f
Author: sadrul at pidgin.im
Date: 2008-01-22T07:54:48
Branch: im.pidgin.pidgin

Added files:
        finch/plugins/grouping.c
Modified files:
        finch/plugins/Makefile.am

ChangeLog: 

Add a plugin to provide 'Online/Offline' grouping and no grouping.

-------------- next part --------------
============================================================
--- finch/plugins/grouping.c	baa0f5351d3843aa27231f475613c32840b0fd6d
+++ finch/plugins/grouping.c	baa0f5351d3843aa27231f475613c32840b0fd6d
@@ -0,0 +1,217 @@
+/**
+ * @file grouping.c  Provides different grouping options.
+ *
+ * Copyright (C) 2008 Sadrul Habib Chowdhury <sadrul at users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define PURPLE_PLUGIN
+
+#include "internal.h"
+#include "purple.h"
+
+#include "gntblist.h"
+#include "gntplugin.h"
+
+#include "gnttree.h"
+
+/**
+ * Online/Offline
+ */
+static PurpleBlistNode online = {.type = PURPLE_BLIST_OTHER_NODE},
+					   offline = {.type = PURPLE_BLIST_OTHER_NODE};
+
+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 (contact->currentsize > 0)
+					return TRUE;
+				return FALSE;
+			}
+			break;
+		case PURPLE_BLIST_BUDDY_NODE:
+			{
+				PurpleBuddy *buddy = (PurpleBuddy*)node;
+				if (PURPLE_BUDDY_IS_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;
+	}
+}
+
+static gpointer on_offline_find_parent(PurpleBlistNode *node)
+{
+	gpointer ret = NULL;
+	GntTree *tree = finch_blist_get_tree();
+
+	if (!tree)
+		return NULL;
+
+	if (!g_list_find(gnt_tree_get_rows(tree), &online)) {
+		gnt_tree_remove_all(tree);
+		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);
+	}
+
+	switch (purple_blist_node_get_type(node)) {
+		case PURPLE_BLIST_CONTACT_NODE:
+			node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node);
+			ret = PURPLE_BUDDY_IS_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;
+	}
+	return ret;
+}
+
+static gboolean on_offline_create_tooltip(gpointer selected_row, GString **body, char **tool_title)
+{
+	static FinchBlistManager *def = NULL;
+	PurpleBlistNode *node = selected_row;
+
+	if (def == NULL)
+		def = finch_blist_manager_find("default");
+
+	if (purple_blist_node_get_type(node) == PURPLE_BLIST_OTHER_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"));
+		return TRUE;
+	} else {
+		return def ? def->create_tooltip(selected_row, body, tool_title) : FALSE;
+	}
+}
+
+static FinchBlistManager on_offline =
+{
+	"on-offline",
+	N_("Online/Offline"),
+	on_offline_can_add_node,
+	on_offline_find_parent,
+	on_offline_create_tooltip,
+	{NULL, NULL, NULL, NULL}
+};
+
+/**
+ * No Grouping.
+ */
+static gboolean no_group_can_add_node(PurpleBlistNode *node)
+{
+	return on_offline_can_add_node(node);   /* These happen to be the same */
+}
+
+static gpointer no_group_find_parent(PurpleBlistNode *node)
+{
+	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;
+	}
+	return ret;
+}
+
+static FinchBlistManager no_group =
+{
+	"no-group",
+	N_("No Grouping"),
+	no_group_can_add_node,
+	no_group_find_parent,
+	NULL,
+	{NULL, NULL, NULL, NULL}
+};
+
+static gboolean
+plugin_load(PurplePlugin *plugin)
+{
+	finch_blist_install_manager(&on_offline);
+	finch_blist_install_manager(&no_group);
+	return TRUE;
+}
+
+static gboolean
+plugin_unload(PurplePlugin *plugin)
+{
+	finch_blist_uninstall_manager(&on_offline);
+	finch_blist_uninstall_manager(&no_group);
+	return TRUE;
+}
+
+static PurplePluginInfo info =
+{
+	PURPLE_PLUGIN_MAGIC,
+	PURPLE_MAJOR_VERSION,
+	PURPLE_MINOR_VERSION,
+	PURPLE_PLUGIN_STANDARD,
+	FINCH_PLUGIN_TYPE,
+	0,
+	NULL,
+	PURPLE_PRIORITY_DEFAULT,
+	"grouping",
+	N_("Grouping"),
+	VERSION,
+	N_("Provides alternate buddylist grouping options."),
+	N_("Provides alternate buddylist grouping options."),
+	"Sadrul H Chowdhury <sadrul at users.sourceforge.net>",
+	PURPLE_WEBSITE,
+	plugin_load,
+	plugin_unload,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,NULL,NULL,NULL
+};
+
+static void
+init_plugin(PurplePlugin *plugin)
+{
+}
+
+PURPLE_INIT_PLUGIN(ignore, init_plugin, info)
+
+
============================================================
--- finch/plugins/Makefile.am	f0bb61bff968457db8110eb175b6c8c270536af8
+++ finch/plugins/Makefile.am	90e6e785137431ec3787d3dce8469e8b4939921e
@@ -1,7 +1,8 @@ gnthistory_la_LDFLAGS = -module -avoid-v
 gntclipboard_la_LDFLAGS = -module -avoid-version
 gntgf_la_LDFLAGS      = -module -avoid-version
 gnthistory_la_LDFLAGS = -module -avoid-version
-gntlastlog_la_LDFLAGS    = -module -avoid-version
+gntlastlog_la_LDFLAGS = -module -avoid-version
+grouping_la_LDFLAGS   = -module -avoid-version
 
 if PLUGINS
 
@@ -9,7 +10,8 @@ plugin_LTLIBRARIES = \
 	gntclipboard.la \
 	gntgf.la \
 	gnthistory.la \
-	gntlastlog.la
+	gntlastlog.la \
+	grouping.la
 
 plugindir = $(libdir)/finch
 
@@ -17,6 +19,7 @@ gntlastlog_la_SOURCES = lastlog.c
 gntgf_la_SOURCES      = gntgf.c
 gnthistory_la_SOURCES = gnthistory.c
 gntlastlog_la_SOURCES = lastlog.c
+grouping_la_SOURCES   = grouping.c
 
 gntclipboard_la_CFLAGS = $(X11_CFLAGS)
 gntgf_la_CFLAGS = $(X11_CFLAGS)
@@ -25,6 +28,7 @@ gntlastlog_la_LIBADD  = $(GLIB_LIBS)
 gntgf_la_LIBADD       = $(GLIB_LIBS) $(X11_LIBS) $(top_builddir)/finch/libgnt/libgnt.la
 gnthistory_la_LIBADD  = $(GLIB_LIBS)
 gntlastlog_la_LIBADD  = $(GLIB_LIBS)
+grouping_la_LIBADD    = $(GLIB_LIBS) $(top_builddir)/finch/libgnt/libgnt.la
 
 endif # PLUGINS
 


More information about the Commits mailing list