Refactor & centralize mapping of incoming libpurple presence codes.
[thrasher.git] / thpresence.c
blobb44e350ed01361cd4aac3f92b166f27b8a31c99e
1 /*
2 * Thrasher Bird - XMPP transport via libpurple
3 * Copyright (C) 2008 Barracuda Networks, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Thrasher Bird; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
19 #include <glib.h>
20 #include "status.h"
21 #include "account.h"
22 #include "thpresence.h"
26 void thrasher_set_presence (PurpleAccount *pa, PurpleStatusPrimitive primitive, gchar *message)
28 PurplePresence *presence;
29 PurpleStatus *status;
30 PurpleStatusType *type;
31 char *status_id = NULL;
33 /* Get the status_id so we can create a new type */
34 switch (primitive)
36 case PURPLE_STATUS_UNSET:
37 /* See PURPLE_STATUS_EXTENDED_AWAY */
38 status_id = g_strdup("away");
39 break;
40 case PURPLE_STATUS_OFFLINE:
41 status_id = g_strdup("offline");
42 break;
43 case PURPLE_STATUS_AVAILABLE:
44 status_id = g_strdup("available");
45 break;
46 case PURPLE_STATUS_UNAVAILABLE:
47 status_id = g_strdup("unavailable");
48 break;
49 case PURPLE_STATUS_INVISIBLE:
50 /* Currently unsupported */
51 break;
52 case PURPLE_STATUS_AWAY:
53 status_id = g_strdup("away");
54 break;
55 case PURPLE_STATUS_EXTENDED_AWAY:
56 /* We need to do the abstraction in Perl, but for now we're doing it painfully here... */
57 status_id = g_strdup("away");
58 break;
59 case PURPLE_STATUS_MOBILE:
60 /* Currently unsupported */
61 break;
62 case PURPLE_STATUS_TUNE:
63 /* Currently unsupported */
64 break;
65 case PURPLE_STATUS_NUM_PRIMITIVES:
66 /* Unsupported */
67 break;
70 /* No reason to trip statuses if we don't have a status_id */
71 if (status_id)
73 /* Create a new status */
74 if (message)
75 type = purple_status_type_new_with_attrs(primitive, status_id, status_id,
76 TRUE, TRUE, TRUE, "message",
77 "message",
78 purple_value_new(PURPLE_TYPE_STRING),
79 NULL);
80 else
81 type = purple_status_type_new(primitive, status_id, status_id, TRUE);
83 /* Wrap these two calls together */
84 presence = purple_presence_new_for_account(pa);
85 status = purple_status_new(type, presence);
87 /* Flip the status on */
88 if (message)
89 purple_account_set_status(pa, status_id, TRUE, "message", message, NULL);
90 else
91 purple_account_set_status(pa, status_id, TRUE, NULL);