fixed time to change image, added icons to slideshow and flash, added change image...
[livewp] / applet / src / livewp-settings.c
index 3da182e..db6006c 100644 (file)
@@ -179,7 +179,7 @@ create_image_button (gint view, DBusConnection *conn_sess){
     g_object_set_data(G_OBJECT(event_box), "view", GINT_TO_POINTER(view));
     g_object_set_data(G_OBJECT(event_box), "priv", priv);
     set_button_image(event_box, priv, check_applet_state(view));
-    g_signal_connect(G_OBJECT (event_box), "button_press_event", G_CALLBACK(theme_button_clicked), priv);
+    g_signal_connect(G_OBJECT (event_box), "button_release_event", G_CALLBACK(theme_button_clicked), priv);
     return event_box;
 #if 0
     button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
@@ -239,6 +239,9 @@ changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *
         if (!strcmp(choice, _("Flash"))){
             additional_parametr_for_theme_flash(vbox, priv);
         }
+        if (!strcmp(choice, _("Slideshow"))){
+            additional_parametr_for_theme_slideshow(vbox, priv);
+        }
 
     }
     gtk_widget_show(vbox);
@@ -302,7 +305,8 @@ fill_theme_button (Animation_WallpaperPrivate *priv, GtkWidget *button, gchar *c
         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"));
-        num = 5;
+        hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Slideshow"));
+        num = 6;
         if (theme){
             if (!strcmp(theme, "Berlin")){
                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
@@ -324,6 +328,10 @@ fill_theme_button (Animation_WallpaperPrivate *priv, GtkWidget *button, gchar *c
                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 4);
                 hildon_button_set_value(HILDON_BUTTON(button), _("Video"));
             }
+            if (!strcmp(theme, "Slideshow")){
+                hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 5);
+                hildon_button_set_value(HILDON_BUTTON(button), _("Slideshow"));
+            }
        }
     }
     while (store){
@@ -406,6 +414,10 @@ create_categories_button (Animation_WallpaperPrivate *priv){
             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
         }
+        if (!strcmp(theme, "Slideshow")){
+               hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
+            hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
+        }
         GSList *store = priv->extheme_list;
         num = 1;
         while (store){
@@ -427,7 +439,35 @@ create_categories_button (Animation_WallpaperPrivate *priv){
     }
     return button;
 }
-
+/*******************************************************************************/
+GtkWidget *
+create_time_button (guint *active, gchar *name)
+{
+       GtkWidget *button;
+       GtkWidget *selector;
+       guint values[5] = {20, 40, 60, 120, 300};
+       int i, num = 0;
+       gchar *str;
+
+       button = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+       hildon_button_set_title (HILDON_BUTTON (button), name);
+
+       selector = hildon_touch_selector_new_text();
+       for (i=0; i<5; i++){
+               str = g_strdup_printf("%d", values[i]);
+               hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), str);
+               if (values[i] == active) num = i;
+       }
+       hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
+                       HILDON_TOUCH_SELECTOR (selector));
+       hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, num);
+       if (active){
+        str = g_strdup_printf("%d", active);
+               hildon_button_set_value(HILDON_BUTTON(button), str);
+    }else
+               hildon_button_set_value(HILDON_BUTTON(button), "");
+       return button;
+}
 /*******************************************************************************/
 GtkWidget *
 create_bool_button (gboolean active, gchar *name)
@@ -459,10 +499,12 @@ void
 create_themes_buttons_hbox(Animation_WallpaperPrivate *priv){
     GtkWidget *hbox = NULL;
     GtkWidget *area_hbox = NULL;
-    GtkWidget *theme_button1;
-    GtkWidget *theme_button2;
-    GtkWidget *theme_button3;
-    GtkWidget *theme_button4;
+    GtkWidget *theme_button;
+    GSList *stlist = NULL;
+    GConfClient *gconf_client = NULL;
+    GConfValue *value = NULL;
+    guint count_of_view = 1;
+    guint i;
 
 
     area_hbox = g_object_get_data(G_OBJECT(priv->window), "area_hbox");
@@ -472,31 +514,39 @@ create_themes_buttons_hbox(Animation_WallpaperPrivate *priv){
     if (hbox){
         gtk_widget_destroy(hbox);
     }
+
     hbox = gtk_hbox_new(FALSE, 0);
     g_object_set_data(G_OBJECT(priv->window), "custom_hbox", hbox);
     gtk_box_pack_start(GTK_BOX(area_hbox),
                                    hbox, FALSE, FALSE, 5);
     /* Create Theme buttons */
-    theme_button1 = create_image_button(1, priv->dbus_conn_session);
+    theme_button = create_image_button(1, priv->dbus_conn_session);
     gtk_box_pack_start(GTK_BOX(hbox),
-                                   theme_button1, TRUE, TRUE, 0);
-    gtk_widget_show (theme_button1);
+                                   theme_button, TRUE, TRUE, 10);
+    gtk_widget_show (theme_button);
     gtk_widget_show (hbox);
     if (priv->one_in_all_view)
         return;
-    theme_button2 = create_image_button(2, priv->dbus_conn_session);
-    gtk_box_pack_start(GTK_BOX(hbox),
-                                   theme_button2, TRUE, TRUE, 0);
-    gtk_widget_show (theme_button2);
-    theme_button3 = create_image_button(3, priv->dbus_conn_session);
-    gtk_box_pack_start(GTK_BOX(hbox),
-                                   theme_button3, TRUE, TRUE, 0);
-    gtk_widget_show (theme_button3);
-    theme_button4 = create_image_button(4, priv->dbus_conn_session);
-    gtk_box_pack_start(GTK_BOX(hbox),
-                                   theme_button4, TRUE, TRUE, 0);
-    gtk_widget_show (theme_button4);
 
+    gconf_client = gconf_client_get_default();
+    if (!gconf_client)
+        return;
+
+    stlist = gconf_client_get_list(gconf_client,
+                                       "/apps/osso/hildon-desktop/views/active",
+                                       GCONF_VALUE_INT, NULL);
+    if (stlist){
+        count_of_view = g_slist_length(stlist);
+        g_slist_free(stlist);
+    }else
+        count_of_view = 4;
+    g_object_unref(gconf_client);
+    for (i = 2; i < count_of_view + 1; i++){
+        theme_button = create_image_button(i, priv->dbus_conn_session);
+        gtk_box_pack_start(GTK_BOX(hbox),
+                                   theme_button, TRUE, TRUE, 10);
+        gtk_widget_show (theme_button);
+    }
 }
 /*******************************************************************************/
 void
