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 fprintf(stderr,"dddddddddddddddddddd\n");
77 if (priv->dbus_conn_session){
79 g_strdup_printf("type='signal', interface='%s'", LIVEWP_SIGNAL_INTERFACE);
81 dbus_error_init (&error);
82 dbus_bus_remove_match(priv->dbus_conn_session, filter_string, &error);
83 if (!dbus_error_is_set(&error)){
84 dbus_connection_remove_filter(priv->dbus_conn_session,
85 (DBusHandleMessageFunction)get_livewp_signal_cb,
89 fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
90 dbus_error_free(&error);
93 g_free(filter_string);
96 g_strdup_printf("type='signal', interface='%s'", NOTIFY_SIGNAL_INTERFACE);
98 dbus_error_init (&error);
99 dbus_bus_remove_match(priv->dbus_conn_session, filter_string, &error);
100 if (!dbus_error_is_set(&error)){
101 dbus_connection_remove_filter(priv->dbus_conn_session,
102 (DBusHandleMessageFunction)get_livewp_signal_cb,
106 fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
107 dbus_error_free(&error);
110 g_free(filter_string);
115 /*******************************************************************************/
117 send_dbus_signal (Animation_WallpaperPrivate *priv,
118 const gchar *interface,
125 dbus_uint32_t serial = 0;
126 DBusMessageIter args;
129 DBusMessage *message = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
130 dbus_message_set_interface (message, interface);
131 dbus_message_set_path (message, path);
132 dbus_message_set_member (message, member);
134 if (member == LIVEWP_PLAY_LIVEBG_ON_VIEW ||
135 member == LIVEWP_PAUSE_LIVEBG_ON_VIEW){
136 param = priv->view + 1;
138 fprintf(stderr, "dbus send try send %s %i\n", member, param);
139 dbus_message_iter_init_append(message, &args);
140 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, ¶m)){
141 fprintf(stderr, "error append param\n");
144 if (!dbus_connection_send(priv->dbus_conn_session, message, &serial)){
145 fprintf(stderr, "error send\n");
147 dbus_connection_flush(priv->dbus_conn_session);
149 success = dbus_connection_send (priv->dbus_conn_session, message, NULL);
150 dbus_message_unref (message);
153 fprintf (stderr, "%s '%s' message.\n",
154 success ? "Sent" : "Failed to send",
160 /*******************************************************************************/
162 get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_WallpaperPrivate *priv)
165 #ifdef DEBUGFUNCTIONCALL
170 #if defined APPLICATION
171 fprintf (stderr, "APPLICATION PATH11111111111111111111 %s %s %s\n", dbus_message_get_path(msg), dbus_message_get_interface (msg), dbus_message_get_member (msg));
174 #if defined CONTROLPANEL
175 fprintf (stderr, "APPLICATION PATH11111111111111111111 %s %s %s\n", dbus_message_get_path(msg), dbus_message_get_interface (msg), dbus_message_get_member (msg));
178 #if !(defined CONTROLPANEL || defined APPLICATION)
179 fprintf (stderr, "APPLET PATH11111111111111111111 %s %s %s\n", dbus_message_get_path(msg), dbus_message_get_interface (msg), dbus_message_get_member (msg));
183 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
185 if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_RELOAD_CONFIG)){
186 if(read_config(priv)){
187 fprintf(stderr, "\nCan not read config file.\n");
190 #if defined APPLICATION
191 reload_scene(priv->desktop_plugin);
195 #if defined APPLICATION
196 /* QUIT FROM APPLICATION */
197 if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW1))||
198 (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW2))||
199 (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW3))||
200 (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW4))){
202 quit_from_program(priv);
205 if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW1))||
206 (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW2))||
207 (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW3))||
208 (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW4))){
209 /* fprintf(stderr, "Play scene visible %i\n", priv->visible); */
210 if (priv->visible != TRUE){
211 priv->visible = TRUE;
212 view_state_changed(priv);
216 if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW1))||
217 (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW2))||
218 (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW3))||
219 (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW4))){
220 /* fprintf(stderr, "Pause scene visible %i\n", priv->visible); */
221 if (priv->visible != FALSE){
222 priv->visible = FALSE;
223 view_state_changed(priv);
226 /* ALIVE APPLICATION */
227 if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW1))||
228 (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW2))||
229 (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW3))||
230 (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW4))){
232 priv->last_alive_event = time(NULL);
235 /* Check notification of mail, sms, call */
236 //fprintf(stderr, "Type %i\n", dbus_message_get_type (msg));
237 if (dbus_message_is_method_call(msg, NOTIFY_SIGNAL_INTERFACE, NOTIFY_MEMBER)){
238 //fprintf(stderr,"read notifications.db notify\n");
239 //read_notification(priv->desktop_plugin);
240 priv->scene->notification = time(NULL) + 5;
242 if (dbus_message_is_signal(msg, NOTIFY_SIGNAL_INTERFACE, CLOSENOTIFY_MEMBER)){
243 //fprintf(stderr,"read notifications.db close notify\n");
244 //read_notification(priv->desktop_plugin);
245 priv->scene->notification = time(NULL) + 5;
249 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;