media: also fill zero ports of active candidates
[siplcs.git] / src / core / sipe-status.c
blob0350bfeb4b68444dd7e4796997287e2cce1f16e3
1 /**
2 * @file sipe-status.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2015 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-common.h"
33 #include "sipe-backend.h"
34 #include "sipe-cal.h"
35 #include "sipe-core.h"
36 #include "sipe-core-private.h"
37 #include "sipe-nls.h"
38 #include "sipe-ocs2005.h"
39 #include "sipe-ocs2007.h"
40 #include "sipe-schedule.h"
41 #include "sipe-status.h"
42 #include "sipe-utils.h"
44 static struct
46 const gchar *status_id;
47 const gchar *desc;
48 } const sipe_activity_map[SIPE_ACTIVITY_NUM_TYPES] = {
50 * This has nothing to do with Availability numbers, like 3500 (online).
51 * Just a mapping of Communicator Activities to tokens/translations
53 /* @TODO: NULL means "default translation from Pidgin"?
54 * What about other backends? */
55 /* SIPE_ACTIVITY_UNSET */ { "unset", NULL },
56 /* SIPE_ACTIVITY_AVAILABLE */ { "available", NULL },
57 /* SIPE_ACTIVITY_ONLINE */ { "online", NULL },
58 /* SIPE_ACTIVITY_INACTIVE */ { "idle", N_("Inactive") },
59 /* SIPE_ACTIVITY_BUSY */ { "busy", N_("Busy") },
60 /* SIPE_ACTIVITY_BUSYIDLE */ { "busyidle", N_("Busy-Idle") },
61 /* SIPE_ACTIVITY_DND */ { "do-not-disturb", NULL },
62 /* SIPE_ACTIVITY_BRB */ { "be-right-back", N_("Be right back") },
63 /* SIPE_ACTIVITY_AWAY */ { "away", NULL },
64 /* SIPE_ACTIVITY_LUNCH */ { "out-to-lunch", N_("Out to lunch") },
65 /* SIPE_ACTIVITY_INVISIBLE */ { "invisible", NULL },
66 /* SIPE_ACTIVITY_OFFLINE */ { "offline", NULL },
67 /* SIPE_ACTIVITY_ON_PHONE */ { "on-the-phone", N_("In a call") },
68 /* SIPE_ACTIVITY_IN_CONF */ { "in-a-conference", N_("In a conference") },
69 /* SIPE_ACTIVITY_IN_MEETING */ { "in-a-meeting", N_("In a meeting") },
70 /* SIPE_ACTIVITY_OOF */ { "out-of-office", N_("Out of office") },
71 /* SIPE_ACTIVITY_URGENT_ONLY */ { "urgent-interruptions-only", N_("Urgent interruptions only") },
74 static GHashTable *token_map;
76 void sipe_status_init(void)
78 guint index;
80 token_map = g_hash_table_new(g_str_hash, g_str_equal);
81 for (index = SIPE_ACTIVITY_UNSET;
82 index < SIPE_ACTIVITY_NUM_TYPES;
83 index++) {
84 g_hash_table_insert(token_map,
85 (gchar *) sipe_activity_map[index].status_id,
86 GUINT_TO_POINTER(index));
90 void sipe_status_shutdown(void)
92 g_hash_table_destroy(token_map);
95 /* type == SIPE_ACTIVITY_xxx (see sipe-core.h) */
96 const gchar *sipe_status_activity_to_token(guint type)
98 return(sipe_activity_map[type].status_id);
101 guint sipe_status_token_to_activity(const gchar *token)
103 if (!token) return(SIPE_ACTIVITY_UNSET);
104 return(GPOINTER_TO_UINT(g_hash_table_lookup(token_map, token)));
107 const gchar *sipe_core_activity_description(guint type)
109 return(gettext(sipe_activity_map[type].desc));
112 void sipe_status_set_token(struct sipe_core_private *sipe_private,
113 const gchar *status_id)
115 g_free(sipe_private->status);
116 sipe_private->status = g_strdup(status_id);
119 void sipe_status_set_activity(struct sipe_core_private *sipe_private,
120 guint activity)
122 sipe_status_set_token(sipe_private,
123 sipe_status_activity_to_token(activity));
126 void sipe_core_reset_status(struct sipe_core_public *sipe_public)
128 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
129 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007))
130 sipe_ocs2007_reset_status(sipe_private);
131 else
132 sipe_ocs2005_reset_status(sipe_private);
135 void sipe_status_and_note(struct sipe_core_private *sipe_private,
136 const gchar *status_id)
138 guint activity;
140 if (!status_id)
141 status_id = sipe_private->status;
143 SIPE_DEBUG_INFO("sipe_status_and_note: switch to '%s' for the account", status_id);
145 activity = sipe_status_token_to_activity(status_id);
146 if (sipe_backend_status_changed(SIPE_CORE_PUBLIC,
147 activity,
148 sipe_private->note)) {
149 /* status has changed */
150 SIPE_DEBUG_INFO_NOFORMAT("sipe_status_and_note: updating backend status");
152 /* update backend status */
153 sipe_backend_status_and_note(SIPE_CORE_PUBLIC,
154 activity,
155 sipe_private->note);
159 void sipe_core_status_set(struct sipe_core_public *sipe_public,
160 gboolean set_by_user,
161 guint activity,
162 const gchar *note)
164 struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE;
165 gchar *tmp;
166 const gchar *status_id = sipe_status_activity_to_token(activity);
168 SIPE_DEBUG_INFO("sipe_core_status_set: status: %s (%s)",
169 status_id,
170 set_by_user ? "USER" : "MACHINE");
172 sipe_private->status_set_by_user = set_by_user;
174 sipe_status_set_token(sipe_private, status_id);
176 /* hack to escape apostrof before comparison */
177 tmp = note ? sipe_utils_str_replace(note, "'", "&apos;") : NULL;
179 /* this will preserve OOF flag as well */
180 if (!sipe_strequal(tmp, sipe_private->note)) {
181 SIPE_CORE_PRIVATE_FLAG_UNSET(OOF_NOTE);
182 g_free(sipe_private->note);
183 sipe_private->note = g_strdup(note);
184 sipe_private->note_since = time(NULL);
186 g_free(tmp);
188 sipe_cal_presence_publish(sipe_private, FALSE);
192 Local Variables:
193 mode: c
194 c-file-style: "bsd"
195 indent-tabs-mode: t
196 tab-width: 8
197 End: