Merge branch 'master' of ssh://drop.maemo.org/git/livewp
[livewp] / applet / src / livewp-main.c
index ba880b9..4df4827 100644 (file)
 #include "livewp-home-widget.h"
 /*******************************************************************************/
 
-static void set_live_bg (Display *display, Window xwindow, int mode);
+void set_live_bg (Display *display, Window xwindow, int mode);
 void quit_from_program (Animation_WallpaperPrivate *priv);
 void view_state_changed (Animation_WallpaperPrivate *priv);
 static gboolean short_timeout (AWallpaperPlugin *desktop_plugin);
 void run_long_timeout(AWallpaperPlugin *desktop_plugin);
 gboolean long_timeout (AWallpaperPlugin *desktop_plugin);
+void conky_visible(AWallpaperPlugin *desktop_plugin);
 
-static 
-void set_live_bg (Display *display, Window xwindow, int mode)
+void 
+set_live_bg (Display *display, Window xwindow, int mode)
 {
-        Atom atom;
+   Atom atom;
+   atom = XInternAtom (display, "_HILDON_LIVE_DESKTOP_BACKGROUND", False);
+   fprintf (stderr, "XID: 0x%x\n", (unsigned)xwindow);
 
-        atom = XInternAtom (display, "_HILDON_LIVE_DESKTOP_BACKGROUND", False);
-        fprintf (stderr, "XID: 0x%x\n", (unsigned)xwindow);
-
-        XChangeProperty (display,
-                       xwindow,
-                       atom,
-                       XA_INTEGER, 32, PropModeReplace,
-                       (unsigned char *) &mode, 1);
+   XChangeProperty (display,
+                 xwindow,
+                  atom,
+                  XA_INTEGER, 32, PropModeReplace,
+                  (unsigned char *) &mode, 1);
 }
 /*******************************************************************************/
 
@@ -55,12 +55,9 @@ void
 view_state_changed (Animation_WallpaperPrivate *priv)
 {
    fprintf(stderr," VIew %i State %i\n", priv->view, priv->visible);
-   if (priv->visible){
-       if (!priv->running){
-            if (!strcmp(priv->theme, "Xsnow")){
-                init_scene_Xsnow(priv->desktop_plugin);
-            }
-       }
+   if (priv->visible){  
+       /* ToDo  make undependent function */
+       /* For Video */
        if (!strcmp(priv->theme,"Video")){
            if (priv->pipeline){
                gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
@@ -68,6 +65,17 @@ view_state_changed (Animation_WallpaperPrivate *priv)
                init_scene_Video(priv->desktop_plugin);
            }
        }
+       /* For Conky */
+       if (!strcmp(priv->theme,"Conky")&& priv->running){
+           conky_visible(priv->desktop_plugin);
+           return;
+       }
+
+       if (!priv->running){
+            if (g_hash_table_lookup(priv->hash_theme, "exec_path")){
+                init_scene_External(priv->desktop_plugin);
+            }
+       }
        if (priv->long_timer == 0 ){
             priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, priv->desktop_plugin);
             run_long_timeout(priv->desktop_plugin);
@@ -75,10 +83,16 @@ view_state_changed (Animation_WallpaperPrivate *priv)
             run_long_timeout(priv->desktop_plugin);
        }
    }else{
+        /* For Video */
         if (priv->pipeline){
            gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
            return;
         }
+        /* For Conky */
+        if (!strcmp(priv->theme,"Conky")){
+           conky_visible(priv->desktop_plugin);
+           return;
+        }
         if (priv->long_timer != 0 ){
             g_source_remove(priv->long_timer);
             priv->long_timer = 0;
@@ -134,7 +148,7 @@ quit_from_program (Animation_WallpaperPrivate *priv)
             }
             destroy_scene(priv->desktop_plugin);
          osso_deinitialize(priv->osso);
-         g_hash_table_destroy(priv->hash_scene_func);
+         //g_hash_table_destroy(priv->hash_scene_func);
          g_free(priv->desktop_plugin);
          priv->desktop_plugin = NULL;
          g_free(priv);
@@ -182,7 +196,7 @@ short_timeout (AWallpaperPlugin *desktop_plugin)
     }else
          return TRUE; /* keep running this event */
 }
-
+/*******************************************************************************/
 void
 run_long_timeout(AWallpaperPlugin *desktop_plugin)
 {
@@ -230,7 +244,7 @@ run_long_timeout(AWallpaperPlugin *desktop_plugin)
     }
  
 }
