changed some parametres
[livewp] / applet / src / livewp-home-widget.c
index 219dc8a..3d53e65 100644 (file)
@@ -45,19 +45,38 @@ lw_applet_realize (GtkWidget *widget)
     gchar * strid; 
     gint id; 
     AWallpaperPlugin *desktop_plugin = widget;
+    char* child_argv[] =  {"/usr/bin/livewp", "0", (char *) 0 };
+
 
     strid = g_strdup(hd_plugin_item_get_plugin_id (HD_PLUGIN_ITEM (widget)));
     id = strid[strlen(strid)-1] - '0';
     desktop_plugin->priv->view = id;
     g_free(strid); 
     
+
+    switch (id){
+           case 0: child_argv[1] = "1";
+               break;
+           case 1: child_argv[1] = "2";
+               break;
+           case 2: child_argv[1] = "3";
+               break;
+           case 3: child_argv[1] = "4";
+               break;
+    }
+    desktop_plugin->priv->pid = fork();
+    if (desktop_plugin->priv->pid == 0){
+       execvp("/usr/bin/livewp", child_argv);
+       fprintf(stderr,"Problem with new process");
+    }
+#if 0
     /* Load config */
     read_config(desktop_plugin->priv);
 
     init_scene_theme(desktop_plugin);
         
     desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
-
+#endif
     screen = gtk_widget_get_screen (widget);
     gtk_widget_set_colormap (widget,
                                 gdk_screen_get_rgba_colormap (screen));
@@ -416,28 +435,73 @@ desktop_plugin_visible_notify (GObject    *object,
                                           AWallpaperPlugin *desktop_plugin)
 {
     gboolean visible;
+    Animation_WallpaperPrivate *priv = desktop_plugin->priv;
     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;
-        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;
-        if (desktop_plugin->priv->long_timer != 0 ){
-            g_source_remove(desktop_plugin->priv->long_timer);
-            desktop_plugin->priv->long_timer = 0;
-        }
-    }
+    fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); 
+    if (priv){
+            switch (priv->view + 1){
+               case 1: if (visible)
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW1);
+                       else
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW1);
+                       break;
+               case 2: if (visible)
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW2);
+                       else
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW2);
+                       break;
+               case 3: if (visible)
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW3);
+                       else
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW3);
+                       break;
+               case 4: if (visible)
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW4);
+                       else
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW4);
+                       break;
+            }
+     }
+
 }
+
 gboolean
 rich_animation_press(GtkWidget *widget, GdkEvent *event,
                                             gpointer user_data){
     fprintf(stderr,"gggggggggggggggggggg2222\n");
     return FALSE;
 }    
+
+gboolean
+send_alive_event(Animation_WallpaperPrivate *priv) 
+{
+    fprintf(stderr, "send_alive_event\n");
+    switch (priv->view + 1){
+       case 1: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW1);
+               break;
+       case 2: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW2);
+               break;
+       case 3: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW3);
+               break;
+       case 4: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW4);
+               break;
+    }
+
+    return TRUE;
+}
+
 static void
 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
 {
@@ -468,73 +532,32 @@ animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
     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("Accel"), (gpointer)&init_scene_Accel);
+    g_hash_table_insert(priv->hash_scene_func, g_strdup("Video"), (gpointer)&init_scene_Video);
 //#endif
-    priv->theme = g_strdup("Accel");
+    //priv->theme = g_strdup("Accel");
     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);
-    }
-#if 0
-    GtkWidget *label = gtk_label_new ("1111ddddddddd");
-    gtk_widget_set_size_request(label, 95, 30);
-    gtk_widget_show (label);
-    gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
-#endif
-    hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
-    g_signal_connect (desktop_plugin, "show-settings",
-                            G_CALLBACK (show_settings), priv);
+    gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 1, 1);
     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));
 
     
-    //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_Modern(desktop_plugin);
-    else if (!strcmp(priv->theme,"Berlin")) 
-        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;
     g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
                    G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
 
-   
-    //sleep(2);
+    priv->alive_timer = g_timeout_add(60000*3, (GtkFunction)send_alive_event, priv);  /* One per 3 minute */ 
 }
 
 static void
 lw_applet_finalize (GObject *object)
 {
+     int status = 0; int wpid; 
 fprintf(stderr,"lw_applet_finalize\n");
-/*
      AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
      Animation_WallpaperPrivate *priv = desktop_plugin->priv;
+/*
      
      if (priv){
             livewp_deinitialize_dbus(priv);
@@ -550,7 +573,33 @@ fprintf(stderr,"lw_applet_finalize\n");
 
             destroy_scene(desktop_plugin);
      }
-*/
+*/    
+     
+     if (priv){
+            switch (priv->view + 1){
+               case 1: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW1);
+                       break;
+               case 2: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW2);
+                       break;
+               case 3: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW3);
+                       break;
+               case 4: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_STOP_LIVEBG_ON_VIEW4);
+                       break;
+            }
+     }
+     if(priv->alive_timer > 0) 
+         g_source_remove(priv->alive_timer);
+
+     livewp_deinitialize_dbus(priv);
+     while (TRUE){
+         wpid = wait(&status);
+        if (wpid == priv->pid)
+            break;
+     }
 }
 
 static void
@@ -559,21 +608,7 @@ desktop_widget_finalize (GObject *object)
      AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
      Animation_WallpaperPrivate *priv = desktop_plugin->priv;
      
-     if (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;
-            }
-            if (priv->short_timer){
-               g_source_remove(priv->short_timer);
-               priv->short_timer = 0;
-            }
-
-            destroy_scene(desktop_plugin);
-     }
-      /* Call the base class's implementation: */
+       /* Call the base class's implementation: */
       G_OBJECT_CLASS (animation_wallpaper_plugin_parent_class)->finalize (object);
 }
 
@@ -588,7 +623,7 @@ animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
     gobject_class->destroy = (gpointer)lw_applet_finalize;
     object_class->finalize = desktop_widget_finalize;
     widget_class->realize = lw_applet_realize;
-    widget_class->expose_event = lw_applet_expose_event;
+//    widget_class->expose_event = lw_applet_expose_event;
 
     g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));