comparison libpurple/protocols/msn/state.c @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
1 /**
2 * @file state.c State functions and definitions
3 *
4 * gaim
5 *
6 * Gaim is the legal property of its developers, whose names are too numerous
7 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * source distribution.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 #include "msn.h"
25 #include "state.h"
26
27 static const char *away_text[] =
28 {
29 N_("Available"),
30 N_("Available"),
31 N_("Busy"),
32 N_("Idle"),
33 N_("Be Right Back"),
34 N_("Away From Computer"),
35 N_("On The Phone"),
36 N_("Out To Lunch"),
37 N_("Available"),
38 N_("Available")
39 };
40
41 void
42 msn_change_status(MsnSession *session)
43 {
44 GaimAccount *account;
45 MsnCmdProc *cmdproc;
46 MsnUser *user;
47 MsnObject *msnobj;
48 const char *state_text;
49
50 g_return_if_fail(session != NULL);
51 g_return_if_fail(session->notification != NULL);
52
53 account = session->account;
54 cmdproc = session->notification->cmdproc;
55 user = session->user;
56 state_text = msn_state_get_text(msn_state_from_account(account));
57
58 /* If we're not logged in yet, don't send the status to the server,
59 * it will be sent when login completes
60 */
61 if (!session->logged_in)
62 return;
63
64 msnobj = msn_user_get_object(user);
65
66 if (msnobj == NULL)
67 {
68 msn_cmdproc_send(cmdproc, "CHG", "%s %d", state_text,
69 MSN_CLIENT_ID);
70 }
71 else
72 {
73 char *msnobj_str;
74
75 msnobj_str = msn_object_to_string(msnobj);
76
77 msn_cmdproc_send(cmdproc, "CHG", "%s %d %s", state_text,
78 MSN_CLIENT_ID, gaim_url_encode(msnobj_str));
79
80 g_free(msnobj_str);
81 }
82 }
83
84 const char *
85 msn_away_get_text(MsnAwayType type)
86 {
87 g_return_val_if_fail(type <= MSN_HIDDEN, NULL);
88
89 return _(away_text[type]);
90 }
91
92 const char *
93 msn_state_get_text(MsnAwayType state)
94 {
95 static char *status_text[] =
96 { "NLN", "NLN", "BSY", "IDL", "BRB", "AWY", "PHN", "LUN", "HDN", "HDN" };
97
98 return status_text[state];
99 }
100
101 MsnAwayType
102 msn_state_from_account(GaimAccount *account)
103 {
104 MsnAwayType msnstatus;
105 GaimPresence *presence;
106 GaimStatus *status;
107 const char *status_id;
108
109 presence = gaim_account_get_presence(account);
110 status = gaim_presence_get_active_status(presence);
111 status_id = gaim_status_get_id(status);
112
113 if (!strcmp(status_id, "away"))
114 msnstatus = MSN_AWAY;
115 else if (!strcmp(status_id, "brb"))
116 msnstatus = MSN_BRB;
117 else if (!strcmp(status_id, "busy"))
118 msnstatus = MSN_BUSY;
119 else if (!strcmp(status_id, "phone"))
120 msnstatus = MSN_PHONE;
121 else if (!strcmp(status_id, "lunch"))
122 msnstatus = MSN_LUNCH;
123 else if (!strcmp(status_id, "invisible"))
124 msnstatus = MSN_HIDDEN;
125 else
126 msnstatus = MSN_ONLINE;
127
128 if ((msnstatus == MSN_ONLINE) && gaim_presence_is_idle(presence))
129 msnstatus = MSN_IDLE;
130
131 return msnstatus;
132 }