/soc/2013/ankitkv/gobjectification: 4a12e889d1fd: Refactored nul...

Ankit Vani a at nevitus.org
Tue Aug 27 14:44:35 EDT 2013


Changeset: 4a12e889d1fdb8d183677d1a064cb67613b06362
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-28 00:13 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/4a12e889d1fd

Description:

Refactored nullprotocol (renamed from nullprpl) to use the new protocol API

diffstat:

 libpurple/protocols/null/Makefile.am    |    4 +-
 libpurple/protocols/null/nullprpl.c     |  577 ++++++++++++++++---------------
 libpurple/protocols/null/nullprotocol.h |   53 ++
 3 files changed, 345 insertions(+), 289 deletions(-)

diffs (truncated from 1290 to 300 lines):

diff --git a/libpurple/protocols/null/Makefile.am b/libpurple/protocols/null/Makefile.am
--- a/libpurple/protocols/null/Makefile.am
+++ b/libpurple/protocols/null/Makefile.am
@@ -4,7 +4,9 @@ EXTRA_DIST = \
 
 pkgdir = $(libdir)/purple-$(PURPLE_MAJOR_VERSION)
 
-NULLSOURCES = nullprpl.c
+NULLSOURCES = \
+	nullprotocol.h \
+	nullprotocol.c
 
 AM_CFLAGS = $(st)
 
diff --git a/libpurple/protocols/null/nullprpl.c b/libpurple/protocols/null/nullprotocol.c
rename from libpurple/protocols/null/nullprpl.c
rename to libpurple/protocols/null/nullprotocol.c
--- a/libpurple/protocols/null/nullprpl.c
+++ b/libpurple/protocols/null/nullprotocol.c
@@ -5,22 +5,22 @@
  * to list here.  Please refer to the COPYRIGHT file distributed with this
  * source distribution.
  *
- * Nullprpl is a mock protocol plugin for Pidgin and libpurple. You can create
- * accounts with it, sign on and off, add buddies, and send and receive IMs,
- * all without connecting to a server!
+ * NullProtocol is a mock protocol plugin for Pidgin and libpurple. You can
+ * create accounts with it, sign on and off, add buddies, and send and receive
+ * IMs, all without connecting to a server!
  *
- * Beyond that basic functionality, nullprpl supports presence and
+ * Beyond that basic functionality, nullprotocol supports presence and
  * away/available messages, offline messages, user info, typing notification,
  * privacy allow/block lists, chat rooms, whispering, room lists, and protocol
  * icons and emblems. Notable missing features are file transfer and account
  * registration and authentication.
  *
- * Nullprpl is intended as an example of how to write a libpurple protocol
+ * NullProtocol is intended as an example of how to write a libpurple protocol
  * plugin. It doesn't contain networking code or an event loop, but it does
- * demonstrate how to use the libpurple API to do pretty much everything a prpl
- * might need to do.
+ * demonstrate how to use the libpurple API to do pretty much everything a
+ * protocol might need to do.
  *
- * Nullprpl is also a useful tool for hacking on Pidgin, Finch, and other
+ * NullProtocol is also a useful tool for hacking on Pidgin, Finch, and other
  * libpurple clients. It's a full-featured protocol plugin, but doesn't depend
  * on an external server, so it's a quick and easy way to exercise test new
  * code. It also allows you to work while you're disconnected.
@@ -46,7 +46,9 @@
 
 #include <glib.h>
 
-/* If you're using this as the basis of a prpl that will be distributed
+#include "nullprotocol.h"
+
+/* If you're using this as the basis of a protocol that will be distributed
  * separately from libpurple, remove the internal.h include below and replace
  * it with code to include your own config.h or similar.  If you're going to
  * provide for translation, you'll also need to setup the gettext macros. */
@@ -61,14 +63,12 @@
 #include "debug.h"
 #include "notify.h"
 #include "plugins.h"
-#include "protocol.h"
 #include "roomlist.h"
 #include "status.h"
 #include "util.h"
 #include "version.h"
 
-#define NULLPRPL_ID "prpl-null"
-static PurpleProtocol *_null_protocol = NULL;
+static PurpleProtocol *my_protocol = NULL;
 
 #define NULL_STATUS_ONLINE   "online"
 #define NULL_STATUS_AWAY     "away"
