6 * Copyright (C) 2010-2013 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
33 #if PURPLE_VERSION_CHECK(3,0,0)
35 #include "buddylist.h"
39 #define purple_account_privacy_check(a, n) purple_privacy_check(a, n)
40 #define purple_account_privacy_deny_add(a, n, l) purple_privacy_deny_add(a, n, l)
41 #define purple_account_privacy_deny_remove(a, n, l) purple_privacy_deny_remove(a, n, l)
42 #define purple_blist_find_buddies(a, n) purple_find_buddies(a, n)
43 #define purple_blist_find_buddy(a, n) purple_find_buddy(a, n)
44 #define purple_blist_find_buddy_in_group(a, n, g) purple_find_buddy_in_group(a, n, g)
45 #define purple_blist_find_group(n) purple_find_group(n)
46 #define purple_buddy_set_local_alias(b, n) purple_blist_alias_buddy(b, n)
47 #define purple_buddy_set_server_alias(b, n) purple_blist_server_alias_buddy(b, n)
48 #define purple_buddy_set_name(b, n) purple_blist_rename_buddy(b, n)
49 #define purple_group_set_name(g, n) purple_blist_rename_group(g, n)
50 #define purple_notify_user_info_add_pair_html(i, k, v) purple_notify_user_info_add_pair(i, k, v)
51 #define PURPLE_IS_BUDDY(b) PURPLE_BLIST_NODE_IS_BUDDY(b)
52 #define PURPLE_IS_GROUP(b) PURPLE_BLIST_NODE_IS_GROUP(b)
55 #include "sipe-common.h"
56 #include "sipe-backend.h"
57 #include "sipe-core.h"
60 #include "purple-private.h"
63 const gchar
*property
; /* property name to store in blist.xml */
64 const gchar
*description
; /* label for "Get Info" dialog */
65 } buddy_info_map
[] = {
66 /* SIPE_BUDDY_INFO_DISPLAY_NAME */ { "alias", N_("Display name") },
67 /* SIPE_BUDDY_INFO_JOB_TITLE */ { "title", N_("Job title") },
68 /* SIPE_BUDDY_INFO_CITY */ { "address-city", N_("City") },
69 /* SIPE_BUDDY_INFO_STATE */ { "address-state", N_("State") },
70 /* SIPE_BUDDY_INFO_OFFICE */ { "office", N_("Office") },
71 /* SIPE_BUDDY_INFO_DEPARTMENT */ { "department", NULL
},
72 /* SIPE_BUDDY_INFO_COUNTRY */ { "address-country-code", N_("Country") },
73 /* SIPE_BUDDY_INFO_WORK_PHONE */ { "phone", N_("Business phone") },
74 /* SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY */ { "phone-display", NULL
},
75 /* SIPE_BUDDY_INFO_COMPANY */ { "company", N_("Company") },
76 /* SIPE_BUDDY_INFO_EMAIL */ { "email", N_("Email address") },
77 /* SIPE_BUDDY_INFO_SITE */ { "site", N_("Site") },
78 /* SIPE_BUDDY_INFO_ZIPCODE */ { "address-zipcode", NULL
},
79 /* SIPE_BUDDY_INFO_STREET */ { "address-street", NULL
},
80 /* SIPE_BUDDY_INFO_MOBILE_PHONE */ { "phone-mobile", NULL
},
81 /* SIPE_BUDDY_INFO_MOBILE_PHONE_DISPLAY */ { "phone-mobile-display", NULL
},
82 /* SIPE_BUDDY_INFO_HOME_PHONE */ { "phone-home", NULL
},
83 /* SIPE_BUDDY_INFO_HOME_PHONE_DISPLAY */ { "phone-home-display", NULL
},
84 /* SIPE_BUDDY_INFO_OTHER_PHONE */ { "phone-other", NULL
},
85 /* SIPE_BUDDY_INFO_OTHER_PHONE_DISPLAY */ { "phone-other-display", NULL
},
86 /* SIPE_BUDDY_INFO_CUSTOM1_PHONE */ { "phone-custom1", NULL
},
87 /* SIPE_BUDDY_INFO_CUSTOM1_PHONE_DISPLAY */ { "phone-custom1-display", NULL
},
88 /* SIPE_BUDDY_INFO_ALIAS */ { NULL
, N_("Alias") },
89 /* SIPE_BUDDY_INFO_DEVICE */ { NULL
, N_("Device") },
92 #define buddy_info_property(i) buddy_info_map[i].property
93 #define buddy_info_description(i) gettext(buddy_info_map[i].description)
95 sipe_backend_buddy
sipe_backend_buddy_find(struct sipe_core_public
*sipe_public
,
96 const gchar
*buddy_name
,
97 const gchar
*group_name
)
99 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
100 PurpleGroup
*purple_group
;
104 purple_group
= purple_blist_find_group(group_name
);
108 return purple_blist_find_buddy_in_group(purple_private
->account
,
112 return purple_blist_find_buddy(purple_private
->account
,
117 GSList
* sipe_backend_buddy_find_all(struct sipe_core_public
*sipe_public
,
118 const gchar
*buddy_name
,
119 const gchar
*group_name
)
121 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
125 SIPE_DEBUG_ERROR_NOFORMAT("Finding all buddies in a group not supported on purple");
129 return purple_blist_find_buddies(purple_private
->account
, buddy_name
);
132 gchar
* sipe_backend_buddy_get_name(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
133 const sipe_backend_buddy who
)
135 return g_strdup(purple_buddy_get_name((PurpleBuddy
*) who
));
138 gchar
* sipe_backend_buddy_get_alias(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
139 const sipe_backend_buddy who
)
141 return g_strdup(purple_buddy_get_alias(who
));
144 gchar
* sipe_backend_buddy_get_server_alias(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
145 const sipe_backend_buddy who
)
147 return g_strdup(purple_buddy_get_server_alias(who
));
150 gchar
*sipe_backend_buddy_get_local_alias(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
151 const sipe_backend_buddy who
)
154 #if PURPLE_VERSION_CHECK(2,6,0)
155 purple_buddy_get_local_buddy_alias(who
)
157 purple_buddy_get_local_alias(who
)
162 gchar
* sipe_backend_buddy_get_group_name(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
163 const sipe_backend_buddy who
)
165 return g_strdup(purple_group_get_name(purple_buddy_get_group((PurpleBuddy
*)who
)));
168 guint
sipe_backend_buddy_get_status(struct sipe_core_public
*sipe_public
,
171 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
172 PurpleBuddy
*pbuddy
= purple_blist_find_buddy(purple_private
->account
, uri
);
173 const PurplePresence
*presence
= purple_buddy_get_presence(pbuddy
);
174 const PurpleStatus
*pstatus
= purple_presence_get_active_status(presence
);
175 return(sipe_purple_token_to_activity(purple_status_get_id(pstatus
)));
178 void sipe_backend_buddy_set_alias(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
179 const sipe_backend_buddy who
,
182 purple_buddy_set_local_alias(who
, alias
);
185 void sipe_backend_buddy_set_server_alias(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
186 const sipe_backend_buddy who
,
189 purple_buddy_set_server_alias(who
, alias
);
192 gchar
* sipe_backend_buddy_get_string(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
193 sipe_backend_buddy buddy
,
194 const sipe_buddy_info_fields key
)
196 PurpleBuddy
*b
= (PurpleBuddy
*) buddy
;
197 return g_strdup(purple_blist_node_get_string(&b
->node
, buddy_info_property(key
)));
200 void sipe_backend_buddy_set_string(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
201 sipe_backend_buddy buddy
,
202 const sipe_buddy_info_fields key
,
205 PurpleBuddy
*b
= (PurpleBuddy
*) buddy
;
206 purple_blist_node_set_string(&b
->node
, buddy_info_property(key
), val
);
209 void sipe_backend_buddy_refresh_properties(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
210 SIPE_UNUSED_PARAMETER
const gchar
*uri
)
212 /* nothing to do here: already taken care of by libpurple */
215 void sipe_backend_buddy_list_processing_start(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
)
219 void sipe_backend_buddy_list_processing_finish(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
)
223 sipe_backend_buddy
sipe_backend_buddy_add(struct sipe_core_public
*sipe_public
,
226 const gchar
*groupname
)
228 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
230 PurpleGroup
*purple_group
= purple_blist_find_group(groupname
);
235 b
= purple_buddy_new(purple_private
->account
, name
, alias
);
236 purple_blist_add_buddy(b
, NULL
, purple_group
, NULL
);
240 void sipe_backend_buddy_remove(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
241 const sipe_backend_buddy who
)
243 purple_blist_remove_buddy(who
);
246 void sipe_backend_buddy_request_authorization(struct sipe_core_public
*sipe_public
,
250 sipe_backend_buddy_request_authorization_cb auth_cb
,
251 sipe_backend_buddy_request_authorization_cb deny_cb
,
254 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
256 purple_account_request_authorization(
257 purple_private
->account
,
263 (PurpleAccountRequestAuthorizationCb
) auth_cb
,
264 (PurpleAccountRequestAuthorizationCb
) deny_cb
,
269 void sipe_backend_buddy_request_add(struct sipe_core_public
*sipe_public
,
273 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
275 purple_account_request_add(purple_private
->account
,
283 gboolean
sipe_backend_buddy_is_blocked(struct sipe_core_public
*sipe_public
,
286 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
288 return(!purple_account_privacy_check(purple_private
->account
, who
));
291 void sipe_backend_buddy_set_blocked_status(struct sipe_core_public
*sipe_public
,
295 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
298 purple_account_privacy_deny_add(purple_private
->account
, who
, TRUE
);
300 purple_account_privacy_deny_remove(purple_private
->account
, who
, TRUE
);
303 /* stupid workaround to make pidgin re-render screen to reflect our changes */
304 SIPE_DEBUG_INFO_NOFORMAT("sipe_backend_buddy_set_blocked_status: forcefully refreshing screen.");
305 sipe_core_buddy_got_status(sipe_public
,
307 sipe_backend_buddy_get_status(sipe_public
,
311 void sipe_backend_buddy_set_status(struct sipe_core_public
*sipe_public
,
315 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
317 purple_prpl_got_user_status(purple_private
->account
, who
,
318 sipe_purple_activity_to_token(activity
),
322 gboolean
sipe_backend_uses_photo(void)
327 void sipe_backend_buddy_set_photo(struct sipe_core_public
*sipe_public
,
331 const gchar
*photo_hash
)
333 PurpleAccount
*account
= sipe_public
->backend_private
->account
;
335 purple_buddy_icons_set_for_user(account
, who
, photo_data
,
336 data_len
, photo_hash
);
339 const gchar
*sipe_backend_buddy_get_photo_hash(struct sipe_core_public
*sipe_public
,
342 PurpleAccount
*account
= sipe_public
->backend_private
->account
;
343 const gchar
*result
= NULL
;
345 PurpleBuddyIcon
*icon
= purple_buddy_icons_find(account
, who
);
347 result
= purple_buddy_icon_get_checksum(icon
);
348 purple_buddy_icon_unref(icon
);
354 gboolean
sipe_backend_buddy_group_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
355 const gchar
*group_name
)
357 PurpleGroup
* purple_group
= purple_blist_find_group(group_name
);
359 purple_group
= purple_group_new(group_name
);
360 purple_blist_add_group(purple_group
, NULL
);
363 return (purple_group
!= NULL
);
366 gboolean
sipe_backend_buddy_group_rename(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
367 const gchar
*old_name
,
368 const gchar
*new_name
)
370 PurpleGroup
*purple_group
= purple_blist_find_group(old_name
);
372 purple_group_set_name(purple_group
, new_name
);
373 return(purple_group
!= NULL
);
376 void sipe_backend_buddy_group_remove(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
377 const gchar
*group_name
)
379 PurpleGroup
*purple_group
= purple_blist_find_group(group_name
);
381 purple_blist_remove_group(purple_group
);
384 struct sipe_backend_buddy_info
*sipe_backend_buddy_info_start(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
)
386 return((struct sipe_backend_buddy_info
*)purple_notify_user_info_new());
389 void sipe_backend_buddy_info_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
390 struct sipe_backend_buddy_info
*info
,
391 sipe_buddy_info_fields key
,
395 purple_notify_user_info_add_pair_html((PurpleNotifyUserInfo
*) info
,
396 buddy_info_description(key
),
401 void sipe_backend_buddy_info_break(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
402 struct sipe_backend_buddy_info
*info
)
404 purple_notify_user_info_add_section_break((PurpleNotifyUserInfo
*) info
);
407 void sipe_backend_buddy_info_finalize(struct sipe_core_public
*sipe_public
,
408 struct sipe_backend_buddy_info
*info
,
411 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
413 /* show a buddy's user info in a nice dialog box */
414 purple_notify_userinfo(purple_private
->gc
,
415 uri
, /* buddy's URI */
416 (PurpleNotifyUserInfo
*) info
,
417 NULL
, /* callback called when dialog closed */
418 NULL
); /* userdata for callback */
421 void sipe_backend_buddy_tooltip_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
422 struct sipe_backend_buddy_tooltip
*tooltip
,
423 const gchar
*description
,
426 purple_notify_user_info_add_pair_html((PurpleNotifyUserInfo
*) tooltip
,
431 void sipe_purple_add_buddy(PurpleConnection
*gc
,
434 #if PURPLE_VERSION_CHECK(3,0,0)
435 , SIPE_UNUSED_PARAMETER
const gchar
*message
439 SIPE_DEBUG_INFO("sipe_purple_add_buddy[CB]: buddy:%s group:%s",
440 buddy
? purple_buddy_get_name(buddy
) : "",
441 group
? purple_group_get_name(group
) : "");
443 /* libpurple can call us with undefined buddy or group */
444 if (buddy
&& group
) {
446 * Buddy name must be lower case as we use
447 * purple_normalize_nocase() to compare
449 gchar
*buddy_name
= g_ascii_strdown(purple_buddy_get_name(buddy
), -1);
450 gchar
*uri
= sip_uri_if_valid(buddy_name
);
454 purple_buddy_set_name(buddy
, uri
);
457 sipe_core_buddy_add(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
458 purple_buddy_get_name(buddy
),
459 purple_group_get_name(group
));
461 SIPE_DEBUG_ERROR_NOFORMAT("sipe_purple_add_buddy[CB]: buddy name is invalid for URI");
462 purple_blist_remove_buddy(buddy
);
463 purple_notify_error(gc
, NULL
,
464 _("User name should be a valid SIP URI\nExample: user@company.com"),
466 #if PURPLE_VERSION_CHECK(3,0,0)
474 void sipe_purple_remove_buddy(PurpleConnection
*gc
,
478 SIPE_DEBUG_INFO("sipe_purple_remove_buddy[CB]: buddy: '%s' group: '%s'",
479 buddy
? purple_buddy_get_name(buddy
) : "",
480 group
? purple_group_get_name(group
) : "");
483 sipe_core_buddy_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
484 purple_buddy_get_name(buddy
),
485 group
? purple_group_get_name(group
) : NULL
);
488 void sipe_purple_group_buddy(PurpleConnection
*gc
,
490 const char *old_group_name
,
491 const char *new_group_name
)
493 sipe_core_buddy_group(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
, old_group_name
, new_group_name
);
496 /* Buddy Menu Handling */
498 static void sipe_purple_buddy_make_chat_leader_cb(PurpleBuddy
*buddy
,
501 SIPE_DEBUG_INFO("sipe_purple_buddy_make_chat_leader_cb: name '%s'",
502 purple_buddy_get_name(buddy
));
503 sipe_core_conf_make_leader(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
505 purple_buddy_get_name(buddy
));
508 static void sipe_purple_buddy_remove_from_chat_cb(PurpleBuddy
*buddy
,
511 SIPE_DEBUG_INFO("sipe_purple_buddy_remove_from_chat_cb: name '%s'",
512 purple_buddy_get_name(buddy
));
513 sipe_core_conf_remove_from(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
515 purple_buddy_get_name(buddy
));
518 static void sipe_purple_buddy_invite_to_chat_cb(PurpleBuddy
*buddy
,
521 SIPE_DEBUG_INFO("sipe_purple_buddy_invite_to_chat_cb: name '%s'",
522 purple_buddy_get_name(buddy
));
523 sipe_core_chat_invite(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
525 purple_buddy_get_name(buddy
));
528 static void sipe_purple_buddy_new_chat_cb(PurpleBuddy
*buddy
,
529 SIPE_UNUSED_PARAMETER gpointer parameter
)
531 SIPE_DEBUG_INFO("sipe_purple_buddy_new_chat_cb: name '%s'",
532 purple_buddy_get_name(buddy
));
533 sipe_core_buddy_new_chat(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
534 purple_buddy_get_name(buddy
));
537 static void sipe_purple_buddy_make_call_cb(PurpleBuddy
*buddy
,
540 SIPE_DEBUG_INFO("sipe_purple_buddy_make_call_cb: name '%s'",
541 purple_buddy_get_name(buddy
));
542 sipe_core_buddy_make_call(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
546 static void sipe_purple_buddy_send_email_cb(PurpleBuddy
*buddy
,
547 SIPE_UNUSED_PARAMETER gpointer parameter
)
549 SIPE_DEBUG_INFO("sipe_purple_buddy_send_email_cb: name '%s'",
550 purple_buddy_get_name(buddy
));
551 sipe_core_buddy_send_email(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
552 purple_buddy_get_name(buddy
));
555 static void sipe_purple_buddy_access_level_help_cb(PurpleBuddy
*buddy
,
556 SIPE_UNUSED_PARAMETER gpointer parameter
)
559 * Translators: replace with URL to localized page
560 * If it doesn't exist copy the original URL
562 purple_notify_uri(purple_account_get_connection(purple_buddy_get_account(buddy
)),
563 _("https://sourceforge.net/apps/mediawiki/sipe/index.php?title=Access_Levels"));
566 static void sipe_purple_buddy_change_access_level_cb(PurpleBuddy
*buddy
,
569 sipe_core_change_access_level_from_container(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
573 static void sipe_purple_ask_access_domain_cb(PurpleConnection
*gc
,
574 PurpleRequestFields
*fields
)
576 const gchar
*domain
= purple_request_fields_get_string(fields
, "access_domain");
578 #if PURPLE_VERSION_CHECK(3,0,0)
581 purple_request_fields_get_choice(fields
, "container_id")
582 #if PURPLE_VERSION_CHECK(3,0,0)
587 sipe_core_change_access_level_for_domain(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
592 static void sipe_purple_buddy_add_new_domain_cb(PurpleBuddy
*buddy
,
593 SIPE_UNUSED_PARAMETER gpointer parameter
)
595 PurpleAccount
*account
= purple_buddy_get_account(buddy
);
596 PurpleConnection
*gc
= purple_account_get_connection(account
);
597 PurpleRequestFields
*fields
;
598 PurpleRequestFieldGroup
*g
;
599 PurpleRequestField
*f
;
600 #if PURPLE_VERSION_CHECK(3,0,0)
601 PurpleRequestCommonParameters
*cpar
= purple_request_cpar_from_account(account
);
604 fields
= purple_request_fields_new();
606 g
= purple_request_field_group_new(NULL
);
607 f
= purple_request_field_string_new("access_domain",
609 "partner-company.com",
611 purple_request_field_set_required(f
, TRUE
);
612 purple_request_field_group_add_field(g
, f
);
614 f
= purple_request_field_choice_new("container_id",
617 #if PURPLE_VERSION_CHECK(3,0,0)
618 purple_request_field_choice_add(f
, _("Personal"), GUINT_TO_POINTER(0));
619 purple_request_field_choice_add(f
, _("Team"), GUINT_TO_POINTER(1));
620 purple_request_field_choice_add(f
, _("Company"), GUINT_TO_POINTER(2));
621 purple_request_field_choice_add(f
, _("Public"), GUINT_TO_POINTER(3));
622 purple_request_field_choice_add(f
, _("Blocked"), GUINT_TO_POINTER(4));
623 purple_request_field_choice_set_default_value(f
, GUINT_TO_POINTER(3));
625 purple_request_field_choice_add(f
, _("Personal")); /* index 0 */
626 purple_request_field_choice_add(f
, _("Team"));
627 purple_request_field_choice_add(f
, _("Company"));
628 purple_request_field_choice_add(f
, _("Public"));
629 purple_request_field_choice_add(f
, _("Blocked")); /* index 4 */
630 purple_request_field_choice_set_default_value(f
, 3); /* index */
632 purple_request_field_set_required(f
, TRUE
);
633 purple_request_field_group_add_field(g
, f
);
635 purple_request_fields_add_group(fields
, g
);
637 purple_request_fields(gc
, _("Add new domain"),
638 _("Add new domain"), NULL
, fields
,
639 _("Add"), G_CALLBACK(sipe_purple_ask_access_domain_cb
),
641 #if PURPLE_VERSION_CHECK(3,0,0)
643 purple_request_cpar_unref(cpar
);
645 account
, NULL
, NULL
, gc
);
649 typedef void (*buddy_menu_callback
)(PurpleBuddy
*buddy
,
651 static const buddy_menu_callback callback_map
[SIPE_BUDDY_MENU_TYPES
] = {
652 /* SIPE_BUDDY_MENU_MAKE_CHAT_LEADER */ sipe_purple_buddy_make_chat_leader_cb
,
653 /* SIPE_BUDDY_MENU_REMOVE_FROM_CHAT */ sipe_purple_buddy_remove_from_chat_cb
,
654 /* SIPE_BUDDY_MENU_INVITE_TO_CHAT */ sipe_purple_buddy_invite_to_chat_cb
,
655 /* SIPE_BUDDY_MENU_NEW_CHAT */ sipe_purple_buddy_new_chat_cb
,
656 /* SIPE_BUDDY_MENU_MAKE_CALL */ sipe_purple_buddy_make_call_cb
,
657 /* SIPE_BUDDY_MENU_SEND_EMAIL */ sipe_purple_buddy_send_email_cb
,
658 /* SIPE_BUDDY_MENU_ACCESS_LEVEL_HELP */ sipe_purple_buddy_access_level_help_cb
,
659 /* SIPE_BUDDY_MENU_CHANGE_ACCESS_LEVEL */ sipe_purple_buddy_change_access_level_cb
,
660 /* SIPE_BUDDY_MENU_ADD_NEW_DOMAIN */ sipe_purple_buddy_add_new_domain_cb
,
663 struct sipe_backend_buddy_menu
*sipe_backend_buddy_menu_start(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
)
668 struct sipe_backend_buddy_menu
*sipe_backend_buddy_menu_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
669 struct sipe_backend_buddy_menu
*menu
,
671 enum sipe_buddy_menu_type type
,
674 return((struct sipe_backend_buddy_menu
*)
675 g_list_prepend((GList
*) menu
,
676 purple_menu_action_new(label
,
677 PURPLE_CALLBACK(callback_map
[type
]),
681 struct sipe_backend_buddy_menu
*sipe_backend_buddy_menu_separator(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
682 struct sipe_backend_buddy_menu
*menu
,
685 return((struct sipe_backend_buddy_menu
*)
686 g_list_prepend((GList
*) menu
,
687 purple_menu_action_new(label
, NULL
, NULL
, NULL
)));
690 struct sipe_backend_buddy_menu
*sipe_backend_buddy_sub_menu_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
691 struct sipe_backend_buddy_menu
*menu
,
693 struct sipe_backend_buddy_menu
*sub
)
695 return((struct sipe_backend_buddy_menu
*)
696 g_list_prepend((GList
*) menu
,
697 purple_menu_action_new(label
,
700 g_list_reverse((GList
*) sub
))));
703 static void sipe_purple_buddy_copy_to_cb(PurpleBlistNode
*node
,
704 const gchar
*group_name
)
706 struct sipe_core_public
*sipe_public
;
707 PurpleBuddy
*buddy
= (PurpleBuddy
*)node
;
711 g_return_if_fail(PURPLE_IS_BUDDY(node
));
713 sipe_public
= PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
;
714 group
= purple_blist_find_group(group_name
);
716 SIPE_DEBUG_INFO("sipe_purple_buddy_copy_to_cb: copying %s to %s",
717 purple_buddy_get_name(buddy
), group_name
);
719 clone
= purple_blist_find_buddy_in_group(purple_buddy_get_account(buddy
),
720 purple_buddy_get_name(buddy
),
723 clone
= sipe_backend_buddy_add(sipe_public
,
724 purple_buddy_get_name(buddy
),
725 #if PURPLE_VERSION_CHECK(3,0,0)
726 purple_buddy_get_local_alias(buddy
),
730 purple_group_get_name(group
));
734 const PurpleStatus
*status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
736 tmp
= purple_buddy_get_server_alias(buddy
);
737 if (tmp
) purple_buddy_set_server_alias(clone
, tmp
);
739 key
= buddy_info_property(SIPE_BUDDY_INFO_EMAIL
);
740 tmp
= purple_blist_node_get_string(&buddy
->node
, key
);
741 if (tmp
) purple_blist_node_set_string(&clone
->node
,
745 tmp
= purple_status_get_id(status
);
746 purple_presence_set_status_active(purple_buddy_get_presence(clone
),
751 purple_prpl_got_user_status(purple_buddy_get_account(clone
),
752 purple_buddy_get_name(clone
),
759 sipe_core_buddy_add(sipe_public
,
760 purple_buddy_get_name(clone
),
761 purple_group_get_name(group
));
764 static GList
*sipe_purple_copy_to_menu(GList
*menu
,
767 GList
*menu_groups
= NULL
;
768 PurpleGroup
*gr_parent
= purple_buddy_get_group(buddy
);
769 PurpleBlistNode
*g_node
;
771 for (g_node
= purple_blist_get_root(); g_node
; g_node
= g_node
->next
) {
772 PurpleGroup
*group
= (PurpleGroup
*)g_node
;
773 PurpleMenuAction
*act
;
775 if ((PURPLE_IS_GROUP(g_node
)) ||
776 (group
== gr_parent
) ||
777 purple_blist_find_buddy_in_group(purple_buddy_get_account(buddy
),
778 purple_buddy_get_name(buddy
),
782 act
= purple_menu_action_new(purple_group_get_name(group
),
783 PURPLE_CALLBACK(sipe_purple_buddy_copy_to_cb
),
784 (gpointer
) purple_group_get_name(group
),
786 menu_groups
= g_list_prepend(menu_groups
, act
);
790 menu
= g_list_prepend(menu
,
791 purple_menu_action_new(_("Copy to"),
794 g_list_reverse(menu_groups
)));
799 GList
*sipe_purple_buddy_menu(PurpleBuddy
*buddy
)
801 struct sipe_core_public
*sipe_public
= PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
;
802 GList
*menu
= (GList
*) sipe_core_buddy_create_menu(sipe_public
,
803 purple_buddy_get_name(buddy
),
805 menu
= sipe_purple_copy_to_menu(menu
, buddy
);
806 return(g_list_reverse(menu
));