core cleanup: move code for "copy to" menu to purple backend
[siplcs.git] / src / purple / purple-status.c
blob6872ba5fd2aabf4cbf7615e1abe7ee1d68472cda
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 const gchar *sipe_backend_status(struct sipe_core_public *sipe_public)
35 struct sipe_backend_private *purple_private = sipe_public->backend_private;
36 PurpleStatus *status = purple_account_get_active_status(purple_private->account);
37 if (!status) return(NULL);
38 return(purple_status_get_id(status));
41 /**
42 * This method motivates Purple's Host (e.g. Pidgin) to update its UI
43 * by using standard Purple's means of signals and saved statuses.
45 * Thus all UI elements get updated: Status Button with Note, docklet.
46 * This is ablolutely important as both our status and note can come
47 * inbound (roaming) or be updated programmatically (e.g. based on our
48 * calendar data).
50 gboolean sipe_backend_status_and_note(struct sipe_core_public *sipe_public,
51 const gchar *status_id,
52 const gchar *message)
54 struct sipe_backend_private *purple_private = sipe_public->backend_private;
55 PurpleAccount *account = purple_private->account;
56 PurpleStatus *status = purple_account_get_active_status(account);
57 gboolean changed = TRUE;
59 if (g_str_equal(status_id, purple_status_get_id(status)) &&
60 sipe_strequal(message,
61 purple_status_get_attr_string(status,
62 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE)))
64 changed = FALSE;
67 if (purple_savedstatus_is_idleaway()) {
68 changed = FALSE;
71 if (changed) {
72 PurpleSavedStatus *saved_status;
73 const PurpleStatusType *acct_status_type =
74 purple_status_type_find_with_id(account->status_types, status_id);
75 PurpleStatusPrimitive primitive = purple_status_type_get_primitive(acct_status_type);
77 saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, message);
78 if (saved_status) {
79 purple_savedstatus_set_substatus(saved_status, account, acct_status_type, message);
82 /* If this type+message is unique then create a new transient saved status
83 * Ref: gtkstatusbox.c
85 if (!saved_status) {
86 GList *tmp;
87 GList *active_accts = purple_accounts_get_all_active();
89 saved_status = purple_savedstatus_new(NULL, primitive);
90 purple_savedstatus_set_message(saved_status, message);
92 for (tmp = active_accts; tmp != NULL; tmp = tmp->next) {
93 purple_savedstatus_set_substatus(saved_status,
94 (PurpleAccount *)tmp->data, acct_status_type, message);
96 g_list_free(active_accts);
99 /* Set the status for each account */
100 purple_savedstatus_activate(saved_status);
103 return(changed);
106 void sipe_purple_set_status(PurpleAccount *account,
107 PurpleStatus *status)
109 SIPE_DEBUG_INFO("sipe_purple_set_status[CB]: status=%s",
110 purple_status_get_id(status));
112 if (!purple_status_is_active(status))
113 return;
115 if (account->gc) {
116 const gchar *status_id = purple_status_get_id(status);
117 const gchar *note = purple_status_get_attr_string(status,
118 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE);
119 sipe_core_status_set(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
120 status_id,
121 note);
125 void sipe_purple_set_idle(PurpleConnection *gc,
126 int interval)
128 SIPE_DEBUG_INFO("sipe_purple_set_idle[CB]: interval=%d", interval);
129 if (gc) sipe_core_status_idle(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
133 Local Variables:
134 mode: c
135 c-file-style: "bsd"
136 indent-tabs-mode: t
137 tab-width: 8
138 End: