6 * Copyright (C) 2011-2016 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
32 #include "sipe-backend.h"
34 #include "sipe-core.h"
35 #include "sipe-core-private.h"
37 #include "sipe-ocs2005.h"
38 #include "sipe-ocs2007.h"
39 #include "sipe-status.h"
40 #include "sipe-utils.h"
44 const gchar
*status_id
;
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)
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
;
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
,
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
;
127 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007
))
128 sipe_ocs2007_reset_status(sipe_private
);
130 sipe_ocs2005_reset_status(sipe_private
);
133 void sipe_status_and_note(struct sipe_core_private
*sipe_private
,
134 const gchar
*status_id
)
139 status_id
= sipe_private
->status
;
141 SIPE_DEBUG_INFO("sipe_status_and_note: switch to '%s' for the account", status_id
);
143 activity
= sipe_status_token_to_activity(status_id
);
144 if (sipe_backend_status_changed(SIPE_CORE_PUBLIC
,
146 sipe_private
->note
)) {
147 /* status has changed */
148 SIPE_DEBUG_INFO_NOFORMAT("sipe_status_and_note: updating backend status");
150 /* update backend status */
151 sipe_backend_status_and_note(SIPE_CORE_PUBLIC
,
157 void sipe_core_status_set(struct sipe_core_public
*sipe_public
,
158 gboolean set_by_user
,
162 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
164 const gchar
*status_id
= sipe_status_activity_to_token(activity
);
166 SIPE_DEBUG_INFO("sipe_core_status_set: status: %s (%s)",
168 set_by_user
? "USER" : "MACHINE");
170 sipe_private
->status_set_by_user
= set_by_user
;
172 sipe_status_set_token(sipe_private
, status_id
);
174 /* hack to escape apostrof before comparison */
175 tmp
= note
? sipe_utils_str_replace(note
, "'", "'") : NULL
;
177 /* this will preserve OOF flag as well */
178 if (!sipe_strequal(tmp
, sipe_private
->note
)) {
179 SIPE_CORE_PRIVATE_FLAG_UNSET(OOF_NOTE
);
180 g_free(sipe_private
->note
);
181 sipe_private
->note
= g_strdup(note
);
182 sipe_private
->note_since
= time(NULL
);
186 sipe_cal_presence_publish(sipe_private
, FALSE
);