purple: don't use PurpleXfer.fd
[siplcs.git] / src / purple / purple-status.c
blob50c6f163ebb51e0e4460e15b18f35f768cc48f3b
1 /**
2 * @file purple-status.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2013 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 guint 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(SIPE_ACTIVITY_UNSET);
38 return(sipe_purple_token_to_activity(purple_status_get_id(status)));
41 gboolean sipe_backend_status_changed(struct sipe_core_public *sipe_public,
42 guint activity,
43 const gchar *message)
45 struct sipe_backend_private *purple_private = sipe_public->backend_private;
46 PurpleStatus *status = purple_account_get_active_status(purple_private->account);
47 const gchar *status_id = sipe_purple_activity_to_token(activity);
48 gboolean changed = TRUE;
50 if (g_str_equal(status_id, purple_status_get_id(status)) &&
51 sipe_strequal(message,
52 purple_status_get_attr_string(status,
53 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE)))
55 changed = FALSE;
58 if (purple_savedstatus_is_idleaway()) {
59 changed = FALSE;
62 return(changed);
65 /**
66 * This method motivates Purple's Host (e.g. Pidgin) to update its UI
67 * by using standard Purple's means of signals and saved statuses.
69 * Thus all UI elements get updated: Status Button with Note, docklet.
70 * This is ablolutely important as both our status and note can come
71 * inbound (roaming) or be updated programmatically (e.g. based on our
72 * calendar data).
74 void sipe_backend_status_and_note(struct sipe_core_public *sipe_public,
75 guint activity,
76 const gchar *message)
78 struct sipe_backend_private *purple_private = sipe_public->backend_private;
79 PurpleAccount *account = purple_private->account;
80 const gchar *status_id = sipe_purple_activity_to_token(activity);
81 PurpleSavedStatus *saved_status;
82 const PurpleStatusType *acct_status_type =
83 purple_status_type_find_with_id(purple_account_get_status_types(account),
84 status_id);
85 PurpleStatusPrimitive primitive = purple_status_type_get_primitive(acct_status_type);
87 saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, message);
88 if (saved_status) {
89 purple_savedstatus_set_substatus(saved_status, account, acct_status_type, message);
92 /* If this type+message is unique then create a new transient saved status
93 * Ref: gtkstatusbox.c
95 if (!saved_status) {
96 GList *tmp;
97 GList *active_accts = purple_accounts_get_all_active();
99 saved_status = purple_savedstatus_new(NULL, primitive);
100 purple_savedstatus_set_message(saved_status, message);
102 for (tmp = active_accts; tmp != NULL; tmp = tmp->next) {
103 purple_savedstatus_set_substatus(saved_status,
104 (PurpleAccount *)tmp->data, acct_status_type, message);
106 g_list_free(active_accts);
109 /* Set the status for each account */
110 purple_savedstatus_activate(saved_status);
113 void sipe_purple_set_status(PurpleAccount *account,
114 PurpleStatus *status)
116 SIPE_DEBUG_INFO("sipe_purple_set_status[CB]: status=%s",
117 purple_status_get_id(status));
119 if (!purple_status_is_active(status))
120 return;
122 if (purple_account_get_connection(account)) {
123 const gchar *status_id = purple_status_get_id(status);
124 const gchar *note = purple_status_get_attr_string(status,
125 SIPE_PURPLE_STATUS_ATTR_ID_MESSAGE);
126 sipe_core_status_set(PURPLE_ACCOUNT_TO_SIPE_CORE_PUBLIC,
127 sipe_purple_token_to_activity(status_id),
128 note);
132 void sipe_purple_set_idle(PurpleConnection *gc,
133 int interval)
135 SIPE_DEBUG_INFO("sipe_purple_set_idle[CB]: interval=%d", interval);
136 if (gc) sipe_core_status_idle(PURPLE_GC_TO_SIPE_CORE_PUBLIC);
140 Local Variables:
141 mode: c
142 c-file-style: "bsd"
143 indent-tabs-mode: t
144 tab-width: 8
145 End: