soc.2009.telepathy: 099ee5ce: Better status support, refractored telep...
sttwister at soc.pidgin.im
sttwister at soc.pidgin.im
Fri Jun 12 14:35:29 EDT 2009
-----------------------------------------------------------------
Revision: 099ee5ce78534d63fc2eb2cdeef152ec28e64473
Ancestor: e51223a0b1b49a3898e2f9342eb27901077875cc
Author: sttwister at soc.pidgin.im
Date: 2009-06-12T18:31:16
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/099ee5ce78534d63fc2eb2cdeef152ec28e64473
Modified files:
libpurple/protocols/telepathy/telepathy.c
ChangeLog:
Better status support, refractored telepathy_status_types
-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy.c c88dc5f4e030817c868daf330a0bb550d742a1ec
+++ libpurple/protocols/telepathy/telepathy.c b88abf56d451b055bac1a324f37730ae27455572
@@ -41,10 +41,6 @@
#define TELEPATHY_ID "prpl-telepathy"
#define TELEPATHY_DISPLAY_VERSION "1.0"
-#define TELEPATHY_STATUS_ONLINE "available"
-#define TELEPATHY_STATUS_AWAY "away"
-#define TELEPATHY_STATUS_OFFLINE "offline"
-
static void *module_handle;
static gchar *module_path;
@@ -113,6 +109,28 @@ static const OptionMapping options[] = {
{ NULL, NULL, NULL}
};
+typedef struct
+{
+ const guint status_primitive;
+ const gchar* id;
+ const gchar* description;
+} StatusMapping;
+
+static const StatusMapping statuses[] =
+{
+ { PURPLE_STATUS_AVAILABLE, "available", "Available" },
+ { PURPLE_STATUS_AWAY, "away", N_("Away") },
+ { PURPLE_STATUS_AWAY, "brb", N_("Be right back") },
+ { PURPLE_STATUS_UNAVAILABLE, "dnd", N_("Do not disturb") },
+ { PURPLE_STATUS_UNAVAILABLE, "busy", N_("Busy") },
+ { PURPLE_STATUS_EXTENDED_AWAY, "xa", N_("Extended away") },
+ { PURPLE_STATUS_INVISIBLE, "hidden", NULL },
+ { PURPLE_STATUS_OFFLINE, "offline", NULL },
+ { PURPLE_STATUS_UNSET, "unknown", NULL },
+ { PURPLE_STATUS_UNSET, "error", NULL },
+ { 0, NULL, NULL}
+};
+
static void
telepathy_input_user_info(PurplePluginAction *action)
{
@@ -147,6 +165,24 @@ telepathy_list_icon(PurpleAccount *acct,
return "telepathy";
}
+static const gchar*
+telepathy_get_status_string(PurpleStatus *status)
+{
+ const gchar* id = purple_status_get_id(status);
+
+ int i;
+
+ for (i = 0; statuses[i].id != NULL; ++i)
+ {
+ if (statuses[i].status_primitive != PURPLE_STATUS_AVAILABLE && g_strcmp0(id, statuses[i].id) == 0)
+ {
+ return statuses[i].description;
+ }
+ }
+
+ return NULL;
+}
+
static gchar*
telepathy_status_text(PurpleBuddy* buddy)
{
@@ -162,6 +198,10 @@ telepathy_status_text(PurpleBuddy* buddy
{
const gchar *message = purple_status_get_attr_string(status, "message");
+ /* return the description of the current status if there's no custom message */
+ if (g_strcmp0(message, "") == 0)
+ message = telepathy_get_status_string(status);
+
/* an empty message confuses the UI, NULL is better */
if (g_strcmp0(message, "") == 0)
return NULL;
@@ -196,28 +236,24 @@ telepathy_status_types(PurpleAccount *ac
GList *types = NULL;
PurpleStatusType *type;
- purple_debug_info("telepathy", "Returning status types for %s: %s, %s, %s\n",
- acct->username,
- TELEPATHY_STATUS_ONLINE, TELEPATHY_STATUS_AWAY, TELEPATHY_STATUS_OFFLINE);
+ int i;
- type = purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE,
- TELEPATHY_STATUS_ONLINE, NULL, TRUE, TRUE, FALSE,
- "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING),
- NULL);
- types = g_list_prepend(types, type);
+ for (i = 0; statuses[i].id != NULL; ++i)
+ {
+ if (statuses[i].description == NULL)
+ {
+ type = purple_status_type_new(statuses[i].status_primitive, statuses[i].id, NULL, TRUE);
+ }
+ else
+ {
+ type = purple_status_type_new_with_attrs(statuses[i].status_primitive,
+ statuses[i].id, statuses[i].description, TRUE, TRUE, FALSE,
+ "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING),
+ NULL);
+ }
+ types = g_list_prepend(types, type);
+ }
- type = purple_status_type_new_with_attrs(PURPLE_STATUS_AWAY,
- TELEPATHY_STATUS_AWAY, NULL, TRUE, TRUE, FALSE,
- "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING),
- NULL);
- types = g_list_prepend(types, type);
-
- type = purple_status_type_new_with_attrs(PURPLE_STATUS_OFFLINE,
- NULL, NULL, TRUE, TRUE, FALSE,
- "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING),
- NULL);
- types = g_list_prepend(types, type);
-
return g_list_reverse(types);
}
More information about the Commits
mailing list