destronig
[livewp] / applet / src / livewp-home-widget.c
index f309794..8ad44f5 100644 (file)
@@ -45,6 +45,9 @@ HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_H
 
 gint xapplet = 0, yapplet = 0;
 Scene scene;
+gint hour=8;
+gint min=0;
+gint ttt = 0;
 
 static void
 lw_applet_realize (GtkWidget *widget)
@@ -249,7 +252,7 @@ probability_sun()
 gint 
 probability_plane()
 {
-    return (fast_rnd(10) + 1) * 60;
+    return (fast_rnd(60));
 //    return 0;
 }
 
@@ -300,13 +303,13 @@ change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
                 actor->visible = TRUE;
                 create_hildon_actor(actor, desktop_plugin);
             }
-            get_sun_pos(&alt, &azm);
+            get_sun_pos(hour, min, &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);
-            actor->time_start_animation = time(NULL) + probability_sun();
+            actor->time_start_animation = time(NULL);
          }else if (actor->visible){
             actor->visible = FALSE;
             destroy_hildon_actor(actor);
@@ -326,6 +329,7 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
     suseconds_t ms;
     long sec;
     double t;
+    gchar *newfile;
 
     //fprintf(stderr, "change tram\n");
     gettimeofday(&tvb, NULL);
@@ -335,7 +339,7 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
     
     if (!actor->visible){
         actor->visible = TRUE;
-        if (scene.daytime == TIME_NIGHT){
+        if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
             if (actor->filename)
                 g_free(actor->filename);
             actor->filename = g_strdup("tram_dark.png");
@@ -346,6 +350,20 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
         }
         create_hildon_actor(actor, desktop_plugin);
     }
+    if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
+            newfile = g_strdup("tram_dark.png");
+        }else{
+            newfile = g_strdup("tram.png");
+        } 
+        if (strcmp(actor->filename, newfile)){
+        if (actor->filename)
+            g_free(actor->filename);
+        actor->filename = newfile;
+         
+
+        change_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);
@@ -357,7 +375,7 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
         /* stop animation */
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + fast_rnd(300);
+        actor->time_start_animation = sec + 20;
     }
 }
 
@@ -371,6 +389,7 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
     suseconds_t ms;
     long sec;
     double t;
+    gchar *newfile;
 
     gettimeofday(&tvb, NULL);
     
@@ -388,10 +407,24 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
         actor->visible = TRUE;
         create_hildon_actor(actor, desktop_plugin);
     }
+if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
+            newfile = g_strdup("dot1.png");
+        }else{
+            newfile = g_strdup("tu154.png");
+        } 
+        if (strcmp(actor->filename, newfile)){
+        if (actor->filename)
+            g_free(actor->filename);
+        actor->filename = newfile;
+         
+
+        change_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);
+    //scale 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(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
@@ -402,7 +435,7 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
         if (scene.daytime == TIME_NIGHT) 
             actor->time_start_animation = 0;
         else 
-            actor->time_start_animation = sec + probability_plane();
+            actor->time_start_animation = sec + 10;
     }
 
 }
@@ -417,6 +450,7 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
     suseconds_t ms;
     long sec;
     double t;
+    gchar * newfile;
 
     gettimeofday(&tvb, NULL);
     
@@ -433,6 +467,19 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
         actor->visible = TRUE;
         create_hildon_actor(actor, desktop_plugin);
     }
+if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
+            newfile = g_strdup("dot1.png");
+        }else{
+            newfile = g_strdup("plane3.png");
+        } 
+        if (strcmp(actor->filename, newfile)){
+        if (actor->filename)
+            g_free(actor->filename);
+        actor->filename = newfile;
+         
+
+        change_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);
@@ -448,7 +495,7 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
         if (scene.daytime == TIME_NIGHT) 
             actor->time_start_animation = 0;
         else 
-            actor->time_start_animation = sec + probability_plane();
+            actor->time_start_animation = sec + 15;
     }
 
 }
