adde images for notifications
[livewp] / applet / src / livewp-home-widget.c
index e4dce2b..aa10397 100644 (file)
@@ -1,4 +1,4 @@
-/* vim: set sw=4 ts=4 et: */
+/*vim: set sw=4 ts=4 et: */
 /*
  * This file is part of Live Wallpaper (livewp)
  * 
@@ -26,7 +26,9 @@
 #include "livewp-home-widget.h"
 #include <gconf/gconf-client.h>
 #include "livewp-rules.h"
+#include "livewp-scene.h"
 #include <sys/time.h>
+#include <stdlib.h>
 
 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
@@ -38,14 +40,6 @@ HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_H
                                                           Animation_Wallpaper_TYPE_HOME_PLUGIN,\
                                                           Animation_WallpaperPrivate))
 
-/* Position of plugin on desktop */
-#define Xstartposition 700 
-#define Ystartposition 425 
-
-gint xapplet = 0, yapplet = 0;
-GSList * objects_list = NULL;
-Scene scene;
-
 static void
 lw_applet_realize (GtkWidget *widget)
 {
@@ -111,7 +105,7 @@ realize (GtkWidget *widget)
 
 /* Set position of widget on desktop */
 static void
-init_applet_position(void)
+init_applet_position(gint *xapplet, gint *yapplet)
 {
   GSList *position = NULL;
   gchar *position_key;
@@ -125,8 +119,8 @@ init_applet_position(void)
                                     GCONF_VALUE_INT,
                                     NULL);
   if (position && position->data && position->next->data){
-       xapplet = GPOINTER_TO_INT (position->data);
-       yapplet = GPOINTER_TO_INT (position->next->data);
+       *xapplet = GPOINTER_TO_INT (position->data);
+       *yapplet = GPOINTER_TO_INT (position->next->data);
   }else{
        position = g_slist_prepend (g_slist_prepend (NULL,
                                       GINT_TO_POINTER (Ystartposition)),
@@ -136,11 +130,11 @@ init_applet_position(void)
                                GCONF_VALUE_INT,
                               position,
                               &error);
-       xapplet = Xstartposition;
-       yapplet = Ystartposition;
+       *xapplet = Xstartposition;
+       *yapplet = Ystartposition;
   }
   g_free (position_key);
-  modified = g_strdup_printf ("%ld", 0);
+  modified = g_strdup_printf ("%i", 0);
   modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
   gconf_client_set_string (gconf_client,
                            modified_key,
@@ -151,190 +145,65 @@ init_applet_position(void)
   gconf_client_clear_cache(gconf_client);
   g_object_unref(gconf_client);
 }
-
+#if 0
 void
 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
 {
-// fprintf(stderr, "actor_set_position_full\n");
- hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
-}
-
-static gint 
-path_line(gint x0, gint x1, double t)
-{
-    // уравниение прямой
-    return ((x1 - x0) * t + x0);
+/*  fprintf(stderr, "actor_set_position_full z=%d\n", z); */
+    hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-0, y-0, z);
 }
-
+#endif
 
 void
 destroy_hildon_actor(Actor *actor)
 {
-    fprintf(stderr, "estroy_hildon_actor %p\n",actor->widget);
+    //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
     gtk_widget_destroy(actor->widget);
     actor->widget = NULL;
 }
 
-static Actor* 
-init_object(AWallpaperPlugin *desktop_plugin, 
-            gchar * name, 
-            gchar * filename, 
-            gint x, 
-            gint y, 
-            gint z, 
-            gint width, 
-            gint height, 
-            gboolean visible, 
-            gint scale, 
-            gint opacity, 
-            void (*pfunc_change)(Actor*),
-            void (*pfunc_probability)(Actor*)
-           )
+void
+create_hildon_actor_text(Actor *actor, AWallpaperPlugin *desktop_plugin) 
 {
-  Actor *actor = NULL;
-  actor = g_new0(Actor, 1);
-  actor->x = x;
-  actor->y = y;
-  actor->z = z;
-  actor->width = width;
-  actor->height = height;
-  actor->visible = visible;
-  actor->scale = scale;
-  actor->opacity = opacity;
-  actor->filename = g_strdup(filename);
-  actor->name = g_strdup(name);
-  actor->func_change = pfunc_change; 
-  actor->func_probability = pfunc_probability;
-  if (visible)
-    create_hildon_actor(actor, desktop_plugin);
-  else 
-    actor->widget = NULL;
-  actor->time_start_animation = 0;
-  actor->duration_animation = 0;
-  /*
-  a.widget = actor;
-  a.name = name;
-  a.x = x;
-  a.y = y;
-  a.z = z;
-  */
-  //objects_list = g_slist_append(objects_list, G_OBJECT(actor));
-  //objects_list = g_slist_append(objects_list, G_OBJECT(a));
-  return actor;
-}
+  GtkWidget *ha = NULL;
+  GdkPixbuf *pixbuf = NULL;
+  GtkWidget *image = NULL;
+  GtkWidget *label = NULL;
 
