added windows in all houses in Modern
[livewp] / applet / src / livewp-home-widget.c
1 /* vim: set sw=4 ts=4 et: */
2 /*
3  * This file is part of Live Wallpaper (livewp)
4  * 
5  * Copyright (C) 2010 Vlad Vasiliev
6  * Copyright (C) 2010 Tanya Makova
7  *       for the code
8  * 
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.
13  * 
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.
18  * 
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
22  * 02110-1301 USA
23 */
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 <sys/time.h>
30 #include <stdlib.h>
31
32 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
33 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
34 #define GCONF_KEY_MODIFIED "/apps/osso/hildon-desktop/applets/%s/modified"
35 #define GCONF_KEY_VIEW     "/apps/osso/hildon-desktop/applets/%s/view"
36
37 HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
38 #define Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE (obj,\
39                                                           Animation_Wallpaper_TYPE_HOME_PLUGIN,\
40                                                           Animation_WallpaperPrivate))
41
42 /* Position of plugin on desktop */
43 #define Xstartposition 700 
44 #define Ystartposition 448 
45
46 gint xapplet = 0, yapplet = 0;
47 Scene scene;
48
49 static void
50 lw_applet_realize (GtkWidget *widget)
51 {
52       GdkScreen *screen;
53
54       screen = gtk_widget_get_screen (widget);
55       gtk_widget_set_colormap (widget,
56                                 gdk_screen_get_rgba_colormap (screen));
57       gtk_widget_set_app_paintable (widget,
58                                 TRUE);
59       GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
60 }
61
62
63 static gboolean
64 lw_applet_expose_event(GtkWidget      *widget,
65                                         GdkEventExpose *event)
66 {
67   cairo_t *cr;
68
69   /* Create cairo context */
70   cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
71   gdk_cairo_region (cr, event->region);
72   cairo_clip (cr);
73
74   /* Draw alpha background */
75   cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
76   cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
77   cairo_paint (cr);
78
79   /* Free context */
80   cairo_destroy (cr);
81
82   return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
83                                                                                   event);
84 }
85
86 static gboolean
87 expose_event (GtkWidget *widget,GdkEventExpose *event,
88      gpointer data)
89 {
90     cairo_t *cr;
91     GdkPixbuf *pixbuf = (GdkPixbuf *) data;
92         
93     cr = gdk_cairo_create(widget->window);
94     if (cr){
95         gdk_cairo_region(cr, event->region);
96         cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
97         gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
98         cairo_paint(cr);
99         cairo_destroy(cr);
100     }
101     return TRUE;
102 }
103
104 static void
105 realize (GtkWidget *widget)
106 {
107     GdkScreen *screen;
108     screen = gtk_widget_get_screen (widget);
109     gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
110 }
111
112 /* Set position of widget on desktop */
113 static void
114 init_applet_position(void)
115 {
116   GSList *position = NULL;
117   gchar *position_key;
118   gchar *modified_key;
119   gchar *modified;
120   GError *error = NULL;
121   GConfClient   *gconf_client = gconf_client_get_default ();
122   position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
123   position = gconf_client_get_list (gconf_client,
124                                     position_key,
125                                     GCONF_VALUE_INT,
126                                     NULL);
127   if (position && position->data && position->next->data){
128         xapplet = GPOINTER_TO_INT (position->data);
129         yapplet = GPOINTER_TO_INT (position->next->data);
130   }else{
131         position = g_slist_prepend (g_slist_prepend (NULL,
132                                       GINT_TO_POINTER (Ystartposition)),
133                                       GINT_TO_POINTER (Xstartposition));
134         gconf_client_set_list (gconf_client,
135                                position_key,
136                                GCONF_VALUE_INT,
137                                position,
138                                &error);
139         xapplet = Xstartposition;
140         yapplet = Ystartposition;
141   }
142   g_free (position_key);
143   modified = g_strdup_printf ("%i", 0);
144   modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
145   gconf_client_set_string (gconf_client,
146                            modified_key,
147                            modified,
148                            &error);
149   g_free(modified);
150   g_free(modified_key);
151   gconf_client_clear_cache(gconf_client);
152   g_object_unref(gconf_client);
153 }
154
155 void
156 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
157 {
158 /*  fprintf(stderr, "actor_set_position_full z=%d\n", z); */
159     hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
160 }
161
162 static gint 
163 path_line(gint x0, gint x1, double t)
164 {
165     // уравниение прямой
166     return ((x1 - x0) * t + x0);
167 }
168
169
170 void
171 destroy_hildon_actor(Actor *actor)
172 {
173     fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
174     gtk_widget_destroy(actor->widget);
175     actor->widget = NULL;
176 }
177
178 static Actor* 
179 init_object(AWallpaperPlugin *desktop_plugin, 
180             gchar * name, 
181             gchar * filename, 
182             gint x, 
183             gint y, 
184             gint z, 
185             gint width, 
186             gint height, 
187             gboolean visible, 
188             gint scale, 
189             gint opacity, 
190             void (*pfunc_change)(Actor*),
191             void (*pfunc_probability)(Actor*)
192            )
193 {
194   Actor *actor = NULL;
195   actor = g_new0(Actor, 1);
196   actor->x = x;
197   actor->y = y;
198   actor->z = z;
199   actor->width = width;
200   actor->height = height;
201   actor->visible = visible;
202   actor->scale = scale;
203   actor->opacity = opacity;
204   actor->filename = g_strdup(filename);
205   actor->name = g_strdup(name);
206   actor->func_change = (gpointer)pfunc_change; 
207   actor->func_probability = (gpointer)pfunc_probability;
208   if (visible)
209     create_hildon_actor(actor, desktop_plugin);
210   else 
211     actor->widget = NULL;
212   actor->time_start_animation = 0;
213   actor->duration_animation = 0;
214   /*
215   a.widget = actor;
216   a.name = name;
217   a.x = x;
218   a.y = y;
219   a.z = z;
220   */
221   //objects_list = g_slist_append(objects_list, G_OBJECT(actor));
222   //objects_list = g_slist_append(objects_list, G_OBJECT(a));
223   return actor;
224 }
225
226 gint 
227 rnd(gint max)
228 {
229     srand(time(NULL));
230     return rand() % max;
231 }
232 gint fast_rnd(gint max)
233 {
234     guint offset = 12923;
235     guint multiplier = 4079;
236     
237     scene.seed = scene.seed * multiplier + offset;
238     return (gint)(scene.seed % max);
239 }
240
241 gint 
242 probability_sun()
243 {
244     /* update sun position after ...  second */
245     return 60;
246 }
247
248
249 gint 
250 probability_plane()
251 {
252     return (fast_rnd(10) + 1) * 60;
253 }
254
255 void 
256 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
257 {
258     gint phase;
259     char *newfile;
260
261     if (actor){
262         if (scene.daytime == TIME_NIGHT){
263             if (!actor->visible){
264                 actor->visible = TRUE;
265                 phase = get_moon_phase();
266                 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
267                 if (actor->filename)
268                     g_free(actor->filename);
269                 actor->filename = newfile;
270                 create_hildon_actor(actor, desktop_plugin);
271
272             }
273             //actor->x = 400;
274             //actor->y = 10;
275            // actor_set_position_full(actor->widget, x, y, actor->z);
276             //probability_sun(actor);
277             //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
278          }else if (actor->visible){
279             actor->visible = FALSE;
280             fprintf(stderr, "destroy moon \n");
281             destroy_hildon_actor(actor);
282             /* TO DO make moonrise*/
283             actor->time_start_animation = 0;
284         } 
285     }
286     
287 }
288
289 void 
290 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
291 {
292     double alt, azm;
293     gint x, y;
294
295     //fprintf(stderr, "change sun\n");
296     if (actor){
297         if (scene.daytime != TIME_NIGHT){
298             if (!actor->visible){
299                 actor->visible = TRUE;
300                 create_hildon_actor(actor, desktop_plugin);
301             }
302             get_sun_pos(&alt, &azm);
303             get_sun_screen_pos(alt, azm, &x, &y);
304             actor->x = x;
305             actor->y = y;
306             actor_set_position_full(actor->widget, x, y, actor->z);
307             //probability_sun(actor);
308             actor->time_start_animation = time(NULL) + probability_sun();
309          }else if (actor->visible){
310             actor->visible = FALSE;
311             destroy_hildon_actor(actor);
312             actor->time_start_animation = 0;
313         } 
314     }
315     
316 }
317
318 static void 
319 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
320 {
321     gint x0 = -300, y0 = 225, scale0 = 100,
322          x1 = 800, y1 = 162, scale1 = 130, 
323          x, y, scale;
324     struct timeval tvb;     
325     suseconds_t ms;
326     long sec;
327     double t;
328
329     gettimeofday(&tvb, NULL);
330     
331     ms = tvb.tv_usec;
332     sec = tvb.tv_sec;
333     
334     if (!actor->visible){
335         actor->visible = TRUE;
336         if (scene.daytime == TIME_NIGHT){
337             if (actor->filename)
338                 g_free(actor->filename);
339             actor->filename = g_strdup("tram_dark.png");
340         } else{
341             if (actor->filename)
342                 g_free(actor->filename);
343             actor->filename = g_strdup("tram.png");
344         }
345         create_hildon_actor(actor, desktop_plugin);
346     }
347     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
348     x = path_line(x0, x1, t);
349     y = path_line(y0, y1, t);
350     scale = path_line(scale0, scale1, t);
351     //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
352     actor_set_position_full(actor->widget, x, y, actor->z);
353     hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
354     if (t >= 1){
355         /* stop animation */
356         actor->visible = FALSE;
357         destroy_hildon_actor(actor);
358         actor->time_start_animation = sec + fast_rnd(300);
359     }
360 }
361
362 void
363 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
364 {
365     gint x0 = 620, y0 = 233, scale0 = 100,
366          x1 = 79, y1 = -146, scale1 = 100, 
367          x, y, scale;
368     struct timeval tvb;     
369     suseconds_t ms;
370     long sec;
371     double t;
372
373     gettimeofday(&tvb, NULL);
374     
375     ms = tvb.tv_usec;
376     sec = tvb.tv_sec;
377 //    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
378    
379     if (scene.daytime != TIME_NIGHT){
380         if (actor->time_start_animation == 0){
381             actor->time_start_animation = sec + probability_plane();
382             return;
383         }
384     }
385     if (!actor->visible){
386         actor->visible = TRUE;
387         create_hildon_actor(actor, desktop_plugin);
388     }
389     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
390     x = path_line(x0, x1, t);
391     y = path_line(y0, y1, t);
392     //scale = path_line(scale0, scale1, t);
393     //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
394     actor_set_position_full(actor->widget, x, y, actor->z);
395     //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
396     if (t >= 1){
397         /* stop animation */
398         actor->visible = FALSE;
399         destroy_hildon_actor(actor);
400         if (scene.daytime == TIME_NIGHT) 
401             actor->time_start_animation = 0;
402         else 
403             actor->time_start_animation = sec + probability_plane();
404     }
405
406 }
407
408 void
409 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
410 {
411     gint x0 = -actor->width, y0 = 45, scale0 = 100,
412          x1 = 800, y1 = 20, scale1 = 100, 
413          x, y, scale;
414     struct timeval tvb;     
415     suseconds_t ms;
416     long sec;
417     double t;
418
419     gettimeofday(&tvb, NULL);
420     
421     ms = tvb.tv_usec;
422     sec = tvb.tv_sec;
423 //    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
424     if (scene.daytime != TIME_NIGHT){
425         if (actor->time_start_animation == 0){
426             actor->time_start_animation = sec + probability_plane();
427             return;
428         }
429     }
430     if (!actor->visible){
431         actor->visible = TRUE;
432         create_hildon_actor(actor, desktop_plugin);
433     }
434
435     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
436     x = path_line(x0, x1, t);
437     y = path_line(y0, y1, t);
438     //scale = path_line(scale0, scale1, t);
439     //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
440     actor_set_position_full(actor->widget, x, y, actor->z);
441     //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
442     if (t >= 1){
443         /* stop animation */
444         actor->visible = FALSE;
445         destroy_hildon_actor(actor);
446         if (scene.daytime == TIME_NIGHT) 
447             actor->time_start_animation = 0;
448         else 
449             actor->time_start_animation = sec + probability_plane();
450     }
451
452 }
453
454 void
455 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
456 {
457     gint x0, y0 = 300, scale0 = 100,
458          x1, y1 = -actor->height, scale1 = 150, 
459          x, y, scale;
460     struct timeval tvb;     
461     suseconds_t ms;
462     long sec;
463     double t;
464
465     gettimeofday(&tvb, NULL);
466     
467     ms = tvb.tv_usec;
468     sec = tvb.tv_sec;
469     //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
470    
471     if (!actor->visible){
472         actor->visible = TRUE;
473         if (scene.daytime == TIME_NIGHT)
474             actor->filename = actor->filename;
475         else
476             actor->filename = actor->filename;
477         create_hildon_actor(actor, desktop_plugin);
478     }
479     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
480     
481     if (scene.wind_orientation == 1){
482         x0 = -actor->width;
483         x1 = 800;
484     }
485     else {
486         x0 = 800;
487         x1 = -actor->width;
488     }
489
490     x = path_line(x0, x1, t);    
491     y = -scene.wind_angle * (x - x0) + actor->y;
492     scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
493
494     //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
495     actor_set_position_full(actor->widget, x, y, actor->z);
496     hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
497     if ((y < y1 || y > y0) || t >= 1){
498         /* stop animation */
499         actor->visible = FALSE;
500         destroy_hildon_actor(actor);
501         actor->time_start_animation = sec + fast_rnd(300);
502         actor->y = fast_rnd(300);
503     }
504
505 }
506
507 void
508 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
509 {
510     scene.wind_orientation = fast_rnd(2);
511     if (scene.wind_orientation == 0) scene.wind_orientation = -1;
512     scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
513     actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
514     fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
515 }
516
517 void 
518 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
519 {
520     
521     gint now = time(NULL);
522
523     if (scene.daytime == TIME_DAY){
524         if (actor->visible){
525             actor->visible = FALSE;
526             destroy_hildon_actor(actor);
527         }
528         actor->time_start_animation = 0;
529         return;
530     }else if (actor->time_start_animation == 0){
531         actor->time_start_animation = now + fast_rnd(30);
532         return;
533     }
534
535     if (!actor->visible){
536         actor->visible = TRUE;
537         create_hildon_actor(actor, desktop_plugin);
538         actor->time_start_animation = now + fast_rnd(20) + 10;
539     }else {
540         actor->visible = FALSE;
541         destroy_hildon_actor(actor);
542         actor->time_start_animation = now + fast_rnd(20) + 10;
543     }
544    
545 }
546
547 void
548 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin) 
549 {
550   GtkWidget *ha = NULL;
551   GdkPixbuf *pixbuf = NULL;
552   GtkWidget *image = NULL;
553   gchar     *str = NULL;
554
555   /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
556   ha = hildon_animation_actor_new();
557   str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
558                         desktop_plugin->priv->theme, actor->filename);
559   pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
560                                              actor->width, 
561                                              actor->height, 
562                                              NULL);
563   if (str)
564       g_free(str);
565   if (pixbuf){
566       image = gtk_image_new_from_pixbuf (pixbuf);
567       g_object_unref(G_OBJECT(pixbuf));
568   }
569   if (image){
570     g_signal_connect(G_OBJECT(image), "expose_event",
571                            G_CALLBACK(expose_event), pixbuf);
572     gtk_container_add (GTK_CONTAINER (ha), image);
573   }  
574   actor_set_position_full(ha, actor->x, actor->y, actor->z);
575   hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
576   hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
577   realize(ha);
578   gtk_widget_show_all(ha);
579
580   /* TO DO check it */
581   /*  gdk_flush (); */
582
583   //g_object_set_data(G_OBJECT(ha), "name", name);
584   //g_object_set_data(G_OBJECT(ha), "filename", filename);
585   g_object_set_data(G_OBJECT(ha), "image", image);
586   /*
587   g_object_set_data(G_OBJECT(ha), "x", x);
588   g_object_set_data(G_OBJECT(ha), "y", y);
589   g_object_set_data(G_OBJECT(ha), "z", z);
590   g_object_set_data(G_OBJECT(ha), "width", width);
591   g_object_set_data(G_OBJECT(ha), "height", height);
592   g_object_set_data(G_OBJECT(ha), "scale", scale);
593   g_object_set_data(G_OBJECT(ha), "visible", visible);
594   g_object_set_data(G_OBJECT(ha), "opacity", opacity);
595   g_object_set_data(G_OBJECT(ha), "func", pfunc);
596   */
597   hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
598   actor->widget = ha;
599 }
600
601
602 void
603 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
604 {
605     GtkWidget *image = NULL;
606     GdkPixbuf *pixbuf = NULL;
607     gchar     *str = NULL;
608
609     str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
610                             desktop_plugin->priv->theme, actor->filename);
611  
612     pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
613                                                actor->width, 
614                                                actor->height, 
615                                                NULL);
616     if(str)
617         g_free(str);
618     if (pixbuf){
619         image = gtk_image_new_from_pixbuf (pixbuf);
620         g_object_unref(G_OBJECT(pixbuf));
621     }
622     if (image){ 
623         g_signal_connect(G_OBJECT(image), "expose_event",
624                                        G_CALLBACK(expose_event), pixbuf);
625         if (g_object_get_data(G_OBJECT(actor->widget), "image")){
626             gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));  
627         }
628         g_object_set_data(G_OBJECT(actor->widget), "image", image);
629         gtk_container_add (GTK_CONTAINER (actor->widget), image);
630         realize(actor->widget);
631         gtk_widget_show_all(actor->widget);
632         /* TO DO check it */
633        /*  gdk_flush (); */
634
635
636     }
637
638 }
639
640
641 void 
642 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
643 {
644     gchar *newfile;
645     newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime); 
646     if (actor->filename)
647             g_free(actor->filename);
648     actor->filename = newfile;
649     change_hildon_actor(actor, desktop_plugin);
650 }
651
652
653
654 /*
655 static gint 
656 get_time(gint t){
657     // уравнение изменения времени
658     return t*1.1;
659 }
660 */
661 static void 
662 destroy_scene(void){
663     GSList * tmp = scene.actors;
664     Actor *actor;
665     while (tmp != NULL){
666         actor = tmp->data;
667         if (actor){
668             if (actor->filename)
669                 g_free(actor->filename);
670             if (actor->name)
671                 g_free(actor->name);
672             gtk_widget_destroy(actor->widget);
673             //actor->widget = NULL;
674             g_free(actor);
675         }
676         tmp = g_slist_next(tmp);
677     }
678     g_slist_free(tmp);
679
680 }
681
682 void
683 reload_scene(AWallpaperPlugin *desktop_plugin)
684 {
685     fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);  
686     destroy_scene();
687     if (!strcmp(desktop_plugin->priv->theme,"Modern"))
688         init_scene(desktop_plugin);
689     else if (!strcmp(desktop_plugin->priv->theme,"Berlin")) 
690         init_scene1(desktop_plugin);
691 }
692
693
694 /* Init Modern Scene */
695 static void
696 init_scene(AWallpaperPlugin *desktop_plugin)
697 {
698   Actor *actor;
699   gint now = time(NULL);
700   gint i;
701
702   /* fprintf(stderr, "init scene \n");*/
703   scene.daytime = get_daytime();
704   scene.actors = NULL;
705   scene.wind_orientation = -1;
706   scene.wind_angle = 0.3;
707   /* init value for random */
708   scene.seed = time(NULL);
709
710   
711
712   actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480, 
713                       TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
714   change_static_actor(actor, desktop_plugin);
715   scene.actors = g_slist_append(scene.actors, actor);
716
717   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
718                       TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
719   actor->time_start_animation = now;
720   actor->duration_animation = G_MAXINT;
721   change_sun(actor, desktop_plugin);
722   scene.actors = g_slist_append(scene.actors, actor);
723
724   //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
725     //                  TRUE, 100, 255, NULL, NULL);
726   //scene.actors = g_slist_append(scene.actors, actor);
727   
728   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
729                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
730   actor->time_start_animation = now + fast_rnd(180);
731   actor->duration_animation = 5*60;
732   scene.actors = g_slist_append(scene.actors, actor);
733   
734   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
735                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
736   actor->time_start_animation = now + fast_rnd(180);
737   actor->duration_animation = 5*60;
738   scene.actors = g_slist_append(scene.actors, actor);
739
740   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
741                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
742   actor->time_start_animation = now + fast_rnd(180);
743   actor->duration_animation = 5*60;
744   scene.actors = g_slist_append(scene.actors, actor);
745
746
747   actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480, 
748                       TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
749   change_static_actor(actor, desktop_plugin);
750   scene.actors = g_slist_append(scene.actors, actor);
751
752   actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210, 
753                       FALSE, 100, 255, (gpointer)&change_tram, NULL);
754   actor->time_start_animation = time(NULL) + fast_rnd(60);
755   actor->duration_animation = 60;
756   scene.actors = g_slist_append(scene.actors, actor);
757
758   actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
759                       TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
760   change_static_actor(actor, desktop_plugin);
761   scene.actors = g_slist_append(scene.actors, actor);
762   
763   actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 6, 60, 60, 
764                       FALSE, 100, 255, (gpointer)&change_moon, NULL);
765   change_moon(actor, desktop_plugin);
766   scene.actors = g_slist_append(scene.actors, actor);
767
768   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
769                       FALSE, 100, 255, (gpointer)&change_wind, NULL);
770   change_wind(actor, desktop_plugin);
771   scene.actors = g_slist_append(scene.actors, actor);
772
773     /* windows in 4-th house  */
774     gint winds[13][2];
775
776     winds[0][0] = 482;
777     winds[0][1] = 180;
778
779     winds[1][0] = 495;
780     winds[1][1] = 179;
781
782     winds[2][0] = 482;
783     winds[2][1] = 191;
784
785     winds[3][0] = 495;
786     winds[3][1] = 190;
787     
788     winds[4][0] = 482;
789     winds[4][1] = 201;
790     
791     winds[5][0] = 495;
792     winds[5][1] = 210;
793     
794     winds[6][0] = 482;
795     winds[6][1] = 222;
796     
797     winds[7][0] = 495;
798     winds[7][1] = 221;
799     
800     winds[8][0] = 459;
801     winds[8][1] = 203;
802     
803     winds[9][0] = 495;
804     winds[9][1] = 241;
805     
806     winds[10][0] = 495;
807     winds[10][1] = 252;
808     
809     winds[11][0] = 482;
810     winds[11][1] = 273;
811     
812     winds[12][0] = 495;
813     winds[12][1] = 303;
814     for (i=0; i<13; i++){
815         actor = init_object(desktop_plugin, "window1", "window1.png", 
816                             winds[i][0], winds[i][1], 8, 8, 10, 
817                             FALSE, 100, 255, (gpointer)&change_window1, NULL);
818         //change_window1(actor, desktop_plugin);
819         actor->time_start_animation = now + fast_rnd(30);
820         scene.actors = g_slist_append(scene.actors, actor);
821
822     }
823     
824     /* windows in 1-th house  */
825     
826     winds[0][0] = 86;
827     winds[0][1] = 321;
828
829     winds[1][0] = 86;
830     winds[1][1] = 363;
831
832     winds[2][0] = 86;
833     winds[2][1] = 385;
834
835     winds[3][0] = 86;
836     winds[3][1] = 286;
837     
838     winds[4][0] = 94;
839     winds[4][1] = 232;
840     
841     winds[5][0] = 94;
842     winds[5][1] = 243;
843     
844     winds[6][0] = 94;
845     winds[6][1] = 265;
846     
847     winds[7][0] = 94;
848     winds[7][1] = 331;
849     for (i=0; i<8; i++){
850         actor = init_object(desktop_plugin, "window2", "window2.png", 
851                             winds[i][0], winds[i][1], 8, 8, 10, 
852                             TRUE, 100, 255, (gpointer)&change_window1, NULL);
853         //change_window1(actor, desktop_plugin);
854         actor->time_start_animation = now + fast_rnd(30);
855         scene.actors = g_slist_append(scene.actors, actor);
856
857     }
858     
859     /* windows in 3-th house  */
860     
861     winds[0][0] = 251;
862     winds[0][1] = 162;
863
864     winds[1][0] = 251;
865     winds[1][1] = 196;
866
867     winds[2][0] = 251;
868     winds[2][1] = 278;
869
870     winds[3][0] = 251;
871     winds[3][1] = 289;
872     
873     winds[4][0] = 313;
874     winds[4][1] = 173;
875     
876     winds[5][0] = 322;
877     winds[5][1] = 160;
878     
879     winds[6][0] = 303;
880     winds[6][1] = 217;
881     
882     winds[7][0] = 322;
883     winds[7][1] = 224;
884     
885     winds[8][0] = 323;
886     winds[8][1] = 217;
887     
888     winds[9][0] = 322;
889     winds[9][1] = 288;
890     
891     for (i=0; i<10; i++){
892         actor = init_object(desktop_plugin, "window3", "window3.png", 
893                             winds[i][0], winds[i][1], 8, 8, 10, 
894                             FALSE, 100, 255, (gpointer)&change_window1, NULL);
895         //change_window1(actor, desktop_plugin);
896         actor->time_start_animation = now + fast_rnd(30);
897         scene.actors = g_slist_append(scene.actors, actor);
898
899     }
900
901     /* windows in 5-th house  */
902     
903     winds[0][0] = 610;
904     winds[0][1] = 224;
905
906     winds[1][0] = 602;
907     winds[1][1] = 245;
908
909     winds[2][0] = 602;
910     winds[2][1] = 264;
911
912     winds[3][0] = 610;
913     winds[3][1] = 301;
914     
915     winds[4][0] = 610;
916     winds[4][1] = 320;
917     
918     winds[5][0] = 593;
919     winds[5][1] = 352;
920     
921     winds[6][0] = 610;
922     winds[6][1] = 368;
923     
924     for (i=0; i<7; i++){
925         actor = init_object(desktop_plugin, "window4", "window4.png", 
926                             winds[i][0], winds[i][1], 8, 8, 10, 
927                             FALSE, 100, 255, (gpointer)&change_window1, NULL);
928         //change_window1(actor, desktop_plugin);
929         actor->time_start_animation = now + fast_rnd(30);
930         scene.actors = g_slist_append(scene.actors, actor);
931
932     }
933
934     /* windows in 6-th house  */
935     
936     winds[0][0] = 717;
937     winds[0][1] = 283;
938
939     winds[1][0] = 698;
940     winds[1][1] = 293;
941
942     winds[2][0] = 717;
943     winds[2][1] = 315;
944
945     winds[3][0] = 717;
946     winds[3][1] = 323;
947     
948     winds[4][0] = 698;
949     winds[4][1] = 362;
950     
951     winds[5][0] = 698;
952     winds[5][1] = 400;
953     
954     for (i=0; i<6; i++){
955         actor = init_object(desktop_plugin, "window5", "window5.png", 
956                             winds[i][0], winds[i][1], 8, 8, 10, 
957                             FALSE, 100, 255, (gpointer)&change_window1, NULL);
958         //change_window1(actor, desktop_plugin);
959         actor->time_start_animation = now + fast_rnd(30);
960         scene.actors = g_slist_append(scene.actors, actor);
961
962     }
963
964 #if 0    
965   anim = g_new0(Animation, 1);
966   anim->count = 1;
967   anim->actor = actor;
968   anim->func_change = &change_tram;
969   anim->func_time = NULL;
970   anim->timestart = time(NULL); 
971   anim->timeall = 10;
972   
973   scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
974 #endif  
975  }
976
977 /* Init Berlin Scene */
978 static void
979 init_scene1(AWallpaperPlugin *desktop_plugin)
980 {
981   Actor *actor;
982   gint now = time(NULL);
983   
984
985   scene.daytime = get_daytime();
986   scene.actors = NULL;
987   scene.wind_orientation = -1;
988   scene.wind_angle = 0.3;
989   /* init value for random */
990   scene.seed = time(NULL);
991
992   
993   actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480, 
994                       TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
995   change_static_actor(actor, desktop_plugin);
996   scene.actors = g_slist_append(scene.actors, actor);
997
998   
999   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
1000                       TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
1001   actor->time_start_animation = time(NULL);
1002   actor->duration_animation = G_MAXINT;
1003   change_sun(actor, desktop_plugin);
1004   scene.actors = g_slist_append(scene.actors, actor);
1005
1006
1007   actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
1008                       TRUE, 100, 255, NULL, NULL);
1009   scene.actors = g_slist_append(scene.actors, actor);
1010
1011
1012   actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60, 
1013                       FALSE, 100, 255, (gpointer)&change_moon, NULL);
1014   change_moon(actor, desktop_plugin);
1015   scene.actors = g_slist_append(scene.actors, actor);
1016   
1017   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
1018                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1019   actor->time_start_animation = now + fast_rnd(180);
1020   actor->duration_animation = 5*60;
1021   scene.actors = g_slist_append(scene.actors, actor);
1022   
1023   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
1024                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1025   actor->time_start_animation = now + fast_rnd(180);
1026   actor->duration_animation = 5*60;
1027   scene.actors = g_slist_append(scene.actors, actor);
1028
1029   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
1030                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1031   actor->time_start_animation = now + fast_rnd(180);
1032   actor->duration_animation = 5*60;
1033   scene.actors = g_slist_append(scene.actors, actor);
1034
1035  
1036   actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
1037                       FALSE, 100, 255, (gpointer)&change_plane2, NULL);
1038   actor->time_start_animation = now + probability_plane();
1039   actor->duration_animation = 60;
1040   scene.actors = g_slist_append(scene.actors, actor);
1041   
1042   actor = init_object(desktop_plugin, "plane1", "tu154_small.png", 620, 233, 9, 300, 116, 
1043                       FALSE, 100, 255, (gpointer)&change_plane1, NULL);
1044   actor->time_start_animation = now + probability_plane();
1045   actor->duration_animation = 30;
1046   scene.actors = g_slist_append(scene.actors, actor);
1047
1048   actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
1049                       TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
1050   change_static_actor(actor, desktop_plugin);
1051   scene.actors = g_slist_append(scene.actors, actor);
1052
1053   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
1054                       FALSE, 100, 255, (gpointer)&change_wind, NULL);
1055   change_wind(actor, desktop_plugin);
1056   scene.actors = g_slist_append(scene.actors, actor);
1057
1058 }
1059
1060
1061 void 
1062 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
1063 {
1064     gint y0 = 365;// - уровень горизонта
1065     *x = (int)(azm * 800) - 64;
1066     *y = (int)((1 - alt) * y0) - 64;
1067     //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
1068 }
1069 #if 0
1070 static void 
1071 change_actor(GtkWidget * actor)
1072 {
1073     char * name;
1074     gint x, y, daytime, scale;
1075     gdouble sc;
1076     double alt, azm;
1077
1078     GtkWidget *image;
1079     GdkPixbuf *pixbuf;
1080
1081     void (*pfunc)(gpointer, gpointer);
1082
1083     name = g_object_get_data(G_OBJECT(actor), "name");
1084     fprintf(stderr, "change actor %s\n", name);
1085     if (name == "sun"){
1086         pfunc = g_object_get_data(G_OBJECT(actor), "func");
1087         if (pfunc)
1088             (*pfunc)(actor, g_strdup(name));
1089         daytime = get_daytime();
1090         if (daytime != TIME_NIGHT){
1091             hildon_animation_actor_set_show(actor, 1);
1092             get_sun_pos(&alt, &azm);
1093             get_sun_screen_pos(alt, azm, &x, &y);
1094             actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1095         }
1096     }
1097     
1098     if (name == "cloud1"){
1099         x = g_object_get_data(G_OBJECT(actor), "x");
1100         y = g_object_get_data(G_OBJECT(actor), "y");
1101         scale = g_object_get_data(G_OBJECT(actor), "scale");
1102
1103         /* Start */
1104         image = g_object_get_data(G_OBJECT(actor), "image");
1105         
1106         gtk_container_remove(actor, image);  
1107         pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png", 
1108                                              200, 
1109                                              200, 
1110                                              NULL);
1111         if (pixbuf){
1112               image = gtk_image_new_from_pixbuf (pixbuf);
1113               g_object_unref(G_OBJECT(pixbuf));
1114         }
1115         g_signal_connect(G_OBJECT(image), "expose_event",
1116                                    G_CALLBACK(expose_event), pixbuf);
1117         gtk_container_add (GTK_CONTAINER (actor), image);
1118         realize(actor);
1119         gtk_widget_show_all(actor);
1120         /* End*/
1121
1122             
1123         x += 40;
1124         y -= 20;
1125         scale -= 10;
1126         if (x > 500){
1127             x = 400;
1128             y = 150;
1129             sc = 1;
1130         }
1131         sc = (double)scale / 100;
1132         hildon_animation_actor_set_scale(actor, sc, sc);
1133         fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
1134         actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1135         g_object_set_data(G_OBJECT(actor), "x", x);
1136         g_object_set_data(G_OBJECT(actor), "y", y);
1137         g_object_set_data(G_OBJECT(actor), "scale", scale);
1138     }
1139
1140 }
1141 #endif
1142 static gboolean
1143 short_timeout (AWallpaperPlugin *desktop_plugin)
1144 {
1145     gint daytime = get_daytime();
1146     GSList * tmp;
1147     void (*pfunc)(gpointer, gpointer);
1148     time_t now;
1149     Actor *actor;
1150     gboolean stop_flag = TRUE;
1151
1152     if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
1153         desktop_plugin->priv->short_timer = 0;
1154         return FALSE;
1155     }
1156
1157     now = time(NULL);
1158     //scene.daytime = daytime;
1159     /* fprintf(stderr, "Short timer %d\n", now); */
1160     tmp = scene.actors;
1161     while (tmp != NULL){
1162            actor = tmp->data;
1163            if (now >= actor->time_start_animation  
1164                && actor->time_start_animation > 0
1165                /* && now - actor->time_start_animation <= actor->duration_animation*/){
1166                 pfunc = actor->func_change;
1167                 if (pfunc){ 
1168                     (*pfunc)(actor, desktop_plugin);
1169                     stop_flag = FALSE;
1170                 }
1171             }
1172             tmp = g_slist_next(tmp);
1173     }
1174     if (stop_flag){
1175          desktop_plugin->priv->short_timer = 0;
1176          return FALSE;
1177     }else
1178          return TRUE; /* keep running this event */
1179 }
1180
1181
1182 static gboolean
1183 long_timeout (AWallpaperPlugin *desktop_plugin)
1184 {
1185     gint daytime = get_daytime();
1186     GSList * tmp;
1187     void (*pfunc)(gpointer, gpointer);
1188     time_t now;
1189     Actor *actor;
1190
1191     fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer);
1192     if (desktop_plugin->priv->long_timer == 0 )
1193         return FALSE;
1194     if (!desktop_plugin->priv->visible){
1195         if(desktop_plugin->priv->short_timer != 0){
1196             g_source_remove(desktop_plugin->priv->short_timer);
1197             desktop_plugin->priv->short_timer = 0;
1198         }
1199         return FALSE;
1200     }
1201     //fprintf(stderr, "timer daytime=%d\n", daytime);
1202     if (scene.daytime != daytime){
1203         scene.daytime = daytime;
1204         tmp = scene.actors;
1205         while (tmp != NULL){
1206             //change_actor(tmp->data);
1207             pfunc =((Actor*)tmp->data)->func_change;
1208             if (pfunc){
1209                 (*pfunc)(tmp->data, desktop_plugin);
1210             }
1211             tmp = g_slist_next(tmp);
1212         }
1213     }
1214    
1215     now = time(NULL);
1216     //fprintf(stderr, "Now  %d\n", now);
1217     tmp = scene.actors;
1218     while (tmp != NULL){
1219         actor = tmp->data;
1220         if (now >= actor->time_start_animation  
1221             && actor->time_start_animation > 0
1222             && desktop_plugin->priv->short_timer == 0){
1223             actor->time_start_animation = now;
1224             /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1225             if (desktop_plugin->priv->rich_animation)
1226                 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1227         }
1228         tmp = g_slist_next(tmp);
1229     }
1230    
1231
1232     return TRUE; /* keep running this event */
1233 }
1234
1235 static void
1236 desktop_plugin_visible_notify (GObject    *object,
1237                                           GParamSpec *spec,
1238                                           AWallpaperPlugin *desktop_plugin)
1239 {
1240     gboolean visible;
1241     g_object_get (object, "is-on-current-desktop", &visible, NULL);
1242     /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1243     if (visible){
1244         desktop_plugin->priv->visible = TRUE;
1245         if (desktop_plugin->priv->long_timer == 0 )
1246             desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1247     }else{
1248         desktop_plugin->priv->visible = FALSE;
1249         if (desktop_plugin->priv->long_timer != 0 ){
1250             g_source_remove(desktop_plugin->priv->long_timer);
1251             desktop_plugin->priv->long_timer = 0;
1252         }
1253     }
1254 }
1255
1256 gboolean
1257 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1258                                             gpointer user_data){
1259     fprintf(stderr,"gggggggggggggggggggg2222\n");
1260 }    
1261 static void
1262 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1263 {
1264     GtkWidget *widget;
1265     GtkWidget *rich_animation;
1266     gchar           buffer[2048];
1267
1268     GtkWidget  *background_town = NULL;
1269
1270     fprintf(stderr, "!!!!!!!plugin init \n");
1271     Animation_WallpaperPrivate *priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1272     desktop_plugin->priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1273
1274     /* Load config */
1275     read_config(priv);
1276     priv->desktop_plugin = desktop_plugin;
1277     widget = gtk_fixed_new();
1278
1279     gtk_widget_set_size_request(widget, 100, 32);
1280     snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1281     background_town = gtk_image_new_from_file (buffer);
1282     if (background_town){
1283         gtk_fixed_put(GTK_FIXED(widget), background_town, 0, 0);
1284         gtk_widget_show (background_town);
1285     }
1286     /* Create rich animation event */
1287     rich_animation = gtk_event_box_new();
1288     if(rich_animation){
1289         gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1290         gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1291         gtk_widget_set_size_request(rich_animation, 100, 32);
1292         gtk_widget_show (rich_animation);
1293         g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1294         gtk_fixed_put(GTK_FIXED(widget), rich_animation, 0, 0);
1295     }
1296 /*
1297     GtkWidget *label = gtk_label_new ("ddddddddddddd"); 
1298     gtk_widget_set_size_request(label, 95, 30);
1299     gtk_widget_show (label);
1300 //    gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1301     gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1302 */
1303     hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1304     g_signal_connect (desktop_plugin, "show-settings",
1305                              G_CALLBACK (lw_settings), priv);
1306     gtk_widget_show (widget);
1307     gtk_container_add (GTK_CONTAINER (desktop_plugin), widget);
1308     init_applet_position();
1309
1310     
1311     fprintf(stderr, "!!!theme = %s\n", priv->theme);
1312     if (!strcmp(priv->theme,"Modern"))
1313         init_scene(desktop_plugin);
1314     else if (!strcmp(priv->theme,"Berlin")) 
1315         init_scene1(desktop_plugin);
1316     priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1317     priv->short_timer = 0;
1318     /* TODO Move scene to priv */
1319     scene.timer_type = LONG_TIMER_TYPE;
1320     g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1321                      G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1322
1323    
1324     //sleep(2);
1325 }
1326
1327 static void
1328 lw_applet_finalize (GObject *object)
1329 {
1330      AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1331      Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1332      
1333      fprintf(stderr,"finalaze %i\n", priv->long_timer);
1334      if (priv->long_timer){
1335         g_source_remove(priv->long_timer);
1336         priv->long_timer = 0;
1337      }
1338      if (priv->short_timer){
1339         g_source_remove(priv->short_timer);
1340         priv->short_timer = 0;
1341      }
1342
1343      destroy_scene();
1344 }
1345
1346 static void
1347 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1348
1349     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1350     GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1351
1352     /* gobject */
1353     gobject_class->destroy = (gpointer)lw_applet_finalize;
1354     widget_class->realize = lw_applet_realize;
1355     widget_class->expose_event = lw_applet_expose_event;
1356
1357     g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1358
1359 }
1360
1361 static void
1362 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {
1363 }