@@ -474,7 +521,7 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
    
     if (!actor->visible){
         actor->visible = TRUE;
-        if (scene.daytime == TIME_NIGHT){
+        if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
             newfile = g_strdup_printf("%s_dark.png", actor->name);
         }else{
             newfile = g_strdup_printf("%s.png", actor->name);
@@ -486,6 +533,20 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
 
         create_hildon_actor(actor, desktop_plugin);
     }
+    if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
+            newfile = g_strdup_printf("%s_dark.png", actor->name);
+        }else{
+            newfile = g_strdup_printf("%s.png", actor->name);
+        } 
+        if (strcmp(actor->filename, newfile)){
+        if (actor->filename)
+            g_free(actor->filename);
+        actor->filename = newfile;
+         
+
+        change_hildon_actor(actor, desktop_plugin);
+        }
+
     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
     
     if (scene.wind_orientation == 1){
@@ -508,7 +569,7 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
         /* stop animation */
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + fast_rnd(300);
+        actor->time_start_animation = sec + 10;
         actor->y = fast_rnd(300);
     }
 
@@ -544,11 +605,11 @@ change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
     if (!actor->visible){
         actor->visible = TRUE;
         create_hildon_actor(actor, desktop_plugin);
-        actor->time_start_animation = now + fast_rnd(60) + 10;
+        actor->time_start_animation = now + 10;
     }else {
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = now + fast_rnd(60) + 10;
+        actor->time_start_animation = now + 10;
     }
    
 }
@@ -566,7 +627,7 @@ change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
     g_free(actor->filename);
     actor->filename = newfile;
     change_hildon_actor(actor, desktop_plugin);
-    actor->time_start_animation = now + fast_rnd(30) + 10;
+    actor->time_start_animation = now + 5;
 }
 
 void
@@ -744,7 +805,7 @@ init_scene(AWallpaperPlugin *desktop_plugin)
   gint winds[13][2];
 
   /* fprintf(stderr, "init scene \n");*/
-  scene.daytime = get_daytime();
+  scene.daytime = get_daytime(hour, min);
   scene.actors = NULL;
   scene.wind_orientation = -1;
   scene.wind_angle = 0.3;
@@ -769,22 +830,22 @@ init_scene(AWallpaperPlugin *desktop_plugin)
     //                  TRUE, 100, 255, NULL, NULL);
   //scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
+  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 0, 7, 150, 97, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + fast_rnd(180);
-  actor->duration_animation = 3*60;
+  actor->time_start_animation = now;
+  actor->duration_animation = 1*60;
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
+  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 80, 7, 188, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + fast_rnd(180);
-  actor->duration_animation = 3*60;
+  actor->time_start_animation = now + 20;
+  actor->duration_animation = 1*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
-  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
+  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 30, 7, 150, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + fast_rnd(180);
-  actor->duration_animation = 5*60;
+  actor->time_start_animation = now + 40;
+  actor->duration_animation = 1*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
 
@@ -795,8 +856,8 @@ init_scene(AWallpaperPlugin *desktop_plugin)
 
   actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210, 
                       FALSE, 100, 255, (gpointer)&change_tram, NULL);
-  actor->time_start_animation = time(NULL) + fast_rnd(10); 
-  actor->duration_animation = 60;
+  actor->time_start_animation = now; 
+  actor->duration_animation = 40;
   scene.actors = g_slist_append(scene.actors, actor);
 
   actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
@@ -808,12 +869,12 @@ init_scene(AWallpaperPlugin *desktop_plugin)
                       FALSE, 100, 255, (gpointer)&change_moon, NULL);
   change_moon(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
-
+/*
   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
                       FALSE, 100, 255, (gpointer)&change_wind, NULL);
   change_wind(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
-
+*/
     /* windows in 4-th house  */
 
     winds[0][0] = 482;
@@ -1027,9 +1088,9 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   gint i; 
   gint winds[13][2];
 
-  scene.daytime = get_daytime();
+  scene.daytime = get_daytime(hour, min);
   scene.actors = NULL;
-  scene.wind_orientation = -1;
+  scene.wind_orientation = 1;
   scene.wind_angle = 0.3;
   /* init value for random */
   scene.seed = time(NULL);
@@ -1059,50 +1120,50 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   change_moon(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
+  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 300, 7, 150, 97, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + fast_rnd(180);
-  actor->duration_animation = 3*60;
+  actor->time_start_animation = now + 20;
+  actor->duration_animation = 1*60;
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
+  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 100, 7, 188, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + fast_rnd(180);
-  actor->duration_animation = 3*60;
+  actor->time_start_animation = now;
+  actor->duration_animation = 1*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
-  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
+  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 200, 7, 150, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + fast_rnd(180);
-  actor->duration_animation = 5*60;
+  actor->time_start_animation = now + 40;
+  actor->duration_animation = 1*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
  
-  actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
+  actor = init_object(desktop_plugin, "plane3", "plane3.png", 0, 45, 8, 160, 50, 
                       FALSE, 100, 255, (gpointer)&change_plane2, NULL);
-  actor->time_start_animation = now + probability_plane();
-  actor->duration_animation = 60;
+  actor->time_start_animation = now + 20;
+  actor->duration_animation = 40;
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116, 
+  actor = init_object(desktop_plugin, "tu154", "tu154.png", 620, 233, 9, 300, 116, 
                       FALSE, 100, 255, (gpointer)&change_plane1, NULL);
-  actor->time_start_animation = now + probability_plane();
-  actor->duration_animation = 30;
+  actor->time_start_animation = now;
+  actor->duration_animation = 20;
   scene.actors = g_slist_append(scene.actors, actor);
 
   actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
                       TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
   change_static_actor_with_corner(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
-
+/*
   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
                       FALSE, 100, 255, (gpointer)&change_wind, NULL);
   change_wind(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
-
+*/
   actor = init_object(desktop_plugin, "signal", "red.png", 486, 425, 10, 18, 38, 
                       TRUE, 100, 255, (gpointer)&change_signal, NULL);
-  actor->time_start_animation = now + fast_rnd(30) + 10;  
+  actor->time_start_animation = now;  
   scene.actors = g_slist_append(scene.actors, actor);winds[0][0] = 717;
     
     winds[0][0] = 389;
@@ -1243,13 +1304,22 @@ change_actor(GtkWidget * actor)
 static gboolean
 short_timeout (AWallpaperPlugin *desktop_plugin)
 {
-    gint daytime = get_daytime();
+    //gint daytime = get_daytime();
     GSList * tmp;
     void (*pfunc)(gpointer, gpointer);
     time_t now;
     Actor *actor;
     gboolean stop_flag = TRUE;
-
+    
+    if (ttt == 1){
+        min ++;
+        if (min == 60){
+            hour ++;
+            min = 0;
+            if (hour == 23) hour = 0;
+        }
+        ttt = 0;
+    }else ttt ++;
     if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
         desktop_plugin->priv->short_timer = 0;
         return FALSE;
@@ -1282,12 +1352,17 @@ short_timeout (AWallpaperPlugin *desktop_plugin)
 void
 run_long_timeout(AWallpaperPlugin *desktop_plugin){
 
-    gint daytime = get_daytime();
+    gint daytime = get_daytime(hour, min);
     GSList * tmp;
     void (*pfunc)(gpointer, gpointer);
     time_t now;
     Actor *actor;
 
+    //hour = hour + 1;
+    //min = 0;
+    //if (hour == 24) hour = 0;
+    fprintf(stderr, "---- %d:%d\n", hour, min);
+
 
     //fprintf(stderr, "timer daytime=%d\n", daytime);
     if (scene.daytime != daytime){