-void 
-change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
-{
-    gint x, y, z, daytime, phase;
-    char *newfile;
-
-    if (actor){
-        daytime = get_daytime();
-        if (daytime == TIME_NIGHT){
-            if (!actor->visible){
-                actor->visible = TRUE;
-                phase = get_moon_phase();
-                newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
-                
-                actor->filename = newfile;
-                create_hildon_actor(actor, desktop_plugin);
+  ha = hildon_animation_actor_new();
+  label = gtk_label_new(NULL);  
 
-            }
-            //actor->x = 400;
-            //actor->y = 10;
-           // actor_set_position_full(actor->widget, x, y, actor->z);
-            //probability_sun(actor);
-            //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
-         }else if (actor->visible){
-            actor->visible = FALSE;
-            fprintf(stderr, "destroy moon \n");
-            destroy_hildon_actor(actor);
-            /* TO DO make moonrise*/
-            actor->time_start_animation = get_next_sunset();
-        } 
-    }
-    
+  if (label){
+    //g_signal_connect(G_OBJECT(label), "expose_event", G_CALLBACK(expose_event), NULL);
+
+    gtk_container_add (GTK_CONTAINER (ha), label);
+  }  
+  realize(ha);
+  gtk_widget_show(label);
+  gtk_widget_show_all(ha);
+  
+  /* TO DO check it */
+  /*  gdk_flush (); */
+
+  //g_object_set_data(G_OBJECT(ha), "image", image);
+  actor->image = label;
+  hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
+  actor->widget = ha;
+  set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
+  set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
+  set_actor_visible(actor, actor->visible);
 }
 
-void 
-change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
-{
-    double alt, azm;
-    gint x, y, z, daytime;
 
-    if (actor){
-        daytime = get_daytime();
-        if (daytime != TIME_NIGHT){
-            if (!actor->visible){
-                actor->visible = TRUE;
 
-                create_hildon_actor(actor, desktop_plugin);
-            }
-            get_sun_pos(&alt, &azm);
-            get_sun_screen_pos(alt, azm, &x, &y);
-            actor->x = x;
-            actor->y = y;
-            actor_set_position_full(actor->widget, x, y, actor->z);
-            probability_sun(actor);
-         }else if (actor->visible){
-            actor->visible = FALSE;
-            destroy_hildon_actor(actor);
-            actor->time_start_animation = get_next_sunrise();
-        } 
-    }
-    
-}
-static void 
-change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
-{
-    gint x0 = -300, y0 = 225, scale0 = 100,
-         x1 = 800, y1 = 162, scale1 = 130, 
-         x, y, scale;
-    struct timeval tvb;     
-    suseconds_t ms;
-    long sec;
-
-    gettimeofday(&tvb, NULL);
-    
-    gint daytime = get_daytime();
-    ms = tvb.tv_usec;
-    sec = tvb.tv_sec;
-    time_t now = time(NULL);
-    double t;
-//    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
-   
-    if (!actor->visible){
-        actor->visible = TRUE;
-        if (daytime == TIME_NIGHT)
-            actor->filename = g_strdup("tram_dark.png");
-        else
-            actor->filename = g_strdup("tram.png");
-        create_hildon_actor(actor, desktop_plugin);
-    }
-    t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
-    x = path_line(x0, x1, t);
-    y = path_line(y0, y1, t);
-    scale = path_line(scale0, scale1, t);
-    //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
-    actor_set_position_full(actor->widget, x, y, actor->z);
-    hildon_animation_actor_set_scale(actor->widget, (double)scale/100, (double)scale/100);
-    if (t >= 1){
-        /* stop animation */
-        actor->visible = FALSE;
-        destroy_hildon_actor(actor);
-        actor->time_start_animation = now + 5*60;
-    }
-}
 void
 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin) 
 {
   GtkWidget *ha = NULL;
   GdkPixbuf *pixbuf = NULL;
   GtkWidget *image = NULL;
-  gchar *str;
+  gchar     *str = NULL;
 
-  fprintf(stderr, "create_hildon_actor %s\n", actor->name);
   ha = hildon_animation_actor_new();
   str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
                         desktop_plugin->priv->theme, actor->filename);
@@ -342,6 +211,9 @@ create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
                                              actor->width, 
                                              actor->height, 
                                              NULL);
+  /*fprintf(stderr, "create_hildon_actor %s %s\n", actor->name, str);*/
+  if (str)
+      g_free(str);
   if (pixbuf){
       image = gtk_image_new_from_pixbuf (pixbuf);
       g_object_unref(G_OBJECT(pixbuf));
@@ -351,29 +223,19 @@ create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
                            G_CALLBACK(expose_event), pixbuf);
     gtk_container_add (GTK_CONTAINER (ha), image);
   }  
-  actor_set_position_full(ha, actor->x, actor->y, actor->z);
-  hildon_animation_actor_set_show (ha, actor->visible);
-  hildon_animation_actor_set_scale(ha, (double)actor->scale/100, (double)actor->scale/100);
   realize(ha);
   gtk_widget_show_all(ha);
+  
+  /* TO DO check it */
+  /*  gdk_flush (); */
 
-  //g_object_set_data(G_OBJECT(ha), "name", name);
-  //g_object_set_data(G_OBJECT(ha), "filename", filename);
-  g_object_set_data(G_OBJECT(ha), "image", image);
-  /*
-  g_object_set_data(G_OBJECT(ha), "x", x);
-  g_object_set_data(G_OBJECT(ha), "y", y);
-  g_object_set_data(G_OBJECT(ha), "z", z);
-  g_object_set_data(G_OBJECT(ha), "width", width);
-  g_object_set_data(G_OBJECT(ha), "height", height);
-  g_object_set_data(G_OBJECT(ha), "scale", scale);
-  g_object_set_data(G_OBJECT(ha), "visible", visible);
-  g_object_set_data(G_OBJECT(ha), "opacity", opacity);
-  g_object_set_data(G_OBJECT(ha), "func", pfunc);
-  */
-  hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), desktop_plugin);
-      fprintf(stderr, "ha %p\n", ha);
+  //g_object_set_data(G_OBJECT(ha), "image", image);
+  actor->image = image;
+  hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
   actor->widget = ha;
+  set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
+  set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
+  set_actor_visible(actor, actor->visible);
 }
 
 
@@ -382,7 +244,7 @@ change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
 {
     GtkWidget *image = NULL;
     GdkPixbuf *pixbuf = NULL;
-    gchar *str;
+    gchar     *str = NULL;
 
     str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
                             desktop_plugin->priv->theme, actor->filename);
@@ -391,6 +253,8 @@ change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
                                                actor->width, 
                                                actor->height, 
                                                NULL);
