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
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
,
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
) ?
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
);
62 gchar
*sipe_buddy_get_alias(struct sipe_core_private
*sipe_private
,
65 sipe_backend_buddy pbuddy
;
67 if ((pbuddy
= sipe_backend_buddy_find(SIPE_CORE_PUBLIC
, with
, NULL
))) {
68 alias
= sipe_backend_buddy_get_alias(SIPE_CORE_PUBLIC
, pbuddy
);
73 void sipe_core_buddy_group(struct sipe_core_public
*sipe_public
,
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
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
);
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
);
100 sipe_group_create(SIPE_CORE_PRIVATE
, new_group_name
, who
);
102 buddy
->groups
= slist_insert_unique_sorted(buddy
->groups
, new_group
, (GCompareFunc
)sipe_group_compare
);
103 sipe_core_group_set_user(sipe_public
, who
);