@@ -505,8 +555,10 @@ lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
     GtkWidget *window = NULL;
     GtkWidget *banner = NULL;
     GtkWidget *area_hbox;
+    GtkWidget *scrolled_window;
     GtkWidget *one_in_all_view_button;
     gboolean one_in_all_view;
+    gint i;
 
     window = gtk_dialog_new();
     priv->window = window;
@@ -520,38 +572,26 @@ lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), one_in_all_view_button, TRUE, TRUE, 5);
     area_hbox = gtk_vbox_new(FALSE, 2);
     g_object_set_data(G_OBJECT(window), "area_hbox", area_hbox);
+
     create_themes_buttons_hbox(priv);
+    scrolled_window = hildon_pannable_area_new ();
+    g_object_set (G_OBJECT (scrolled_window), "mov-mode", HILDON_MOVEMENT_MODE_HORIZ, NULL);
+    g_object_set (G_OBJECT (scrolled_window), "hscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
+    g_object_set (G_OBJECT (scrolled_window), "scrollbar-fade-delay", 27000, NULL);
+    g_object_set (G_OBJECT (scrolled_window), "indicator-width", 28, NULL);
+    gtk_widget_set_size_request(scrolled_window, -1, 120);
+    hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (scrolled_window), GTK_WIDGET (area_hbox));
+
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
-                                   area_hbox, TRUE, TRUE, 0);
+                                   scrolled_window, TRUE, TRUE, 0);
 
-    gtk_widget_show (one_in_all_view_button);
-    gtk_widget_show_all (area_hbox);
-    gtk_widget_show (window);
+    gtk_widget_show(scrolled_window);
+    gtk_widget_show(one_in_all_view_button);
+    gtk_widget_show_all(area_hbox);
+    gtk_widget_show(window);
     gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
 
     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:
@@ -566,10 +606,8 @@ lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
         //fprintf(stderr,"CHECK!!!!!!!!!!!!!!\n");
         banner = hildon_banner_show_information (window, NULL, _("Livewallpaper is reloading..."));
         hildon_banner_set_timeout(HILDON_BANNER(banner), 3000);
