tryed fix xsnow
[livewp] / applet / src / livewp-settings.c
index b959d5f..ef23997 100644 (file)
@@ -34,9 +34,9 @@ void lw_about(void){
     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
     vbox = gtk_vbox_new (FALSE, 5);
-    label_about = gtk_label_new (_("Live Wallpaper\n Version 0.5 \n Copyright(c) 2010\n \
+    label_about = gtk_label_new (_("Live Wallpaper Version 0.7.1 \n Copyright(c) 2010\n \
 Tanya Makova\n Vlad Vasiliev\n \
-Copyright(c) 2010 for design themes Berlin and Modern Vasya Bobrikov\n \
+Copyright(c) 2010 for design themes Berlin, Modern and Accel Vasya Bobrikov\n \
 Copyright(c) 2010 for design theme Matrix Andrew Zhilin\n \
 Translators:\n \
 Finnish - Marko Vertainen\n \
@@ -62,32 +62,29 @@ create_theme_selector (void){
       hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Berlin"));
       hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Modern"));
       hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Matrix"));
+      hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Accel"));
+      hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Video"));
+      hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Xsnow"));
       return selector;
 }
 /*******************************************************************************/
 void
 theme_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
 
-    lw_theme_settings(priv, NULL);
+    lw_theme_settings(GTK_WIDGET(button), priv);
 }
 /********************************************************************************/
-
-GtkWidget *
-create_image_button (gint view){
-    GtkWidget *button;
-    GtkWidget *image;
-    gchar * str;
-    GdkPixbuf * pixbuf;
-    
-    fprintf(stderr,"create_image_button\n");
-    Animation_WallpaperPrivate *priv = g_new0(Animation_WallpaperPrivate, 1);
-    priv->view = view;
-    read_config(priv);
-    button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
-                                    HILDON_BUTTON_ARRANGEMENT_VERTICAL);
-    g_object_set_data(G_OBJECT(button), "view", GINT_TO_POINTER(view));
-    str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
-                        priv->theme, "icon.png");
+void
+set_button_image(GtkWidget * button, gchar *theme, gboolean enable){
+    GtkWidget * image = NULL; 
+    GdkPixbuf * pixbuf = NULL;
+    gchar *str = NULL;
+    if (enable)
+        str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
+                        theme, "icon.png");
+    else 
+        str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
+                        theme, "icond.png");
     pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
                                              100, 
                                              60, 
@@ -99,13 +96,67 @@ create_image_button (gint view){
         g_object_unref(G_OBJECT(pixbuf));
     }
 
-    hildon_button_set_image (HILDON_BUTTON (button), image);
+   hildon_button_set_image (HILDON_BUTTON (button), image);
+}
+/********************************************************************************/
+GtkWidget *
+create_image_button (gint view, DBusConnection *conn_sess){
+    GtkWidget *button;
+    
+    Animation_WallpaperPrivate *priv = g_new0(Animation_WallpaperPrivate, 1);
+    priv->view = view;
+    priv->theme_string_parametr1 = NULL;
+    priv->dbus_conn_session = conn_sess;
+    read_config(priv);
+    button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
+                                    HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+    g_object_set_data(G_OBJECT(button), "view", GINT_TO_POINTER(view));
+    g_object_set_data(G_OBJECT(button), "priv", priv);
+    set_button_image(button, priv->theme, check_applet_state(view));
     g_signal_connect(button, "clicked", G_CALLBACK(theme_button_clicked), priv);
-    //hildon_button_set_image_position (HILDON_BUTTON (button), GTK_POS_RIGHT);
+    hildon_button_set_image_position (HILDON_BUTTON (button), GTK_POS_RIGHT);
     return button;
 
 }
 /********************************************************************************/
