adium: clean up paths in xcconfigs
[siplcs.git] / src / core / sipe-status.c
bloba94083caa2d592bb86d141640002d7121ad51c4c
1 /**
2 * @file sipe-status.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2017 SIPE Project <http://sipe.sourceforge.net/>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #include <time.h>
30 #include <glib.h>
32 #include "sipe-backend.h"
33 #include "sipe-cal.h"
34 #include "sipe-core.h"
35 #include "sipe-core-private.h"
36 #include "sipe-nls.h"
37 #include "sipe-ocs2005.h"
38 #include "sipe-ocs2007.h"
39 #include "sipe-status.h"
40 #include "sipe-utils.h"
42 static struct
44 const gchar *status_id;
45 const gchar *desc;
46 } const sipe_activity_map[SIPE_ACTIVITY_NUM_TYPES] = {
48 * This has nothing to do with Availability numbers, like 3500 (online).
49 * Just a mapping of Communicator Activities to tokens/translations
51 /* @TODO: NULL means "default translation from Pidgin"?
52 * What about other backends? */
53 /* SIPE_ACTIVITY_UNSET */ { "unset", NULL },
54 /* SIPE_ACTIVITY_AVAILABLE */ { "available", NULL },
55 /* SIPE_ACTIVITY_ONLINE */ { "online", NULL },
56 /* SIPE_ACTIVITY_INACTIVE */ { "idle", N_("Inactive") },
57 /* SIPE_ACTIVITY_BUSY */ { "busy", N_("Busy") },
58 /* SIPE_ACTIVITY_BUSYIDLE */ { "busyidle", N_("Busy-Idle") },
59 /* SIPE_ACTIVITY_DND */ { "do-not-disturb", NULL },
60 /* SIPE_ACTIVITY_BRB */ { "be-right-back", N_("Be right back") },
61 /* SIPE_ACTIVITY_AWAY */ { "away", NULL },
62 /* SIPE_ACTIVITY_LUNCH */ { "out-to-lunch", N_("Out to lunch") },
63 /* SIPE_ACTIVITY_INVISIBLE */ { "invisible", NULL },
64 /* SIPE_ACTIVITY_OFFLINE */ { "offline", NULL },
65 /* SIPE_ACTIVITY_ON_PHONE */ { "on-the-phone", N_("In a call") },
66 /* SIPE_ACTIVITY_IN_CONF */ { "in-a-conference", N_("In a conference") },
67 /* SIPE_ACTIVITY_IN_MEETING */ { "in-a-meeting", N_("In a meeting") },
68 /* SIPE_ACTIVITY_OOF */ { "out-of-office", N_("Out of office") },
69 /* SIPE_ACTIVITY_URGENT_ONLY */ { "urgent-interruptions-only", N_("Urgent interruptions only") },
72 static GHashTable *token_map;
74 void sipe_status_init(void)
76 guint index;
78 token_map = g_hash_table_new(g_str_hash, g_str_equal);
79 for (index = SIPE_ACTIVITY_UNSET;
80 index < SIPE_ACTIVITY_NUM_TYPES;
81 index++) {
82 g_hash_table_insert(token_map,
83 (gchar *) sipe_activity_map[index].status_id,
84 GUINT_TO_POINTER(index));
88 void sipe_status_shutdown(void)
90 g_hash_table_destroy(token_map);
93 /* type == SIPE_ACTIVITY_xxx (see sipe-core.h) */
94 const gchar *sipe_status_activity_to_token(guint type)
96 return(sipe_activity_map[type].status_id);
99 guint sipe_status_token_to_activity(const gchar *token)
101 if (!token) return(SIPE_ACTIVITY_UNSET);
102 return(GPOINTER_TO_UINT(g_hash_table_lookup(token_map, token)));
105 const gchar *sipe_core_activity_description(guint type)
107 return(gettext(sipe_activity_map[type].desc));
110 void sipe_status_set_token(struct sipe_core_private *sipe_private,
111 const gchar *status_id)
113 g_free(sipe_private->status);
114 sipe_private->status = g_strdup(status_id);
117 void sipe_status_set_activity(struct sipe_core_private *sipe_private,
118 guint activity)
120 sipe_status_set_token(sipe_private,
121 sipe_status_activity_to_token(activity));
124 void sipe_core_reset_status(struct sipe_core_public *sipe_public)
126 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
128 SIPE_DEBUG_INFO_NOFORMAT("sipe_core_reset_status: start");
130 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007))
131 sipe_ocs2007_reset_status(sipe_private);
132 else
133 sipe_ocs2005_reset_status(sipe_private);
136 void sipe_status_and_note(struct sipe_core_private *sipe_private,
137 const gchar *status_id)
139 guint activity;
141 if (!status_id)
142 status_id = sipe_private->status;
144 SIPE_DEBUG_INFO("sipe_status_and_note: switch to '%s' for the account", status_id);
146 activity = sipe_status_token_to_activity(status_id);
147 if (sipe_backend_status_changed(SIPE_CORE_PUBLIC,
148 activity,
149 sipe_private->note)) {
150 /* status has changed */
151 SIPE_DEBUG_INFO_NOFORMAT("sipe_status_and_note: updating backend status");
153 /* update backend status */
154 sipe_backend_status_and_note(SIPE_CORE_PUBLIC,
155 activity,
156 sipe_private->note);
160 void sipe_core_status_set(struct sipe_core_public *sipe_public,
161 gboolean set_by_user,
162 guint activity,
163 const gchar *note)
165 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
166 gchar *tmp;
167 const gchar *status_id = sipe_status_activity_to_token(activity);
169 SIPE_DEBUG_INFO("sipe_core_status_set: status: %s (%s)",
170 status_id,
171 set_by_user ? "USER" : "MACHINE");
173 sipe_private->status_set_by_user = set_by_user;
175 sipe_status_set_token(sipe_private, status_id);
177 /* hack to escape apostrof before comparison */
178 tmp = note ? sipe_utils_str_replace(note, "'", "&apos;") : NULL;
180 /* this will preserve OOF flag as well */
181 if (!sipe_strequal(tmp, sipe_private->note)) {
182 SIPE_CORE_PRIVATE_FLAG_UNSET(OOF_NOTE);
183 g_free(sipe_private->note);
184 sipe_private->note = g_strdup(note);
185 sipe_private->note_since = time(NULL);
187 g_free(tmp);
189 sipe_cal_presence_publish(sipe_private, FALSE);
193 Local Variables:
194 mode: c
195 c-file-style: "bsd"
196 indent-tabs-mode: t
197 tab-width: 8
198 End: