From 6089e569fac1de1e7949168a8ddf22ebe269bd28 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sat, 10 Dec 2011 01:24:30 +0200 Subject: [PATCH] core cleanup: start to separate buddy menu code As this change is too big to do in one go I have chosen to take a piecemeal approach. This breaks the compilation of sipe.c, so the first step was to remove sipe.c from the build. The module is still included in the tarball, because otherwise the intltool check will fail. Removed sipe.h and core-depurple.h and updated sipe-core.c and purple-plugin.c accordingly. Removed all purple stuff from src/core/Makefile.am. I also noticed that we still compiled sipe-utils.c as purple module under Windows, although that purple dependency had already been removed months ago. All of the above means that finally the core directory is purple-free! As an initial step for the buddy menu cleanup the code for the first 4 entries, all related to chat, was separated and moved to the appropriate modules in core and purple directories. --- siplcs.vcproj | 8 - .../SIPEAdiumPlugin.xcodeproj/project.pbxproj | 4 - src/api/Makefile.am | 1 - src/api/core-depurple.h | 32 --- src/api/sipe-backend.h | 18 ++ src/api/sipe-core.h | 18 ++ src/core/Makefile.am | 28 +-- src/core/Makefile.mingw | 5 +- src/core/sipe-buddy.c | 112 ++++++++++ src/core/sipe-conf.c | 29 +++ src/core/sipe-core.c | 3 +- src/core/sipe-ocs2007.c | 21 +- src/core/sipe-ocs2007.h | 6 +- src/core/sipe.c | 225 +-------------------- src/core/sipe.h | 50 ----- src/purple/Makefile.am | 1 - src/purple/purple-buddy.c | 96 +++++++++ src/purple/purple-plugin.c | 7 +- src/purple/purple-private.h | 2 + 19 files changed, 322 insertions(+), 344 deletions(-) delete mode 100644 src/api/core-depurple.h delete mode 100644 src/core/sipe.h diff --git a/siplcs.vcproj b/siplcs.vcproj index 17d6305a..04de1a1b 100755 --- a/siplcs.vcproj +++ b/siplcs.vcproj @@ -628,14 +628,6 @@ > - - - - diff --git a/src/adium/SIPEAdiumPlugin.xcodeproj/project.pbxproj b/src/adium/SIPEAdiumPlugin.xcodeproj/project.pbxproj index 4dacc3c6..76aafea8 100644 --- a/src/adium/SIPEAdiumPlugin.xcodeproj/project.pbxproj +++ b/src/adium/SIPEAdiumPlugin.xcodeproj/project.pbxproj @@ -75,7 +75,6 @@ B13FAC0A119D585A001CE037 /* sipe-utils.c in Sources */ = {isa = PBXBuildFile; fileRef = B13FABCE119D585A001CE037 /* sipe-utils.c */; }; B13FAC0E119D585A001CE037 /* sipe-xml-tests.c in Sources */ = {isa = PBXBuildFile; fileRef = B13FABD2119D585A001CE037 /* sipe-xml-tests.c */; }; B13FAC0F119D585A001CE037 /* sipe-xml.c in Sources */ = {isa = PBXBuildFile; fileRef = B13FABD3119D585A001CE037 /* sipe-xml.c */; }; - B13FAC11119D585A001CE037 /* sipe.c in Sources */ = {isa = PBXBuildFile; fileRef = B13FABD5119D585A001CE037 /* sipe.c */; }; B13FAC13119D585A001CE037 /* sipmsg.c in Sources */ = {isa = PBXBuildFile; fileRef = B13FABD7119D585A001CE037 /* sipmsg.c */; }; B13FAC15119D585A001CE037 /* uuid.c in Sources */ = {isa = PBXBuildFile; fileRef = B13FABD9119D585A001CE037 /* uuid.c */; }; B13FAC61119D721E001CE037 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B13FAC60119D721E001CE037 /* libxml2.dylib */; }; @@ -163,7 +162,6 @@ B13FABCE119D585A001CE037 /* sipe-utils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "sipe-utils.c"; sourceTree = ""; }; B13FABD2119D585A001CE037 /* sipe-xml-tests.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "sipe-xml-tests.c"; sourceTree = ""; }; B13FABD3119D585A001CE037 /* sipe-xml.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "sipe-xml.c"; sourceTree = ""; }; - B13FABD5119D585A001CE037 /* sipe.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sipe.c; sourceTree = ""; }; B13FABD7119D585A001CE037 /* sipmsg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sipmsg.c; sourceTree = ""; }; B13FABD9119D585A001CE037 /* uuid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = uuid.c; sourceTree = ""; }; B13FAC60119D721E001CE037 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; }; @@ -366,7 +364,6 @@ B13FABCE119D585A001CE037 /* sipe-utils.c */, B13FABD2119D585A001CE037 /* sipe-xml-tests.c */, B13FABD3119D585A001CE037 /* sipe-xml.c */, - B13FABD5119D585A001CE037 /* sipe.c */, B13FABD7119D585A001CE037 /* sipmsg.c */, B13FABD9119D585A001CE037 /* uuid.c */, ); @@ -521,7 +518,6 @@ B13FAC0A119D585A001CE037 /* sipe-utils.c in Sources */, B13FAC0E119D585A001CE037 /* sipe-xml-tests.c in Sources */, B13FAC0F119D585A001CE037 /* sipe-xml.c in Sources */, - B13FAC11119D585A001CE037 /* sipe.c in Sources */, B13FAC13119D585A001CE037 /* sipmsg.c in Sources */, B13FAC15119D585A001CE037 /* uuid.c in Sources */, 1CF260F912C2DFA00045B6CC /* purple-buddy.c in Sources */, diff --git a/src/api/Makefile.am b/src/api/Makefile.am index 5555df60..8341d63d 100644 --- a/src/api/Makefile.am +++ b/src/api/Makefile.am @@ -2,7 +2,6 @@ MAINTAINERCLEANFILES = \ Makefile.in EXTRA_DIST = \ - core-depurple.h \ sipe-backend.h \ sipe-common.h \ sipe-core.h \ diff --git a/src/api/core-depurple.h b/src/api/core-depurple.h deleted file mode 100644 index 6e4247c0..00000000 --- a/src/api/core-depurple.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @file core-depurple.h - * - * pidgin-sipe - * - * Copyright (C) 2010-11 SIPE Project - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * This is a temporary file for the core de-purple transition period - */ -GList *sipe_buddy_menu(PurpleBuddy *buddy); - -/* Convenience macros */ -#define PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE ((struct sipe_core_private *)buddy->account->gc->proto_data) -#define PURPLE_GC_TO_SIPE_CORE_PRIVATE ((struct sipe_core_private *)gc->proto_data) -#define PURPLE_GC_TO_SIPE_CORE_PUBLIC ((struct sipe_core_public *) gc->proto_data) - diff --git a/src/api/sipe-backend.h b/src/api/sipe-backend.h index be3ad79e..266630d7 100644 --- a/src/api/sipe-backend.h +++ b/src/api/sipe-backend.h @@ -883,6 +883,24 @@ void sipe_backend_buddy_tooltip_add(struct sipe_core_public *sipe_public, const gchar *description, const gchar *value); +/** + * Buddy menu creation + */ +enum sipe_buddy_menu_type { + SIPE_BUDDY_MENU_MAKE_CHAT_LEADER = 0, + SIPE_BUDDY_MENU_REMOVE_FROM_CHAT, + SIPE_BUDDY_MENU_INVITE_TO_CHAT, + SIPE_BUDDY_MENU_NEW_CHAT, + SIPE_BUDDY_MENU_TYPES +}; + +struct sipe_backend_buddy_menu *sipe_backend_buddy_menu_start(struct sipe_core_public *sipe_public); +struct sipe_backend_buddy_menu *sipe_backend_buddy_menu_add(struct sipe_core_public *sipe_public, + struct sipe_backend_buddy_menu *menu, + const gchar *label, + enum sipe_buddy_menu_type type, + gpointer parameter); + #ifdef __cplusplus } #endif diff --git a/src/api/sipe-core.h b/src/api/sipe-core.h index 2e3e2999..96e2e9bf 100644 --- a/src/api/sipe-core.h +++ b/src/api/sipe-core.h @@ -338,6 +338,14 @@ struct sip_session * sipe_core_conf_create(struct sipe_core_public *sipe_public, const gchar *focus_uri); +/* buddy menu callback: parameter == chat_session */ +void sipe_core_conf_make_leader(struct sipe_core_public *sipe_public, + gpointer parameter, + const gchar *buddy_name); +void sipe_core_conf_remove_from(struct sipe_core_public *sipe_public, + gpointer parameter, + const gchar *buddy_name); + /* media */ void sipe_core_media_initiate_call(struct sipe_core_public *sipe_public, const char *participant, @@ -420,6 +428,16 @@ void sipe_core_buddy_search(struct sipe_core_public *sipe_public, void sipe_core_buddy_get_info(struct sipe_core_public *sipe_public, const gchar *who); +void sipe_core_buddy_new_chat(struct sipe_core_public *sipe_public, + const gchar *who); + +struct sipe_backend_buddy_menu; +struct sipe_backend_buddy_menu *sipe_core_buddy_create_menu(struct sipe_core_public *sipe_public, + const gchar *buddy, + struct sipe_backend_buddy_menu *menu); + +void sipe_core_buddy_menu_free(struct sipe_core_public *sipe_public); + /* status */ void sipe_core_status_set(struct sipe_core_public *sipe_public, const gchar *status_id, diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 81cc9931..679662de 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -1,12 +1,15 @@ noinst_LTLIBRARIES = \ libsipe_core.la \ libsipe_core_crypto_nss.la \ - libsipe_core_libxml2.la \ - libsipe_core_purple.la + libsipe_core_libxml2.la MAINTAINERCLEANFILES = \ Makefile.in +# temporary: we don't compile it anymore, but we still need to put it into +# the tarball as it is required for the intltool check to pass. +noinst_HEADERS = sipe.c + libsipe_core_la_SOURCES = \ http-conn.h \ http-conn.c \ @@ -71,6 +74,8 @@ libsipe_core_la_SOURCES = \ sipe-svc.c \ sipe-tls.h \ sipe-tls.c \ + sipe-utils.h \ + sipe-utils.c \ sipe-user.c \ sipe-user.h \ sipe-xml.h \ @@ -92,9 +97,7 @@ libsipe_core_la_SOURCES += \ sip-sec-ntlm.h \ sip-sec-ntlm.c \ sip-sec-tls-dsk.h \ - sip-sec-tls-dsk.c \ - sipe-utils.h \ - sipe-utils.c + sip-sec-tls-dsk.c noinst_LTLIBRARIES += \ libsipe_core_tests.la @@ -111,17 +114,6 @@ libsipe_core_crypto_nss_la_SOURCES = \ libsipe_core_libxml2_la_SOURCES = \ sipe-xml.c -libsipe_core_purple_la_SOURCES = \ - sipe.h \ - sipe.c - -if SIPE_OS_WIN32 -# sipe-utils.c contain windows networking dependency wrapped in purple -libsipe_core_purple_la_SOURCES += \ - sipe-utils.h \ - sipe-utils.c -endif - AM_CFLAGS = $(st) libsipe_core_la_CFLAGS = \ @@ -157,10 +149,6 @@ libsipe_core_crypto_nss_la_CFLAGS = \ libsipe_core_libxml2_la_CFLAGS = $(libsipe_core_la_CFLAGS) $(LIBXML2_CFLAGS) -if SIPE_INCLUDE_PURPLE -libsipe_core_purple_la_CFLAGS = $(libsipe_core_la_CFLAGS) $(PURPLE_CFLAGS) -endif - if SIPE_WITH_VV libsipe_core_la_SOURCES += sipe-media.h sipe-media.c \ sdpmsg.h sdpmsg.c diff --git a/src/core/Makefile.mingw b/src/core/Makefile.mingw index 0a4e3b6e..93e53aa6 100644 --- a/src/core/Makefile.mingw +++ b/src/core/Makefile.mingw @@ -113,6 +113,7 @@ CLEAN_C_SRC = http-conn.c \ sipe-svc.c \ sipe-tls.c \ sipe-user.c \ + sipe-utils.c \ sipe-ews.c \ sipmsg.c \ sipe-sign.c \ @@ -139,9 +140,7 @@ PURPLE_C_SRC = ../purple/purple-buddy.c \ ../purple/purple-setting.c \ ../purple/purple-status.c \ ../purple/purple-transport.c \ - ../purple/purple-user.c \ - sipe-utils.c \ - sipe.c + ../purple/purple-user.c C_TEST_SRC = sipe-xml-tests.c diff --git a/src/core/sipe-buddy.c b/src/core/sipe-buddy.c index 9472f22a..4e464c05 100644 --- a/src/core/sipe-buddy.c +++ b/src/core/sipe-buddy.c @@ -38,13 +38,17 @@ #include "sipe-backend.h" #include "sipe-buddy.h" #include "sipe-cal.h" +#include "sipe-chat.h" +#include "sipe-conf.h" #include "sipe-core.h" #include "sipe-core-private.h" #include "sipe-group.h" +#include "sipe-im.h" #include "sipe-nls.h" #include "sipe-ocs2005.h" #include "sipe-ocs2007.h" #include "sipe-schedule.h" +#include "sipe-session.h" #include "sipe-subscriptions.h" #include "sipe-utils.h" #include "sipe-xml.h" @@ -786,6 +790,114 @@ void sipe_core_buddy_get_info(struct sipe_core_public *sipe_public, g_free(row); } +/* Buddy menu callbacks*/ + +void sipe_core_buddy_new_chat(struct sipe_core_public *sipe_public, + const gchar *who) +{ + struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE; + + /* 2007+ conference */ + if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) { + sipe_conf_add(sipe_private, who); + + /* 2005- multiparty chat */ + } else { + gchar *self = sip_uri_self(sipe_private); + struct sip_session *session; + + session = sipe_session_add_chat(sipe_private, + NULL, + TRUE, + self); + session->chat_session->backend = sipe_backend_chat_create(SIPE_CORE_PUBLIC, + session->chat_session, + session->chat_session->title, + self); + g_free(self); + + sipe_im_invite(sipe_private, session, who, + NULL, NULL, NULL, FALSE); + } +} + +/* Buddy menu */ + +struct sipe_backend_buddy_menu *sipe_core_buddy_create_menu(struct sipe_core_public *sipe_public, + const gchar *buddy, + struct sipe_backend_buddy_menu *menu) +{ + struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE; + gchar *self = sip_uri_self(sipe_private); + + SIPE_SESSION_FOREACH { + if (!sipe_strcase_equal(self, buddy) && session->chat_session) + { + struct sipe_chat_session *chat_session = session->chat_session; + gboolean is_conf = (chat_session->type == SIPE_CHAT_TYPE_CONFERENCE); + + if (sipe_backend_chat_find(chat_session->backend, buddy)) + { + gboolean conf_op = sipe_backend_chat_is_operator(chat_session->backend, self); + + if (is_conf && + /* Not conf OP */ + !sipe_backend_chat_is_operator(chat_session->backend, buddy) && + /* We are a conf OP */ + conf_op) { + gchar *label = g_strdup_printf(_("Make leader of '%s'"), + chat_session->title); + menu = sipe_backend_buddy_menu_add(SIPE_CORE_PUBLIC, + menu, + label, + SIPE_BUDDY_MENU_MAKE_CHAT_LEADER, + chat_session); + g_free(label); + } + + if (is_conf && + /* We are a conf OP */ + conf_op) { + gchar *label = g_strdup_printf(_("Remove from '%s'"), + chat_session->title); + menu = sipe_backend_buddy_menu_add(SIPE_CORE_PUBLIC, + menu, + label, + SIPE_BUDDY_MENU_REMOVE_FROM_CHAT, + chat_session); + g_free(label); + } + } + else + { + if (!is_conf || + (is_conf && !session->locked)) { + gchar *label = g_strdup_printf(_("Invite to '%s'"), + chat_session->title); + menu = sipe_backend_buddy_menu_add(SIPE_CORE_PUBLIC, + menu, + label, + SIPE_BUDDY_MENU_INVITE_TO_CHAT, + chat_session); + g_free(label); + } + } + } + } SIPE_SESSION_FOREACH_END; + + menu = sipe_backend_buddy_menu_add(SIPE_CORE_PUBLIC, + menu, + _("New chat"), + SIPE_BUDDY_MENU_NEW_CHAT, + NULL); + + /*--------------------- START WIP ------------------------------*/ + + g_free(self); + + return(menu); +} + /* Local Variables: mode: c diff --git a/src/core/sipe-conf.c b/src/core/sipe-conf.c index bfff65c2..95078d91 100644 --- a/src/core/sipe-conf.c +++ b/src/core/sipe-conf.c @@ -1177,6 +1177,35 @@ sipe_process_imdn(struct sipe_core_private *sipe_private, g_free(with); } +void sipe_core_conf_make_leader(struct sipe_core_public *sipe_public, + gpointer parameter, + const gchar *buddy_name) +{ + struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE; + struct sipe_chat_session *chat_session = parameter; + struct sip_session *session; + + SIPE_DEBUG_INFO("sipe_core_conf_make_leader: chat_title=%s", + chat_session->title); + + session = sipe_session_find_chat(sipe_private, chat_session); + sipe_conf_modify_user_role(sipe_private, session, buddy_name); +} + +void sipe_core_conf_remove_from(struct sipe_core_public *sipe_public, + gpointer parameter, + const gchar *buddy_name) +{ + struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE; + struct sipe_chat_session *chat_session = parameter; + struct sip_session *session; + + SIPE_DEBUG_INFO("sipe_core_conf_remove_from: chat_title=%s", + chat_session->title); + + session = sipe_session_find_chat(sipe_private, chat_session); + sipe_conf_delete_user(sipe_private, session, buddy_name); +} /* Local Variables: diff --git a/src/core/sipe-core.c b/src/core/sipe-core.c index 11dfecd9..3152696e 100644 --- a/src/core/sipe-core.c +++ b/src/core/sipe-core.c @@ -55,7 +55,6 @@ #include "sipe-subscriptions.h" #include "sipe-svc.h" #include "sipe-utils.h" -#include "sipe.h" /* locale_dir is unused if ENABLE_NLS is not defined */ void sipe_core_init(SIPE_UNUSED_PARAMETER const char *locale_dir) @@ -303,7 +302,7 @@ void sipe_core_connection_cleanup(struct sipe_core_private *sipe_private) sipe_ocs2007_free(sipe_private); - sipe_blist_menu_free_containers(sipe_private); + sipe_core_buddy_menu_free(SIPE_CORE_PUBLIC); if (sipe_private->contact) g_free(sipe_private->contact); diff --git a/src/core/sipe-ocs2007.c b/src/core/sipe-ocs2007.c index 5233bf58..aa832cc3 100644 --- a/src/core/sipe-ocs2007.c +++ b/src/core/sipe-ocs2007.c @@ -268,7 +268,7 @@ static void free_container_member(struct sipe_container_member *member) g_free(member); } -void sipe_ocs2007_free_container(struct sipe_container *container) +static void sipe_ocs2007_free_container(struct sipe_container *container) { GSList *entry; @@ -283,6 +283,25 @@ void sipe_ocs2007_free_container(struct sipe_container *container) g_free(container); } +void sipe_core_buddy_menu_free(struct sipe_core_public *sipe_public) +{ + struct sipe_core_private *sipe_private = SIPE_CORE_PRIVATE; + GSList *entry = sipe_private->blist_menu_containers; + while (entry) { + sipe_ocs2007_free_container(entry->data); + entry = entry->next; + } + g_slist_free(sipe_private->blist_menu_containers); + sipe_private->blist_menu_containers = NULL; +} + +void sipe_ocs2007_blist_menu_remember_container(struct sipe_core_private *sipe_private, + struct sipe_container *container) +{ + sipe_private->blist_menu_containers = g_slist_prepend(sipe_private->blist_menu_containers, + container); +} + struct sipe_container *sipe_ocs2007_create_container(guint index, const gchar *member_type, const gchar *member_value, diff --git a/src/core/sipe-ocs2007.h b/src/core/sipe-ocs2007.h index 85f90077..1d52d268 100644 --- a/src/core/sipe-ocs2007.h +++ b/src/core/sipe-ocs2007.h @@ -59,7 +59,6 @@ void sipe_ocs2007_process_roaming_self(struct sipe_core_private *sipe_private, guint sipe_ocs2007_containers(void); const gchar *sipe_ocs2007_access_level_name(guint id); int sipe_ocs2007_container_id(guint index); -void sipe_ocs2007_free_container(struct sipe_container *container); struct sipe_container *sipe_ocs2007_create_container(guint index, const gchar *member_type, const gchar *member_value, @@ -79,6 +78,11 @@ void sipe_ocs2007_change_access_level_for_domain(struct sipe_core_private *sipe_ guint index); GSList *sipe_ocs2007_get_access_domains(struct sipe_core_private *sipe_private); +/* buddy menu */ +void sipe_ocs2007_blist_menu_remember_container(struct sipe_core_private *sipe_private, + struct sipe_container *container); + + /* Local Variables: mode: c diff --git a/src/core/sipe.c b/src/core/sipe.c index 0001cdf1..08932815 100644 --- a/src/core/sipe.c +++ b/src/core/sipe.c @@ -4,7 +4,9 @@ ***************************************************************************** *** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *** *** *** - *** THIS MODULE IS DEPECRATED *** + *** THIS MODULE IS NO LONGER COMPILED *** + *** *** + *** YES, IT IS INTENTIONALLY BROKEN.... *** *** *** *** DO NOT ADD ANY NEW CODE TO THIS MODULE *** *** *** @@ -43,36 +45,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "sipe-common.h" - -#include "account.h" -#include "blist.h" -#include "connection.h" -#include "notify.h" -#include "request.h" - -#include "core-depurple.h" /* Temporary for the core de-purple transition */ - -#include "sip-csta.h" -#include "sipe-backend.h" -#include "sipe-chat.h" -#include "sipe-conf.h" -#include "sipe-core.h" -#include "sipe-core-private.h" -#include "sipe-im.h" -#include "sipe-nls.h" -#include "sipe-ocs2007.h" -#include "sipe-session.h" -#include "sipe-utils.h" - -#include "sipe.h" - /** for Access levels menu */ #define INDENT_FMT " %s" @@ -153,85 +125,6 @@ sipe_buddy_menu_copy_to_cb(PurpleBlistNode *node, const char *group_name) } static void -sipe_buddy_menu_chat_new_cb(PurpleBuddy *buddy) -{ - struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE; - - SIPE_DEBUG_INFO("sipe_buddy_menu_chat_new_cb: buddy->name=%s", buddy->name); - - /* 2007+ conference */ - if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) - { - sipe_conf_add(sipe_private, buddy->name); - } - else /* 2005- multiparty chat */ - { - gchar *self = sip_uri_self(sipe_private); - struct sip_session *session; - - session = sipe_session_add_chat(sipe_private, - NULL, - TRUE, - self); - session->chat_session->backend = sipe_backend_chat_create(SIPE_CORE_PUBLIC, - session->chat_session, - session->chat_session->title, - self); - g_free(self); - - sipe_im_invite(sipe_private, session, buddy->name, NULL, NULL, NULL, FALSE); - } -} - -/** - * For 2007+ conference only. - */ -static void -sipe_buddy_menu_chat_make_leader_cb(PurpleBuddy *buddy, - struct sipe_chat_session *chat_session) -{ - struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE; - struct sip_session *session; - - SIPE_DEBUG_INFO("sipe_buddy_menu_chat_make_leader_cb: buddy->name=%s", buddy->name); - SIPE_DEBUG_INFO("sipe_buddy_menu_chat_make_leader_cb: chat_title=%s", chat_session->title); - - session = sipe_session_find_chat(sipe_private, chat_session); - - sipe_conf_modify_user_role(sipe_private, session, buddy->name); -} - -/** - * For 2007+ conference only. - */ -static void -sipe_buddy_menu_chat_remove_cb(PurpleBuddy *buddy, - struct sipe_chat_session *chat_session) -{ - struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE; - struct sip_session *session; - - SIPE_DEBUG_INFO("sipe_buddy_menu_chat_remove_cb: buddy->name=%s", buddy->name); - SIPE_DEBUG_INFO("sipe_buddy_menu_chat_remove_cb: chat_title=%s", chat_session->title); - - session = sipe_session_find_chat(sipe_private, chat_session); - - sipe_conf_delete_user(sipe_private, session, buddy->name); -} - -static void -sipe_buddy_menu_chat_invite_cb(PurpleBuddy *buddy, - struct sipe_chat_session *chat_session) -{ - struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE; - - SIPE_DEBUG_INFO("sipe_buddy_menu_chat_invite_cb: buddy->name=%s", buddy->name); - SIPE_DEBUG_INFO("sipe_buddy_menu_chat_invite_cb: chat_title=%s", chat_session->title); - - sipe_core_chat_invite(SIPE_CORE_PUBLIC, chat_session, buddy->name); -} - -static void sipe_buddy_menu_make_call_cb(PurpleBuddy *buddy, const char *phone) { struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE; @@ -299,77 +192,15 @@ static GList * sipe_get_access_control_menu(struct sipe_core_private *sipe_private, const char* uri); -/* - * A menu which appear when right-clicking on buddy in contact list. - */ -GList * -sipe_buddy_menu(PurpleBuddy *buddy) +struct sipe_backend_buddy_menu *sipe_core_buddy_create_menu(struct sipe_core_public *sipe_public, + const gchar *buddy, + struct sipe_backend_buddy_menu *menu) { - PurpleBlistNode *g_node; - PurpleGroup *gr_parent; - PurpleMenuAction *act; - GList *menu = NULL; - GList *menu_groups = NULL; - struct sipe_core_private *sipe_private = PURPLE_BUDDY_TO_SIPE_CORE_PRIVATE; + struct sipe_backend_buddy_menu *menu_groups = sipe_backend_buddy_menu_start(sipe_p gchar *email; - gchar *self = sip_uri_self(sipe_private); - - SIPE_SESSION_FOREACH { - if (!sipe_strcase_equal(self, buddy->name) && session->chat_session) - { - struct sipe_chat_session *chat_session = session->chat_session; - gboolean is_conf = (chat_session->type == SIPE_CHAT_TYPE_CONFERENCE); - - if (sipe_backend_chat_find(chat_session->backend, buddy->name)) - { - gboolean conf_op = sipe_backend_chat_is_operator(chat_session->backend, self); - - if (is_conf - && !sipe_backend_chat_is_operator(chat_session->backend, buddy->name) /* Not conf OP */ - && conf_op) /* We are a conf OP */ - { - gchar *label = g_strdup_printf(_("Make leader of '%s'"), - chat_session->title); - act = purple_menu_action_new(label, - PURPLE_CALLBACK(sipe_buddy_menu_chat_make_leader_cb), - chat_session, NULL); - g_free(label); - menu = g_list_prepend(menu, act); - } - - if (is_conf - && conf_op) /* We are a conf OP */ - { - gchar *label = g_strdup_printf(_("Remove from '%s'"), - chat_session->title); - act = purple_menu_action_new(label, - PURPLE_CALLBACK(sipe_buddy_menu_chat_remove_cb), - chat_session, NULL); - g_free(label); - menu = g_list_prepend(menu, act); - } - } - else - { - if (!is_conf - || (is_conf && !session->locked)) - { - gchar *label = g_strdup_printf(_("Invite to '%s'"), - chat_session->title); - act = purple_menu_action_new(label, - PURPLE_CALLBACK(sipe_buddy_menu_chat_invite_cb), - chat_session, NULL); - g_free(label); - menu = g_list_prepend(menu, act); - } - } - } - } SIPE_SESSION_FOREACH_END; - act = purple_menu_action_new(_("New chat"), - PURPLE_CALLBACK(sipe_buddy_menu_chat_new_cb), - NULL, NULL); - menu = g_list_prepend(menu, act); + /*--------------------- START WIP ------------------------------*/ + if (sipe_private->csta && !sipe_private->csta->line_status) { gchar *phone; @@ -520,10 +351,7 @@ sipe_buddy_menu(PurpleBuddy *buddy) NULL, menu_groups); menu = g_list_prepend(menu, act); - menu = g_list_reverse(menu); - - g_free(self); - return menu; +/*--------------------- END WIP ------------------------------*/ } static void @@ -570,39 +398,6 @@ static void sipe_buddy_menu_access_level_add_domain_cb(PurpleBuddy *buddy) buddy->account, NULL, NULL, gc); } -/* - * Workaround for missing libpurple API to release resources allocated - * during blist_node_menu() callback. See also: - * - * - * - * We remember all memory blocks in a list and deallocate them when - * - * - the next time we enter the callback, or - * - the account is disconnected - * - * That means that after the buddy menu has been closed we have unused - * resources but at least we don't leak them anymore... - */ -void sipe_blist_menu_free_containers(struct sipe_core_private *sipe_private) -{ - GSList *entry = sipe_private->blist_menu_containers; - while (entry) { - sipe_ocs2007_free_container(entry->data); - entry = entry->next; - } - g_slist_free(sipe_private->blist_menu_containers); - sipe_private->blist_menu_containers = NULL; -} - -static void -sipe_blist_menu_remember_container(struct sipe_core_private *sipe_private, - struct sipe_container *container) -{ - sipe_private->blist_menu_containers = g_slist_prepend(sipe_private->blist_menu_containers, - container); -} - static GList * sipe_get_access_levels_menu(struct sipe_core_private *sipe_private, const char* member_type, diff --git a/src/core/sipe.h b/src/core/sipe.h deleted file mode 100644 index 8e630527..00000000 --- a/src/core/sipe.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @file sipe.h - * - ***************************************************************************** - *** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *** - *** *** - *** THIS INTERFACE IS DEPECRATED *** - *** *** - *** DO NOT INCLUDE IT IN ANY NEW CODE *** - *** *** - *** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *** - ***************************************************************************** - * - * pidgin-sipe - * - * Copyright (C) 2010-11 SIPE Project - * Copyright (C) 2008 Novell, Inc. - * Copyright (C) 2007 Anibal Avelar - * Copyright (C) 2005 Thomas Butter - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* Forward declarations */ -struct sipe_core_private; - -/** - * THE BIG SPLIT - temporary interfaces - * - * Previously private functions in sipe.c that are - * - waiting to be factored out to an appropriate module - * - are needed by the already created new modules - */ - -/* libpurple memory leak workaround */ -void sipe_blist_menu_free_containers(struct sipe_core_private *sipe_private); - -/*** THE BIG SPLIT END ***/ diff --git a/src/purple/Makefile.am b/src/purple/Makefile.am index 6c426425..f781c243 100644 --- a/src/purple/Makefile.am +++ b/src/purple/Makefile.am @@ -53,7 +53,6 @@ libsipe_la_LIBADD = \ ../core/libsipe_core.la \ ../core/libsipe_core_crypto_nss.la \ ../core/libsipe_core_libxml2.la \ - ../core/libsipe_core_purple.la \ libsipe_backend.la \ $(LIBXML2_LIBS) \ $(NSS_LIBS) \ diff --git a/src/purple/purple-buddy.c b/src/purple/purple-buddy.c index d27dc3dd..fa13adcc 100644 --- a/src/purple/purple-buddy.c +++ b/src/purple/purple-buddy.c @@ -418,6 +418,102 @@ void sipe_purple_group_buddy(PurpleConnection *gc, sipe_core_buddy_group(PURPLE_GC_TO_SIPE_CORE_PUBLIC, who, old_group_name, new_group_name); } +/* Buddy Menu Handling */ + +static void sipe_purple_buddy_make_chat_leader_cb(PurpleBuddy *buddy, + gpointer parameter) +{ + SIPE_DEBUG_INFO("sipe_purple_buddy_make_chat_leader_cb: buddy->name=%s", + buddy->name); + sipe_core_conf_make_leader(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC, + parameter, + buddy->name); +} + +static void sipe_purple_buddy_remove_from_chat_cb(PurpleBuddy *buddy, + gpointer parameter) +{ + SIPE_DEBUG_INFO("sipe_purple_buddy_remove_from_chat_cb: buddy->name=%s", + buddy->name); + sipe_core_conf_remove_from(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC, + parameter, + buddy->name); +} + +static void sipe_purple_buddy_invite_to_chat_cb(PurpleBuddy *buddy, + gpointer parameter) +{ + SIPE_DEBUG_INFO("sipe_purple_buddy_invite_to_chat_cb: buddy->name=%s", + buddy->name); + sipe_core_chat_invite(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC, + parameter, + buddy->name); +} + +static void sipe_purple_buddy_new_chat_cb(PurpleBuddy *buddy, + SIPE_UNUSED_PARAMETER gpointer parameter) +{ + SIPE_DEBUG_INFO("sipe_purple_buddy_new_chat_cb: buddy->name=%s", + buddy->name); + sipe_core_buddy_new_chat(PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC, + buddy->name); +} + +typedef void (*buddy_menu_callback)(PurpleBuddy *buddy, + gpointer parameter); +static const buddy_menu_callback callback_map[SIPE_BUDDY_MENU_TYPES] = { + /* SIPE_BUDDY_MENU_MAKE_CHAT_LEADER */ sipe_purple_buddy_make_chat_leader_cb, + /* SIPE_BUDDY_MENU_REMOVE_FROM_CHAT */ sipe_purple_buddy_remove_from_chat_cb, + /* SIPE_BUDDY_MENU_INVITE_TO_CHAT */ sipe_purple_buddy_invite_to_chat_cb, + /* SIPE_BUDDY_MENU_NEW_CHAT */ sipe_purple_buddy_new_chat_cb, +}; + +struct sipe_backend_buddy_menu *sipe_backend_buddy_menu_start(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public) +{ + return(NULL); +} + +struct sipe_backend_buddy_menu *sipe_backend_buddy_menu_add(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public, + struct sipe_backend_buddy_menu *menu, + const gchar *label, + enum sipe_buddy_menu_type type, + gpointer parameter) +{ + return((struct sipe_backend_buddy_menu *) + g_list_prepend((GList *) menu, + purple_menu_action_new(label, + PURPLE_CALLBACK(callback_map[type]), + parameter, NULL))); +} + +GList *sipe_purple_buddy_menu(PurpleBuddy *buddy) +{ + struct sipe_core_public *sipe_public = PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC; + + /* + * Workaround for missing libpurple API to release resources allocated + * during blist_node_menu() callback. See also: + * + * + * + * We remember all memory blocks in a list and deallocate them when + * + * - the next time we enter the callback, or + * - the account is disconnected + * + * That means that after the buddy menu has been closed we have unused + * resources but at least we don't leak them anymore... + */ + sipe_core_buddy_menu_free(sipe_public); + + /* now create the new menu... */ + return(g_list_reverse((GList *) + sipe_core_buddy_create_menu(sipe_public, + buddy->name, + NULL))); +} + + /* Local Variables: mode: c diff --git a/src/purple/purple-plugin.c b/src/purple/purple-plugin.c index 42dabc93..d5765fa5 100644 --- a/src/purple/purple-plugin.c +++ b/src/purple/purple-plugin.c @@ -67,8 +67,6 @@ #include "sipe-core.h" #include "sipe-nls.h" -#include "core-depurple.h" - #define _PurpleMessageFlags PurpleMessageFlags #include "purple-private.h" @@ -77,9 +75,6 @@ #define PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY 0x0100 #endif -/* Convenience macros */ -#define PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC ((struct sipe_core_public *) buddy->account->gc->proto_data) - /* Sipe core activity <-> Purple status mapping */ static const gchar * const activity_to_purple[SIPE_ACTIVITY_NUM_TYPES] = { /* SIPE_ACTIVITY_UNSET */ "unset", /* == purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) */ @@ -232,7 +227,7 @@ static GList *sipe_purple_status_types(SIPE_UNUSED_PARAMETER PurpleAccount *acc) static GList *sipe_purple_blist_node_menu(PurpleBlistNode *node) { if(PURPLE_BLIST_NODE_IS_BUDDY(node)) { - return sipe_buddy_menu((PurpleBuddy *) node); + return sipe_purple_buddy_menu((PurpleBuddy *) node); } else if(PURPLE_BLIST_NODE_IS_CHAT(node)) { return sipe_purple_chat_menu((PurpleChat *)node); } else { diff --git a/src/purple/purple-private.h b/src/purple/purple-private.h index 742a8b5e..78bd5eb2 100644 --- a/src/purple/purple-private.h +++ b/src/purple/purple-private.h @@ -108,6 +108,7 @@ void sipe_purple_group_buddy(struct _PurpleConnection *gc, const char *who, const char *old_group_name, const char *new_group_name); +GList *sipe_purple_buddy_menu(struct _PurpleBuddy *buddy); /* libpurple status callbacks */ void sipe_purple_set_status(struct _PurpleAccount *account, @@ -117,6 +118,7 @@ void sipe_purple_set_idle(struct _PurpleConnection *gc, /* Convenience macros */ #define PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC ((struct sipe_core_public *) account->gc->proto_data) +#define PURPLE_BUDDY_TO_SIPE_CORE_PUBLIC ((struct sipe_core_public *) buddy->account->gc->proto_data) #define PURPLE_GC_TO_SIPE_CORE_PUBLIC ((struct sipe_core_public *) gc->proto_data) /* -- 2.11.4.GIT