+    if(str)
+        g_free(str);
     if (pixbuf){
         image = gtk_image_new_from_pixbuf (pixbuf);
         g_object_unref(G_OBJECT(pixbuf));
@@ -398,319 +262,43 @@ change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
     if (image){ 
         g_signal_connect(G_OBJECT(image), "expose_event",
                                        G_CALLBACK(expose_event), pixbuf);
-        if (g_object_get_data(G_OBJECT(actor->widget), "image")){
-            gtk_container_remove(actor->widget, g_object_get_data(G_OBJECT(actor->widget), "image"));  
+        //if (g_object_get_data(G_OBJECT(actor->widget), "image")){
+        if (actor->image){
+            gtk_container_remove(GTK_CONTAINER(actor->widget), actor->image);  
         }
-        g_object_set_data(G_OBJECT(actor->widget), "image", image);
+        //g_object_set_data(G_OBJECT(actor->widget), "image", image);
+        actor->image = image;
         gtk_container_add (GTK_CONTAINER (actor->widget), image);
         realize(actor->widget);
         gtk_widget_show_all(actor->widget);
-    }
-
-}
+        /* TO DO check it */
+       /*  gdk_flush (); */
 
 
-void 
-change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
-{
-    gint daytime;
-    gchar *newfile;
-    if (!actor) return;
-    daytime = get_daytime();
-    newfile = g_strdup_printf("%s%d.png", actor->name, daytime); 
-    actor->filename = newfile;
-    change_hildon_actor(actor, desktop_plugin);
-}
-
-
-
-void change_sky(GtkWidget * actor, gpointer data)
-{
-    gint daytime, opacity;
-    //fprintf(stderr, "change sky \n");
-    if (actor){
-        daytime = get_daytime();
-        opacity = g_object_get_data(G_OBJECT(actor), "opacity") - 10;
-        if (opacity < 0) opacity = 255;
-        hildon_animation_actor_set_show_full(actor, 1, opacity);
-        g_object_set_data(G_OBJECT(actor), "opacity", opacity);
-        switch (daytime){
-            case TIME_NIGHT:
-                //fprintf(stderr, "change sky night\n");
-            break;
-            case TIME_DAY:
-                //fprintf(stderr, "change sky day\n");
-            break;
-
-        }
-    }
-}
-void 
-change_background(GtkWidget * actor, gpointer data)
-{
-    gint opacity;
-    if (actor){
-        opacity = g_object_get_data(G_OBJECT(actor), "opacity") - 1;
-        if (opacity < 0) opacity = 255;
-        hildon_animation_actor_set_show_full(actor, 1, opacity);
-        g_object_set_data(G_OBJECT(actor), "opacity", opacity);
-
-    }
-}
-
-static gint 
-get_time(gint t){
-    // уравнение изменения времени
-    return t*1.1;
-}
-
-static void 
-destroy_scene(void){
-    GSList * tmp = scene.actors;
-    Actor *actor;
-    while (tmp != NULL){
-        actor = tmp->data;
-        if (actor){
-            gtk_widget_destroy(actor->widget);
-            //actor->widget = NULL;
-            g_free(actor);
-        }
-        tmp = g_slist_next(tmp);
     }
-    g_slist_free(tmp);
-
-}
-
-void
-reload_scene(AWallpaperPlugin *desktop_plugin)
-{
-    fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);  
-    destroy_scene();
-    if (!strcmp(desktop_plugin->priv->theme,"Modern"))
-        init_scene(desktop_plugin);
-    else if (!strcmp(desktop_plugin->priv->theme,"Berlin")) 
-        init_scene1(desktop_plugin);
-}
-
-void 
-probability_sun(Actor *actor)
-{
-    actor->time_start_animation += 20 * 1;
-    actor->duration_animation = G_MAXINT;
-}
-
-static void
-init_scene(AWallpaperPlugin *desktop_plugin)
-{
-  Actor *actor;
-
-fprintf(stderr, "init scene \n");
-  scene.daytime = get_daytime();
-  scene.actors = NULL;
-  //get_sun_pos(&alt, &azm);
-  //get_sun_screen_pos(alt, azm, &x, &y);
-  
-  //scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
-  actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, SKY_LEVEL, 800, 480, 
-                      TRUE, 100, 255, &change_static_actor, NULL);
-  change_static_actor(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-
-  actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, SUN_LEVEL, 88, 88, 
-                      TRUE, 100, 255, &change_sun, &probability_sun);
-  actor->time_start_animation = time(NULL);
-  actor->duration_animation = G_MAXINT;
-  change_sun(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-
-  actor = init_object(desktop_plugin, "town", "town0.png", 0, 480-374, TOWN_LEVEL, 800, 374, 
-                      TRUE, 100, 255, &change_static_actor, NULL);
-  change_static_actor(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-  
-  actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, TOWN_LEVEL+5, 800, 79, 
-                      TRUE, 100, 255, &change_static_actor, NULL);
-  change_static_actor(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-
-  actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, SUN_LEVEL, 60, 60, 
-                      FALSE, 100, 255, &change_moon, NULL);
-  change_moon(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-
-
-  //if (scene.daytime == TIME_DAY) snprintf(str, 255, "tram.png");
-  //else snprintf(str, 255, "tram_dark.png");
-  //actor = init_object("tram", "tram.png", -300, 191, 25, 350, 210, 1, 100, 255, NULL);
-  
-  actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, TRAM_LEVEL, 350, 210, 
-                      FALSE, 100, 255, &change_tram, NULL);
-  actor->time_start_animation = time(NULL) + 10;
-  actor->duration_animation = 60;
-  scene.actors = g_slist_append(scene.actors, actor);
-#if 0    
-  anim = g_new0(Animation, 1);
-  anim->count = 1;
-  anim->actor = actor;
-  anim->func_change = &change_tram;
-  anim->func_time = NULL;
-  anim->timestart = time(NULL); 
-  anim->timeall = 10;
-  
-  scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
-#endif  
- }
-
-static void
-init_scene1(AWallpaperPlugin *desktop_plugin)
-{
-  Actor *actor;
-
-  scene.daytime = get_daytime();
-  scene.actors = NULL;
-  
-
-  actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, SKY_LEVEL, 800, 480, 
-                      TRUE, 100, 255, &change_static_actor, NULL);
-  change_static_actor(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-  actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, SUN_LEVEL, 88, 88, 
-                      TRUE, 100, 255, &change_sun, &probability_sun);
-  actor->time_start_animation = time(NULL);
-  actor->duration_animation = G_MAXINT;
-  change_sun(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-
-  actor = init_object(desktop_plugin, "town", "town.png", 0, 0, TOWN_LEVEL, 800, 480, 
-                      TRUE, 100, 255, &change_static_actor, NULL);
-  change_static_actor(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-
-  actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, SUN_LEVEL, 60, 60, 
-                      FALSE, 100, 255, &change_moon, NULL);
-  change_moon(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-  //scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
-   /*
-  actor = init_object("cloud1", 400, 150, 2, 200, 150, NULL);
-  scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
-
-  actor = init_object("sun", 10, 10, 50, 88, 88, NULL);
-  list = g_slist_append(list, G_OBJECT(actor));
-  actor = init_object("cloud1", 50, 50, 49, 150, 100, NULL);
-  list = g_slist_append(list, G_OBJECT(actor));
-
-  ma1 = multiactor_init("multi", list, 0, 0, 50, 1.0, TRUE);
-  //objects_list = g_slist_append(objects_list, G_OBJECT(ma)); 
-  */
 
 }
 
 
-void 
-get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
-{
-    gint y0 = 365;// - уровень горизонта
-    gint o_width = 128,
-         o_height = 128; 
-    *x = (int)(azm * 800) - 64;
-    *y = (int)((1 - alt) * y0) - 64;
-    //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
-}
-#if 0
-static void 
-change_actor(GtkWidget * actor)
+static gboolean
+short_timeout (AWallpaperPlugin *desktop_plugin)
 {
-    char * name;
-    gint x, y, daytime, scale;
-    gdouble sc;
-    double alt, azm;
-
-    GtkWidget *image;
-    GdkPixbuf *pixbuf;
-
+    //gint daytime = get_daytime();
+    GSList * tmp;
     void (*pfunc)(gpointer, gpointer);
+    time_t now;
+    Actor *actor;
+    gboolean stop_flag = TRUE;
 
-    name = g_object_get_data(G_OBJECT(actor), "name");
-    fprintf(stderr, "change actor %s\n", name);
-    if (name == "sun"){
-        pfunc = g_object_get_data(G_OBJECT(actor), "func");
-        if (pfunc)
-            (*pfunc)(actor, g_strdup(name));
-        daytime = get_daytime();
-        if (daytime != TIME_NIGHT){
-            hildon_animation_actor_set_show(actor, 1);
-            get_sun_pos(&alt, &azm);
-            get_sun_screen_pos(alt, azm, &x, &y);
-            actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
-        }
+if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
+        desktop_plugin->priv->short_timer = 0;
+        return FALSE;
     }
-    
-    if (name == "cloud1"){
-        x = g_object_get_data(G_OBJECT(actor), "x");
-        y = g_object_get_data(G_OBJECT(actor), "y");
-        scale = g_object_get_data(G_OBJECT(actor), "scale");
 
-        /* Start */
-        image = g_object_get_data(G_OBJECT(actor), "image");
-        
-        gtk_container_remove(actor, image);  
-        pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png", 
-                                             200, 
-                                             200, 
-                                             NULL);
-        if (pixbuf){
-              image = gtk_image_new_from_pixbuf (pixbuf);
-              g_object_unref(G_OBJECT(pixbuf));
-        }
-        g_signal_connect(G_OBJECT(image), "expose_event",
-                                   G_CALLBACK(expose_event), pixbuf);
-        gtk_container_add (GTK_CONTAINER (actor), image);
-        realize(actor);
-        gtk_widget_show_all(actor);
-        /* End*/
-
-            
-        x += 40;
-        y -= 20;
-        scale -= 10;
-        if (x > 500){
-            x = 400;
-            y = 150;
-            sc = 1;
-        }
-        sc = (double)scale / 100;
-        hildon_animation_actor_set_scale(actor, sc, sc);
-        fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
-        actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
-        g_object_set_data(G_OBJECT(actor), "x", x);
-        g_object_set_data(G_OBJECT(actor), "y", y);
-        g_object_set_data(G_OBJECT(actor), "scale", scale);
-    }
-
-}
-#endif
-static gboolean
-short_timeout (AWallpaperPlugin *desktop_plugin)
-{
-      gint daytime = get_daytime();
-      GSList * tmp;
-      gchar * name;
-      void (*pfunc)(gpointer, gpointer);
-      time_t now;
-      gint t;
-      Actor *actor;
-      gboolean stop_flag = TRUE;
-    if (!desktop_plugin->priv->visible)
-        return TRUE;
-  
     now = time(NULL);
-    //fprintf(stderr, "Short timer %d\n", now);
-    tmp = scene.actors;
+    //scene.daytime = daytime;
+    /* fprintf(stderr, "Short timer %d\n", now); */
+    tmp = desktop_plugin->priv->scene->actors;
     while (tmp != NULL){
            actor = tmp->data;
            if (now >= actor->time_start_animation  
@@ -724,8 +312,6 @@ short_timeout (AWallpaperPlugin *desktop_plugin)
             }
             tmp = g_slist_next(tmp);
     }
-       
-    scene.daytime = daytime;
     if (stop_flag){
          desktop_plugin->priv->short_timer = 0;
          return FALSE;
@@ -733,52 +319,71 @@ short_timeout (AWallpaperPlugin *desktop_plugin)
          return TRUE; /* keep running this event */
 }
 
+void
+run_long_timeout(AWallpaperPlugin *desktop_plugin)
+{
+
+    gint daytime = get_daytime();
+    GSList * tmp;
+    void (*pfunc)(gpointer, gpointer);
+    time_t now;
+    Actor *actor;
+
+
+    //fprintf(stderr, "!!!run long timeout short_timer=%d\n", desktop_plugin->priv->short_timer);
+    if (desktop_plugin->priv->scene->daytime != daytime){
+        desktop_plugin->priv->scene->daytime = daytime;
+        tmp = desktop_plugin->priv->scene->actors;
+        while (tmp != NULL){
+            //change_actor(tmp->data);
+            pfunc =((Actor*)tmp->data)->func_change;
+            if (pfunc){
+                (*pfunc)(tmp->data, desktop_plugin);
+            }
+            tmp = g_slist_next(tmp);
+        }
+    }
+   
+    now = time(NULL);
+    //fprintf(stderr, "Now  %d\n", now);
+    tmp = desktop_plugin->priv->scene->actors;
+    while (tmp != NULL){
+        actor = tmp->data;
+        if (now >= actor->time_start_animation  
+            && actor->time_start_animation > 0
+            && desktop_plugin->priv->short_timer == 0){
+            /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
+            if (desktop_plugin->priv->rich_animation){
+                actor->time_start_animation = now;
+                desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
+            }
+            else {
+                (*actor->func_change)(actor, desktop_plugin);
+            }
+        }
+        tmp = g_slist_next(tmp);
+    }
+}
 
 static gboolean
 long_timeout (AWallpaperPlugin *desktop_plugin)
 {
-      gint daytime = get_daytime();
-      GSList * tmp;
-      gchar * name;
-      void (*pfunc)(gpointer, gpointer);
-      time_t now;
-      gint t;
-      Actor *actor;
-
-    /* TODO  remove timeout */
-    if (!desktop_plugin->priv->visible)
-        return TRUE;
-  //fprintf(stderr, "timer daytime=%d\n", daytime);
-  if (scene.daytime != daytime){
-      tmp = scene.actors;
-      while (tmp != NULL){
-          //change_actor(tmp->data);
-          pfunc =((Actor*)tmp->data)->func_change;
-          if (pfunc){
-              (*pfunc)(tmp->data, desktop_plugin);
-          }
-          tmp = g_slist_next(tmp);
-      }
-   }
-   
-   now = time(NULL);
-//fprintf(stderr, "Now  %d\n", now);
-   tmp = scene.actors;
-   while (tmp != NULL){
-       actor = tmp->data;
-       if (now >= actor->time_start_animation  
-           && actor->time_start_animation > 0
-           && desktop_plugin->priv->short_timer == 0){
-            actor->time_start_animation = now;
-            fprintf(stderr, "start shor timer act = %s %d\n", actor->name, now);
-            desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, short_timeout, desktop_plugin);
+    /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
+    if (desktop_plugin->priv->long_timer == 0 )
+        return FALSE;
+    if (!desktop_plugin->priv->visible){
+        if(desktop_plugin->priv->short_timer != 0){
+            g_source_remove(desktop_plugin->priv->short_timer);
+            desktop_plugin->priv->short_timer = 0;
         }
-        tmp = g_slist_next(tmp);
-   }
-   
- scene.daytime = daytime;
+        desktop_plugin->priv->long_timer = 0;
+        return FALSE;
+    }
+  
 
- return TRUE; /* keep running this event */
+    run_long_timeout(desktop_plugin);
+    return TRUE; /* keep running this event */
 }
 
 static void
@@ -786,46 +391,118 @@ desktop_plugin_visible_notify (GObject    *object,
                                           GParamSpec *spec,
                                           AWallpaperPlugin *desktop_plugin)
 {
-      gboolean visible;
-      g_object_get (object, "is-on-current-desktop", &visible, NULL);
-      if (visible)
+    gboolean visible;
+    g_object_get (object, "is-on-current-desktop", &visible, NULL);
+    /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
+    if (visible){
         desktop_plugin->priv->visible = TRUE;
-      else
+        if (desktop_plugin->priv->long_timer == 0 ){
+            desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
+            run_long_timeout(desktop_plugin);
+        }
+    }else{
         desktop_plugin->priv->visible = FALSE;
-   /*   fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
+        if (desktop_plugin->priv->long_timer != 0 ){
+            g_source_remove(desktop_plugin->priv->long_timer);
+            desktop_plugin->priv->long_timer = 0;
+        }
+    }
 }
 
+gboolean
+rich_animation_press(GtkWidget *widget, GdkEvent *event,
+                                            gpointer user_data){
+    fprintf(stderr,"gggggggggggggggggggg2222\n");
+    return FALSE;
+}    
+
 static void
 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
 {
-    GtkWidget *label;
+    GtkWidget *rich_animation;
+    gchar           buffer[2048];
+    gchar str[128];
 
-    fprintf(stderr, "!!!!!!!plugin init \n");
+    //fprintf(stderr, "!!!!!!!plugin init \n");
     Animation_WallpaperPrivate *priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
     desktop_plugin->priv =  Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
+    priv->osso = osso_initialize(PACKAGE, VERSION, TRUE, NULL);
+
     /* Load config */
     read_config(priv);
+    /* Initialize DBUS */
+    livewp_initialize_dbus(priv);
+
     priv->desktop_plugin = desktop_plugin;
-    label = gtk_label_new (""); 
+    priv->visible = TRUE;
+    priv->short_timer = 0;
+    priv->xapplet = 0;
+    priv->yapplet = 0;
+//#if 0 
+    priv->hash_scene_func = g_hash_table_new(g_str_hash, g_str_equal);
+    
+    g_hash_table_insert(priv->hash_scene_func, g_strdup("Berlin"), (gpointer)&init_scene_Berlin);
+    g_hash_table_insert(priv->hash_scene_func, g_strdup("Modern"), (gpointer)&init_scene_Modern);
+    g_hash_table_insert(priv->hash_scene_func, g_strdup("Matrix"), (gpointer)&init_scene_Matrix);
+//#endif
+    priv->theme = g_strdup("Modern");
+    desktop_plugin->priv->main_widget = gtk_fixed_new();
+
+    gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
+    desktop_plugin->priv->right_corner = NULL;
+    snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
+    desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
+    if (desktop_plugin->priv->right_corner){
+        gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
+        gtk_widget_show (desktop_plugin->priv->right_corner);
+    }
+    /* Create rich animation event */
+    rich_animation = gtk_event_box_new();
+    if(rich_animation){
+        gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
+        gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
+        gtk_widget_set_size_request(rich_animation, 100, 32);
+        gtk_widget_show (rich_animation);
+        g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
+        gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
+    }
+/*
+    GtkWidget *label = gtk_label_new ("ddddddddddddd"); 
     gtk_widget_set_size_request(label, 95, 30);
     gtk_widget_show (label);
+    gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
+    gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
+*/
     hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
     g_signal_connect (desktop_plugin, "show-settings",
-                            G_CALLBACK (lw_settings), priv);
-    g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
-                     G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
+                            G_CALLBACK (show_settings), priv);
+    gtk_widget_show (desktop_plugin->priv->main_widget);
+    gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
+    init_applet_position(&(priv->xapplet), &(priv->yapplet));
 
-    gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
-    init_applet_position();
+    
     fprintf(stderr, "!!!theme = %s\n", priv->theme);
+    snprintf(str, sizeof(str) - 1, "%s", "init_scene2");
+    fprintf(stderr, " str = %s\n", str);
+    priv->scene = NULL;
+#if 0
     if (!strcmp(priv->theme,"Modern"))
-        init_scene(desktop_plugin);
+        init_scene_Modern(desktop_plugin);
     else if (!strcmp(priv->theme,"Berlin")) 
-        init_scene1(desktop_plugin);
-    priv->long_timer = g_timeout_add(LONG_TIMER, long_timeout, desktop_plugin);
-    priv->short_timer = 0;
+        init_scene_Berlin(desktop_plugin);
+    else if (!strcmp(priv->theme, "Matrix"))
+        init_scene_Matrix(desktop_plugin);
+#endif
+    init_scene_theme(desktop_plugin);
+        
+    priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
     /* TODO Move scene to priv */
-    scene.timer_type = LONG_TIMER_TYPE;
+    //scene.timer_type = LONG_TIMER_TYPE;
+    g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
+                     G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
+
+   
+    //sleep(2);
 }
 
 static void
@@ -834,6 +511,8 @@ lw_applet_finalize (GObject *object)
      AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
      Animation_WallpaperPrivate *priv = desktop_plugin->priv;
 
+     livewp_deinitialize_dbus(priv);
+     fprintf(stderr,"finalaze %i\n", priv->long_timer);
      if (priv->long_timer){
         g_source_remove(priv->long_timer);
         priv->long_timer = 0;
@@ -843,7 +522,7 @@ lw_applet_finalize (GObject *object)
         priv->short_timer = 0;
      }
 
-     destroy_scene();
+     destroy_scene(desktop_plugin);
 }
 
 static void
@@ -853,7 +532,7 @@ animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
     GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
 
     /* gobject */
-    gobject_class->destroy = lw_applet_finalize;
+    gobject_class->destroy = (gpointer)lw_applet_finalize;
     widget_class->realize = lw_applet_realize;
     widget_class->expose_event = lw_applet_expose_event;
 
@@ -862,4 +541,7 @@ animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
 }
 
 static void
-animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {}
+animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {
+}
+
+