@@ -100,26 +100,26 @@ typedef struct {
 /*
  * helpers
  */
-static PurpleConnection *get_nullprpl_gc(const char *username) {
-  PurpleAccount *acct = purple_accounts_find(username, NULLPRPL_ID);
+static PurpleConnection *get_null_gc(const char *username) {
+  PurpleAccount *acct = purple_accounts_find(username, NULL_ID);
   if (acct && purple_account_is_connected(acct))
     return purple_account_get_connection(acct);
   else
     return NULL;
 }
 
-static void call_if_nullprpl(gpointer data, gpointer userdata) {
+static void call_if_nullprotocol(gpointer data, gpointer userdata) {
   PurpleConnection *gc = (PurpleConnection *)(data);
   GcFuncData *gcfdata = (GcFuncData *)userdata;
 
-  if (!strcmp(purple_account_get_protocol_id(purple_connection_get_account(gc)), NULLPRPL_ID))
+  if (!strcmp(purple_account_get_protocol_id(purple_connection_get_account(gc)), NULL_ID))
     gcfdata->fn(gcfdata->from, gc, gcfdata->userdata);
 }
 
-static void foreach_nullprpl_gc(GcFunc fn, PurpleConnection *from,
+static void foreach_null_gc(GcFunc fn, PurpleConnection *from,
                                 gpointer userdata) {
   GcFuncData gcfdata = { fn, from, userdata };
-  g_list_foreach(purple_connections_get_all(), call_if_nullprpl,
+  g_list_foreach(purple_connections_get_all(), call_if_nullprotocol,
                  &gcfdata);
 }
 
@@ -169,12 +169,12 @@ static void discover_status(PurpleConnec
     if (!strcmp(status_id, NULL_STATUS_ONLINE) ||
         !strcmp(status_id, NULL_STATUS_AWAY) ||
         !strcmp(status_id, NULL_STATUS_OFFLINE)) {
-      purple_debug_info("nullprpl", "%s sees that %s is %s: %s\n",
+      purple_debug_info("nullprotocol", "%s sees that %s is %s: %s\n",
                         from_username, to_username, status_id, message);
       purple_protocol_got_user_status(purple_connection_get_account(from), to_username, status_id,
                                   (message) ? "message" : NULL, message, NULL);
     } else {
-      purple_debug_error("nullprpl",
+      purple_debug_error("nullprotocol",
                          "%s's buddy %s has an unknown status: %s, %s",
                          from_username, to_username, status_id, message);
     }
@@ -183,7 +183,7 @@ static void discover_status(PurpleConnec
 
 static void report_status_change(PurpleConnection *from, PurpleConnection *to,
                                  gpointer userdata) {
-  purple_debug_info("nullprpl", "notifying %s that %s changed status\n",
+  purple_debug_info("nullprotocol", "notifying %s that %s changed status\n",
                     purple_account_get_username(purple_connection_get_account(to)), purple_account_get_username(purple_connection_get_account(from)));
   discover_status(to, from, NULL);
 }
@@ -192,11 +192,11 @@ static void report_status_change(PurpleC
 /*
  * UI callbacks
  */
-static void nullprpl_input_user_info(PurpleProtocolAction *action)
+static void null_input_user_info(PurpleProtocolAction *action)
 {
   PurpleConnection *gc = action->connection;
   PurpleAccount *acct = purple_connection_get_account(gc);
-  purple_debug_info("nullprpl", "showing 'Set User Info' dialog for %s\n",
+  purple_debug_info("nullprotocol", "showing 'Set User Info' dialog for %s\n",
                     purple_account_get_username(acct));
 
   purple_account_request_change_user_info(acct);
@@ -205,20 +205,20 @@ static void nullprpl_input_user_info(Pur
 /*
  * prpl functions
  */
-static GList *nullprpl_get_actions(PurpleConnection *gc)
+static GList *null_get_actions(PurpleConnection *gc)
 {
   PurpleProtocolAction *action = purple_protocol_action_new(
-    _("Set User Info..."), nullprpl_input_user_info);
+    _("Set User Info..."), null_input_user_info);
   return g_list_append(NULL, action);
 }
 
-static const char *nullprpl_list_icon(PurpleAccount *acct, PurpleBuddy *buddy)
+static const char *null_list_icon(PurpleAccount *acct, PurpleBuddy *buddy)
 {
   return "null";
 }
 
-static char *nullprpl_status_text(PurpleBuddy *buddy) {
-  purple_debug_info("nullprpl", "getting %s's status text for %s\n",
+static char *null_status_text(PurpleBuddy *buddy) {
+  purple_debug_info("nullprotocol", "getting %s's status text for %s\n",
                     purple_buddy_get_name(buddy),
                     purple_account_get_username(purple_buddy_get_account(buddy)));
 
@@ -234,28 +234,28 @@ static char *nullprpl_status_text(Purple
     else
       text = g_strdup(name);
 
-    purple_debug_info("nullprpl", "%s's status text is %s\n",
+    purple_debug_info("nullprotocol", "%s's status text is %s\n",
                       purple_buddy_get_name(buddy), text);
     return text;
 
   } else {
-    purple_debug_info("nullprpl", "...but %s is not logged in\n", purple_buddy_get_name(buddy));
+    purple_debug_info("nullprotocol", "...but %s is not logged in\n", purple_buddy_get_name(buddy));
     return g_strdup("Not logged in");
   }
 }
 
-static void nullprpl_tooltip_text(PurpleBuddy *buddy,
+static void null_tooltip_text(PurpleBuddy *buddy,
                                   PurpleNotifyUserInfo *info,
                                   gboolean full) {
-  PurpleConnection *gc = get_nullprpl_gc(purple_buddy_get_name(buddy));
+  PurpleConnection *gc = get_null_gc(purple_buddy_get_name(buddy));
 
   if (gc) {
     /* they're logged in */
     PurplePresence *presence = purple_buddy_get_presence(buddy);
     PurpleStatus *status = purple_presence_get_active_status(presence);
-    char *msg = nullprpl_status_text(buddy);
-	/* TODO: Check whether it's correct to call add_pair_html,
-	         or if we should be using add_pair_plaintext */
+    char *msg = null_status_text(buddy);
+  /* TODO: Check whether it's correct to call add_pair_html,
+           or if we should be using add_pair_plaintext */
     purple_notify_user_info_add_pair_html(info, purple_status_get_name(status),
                                      msg);
     g_free(msg);
@@ -263,8 +263,8 @@ static void nullprpl_tooltip_text(Purple
     if (full) {
       const char *user_info = purple_account_get_user_info(purple_connection_get_account(gc));
       if (user_info)
-		/* TODO: Check whether it's correct to call add_pair_html,
-		         or if we should be using add_pair_plaintext */
+    /* TODO: Check whether it's correct to call add_pair_html,
+             or if we should be using add_pair_plaintext */
         purple_notify_user_info_add_pair_html(info, _("User info"), user_info);
     }
 
@@ -273,16 +273,16 @@ static void nullprpl_tooltip_text(Purple
     purple_notify_user_info_add_pair_plaintext(info, _("User info"), _("not logged in"));
   }
 
-  purple_debug_info("nullprpl", "showing %s tooltip for %s\n",
+  purple_debug_info("nullprotocol", "showing %s tooltip for %s\n",
                     (full) ? "full" : "short", purple_buddy_get_name(buddy));
 }
 
-static GList *nullprpl_status_types(PurpleAccount *acct)
+static GList *null_status_types(PurpleAccount *acct)
 {
   GList *types = NULL;
   PurpleStatusType *type;
 
-  purple_debug_info("nullprpl", "returning status types for %s: %s, %s, %s\n",
+  purple_debug_info("nullprotocol", "returning status types for %s: %s, %s, %s\n",
                     purple_account_get_username(acct),
                     NULL_STATUS_ONLINE, NULL_STATUS_AWAY, NULL_STATUS_OFFLINE);
 
@@ -308,21 +308,21 @@ static GList *nullprpl_status_types(Purp
 }
 
 static void blist_example_menu_item(PurpleBlistNode *node, gpointer userdata) {
-  purple_debug_info("nullprpl", "example menu item clicked on user %s\n",
+  purple_debug_info("nullprotocol", "example menu item clicked on user %s\n",
                     purple_buddy_get_name(PURPLE_BUDDY(node)));
 
   purple_notify_info(NULL,  /* plugin handle or PurpleConnection */
                      _("Primary title"),
                      _("Secondary title"),
-                     _("This is the callback for the nullprpl menu item."));
+                     _("This is the callback for the nullprotocol menu item."));
 }
 
-static GList *nullprpl_blist_node_menu(PurpleBlistNode *node) {
-  purple_debug_info("nullprpl", "providing buddy list context menu item\n");
+static GList *null_blist_node_menu(PurpleBlistNode *node) {
+  purple_debug_info("nullprotocol", "providing buddy list context menu item\n");
 
   if (PURPLE_IS_BUDDY(node)) {
     PurpleMenuAction *action = purple_menu_action_new(
-      _("Nullprpl example menu item"),
+      _("NullProtocol example menu item"),
       PURPLE_CALLBACK(blist_example_menu_item),
       NULL,   /* userdata passed to the callback */
       NULL);  /* child menu items */
@@ -332,10 +332,10 @@ static GList *nullprpl_blist_node_menu(P
   }
 }
 
-static GList *nullprpl_chat_info(PurpleConnection *gc) {
-  PurpleProtocolChatEntry *pce; /* defined in protocol.h */
+static GList *null_chat_info(PurpleConnection *gc) {
+  PurpleProtocolChatEntry *pce; /* defined in protocols.h */
 
-  purple_debug_info("nullprpl", "returning chat setting 'room'\n");
+  purple_debug_info("nullprotocol", "returning chat setting 'room'\n");
 
   pce = g_new0(PurpleProtocolChatEntry, 1);
   pce->label = _("Chat _room");
@@ -345,11 +345,11 @@ static GList *nullprpl_chat_info(PurpleC
   return g_list_append(NULL, pce);
 }
 
-static GHashTable *nullprpl_chat_info_defaults(PurpleConnection *gc,
+static GHashTable *null_chat_info_defaults(PurpleConnection *gc,
                                                const char *room) {
   GHashTable *defaults;
 
-  purple_debug_info("nullprpl", "returning chat default setting "
+  purple_debug_info("nullprotocol", "returning chat default setting "
                     "'room' = 'default'\n");
 
   defaults = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
@@ -357,12 +357,12 @@ static GHashTable *nullprpl_chat_info_de
   return defaults;
 }
 



More information about the Commits mailing list