From 05ba791f4a46240c7ed165075eddd4e903345eac Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Thu, 2 Aug 2012 10:08:10 +0300 Subject: [PATCH] status: fix broken busy->available switch Commit 6e3a4db91e3f2c664e36005845bed46b5c4bac59 broke the status switching for meeting/phone calls, because the re-factoring didn't take into account that purple_savedstatus_activate() will trigger a call to sipe_purple_set_status(). That code requires do_not_publish[] to be updated already, which in the new code happened *AFTER* the call. Split the functionality of sipe_backend_status_and_note() into two functions and update sipe_status_and_note() accordingly. Updated the code in the Miranda backend too, but it is untested. (cherry picked from commit b7db31744cb52ddf427f65dabf18632b3891f280) --- src/api/sipe-backend.h | 11 ++++-- src/core/sipe-status.c | 13 +++++-- src/miranda/miranda-status.c | 19 +++++++-- src/purple/purple-status.c | 91 +++++++++++++++++++++++--------------------- 4 files changed, 79 insertions(+), 55 deletions(-) diff --git a/src/api/sipe-backend.h b/src/api/sipe-backend.h index 2f892602..09676f46 100644 --- a/src/api/sipe-backend.h +++ b/src/api/sipe-backend.h @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2010-11 SIPE Project + * Copyright (C) 2010-12 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 @@ -562,9 +562,12 @@ const gchar *sipe_backend_setting(struct sipe_core_public *sipe_public, /** STATUS *******************************************************************/ guint sipe_backend_status(struct sipe_core_public *sipe_public); -gboolean sipe_backend_status_and_note(struct sipe_core_public *sipe_public, - guint activity, - const gchar *message); +gboolean sipe_backend_status_changed(struct sipe_core_public *sipe_public, + guint activity, + const gchar *message); +void sipe_backend_status_and_note(struct sipe_core_public *sipe_public, + guint activity, + const gchar *message); /** TRANSPORT ****************************************************************/ diff --git a/src/core/sipe-status.c b/src/core/sipe-status.c index cb4e9d30..e89e5770 100644 --- a/src/core/sipe-status.c +++ b/src/core/sipe-status.c @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2011 SIPE Project + * Copyright (C) 2011-12 SIPE Project * * * This program is free software; you can redistribute it and/or modify @@ -145,14 +145,19 @@ void sipe_status_and_note(struct sipe_core_private *sipe_private, SIPE_DEBUG_INFO("sipe_status_and_note: switch to '%s' for the account", status_id); activity = sipe_status_token_to_activity(status_id); - if (sipe_backend_status_and_note(SIPE_CORE_PUBLIC, - activity, - sipe_private->note)) { + if (sipe_backend_status_changed(SIPE_CORE_PUBLIC, + activity, + sipe_private->note)) { /* status has changed */ sipe_private->do_not_publish[activity] = time(NULL); SIPE_DEBUG_INFO("sipe_status_and_note: do_not_publish[%s]=%d [now]", status_id, (int) sipe_private->do_not_publish[activity]); + + /* update backend status */ + sipe_backend_status_and_note(SIPE_CORE_PUBLIC, + activity, + sipe_private->note); } } diff --git a/src/miranda/miranda-status.c b/src/miranda/miranda-status.c index ba7e060c..cef798fc 100644 --- a/src/miranda/miranda-status.c +++ b/src/miranda/miranda-status.c @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2011 SIPE Project + * Copyright (C) 2011-12 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 @@ -92,9 +92,20 @@ int sipe_miranda_SetStatus( SIPPROTO *pr, int iNewStatus ) return 0; } -gboolean sipe_backend_status_and_note(struct sipe_core_public *sipe_public, - guint activity, - const gchar *message) +gboolean sipe_backend_status_changed(struct sipe_core_public *sipe_public, + guint activity, + const gchar *message) +{ + SIPPROTO *pr = sipe_public->backend_private; + int iNewStatus = SipeStatusToMiranda(activity); + if (!pr->m_hServerNetlibUser) return FALSE; + if (pr->proto.m_iDesiredStatus == iNewStatus) return FALSE; + return(TRUE); +} + +void sipe_backend_status_and_note(struct sipe_core_public *sipe_public, + guint activity, + const gchar *message) { sipe_miranda_SetStatus(sipe_public->backend_private, SipeStatusToMiranda(activity)); } diff --git a/src/purple/purple-status.c b/src/purple/purple-status.c index 25bffe0c..5c1f7e96 100644 --- a/src/purple/purple-status.c +++ b/src/purple/purple-status.c @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2011 SIPE Project + * Copyright (C) 2011-12 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 @@ -38,22 +38,12 @@ guint sipe_backend_status(struct sipe_core_public *sipe_public) return(sipe_purple_token_to_activity(purple_status_get_id(status))); } -/** - * 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, - guint activity, - const gchar *message) +gboolean sipe_backend_status_changed(struct sipe_core_public *sipe_public, + guint activity, + 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); + PurpleStatus *status = purple_account_get_active_status(purple_private->account); const gchar *status_id = sipe_purple_activity_to_token(activity); gboolean changed = TRUE; @@ -69,39 +59,54 @@ gboolean sipe_backend_status_and_note(struct sipe_core_public *sipe_public, 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); + return(changed); +} - 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); - } +/** + * 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_status_and_note(struct sipe_core_public *sipe_public, + guint activity, + const gchar *message) +{ + struct sipe_backend_private *purple_private = sipe_public->backend_private; + PurpleAccount *account = purple_private->account; + const gchar *status_id = sipe_purple_activity_to_token(activity); + 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); - } + /* 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); - /* Set the status for each account */ - purple_savedstatus_activate(saved_status); + 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); } - return(changed); + /* Set the status for each account */ + purple_savedstatus_activate(saved_status); } void sipe_purple_set_status(PurpleAccount *account, -- 2.11.4.GIT