From 6e3a4db91e3f2c664e36005845bed46b5c4bac59 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 4 Dec 2011 16:13:57 +0200 Subject: [PATCH] core cleanup: separate code for sipe_backend_account_status_and_note() --- src/api/sipe-backend.h | 6 +++ src/core/Makefile.mingw | 1 + src/core/sipe-ocs2007.c | 3 +- src/core/sipe-status.c | 23 ++++++++++ src/core/sipe-status.h | 6 +++ src/core/sipe.c | 78 +++----------------------------- src/core/sipe.h | 5 +-- src/purple/Makefile.am | 1 + src/purple/purple-status.c | 108 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 153 insertions(+), 78 deletions(-) create mode 100644 src/purple/purple-status.c diff --git a/src/api/sipe-backend.h b/src/api/sipe-backend.h index 3cc2dbcd..a4bbc949 100644 --- a/src/api/sipe-backend.h +++ b/src/api/sipe-backend.h @@ -556,6 +556,12 @@ typedef enum { const gchar *sipe_backend_setting(struct sipe_core_public *sipe_public, sipe_setting type); +/** STATUS *******************************************************************/ + +gboolean sipe_backend_status_and_note(struct sipe_core_public *sipe_public, + const gchar *status_id, + const gchar *message); + /** TRANSPORT ****************************************************************/ typedef void transport_connected_cb(struct sipe_transport_connection *conn); diff --git a/src/core/Makefile.mingw b/src/core/Makefile.mingw index c2997bb0..0a4e3b6e 100644 --- a/src/core/Makefile.mingw +++ b/src/core/Makefile.mingw @@ -137,6 +137,7 @@ PURPLE_C_SRC = ../purple/purple-buddy.c \ ../purple/purple-schedule.c \ ../purple/purple-search.c \ ../purple/purple-setting.c \ + ../purple/purple-status.c \ ../purple/purple-transport.c \ ../purple/purple-user.c \ sipe-utils.c \ diff --git a/src/core/sipe-ocs2007.c b/src/core/sipe-ocs2007.c index c9a975d9..92256934 100644 --- a/src/core/sipe-ocs2007.c +++ b/src/core/sipe-ocs2007.c @@ -50,6 +50,7 @@ #include "sipe-nls.h" #include "sipe-ocs2007.h" #include "sipe-schedule.h" +#include "sipe-status.h" #include "sipe-utils.h" #include "sipe-xml.h" @@ -2216,7 +2217,7 @@ void sipe_ocs2007_process_roaming_self(struct sipe_core_private *sipe_private, if (do_update_status) { SIPE_DEBUG_INFO("sipe_ocs2007_process_roaming_self: switch to '%s' for the account", sip->status); - sipe_backend_account_status_and_note(sipe_private, sip->status); + sipe_status_and_note(sipe_private, sip->status); } g_free(to); diff --git a/src/core/sipe-status.c b/src/core/sipe-status.c index b9d5764a..3da4bb6e 100644 --- a/src/core/sipe-status.c +++ b/src/core/sipe-status.c @@ -21,13 +21,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include +#include "sipe-backend.h" #include "sipe-core.h" #include "sipe-core-private.h" #include "sipe-ocs2005.h" #include "sipe-ocs2007.h" #include "sipe-status.h" +#define _SIPE_NEED_ACTIVITIES +#include "sipe.h" void sipe_core_reset_status(struct sipe_core_public *sipe_public) { @@ -38,6 +43,24 @@ void sipe_core_reset_status(struct sipe_core_public *sipe_public) sipe_ocs2005_reset_status(sipe_private); } +void sipe_status_and_note(struct sipe_core_private *sipe_private, + const gchar *status_id) +{ + struct sipe_account_data *sip = SIPE_ACCOUNT_DATA_PRIVATE; + gboolean changed = sipe_backend_status_and_note(SIPE_CORE_PUBLIC, + status_id, + sip->note); + + if (changed) { + sipe_activity activity = sipe_activity_from_token(status_id); + + sip->do_not_publish[activity] = time(NULL); + SIPE_DEBUG_INFO("sipe_status_and_note: do_not_publish[%s]=%d [now]", + status_id, + (int) sip->do_not_publish[activity]); + } +} + /* Local Variables: mode: c diff --git a/src/core/sipe-status.h b/src/core/sipe-status.h index f0233e7f..ffd15771 100644 --- a/src/core/sipe-status.h +++ b/src/core/sipe-status.h @@ -21,6 +21,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* Forward declarations */ +struct sipe_core_private; + +void sipe_status_and_note(struct sipe_core_private *sipe_private, + const gchar *status_id); + /* Local Variables: mode: c diff --git a/src/core/sipe.c b/src/core/sipe.c index 0ef6f9be..f134a6d9 100644 --- a/src/core/sipe.c +++ b/src/core/sipe.c @@ -69,7 +69,6 @@ #include "plugin.h" #include "privacy.h" #include "request.h" -#include "savedstatuses.h" #include "version.h" #include "core-depurple.h" /* Temporary for the core de-purple transition */ @@ -92,6 +91,7 @@ #include "sipe-ocs2007.h" #include "sipe-schedule.h" #include "sipe-session.h" +#include "sipe-status.h" #include "sipe-subscriptions.h" #include "sipe-utils.h" #include "sipe-xml.h" @@ -191,8 +191,7 @@ void sipe_set_invisible_status(struct sipe_core_private *sipe_private) sip->status = g_strdup(SIPE_STATUS_ID_INVISIBLE); } -static sipe_activity -sipe_get_activity_by_token(const char *token) +sipe_activity sipe_activity_from_token(const gchar *token) { int i; @@ -209,7 +208,7 @@ const gchar *sipe_activity_description_from_token(const gchar *token) { if (!token) return NULL; - return sipe_activity_description(sipe_get_activity_by_token(token)); + return sipe_activity_description(sipe_activity_from_token(token)); } void @@ -280,7 +279,7 @@ sipe_apply_calendar_status(struct sipe_core_private *sipe_private, } SIPE_DEBUG_INFO("sipe_apply_calendar_status: switch to '%s' for the account", sip->status); - sipe_backend_account_status_and_note(sipe_private, status_id); + sipe_status_and_note(sipe_private, status_id); } g_free(self_uri); } @@ -302,7 +301,7 @@ void sipe_set_status(PurpleAccount *account, PurpleStatus *status) time_t now = time(NULL); const char *status_id = purple_status_get_id(status); const char *note = purple_status_get_attr_string(status, SIPE_STATUS_ATTR_ID_MESSAGE); - sipe_activity activity = sipe_get_activity_by_token(status_id); + sipe_activity activity = sipe_activity_from_token(status_id); gboolean do_not_publish = ((now - sip->do_not_publish[activity]) <= 2); /* when other point of presence clears note, but we are keeping @@ -498,73 +497,6 @@ sipe_get_first_last_names(struct sipe_core_private *sipe_private, g_strfreev(parts); } -/** - * This method motivates Purple's Host (e.g. Pidgin) to update its UI - * by using standard Purple's means of signals and saved statuses. - * - * Thus all UI elements get updated: Status Button with Note, docklet. - * This is ablolutely important as both our status and note can come - * inbound (roaming) or be updated programmatically (e.g. based on our - * calendar data). - */ -void sipe_backend_account_status_and_note(struct sipe_core_private *sipe_private, - const gchar *status_id) -{ - struct sipe_account_data *sip = SIPE_ACCOUNT_DATA_PRIVATE; - PurpleAccount *account = sip->account; - PurpleStatus *status = purple_account_get_active_status(account); - const gchar *message = sip->note; - time_t *do_not_publish = sip->do_not_publish; - gboolean changed = TRUE; - - if (g_str_equal(status_id, purple_status_get_id(status)) && - sipe_strequal(message, purple_status_get_attr_string(status, SIPE_STATUS_ATTR_ID_MESSAGE))) - { - changed = FALSE; - } - - if (purple_savedstatus_is_idleaway()) { - changed = FALSE; - } - - if (changed) { - PurpleSavedStatus *saved_status; - const PurpleStatusType *acct_status_type = - purple_status_type_find_with_id(account->status_types, status_id); - PurpleStatusPrimitive primitive = purple_status_type_get_primitive(acct_status_type); - sipe_activity activity = sipe_get_activity_by_token(status_id); - - saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, message); - if (saved_status) { - purple_savedstatus_set_substatus(saved_status, account, acct_status_type, message); - } - - /* If this type+message is unique then create a new transient saved status - * Ref: gtkstatusbox.c - */ - if (!saved_status) { - GList *tmp; - GList *active_accts = purple_accounts_get_all_active(); - - saved_status = purple_savedstatus_new(NULL, primitive); - purple_savedstatus_set_message(saved_status, message); - - for (tmp = active_accts; tmp != NULL; tmp = tmp->next) { - purple_savedstatus_set_substatus(saved_status, - (PurpleAccount *)tmp->data, acct_status_type, message); - } - g_list_free(active_accts); - } - - do_not_publish[activity] = time(NULL); - SIPE_DEBUG_INFO("sipe_set_purple_account_status_and_note: do_not_publish[%s]=%d [now]", - status_id, (int)do_not_publish[activity]); - - /* Set the status for each account */ - purple_savedstatus_activate(saved_status); - } -} - /* IM Session (INVITE and MESSAGE methods) */ static gboolean diff --git a/src/core/sipe.h b/src/core/sipe.h index 84c40750..0d9c2a51 100644 --- a/src/core/sipe.h +++ b/src/core/sipe.h @@ -115,6 +115,7 @@ struct sipe_account_data { /* need to improve or reduce visibility of this interface */ const gchar *sipe_activity_to_token(sipe_activity); const gchar *sipe_activity_description(sipe_activity); +sipe_activity sipe_activity_from_token(const gchar *token); const gchar *sipe_activity_description_from_token(const gchar *token); #endif void sipe_set_unknown_status(struct sipe_core_private *sipe_private); @@ -141,10 +142,6 @@ void sipe_apply_calendar_status(struct sipe_core_private *sipe_private, /* libpurple memory leak workaround */ void sipe_blist_menu_free_containers(struct sipe_core_private *sipe_private); -/* this should be in backend? */ -void sipe_backend_account_status_and_note(struct sipe_core_private *sipe_private, - const gchar *status_id); - /** * referenced by sipe-notify.c - start */ diff --git a/src/purple/Makefile.am b/src/purple/Makefile.am index bdc40376..6c426425 100644 --- a/src/purple/Makefile.am +++ b/src/purple/Makefile.am @@ -23,6 +23,7 @@ libsipe_backend_la_SOURCES = \ purple-schedule.c \ purple-search.c \ purple-setting.c \ + purple-status.c \ purple-transport.c \ purple-user.c diff --git a/src/purple/purple-status.c b/src/purple/purple-status.c new file mode 100644 index 00000000..b2970908 --- /dev/null +++ b/src/purple/purple-status.c @@ -0,0 +1,108 @@ +/** + * @file purple-status.c + * + * pidgin-sipe + * + * Copyright (C) 2011 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 + */ + +#include + +#include "account.h" +#include "savedstatuses.h" + +#include "sipe-backend.h" +#include "sipe-core.h" + +#include "purple-private.h" + +/* Status attributes */ +#define PURPLE_STATUS_ATTR_ID_MESSAGE "message" + +/** + * This method motivates Purple's Host (e.g. Pidgin) to update its UI + * by using standard Purple's means of signals and saved statuses. + * + * Thus all UI elements get updated: Status Button with Note, docklet. + * This is ablolutely important as both our status and note can come + * inbound (roaming) or be updated programmatically (e.g. based on our + * calendar data). + */ +gboolean sipe_backend_status_and_note(struct sipe_core_public *sipe_public, + const gchar *status_id, + const gchar *message) +{ + struct sipe_backend_private *purple_private = sipe_public->backend_private; + PurpleAccount *account = purple_private->account; + PurpleStatus *status = purple_account_get_active_status(account); + gboolean changed = TRUE; + + if (g_str_equal(status_id, purple_status_get_id(status)) && + sipe_strequal(message, + purple_status_get_attr_string(status, + PURPLE_STATUS_ATTR_ID_MESSAGE))) + { + changed = FALSE; + } + + if (purple_savedstatus_is_idleaway()) { + changed = FALSE; + } + + if (changed) { + PurpleSavedStatus *saved_status; + const PurpleStatusType *acct_status_type = + purple_status_type_find_with_id(account->status_types, status_id); + PurpleStatusPrimitive primitive = purple_status_type_get_primitive(acct_status_type); + + saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, message); + if (saved_status) { + purple_savedstatus_set_substatus(saved_status, account, acct_status_type, message); + } + + /* If this type+message is unique then create a new transient saved status + * Ref: gtkstatusbox.c + */ + if (!saved_status) { + GList *tmp; + GList *active_accts = purple_accounts_get_all_active(); + + saved_status = purple_savedstatus_new(NULL, primitive); + purple_savedstatus_set_message(saved_status, message); + + for (tmp = active_accts; tmp != NULL; tmp = tmp->next) { + purple_savedstatus_set_substatus(saved_status, + (PurpleAccount *)tmp->data, acct_status_type, message); + } + g_list_free(active_accts); + } + + /* Set the status for each account */ + purple_savedstatus_activate(saved_status); + } + + return(changed); +} + +/* + Local Variables: + mode: c + c-file-style: "bsd" + indent-tabs-mode: t + tab-width: 8 + End: +*/ -- 2.11.4.GIT