core cleanup: separate code for sipe_backend_account_status_and_note()
[siplcs.git] / src / purple / purple-status.c
blobb297090821bd2d9c0ccd0504aa712ae4f98eef95
1 /**
2 * @file purple-status.c
4 * pidgin-sipe
6 * Copyright (C) 2011 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 #include <glib.h>
25 #include "account.h"
26 #include "savedstatuses.h"
28 #include "sipe-backend.h"
29 #include "sipe-core.h"
31 #include "purple-private.h"
33 /* Status attributes */
34 #define PURPLE_STATUS_ATTR_ID_MESSAGE "message"
36 /**
37 * This method motivates Purple's Host (e.g. Pidgin) to update its UI
38 * by using standard Purple's means of signals and saved statuses.
40 * Thus all UI elements get updated: Status Button with Note, docklet.
41 * This is ablolutely important as both our status and note can come
42 * inbound (roaming) or be updated programmatically (e.g. based on our
43 * calendar data).
45 gboolean sipe_backend_status_and_note(struct sipe_core_public *sipe_public,
46 const gchar *status_id,
47 const gchar *message)
49 struct sipe_backend_private *purple_private = sipe_public->backend_private;
50 PurpleAccount *account = purple_private->account;
51 PurpleStatus *status = purple_account_get_active_status(account);
52 gboolean changed = TRUE;
54 if (g_str_equal(status_id, purple_status_get_id(status)) &&
55 sipe_strequal(message,
56 purple_status_get_attr_string(status,
57 PURPLE_STATUS_ATTR_ID_MESSAGE)))
59 changed = FALSE;
62 if (purple_savedstatus_is_idleaway()) {
63 changed = FALSE;
66 if (changed) {
67 PurpleSavedStatus *saved_status;
68 const PurpleStatusType *acct_status_type =
69 purple_status_type_find_with_id(account->status_types, status_id);
70 PurpleStatusPrimitive primitive = purple_status_type_get_primitive(acct_status_type);
72 saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, message);
73 if (saved_status) {
74 purple_savedstatus_set_substatus(saved_status, account, acct_status_type, message);
77 /* If this type+message is unique then create a new transient saved status
78 * Ref: gtkstatusbox.c
80 if (!saved_status) {
81 GList *tmp;
82 GList *active_accts = purple_accounts_get_all_active();
84 saved_status = purple_savedstatus_new(NULL, primitive);
85 purple_savedstatus_set_message(saved_status, message);
87 for (tmp = active_accts; tmp != NULL; tmp = tmp->next) {
88 purple_savedstatus_set_substatus(saved_status,
89 (PurpleAccount *)tmp->data, acct_status_type, message);
91 g_list_free(active_accts);
94 /* Set the status for each account */
95 purple_savedstatus_activate(saved_status);
98 return(changed);
102 Local Variables:
103 mode: c
104 c-file-style: "bsd"
105 indent-tabs-mode: t
106 tab-width: 8
107 End: