tls: internalize state handling
[siplcs.git] / src / core / sipe-buddy.c
blob7fbfd3f393af774a856a538f88ee6e55037c7234
1 /**
2 * @file sipe-buddy.c
4 * pidgin-sipe
6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <time.h>
25 #include <glib.h>
27 #include "sipe-backend.h"
28 #include "sipe-buddy.h"
29 #include "sipe-core.h"
30 #include "sipe-core-private.h"
31 #include "sipe-group.h"
32 #include "sipe-utils.h"
34 gchar *sipe_core_buddy_status(struct sipe_core_public *sipe_public,
35 const gchar *name,
36 const sipe_activity activity,
37 const gchar *status_text)
39 struct sipe_buddy *sbuddy;
40 const char *activity_str;
42 if (!sipe_public) return NULL; /* happens on pidgin exit */
44 sbuddy = g_hash_table_lookup(SIPE_CORE_PRIVATE->buddies, name);
45 if (!sbuddy) return NULL;
47 activity_str = sbuddy->activity ? sbuddy->activity :
48 (activity == SIPE_ACTIVITY_BUSY) || (activity == SIPE_ACTIVITY_BRB) ?
49 status_text : NULL;
51 if (activity_str && sbuddy->note) {
52 return g_strdup_printf("%s - <i>%s</i>", activity_str, sbuddy->note);
53 } else if (activity_str) {
54 return g_strdup(activity_str);
55 } else if (sbuddy->note) {
56 return g_strdup_printf("<i>%s</i>", sbuddy->note);
57 } else {
58 return NULL;
62 gchar *sipe_buddy_get_alias(struct sipe_core_private *sipe_private,
63 const gchar *with)
65 sipe_backend_buddy pbuddy;
66 gchar *alias = NULL;
67 if ((pbuddy = sipe_backend_buddy_find(SIPE_CORE_PUBLIC, with, NULL))) {
68 alias = sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC, pbuddy);
70 return alias;
73 void sipe_core_buddy_group(struct sipe_core_public *sipe_public,
74 const gchar *who,
75 const gchar *old_group_name,
76 const gchar *new_group_name)
78 struct sipe_buddy * buddy = g_hash_table_lookup(SIPE_CORE_PRIVATE->buddies, who);
79 struct sipe_group * old_group = NULL;
80 struct sipe_group * new_group;
82 SIPE_DEBUG_INFO("sipe_group_buddy[CB]: who:%s old_group_name:%s new_group_name:%s",
83 who ? who : "", old_group_name ? old_group_name : "", new_group_name ? new_group_name : "");
85 if(!buddy) { // buddy not in roaming list
86 return;
89 if (old_group_name) {
90 old_group = sipe_group_find_by_name(SIPE_CORE_PRIVATE, old_group_name);
92 new_group = sipe_group_find_by_name(SIPE_CORE_PRIVATE, new_group_name);
94 if (old_group) {
95 buddy->groups = g_slist_remove(buddy->groups, old_group);
96 SIPE_DEBUG_INFO("buddy %s removed from old group %s", who, old_group_name);
99 if (!new_group) {
100 sipe_group_create(SIPE_CORE_PRIVATE, new_group_name, who);
101 } else {
102 buddy->groups = slist_insert_unique_sorted(buddy->groups, new_group, (GCompareFunc)sipe_group_compare);
103 sipe_core_group_set_user(sipe_public, who);
108 Local Variables:
109 mode: c
110 c-file-style: "bsd"
111 indent-tabs-mode: t
112 tab-width: 8
113 End: