Merge branch 'mob' of git+ssh://repo.or.cz/srv/git/siplcs into mob
[siplcs.git] / src / purple / purple-buddy.c
blob9159c506a7e51a4a3dbc8e7e0795e76d43109289
1 /**
2 * @file purple-buddy.c
4 * pidgin-sipe
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
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <glib.h>
29 #include "notify.h"
30 #include "request.h"
32 #include "version.h"
33 #if PURPLE_VERSION_CHECK(3,0,0)
34 #include "account.h"
35 #include "buddylist.h"
36 #else
37 #include "blist.h"
38 #include "privacy.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)
53 #endif
55 #include "sipe-common.h"
56 #include "sipe-backend.h"
57 #include "sipe-core.h"
58 #include "sipe-nls.h"
60 #include "purple-private.h"
62 static const struct {
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;
102 if (group_name)
104 purple_group = purple_blist_find_group(group_name);
105 if (!purple_group)
106 return NULL;
108 return purple_blist_find_buddy_in_group(purple_private->account,
109 buddy_name,
110 purple_group);
111 } else {
112 return purple_blist_find_buddy(purple_private->account,
113 buddy_name);
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;
123 if (group_name)
125 SIPE_DEBUG_ERROR_NOFORMAT("Finding all buddies in a group not supported on purple");
126 return NULL;
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)
153 return g_strdup(
154 #if PURPLE_VERSION_CHECK(2,6,0)
155 purple_buddy_get_local_buddy_alias(who)
156 #else
157 purple_buddy_get_local_alias(who)
158 #endif
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,
169 const gchar *uri)
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,
180 const gchar *alias)
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,
187 const gchar *alias)
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,
203 const gchar *val)
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,
224 const gchar *name,
225 const gchar *alias,
226 const gchar *groupname)
228 struct sipe_backend_private *purple_private = sipe_public->backend_private;
229 PurpleBuddy *b;
230 PurpleGroup *purple_group = purple_blist_find_group(groupname);
232 if (!purple_group)
233 return NULL;
235 b = purple_buddy_new(purple_private->account, name, alias);
236 purple_blist_add_buddy(b, NULL, purple_group, NULL);
237 return b;
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,
247 const gchar *who,
248 const gchar *alias,
249 gboolean on_list,
250 sipe_backend_buddy_request_authorization_cb auth_cb,
251 sipe_backend_buddy_request_authorization_cb deny_cb,
252 gpointer data)
254 struct sipe_backend_private *purple_private = sipe_public->backend_private;
256 purple_account_request_authorization(
257 purple_private->account,
258 who,
259 _("you"), /* id */
260 alias,
261 NULL, /* message */
262 on_list,
263 (PurpleAccountRequestAuthorizationCb) auth_cb,
264 (PurpleAccountRequestAuthorizationCb) deny_cb,
265 data);
269 void sipe_backend_buddy_request_add(struct sipe_core_public *sipe_public,
270 const gchar *who,
271 const gchar *alias)
273 struct sipe_backend_private *purple_private = sipe_public->backend_private;
275 purple_account_request_add(purple_private->account,
276 who,
277 _("you"),
278 alias,
279 NULL);
283 gboolean sipe_backend_buddy_is_blocked(struct sipe_core_public *sipe_public,
284 const gchar *who)
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,
292 const gchar *who,
293 gboolean blocked)
295 struct sipe_backend_private *purple_private = sipe_public->backend_private;
297 if (blocked) {
298 purple_account_privacy_deny_add(purple_private->account, who, TRUE);
299 } else {
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,
306 who,
307 sipe_backend_buddy_get_status(sipe_public,
308 who));
311 void sipe_backend_buddy_set_status(struct sipe_core_public *sipe_public,
312 const gchar *who,
313 guint activity)
315 struct sipe_backend_private *purple_private = sipe_public->backend_private;
316 PurpleBuddy *buddy = NULL;
317 PurpleStatus *status = NULL;
318 gchar *tmp = NULL;
320 buddy = purple_blist_find_buddy(purple_private->account, who);
321 if (buddy)
322 status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
324 if (status)
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));
330 if (tmp) {
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,
334 NULL);
335 g_free(tmp);
336 } else
337 purple_prpl_got_user_status(purple_private->account, who,
338 sipe_purple_activity_to_token(activity),
339 NULL);
342 gboolean sipe_backend_uses_photo(void)
344 return TRUE;
347 void sipe_backend_buddy_set_photo(struct sipe_core_public *sipe_public,
348 const gchar *who,
349 gpointer photo_data,
350 gsize data_len,
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,
360 const gchar *who)
362 PurpleAccount *account = sipe_public->backend_private->account;
363 const gchar *result = NULL;
365 PurpleBuddyIcon *icon = purple_buddy_icons_find(account, who);
366 if (icon) {
367 result = purple_buddy_icon_get_checksum(icon);
368 purple_buddy_icon_unref(icon);
371 return result;
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);
378 if (!purple_group) {
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);
391 if (purple_group)
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);
400 if (purple_group)
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,
412 const gchar *value)
414 if (info) {
415 purple_notify_user_info_add_pair_html((PurpleNotifyUserInfo *) info,
416 buddy_info_description(key),
417 value);
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,
429 const gchar *uri)
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,
444 const gchar *value)
446 purple_notify_user_info_add_pair_html((PurpleNotifyUserInfo *) tooltip,
447 description,
448 value);
451 void sipe_purple_add_buddy(PurpleConnection *gc,
452 PurpleBuddy *buddy,
453 PurpleGroup *group
454 #if PURPLE_VERSION_CHECK(3,0,0)
455 , SIPE_UNUSED_PARAMETER const gchar *message
456 #endif
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);
471 g_free(buddy_name);
473 if (uri) {
474 purple_buddy_set_name(buddy, uri);
475 g_free(uri);
477 sipe_core_buddy_add(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
478 purple_buddy_get_name(buddy),
479 purple_group_get_name(group));
480 } else {
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"),
485 NULL
486 #if PURPLE_VERSION_CHECK(3,0,0)
487 , NULL
488 #endif
494 void sipe_purple_remove_buddy(PurpleConnection *gc,
495 PurpleBuddy *buddy,
496 PurpleGroup *group)
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) : "");
501 if (!buddy) return;
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,
509 const char *who,
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,
519 gpointer parameter)
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,
524 parameter,
525 purple_buddy_get_name(buddy));
528 static void sipe_purple_buddy_remove_from_chat_cb(PurpleBuddy *buddy,
529 gpointer parameter)
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,
534 parameter,
535 purple_buddy_get_name(buddy));
538 static void sipe_purple_buddy_invite_to_chat_cb(PurpleBuddy *buddy,
539 gpointer parameter)
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,
544 parameter,
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,
558 gpointer parameter)
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,
563 parameter);
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,
587 gpointer parameter)
589 sipe_core_change_access_level_from_container(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC,
590 parameter);
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");
597 guint index =
598 #if PURPLE_VERSION_CHECK(3,0,0)
599 GPOINTER_TO_UINT(
600 #endif
601 purple_request_fields_get_choice(fields, "container_id")
602 #if PURPLE_VERSION_CHECK(3,0,0)
604 #endif
607 sipe_core_change_access_level_for_domain(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
608 domain,
609 index);
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",
625 _("Domain"),
626 "partner-company.com",
627 FALSE);
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",
632 _("Access level"),
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));
641 #else
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 */
648 #endif
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),
657 _("Cancel"), NULL,
658 #if PURPLE_VERSION_CHECK(3,0,0)
659 purple_request_cpar_from_account(account),
660 #else
661 account, NULL, NULL,
662 #endif
663 gc);
666 typedef void (*buddy_menu_callback)(PurpleBuddy *buddy,
667 gpointer parameter);
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)
682 return(NULL);
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,
687 const gchar *label,
688 enum sipe_buddy_menu_type type,
689 gpointer parameter)
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]),
695 parameter, NULL)));
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,
700 const gchar *label)
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,
709 const gchar *label,
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,
715 NULL,
716 NULL,
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;
725 PurpleGroup *group;
726 PurpleBuddy *clone;
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),
738 group);
739 if (!clone) {
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),
744 #else
745 buddy->alias,
746 #endif
747 purple_group_get_name(group));
748 if (clone) {
749 const gchar *tmp;
750 const gchar *key;
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,
759 key,
760 tmp);
762 tmp = purple_status_get_id(status);
763 purple_presence_set_status_active(purple_buddy_get_presence(clone),
764 tmp,
765 TRUE);
767 /* update UI */
768 purple_prpl_got_user_status(purple_buddy_get_account(clone),
769 purple_buddy_get_name(clone),
770 tmp,
771 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE, tmp,
772 NULL);
776 if (clone && group)
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,
783 PurpleBuddy *buddy)
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),
797 group))
798 continue;
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),
803 NULL);
804 menu_groups = g_list_prepend(menu_groups, act);
807 if (menu_groups)
808 menu = g_list_prepend(menu,
809 purple_menu_action_new(_("Copy to"),
810 NULL,
811 NULL,
812 g_list_reverse(menu_groups)));
814 return(menu);
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),
822 NULL);
823 menu = sipe_purple_copy_to_menu(menu, buddy);
824 return(g_list_reverse(menu));
829 Local Variables:
830 mode: c
831 c-file-style: "bsd"
832 indent-tabs-mode: t
833 tab-width: 8
834 End: