1 /* vim: set sw=4 ts=4 et: */
3 * This file is part of Live Wallpaper (livewp)
5 * Copyright (C) 2010 Vlad Vasiliev
6 * Copyright (C) 2010 Tanya Makova
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This software is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 /*******************************************************************************/
26 #include "livewp-common.h"
27 #include "livewp-dbus.h"
28 /*******************************************************************************/
30 livewp_initialize_dbus(Animation_WallpaperPrivate *priv){
34 dbus_error_init (&error);
35 /* Add D-BUS signal handler for 'status_changed' */
36 priv->dbus_conn = (DBusConnection *) osso_get_sys_dbus_connection(priv->osso);
37 priv->dbus_conn_session = (DBusConnection *) osso_get_dbus_connection(priv->osso);
39 if (priv->dbus_conn_session){
41 g_strdup_printf("type='signal', interface='%s'", LIVEWP_SIGNAL_INTERFACE);
42 dbus_bus_add_match(priv->dbus_conn_session, filter_string, &error);
43 if (dbus_error_is_set(&error)){
44 fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
45 dbus_error_free(&error);
47 g_free(filter_string);
48 /* add the callback */
49 dbus_connection_add_filter(priv->dbus_conn_session,
50 (DBusHandleMessageFunction)get_livewp_signal_cb,
54 g_strdup_printf("type='signal', interface='%s'", NOTIFY_SIGNAL_INTERFACE);
55 dbus_bus_add_match(priv->dbus_conn_session, filter_string, &error);
56 if (dbus_error_is_set(&error)){
57 fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
58 dbus_error_free(&error);
60 g_free(filter_string);
61 /* add the callback */
62 dbus_connection_add_filter(priv->dbus_conn_session,
63 (DBusHandleMessageFunction)get_livewp_signal_cb,
69 /*******************************************************************************/
71 livewp_deinitialize_dbus(Animation_WallpaperPrivate *priv){
76 if (priv->dbus_conn_session){
78 g_strdup_printf("type='signal', interface='%s'", LIVEWP_SIGNAL_INTERFACE);
80 dbus_error_init (&error);
81 dbus_bus_remove_match(priv->dbus_conn_session, filter_string, &error);
82 if (!dbus_error_is_set(&error)){
83 dbus_connection_remove_filter(priv->dbus_conn_session,
84 (DBusHandleMessageFunction)get_livewp_signal_cb,
88 fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
89 dbus_error_free(&error);
92 g_free(filter_string);
94 g_strdup_printf("type='signal', interface='%s'", NOTIFY_SIGNAL_INTERFACE);
96 dbus_error_init (&error);
97 dbus_bus_remove_match(priv->dbus_conn_session, filter_string, &error);
98 if (!dbus_error_is_set(&error)){
99 dbus_connection_remove_filter(priv->dbus_conn_session,
100 (DBusHandleMessageFunction)get_livewp_signal_cb,
104 fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
105 dbus_error_free(&error);
108 g_free(filter_string);
113 /*******************************************************************************/
115 send_dbus_signal (Animation_WallpaperPrivate *priv,
116 const gchar *interface,
122 DBusMessage *message = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
123 dbus_message_set_interface (message, interface);
124 dbus_message_set_path (message, path);
125 dbus_message_set_member (message, member);
126 success = dbus_connection_send (priv->dbus_conn_session, message, NULL);
127 dbus_message_unref (message);
130 fprintf (stderr, "%s '%s' message.\n",
131 success ? "Sent" : "Failed to send",
137 /*******************************************************************************/
139 get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_WallpaperPrivate *priv)
142 #ifdef DEBUGFUNCTIONCALL
147 #if defined APPLICATION
148 fprintf (stderr, "APPLICATION PATH11111111111111111111 %s %s %s\n", dbus_message_get_path(msg), dbus_message_get_interface (msg), dbus_message_get_member (msg));
151 #if defined CONTROLPANEL
152 fprintf (stderr, "APPLICATION PATH11111111111111111111 %s %s %s\n", dbus_message_get_path(msg), dbus_message_get_interface (msg), dbus_message_get_member (msg));
155 #if !(defined CONTROLPANEL || defined APPLICATION)
156 fprintf (stderr, "APPLET PATH11111111111111111111 %s %s %s\n", dbus_message_get_path(msg), dbus_message_get_interface (msg), dbus_message_get_member (msg));
161 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
163 if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_RELOAD_CONFIG)){
164 if(read_config(priv)){
165 fprintf(stderr, "\nCan not read config file.\n");
168 #if defined APPLICATION
169 reload_scene(priv->desktop_plugin);
173 #if defined APPLICATION
174 /* QUIT FROM APPLICATION */
175 if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW1))||
176 (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW2))||
177 (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW3))||
178 (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW4))){
180 quit_from_program(priv);
183 if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW1))||
184 (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW2))||
185 (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW3))||
186 (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW4))){
187 if (priv->visible != TRUE){
188 priv->visible = TRUE;
189 view_state_changed(priv);
193 if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW1))||
194 (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW2))||
195 (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW3))||
196 (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW4))){
197 if (priv->visible != FALSE){
198 priv->visible = FALSE;
199 view_state_changed(priv);
202 /* ALIVE APPLICATION */
203 if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW1))||
204 (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW2))||
205 (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW3))||
206 (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW4))){
208 priv->last_alive_event = time(NULL);
211 /* Check notification of mail, sms, call */
212 //fprintf(stderr, "Type %i\n", dbus_message_get_type (msg));
213 if (dbus_message_is_method_call(msg, NOTIFY_SIGNAL_INTERFACE, NOTIFY_MEMBER)){
214 //fprintf(stderr,"read notifications.db notify\n");
215 //read_notification(priv->desktop_plugin);
216 priv->scene->notification = time(NULL) + 5;
218 if (dbus_message_is_signal(msg, NOTIFY_SIGNAL_INTERFACE, CLOSENOTIFY_MEMBER)){
219 //fprintf(stderr,"read notifications.db close notify\n");
220 //read_notification(priv->desktop_plugin);
221 priv->scene->notification = time(NULL) + 5;
225 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;