added select file into dialog
[livewp] / applet / src / livewp-scene.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 General Public License
11  * as published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
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-scene.h" 
26 /* This code form X11-utils */
27 Window Window_With_Name( Display *dpy, Window top, char *name)
28 {
29         Window *children, dummy;
30         unsigned int nchildren;
31         int i;
32         Window w=0;
33         char *window_name;
34
35     XClassHint *class_hint;
36     class_hint = XAllocClassHint();
37     XGetClassHint(dpy, top, class_hint);
38     if (class_hint->res_name && name && !strcmp(class_hint->res_name, name)){
39       XFree(class_hint->res_class);
40       XFree(class_hint->res_name);
41       return(top);
42     }
43     XFree(class_hint->res_class);
44     XFree(class_hint->res_name);
45
46         if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
47           return(top);
48
49         if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
50           return(0);
51
52         for (i=0; i<nchildren; i++) {
53                 w = Window_With_Name(dpy, children[i], name);
54                 if (w)
55                   break;
56         }
57         if (children) XFree ((char *)children);
58         return(w);
59 }
60
61 /*******************************************************************************/
62
63 void 
64 destroy_scene(AWallpaperPlugin *desktop_plugin)
65 {
66     int status = 0;
67      
68     if (desktop_plugin->priv->scene){
69             GSList * tmp = desktop_plugin->priv->scene->actors;
70             while (tmp != NULL){
71                     destroy_actor(tmp->data);
72                     tmp = g_slist_next(tmp);
73             }
74             if (tmp)
75                     g_slist_free(tmp);
76             desktop_plugin->priv->scene->actors = NULL;
77             if (desktop_plugin->priv->scene){
78                     g_free(desktop_plugin->priv->scene);
79                     desktop_plugin->priv->scene = NULL;
80             }
81     }
82     if (desktop_plugin->priv->pipeline){
83         gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL);
84         gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
85         desktop_plugin->priv->pipeline = NULL;
86     }
87     if (desktop_plugin->priv->podpid > 1){
88         kill (desktop_plugin->priv->podpid, SIGTERM);
89         while (TRUE){
90             if (wait(&status) == desktop_plugin->priv->podpid) 
91                 break;
92         } 
93         desktop_plugin->priv->podpid = -1;
94         desktop_plugin->priv->running = FALSE;
95     }
96 }
97 /*******************************************************************************/
98 void
99 reload_scene(AWallpaperPlugin *desktop_plugin)
100 {
101     fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme); 
102     destroy_scene(desktop_plugin);
103     fill_priv(desktop_plugin->priv);
104     gtk_widget_destroy(desktop_plugin->priv->window); 
105     if (desktop_plugin->priv->one_in_all_view && desktop_plugin->priv->view >1)
106         exit(-1);   
107     create_xwindow(desktop_plugin->priv);
108     init_scene_theme(desktop_plugin);
109 }
110 /*******************************************************************************/
111 void 
112 init_scene_Accel(AWallpaperPlugin *desktop_plugin)
113 {
114     Actor *actor;
115     Scene *scene;
116     GPtrArray *child;
117     gint now = time(NULL);
118     gchar *str;
119     gchar *bgfile = NULL;
120     gint sizes1[4] = {57, 76, 43, 50},
121          n, j;
122     
123     /* fprintf(stderr, "init scene accel\n"); */
124     scene = g_new0(Scene, 1);
125     scene->actors = NULL;
126     desktop_plugin->priv->scene = scene;
127     
128     bgfile = g_strdup_printf("/home/user/.backgrounds/background-%i.png", desktop_plugin->priv->view);
129     actor = init_object(desktop_plugin, "original", bgfile, 
130                       0, 0, 0, 800, 480, 
131                       TRUE, TRUE, 100, 255, 
132                       NULL, NULL, NULL);
133     scene->actors = g_slist_append(scene->actors, actor);
134
135     child = g_ptr_array_sized_new(16);
136     
137     for (j= 0; j<4; j++){
138         for (n=0; n<4; n++){
139             str = g_strdup_printf("tape%i.png", n+1);
140             actor = init_object(desktop_plugin, "tape", str,
141                                 fast_rnd(800), fast_rnd(480), 2+fast_rnd(6), 800, sizes1[n],
142                                 TRUE, TRUE, 100, 255,
143                                 NULL, NULL, NULL);
144             scene->actors = g_slist_append(scene->actors, actor);
145             g_ptr_array_add(child, actor);
146             g_free(str);
147         }
148     }
149     actor = init_object(desktop_plugin, "tape", "", 
150                       0, 800, 5, 800, 170, 
151                       FALSE, FALSE, 100, 255, 
152                       (gpointer)&change_tape, NULL, child);
153     actor->time_start_animation = now;
154     actor->duration_animation = G_MAXINT;
155     scene->actors = g_slist_append(scene->actors, actor);
156
157     run_long_timeout(desktop_plugin);
158 }
159 /*******************************************************************************/
160 void  
161 parsestring(char *line, char **argv)
162 {
163    while (*line != '\0') {  
164           while (*line == ' ' || *line == '\n')
165                 *line++ = '\0';     /* replace white spaces with 0    */
166                  *argv++ = line;          /* save the argument position     */
167                  while (*line != '\0' && *line != ' ' && 
168                         *line != '\n') 
169                      line++;             /* skip the argument until ...    */
170    }
171                   *argv = '\0';                 /* mark the end of argument list  */
172 }
173
174 #if 0
175 GstBusSyncReply 
176 sync_handler(GstBus *bus, GstMessage *message, AWallpaperPlugin *desktop_plugin){
177
178     if (!desktop_plugin->priv->visible)
179         gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PAUSED);
180     if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_ELEMENT){
181                 return (GST_BUS_PASS);
182         }
183     if (!gst_structure_has_name(message->structure, "prepare-xwindow-id")){
184         return (GST_BUS_PASS);
185     }
186     return (GST_BUS_DROP);
187
188 }
189 #endif
190 /*******************************************************************************/
191 static gboolean
192 bus_call (GstBus *bus, GstMessage *msg, AWallpaperPlugin *desktop_plugin)
193 {
194     switch (GST_MESSAGE_TYPE (msg))
195     {
196        case GST_MESSAGE_EOS: 
197            if (desktop_plugin->priv->rich_animation){
198
199                 GstClockTime nach   = (GstClockTime)(0 * GST_MSECOND);
200                 if (!gst_element_seek(desktop_plugin->priv->pipeline, 1.0, GST_FORMAT_TIME,
201                    (GstSeekFlags) (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT), GST_SEEK_TYPE_SET, 
202                    nach, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
203                     fprintf(stderr,"ERROR in seek\n");
204
205                 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
206
207            }else{
208                 if (desktop_plugin->priv->pipeline){
209                     gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL);
210                     gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
211                 } 
212            }
213            break;
214        case GST_MESSAGE_ERROR: break;
215        default: break;
216      }
217        return TRUE;
218 }
219
220 /*******************************************************************************/
221 void
222 init_scene_External(AWallpaperPlugin *desktop_plugin){
223
224     char* child_argv[2048];
225     char *run_string = NULL;
226     gchar *exec_path = NULL,
227         *window_id = NULL,
228         *window_name = NULL,
229         *view = NULL,
230         *gtk_socket_id = NULL,
231         *strwin = NULL,
232         *strsocket = NULL,
233         *addedstring = NULL,
234         *theme_string_parametr1 = NULL,
235         *straddedstring = NULL,
236         *strview = NULL;
237     gint i;
238     Window  id_xwindow;
239     if (!desktop_plugin->priv->visible)
240         return;
241     
242     exec_path = g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "exec_path"));
243     window_id = g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "window_id"));
244     view = g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "view"));
245     window_name = g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "window_name"));
246     gtk_socket_id =  g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "gtk_socket_id"));
247     addedstring =  g_strdup(g_hash_table_lookup(desktop_plugin->priv->hash_theme, "added_string"));
248     if (!exec_path) 
249         return;
250     if (window_id){
251         strwin = g_strdup_printf(" %s %i", window_id, (gint)GDK_WINDOW_XID(desktop_plugin->priv->window->window));
252     }else
253         strwin = "";
254     if (gtk_socket_id){
255         strsocket = g_strdup_printf(" %s %i", gtk_socket_id, (int)gtk_socket_get_id (GTK_SOCKET (desktop_plugin->priv->video_socket)));
256     }else
257         strsocket = "";
258
259     if (view){
260         strview = g_strdup_printf(" %s %i", view, desktop_plugin->priv->view);
261     }else
262         strview = "";
263
264     if (addedstring){
265         straddedstring = g_strdup_printf(" %s", addedstring);
266     }else
267         straddedstring = "";
268
269     if (desktop_plugin->priv->theme_string_parametr1){
270         theme_string_parametr1 = g_strdup_printf(" %s", desktop_plugin->priv->theme_string_parametr1);
271     }else
272         theme_string_parametr1 = "";
273
274     run_string = g_strdup_printf("%s%s%s%s%s%s", exec_path, strwin, strview, strsocket, straddedstring, theme_string_parametr1);
275     fprintf(stderr, "runs string = %s\n", run_string);
276     parsestring(run_string, child_argv);
277
278     desktop_plugin->priv->running = TRUE;
279     desktop_plugin->priv->podpid = fork();
280     if (desktop_plugin->priv->podpid == 0){
281         execvp(child_argv[0], child_argv);
282         fprintf(stderr,"Problem with new podprocess");
283     }
284     g_free(run_string);
285
286     fprintf(stderr, "window name = %s\n", window_name);
287     if (window_name){
288         /* Do 10 trying to search of window */
289         for (i=0; i<10; i++){
290             sleep(1);
291             id_xwindow = Window_With_Name(GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window), 
292                 RootWindow( GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window), XDefaultScreen( GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window))),
293                 window_name);
294             fprintf(stderr,"name %s %i %i\n", window_name, id_xwindow, i);
295             if (id_xwindow>0){
296                 if (desktop_plugin->priv->one_in_all_view)
297                     set_live_bg (GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window), 
298                                                       id_xwindow, -1);
299                 else
300                     set_live_bg (GDK_WINDOW_XDISPLAY (desktop_plugin->priv->window->window),  
301                                                       id_xwindow, desktop_plugin->priv->view);
302                 /* gtk_widget_destroy(desktop_plugin->priv->window); */
303                 break;
304             }
305         }
306     }
307 }
308 /*******************************************************************************/
309 gboolean 
310 cb_timeout0(AWallpaperPlugin *desktop_plugin) {
311
312     if (!desktop_plugin || !desktop_plugin->priv->pipeline)
313         return FALSE;
314     if (desktop_plugin->priv->theme_int_parametr1 == 0){
315         if (!gst_element_seek((GstElement *)GST_PIPELINE (desktop_plugin->priv->pipeline), 1.0, GST_FORMAT_TIME,
316                                           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 
317                                           desktop_plugin->priv->theme_int_parametr1 * GST_SECOND,
318                                           GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
319             fprintf(stderr,"Error in seek:\n");
320         return FALSE;
321     }
322        
323     if (gst_element_get_state (desktop_plugin->priv->pipeline, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) 
324         return TRUE;
325     else{
326          if (!gst_element_seek((GstElement *)GST_PIPELINE (desktop_plugin->priv->pipeline), 1.0, GST_FORMAT_TIME,
327                                           GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 
328                                           desktop_plugin->priv->theme_int_parametr1 * GST_SECOND,
329                                           GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
330             fprintf(stderr,"Error in seek:\n");
331          return FALSE;
332     }
333
334 /*******************************************************************************/
335 void
336 init_scene_Video(AWallpaperPlugin *desktop_plugin)
337 {
338     GstElement *bin;                                                                                                                                                           
339     GstElement *videosink;                                                                                                
340     gchar *file_plus_uri;
341
342
343     /* fprintf(stderr, "init scene Video \n"); */
344     desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
345     bin = gst_element_factory_make ("playbin2", "bin");
346     videosink = gst_element_factory_make ("ximagesink", "videosink");
347     g_object_set (G_OBJECT (bin), "video-sink", videosink, NULL);
348     gst_bin_add (GST_BIN (desktop_plugin->priv->pipeline), bin);
349
350     {
351         GstBus *bus;
352         bus = gst_pipeline_get_bus (GST_PIPELINE (desktop_plugin->priv->pipeline));
353         gst_bus_add_watch(bus, (GstBusFunc)bus_call, desktop_plugin);
354         gst_object_unref (bus);
355     }
356     file_plus_uri = g_strdup_printf("file://%s",desktop_plugin->priv->theme_string_parametr1);
357     g_object_set (G_OBJECT (bin), "uri", file_plus_uri, NULL );
358 #if 0
359     /* Doesn't work in real device. Hardware volume buttons can to change volume for mutted track */
360     /* Set Mute */
361     if (!desktop_plugin->priv->theme_bool_parametr1)
362         g_object_set (G_OBJECT (bin), "mute", TRUE, NULL );
363 #endif
364     g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE, NULL  );
365
366     if (GST_IS_X_OVERLAY (videosink))
367             gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
368
369     if (desktop_plugin->priv->visible){
370         g_timeout_add(50, (GSourceFunc)cb_timeout0, desktop_plugin); 
371         gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
372     }
373    
374     //gst_element_get_state(deskddtop_plugin->priv->pipeline, NULL, NULL, 100 * GST_MSECOND);
375
376 }
377 /*******************************************************************************/
378 void
379 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
380 {
381   Actor *actor;
382   Scene *scene;
383   GPtrArray *child;
384   gint now = time(NULL);
385   gint y1, y2;
386
387   if (desktop_plugin->priv->rich_animation){
388       y1 = -480;
389       y2 = -480-480;
390   }else {
391       y1 = 0;
392       y2 = -480;
393   }
394
395   /* fprintf(stderr, "init scene2 \n"); */
396   scene = g_new0(Scene, 1);
397   //scene.daytime = get_daytime();
398   scene->actors = NULL;
399   desktop_plugin->priv->scene = scene;
400   
401   actor = init_object(desktop_plugin, "background", "bg.png", 
402                       0, 0, 5, 800, 480, 
403                       TRUE, TRUE, 100, 255, 
404                       NULL, NULL, NULL);
405   scene->actors = g_slist_append(scene->actors, actor);
406
407   actor = init_object(desktop_plugin, "symbols", "symbols.png", 
408                       0, 0, 10, 800, 480, 
409                       TRUE, TRUE, 100, 255, 
410                       NULL, NULL, NULL);
411   scene->actors = g_slist_append(scene->actors, actor);
412
413   child = g_ptr_array_sized_new(4);
414   actor = init_object(desktop_plugin, "layer1", "layer1_2.png", 
415                       0, y1, 6, 800, 960, 
416                       TRUE, TRUE, 100, 255, 
417                       NULL, NULL, NULL);
418   //actor->time_start_animation = now;
419   //actor->duration_animation = G_MAXINT;
420   scene->actors = g_slist_append(scene->actors, actor);
421   g_ptr_array_add(child, actor);
422
423   actor = init_object(desktop_plugin, "layer1", "layer1_1.png", 
424                       0, y2, 7, 800, 960, 
425                       TRUE, TRUE, 100, 255, 
426                       NULL, NULL, NULL);
427   //actor->time_start_animation = now;
428   //actor->duration_animation = G_MAXINT;
429   scene->actors = g_slist_append(scene->actors, actor);
430   g_ptr_array_add(child, actor);
431
432   actor = init_object(desktop_plugin, "layer2", "layer2_2.png", 
433                       0, y1, 8, 800, 960, 
434                       TRUE, TRUE, 100, 255, 
435                       NULL, NULL, NULL);
436   //actor->time_start_animation = now;
437   //actor->duration_animation = G_MAXINT;
438   scene->actors = g_slist_append(scene->actors, actor);
439   g_ptr_array_add(child, actor);
440
441   actor = init_object(desktop_plugin, "layer2", "layer2_1.png", 
442                       0, y2, 9, 800, 960, 
443                       TRUE, TRUE, 100, 255, 
444                       NULL, NULL, NULL);
445   //actor->time_start_animation = now;
446   //actor->duration_animation = G_MAXINT;
447   scene->actors = g_slist_append(scene->actors, actor);
448   g_ptr_array_add(child, actor);
449
450   actor = init_object(desktop_plugin, "layers", "", 
451                       0, y2, 9, 800, 960, 
452                       FALSE, FALSE, 100, 255, 
453                       (gpointer)&change_layer, NULL, child);
454   actor->time_start_animation = now;
455   actor->duration_animation = G_MAXINT;
456   scene->actors = g_slist_append(scene->actors, actor);
457
458   run_long_timeout(desktop_plugin);
459
460 }
461 /*******************************************************************************/
462 /* Init Modern Scene */
463 void
464 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
465 {
466   Actor *actor;
467   Scene *scene;
468   gint now = time(NULL);
469   gint i;
470   gint winds[13][2];
471   GPtrArray *child; 
472
473   /* fprintf(stderr, "init scene \n"); */
474   scene = g_new0(Scene, 1);
475   scene->daytime = get_daytime();
476   scene->actors = NULL;
477   scene->wind_orientation = -1;
478   scene->wind_angle = 0.3;
479   /* init value for random */
480   scene->seed = time(NULL);
481   scene->notification = TRUE;
482   desktop_plugin->priv->scene = scene;
483   actor = init_object(desktop_plugin, "sky", "sky0.png", 
484                       0, 0, 5, 800, 480, 
485                       TRUE , TRUE, 100, 255, 
486                       (gpointer)&change_static_actor, NULL, NULL);
487   scene->actors = g_slist_append(scene->actors, actor);
488   change_static_actor(actor, desktop_plugin);
489   
490   actor = init_object(desktop_plugin, "sun", "sun.png", 
491                       0, 0, 6, 88, 88, 
492                       FALSE, FALSE, 100, 255, 
493                       (gpointer)&change_sun, NULL, NULL);
494   actor->time_start_animation = now;
495   actor->duration_animation = G_MAXINT;
496   change_sun(actor, desktop_plugin);
497   scene->actors = g_slist_append(scene->actors, actor);
498
499   //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
500     //                  TRUE, 100, 255, NULL, NULL);
501   //scene.actors = g_slist_append(scene.actors, actor);
502   
503   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 
504                       0, fast_rnd(300)-97, 7, 150, 97, 
505                       FALSE, FALSE, 100, 255, 
506                       (gpointer)&change_cloud, NULL, NULL);
507   actor->time_start_animation = now + fast_rnd(20);
508   actor->duration_animation = 3*60;
509   scene->actors = g_slist_append(scene->actors, actor);
510   
511   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 
512                       0, fast_rnd(300)-75, 7, 188, 75, 
513                       FALSE, FALSE, 100, 255, 
514                       (gpointer)&change_cloud, NULL, NULL);
515   actor->time_start_animation = now + fast_rnd(40)+10;
516   actor->duration_animation = 3*60;
517   scene->actors = g_slist_append(scene->actors, actor);
518
519   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 
520                       0, fast_rnd(300)-75, 7, 150, 75, 
521                       FALSE, FALSE, 100, 255, 
522                       (gpointer)&change_cloud, NULL, NULL);
523   actor->time_start_animation = now + fast_rnd(60) + 20;
524   actor->duration_animation = 5*60;
525   scene->actors = g_slist_append(scene->actors, actor);
526
527
528   actor = init_object(desktop_plugin, "town", "town0.png", 
529                       0, 0, 8, 800, 480, 
530                       TRUE, TRUE, 100, 255, 
531                       (gpointer)&change_static_actor, NULL, NULL);
532   change_static_actor(actor, desktop_plugin);
533   scene->actors = g_slist_append(scene->actors, actor);
534
535   actor = init_object(desktop_plugin, "stend", "stend0.png", 
536                       452, 166, 9, 300, 305, 
537                       TRUE, TRUE, 100, 255, 
538                       (gpointer)&change_static_actor, NULL, NULL);
539   change_static_actor(actor, desktop_plugin);
540   scene->actors = g_slist_append(scene->actors, actor);
541
542
543   child = g_ptr_array_sized_new(4);
544   actor = init_object(desktop_plugin, "call", "call.png", 
545                       480, 190, 9, 50, 58, 
546                       FALSE, TRUE, 100, 255, 
547                       NULL, NULL, NULL);
548   scene->actors = g_slist_append(scene->actors, actor);
549   g_ptr_array_add(child, actor);
550
551   actor = init_object(desktop_plugin, "chat", "chat.png", 
552                       540, 190, 9, 50, 58, 
553                       FALSE, TRUE, 100, 255, 
554                       NULL, NULL, NULL);
555   scene->actors = g_slist_append(scene->actors, actor);
556   g_ptr_array_add(child, actor);
557
558   actor = init_object(desktop_plugin, "mail", "mail.png", 
559                       600, 190, 9, 50, 58, 
560                       FALSE, TRUE, 100, 255, 
561                       NULL, NULL, NULL);
562   scene->actors = g_slist_append(scene->actors, actor);
563   g_ptr_array_add(child, actor);
564   
565   actor = init_object(desktop_plugin, "sms", "sms.png", 
566                       660, 190, 9, 50, 58, 
567                       FALSE, TRUE, 100, 255, 
568                       NULL, NULL, NULL);
569   scene->actors = g_slist_append(scene->actors, actor);
570   g_ptr_array_add(child, actor);
571
572   actor = init_object(desktop_plugin, "billboard_text", "",
573                       470, 174, 9, 300, 108,
574                       FALSE, FALSE, 100, 255,
575                       (gpointer)&change_billboard, NULL, child);
576   create_hildon_actor_text(actor, desktop_plugin);
577   //actor->time_start_animation = time(NULL) + 20;
578   change_billboard(actor, desktop_plugin);
579   scene->actors = g_slist_append(scene->actors, actor);
580
581   actor = init_object(desktop_plugin, "tram", "tram.png", 
582                       -300, 225, 10, 350, 210, 
583                       FALSE, FALSE, 100, 255, 
584                       (gpointer)&change_tram, NULL, NULL);
585   actor->time_start_animation = time(NULL) + fast_rnd(10); 
586   actor->duration_animation = 60;
587   scene->actors = g_slist_append(scene->actors, actor);
588
589   actor = init_object(desktop_plugin, "border", "border0.png", 
590                       0, 480-79, 11, 800, 79,
591                       TRUE, TRUE, 100, 255, 
592                       (gpointer)&change_static_actor_with_corner, NULL, NULL);
593   change_static_actor_with_corner(actor, desktop_plugin);
594   scene->actors = g_slist_append(scene->actors, actor);
595   
596   actor = init_object(desktop_plugin, "moon", "moon1.png", 
597                       400, 20, 6, 60, 60, 
598                       FALSE, FALSE, 100, 255, 
599                       (gpointer)&change_moon, NULL, NULL);
600   change_moon(actor, desktop_plugin);
601   scene->actors = g_slist_append(scene->actors, actor);
602
603   actor = init_object(desktop_plugin, "wind", "", 
604                       0, 0, 5, 0, 0, 
605                       FALSE, FALSE, 100, 255, 
606                       (gpointer)&change_wind, NULL, NULL);
607   change_wind(actor, desktop_plugin);
608   scene->actors = g_slist_append(scene->actors, actor);
609
610     /* windows in 4-th house  */
611
612     winds[0][0] = 482;
613     winds[0][1] = 180;
614
615     winds[1][0] = 495;
616     winds[1][1] = 179;
617
618     winds[2][0] = 482;
619     winds[2][1] = 191;
620
621     winds[3][0] = 495;
622     winds[3][1] = 190;
623     
624     winds[4][0] = 482;
625     winds[4][1] = 201;
626     
627     winds[5][0] = 495;
628     winds[5][1] = 210;
629     
630     winds[6][0] = 482;
631     winds[6][1] = 222;
632     
633     winds[7][0] = 495;
634     winds[7][1] = 221;
635     
636     winds[8][0] = 459;
637     winds[8][1] = 203;
638     
639     winds[9][0] = 495;
640     winds[9][1] = 241;
641     
642     winds[10][0] = 495;
643     winds[10][1] = 252;
644     
645     winds[11][0] = 482;
646     winds[11][1] = 273;
647     
648     winds[12][0] = 495;
649     winds[12][1] = 303;
650     for (i=0; i<13; i++){
651         actor = init_object(desktop_plugin, "window1", "window1.png", 
652                             winds[i][0], winds[i][1], 8, 8, 10, 
653                             FALSE, FALSE, 100, 255, 
654                             (gpointer)&change_window1, NULL, NULL);
655         //change_window1(actor, desktop_plugin);
656         actor->time_start_animation = now + fast_rnd(30);
657         scene->actors = g_slist_append(scene->actors, actor);
658
659     }
660     
661     /* windows in 1-th house  */
662     
663     winds[0][0] = 86;
664     winds[0][1] = 321;
665
666     winds[1][0] = 86;
667     winds[1][1] = 363;
668
669     winds[2][0] = 86;
670     winds[2][1] = 385;
671
672     winds[3][0] = 86;
673     winds[3][1] = 286;
674     
675     winds[4][0] = 94;
676     winds[4][1] = 232;
677     
678     winds[5][0] = 94;
679     winds[5][1] = 243;
680     
681     winds[6][0] = 94;
682     winds[6][1] = 265;
683     
684     winds[7][0] = 94;
685     winds[7][1] = 331;
686     for (i=0; i<8; i++){
687         actor = init_object(desktop_plugin, "window2", "window2.png", 
688                             winds[i][0], winds[i][1], 8, 8, 10, 
689                             FALSE, FALSE, 100, 255, 
690                             (gpointer)&change_window1, NULL, NULL);
691         //change_window1(actor, desktop_plugin);
692         actor->time_start_animation = now + fast_rnd(30);
693         scene->actors = g_slist_append(scene->actors, actor);
694
695     }
696     
697     /* windows in 3-th house  */
698     
699     winds[0][0] = 251;
700     winds[0][1] = 162;
701
702     winds[1][0] = 251;
703     winds[1][1] = 196;
704
705     winds[2][0] = 251;
706     winds[2][1] = 278;
707
708     winds[3][0] = 251;
709     winds[3][1] = 289;
710     
711     winds[4][0] = 313;
712     winds[4][1] = 173;
713     
714     winds[5][0] = 322;
715     winds[5][1] = 160;
716     
717     winds[6][0] = 303;
718     winds[6][1] = 217;
719     
720     winds[7][0] = 322;
721     winds[7][1] = 224;
722     
723     winds[8][0] = 323;
724     winds[8][1] = 217;
725     
726     winds[9][0] = 322;
727     winds[9][1] = 288;
728     
729     for (i=0; i<10; i++){
730         actor = init_object(desktop_plugin, "window3", "window3.png", 
731                             winds[i][0], winds[i][1], 8, 8, 10, 
732                             FALSE, FALSE, 100, 255, 
733                             (gpointer)&change_window1, NULL, NULL);
734         //change_window1(actor, desktop_plugin);
735         actor->time_start_animation = now + fast_rnd(30);
736         scene->actors = g_slist_append(scene->actors, actor);
737
738     }
739
740     /* windows in 5-th house  */
741     
742     winds[0][0] = 610;
743     winds[0][1] = 224;
744
745     winds[1][0] = 602;
746     winds[1][1] = 245;
747
748     winds[2][0] = 602;
749     winds[2][1] = 264;
750
751     winds[3][0] = 610;
752     winds[3][1] = 301;
753     
754     winds[4][0] = 610;
755     winds[4][1] = 320;
756     
757     winds[5][0] = 593;
758     winds[5][1] = 352;
759     
760     winds[6][0] = 610;
761     winds[6][1] = 368;
762     
763     for (i=0; i<7; i++){
764         actor = init_object(desktop_plugin, "window4", "window4.png", 
765                             winds[i][0], winds[i][1], 8, 8, 10, 
766                             FALSE, FALSE, 100, 255, 
767                             (gpointer)&change_window1, NULL, NULL);
768         //change_window1(actor, desktop_plugin);
769         actor->time_start_animation = now + fast_rnd(30);
770         scene->actors = g_slist_append(scene->actors, actor);
771
772     }
773
774     /* windows in 6-th house  */
775     
776     winds[0][0] = 717;
777     winds[0][1] = 283;
778
779     winds[1][0] = 698;
780     winds[1][1] = 293;
781
782     winds[2][0] = 717;
783     winds[2][1] = 315;
784
785     winds[3][0] = 717;
786     winds[3][1] = 323;
787     
788     winds[4][0] = 698;
789     winds[4][1] = 362;
790     
791     winds[5][0] = 698;
792     winds[5][1] = 400;
793     
794     for (i=0; i<6; i++){
795         actor = init_object(desktop_plugin, "window5", "window5.png", 
796                             winds[i][0], winds[i][1], 8, 8, 10, 
797                             FALSE, FALSE, 100, 255, 
798                             (gpointer)&change_window1, NULL, NULL);
799         //change_window1(actor, desktop_plugin);
800         actor->time_start_animation = now + fast_rnd(30);
801         scene->actors = g_slist_append(scene->actors, actor);
802
803     }
804     run_long_timeout(desktop_plugin);
805
806 #if 0    
807   anim = g_new0(Animation, 1);
808   anim->count = 1;
809   anim->actor = actor;
810   anim->func_change = &change_tram;
811   anim->func_time = NULL;
812   anim->timestart = time(NULL); 
813   anim->timeall = 10;
814   
815   scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
816 #endif  
817 }
818 /*******************************************************************************/
819 /* Init Berlin Scene */
820 void
821 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
822 {
823   Actor *actor, *actor1, *actor2;
824   Scene *scene;
825   gint now = time(NULL);
826   gint i; 
827   gint winds[13][2];
828   GPtrArray *child = NULL;
829
830   scene = g_new0(Scene, 1);
831   scene->daytime = get_daytime();
832   scene->actors = NULL;
833   scene->wind_orientation = -1;
834   scene->wind_angle = 0.3;
835   /* init value for random */
836   scene->seed = time(NULL);
837   desktop_plugin->priv->scene = scene;
838   
839   actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480, 
840                       TRUE, TRUE, 100, 255, 
841                       (gpointer)&change_static_actor, NULL, NULL);
842   change_static_actor(actor, desktop_plugin);
843   scene->actors = g_slist_append(scene->actors, actor);
844
845   
846   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
847                       FALSE, FALSE, 100, 255, 
848                       (gpointer)&change_sun, NULL, NULL);
849   actor->time_start_animation = time(NULL);
850   actor->duration_animation = G_MAXINT;
851   change_sun(actor, desktop_plugin);
852   scene->actors = g_slist_append(scene->actors, actor);
853
854 #if 0
855   actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
856                       TRUE, 100, 255, NULL, NULL);
857   scene.actors = g_slist_append(scene.actors, actor);
858 #endif
859
860   actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60, 
861                       FALSE, FALSE, 100, 255, 
862                       (gpointer)&change_moon, NULL, NULL);
863   change_moon(actor, desktop_plugin);
864   scene->actors = g_slist_append(scene->actors, actor);
865   
866   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
867                       FALSE, FALSE, 100, 255, 
868                       (gpointer)&change_cloud, NULL, NULL);
869   actor->time_start_animation = now + fast_rnd(30) + 10;
870   actor->duration_animation = 3*60;
871   scene->actors = g_slist_append(scene->actors, actor);
872   
873   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
874                       FALSE, FALSE, 100, 255, 
875                       (gpointer)&change_cloud, NULL, NULL);
876   actor->time_start_animation = now + fast_rnd(10);
877   actor->duration_animation = 3*60;
878   scene->actors = g_slist_append(scene->actors, actor);
879
880   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
881                       FALSE, FALSE, 100, 255, 
882                       (gpointer)&change_cloud, NULL, NULL);
883   actor->time_start_animation = now + fast_rnd(60) + 20;
884   actor->duration_animation = 5*60;
885   scene->actors = g_slist_append(scene->actors, actor);
886
887  
888   actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
889                       FALSE, FALSE, 100, 255, 
890                       (gpointer)&change_plane2, NULL, NULL);
891   actor->time_start_animation = now + fast_rnd(40) + 20;
892   actor->duration_animation = 60;
893   scene->actors = g_slist_append(scene->actors, actor);
894   
895   actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116, 
896                       FALSE, FALSE, 100, 255, 
897                       (gpointer)&change_plane1, NULL, NULL);
898   actor->time_start_animation = now + fast_rnd(20);
899   actor->duration_animation = 30;
900   scene->actors = g_slist_append(scene->actors, actor);
901
902   actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
903                       TRUE, TRUE, 100, 255, 
904                       (gpointer)&change_static_actor_with_corner, NULL, NULL);
905   change_static_actor_with_corner(actor, desktop_plugin);
906   scene->actors = g_slist_append(scene->actors, actor);
907
908   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
909                       FALSE, FALSE, 100, 255, 
910                       (gpointer)&change_wind, NULL, NULL);
911   change_wind(actor, desktop_plugin);
912   scene->actors = g_slist_append(scene->actors, actor);
913
914   actor1 = init_object(desktop_plugin, "signal_red", "red.png", 
915                       486, 425, 10, 18, 38, 
916                       FALSE, TRUE, 100, 255, NULL, NULL, NULL);
917   //actor->time_start_animation = now + fast_rnd(30) + 10;  
918   scene->actors = g_slist_append(scene->actors, actor1);
919    
920   actor2 = init_object(desktop_plugin, "signal_green", "green.png", 
921                       486, 425, 10, 18, 38, 
922                       TRUE, TRUE, 100, 255, NULL, NULL, NULL);
923   //actor->time_start_animation = now + fast_rnd(30) + 10;  
924   scene->actors = g_slist_append(scene->actors, actor2);
925   child = g_ptr_array_sized_new(2);
926   g_ptr_array_add(child, actor1);
927   g_ptr_array_add(child, actor2);
928   actor = init_object(desktop_plugin, "signal", "",
929                       486, 425, 10, 18, 38,
930                       FALSE, FALSE, 100, 255, 
931                       (gpointer)&change_signal, NULL, child);
932   actor->time_start_animation = now + fast_rnd(30) + 10;
933   scene->actors = g_slist_append(scene->actors, actor);
934     
935     winds[0][0] = 389;
936     winds[0][1] = 305;
937
938     winds[1][0] = 373;
939     winds[1][1] = 306;
940
941     winds[2][0] = 355;
942     winds[2][1] = 306;
943
944     winds[3][0] = 356;
945     winds[3][1] = 288;
946     
947     winds[4][0] = 337;
948     winds[4][1] = 269;
949     
950     winds[5][0] = 372;
951     winds[5][1] = 268;
952   
953     winds[6][0] = 372;
954     winds[6][1] = 249;
955     
956     winds[7][0] = 388;
957     winds[7][1] = 249;
958     
959     winds[8][0] = 387;
960     winds[8][1] = 230;
961     
962     winds[9][0] = 372;
963     winds[9][1] = 211;
964     
965     winds[10][0] = 355;
966     winds[10][1] = 159;
967     
968     winds[11][0] = 335;
969     winds[11][1] = 158;
970     
971     winds[12][0] = 386;
972     winds[12][1] = 119;
973   
974     for (i=0; i<13; i++){
975         actor = init_object(desktop_plugin, "window", "window.png", 
976                             winds[i][0], winds[i][1], 10, 8, 9, 
977                             FALSE, TRUE, 100, 255, 
978                             (gpointer)&change_window1, NULL, NULL);
979         //change_window1(actor, desktop_plugin);
980         actor->time_start_animation = now + fast_rnd(30);
981         scene->actors = g_slist_append(scene->actors, actor);
982
983     }
984     
985     run_long_timeout(desktop_plugin);
986
987 }
988 /*******************************************************************************/
989 void 
990 init_scene_theme(AWallpaperPlugin *desktop_plugin)
991 {
992 #if 0
993     void (*func)(gpointer);
994     func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
995     if (func){
996         (*func)(desktop_plugin);
997     }
998 #endif
999     fprintf(stderr, "Init_scene_theme\n");
1000     void (*func)(gpointer);
1001     func = desktop_plugin->priv->scene_func;
1002     if (func){
1003         fprintf(stderr, "Success init_scene_theme\n");
1004         (*func)(desktop_plugin);
1005     }
1006 }