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 };
53 strid = g_strdup(hd_plugin_item_get_plugin_id (HD_PLUGIN_ITEM (widget)));
55 id = strid[strlen(strid)-1] - '0';
56 desktop_plugin->priv->view = id;
60 case 0: child_argv[1] = "1";
62 case 1: child_argv[1] = "2";
64 case 2: child_argv[1] = "3";
66 case 3: child_argv[1] = "4";
68 case 4: child_argv[1] = "5";
70 case 5: child_argv[1] = "6";
72 case 6: child_argv[1] = "7";
74 case 7: child_argv[1] = "8";
76 case 8: child_argv[1] = "9";
80 desktop_plugin->priv->one_in_all_view = get_one_in_all_views_from_config();
81 /* Check one theme in all view mode */
82 if (!desktop_plugin->priv->one_in_all_view ||
83 (desktop_plugin->priv->one_in_all_view && id == 0)){
84 /* Start a new process */
85 desktop_plugin->priv->pid = fork();
86 if (desktop_plugin->priv->pid == 0){
87 execvp("/usr/bin/livewp", child_argv);
88 fprintf(stderr,"Problem with new process");
92 desktop_plugin_visible_notify((GObject *)widget, NULL, desktop_plugin);
94 screen = gtk_widget_get_screen (widget);
95 gtk_widget_set_colormap (widget,
96 gdk_screen_get_rgba_colormap (screen));
97 gtk_widget_set_app_paintable (widget,
99 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
102 /* Set position of widget on desktop */
104 init_applet_position(gint *xapplet, gint *yapplet)
106 GSList *position = NULL;
110 GError *error = NULL;
112 GConfClient *gconf_client = gconf_client_get_default ();
114 position_key = g_strdup_printf (GCONF_KEY_POSITION, i);
115 position = gconf_client_get_list (gconf_client,
119 if (position && position->data && position->next->data){
120 *xapplet = GPOINTER_TO_INT (position->data);
121 *yapplet = GPOINTER_TO_INT (position->next->data);
123 position = g_slist_prepend (g_slist_prepend (NULL,
124 GINT_TO_POINTER (Ystartposition)),
125 GINT_TO_POINTER (Xstartposition));
126 gconf_client_set_list (gconf_client,
131 *xapplet = Xstartposition;
132 *yapplet = Ystartposition;
134 g_free (position_key);
135 modified = g_strdup_printf ("%i", 0);
136 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, i);
137 gconf_client_set_string (gconf_client,
142 g_free(modified_key);
143 modified_key = g_strdup_printf (GCONF_KEY_VIEW, i);
144 gconf_client_set_int (gconf_client,
148 g_free(modified_key);
151 gconf_client_clear_cache(gconf_client);
152 g_object_unref(gconf_client);
156 desktop_plugin_visible_notify (GObject *object,
158 AWallpaperPlugin *desktop_plugin)
161 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
162 g_object_get (object, "is-on-current-desktop", &visible, NULL);
163 fprintf (stderr, "LWP is-on-current-desktop changed. visible: %u", visible);
165 if (priv->one_in_all_view){
167 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
168 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW1);
170 /* start any application on current view */
171 if ((priv->view + 1) == current_active_view())
172 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
173 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW1);
177 switch (priv->view + 1){
179 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
180 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW1);
182 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
183 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW1);
186 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
187 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW2);
189 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
190 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW2);
193 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
194 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW3);
196 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
197 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW3);
200 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
201 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW4);
203 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
204 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW4);
207 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
208 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW5);
210 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
211 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW5);
214 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
215 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW6);
217 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
218 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW6);
221 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
222 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW7);
224 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
225 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW7);
228 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
229 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW8);
231 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
232 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW8);
235 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
236 LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW9);
238 send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
239 LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW9);
249 send_alive_event(Animation_WallpaperPrivate *priv)
251 switch (priv->view + 1){
252 case 1: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
253 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW1);
255 case 2: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
256 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW2);
258 case 3: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
259 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW3);
261 case 4: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
262 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW4);
264 case 5: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
265 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW5);
267 case 6: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
268 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW6);
270 case 7: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
271 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW7);
273 case 8: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
274 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW8);
276 case 9: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
277 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW9);
287 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
290 //fprintf(stderr, "!!!!!!!plugin init \n");
291 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
292 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
293 priv->osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL);
295 /* Initialize DBUS */
296 livewp_initialize_dbus(priv);
298 priv->desktop_plugin = desktop_plugin;
299 priv->window = (GtkWidget *)desktop_plugin;
300 priv->visible = FALSE;
301 priv->short_timer = 0;
306 priv->theme = g_strdup("Modern");
307 //priv->theme = g_strdup("Accel");
308 desktop_plugin->priv->main_widget = gtk_fixed_new();
310 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 1, 1);
311 gtk_widget_show (desktop_plugin->priv->main_widget);
312 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
313 init_applet_position(&(priv->xapplet), &(priv->yapplet));
317 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
318 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
320 priv->alive_timer = g_timeout_add(60000*3, (GtkFunction)send_alive_event, priv); /* One per 3 minute */
324 lw_applet_finalize (GObject *object)
326 int status = 0; int wpid;
327 fprintf(stderr,"lw_applet_finalize\n");
328 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
329 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
333 livewp_deinitialize_dbus(priv);
334 fprintf(stderr,"finalaze %i\n", priv->long_timer);
335 if (priv->long_timer){
336 g_source_remove(priv->long_timer);
337 priv->long_timer = 0;
339 if (priv->short_timer){
340 g_source_remove(priv->short_timer);
341 priv->short_timer = 0;
344 destroy_scene(desktop_plugin);
348 switch (priv->view + 1){
349 case 1: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
350 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW1);
352 case 2: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
353 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW2);
355 case 3: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
356 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW3);
358 case 4: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
359 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW4);
361 case 5: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
362 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW5);
364 case 6: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
365 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW6);
367 case 7: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
368 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW7);
370 case 8: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
371 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW8);
373 case 9: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE,
374 LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW9);
378 if(priv->alive_timer > 0)
379 g_source_remove(priv->alive_timer);
381 livewp_deinitialize_dbus(priv);
385 wpid = wait(&status);
386 if (wpid == priv->pid)
393 desktop_widget_finalize (GObject *object)
395 fprintf(stderr,"desktop lw_applet_finalize\n");
396 /* Call the base class's implementation: */
397 G_OBJECT_CLASS (animation_wallpaper_plugin_parent_class)->finalize (object);
401 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
403 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
404 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
405 GObjectClass *object_class = G_OBJECT_CLASS (klass);
408 gobject_class->destroy = (gpointer)lw_applet_finalize;
409 object_class->finalize = desktop_widget_finalize;
410 widget_class->realize = lw_applet_realize;
412 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
417 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {
420 Animation_WallpaperPrivate*
421 animation_wallpaper_plugin_new (void)
423 return g_object_new (Animation_Wallpaper_TYPE_HOME_PLUGIN , NULL);