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,
53 g_strdup_printf("type='signal', interface='%s'", NOTIFY_SIGNAL_INTERFACE);
54 dbus_bus_add_match(priv->dbus_conn_session, filter_string, &error);
55 if (dbus_error_is_set(&error)){
56 fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
57 dbus_error_free(&error);
59 g_free(filter_string);
60 /* add the callback */
61 dbus_connection_add_filter(priv->dbus_conn_session,
62 (DBusHandleMessageFunction)get_livewp_signal_cb,
67 /*******************************************************************************/
69 livewp_deinitialize_dbus(Animation_WallpaperPrivate *priv){
74 if (priv->dbus_conn_session){
76 g_strdup_printf("type='signal', interface='%s'", LIVEWP_SIGNAL_INTERFACE);
78 dbus_error_init (&error);
79 dbus_bus_remove_match(priv->dbus_conn_session, filter_string, &error);
80 if (!dbus_error_is_set(&error)){
81 dbus_connection_remove_filter(priv->dbus_conn_session,
82 (DBusHandleMessageFunction)get_livewp_signal_cb,
86 fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
87 dbus_error_free(&error);
90 g_free(filter_string);
92 g_strdup_printf("type='signal', interface='%s'", NOTIFY_SIGNAL_INTERFACE);
94 dbus_error_init (&error);
95 dbus_bus_remove_match(priv->dbus_conn_session, filter_string, &error);
96 if (!dbus_error_is_set(&error)){
97 dbus_connection_remove_filter(priv->dbus_conn_session,
98 (DBusHandleMessageFunction)get_livewp_signal_cb,
102 fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
103 dbus_error_free(&error);
106 g_free(filter_string);
111 /*******************************************************************************/
113 send_dbus_signal (Animation_WallpaperPrivate *priv,
114 const gchar *interface,
120 DBusMessage *message = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
121 dbus_message_set_interface (message, interface);
122 dbus_message_set_path (message, path);
123 dbus_message_set_member (message, member);
124 success = dbus_connection_send (priv->dbus_conn_session, message, NULL);
125 dbus_message_unref (message);
128 fprintf (stderr, "%s '%s' message.\n",
129 success ? "Sent" : "Failed to send",
135 /*******************************************************************************/
137 get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_WallpaperPrivate *priv)
140 #ifdef DEBUGFUNCTIONCALL
144 /*fprintf (stderr, "PATH11111111111111111111 %s %s %s\n", dbus_message_get_path(msg), dbus_message_get_interface (msg), dbus_message_get_member (msg));*/
145 if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_RELOAD_CONFIG)){
146 if(read_config(priv)){
147 fprintf(stderr, "\nCan not read config file.\n");
150 #if !(defined APPLICATION || defined CONTROLPANEL)
151 reload_scene(priv->desktop_plugin);
155 //fprintf(stderr, "Type %i\n", dbus_message_get_type (msg));
156 if (dbus_message_is_method_call(msg, NOTIFY_SIGNAL_INTERFACE, NOTIFY_MEMBER)){
157 //fprintf(stderr,"read notifications.db notify\n");
158 //read_notification(priv->desktop_plugin);
159 priv->scene->notification = time(NULL) + 5;
161 if (dbus_message_is_signal(msg, NOTIFY_SIGNAL_INTERFACE, CLOSENOTIFY_MEMBER)){
162 //fprintf(stderr,"read notifications.db close notify\n");
163 //read_notification(priv->desktop_plugin);
164 priv->scene->notification = time(NULL) + 5;
167 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;