-        stop_applet(1);
-        stop_applet(2);
-        stop_applet(3);
-        stop_applet(4);
+        for (i=1;i<10;i++)
+            stop_applet(i);
         g_timeout_add(3000, (GSourceFunc)cb_timeout_settings, window);
     }else{
         if (window)
@@ -580,10 +618,9 @@ lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
 gboolean
 cb_timeout_settings(GtkWidget *window){
 
-    start_applet(1);
-    start_applet(2);
-    start_applet(3);
-    start_applet(4);
+    gint i;
+    for (i=1;i<10;i++)
+        start_applet(i);
 
     if (window)
         gtk_widget_destroy(window);
@@ -609,6 +646,24 @@ file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
 }
 /*******************************************************************************/
 void
+folder_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
+
+    GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+    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;
 
@@ -699,6 +754,35 @@ additional_parametr_for_theme_flash(GtkWidget *vbox, Animation_WallpaperPrivate
     gtk_widget_show (file_button);
 }
 /*******************************************************************************/
+void
+additional_parametr_for_theme_slideshow(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
+
+    GtkWidget *file_button;
+    GtkWidget *time_button;
+
+    if (priv->theme_string_parametr1)
+        file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+                                                   _("Folder with images"), priv->theme_string_parametr1);
+    else
+        file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+                                                   _("Folder with images")," ");
+
+    g_signal_connect (file_button, "clicked", G_CALLBACK (folder_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);
+
+    if (priv->theme_int_parametr1)
+       time_button = create_time_button(priv->theme_int_parametr1, _("Time to change image"));
+    else
+       time_button = create_time_button(0, _("Time to change image"));
+    gtk_box_pack_start(GTK_BOX(vbox), time_button, TRUE, TRUE, 5);
+    g_object_set_data(G_OBJECT(priv->window), "time_button", time_button);
+
+    gtk_widget_show (time_button);
+    gtk_widget_show (file_button);
+}
+/*******************************************************************************/
 
 void
 show_problem_package (GtkWidget *widget, gchar *package_name){
@@ -729,11 +813,11 @@ lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
     GtkWidget *vbox;
     GtkWidget *area_vbox;
     GtkWidget *temp_button;
-    GtkWidget *button1 = NULL;
+    GtkWidget *button1 = NULL, *button2 = NULL;
     GtkWidget *rich_animation_button = NULL;
     GtkWidget *confirm;
     gint view = priv->view;
-    gint count;
+    gint count, int_param;
     gchar *text;
 
     window = gtk_dialog_new();
@@ -796,57 +880,12 @@ lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
             /* Check theme */
             if (hildon_button_get_value(HILDON_BUTTON (theme_button)) &&
                 strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "")){
-#if 0
-                /* Check Xsnow program */
-                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Xsnow"))){
-                    if (access("/usr/bin/xsnow", F_OK) != 0){
-                        show_problem_package(button, "Xsnow");
-                        /* if not scuccess exit from wthout saving */
-                        break;
-                    }
-                }
-                /* Check Shermans program */
-                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Shermans Aquarium")){
-                    if (access("/usr/bin/shermans", F_OK) != 0){
-                        show_problem_package(button,"'Sherman's Aquarium'");
-                        /* if not scuccess exit from wthout saving */
-                        break;
-                    }
-                }
-                /* Check Conky program */
-                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Conky")){
-                    if (access("/usr/bin/conky", F_OK) != 0){
-                        show_problem_package(button,"'Conky'");
-                        /* if not scuccess exit from wthout saving */
-                        break;
-                    }
-                }
-                /* Check Orrery program */
-                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Orrery")){
-                    if (access("/opt/maemo/usr/bin/orrery", F_OK) != 0){
-                        show_problem_package(button,"'Orrery'");
-                        /* if not scuccess exit from wthout saving */
-                        break;
-                    }
-                }
-                /* Check CrazyChickens program */
-                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "CrazyChickens")){
-                    if (access("/usr/bin/crazychickens", F_OK) != 0){
-                        show_problem_package(button,"'Crazy Chickens'");
-                        /* if not scuccess exit from wthout saving */
-                        break;
-                    }
-                }
 
-                /* Check Colorflood program */
-                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Colorflood")){
-                    if (access("/usr/bin/colorflood", F_OK) != 0){
-                        show_problem_package(button,"'Colorflood'");
-                        /* if not scuccess exit from wthout saving */
-                        break;
-                    }
+                if (priv->theme_string_parametr1){
+                    g_free(priv->theme_string_parametr1);
+                    priv->theme_string_parametr1 = NULL;
                 }
-#endif
+
                 if (priv->theme)
                     g_free(priv->theme);
                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
@@ -861,8 +900,6 @@ lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
                     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)));
                     }
                     temp_button = g_object_get_data(G_OBJECT(priv->window), "smoothing_button");
@@ -881,6 +918,22 @@ lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
                     }
                 }
+                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Slideshow"))){
+                       priv->theme = g_strdup("Slideshow");
+                       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)));
+                       }
+                       button2 = g_object_get_data(G_OBJECT(priv->window), "time_button");
+                       if (button2){
+                               //if (priv->theme_int_parametr1)
+                               //      g_free(priv->theme_int_parametr1);
+                        int_param = atoi(hildon_button_get_value (HILDON_BUTTON(button2)));
+                               priv->theme_int_parametr1 = int_param;
+                       }
+                }
                 /* Check external themes */
                 GSList *store = priv->extheme_list;
                 while (store){
@@ -932,7 +985,7 @@ lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
                     }
                     store = g_slist_next(store);
                 }
-
+                               fprintf(stderr, "theme = %s\n", priv->theme);
             }
 
             rich_animation_button = g_object_get_data(G_OBJECT(priv->window), "rich_animation_button");
@@ -981,7 +1034,7 @@ check_applet_state(gint number){
     GKeyFile *gkey_file = NULL;
     gchar *str = NULL;
     gboolean result = FALSE;
-    if (number > 4 || number < 1)
+    if (number > 9 || number < 1)
         return FALSE;
 
     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
@@ -1002,7 +1055,7 @@ start_applet(gint number){
     GKeyFile *gkey_file = NULL;
     gchar *str = NULL;
 
-    if (number > 4 || number < 1)
+    if (number > 9 || 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");
@@ -1025,7 +1078,7 @@ stop_applet(gint number){
     GKeyFile *gkey_file = NULL;
     gchar *str = NULL;
 
-    if (number > 4 || number < 1)
+    if (number > 9 || 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");