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
22 #include "thpresence.h"
26 void thrasher_set_presence (PurpleAccount
*pa
, PurpleStatusPrimitive primitive
, gchar
*message
)
28 PurplePresence
*presence
;
30 PurpleStatusType
*type
;
31 char *status_id
= NULL
;
33 /* Get the status_id so we can create a new type.
35 * Differs from purple_primitive_get_id_from_type() because
36 * purple_account_set_status() will fail if we send an invalid
37 * status ID for the account and we want to keep consistent with
38 * what the Perl-side supports. E.g. PURPLE_STATUS_UNAVAILABLE:
39 * prpls have it as "dnd" while _get_id_from_type() gives
44 case PURPLE_STATUS_UNSET
:
45 /* See PURPLE_STATUS_EXTENDED_AWAY */
46 status_id
= g_strdup("away");
48 case PURPLE_STATUS_OFFLINE
:
49 status_id
= g_strdup("offline");
51 case PURPLE_STATUS_AVAILABLE
:
52 status_id
= g_strdup("available");
54 case PURPLE_STATUS_UNAVAILABLE
:
55 status_id
= g_strdup("dnd");
57 case PURPLE_STATUS_INVISIBLE
:
58 /* Currently unsupported */
60 case PURPLE_STATUS_AWAY
:
61 status_id
= g_strdup("away");
63 case PURPLE_STATUS_EXTENDED_AWAY
:
64 /* We need to do the abstraction in Perl, but for now we're doing it painfully here... */
65 status_id
= g_strdup("away");
67 case PURPLE_STATUS_MOBILE
:
68 /* Currently unsupported */
70 case PURPLE_STATUS_TUNE
:
71 /* Currently unsupported */
73 case PURPLE_STATUS_NUM_PRIMITIVES
:
78 /* No reason to trip statuses if we don't have a status_id */
81 /* Create a new status */
83 type
= purple_status_type_new_with_attrs(primitive
, status_id
, status_id
,
84 TRUE
, TRUE
, TRUE
, "message",
86 purple_value_new(PURPLE_TYPE_STRING
),
89 type
= purple_status_type_new(primitive
, status_id
, status_id
, TRUE
);
91 /* Wrap these two calls together */
92 presence
= purple_presence_new_for_account(pa
);
93 status
= purple_status_new(type
, presence
);
95 /* Flip the status on */
97 purple_account_set_status(pa
, status_id
, TRUE
, "message", message
, NULL
);
99 purple_account_set_status(pa
, status_id
, TRUE
, NULL
);