-
+/*******************************************************************************/
 gboolean
 long_timeout (AWallpaperPlugin *desktop_plugin)
 {
@@ -263,12 +277,28 @@ long_timeout (AWallpaperPlugin *desktop_plugin)
     run_long_timeout(desktop_plugin);
     return TRUE; /* keep running this event */
 }
-
+/*******************************************************************************/
+void
+create_xwindow (Animation_WallpaperPrivate *priv){
+    GtkWidget *main_widget = NULL;
+    GtkWidget *label = NULL;
+    /* Create Main GUI */
+    main_widget = hildon_window_new ();
+    priv->window = main_widget;
+    gtk_window_set_title(GTK_WINDOW(main_widget), PACKAGE);
+    gtk_window_fullscreen(GTK_WINDOW(main_widget));
+    label = gtk_label_new(_("Loading Livewallpaper scene ..."));
+    gtk_container_add (GTK_CONTAINER (main_widget), label);
+    gtk_widget_show_all(GTK_WIDGET(main_widget));
+    if (priv->one_in_all_view)
+        set_live_bg(GDK_WINDOW_XDISPLAY (main_widget->window), GDK_WINDOW_XID (main_widget->window), -1);
+    else
+        set_live_bg(GDK_WINDOW_XDISPLAY (main_widget->window), GDK_WINDOW_XID (main_widget->window), priv->view);
+}
 /*******************************************************************************/
 int
 main(int argc, char *argv[])
 {
-    GtkWidget *main_widget = NULL;
     HildonProgram       *app;
     int view = 1;
 
@@ -282,7 +312,6 @@ main(int argc, char *argv[])
     Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
     desktop_plugin->priv = priv; 
 
-    gst_init (NULL, NULL);
 
     /* Ininitializing */
     hildon_gtk_init (&argc, &argv);
@@ -301,42 +330,34 @@ main(int argc, char *argv[])
     bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
     textdomain(GETTEXT_PACKAGE);
 #endif
-/* Create Main GUI */
-    main_widget = hildon_window_new ();
-    gtk_window_set_title(GTK_WINDOW(main_widget), PACKAGE);
-    gtk_window_fullscreen(GTK_WINDOW(main_widget));
-    
-    gtk_widget_show_all(GTK_WIDGET(main_widget));
-
-    priv->hash_scene_func = g_hash_table_new(g_str_hash, g_str_equal);
-    g_hash_table_insert(priv->hash_scene_func, g_strdup("Accel"),  (gpointer)&init_scene_Accel);
-    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);
-    g_hash_table_insert(priv->hash_scene_func, g_strdup("Video"),  (gpointer)&init_scene_Video);
-    g_hash_table_insert(priv->hash_scene_func, g_strdup("Xsnow"),  (gpointer)&init_scene_Xsnow);
 
     priv->scene = NULL;
     priv->pipeline = NULL;
     priv->podpid = -1;
     priv->running = FALSE;
-    priv->window = main_widget;
     /* fprintf(stderr,"XWINDOW %i\n",GDK_WINDOW_XID (main_widget->window)); */
     priv->desktop_plugin = desktop_plugin;
+
+
     priv->view = view;
+    fill_priv(priv);
+    fprintf(stderr,"THEME %s\n", priv->theme);
 
-    if (current_active_view() == view) 
+    /* Check activity of opition "One theme in all views" */
+    if (priv->one_in_all_view && view >1)
+        return -1;   
+
+
+    if (current_active_view() == view && !priv->one_in_all_view) 
         priv->visible = TRUE;
     else 
         priv->visible = FALSE;
 
-    /* Load config */
-    read_config(priv);
 
+    create_xwindow(priv);
     /* Initialize DBUS */
     livewp_initialize_dbus(priv);
-    set_live_bg(GDK_WINDOW_XDISPLAY (main_widget->window), GDK_WINDOW_XID (main_widget->window), view);
-    
+        
     priv->view_notify = 0; 
     /* fprintf(stderr,"VISIBLE %i %i\n",priv->visible, current_active_view()); */
     gconf_client_add_dir(gconf_client_get_default (), "/apps/osso/hildon-desktop/views", GCONF_CLIENT_PRELOAD_NONE, NULL);
@@ -344,8 +365,10 @@ main(int argc, char *argv[])
                                                 (GConfClientNotifyFunc)view_changed, priv, NULL, NULL);
 
     /* Set start position of Video to zero */
-    if (!strcmp(priv->theme,"Video"))
+    if (!strcmp(priv->theme,"Video")){
+        gst_init (NULL, NULL);
         priv->theme_int_parametr1 = 0;
+    }
 
     init_scene_theme(desktop_plugin);