purple: add support for latest appstreamcli
[siplcs.git] / src / miranda / miranda-status.c
blob0a5f7c89790baea05b9b5ac6d0fc9f9c8c4a395c
1 /**
2 * @file miranda-status.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2015 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 <windows.h>
24 #include <glib.h>
26 #include "miranda-version.h"
27 #include "newpluginapi.h"
28 #include "m_protosvc.h"
29 #include "m_protoint.h"
30 #include "m_system.h"
32 #include "sipe-backend.h"
33 #include "sipe-core.h"
34 #include "miranda-private.h"
36 guint sipe_backend_status(struct sipe_core_public *sipe_public)
38 SIPPROTO* pr = sipe_public->backend_private;
39 return MirandaStatusToSipe(pr->proto.m_iStatus);
42 int sipe_miranda_SetStatus( SIPPROTO *pr, int iNewStatus )
44 int oldStatus;
45 if (!pr->m_hServerNetlibUser) return 0;
46 if (pr->proto.m_iDesiredStatus == iNewStatus) return 0;
48 oldStatus = pr->proto.m_iStatus;
49 pr->proto.m_iDesiredStatus = iNewStatus;
51 SIPE_DEBUG_INFO("SetStatus: newstatus <%x>", iNewStatus);
53 if (iNewStatus == ID_STATUS_OFFLINE) {
54 pr->disconnecting = TRUE;
55 sipe_miranda_connection_destroy(pr);
56 pr->valid = FALSE;
57 pr->disconnecting = FALSE;
58 } else {
59 if (pr->proto.m_iStatus == ID_STATUS_OFFLINE) {
60 pr->valid = TRUE;
61 pr->state = SIPE_MIRANDA_CONNECTING;
62 pr->proto.m_iStatus = ID_STATUS_CONNECTING;
63 sipe_miranda_SendBroadcast(pr, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, pr->proto.m_iStatus);
64 sipe_miranda_login(pr);
65 } else if (pr->state == SIPE_MIRANDA_CONNECTED) {
66 pr->proto.m_iStatus = pr->proto.m_iDesiredStatus;
67 sipe_miranda_SendBroadcast(pr, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, pr->proto.m_iStatus);
68 LOCK;
69 if (pr->proto.m_iStatus != ID_STATUS_OFFLINE) {
70 gchar *note = sipe_miranda_getString(pr, "note");
71 sipe_core_status_set(pr->sip, TRUE, MirandaStatusToSipe(iNewStatus), note);
72 mir_free(note);
74 UNLOCK;
80 //Will send an ack with:
81 //type=ACKTYPE_STATUS, result=ACKRESULT_SUCCESS, hProcess=(HANDLE)previousMode, lParam=newMode
82 //when the change completes. This ack is sent for all changes, not just ones
83 //caused by calling this function.
84 //Note that newMode can be ID_STATUS_CONNECTING<=newMode<ID_STATUS_CONNECTING+
85 //MAX_CONNECT_RETRIES to signify that it's connecting and it's the nth retry.
86 //Protocols are initially always in offline mode.
87 //Non-network-level protocol modules do not have the concept of a status and
88 //should leave this service unimplemented
89 //If a protocol doesn't support the specific status mode, it should pick the
92 return 0;
95 gboolean sipe_backend_status_changed(struct sipe_core_public *sipe_public,
96 guint activity,
97 const gchar *message)
99 SIPPROTO *pr = sipe_public->backend_private;
100 int iNewStatus = SipeStatusToMiranda(activity);
101 if (!pr->m_hServerNetlibUser) return FALSE;
102 if (pr->proto.m_iDesiredStatus == iNewStatus) return FALSE;
103 return(TRUE);
106 void sipe_backend_status_and_note(struct sipe_core_public *sipe_public,
107 guint activity,
108 const gchar *message)
110 sipe_miranda_SetStatus(sipe_public->backend_private, SipeStatusToMiranda(activity));