~cairo-dock-team/cairo-dock-plug-ins/plug-ins

« back to all changes in this revision

Viewing changes to Messaging-Menu/src/applet-messaging.c

  • Committer: Matthieu Baerts
  • Date: 2014-10-19 00:26:10 UTC
  • Revision ID: matttbe@gmail.com-20141019002610-ulf26s9b4c4rw10r
We just switched from BZR to Git.
Follow us on Github: https://github.com/Cairo-Dock

Note: we will only use Github to manage our source code and all pull requests.
Please continue to report your bugs/ideas/messages on our forum or Launchpad! 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
* This file is a part of the Cairo-Dock project
3
 
*
4
 
* Copyright : (C) see the 'copyright' file.
5
 
* based on indicator-messages.c written by :
6
 
*  Ted Gould <ted@canonical.com>
7
 
*  Cody Russell <cody.russell@canonical.com>
8
 
* E-mail    : see the 'copyright' file.
9
 
*
10
 
* This program is free software; you can redistribute it and/or
11
 
* modify it under the terms of the GNU General Public License
12
 
* as published by the Free Software Foundation; either version 3
13
 
* of the License, or (at your option) any later version.
14
 
*
15
 
* This program is distributed in the hope that it will be useful,
16
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
* GNU General Public License for more details.
19
 
* You should have received a copy of the GNU General Public License
20
 
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 
*/
22
 
 
23
 
#include <stdlib.h>
24
 
#include <string.h>
25
 
 
26
 
#include "applet-struct.h"
27
 
#include "messages-service-client.h"
28
 
#include "applet-messaging.h"
29
 
 
30
 
#define DEFAULT_ICON "indicator-messages"
31
 
 
32
 
  ///////////
33
 
 // PROXY //
34
 
///////////
35
 
 
36
 
/* Called everytime the attention changes in the service. */
37
 
static void
38
 
attention_changed_cb (DBusGProxy * proxy, gboolean dot, GldiModuleInstance *myApplet)
39
 
{
40
 
        //g_print ("%s (attention : %d)\n", __func__, dot);
41
 
        if (dot)
42
 
        {
43
 
                cd_indicator_set_icon (myData.pIndicator, "indicator-messages-new");
44
 
                
45
 
                if (myConfig.cAnimationName != NULL)
46
 
                        CD_APPLET_DEMANDS_ATTENTION (myConfig.cAnimationName, 60);
47
 
        }
48
 
        else
49
 
        {
50
 
                cd_indicator_set_icon (myData.pIndicator, "indicator-messages");
51
 
                
52
 
                CD_APPLET_STOP_DEMANDING_ATTENTION;
53
 
        }
54
 
}
55
 
 
56
 
/* Change the icon to whether it should be visible or not */
57
 
static void
58
 
icon_changed_cb (DBusGProxy * proxy, gboolean hidden, GldiModuleInstance *myApplet)
59
 
{
60
 
        cd_debug ("%s (hidden : %d)", __func__, hidden);
61
 
        if (hidden)
62
 
        {
63
 
                myIcon->fAlpha = .5;
64
 
        }
65
 
        else
66
 
        {
67
 
                myIcon->fAlpha = 1.;
68
 
        }
69
 
        CD_APPLET_REDRAW_MY_ICON;
70
 
}
71
 
 
72
 
/* Callback from getting the attention status from the service. */
73
 
static void
74
 
attention_cb (DBusGProxy * proxy, gboolean dot, GError * error, GldiModuleInstance *myApplet)
75
 
{
76
 
        if (error != NULL) {
77
 
                cd_warning ("Unable to get attention status: %s", error->message);
78
 
                g_error_free(error);
79
 
                return;
80
 
        }
81
 
 
82
 
        return attention_changed_cb(proxy, dot, myApplet);
83
 
}
84
 
 
85
 
/* Change from getting the icon visibility from the service */
86
 
static void
87
 
icon_cb (DBusGProxy * proxy, gboolean hidden, GError * error, GldiModuleInstance *myApplet)
88
 
{
89
 
        if (error != NULL) {
90
 
                cd_warning ("Unable to get icon visibility: %s", error->message);
91
 
                g_error_free(error);
92
 
                return;
93
 
        }
94
 
 
95
 
        return icon_changed_cb(proxy, hidden, myApplet);
96
 
}
97
 
 
98
 
void cd_messaging_on_connect (GldiModuleInstance *myApplet)
99
 
{
100
 
        dbus_g_proxy_add_signal(myData.pIndicator->pServiceProxy, "AttentionChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID);
101
 
        dbus_g_proxy_connect_signal(myData.pIndicator->pServiceProxy,
102
 
                "AttentionChanged",
103
 
                G_CALLBACK(attention_changed_cb),
104
 
                myApplet,
105
 
                NULL);
106
 
        dbus_g_proxy_add_signal(myData.pIndicator->pServiceProxy, "IconChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID);
107
 
        dbus_g_proxy_connect_signal(myData.pIndicator->pServiceProxy,
108
 
                "IconChanged",
109
 
                G_CALLBACK(icon_changed_cb),
110
 
                myApplet,
111
 
                NULL);
112
 
}
113
 
 
114
 
void cd_messaging_on_disconnect (GldiModuleInstance *myApplet)
115
 
{
116
 
        //g_print ("disconnected\n");
117
 
        cd_indicator_set_icon (myData.pIndicator, DEFAULT_ICON);  // If we're disconnecting, go back to offline.
118
 
}
119
 
 
120
 
void cd_messaging_get_initial_values (GldiModuleInstance *myApplet)
121
 
{
122
 
        // query the service to display initial values.
123
 
        org_ayatana_indicator_messages_service_attention_requested_async(myData.pIndicator->pServiceProxy,
124
 
                (org_ayatana_indicator_messages_service_attention_requested_reply)attention_cb,
125
 
                myApplet);
126
 
        
127
 
        org_ayatana_indicator_messages_service_icon_shown_async(myData.pIndicator->pServiceProxy,
128
 
                (org_ayatana_indicator_messages_service_icon_shown_reply)icon_cb,
129
 
                myApplet);
130
 
}