core cleanup: remove struct sipe_account_data
[siplcs.git] / src / core / sipe.c
blob0001cdf158a94fd75d1860d7afb80dd3b42a73ef
1 /**
2 * @file sipe.c
4 *****************************************************************************
5 *** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ***
6 *** ***
7 *** THIS MODULE IS DEPECRATED ***
8 *** ***
9 *** DO NOT ADD ANY NEW CODE TO THIS MODULE ***
10 *** ***
11 *** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ***
12 *****************************************************************************
14 * pidgin-sipe
16 * Copyright (C) 2010-11 SIPE Project <http://sipe.sourceforge.net/>
17 * Copyright (C) 2010 pier11 <pier11@operamail.com>
18 * Copyright (C) 2009 Anibal Avelar <debianmx@gmail.com>
19 * Copyright (C) 2009 pier11 <pier11@operamail.com>
20 * Copyright (C) 2008 Novell, Inc., Anibal Avelar <debianmx@gmail.com>
21 * Copyright (C) 2007 Anibal Avelar <debianmx@gmail.com>
22 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de>
24 * ***
25 * Thanks to Google's Summer of Code Program and the helpful mentors
26 * ***
28 * Session-based SIP MESSAGE documentation:
29 * http://tools.ietf.org/html/draft-ietf-simple-im-session-00
31 * This program is free software; you can redistribute it and/or modify
32 * it under the terms of the GNU General Public License as published by
33 * the Free Software Foundation; either version 2 of the License, or
34 * (at your option) any later version.
36 * This program is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with this program; if not, write to the Free Software
43 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 #ifdef HAVE_CONFIG_H
47 #include "config.h"
48 #endif
50 #include <glib.h>
52 #include "sipe-common.h"
54 #include "account.h"
55 #include "blist.h"
56 #include "connection.h"
57 #include "notify.h"
58 #include "request.h"
60 #include "core-depurple.h" /* Temporary for the core de-purple transition */
62 #include "sip-csta.h"
63 #include "sipe-backend.h"
64 #include "sipe-chat.h"
65 #include "sipe-conf.h"
66 #include "sipe-core.h"
67 #include "sipe-core-private.h"
68 #include "sipe-im.h"
69 #include "sipe-nls.h"
70 #include "sipe-ocs2007.h"
71 #include "sipe-session.h"
72 #include "sipe-utils.h"
74 #include "sipe.h"
76 /** for Access levels menu */
77 #define INDENT_FMT " %s"
79 /** Member is indirectly belong to access level container.
80 * For example 'sameEnterprise' is in the container and user
81 * belongs to that same enterprise.
83 #define INDENT_MARKED_INHERITED_FMT "= %s"
85 static PurpleBuddy *
86 purple_blist_add_buddy_clone(PurpleGroup * group, PurpleBuddy * buddy)
88 struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE;
89 PurpleBuddy *clone;
90 gchar *server_alias, *email;
91 const PurpleStatus *status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
93 clone = sipe_backend_buddy_add(SIPE_CORE_PUBLIC,
94 buddy->name,
95 buddy->alias,
96 group->name);
98 server_alias = sipe_backend_buddy_get_server_alias(SIPE_CORE_PUBLIC,
99 buddy);
100 if (server_alias) {
101 sipe_backend_buddy_set_server_alias(SIPE_CORE_PUBLIC,
102 clone,
103 server_alias);
104 g_free(server_alias);
107 email = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
108 buddy,
109 SIPE_BUDDY_INFO_EMAIL);
110 if (email) {
111 sipe_backend_buddy_set_string(SIPE_CORE_PUBLIC,
112 clone,
113 SIPE_BUDDY_INFO_EMAIL,
114 email);
115 g_free(email);
118 purple_presence_set_status_active(purple_buddy_get_presence(clone),
119 purple_status_get_id(status),
120 TRUE);
121 /* for UI to update */
122 sipe_backend_buddy_set_status(SIPE_CORE_PUBLIC,
123 buddy->name,
124 purple_status_get_id(status));
126 return clone;
129 static void
130 sipe_buddy_menu_copy_to_cb(PurpleBlistNode *node, const char *group_name)
132 PurpleBuddy *buddy, *b;
133 PurpleGroup * group = purple_find_group(group_name);
135 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
137 buddy = (PurpleBuddy *)node;
139 SIPE_DEBUG_INFO("sipe_buddy_menu_copy_to_cb: copying %s to %s",
140 buddy->name, group_name);
142 b = purple_find_buddy_in_group(buddy->account, buddy->name, group);
143 if (!b)
144 b = purple_blist_add_buddy_clone(group, buddy);
146 if (b && group) {
147 PurpleConnection *gc = purple_account_get_connection(b->account);
149 sipe_core_buddy_add(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
150 b->name,
151 group->name);
155 static void
156 sipe_buddy_menu_chat_new_cb(PurpleBuddy *buddy)
158 struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE;
160 SIPE_DEBUG_INFO("sipe_buddy_menu_chat_new_cb: buddy->name=%s", buddy->name);
162 /* 2007+ conference */
163 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007))
165 sipe_conf_add(sipe_private, buddy->name);
167 else /* 2005- multiparty chat */
169 gchar *self = sip_uri_self(sipe_private);
170 struct sip_session *session;
172 session = sipe_session_add_chat(sipe_private,
173 NULL,
174 TRUE,
175 self);
176 session->chat_session->backend = sipe_backend_chat_create(SIPE_CORE_PUBLIC,
177 session->chat_session,
178 session->chat_session->title,
179 self);
180 g_free(self);
182 sipe_im_invite(sipe_private, session, buddy->name, NULL, NULL, NULL, FALSE);
187 * For 2007+ conference only.
189 static void
190 sipe_buddy_menu_chat_make_leader_cb(PurpleBuddy *buddy,
191 struct sipe_chat_session *chat_session)
193 struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE;
194 struct sip_session *session;
196 SIPE_DEBUG_INFO("sipe_buddy_menu_chat_make_leader_cb: buddy->name=%s", buddy->name);
197 SIPE_DEBUG_INFO("sipe_buddy_menu_chat_make_leader_cb: chat_title=%s", chat_session->title);
199 session = sipe_session_find_chat(sipe_private, chat_session);
201 sipe_conf_modify_user_role(sipe_private, session, buddy->name);
205 * For 2007+ conference only.
207 static void
208 sipe_buddy_menu_chat_remove_cb(PurpleBuddy *buddy,
209 struct sipe_chat_session *chat_session)
211 struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE;
212 struct sip_session *session;
214 SIPE_DEBUG_INFO("sipe_buddy_menu_chat_remove_cb: buddy->name=%s", buddy->name);
215 SIPE_DEBUG_INFO("sipe_buddy_menu_chat_remove_cb: chat_title=%s", chat_session->title);
217 session = sipe_session_find_chat(sipe_private, chat_session);
219 sipe_conf_delete_user(sipe_private, session, buddy->name);
222 static void
223 sipe_buddy_menu_chat_invite_cb(PurpleBuddy *buddy,
224 struct sipe_chat_session *chat_session)
226 struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE;
228 SIPE_DEBUG_INFO("sipe_buddy_menu_chat_invite_cb: buddy->name=%s", buddy->name);
229 SIPE_DEBUG_INFO("sipe_buddy_menu_chat_invite_cb: chat_title=%s", chat_session->title);
231 sipe_core_chat_invite(SIPE_CORE_PUBLIC, chat_session, buddy->name);
234 static void
235 sipe_buddy_menu_make_call_cb(PurpleBuddy *buddy, const char *phone)
237 struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE;
239 SIPE_DEBUG_INFO("sipe_buddy_menu_make_call_cb: buddy->name=%s", buddy->name);
240 if (phone) {
241 char *tel_uri = sip_to_tel_uri(phone);
243 SIPE_DEBUG_INFO("sipe_buddy_menu_make_call_cb: going to call number: %s", tel_uri ? tel_uri : "");
244 sip_csta_make_call(sipe_private, tel_uri);
246 g_free(tel_uri);
250 static void
251 sipe_buddy_menu_access_level_help_cb(PurpleBuddy *buddy)
253 /** Translators: replace with URL to localized page
254 * If it doesn't exist copy the original URL */
255 purple_notify_uri(buddy->account->gc, _("https://sourceforge.net/apps/mediawiki/sipe/index.php?title=Access_Levels"));
258 static void
259 sipe_buddy_menu_send_email_cb(PurpleBuddy *buddy)
261 struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE;
262 gchar *email;
263 SIPE_DEBUG_INFO("sipe_buddy_menu_send_email_cb: buddy->name=%s", buddy->name);
265 email = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
266 buddy,
267 SIPE_BUDDY_INFO_EMAIL);
268 if (email)
270 char *command_line = g_strdup_printf(
271 #ifdef _WIN32
272 "cmd /c start"
273 #else
274 "xdg-email"
275 #endif
276 " mailto:%s", email);
277 SIPE_DEBUG_INFO("sipe_buddy_menu_send_email_cb: going to call email client: %s", command_line);
279 g_free(email);
280 g_spawn_command_line_async(command_line, NULL);
281 g_free(command_line);
283 else
285 SIPE_DEBUG_INFO("sipe_buddy_menu_send_email_cb: no email address stored for buddy=%s", buddy->name);
289 static void
290 sipe_buddy_menu_access_level_cb(PurpleBuddy *buddy,
291 struct sipe_container *container)
293 struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE;
294 sipe_ocs2007_change_access_level_from_container(sipe_private,
295 container);
298 static GList *
299 sipe_get_access_control_menu(struct sipe_core_private *sipe_private,
300 const char* uri);
303 * A menu which appear when right-clicking on buddy in contact list.
305 GList *
306 sipe_buddy_menu(PurpleBuddy *buddy)
308 PurpleBlistNode *g_node;
309 PurpleGroup *gr_parent;
310 PurpleMenuAction *act;
311 GList *menu = NULL;
312 GList *menu_groups = NULL;
313 struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE;
314 gchar *email;
315 gchar *self = sip_uri_self(sipe_private);
317 SIPE_SESSION_FOREACH {
318 if (!sipe_strcase_equal(self, buddy->name) && session->chat_session)
320 struct sipe_chat_session *chat_session = session->chat_session;
321 gboolean is_conf = (chat_session->type == SIPE_CHAT_TYPE_CONFERENCE);
323 if (sipe_backend_chat_find(chat_session->backend, buddy->name))
325 gboolean conf_op = sipe_backend_chat_is_operator(chat_session->backend, self);
327 if (is_conf
328 && !sipe_backend_chat_is_operator(chat_session->backend, buddy->name) /* Not conf OP */
329 && conf_op) /* We are a conf OP */
331 gchar *label = g_strdup_printf(_("Make leader of '%s'"),
332 chat_session->title);
333 act = purple_menu_action_new(label,
334 PURPLE_CALLBACK(sipe_buddy_menu_chat_make_leader_cb),
335 chat_session, NULL);
336 g_free(label);
337 menu = g_list_prepend(menu, act);
340 if (is_conf
341 && conf_op) /* We are a conf OP */
343 gchar *label = g_strdup_printf(_("Remove from '%s'"),
344 chat_session->title);
345 act = purple_menu_action_new(label,
346 PURPLE_CALLBACK(sipe_buddy_menu_chat_remove_cb),
347 chat_session, NULL);
348 g_free(label);
349 menu = g_list_prepend(menu, act);
352 else
354 if (!is_conf
355 || (is_conf && !session->locked))
357 gchar *label = g_strdup_printf(_("Invite to '%s'"),
358 chat_session->title);
359 act = purple_menu_action_new(label,
360 PURPLE_CALLBACK(sipe_buddy_menu_chat_invite_cb),
361 chat_session, NULL);
362 g_free(label);
363 menu = g_list_prepend(menu, act);
367 } SIPE_SESSION_FOREACH_END;
369 act = purple_menu_action_new(_("New chat"),
370 PURPLE_CALLBACK(sipe_buddy_menu_chat_new_cb),
371 NULL, NULL);
372 menu = g_list_prepend(menu, act);
374 if (sipe_private->csta && !sipe_private->csta->line_status) {
375 gchar *phone;
376 gchar *phone_disp_str;
377 gchar *tmp = NULL;
378 /* work phone */
379 phone = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
380 buddy,
381 SIPE_BUDDY_INFO_WORK_PHONE);
382 phone_disp_str = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
383 buddy,
384 SIPE_BUDDY_INFO_WORK_PHONE_DISPLAY);
385 if (phone) {
386 gchar *label = g_strdup_printf(_("Work %s"),
387 phone_disp_str ? phone_disp_str : (tmp = sip_tel_uri_denormalize(phone)));
388 act = purple_menu_action_new(label, PURPLE_CALLBACK(sipe_buddy_menu_make_call_cb), (gpointer) phone, NULL);
389 g_free(tmp);
390 tmp = NULL;
391 g_free(label);
392 menu = g_list_prepend(menu, act);
393 g_free(phone);
395 g_free(phone_disp_str);
397 /* mobile phone */
398 phone = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
399 buddy,
400 SIPE_BUDDY_INFO_MOBILE_PHONE);
401 phone_disp_str = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
402 buddy,
403 SIPE_BUDDY_INFO_MOBILE_PHONE_DISPLAY);
404 if (phone) {
405 gchar *label = g_strdup_printf(_("Mobile %s"),
406 phone_disp_str ? phone_disp_str : (tmp = sip_tel_uri_denormalize(phone)));
407 act = purple_menu_action_new(label, PURPLE_CALLBACK(sipe_buddy_menu_make_call_cb), (gpointer) phone, NULL);
408 g_free(tmp);
409 tmp = NULL;
410 g_free(label);
411 menu = g_list_prepend(menu, act);
412 g_free(phone);
414 g_free(phone_disp_str);
416 /* home phone */
417 phone = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
418 buddy,
419 SIPE_BUDDY_INFO_HOME_PHONE);
420 phone_disp_str = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
421 buddy,
422 SIPE_BUDDY_INFO_HOME_PHONE_DISPLAY);
423 if (phone) {
424 gchar *label = g_strdup_printf(_("Home %s"),
425 phone_disp_str ? phone_disp_str : (tmp = sip_tel_uri_denormalize(phone)));
426 act = purple_menu_action_new(label, PURPLE_CALLBACK(sipe_buddy_menu_make_call_cb), (gpointer) phone, NULL);
427 g_free(tmp);
428 tmp = NULL;
429 g_free(label);
430 menu = g_list_prepend(menu, act);
431 g_free(phone);
433 g_free(phone_disp_str);
435 /* other phone */
436 phone = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
437 buddy,
438 SIPE_BUDDY_INFO_OTHER_PHONE);
439 phone_disp_str = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
440 buddy,
441 SIPE_BUDDY_INFO_OTHER_PHONE_DISPLAY);
442 if (phone) {
443 gchar *label = g_strdup_printf(_("Other %s"),
444 phone_disp_str ? phone_disp_str : (tmp = sip_tel_uri_denormalize(phone)));
445 act = purple_menu_action_new(label, PURPLE_CALLBACK(sipe_buddy_menu_make_call_cb), (gpointer) phone, NULL);
446 g_free(tmp);
447 tmp = NULL;
448 g_free(label);
449 menu = g_list_prepend(menu, act);
450 g_free(phone);
452 g_free(phone_disp_str);
454 /* custom1 phone */
455 phone = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
456 buddy,
457 SIPE_BUDDY_INFO_CUSTOM1_PHONE);
458 phone_disp_str = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
459 buddy,
460 SIPE_BUDDY_INFO_CUSTOM1_PHONE_DISPLAY);
461 if (phone) {
462 gchar *label = g_strdup_printf(_("Custom1 %s"),
463 phone_disp_str ? phone_disp_str : (tmp = sip_tel_uri_denormalize(phone)));
464 act = purple_menu_action_new(label, PURPLE_CALLBACK(sipe_buddy_menu_make_call_cb), (gpointer) phone, NULL);
465 g_free(tmp);
466 tmp = NULL;
467 g_free(label);
468 menu = g_list_prepend(menu, act);
469 g_free(phone);
471 g_free(phone_disp_str);
474 email = sipe_backend_buddy_get_string(SIPE_CORE_PUBLIC,
475 buddy,
476 SIPE_BUDDY_INFO_EMAIL);
477 if (email) {
478 act = purple_menu_action_new(_("Send email..."),
479 PURPLE_CALLBACK(sipe_buddy_menu_send_email_cb),
480 NULL, NULL);
481 menu = g_list_prepend(menu, act);
482 g_free(email);
485 /* Access Level */
486 if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) {
487 GList *menu_access_levels = sipe_get_access_control_menu(sipe_private, buddy->name);
489 act = purple_menu_action_new(_("Access level"),
490 NULL,
491 NULL, menu_access_levels);
492 menu = g_list_prepend(menu, act);
495 /* Copy to */
496 gr_parent = purple_buddy_get_group(buddy);
497 for (g_node = purple_blist_get_root(); g_node; g_node = g_node->next) {
498 PurpleGroup *group;
500 if (g_node->type != PURPLE_BLIST_GROUP_NODE)
501 continue;
503 group = (PurpleGroup *)g_node;
504 if (group == gr_parent)
505 continue;
507 if (purple_find_buddy_in_group(buddy->account, buddy->name, group))
508 continue;
510 act = purple_menu_action_new(purple_group_get_name(group),
511 PURPLE_CALLBACK(sipe_buddy_menu_copy_to_cb),
512 group->name, NULL);
513 menu_groups = g_list_prepend(menu_groups, act);
515 /* Coverity complains about RESOURCE_LEAK here - no idea how to fix it */
516 menu_groups = g_list_reverse(menu_groups);
518 act = purple_menu_action_new(_("Copy to"),
519 NULL,
520 NULL, menu_groups);
521 menu = g_list_prepend(menu, act);
523 menu = g_list_reverse(menu);
525 g_free(self);
526 return menu;
529 static void
530 sipe_ask_access_domain_cb(PurpleConnection *gc, PurpleRequestFields *fields)
532 struct sipe_core_private *sipe_private = PURPLE_GC_TO_SIPE_CORE_PRIVATE;
533 const char *domain = purple_request_fields_get_string(fields, "access_domain");
534 guint index = purple_request_fields_get_choice(fields, "container_id");
535 sipe_ocs2007_change_access_level_for_domain(sipe_private,
536 domain,
537 index);
540 static void sipe_buddy_menu_access_level_add_domain_cb(PurpleBuddy *buddy)
542 PurpleConnection *gc = purple_account_get_connection(buddy->account);
543 PurpleRequestFields *fields;
544 PurpleRequestFieldGroup *g;
545 PurpleRequestField *f;
547 fields = purple_request_fields_new();
549 g = purple_request_field_group_new(NULL);
550 f = purple_request_field_string_new("access_domain", _("Domain"), "partner-company.com", FALSE);
551 purple_request_field_set_required(f, TRUE);
552 purple_request_field_group_add_field(g, f);
554 f = purple_request_field_choice_new("container_id", _("Access level"), 0);
555 purple_request_field_choice_add(f, _("Personal")); /* index 0 */
556 purple_request_field_choice_add(f, _("Team"));
557 purple_request_field_choice_add(f, _("Company"));
558 purple_request_field_choice_add(f, _("Public"));
559 purple_request_field_choice_add(f, _("Blocked")); /* index 4 */
560 purple_request_field_choice_set_default_value(f, 3); /* index */
561 purple_request_field_set_required(f, TRUE);
562 purple_request_field_group_add_field(g, f);
564 purple_request_fields_add_group(fields, g);
566 purple_request_fields(gc, _("Add new domain"),
567 _("Add new domain"), NULL, fields,
568 _("Add"), G_CALLBACK(sipe_ask_access_domain_cb),
569 _("Cancel"), NULL,
570 buddy->account, NULL, NULL, gc);
574 * Workaround for missing libpurple API to release resources allocated
575 * during blist_node_menu() callback. See also:
577 * <http://developer.pidgin.im/ticket/12597>
579 * We remember all memory blocks in a list and deallocate them when
581 * - the next time we enter the callback, or
582 * - the account is disconnected
584 * That means that after the buddy menu has been closed we have unused
585 * resources but at least we don't leak them anymore...
587 void sipe_blist_menu_free_containers(struct sipe_core_private *sipe_private)
589 GSList *entry = sipe_private->blist_menu_containers;
590 while (entry) {
591 sipe_ocs2007_free_container(entry->data);
592 entry = entry->next;
594 g_slist_free(sipe_private->blist_menu_containers);
595 sipe_private->blist_menu_containers = NULL;
598 static void
599 sipe_blist_menu_remember_container(struct sipe_core_private *sipe_private,
600 struct sipe_container *container)
602 sipe_private->blist_menu_containers = g_slist_prepend(sipe_private->blist_menu_containers,
603 container);
606 static GList *
607 sipe_get_access_levels_menu(struct sipe_core_private *sipe_private,
608 const char* member_type,
609 const char* member_value,
610 const gboolean extra_menu)
612 GList *menu_access_levels = NULL;
613 unsigned int i;
614 char *menu_name;
615 PurpleMenuAction *act;
616 struct sipe_container *container;
617 gboolean is_group_access = FALSE;
618 int container_id = sipe_ocs2007_find_access_level(sipe_private,
619 member_type,
620 member_value,
621 &is_group_access);
622 guint container_max = sipe_ocs2007_containers();
624 for (i = 1; i <= container_max; i++) {
625 /* to put Blocked level last in menu list.
626 * Blocked should remaim in the first place in the containers[] array.
628 unsigned int j = (i == container_max) ? 0 : i;
629 int container_j = sipe_ocs2007_container_id(j);
630 const gchar *acc_level_name = sipe_ocs2007_access_level_name(container_j);
632 container = sipe_ocs2007_create_container(j,
633 member_type,
634 member_value,
635 FALSE);
637 /* libpurple memory leak workaround */
638 sipe_blist_menu_remember_container(sipe_private, container);
640 /* current container/access level */
641 if (container_j == container_id) {
642 menu_name = is_group_access ?
643 g_strdup_printf(INDENT_MARKED_INHERITED_FMT, acc_level_name) :
644 g_strdup_printf(SIPE_OCS2007_INDENT_MARKED_FMT, acc_level_name);
645 } else {
646 menu_name = g_strdup_printf(INDENT_FMT, acc_level_name);
649 act = purple_menu_action_new(menu_name,
650 PURPLE_CALLBACK(sipe_buddy_menu_access_level_cb),
651 container, NULL);
652 g_free(menu_name);
653 menu_access_levels = g_list_prepend(menu_access_levels, act);
656 if (extra_menu && (container_id >= 0)) {
657 /* separator */
658 act = purple_menu_action_new(" --------------", NULL, NULL, NULL);
659 menu_access_levels = g_list_prepend(menu_access_levels, act);
661 if (!is_group_access) {
662 container = sipe_ocs2007_create_container(0,
663 member_type,
664 member_value,
665 TRUE);
667 /* libpurple memory leak workaround */
668 sipe_blist_menu_remember_container(sipe_private, container);
670 /* Translators: remove (clear) previously assigned access level */
671 menu_name = g_strdup_printf(INDENT_FMT, _("Unspecify"));
672 act = purple_menu_action_new(menu_name,
673 PURPLE_CALLBACK(sipe_buddy_menu_access_level_cb),
674 container, NULL);
675 g_free(menu_name);
676 menu_access_levels = g_list_prepend(menu_access_levels, act);
680 menu_access_levels = g_list_reverse(menu_access_levels);
681 return menu_access_levels;
684 static GList *
685 sipe_get_access_groups_menu(struct sipe_core_private *sipe_private)
687 GList *menu_access_groups = NULL;
688 PurpleMenuAction *act;
689 GSList *access_domains;
690 GSList *entry;
692 act = purple_menu_action_new(_("People in my company"),
693 NULL,
694 NULL, sipe_get_access_levels_menu(sipe_private, "sameEnterprise", NULL, FALSE));
695 menu_access_groups = g_list_prepend(menu_access_groups, act);
697 /* this is original name, don't edit */
698 act = purple_menu_action_new(_("People in domains connected with my company"),
699 NULL,
700 NULL, sipe_get_access_levels_menu(sipe_private, "federated", NULL, FALSE));
701 menu_access_groups = g_list_prepend(menu_access_groups, act);
703 act = purple_menu_action_new(_("People in public domains"),
704 NULL,
705 NULL, sipe_get_access_levels_menu(sipe_private, "publicCloud", NULL, TRUE));
706 menu_access_groups = g_list_prepend(menu_access_groups, act);
708 access_domains = sipe_ocs2007_get_access_domains(sipe_private);
709 entry = access_domains;
710 while (entry) {
711 gchar *domain = entry->data;
712 gchar *menu_name = g_strdup_printf(_("People at %s"), domain);
714 /* takes over ownership of entry->data (= domain) */
715 act = purple_menu_action_new(menu_name,
716 NULL,
717 NULL, sipe_get_access_levels_menu(sipe_private, "domain", domain, TRUE));
718 menu_access_groups = g_list_prepend(menu_access_groups, act);
719 g_free(menu_name);
721 entry = entry->next;
723 g_slist_free(access_domains);
725 /* separator */
726 /* People in domains connected with my company */
727 act = purple_menu_action_new("-------------------------------------------", NULL, NULL, NULL);
728 menu_access_groups = g_list_prepend(menu_access_groups, act);
730 act = purple_menu_action_new(_("Add new domain..."),
731 PURPLE_CALLBACK(sipe_buddy_menu_access_level_add_domain_cb),
732 NULL, NULL);
733 menu_access_groups = g_list_prepend(menu_access_groups, act);
735 menu_access_groups = g_list_reverse(menu_access_groups);
737 return menu_access_groups;
740 static GList *
741 sipe_get_access_control_menu(struct sipe_core_private *sipe_private,
742 const char* uri)
744 GList *menu_access_levels = NULL;
745 GList *menu_access_groups = NULL;
746 char *menu_name;
747 PurpleMenuAction *act;
749 /* libpurple memory leak workaround */
750 sipe_blist_menu_free_containers(sipe_private);
752 menu_access_levels = sipe_get_access_levels_menu(sipe_private, "user", sipe_get_no_sip_uri(uri), TRUE);
754 menu_access_groups = sipe_get_access_groups_menu(sipe_private);
756 menu_name = g_strdup_printf(INDENT_FMT, _("Access groups"));
757 act = purple_menu_action_new(menu_name,
758 NULL,
759 NULL, menu_access_groups);
760 g_free(menu_name);
761 menu_access_levels = g_list_append(menu_access_levels, act);
763 menu_name = g_strdup_printf(INDENT_FMT, _("Online help..."));
764 act = purple_menu_action_new(menu_name,
765 PURPLE_CALLBACK(sipe_buddy_menu_access_level_help_cb),
766 NULL, NULL);
767 g_free(menu_name);
768 menu_access_levels = g_list_append(menu_access_levels, act);
770 return menu_access_levels;
774 Local Variables:
775 mode: c
776 c-file-style: "bsd"
777 indent-tabs-mode: t
778 tab-width: 8
779 End: