6 * Copyright (C) 2010-2014 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
;
316 PurpleBuddy
*buddy
= NULL
;
317 PurpleStatus
*status
= NULL
;
320 buddy
= purple_blist_find_buddy(purple_private
->account
, who
);
322 status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
325 tmp
= sipe_core_buddy_status(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
326 purple_buddy_get_name(buddy
),
327 sipe_purple_token_to_activity(purple_status_get_id(status
)),
328 purple_status_get_name(status
));
331 purple_prpl_got_user_status(purple_private
->account
, who
,
332 sipe_purple_activity_to_token(activity
),
333 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE
, tmp
,
337 purple_prpl_got_user_status(purple_private
->account
, who
,
338 sipe_purple_activity_to_token(activity
),
342 gboolean
sipe_backend_uses_photo(void)
347 void sipe_backend_buddy_set_photo(struct sipe_core_public
*sipe_public
,
351 const gchar
*photo_hash
)
353 PurpleAccount
*account
= sipe_public
->backend_private
->account
;
355 purple_buddy_icons_set_for_user(account
, who
, photo_data
,
356 data_len
, photo_hash
);
359 const gchar
*sipe_backend_buddy_get_photo_hash(struct sipe_core_public
*sipe_public
,
362 PurpleAccount
*account
= sipe_public
->backend_private
->account
;
363 const gchar
*result
= NULL
;
365 PurpleBuddyIcon
*icon
= purple_buddy_icons_find(account
, who
);
367 result
= purple_buddy_icon_get_checksum(icon
);
368 purple_buddy_icon_unref(icon
);
374 gboolean
sipe_backend_buddy_group_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
375 const gchar
*group_name
)
377 PurpleGroup
* purple_group
= purple_blist_find_group(group_name
);
379 purple_group
= purple_group_new(group_name
);
380 purple_blist_add_group(purple_group
, NULL
);
383 return (purple_group
!= NULL
);
386 gboolean
sipe_backend_buddy_group_rename(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
387 const gchar
*old_name
,
388 const gchar
*new_name
)
390 PurpleGroup
*purple_group
= purple_blist_find_group(old_name
);
392 purple_group_set_name(purple_group
, new_name
);
393 return(purple_group
!= NULL
);
396 void sipe_backend_buddy_group_remove(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
397 const gchar
*group_name
)
399 PurpleGroup
*purple_group
= purple_blist_find_group(group_name
);
401 purple_blist_remove_group(purple_group
);
404 struct sipe_backend_buddy_info
*sipe_backend_buddy_info_start(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
)
406 return((struct sipe_backend_buddy_info
*)purple_notify_user_info_new());
409 void sipe_backend_buddy_info_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
410 struct sipe_backend_buddy_info
*info
,
411 sipe_buddy_info_fields key
,
415 purple_notify_user_info_add_pair_html((PurpleNotifyUserInfo
*) info
,
416 buddy_info_description(key
),
421 void sipe_backend_buddy_info_break(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
422 struct sipe_backend_buddy_info
*info
)
424 purple_notify_user_info_add_section_break((PurpleNotifyUserInfo
*) info
);
427 void sipe_backend_buddy_info_finalize(struct sipe_core_public
*sipe_public
,
428 struct sipe_backend_buddy_info
*info
,
431 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
433 /* show a buddy's user info in a nice dialog box */
434 purple_notify_userinfo(purple_private
->gc
,
435 uri
, /* buddy's URI */
436 (PurpleNotifyUserInfo
*) info
,
437 NULL
, /* callback called when dialog closed */
438 NULL
); /* userdata for callback */
441 void sipe_backend_buddy_tooltip_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
442 struct sipe_backend_buddy_tooltip
*tooltip
,
443 const gchar
*description
,
446 purple_notify_user_info_add_pair_html((PurpleNotifyUserInfo
*) tooltip
,
451 void sipe_purple_add_buddy(PurpleConnection
*gc
,
454 #if PURPLE_VERSION_CHECK(3,0,0)
455 , SIPE_UNUSED_PARAMETER
const gchar
*message
459 SIPE_DEBUG_INFO("sipe_purple_add_buddy[CB]: buddy:%s group:%s",
460 buddy
? purple_buddy_get_name(buddy
) : "",
461 group
? purple_group_get_name(group
) : "");
463 /* libpurple can call us with undefined buddy or group */
464 if (buddy
&& group
) {
466 * Buddy name must be lower case as we use
467 * purple_normalize_nocase() to compare
469 gchar
*buddy_name
= g_ascii_strdown(purple_buddy_get_name(buddy
), -1);
470 gchar
*uri
= sip_uri_if_valid(buddy_name
);
474 purple_buddy_set_name(buddy
, uri
);
477 sipe_core_buddy_add(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
478 purple_buddy_get_name(buddy
),
479 purple_group_get_name(group
));
481 SIPE_DEBUG_ERROR_NOFORMAT("sipe_purple_add_buddy[CB]: buddy name is invalid for URI");
482 purple_blist_remove_buddy(buddy
);
483 purple_notify_error(gc
, NULL
,
484 _("User name should be a valid SIP URI\nExample: user@company.com"),
486 #if PURPLE_VERSION_CHECK(3,0,0)
494 void sipe_purple_remove_buddy(PurpleConnection
*gc
,
498 SIPE_DEBUG_INFO("sipe_purple_remove_buddy[CB]: buddy: '%s' group: '%s'",
499 buddy
? purple_buddy_get_name(buddy
) : "",
500 group
? purple_group_get_name(group
) : "");
503 sipe_core_buddy_remove(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
504 purple_buddy_get_name(buddy
),
505 group
? purple_group_get_name(group
) : NULL
);
508 void sipe_purple_group_buddy(PurpleConnection
*gc
,
510 const char *old_group_name
,
511 const char *new_group_name
)
513 sipe_core_buddy_group(PURPLE_GC_TO_SIPE_CORE_PUBLIC
, who
, old_group_name
, new_group_name
);
516 /* Buddy Menu Handling */
518 static void sipe_purple_buddy_make_chat_leader_cb(PurpleBuddy
*buddy
,
521 SIPE_DEBUG_INFO("sipe_purple_buddy_make_chat_leader_cb: name '%s'",
522 purple_buddy_get_name(buddy
));
523 sipe_core_conf_make_leader(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
525 purple_buddy_get_name(buddy
));
528 static void sipe_purple_buddy_remove_from_chat_cb(PurpleBuddy
*buddy
,
531 SIPE_DEBUG_INFO("sipe_purple_buddy_remove_from_chat_cb: name '%s'",
532 purple_buddy_get_name(buddy
));
533 sipe_core_conf_remove_from(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
535 purple_buddy_get_name(buddy
));
538 static void sipe_purple_buddy_invite_to_chat_cb(PurpleBuddy
*buddy
,
541 SIPE_DEBUG_INFO("sipe_purple_buddy_invite_to_chat_cb: name '%s'",
542 purple_buddy_get_name(buddy
));
543 sipe_core_chat_invite(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
545 purple_buddy_get_name(buddy
));
548 static void sipe_purple_buddy_new_chat_cb(PurpleBuddy
*buddy
,
549 SIPE_UNUSED_PARAMETER gpointer parameter
)
551 SIPE_DEBUG_INFO("sipe_purple_buddy_new_chat_cb: name '%s'",
552 purple_buddy_get_name(buddy
));
553 sipe_core_buddy_new_chat(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
554 purple_buddy_get_name(buddy
));
557 static void sipe_purple_buddy_make_call_cb(PurpleBuddy
*buddy
,
560 SIPE_DEBUG_INFO("sipe_purple_buddy_make_call_cb: name '%s'",
561 purple_buddy_get_name(buddy
));
562 sipe_core_buddy_make_call(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
566 static void sipe_purple_buddy_send_email_cb(PurpleBuddy
*buddy
,
567 SIPE_UNUSED_PARAMETER gpointer parameter
)
569 SIPE_DEBUG_INFO("sipe_purple_buddy_send_email_cb: name '%s'",
570 purple_buddy_get_name(buddy
));
571 sipe_core_buddy_send_email(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
572 purple_buddy_get_name(buddy
));
575 static void sipe_purple_buddy_access_level_help_cb(PurpleBuddy
*buddy
,
576 SIPE_UNUSED_PARAMETER gpointer parameter
)
579 * Translators: replace with URL to localized page
580 * If it doesn't exist copy the original URL
582 purple_notify_uri(purple_account_get_connection(purple_buddy_get_account(buddy
)),
583 _("https://sourceforge.net/apps/mediawiki/sipe/index.php?title=Access_Levels"));
586 static void sipe_purple_buddy_change_access_level_cb(PurpleBuddy
*buddy
,
589 sipe_core_change_access_level_from_container(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
,
593 static void sipe_purple_ask_access_domain_cb(PurpleConnection
*gc
,
594 PurpleRequestFields
*fields
)
596 const gchar
*domain
= purple_request_fields_get_string(fields
, "access_domain");
598 #if PURPLE_VERSION_CHECK(3,0,0)
601 purple_request_fields_get_choice(fields
, "container_id")
602 #if PURPLE_VERSION_CHECK(3,0,0)
607 sipe_core_change_access_level_for_domain(PURPLE_GC_TO_SIPE_CORE_PUBLIC
,
612 static void sipe_purple_buddy_add_new_domain_cb(PurpleBuddy
*buddy
,
613 SIPE_UNUSED_PARAMETER gpointer parameter
)
615 PurpleAccount
*account
= purple_buddy_get_account(buddy
);
616 PurpleConnection
*gc
= purple_account_get_connection(account
);
617 PurpleRequestFields
*fields
;
618 PurpleRequestFieldGroup
*g
;
619 PurpleRequestField
*f
;
621 fields
= purple_request_fields_new();
623 g
= purple_request_field_group_new(NULL
);
624 f
= purple_request_field_string_new("access_domain",
626 "partner-company.com",
628 purple_request_field_set_required(f
, TRUE
);
629 purple_request_field_group_add_field(g
, f
);
631 f
= purple_request_field_choice_new("container_id",
634 #if PURPLE_VERSION_CHECK(3,0,0)
635 purple_request_field_choice_add(f
, _("Personal"), GUINT_TO_POINTER(0));
636 purple_request_field_choice_add(f
, _("Team"), GUINT_TO_POINTER(1));
637 purple_request_field_choice_add(f
, _("Company"), GUINT_TO_POINTER(2));
638 purple_request_field_choice_add(f
, _("Public"), GUINT_TO_POINTER(3));
639 purple_request_field_choice_add(f
, _("Blocked"), GUINT_TO_POINTER(4));
640 purple_request_field_choice_set_default_value(f
, GUINT_TO_POINTER(3));
642 purple_request_field_choice_add(f
, _("Personal")); /* index 0 */
643 purple_request_field_choice_add(f
, _("Team"));
644 purple_request_field_choice_add(f
, _("Company"));
645 purple_request_field_choice_add(f
, _("Public"));
646 purple_request_field_choice_add(f
, _("Blocked")); /* index 4 */
647 purple_request_field_choice_set_default_value(f
, 3); /* index */
649 purple_request_field_set_required(f
, TRUE
);
650 purple_request_field_group_add_field(g
, f
);
652 purple_request_fields_add_group(fields
, g
);
654 purple_request_fields(gc
, _("Add new domain"),
655 _("Add new domain"), NULL
, fields
,
656 _("Add"), G_CALLBACK(sipe_purple_ask_access_domain_cb
),
658 #if PURPLE_VERSION_CHECK(3,0,0)
659 purple_request_cpar_from_account(account
),
666 typedef void (*buddy_menu_callback
)(PurpleBuddy
*buddy
,
668 static const buddy_menu_callback callback_map
[SIPE_BUDDY_MENU_TYPES
] = {
669 /* SIPE_BUDDY_MENU_MAKE_CHAT_LEADER */ sipe_purple_buddy_make_chat_leader_cb
,
670 /* SIPE_BUDDY_MENU_REMOVE_FROM_CHAT */ sipe_purple_buddy_remove_from_chat_cb
,
671 /* SIPE_BUDDY_MENU_INVITE_TO_CHAT */ sipe_purple_buddy_invite_to_chat_cb
,
672 /* SIPE_BUDDY_MENU_NEW_CHAT */ sipe_purple_buddy_new_chat_cb
,
673 /* SIPE_BUDDY_MENU_MAKE_CALL */ sipe_purple_buddy_make_call_cb
,
674 /* SIPE_BUDDY_MENU_SEND_EMAIL */ sipe_purple_buddy_send_email_cb
,
675 /* SIPE_BUDDY_MENU_ACCESS_LEVEL_HELP */ sipe_purple_buddy_access_level_help_cb
,
676 /* SIPE_BUDDY_MENU_CHANGE_ACCESS_LEVEL */ sipe_purple_buddy_change_access_level_cb
,
677 /* SIPE_BUDDY_MENU_ADD_NEW_DOMAIN */ sipe_purple_buddy_add_new_domain_cb
,
680 struct sipe_backend_buddy_menu
*sipe_backend_buddy_menu_start(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
)
685 struct sipe_backend_buddy_menu
*sipe_backend_buddy_menu_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
686 struct sipe_backend_buddy_menu
*menu
,
688 enum sipe_buddy_menu_type type
,
691 return((struct sipe_backend_buddy_menu
*)
692 g_list_prepend((GList
*) menu
,
693 purple_menu_action_new(label
,
694 PURPLE_CALLBACK(callback_map
[type
]),
698 struct sipe_backend_buddy_menu
*sipe_backend_buddy_menu_separator(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
699 struct sipe_backend_buddy_menu
*menu
,
702 return((struct sipe_backend_buddy_menu
*)
703 g_list_prepend((GList
*) menu
,
704 purple_menu_action_new(label
, NULL
, NULL
, NULL
)));
707 struct sipe_backend_buddy_menu
*sipe_backend_buddy_sub_menu_add(SIPE_UNUSED_PARAMETER
struct sipe_core_public
*sipe_public
,
708 struct sipe_backend_buddy_menu
*menu
,
710 struct sipe_backend_buddy_menu
*sub
)
712 return((struct sipe_backend_buddy_menu
*)
713 g_list_prepend((GList
*) menu
,
714 purple_menu_action_new(label
,
717 g_list_reverse((GList
*) sub
))));
720 static void sipe_purple_buddy_copy_to_cb(PurpleBlistNode
*node
,
721 const gchar
*group_name
)
723 struct sipe_core_public
*sipe_public
;
724 PurpleBuddy
*buddy
= (PurpleBuddy
*)node
;
728 g_return_if_fail(PURPLE_IS_BUDDY(node
));
730 sipe_public
= PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
;
731 group
= purple_blist_find_group(group_name
);
733 SIPE_DEBUG_INFO("sipe_purple_buddy_copy_to_cb: copying %s to %s",
734 purple_buddy_get_name(buddy
), group_name
);
736 clone
= purple_blist_find_buddy_in_group(purple_buddy_get_account(buddy
),
737 purple_buddy_get_name(buddy
),
740 clone
= sipe_backend_buddy_add(sipe_public
,
741 purple_buddy_get_name(buddy
),
742 #if PURPLE_VERSION_CHECK(3,0,0)
743 purple_buddy_get_local_alias(buddy
),
747 purple_group_get_name(group
));
751 const PurpleStatus
*status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
753 tmp
= purple_buddy_get_server_alias(buddy
);
754 if (tmp
) purple_buddy_set_server_alias(clone
, tmp
);
756 key
= buddy_info_property(SIPE_BUDDY_INFO_EMAIL
);
757 tmp
= purple_blist_node_get_string(&buddy
->node
, key
);
758 if (tmp
) purple_blist_node_set_string(&clone
->node
,
762 tmp
= purple_status_get_id(status
);
763 purple_presence_set_status_active(purple_buddy_get_presence(clone
),
768 purple_prpl_got_user_status(purple_buddy_get_account(clone
),
769 purple_buddy_get_name(clone
),
771 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE
, tmp
,
777 sipe_core_buddy_add(sipe_public
,
778 purple_buddy_get_name(clone
),
779 purple_group_get_name(group
));
782 static GList
*sipe_purple_copy_to_menu(GList
*menu
,
785 GList
*menu_groups
= NULL
;
786 PurpleGroup
*gr_parent
= purple_buddy_get_group(buddy
);
787 PurpleBlistNode
*g_node
;
789 for (g_node
= purple_blist_get_root(); g_node
; g_node
= g_node
->next
) {
790 PurpleGroup
*group
= (PurpleGroup
*)g_node
;
791 PurpleMenuAction
*act
;
793 if ((!PURPLE_IS_GROUP(g_node
)) ||
794 (group
== gr_parent
) ||
795 purple_blist_find_buddy_in_group(purple_buddy_get_account(buddy
),
796 purple_buddy_get_name(buddy
),
800 act
= purple_menu_action_new(purple_group_get_name(group
),
801 PURPLE_CALLBACK(sipe_purple_buddy_copy_to_cb
),
802 (gpointer
) purple_group_get_name(group
),
804 menu_groups
= g_list_prepend(menu_groups
, act
);
808 menu
= g_list_prepend(menu
,
809 purple_menu_action_new(_("Copy to"),
812 g_list_reverse(menu_groups
)));
817 GList
*sipe_purple_buddy_menu(PurpleBuddy
*buddy
)
819 struct sipe_core_public
*sipe_public
= PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC
;
820 GList
*menu
= (GList
*) sipe_core_buddy_create_menu(sipe_public
,
821 purple_buddy_get_name(buddy
),
823 menu
= sipe_purple_copy_to_menu(menu
, buddy
);
824 return(g_list_reverse(menu
));