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 General Public License
11 * as published by the Free Software Foundation; either version 2 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
24 /*******************************************************************************/
25 #include "livewp-common.h"
26 #include "livewp-home-widget.h"
27 #include <gconf/gconf-client.h>
28 #include "livewp-rules.h"
29 #include "livewp-scene.h"
35 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/livewp-home-widget.desktop-%i/position"
36 #define GCONF_KEY_MODIFIED "/apps/osso/hildon-desktop/applets/livewp-home-widget.desktop-%i/modified"
37 #define GCONF_KEY_VIEW "/apps/osso/hildon-desktop/applets/livewp-home-widget.desktop-%i/view"
39 HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
40 #define Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE (obj,\
41 Animation_Wallpaper_TYPE_HOME_PLUGIN,\
42 Animation_WallpaperPrivate))
44 lw_applet_realize (GtkWidget *widget)
49 AWallpaperPlugin *desktop_plugin = (AWallpaperPlugin *)widget;
50 char* child_argv[] = {"/usr/bin/livewp", "0", (char *) 0 };
51 GSList *stlist = NULL;
53 GConfClient *gconf_client = NULL;
54 GConfValue *value = NULL;
55 gboolean result = TRUE;
58 strid = g_strdup(hd_plugin_item_get_plugin_id (HD_PLUGIN_ITEM (widget)));
60 id = strid[strlen(strid)-1] - '0';
61 desktop_plugin->priv->view = id;
64 /* Checking of running view */
65 gconf_client = gconf_client_get_default();
67 stlist = gconf_client_get_list(gconf_client,
68 "/apps/osso/hildon-desktop/views/active",
69 GCONF_VALUE_INT, NULL);
74 if ((id + 1) == GPOINTER_TO_INT(tmp->data))
76 tmp = g_slist_next(tmp);
80 g_object_unref(gconf_client);
84 case 0: child_argv[1] = "1";
86 case 1: child_argv[1] = "2";
88 case 2: child_argv[1] = "3";
90 case 3: child_argv[1] = "4";
92 case 4: child_argv[1] = "5";
94 case 5: child_argv[1] = "6";
96 case 6: child_argv[1] = "7";
98 case 7: child_argv[1] = "8";
100 case 8: child_argv[1] = "9";
104 desktop_plugin->priv->one_in_all_view = get_one_in_all_views_from_config();
105 /* Check one theme in all view mode */
107 (!desktop_plugin->priv->one_in_all_view ||
108 (desktop_plugin->priv->one_in_all_view && id == 0))){
109 /* Start a new process */
110 desktop_plugin->priv->pid = fork();
111 if (desktop_plugin->priv->pid == 0){
112 execvp("/usr/bin/livewp", child_argv);
113 fprintf(stderr,"Problem with new process");
117 desktop_plugin_visible_notify((GObject *)widget, NULL, desktop_plugin);
119 screen = gtk_widget_get_screen (widget);
120 gtk_widget_set_colormap (widget,
121 gdk_screen_get_rgba_colormap (screen));
122 gtk_widget_set_app_paintable (widget,
124 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
127 /* Set position of widget on desktop */
129 init_applet_position(gint *xapplet, gint *yapplet)
131 GSList *position = NULL;
135 GError *error = NULL;
137 GConfClient *gconf_client = gconf_client_get_default ();
139 position_key = g_strdup_printf (GCONF_KEY_POSITION, i);
140 position = gconf_client_get_list (gconf_client,
144 if (position && position->data && position->next->data){
145 *xapplet = GPOINTER_TO_INT (position->data);
146 *yapplet = GPOINTER_TO_INT (position->next->data);
148 position = g_slist_prepend (g_slist_prepend (NULL,
149 GINT_TO_POINTER (Ystartposition)),
150 GINT_TO_POINTER (Xstartposition));
151 gconf_client_set_list (gconf_client,
156 *xapplet = Xstartposition;
157 *yapplet = Ystartposition;
159 g_free (position_key);
160 modified = g_strdup_printf ("%i", 0);
161 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, i);
162 gconf_client_set_string (gconf_client,
167 g_free(modified_key);
168 modified_key = g_strdup_printf (GCONF_KEY_VIEW, i);
169 gconf_client_set_int (gconf_client,
173 g_free(modified_key);
176 gconf_client_clear_cache(gconf_client);
177 g_object_unref(gconf_client);
181 desktop_plugin_visible_notify (GObject *object,
183 AWallpaperPlugin *desktop_plugin)
186 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
187 g_object_get (object, "is-on-current-desktop", &visible, NULL);
188 fprintf (stderr, "LWP is-on-current-desktop changed. visible: %u", visible);
190 if (priv->one_in_all_view){
192 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
193 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW1);
195 /* start any application on current view */
196 if ((priv->view + 1) == current_active_view())
197 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
198 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW1);
202 switch (priv->view + 1){
204 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
205 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW1);
207 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
208 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW1);
211 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
212 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW2);
214 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
215 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW2);
218 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
219 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW3);
221 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
222 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW3);
225 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
226 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW4);
228 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
229 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW4);
232 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
233 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW5);
235 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
236 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW5);
239 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
240 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW6);
242 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
243 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW6);
246 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
247 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW7);
249 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
250 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW7);
253 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
254 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW8);
256 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
257 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW8);
260 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
261 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW9);
263 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
264 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW9);
274 send_alive_event(Animation_WallpaperPrivate *priv)
276 switch (priv->view + 1){
277 case 1: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
278 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW1);
280 case 2: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
281 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW2);
283 case 3: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
284 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW3);
286 case 4: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
287 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW4);
289 case 5: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
290 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW5);
292 case 6: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
293 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW6);
295 case 7: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
296 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW7);
298 case 8: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
299 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW8);
301 case 9: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
302 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW9);
312 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
315 //fprintf(stderr, "!!!!!!!plugin init \n");
316 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
317 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
318 priv->osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL);
320 /* Initialize DBUS */
321 livewp_initialize_dbus(priv);
323 priv->desktop_plugin = desktop_plugin;
324 priv->window = (GtkWidget *)desktop_plugin;
325 priv->visible = FALSE;
326 priv->short_timer = 0;
331 priv->theme = g_strdup("Modern");
332 //priv->theme = g_strdup("Accel");
333 desktop_plugin->priv->main_widget = gtk_fixed_new();
335 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 1, 1);
336 gtk_widget_show (desktop_plugin->priv->main_widget);
337 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
338 init_applet_position(&(priv->xapplet), &(priv->yapplet));
342 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
343 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
345 priv->alive_timer = g_timeout_add(60000*3, (GtkFunction)send_alive_event, priv); /* One per 3 minute */
349 lw_applet_finalize (GObject *object)
351 int status = 0; int wpid;
352 fprintf(stderr,"lw_applet_finalize\n");
353 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
354 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
358 livewp_deinitialize_dbus(priv);
359 fprintf(stderr,"finalaze %i\n", priv->long_timer);
360 if (priv->long_timer){
361 g_source_remove(priv->long_timer);
362 priv->long_timer = 0;
364 if (priv->short_timer){
365 g_source_remove(priv->short_timer);
366 priv->short_timer = 0;
369 destroy_scene(desktop_plugin);
373 switch (priv->view + 1){
374 case 1: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
375 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW1);
377 case 2: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
378 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW2);
380 case 3: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
381 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW3);
383 case 4: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
384 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW4);
386 case 5: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
387 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW5);
389 case 6: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
390 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW6);
392 case 7: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
393 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW7);
395 case 8: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
396 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW8);
398 case 9: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
399 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW9);
403 if(priv->alive_timer > 0)
404 g_source_remove(priv->alive_timer);
406 livewp_deinitialize_dbus(priv);
410 wpid = wait(&status);
411 if (wpid == priv->pid)
418 desktop_widget_finalize (GObject *object)
420 fprintf(stderr,"desktop lw_applet_finalize\n");
421 /* Call the base class's implementation: */
422 G_OBJECT_CLASS (animation_wallpaper_plugin_parent_class)->finalize (object);
426 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
428 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
429 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
430 GObjectClass *object_class = G_OBJECT_CLASS (klass);
433 gobject_class->destroy = (gpointer)lw_applet_finalize;
434 object_class->finalize = desktop_widget_finalize;
435 widget_class->realize = lw_applet_realize;
437 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
442 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {
445 Animation_WallpaperPrivate*
446 animation_wallpaper_plugin_new (void)
448 return g_object_new (Animation_Wallpaper_TYPE_HOME_PLUGIN , NULL);