+void
+changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
+{
+    const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
+    GtkWidget *vbox = NULL;
+        
+    vbox = g_object_get_data(G_OBJECT(priv->window), "custom_vbox");
+    if (vbox)
+        gtk_widget_destroy(vbox);
+    vbox = gtk_vbox_new (FALSE, 5);
+    g_object_set_data(G_OBJECT(priv->window), "custom_vbox", vbox);
+    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(priv->window)->vbox),
+                                   vbox, TRUE, TRUE, 5);
+    if (choice) {
+        if (!strcmp(choice, _("Berlin"))){
+            rich_animation_additional_parametr(vbox,priv);
+        }
+        if (!strcmp(choice, _("Modern"))){
+            rich_animation_additional_parametr(vbox,priv);
+        }
+        if (!strcmp(choice, _("Matrix"))){
+            rich_animation_additional_parametr(vbox,priv);
+        }
+        if (!strcmp(choice, _("Xsnow"))){
+            rich_animation_additional_parametr(vbox,priv);
+        }
+
+        if (!strcmp(choice, _("Accel"))){
+            rich_animation_additional_parametr(vbox,priv);
+        }
+        if (!strcmp(choice, _("Video"))){
+            additional_parametr_for_theme_video(vbox, priv);
+        }
+    }
+    gtk_widget_show(vbox);
+}
+
+/********************************************************************************/
 GtkWidget *
 create_themes_button (gchar *theme){
 
@@ -130,18 +181,30 @@ create_themes_button (gchar *theme){
             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 2);
             hildon_button_set_value(HILDON_BUTTON(button), _("Matrix"));
         }
-
+        if (!strcmp(theme, "Accel")){
+            hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 3);
+            hildon_button_set_value(HILDON_BUTTON(button), _("Accel"));
+        }
+        if (!strcmp(theme, "Video")){
+            hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 4);
+            hildon_button_set_value(HILDON_BUTTON(button), _("Video"));
+        }
+        if (!strcmp(theme, "Xsnow")){
+            hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 5);
+            hildon_button_set_value(HILDON_BUTTON(button), _("Xsnow"));
+        }
     }
+    
     return button;
 }
 
 /*******************************************************************************/
 GtkWidget *
-create_rich_animation_button (gboolean active)
+create_rich_animation_button (gboolean active, gchar *name)
 {
     GtkWidget *button;
     button = hildon_check_button_new (HILDON_SIZE_AUTO);
-    gtk_button_set_label (GTK_BUTTON (button), _("Rich Animation"));
+    gtk_button_set_label (GTK_BUTTON (button), name);
     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
     return button;
 }
@@ -159,7 +222,7 @@ create_enable_button (gboolean active)
 /*******************************************************************************/
 void
 show_settings(GtkWidget *widget, Animation_WallpaperPrivate *priv){
-    lw_settings(priv, NULL);
+    lw_main_settings(priv, NULL);
 }
 /*******************************************************************************/
 void 
@@ -171,8 +234,8 @@ lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
     GtkWidget *theme_button3;
     GtkWidget *theme_button4;
     GtkWidget *hbox;
+    Animation_WallpaperPrivate *priv_temp = NULL;
 
-    fprintf(stderr,"lw_main_settings\n");
     window = gtk_dialog_new();
 
     gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
@@ -180,16 +243,16 @@ lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
     /* Create Theme button */
     hbox = gtk_hbox_new(FALSE, 5);
-    theme_button1 = create_image_button(0);
+    theme_button1 = create_image_button(1, priv->dbus_conn_session);
     gtk_box_pack_start(GTK_BOX(hbox),
                                    theme_button1, TRUE, TRUE, 5);
-    theme_button2 = create_image_button(1);
+    theme_button2 = create_image_button(2, priv->dbus_conn_session);
     gtk_box_pack_start(GTK_BOX(hbox),
                                    theme_button2, TRUE, TRUE, 5);
-    theme_button3 = create_image_button(2);
+    theme_button3 = create_image_button(3, priv->dbus_conn_session);
     gtk_box_pack_start(GTK_BOX(hbox),
                                    theme_button3, TRUE, TRUE, 5);
-    theme_button4 = create_image_button(3);
+    theme_button4 = create_image_button(4, priv->dbus_conn_session);
     gtk_box_pack_start(GTK_BOX(hbox),
                                    theme_button4, TRUE, TRUE, 5);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
@@ -205,6 +268,28 @@ lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
 
     result = gtk_dialog_run(GTK_DIALOG(window));
 
+    priv_temp = g_object_get_data(G_OBJECT(theme_button1), "priv");
+    if (priv_temp){
+        g_free(priv_temp);
+        priv_temp =NULL;
+    }
+    priv_temp = g_object_get_data(G_OBJECT(theme_button2), "priv");
+    if (priv_temp){
+        g_free(priv_temp);
+        priv_temp =NULL;
+    }
+    priv_temp = g_object_get_data(G_OBJECT(theme_button3), "priv");
+    if (priv_temp){
+        g_free(priv_temp);
+        priv_temp =NULL;
+    }
+    priv_temp = g_object_get_data(G_OBJECT(theme_button4), "priv");
+    if (priv_temp){
+        g_free(priv_temp);
+        priv_temp =NULL;
+    }
+
+
     switch(result){
         case GTK_RESPONSE_NO:
             gtk_widget_destroy(window);
@@ -212,25 +297,86 @@ lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
             lw_about();
         break;
     }
+
+
     if (window)
         gtk_widget_destroy(window);
 }
+/*******************************************************************************/
+void
+file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
+
+    GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
+
+    if (priv->theme_string_parametr1)
+        gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
+
+    gtk_widget_show_all (GTK_WIDGET (dialog));
+
+    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
+    {
+      hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
+    }
+    gtk_widget_destroy (dialog);
+
+}
+/*******************************************************************************/
+void
+rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
+    GtkWidget *rich_animation_button;
+    /* Create rich animation button */  
+    rich_animation_button = create_rich_animation_button(priv->rich_animation, _("Rich Animation"));
+    gtk_box_pack_start(GTK_BOX(vbox),
+                                   rich_animation_button, TRUE, TRUE, 5);
+    g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
+    gtk_widget_show (rich_animation_button);
+}
+/*******************************************************************************/
+void
+additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
+
+    GtkWidget *file_button;
+    GtkWidget *rich_animation_button;
+
+    if (priv->theme_string_parametr1)
+        file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+                                                   _("Play file"), priv->theme_string_parametr1);
+    else
+        file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+                                                   _("Play file")," ");
+
+    g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
 
+    gtk_box_pack_start(GTK_BOX(vbox),
+                                   file_button, TRUE, TRUE, 5);
+    g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);    /* Create rich animation button */  
+    rich_animation_button = create_rich_animation_button(priv->rich_animation, _("Loop"));
+    gtk_box_pack_start(GTK_BOX(vbox),
+                                   rich_animation_button, TRUE, TRUE, 5);
+    g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
+
+    gtk_widget_show (file_button);
+    gtk_widget_show (rich_animation_button);
+
+}
 /*******************************************************************************/
 void 
-lw_theme_settings(Animation_WallpaperPrivate *priv, gpointer  data){
+lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
     gint result;
     GtkWidget *window = NULL;
     GtkWidget *save_button;
     GtkWidget *theme_button;
     GtkWidget *enable_button;
-    GtkWidget *rich_animation_button;
+    GtkWidget *vbox;
+    GtkWidget *button1 = NULL;
+    GtkWidget *rich_animation_button = NULL;
     gint view = priv->view;
+    gboolean success_choice = TRUE;
 
-    fprintf(stderr,"lw_theme_settings\n");
     window = gtk_dialog_new();
+    priv->window = window;
 
-    gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
+    gtk_window_set_title(GTK_WINDOW(window), _("View Settings"));
     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
     /* Create Enable button */
@@ -239,17 +385,31 @@ lw_theme_settings(Animation_WallpaperPrivate *priv, gpointer  data){
                                    enable_button, TRUE, TRUE, 5);
     /* Create Theme button */
     theme_button = create_themes_button(priv->theme);
+    g_signal_connect (G_OBJECT (theme_button), "value-changed",  G_CALLBACK (changed_value_theme_cb), priv);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
                                    theme_button, TRUE, TRUE, 5);
-    /* Create rich animation button */  
-    rich_animation_button = create_rich_animation_button(priv->rich_animation);
+
+    /* Create custom vbox */
+    vbox = gtk_vbox_new (FALSE, 5);
+    g_object_set_data(G_OBJECT(window), "custom_vbox", vbox);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
-                                   rich_animation_button, TRUE, TRUE, 5);
+                                   vbox, TRUE, TRUE, 5);
+    if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin"))||
+        !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix"))||
+        !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel"))||
+        !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Xsnow"))||
+        !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern"))){
+        rich_animation_additional_parametr(vbox, priv);
+    }
+
+    if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
+        additional_parametr_for_theme_video(vbox, priv);
+    } 
+
     gtk_widget_show (enable_button);
     gtk_widget_show (theme_button);
-    gtk_widget_show (rich_animation_button);
+    gtk_widget_show (vbox);
     gtk_widget_show (window);
-    gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
     save_button = gtk_dialog_add_button(GTK_DIALOG(window), _("Save"), GTK_RESPONSE_YES);
 
     result = gtk_dialog_run(GTK_DIALOG(window));
@@ -258,35 +418,67 @@ lw_theme_settings(Animation_WallpaperPrivate *priv, gpointer  data){
         case GTK_RESPONSE_YES:
             /* Check theme */
             if (hildon_button_get_value(HILDON_BUTTON (theme_button))){
+
                 if (priv->theme)
                     g_free(priv->theme);
+
                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
                     priv->theme = g_strdup("Berlin");
                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern")))
                     priv->theme = g_strdup("Modern");
                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix")))
                     priv->theme = g_strdup("Matrix");
+                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel")))
+                    priv->theme = g_strdup("Accel");
+                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Xsnow"))){
+                    priv->theme = g_strdup("Xsnow");
+                    if (access("/usr/bin/xsnow", F_OK) != 0){
+                        fprintf(stderr,"sddddddddddddddddddddddddddddd\n");
+                        success_choice = FALSE;
+                        hildon_banner_show_information(GTK_WIDGET(window), NULL, 
+                        _("You haven't got the installed package Xsnow. Please install it via using Application Manager"));
+                    }
+                }
+                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
+                    priv->theme = g_strdup("Video");
+                    button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
+                    if (button1){
+                        if (priv->theme_string_parametr1)
+                            g_free(priv->theme_string_parametr1);
+                        priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
+                    }
+                }
+
+            }
+
+            rich_animation_button = g_object_get_data(G_OBJECT(priv->window), "rich_animation_button");
+            if (rich_animation_button){
+                /* Check rich animation */
+                if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(rich_animation_button)))
+                    priv->rich_animation = TRUE;
+                else
+                    priv->rich_animation = FALSE;
             }
-            /* Check rich animation */
-            if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(rich_animation_button)))
-                priv->rich_animation = TRUE;
-            else
-                priv->rich_animation = FALSE;
+            /* if not scuccess exit from wthout saving */ 
+            if (!success_choice)
+                break;
             /* Save config */
             save_config(priv);
             /* action with applet */
             if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(enable_button))){
-                    if (!check_applet_state(view))
+                    if (!check_applet_state(view)){
                         start_applet(view);
-                    else
+                    }else {
                         send_dbus_signal (priv,
                               LIVEWP_SIGNAL_INTERFACE,
                               LIVEWP_SIGNAL_PATH,
                               LIVEWP_RELOAD_CONFIG);
+                    }
             }else
                     if (check_applet_state(view))
                         stop_applet(view);
 
+            set_button_image(button, priv->theme, check_applet_state(view));
             break;
         default:
         case GTK_RESPONSE_OK:
@@ -308,11 +500,10 @@ check_applet_state(gint number){
     GKeyFile *gkey_file = NULL;
     gchar *str = NULL;
     gboolean result = FALSE;
-fprintf(stderr,"check_applet_state\n");
-    if (number > 3 || number < 0)
+    if (number > 4 || number < 1)
         return FALSE;
 
-    str = g_strdup_printf("livewp-home-widget.desktop-%i",number);
+    str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
     
     gkey_file = hd_config_file_load_file(config_file, FALSE);
@@ -350,9 +541,9 @@ start_applet(gint number){
     GKeyFile *gkey_file = NULL;
     gchar *str = NULL;
 
-    if (number > 3 || number < 0)
+    if (number > 4 || number < 1)
         return;
-    str = g_strdup_printf("livewp-home-widget.desktop-%i",number);
+    str = g_strdup_printf("livewp-home-widget.desktop-%i",(number - 1));
     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
     
     gkey_file = hd_config_file_load_file(config_file, FALSE);
@@ -369,6 +560,27 @@ start_applet(gint number){
 /*******************************************************************************/
 void
 stop_applet(gint number){
+    HDConfigFile *config_file = NULL;
+    GKeyFile *gkey_file = NULL;
+    gchar *str = NULL;
+
+    if (number > 4 || number < 1)
+        return;
+    str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
+    config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
+    
+    gkey_file = hd_config_file_load_file(config_file, FALSE);
+    if (gkey_file){
+         g_key_file_remove_group(gkey_file, str, NULL);  
+        hd_config_file_save_file( config_file, gkey_file);
+        g_key_file_free(gkey_file);
+    }else
+        fprintf(stderr, "Problem with config file");
+    if (str)
+        g_free(str);
+    g_object_unref(config_file);
+
+#if 0    
     FILE    *file_in;
     FILE    *file_out;
     gchar buffer[2048];
@@ -403,4 +615,5 @@ stop_applet(gint number){
             unlink ("/tmp/livewallpaper.plugins");
         }
     }
+#endif
 }