d0637a806dbf868c81080b33d71fc6aae656c0c0
[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     //fprintf(stderr, "change tram\n");
330     gettimeofday(&tvb, NULL);
331     
332     ms = tvb.tv_usec;
333     sec = tvb.tv_sec;
334     
335     if (!actor->visible){
336         actor->visible = TRUE;
337         if (scene.daytime == TIME_NIGHT){
338             if (actor->filename)
339                 g_free(actor->filename);
340             actor->filename = g_strdup("tram_dark.png");
341         } else{
342             if (actor->filename)
343                 g_free(actor->filename);
344             actor->filename = g_strdup("tram.png");
345         }
346         create_hildon_actor(actor, desktop_plugin);
347     }
348     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
349     x = path_line(x0, x1, t);
350     y = path_line(y0, y1, t);
351     scale = path_line(scale0, scale1, t);
352     //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
353     actor_set_position_full(actor->widget, x, y, actor->z);
354     hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
355     if (t >= 1){
356         /* stop animation */
357         actor->visible = FALSE;
358         destroy_hildon_actor(actor);
359         actor->time_start_animation = sec + fast_rnd(300);
360     }
361 }
362
363 void
364 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
365 {
366     gint x0 = 620, y0 = 233, scale0 = 100,
367          x1 = 79, y1 = -146, scale1 = 100, 
368          x, y, scale;
369     struct timeval tvb;     
370     suseconds_t ms;
371     long sec;
372     double t;
373
374     gettimeofday(&tvb, NULL);
375     
376     ms = tvb.tv_usec;
377     sec = tvb.tv_sec;
378 //    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
379    
380     if (scene.daytime != TIME_NIGHT){
381         if (actor->time_start_animation == 0){
382             actor->time_start_animation = sec + probability_plane();
383             return;
384         }
385     }
386     if (!actor->visible){
387         actor->visible = TRUE;
388         create_hildon_actor(actor, desktop_plugin);
389     }
390     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
391     x = path_line(x0, x1, t);
392     y = path_line(y0, y1, t);
393     //scale = path_line(scale0, scale1, t);
394     //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
395     actor_set_position_full(actor->widget, x, y, actor->z);
396     //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
397     if (t >= 1){
398         /* stop animation */
399         actor->visible = FALSE;
400         destroy_hildon_actor(actor);
401         if (scene.daytime == TIME_NIGHT) 
402             actor->time_start_animation = 0;
403         else 
404             actor->time_start_animation = sec + probability_plane();
405     }
406
407 }
408
409 void
410 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
411 {
412     gint x0 = -actor->width, y0 = 45, scale0 = 100,
413          x1 = 800, y1 = 20, scale1 = 100, 
414          x, y, scale;
415     struct timeval tvb;     
416     suseconds_t ms;
417     long sec;
418     double t;
419
420     gettimeofday(&tvb, NULL);
421     
422     ms = tvb.tv_usec;
423     sec = tvb.tv_sec;
424 //    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
425     if (scene.daytime != TIME_NIGHT){
426         if (actor->time_start_animation == 0){
427             actor->time_start_animation = sec + probability_plane();
428             return;
429         }
430     }
431     if (!actor->visible){
432         actor->visible = TRUE;
433         create_hildon_actor(actor, desktop_plugin);
434     }
435
436     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
437     x = path_line(x0, x1, t);
438     y = path_line(y0, y1, t);
439     //scale = path_line(scale0, scale1, t);
440     //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
441     actor_set_position_full(actor->widget, x, y, actor->z);
442     //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
443     if (t >= 1){
444         /* stop animation */
445         actor->visible = FALSE;
446         destroy_hildon_actor(actor);
447         if (scene.daytime == TIME_NIGHT) 
448             actor->time_start_animation = 0;
449         else 
450             actor->time_start_animation = sec + probability_plane();
451     }
452
453 }
454
455 void
456 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
457 {
458     gint x0, y0 = 300, scale0 = 100,
459          x1, y1 = -actor->height, scale1 = 150, 
460          x, y, scale;
461     struct timeval tvb;     
462     suseconds_t ms;
463     long sec;
464     double t;
465
466     //fprintf(stderr, "change cloud\n");
467     gettimeofday(&tvb, NULL);
468     
469     ms = tvb.tv_usec;
470     sec = tvb.tv_sec;
471     //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
472    
473     if (!actor->visible){
474         actor->visible = TRUE;
475         if (scene.daytime == TIME_NIGHT)
476             actor->filename = actor->filename;
477         else
478             actor->filename = actor->filename;
479         create_hildon_actor(actor, desktop_plugin);
480     }
481     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
482     
483     if (scene.wind_orientation == 1){
484         x0 = -actor->width;
485         x1 = 800;
486     }
487     else {
488         x0 = 800;
489         x1 = -actor->width;
490     }
491
492     x = path_line(x0, x1, t);    
493     y = -scene.wind_angle * (x - x0) + actor->y;
494     scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
495
496     //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
497     actor_set_position_full(actor->widget, x, y, actor->z);
498     hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
499     if ((y < y1 || y > y0) || t >= 1){
500         /* stop animation */
501         actor->visible = FALSE;
502         destroy_hildon_actor(actor);
503         actor->time_start_animation = sec + fast_rnd(300);
504         actor->y = fast_rnd(300);
505     }
506
507 }
508
509 void
510 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
511 {
512     scene.wind_orientation = fast_rnd(2);
513     if (scene.wind_orientation == 0) scene.wind_orientation = -1;
514     scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
515     actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
516     //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
517 }
518
519 void 
520 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
521 {
522     
523     gint now = time(NULL);
524
525     if (scene.daytime == TIME_DAY){
526         if (actor->visible){
527             actor->visible = FALSE;
528             destroy_hildon_actor(actor);
529         }
530         actor->time_start_animation = 0;
531         return;
532     }else if (actor->time_start_animation == 0){
533         actor->time_start_animation = now + fast_rnd(30);
534         return;
535     }
536
537     if (!actor->visible){
538         actor->visible = TRUE;
539         create_hildon_actor(actor, desktop_plugin);
540         actor->time_start_animation = now + fast_rnd(60) + 10;
541     }else {
542         actor->visible = FALSE;
543         destroy_hildon_actor(actor);
544         actor->time_start_animation = now + fast_rnd(60) + 10;
545     }
546    
547 }
548
549 void
550 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin) 
551 {
552   GtkWidget *ha = NULL;
553   GdkPixbuf *pixbuf = NULL;
554   GtkWidget *image = NULL;
555   gchar     *str = NULL;
556
557   /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
558   ha = hildon_animation_actor_new();
559   str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
560                         desktop_plugin->priv->theme, actor->filename);
561   pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
562                                              actor->width, 
563                                              actor->height, 
564                                              NULL);
565   if (str)
566       g_free(str);
567   if (pixbuf){
568       image = gtk_image_new_from_pixbuf (pixbuf);
569       g_object_unref(G_OBJECT(pixbuf));
570   }
571   if (image){
572     g_signal_connect(G_OBJECT(image), "expose_event",
573                            G_CALLBACK(expose_event), pixbuf);
574     gtk_container_add (GTK_CONTAINER (ha), image);
575   }  
576   actor_set_position_full(ha, actor->x, actor->y, actor->z);
577   hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
578   hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
579   realize(ha);
580   gtk_widget_show_all(ha);
581
582   /* TO DO check it */
583   /*  gdk_flush (); */
584
585   //g_object_set_data(G_OBJECT(ha), "name", name);
586   //g_object_set_data(G_OBJECT(ha), "filename", filename);
587   g_object_set_data(G_OBJECT(ha), "image", image);
588   /*
589   g_object_set_data(G_OBJECT(ha), "x", x);
590   g_object_set_data(G_OBJECT(ha), "y", y);
591   g_object_set_data(G_OBJECT(ha), "z", z);
592   g_object_set_data(G_OBJECT(ha), "width", width);
593   g_object_set_data(G_OBJECT(ha), "height", height);
594   g_object_set_data(G_OBJECT(ha), "scale", scale);
595   g_object_set_data(G_OBJECT(ha), "visible", visible);
596   g_object_set_data(G_OBJECT(ha), "opacity", opacity);
597   g_object_set_data(G_OBJECT(ha), "func", pfunc);
598   */
599   hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
600   actor->widget = ha;
601 }
602
603
604 void
605 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
606 {
607     GtkWidget *image = NULL;
608     GdkPixbuf *pixbuf = NULL;
609     gchar     *str = NULL;
610
611     str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
612                             desktop_plugin->priv->theme, actor->filename);
613  
614     pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
615                                                actor->width, 
616                                                actor->height, 
617                                                NULL);
618     if(str)
619         g_free(str);
620     if (pixbuf){
621         image = gtk_image_new_from_pixbuf (pixbuf);
622         g_object_unref(G_OBJECT(pixbuf));
623     }
624     if (image){ 
625         g_signal_connect(G_OBJECT(image), "expose_event",
626                                        G_CALLBACK(expose_event), pixbuf);
627         if (g_object_get_data(G_OBJECT(actor->widget), "image")){
628             gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));  
629         }
630         g_object_set_data(G_OBJECT(actor->widget), "image", image);
631         gtk_container_add (GTK_CONTAINER (actor->widget), image);
632         realize(actor->widget);
633         gtk_widget_show_all(actor->widget);
634         /* TO DO check it */
635        /*  gdk_flush (); */
636
637
638     }
639
640 }
641
642
643 void 
644 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
645 {
646     gchar *newfile;
647     newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime); 
648     if (actor->filename)
649             g_free(actor->filename);
650     actor->filename = newfile;
651     change_hildon_actor(actor, desktop_plugin);
652 }
653
654 void 
655 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
656 {
657     gchar *newfile;
658     gchar           buffer[2048];
659
660     if (desktop_plugin->priv->right_corner)
661         gtk_widget_destroy(desktop_plugin->priv->right_corner);
662     snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
663                                   THEME_PATH, desktop_plugin->priv->theme, scene.daytime);
664     desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
665     if (desktop_plugin->priv->right_corner){
666         gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
667         gtk_widget_show (desktop_plugin->priv->right_corner);
668     }
669     change_static_actor(actor, desktop_plugin);
670
671 }
672
673
674 /*
675 static gint 
676 get_time(gint t){
677     // уравнение изменения времени
678     return t*1.1;
679 }
680 */
681 static void 
682 destroy_scene(void){
683     GSList * tmp = scene.actors;
684     Actor *actor;
685     while (tmp != NULL){
686         actor = tmp->data;
687         if (actor){
688             if (actor->filename)
689                 g_free(actor->filename);
690             if (actor->name)
691                 g_free(actor->name);
692             gtk_widget_destroy(actor->widget);
693             //actor->widget = NULL;
694             g_free(actor);
695         }
696         tmp = g_slist_next(tmp);
697     }
698     g_slist_free(tmp);
699
700 }
701
702 void
703 reload_scene(AWallpaperPlugin *desktop_plugin)
704 {
705     fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);  
706     destroy_scene();
707     if (!strcmp(desktop_plugin->priv->theme,"Modern"))
708         init_scene(desktop_plugin);
709     else if (!strcmp(desktop_plugin->priv->theme,"Berlin")) 
710         init_scene1(desktop_plugin);
711 }
712
713
714 /* Init Modern Scene */
715 static void
716 init_scene(AWallpaperPlugin *desktop_plugin)
717 {
718   Actor *actor;
719   gint now = time(NULL);
720   gint i;
721
722   /* fprintf(stderr, "init scene \n");*/
723   scene.daytime = get_daytime();
724   scene.actors = NULL;
725   scene.wind_orientation = -1;
726   scene.wind_angle = 0.3;
727   /* init value for random */
728   scene.seed = time(NULL);
729
730   
731
732   actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480, 
733                       TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
734   change_static_actor(actor, desktop_plugin);
735   scene.actors = g_slist_append(scene.actors, actor);
736
737   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
738                       TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
739   actor->time_start_animation = now;
740   actor->duration_animation = G_MAXINT;
741   change_sun(actor, desktop_plugin);
742   scene.actors = g_slist_append(scene.actors, actor);
743
744   //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
745     //                  TRUE, 100, 255, NULL, NULL);
746   //scene.actors = g_slist_append(scene.actors, actor);
747   
748   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
749                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
750   actor->time_start_animation = now + fast_rnd(180);
751   actor->duration_animation = 3*60;
752   scene.actors = g_slist_append(scene.actors, actor);
753   
754   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
755                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
756   actor->time_start_animation = now + fast_rnd(180);
757   actor->duration_animation = 3*60;
758   scene.actors = g_slist_append(scene.actors, actor);
759
760   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
761                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
762   actor->time_start_animation = now + fast_rnd(180);
763   actor->duration_animation = 5*60;
764   scene.actors = g_slist_append(scene.actors, actor);
765
766
767   actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480, 
768                       TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
769   change_static_actor(actor, desktop_plugin);
770   scene.actors = g_slist_append(scene.actors, actor);
771
772   actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210, 
773                       FALSE, 100, 255, (gpointer)&change_tram, NULL);
774   actor->time_start_animation = time(NULL) + fast_rnd(60);
775   actor->duration_animation = 60;
776   scene.actors = g_slist_append(scene.actors, actor);
777
778   actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
779                       TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
780   change_static_actor_with_corner(actor, desktop_plugin);
781   scene.actors = g_slist_append(scene.actors, actor);
782   
783   actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 6, 60, 60, 
784                       FALSE, 100, 255, (gpointer)&change_moon, NULL);
785   change_moon(actor, desktop_plugin);
786   scene.actors = g_slist_append(scene.actors, actor);
787
788   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
789                       FALSE, 100, 255, (gpointer)&change_wind, NULL);
790   change_wind(actor, desktop_plugin);
791   scene.actors = g_slist_append(scene.actors, actor);
792
793     /* windows in 4-th house  */
794     gint winds[13][2];
795
796     winds[0][0] = 482;
797     winds[0][1] = 180;
798
799     winds[1][0] = 495;
800     winds[1][1] = 179;
801
802     winds[2][0] = 482;
803     winds[2][1] = 191;
804
805     winds[3][0] = 495;
806     winds[3][1] = 190;
807     
808     winds[4][0] = 482;
809     winds[4][1] = 201;
810     
811     winds[5][0] = 495;
812     winds[5][1] = 210;
813     
814     winds[6][0] = 482;
815     winds[6][1] = 222;
816     
817     winds[7][0] = 495;
818     winds[7][1] = 221;
819     
820     winds[8][0] = 459;
821     winds[8][1] = 203;
822     
823     winds[9][0] = 495;
824     winds[9][1] = 241;
825     
826     winds[10][0] = 495;
827     winds[10][1] = 252;
828     
829     winds[11][0] = 482;
830     winds[11][1] = 273;
831     
832     winds[12][0] = 495;
833     winds[12][1] = 303;
834     for (i=0; i<13; i++){
835         actor = init_object(desktop_plugin, "window1", "window1.png", 
836                             winds[i][0], winds[i][1], 8, 8, 10, 
837                             FALSE, 100, 255, (gpointer)&change_window1, NULL);
838         //change_window1(actor, desktop_plugin);
839         actor->time_start_animation = now + fast_rnd(30);
840         scene.actors = g_slist_append(scene.actors, actor);
841
842     }
843     
844     /* windows in 1-th house  */
845     
846     winds[0][0] = 86;
847     winds[0][1] = 321;
848
849     winds[1][0] = 86;
850     winds[1][1] = 363;
851
852     winds[2][0] = 86;
853     winds[2][1] = 385;
854
855     winds[3][0] = 86;
856     winds[3][1] = 286;
857     
858     winds[4][0] = 94;
859     winds[4][1] = 232;
860     
861     winds[5][0] = 94;
862     winds[5][1] = 243;
863     
864     winds[6][0] = 94;
865     winds[6][1] = 265;
866     
867     winds[7][0] = 94;
868     winds[7][1] = 331;
869     for (i=0; i<8; i++){
870         actor = init_object(desktop_plugin, "window2", "window2.png", 
871                             winds[i][0], winds[i][1], 8, 8, 10, 
872                             TRUE, 100, 255, (gpointer)&change_window1, NULL);
873         //change_window1(actor, desktop_plugin);
874         actor->time_start_animation = now + fast_rnd(30);
875         scene.actors = g_slist_append(scene.actors, actor);
876
877     }
878     
879     /* windows in 3-th house  */
880     
881     winds[0][0] = 251;
882     winds[0][1] = 162;
883
884     winds[1][0] = 251;
885     winds[1][1] = 196;
886
887     winds[2][0] = 251;
888     winds[2][1] = 278;
889
890     winds[3][0] = 251;
891     winds[3][1] = 289;
892     
893     winds[4][0] = 313;
894     winds[4][1] = 173;
895     
896     winds[5][0] = 322;
897     winds[5][1] = 160;
898     
899     winds[6][0] = 303;
900     winds[6][1] = 217;
901     
902     winds[7][0] = 322;
903     winds[7][1] = 224;
904     
905     winds[8][0] = 323;
906     winds[8][1] = 217;
907     
908     winds[9][0] = 322;
909     winds[9][1] = 288;
910     
911     for (i=0; i<10; i++){
912         actor = init_object(desktop_plugin, "window3", "window3.png", 
913                             winds[i][0], winds[i][1], 8, 8, 10, 
914                             FALSE, 100, 255, (gpointer)&change_window1, NULL);
915         //change_window1(actor, desktop_plugin);
916         actor->time_start_animation = now + fast_rnd(30);
917         scene.actors = g_slist_append(scene.actors, actor);
918
919     }
920
921     /* windows in 5-th house  */
922     
923     winds[0][0] = 610;
924     winds[0][1] = 224;
925
926     winds[1][0] = 602;
927     winds[1][1] = 245;
928
929     winds[2][0] = 602;
930     winds[2][1] = 264;
931
932     winds[3][0] = 610;
933     winds[3][1] = 301;
934     
935     winds[4][0] = 610;
936     winds[4][1] = 320;
937     
938     winds[5][0] = 593;
939     winds[5][1] = 352;
940     
941     winds[6][0] = 610;
942     winds[6][1] = 368;
943     
944     for (i=0; i<7; i++){
945         actor = init_object(desktop_plugin, "window4", "window4.png", 
946                             winds[i][0], winds[i][1], 8, 8, 10, 
947                             FALSE, 100, 255, (gpointer)&change_window1, NULL);
948         //change_window1(actor, desktop_plugin);
949         actor->time_start_animation = now + fast_rnd(30);
950         scene.actors = g_slist_append(scene.actors, actor);
951
952     }
953
954     /* windows in 6-th house  */
955     
956     winds[0][0] = 717;
957     winds[0][1] = 283;
958
959     winds[1][0] = 698;
960     winds[1][1] = 293;
961
962     winds[2][0] = 717;
963     winds[2][1] = 315;
964
965     winds[3][0] = 717;
966     winds[3][1] = 323;
967     
968     winds[4][0] = 698;
969     winds[4][1] = 362;
970     
971     winds[5][0] = 698;
972     winds[5][1] = 400;
973     
974     for (i=0; i<6; i++){
975         actor = init_object(desktop_plugin, "window5", "window5.png", 
976                             winds[i][0], winds[i][1], 8, 8, 10, 
977                             FALSE, 100, 255, (gpointer)&change_window1, NULL);
978         //change_window1(actor, desktop_plugin);
979         actor->time_start_animation = now + fast_rnd(30);
980         scene.actors = g_slist_append(scene.actors, actor);
981
982     }
983
984 #if 0    
985   anim = g_new0(Animation, 1);
986   anim->count = 1;
987   anim->actor = actor;
988   anim->func_change = &change_tram;
989   anim->func_time = NULL;
990   anim->timestart = time(NULL); 
991   anim->timeall = 10;
992   
993   scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
994 #endif  
995  }
996
997 /* Init Berlin Scene */
998 static void
999 init_scene1(AWallpaperPlugin *desktop_plugin)
1000 {
1001   Actor *actor;
1002   gint now = time(NULL);
1003   
1004
1005   scene.daytime = get_daytime();
1006   scene.actors = NULL;
1007   scene.wind_orientation = -1;
1008   scene.wind_angle = 0.3;
1009   /* init value for random */
1010   scene.seed = time(NULL);
1011
1012   
1013   actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480, 
1014                       TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
1015   change_static_actor(actor, desktop_plugin);
1016   scene.actors = g_slist_append(scene.actors, actor);
1017
1018   
1019   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
1020                       TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
1021   actor->time_start_animation = time(NULL);
1022   actor->duration_animation = G_MAXINT;
1023   change_sun(actor, desktop_plugin);
1024   scene.actors = g_slist_append(scene.actors, actor);
1025
1026 #if 0
1027   actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
1028                       TRUE, 100, 255, NULL, NULL);
1029   scene.actors = g_slist_append(scene.actors, actor);
1030 #endif
1031
1032   actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60, 
1033                       FALSE, 100, 255, (gpointer)&change_moon, NULL);
1034   change_moon(actor, desktop_plugin);
1035   scene.actors = g_slist_append(scene.actors, actor);
1036   
1037   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
1038                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1039   actor->time_start_animation = now + fast_rnd(180);
1040   actor->duration_animation = 3*60;
1041   scene.actors = g_slist_append(scene.actors, actor);
1042   
1043   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
1044                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1045   actor->time_start_animation = now + fast_rnd(180);
1046   actor->duration_animation = 3*60;
1047   scene.actors = g_slist_append(scene.actors, actor);
1048
1049   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
1050                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1051   actor->time_start_animation = now + fast_rnd(180);
1052   actor->duration_animation = 5*60;
1053   scene.actors = g_slist_append(scene.actors, actor);
1054
1055  
1056   actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
1057                       FALSE, 100, 255, (gpointer)&change_plane2, NULL);
1058   actor->time_start_animation = now/* + probability_plane()*/;
1059   actor->duration_animation = 60;
1060   scene.actors = g_slist_append(scene.actors, actor);
1061   
1062   actor = init_object(desktop_plugin, "plane1", "tu154_small.png", 620, 233, 9, 300, 116, 
1063                       FALSE, 100, 255, (gpointer)&change_plane1, NULL);
1064   actor->time_start_animation = now + probability_plane();
1065   actor->duration_animation = 30;
1066   scene.actors = g_slist_append(scene.actors, actor);
1067
1068   actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
1069                       TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
1070   change_static_actor_with_corner(actor, desktop_plugin);
1071   scene.actors = g_slist_append(scene.actors, actor);
1072
1073   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
1074                       FALSE, 100, 255, (gpointer)&change_wind, NULL);
1075   change_wind(actor, desktop_plugin);
1076   scene.actors = g_slist_append(scene.actors, actor);
1077
1078 }
1079
1080
1081 void 
1082 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
1083 {
1084     gint y0 = 365;// - уровень горизонта
1085     *x = (int)(azm * 800) - 64;
1086     *y = (int)((1 - alt) * y0) - 64;
1087     //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
1088 }
1089 #if 0
1090 static void 
1091 change_actor(GtkWidget * actor)
1092 {
1093     char * name;
1094     gint x, y, daytime, scale;
1095     gdouble sc;
1096     double alt, azm;
1097
1098     GtkWidget *image;
1099     GdkPixbuf *pixbuf;
1100
1101     void (*pfunc)(gpointer, gpointer);
1102
1103     name = g_object_get_data(G_OBJECT(actor), "name");
1104     fprintf(stderr, "change actor %s\n", name);
1105     if (name == "sun"){
1106         pfunc = g_object_get_data(G_OBJECT(actor), "func");
1107         if (pfunc)
1108             (*pfunc)(actor, g_strdup(name));
1109         daytime = get_daytime();
1110         if (daytime != TIME_NIGHT){
1111             hildon_animation_actor_set_show(actor, 1);
1112             get_sun_pos(&alt, &azm);
1113             get_sun_screen_pos(alt, azm, &x, &y);
1114             actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1115         }
1116     }
1117     
1118     if (name == "cloud1"){
1119         x = g_object_get_data(G_OBJECT(actor), "x");
1120         y = g_object_get_data(G_OBJECT(actor), "y");
1121         scale = g_object_get_data(G_OBJECT(actor), "scale");
1122
1123         /* Start */
1124         image = g_object_get_data(G_OBJECT(actor), "image");
1125         
1126         gtk_container_remove(actor, image);  
1127         pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png", 
1128                                              200, 
1129                                              200, 
1130                                              NULL);
1131         if (pixbuf){
1132               image = gtk_image_new_from_pixbuf (pixbuf);
1133               g_object_unref(G_OBJECT(pixbuf));
1134         }
1135         g_signal_connect(G_OBJECT(image), "expose_event",
1136                                    G_CALLBACK(expose_event), pixbuf);
1137         gtk_container_add (GTK_CONTAINER (actor), image);
1138         realize(actor);
1139         gtk_widget_show_all(actor);
1140         /* End*/
1141
1142             
1143         x += 40;
1144         y -= 20;
1145         scale -= 10;
1146         if (x > 500){
1147             x = 400;
1148             y = 150;
1149             sc = 1;
1150         }
1151         sc = (double)scale / 100;
1152         hildon_animation_actor_set_scale(actor, sc, sc);
1153         fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
1154         actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1155         g_object_set_data(G_OBJECT(actor), "x", x);
1156         g_object_set_data(G_OBJECT(actor), "y", y);
1157         g_object_set_data(G_OBJECT(actor), "scale", scale);
1158     }
1159
1160 }
1161 #endif
1162 static gboolean
1163 short_timeout (AWallpaperPlugin *desktop_plugin)
1164 {
1165     gint daytime = get_daytime();
1166     GSList * tmp;
1167     void (*pfunc)(gpointer, gpointer);
1168     time_t now;
1169     Actor *actor;
1170     gboolean stop_flag = TRUE;
1171
1172     if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
1173         desktop_plugin->priv->short_timer = 0;
1174         return FALSE;
1175     }
1176
1177     now = time(NULL);
1178     //scene.daytime = daytime;
1179     /* fprintf(stderr, "Short timer %d\n", now); */
1180     tmp = scene.actors;
1181     while (tmp != NULL){
1182            actor = tmp->data;
1183            if (now >= actor->time_start_animation  
1184                && actor->time_start_animation > 0
1185                /* && now - actor->time_start_animation <= actor->duration_animation*/){
1186                 pfunc = actor->func_change;
1187                 if (pfunc){ 
1188                     (*pfunc)(actor, desktop_plugin);
1189                     stop_flag = FALSE;
1190                 }
1191             }
1192             tmp = g_slist_next(tmp);
1193     }
1194     if (stop_flag){
1195          desktop_plugin->priv->short_timer = 0;
1196          return FALSE;
1197     }else
1198          return TRUE; /* keep running this event */
1199 }
1200
1201 void
1202 run_long_timeout(AWallpaperPlugin *desktop_plugin){
1203
1204     gint daytime = get_daytime();
1205     GSList * tmp;
1206     void (*pfunc)(gpointer, gpointer);
1207     time_t now;
1208     Actor *actor;
1209
1210
1211     //fprintf(stderr, "timer daytime=%d\n", daytime);
1212     if (scene.daytime != daytime){
1213         scene.daytime = daytime;
1214         tmp = scene.actors;
1215         while (tmp != NULL){
1216             //change_actor(tmp->data);
1217             pfunc =((Actor*)tmp->data)->func_change;
1218             if (pfunc){
1219                 (*pfunc)(tmp->data, desktop_plugin);
1220             }
1221             tmp = g_slist_next(tmp);
1222         }
1223     }
1224    
1225     now = time(NULL);
1226     //fprintf(stderr, "Now  %d\n", now);
1227     tmp = scene.actors;
1228     while (tmp != NULL){
1229         actor = tmp->data;
1230         if (now >= actor->time_start_animation  
1231             && actor->time_start_animation > 0
1232             && desktop_plugin->priv->short_timer == 0){
1233             /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1234             if (desktop_plugin->priv->rich_animation){
1235                 actor->time_start_animation = now;
1236                 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1237             }
1238             else {
1239                 (*actor->func_change)(actor, desktop_plugin);
1240             }
1241         }
1242         tmp = g_slist_next(tmp);
1243     }
1244  
1245 }
1246
1247 static gboolean
1248 long_timeout (AWallpaperPlugin *desktop_plugin)
1249 {
1250     /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
1251     if (desktop_plugin->priv->long_timer == 0 )
1252         return FALSE;
1253     if (!desktop_plugin->priv->visible){
1254         if(desktop_plugin->priv->short_timer != 0){
1255             g_source_remove(desktop_plugin->priv->short_timer);
1256             desktop_plugin->priv->short_timer = 0;
1257         }
1258         desktop_plugin->priv->long_timer = 0;
1259         return FALSE;
1260     }
1261   
1262
1263     run_long_timeout(desktop_plugin);
1264     return TRUE; /* keep running this event */
1265 }
1266
1267 static void
1268 desktop_plugin_visible_notify (GObject    *object,
1269                                           GParamSpec *spec,
1270                                           AWallpaperPlugin *desktop_plugin)
1271 {
1272     gboolean visible;
1273     g_object_get (object, "is-on-current-desktop", &visible, NULL);
1274     /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1275     if (visible){
1276         desktop_plugin->priv->visible = TRUE;
1277         if (desktop_plugin->priv->long_timer == 0 ){
1278             desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1279             run_long_timeout(desktop_plugin);
1280         }
1281     }else{
1282         desktop_plugin->priv->visible = FALSE;
1283         if (desktop_plugin->priv->long_timer != 0 ){
1284             g_source_remove(desktop_plugin->priv->long_timer);
1285             desktop_plugin->priv->long_timer = 0;
1286         }
1287     }
1288 }
1289
1290 gboolean
1291 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1292                                             gpointer user_data){
1293     fprintf(stderr,"gggggggggggggggggggg2222\n");
1294 }    
1295 static void
1296 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1297 {
1298     GtkWidget *rich_animation;
1299     gchar           buffer[2048];
1300
1301
1302     fprintf(stderr, "!!!!!!!plugin init \n");
1303     Animation_WallpaperPrivate *priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1304     desktop_plugin->priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1305
1306     /* Load config */
1307     read_config(priv);
1308     priv->desktop_plugin = desktop_plugin;
1309     desktop_plugin->priv->main_widget = gtk_fixed_new();
1310
1311     gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
1312     desktop_plugin->priv->right_corner = NULL;
1313     snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1314     desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
1315     if (desktop_plugin->priv->right_corner){
1316         gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
1317         gtk_widget_show (desktop_plugin->priv->right_corner);
1318     }
1319     /* Create rich animation event */
1320     rich_animation = gtk_event_box_new();
1321     if(rich_animation){
1322         gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1323         gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1324         gtk_widget_set_size_request(rich_animation, 100, 32);
1325         gtk_widget_show (rich_animation);
1326         g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1327         gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
1328     }
1329 /*
1330     GtkWidget *label = gtk_label_new ("ddddddddddddd"); 
1331     gtk_widget_set_size_request(label, 95, 30);
1332     gtk_widget_show (label);
1333 //    gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1334     gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1335 */
1336     hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1337     g_signal_connect (desktop_plugin, "show-settings",
1338                              G_CALLBACK (lw_settings), priv);
1339     gtk_widget_show (desktop_plugin->priv->main_widget);
1340     gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
1341     init_applet_position();
1342
1343     
1344     fprintf(stderr, "!!!theme = %s\n", priv->theme);
1345     if (!strcmp(priv->theme,"Modern"))
1346         init_scene(desktop_plugin);
1347     else if (!strcmp(priv->theme,"Berlin")) 
1348         init_scene1(desktop_plugin);
1349     priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1350     priv->short_timer = 0;
1351     /* TODO Move scene to priv */
1352     scene.timer_type = LONG_TIMER_TYPE;
1353     g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1354                      G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1355
1356    
1357     //sleep(2);
1358 }
1359
1360 static void
1361 lw_applet_finalize (GObject *object)
1362 {
1363      AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1364      Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1365      
1366      fprintf(stderr,"finalaze %i\n", priv->long_timer);
1367      if (priv->long_timer){
1368         g_source_remove(priv->long_timer);
1369         priv->long_timer = 0;
1370      }
1371      if (priv->short_timer){
1372         g_source_remove(priv->short_timer);
1373         priv->short_timer = 0;
1374      }
1375
1376      destroy_scene();
1377 }
1378
1379 static void
1380 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1381
1382     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1383     GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1384
1385     /* gobject */
1386     gobject_class->destroy = (gpointer)lw_applet_finalize;
1387     widget_class->realize = lw_applet_realize;
1388     widget_class->expose_event = lw_applet_expose_event;
1389
1390     g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1391
1392 }
1393
1394 static void
1395 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {
1396 }