fixed additional string
[livewp] / applet / src / livewp-settings.c
index d661c40..30857e1 100644 (file)
@@ -66,7 +66,6 @@ create_category_selector (Animation_WallpaperPrivate *priv){
 
     selector = hildon_touch_selector_new_text();
 
-    hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "LiveWallpaper" );
 
     result_table = g_hash_table_new(g_str_hash, g_str_equal);
     while (store){
@@ -82,6 +81,11 @@ create_category_selector (Animation_WallpaperPrivate *priv){
             g_hash_table_insert(result_table, "Xscreensaver", (gint *)1);
             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "Xscreensaver");
     }
+    /* Add LiveWallpaper to selector */
+    if (!g_hash_table_lookup(result_table,"LiveWallpaper")){
+        hildon_touch_selector_prepend_text (HILDON_TOUCH_SELECTOR (selector), "LiveWallpaper" );
+    }
+
     return selector;
 }
 
@@ -175,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,
@@ -232,6 +236,10 @@ changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *
         if (!strcmp(choice, _("Video"))){
             additional_parametr_for_theme_video(vbox, priv);
         }
+        if (!strcmp(choice, _("Flash"))){
+            additional_parametr_for_theme_flash(vbox, priv);
+        }
+
     }
     gtk_widget_show(vbox);
 }
@@ -240,6 +248,10 @@ void
 changed_value_category_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
 {
     GtkWidget *theme_button = NULL;
+    GtkWidget *confirm;
+    gchar *text;
+
+
     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
 
     theme_button = g_object_get_data(G_OBJECT(priv->window), "theme_button");
@@ -253,9 +265,17 @@ changed_value_category_cb (HildonPickerButton *picker, Animation_WallpaperPrivat
     if (choice){
         if (!strcmp(choice,"Xscreensaver"))
             if (access("/usr/bin/xscreensaver", F_OK) != 0){
-                show_problem_package((GtkWidget *)picker, "Xscreensaver");
+                text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),  "Xscreensaver");
+                confirm = hildon_note_new_confirmation(GTK_WINDOW(priv->window), text);
+                if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))){
+                     gchar * cmd = g_strdup_printf("dbus-send --print-reply --dest=com.nokia.osso_browser /com/nokia/osso_browser/service com.nokia.osso_browser.open_new_window string:%s", "http://maemo.org/downloads/product/raw/Maemo5/xscreensaver/?get_installfile");
+                     fprintf(stderr, "system %s\n", cmd);
+                     system(cmd);
+                     g_free(cmd);
+                 }
+                 g_free(text);
+                 gtk_widget_destroy(confirm);
             }
-
     }
 }
 /********************************************************************************/
@@ -439,10 +459,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");
@@ -452,31 +474,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
@@ -485,8 +515,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;
@@ -500,38 +532,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:
@@ -546,10 +566,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)
@@ -560,10 +578,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);
@@ -601,9 +618,20 @@ rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *
 }
 /*******************************************************************************/
 void
+link_button_clicked(GtkButton *button, gchar *url){
+
+  gchar * cmd = g_strdup_printf("dbus-send --print-reply --dest=com.nokia.osso_browser \
+         /com/nokia/osso_browser/service com.nokia.osso_browser.open_new_window string:%s", url);
+  fprintf(stderr, "system %s\n", cmd);
+  system(cmd);
+  g_free(cmd);
+}
+/*******************************************************************************/
+void
 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
 
     GtkWidget *file_button;
+    GtkWidget *link_button;
     GtkWidget *smoothing_button;
     GtkWidget *rich_animation_button;
 
@@ -630,13 +658,46 @@ additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate
     gtk_box_pack_start(GTK_BOX(vbox),
                                    smoothing_button, TRUE, TRUE, 5);
     g_object_set_data(G_OBJECT(priv->window), "smoothing_button", smoothing_button);
+
+    link_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
+                                                   _("Press me for"), _("download more videos"));
+
+    g_signal_connect (link_button, "clicked", G_CALLBACK (link_button_clicked), "http://talk.maemo.org/showthread.php?t=60185");
+    gtk_box_pack_start(GTK_BOX(vbox),
+                                   link_button, TRUE, TRUE, 5);
+
     gtk_widget_show (smoothing_button);
     gtk_widget_show (file_button);
     gtk_widget_show (rich_animation_button);
+    gtk_widget_show (link_button);
 
 }
 /*******************************************************************************/
 void
+additional_parametr_for_theme_flash(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
+
+    GtkWidget *file_button;
+    GtkWidget *link_button;
+    GtkWidget *smoothing_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);
+    gtk_widget_show (file_button);
+}
+/*******************************************************************************/
+
+void
 show_problem_package (GtkWidget *widget, gchar *package_name){
     gchar *text;
     text = g_strdup_printf(_("You haven't got the installed package %s. Please install it via using Application Manager"), package_name);
@@ -667,8 +728,10 @@ lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
     GtkWidget *temp_button;
     GtkWidget *button1 = NULL;
     GtkWidget *rich_animation_button = NULL;
+    GtkWidget *confirm;
     gint view = priv->view;
     gint count;
+    gchar *text;
 
     window = gtk_dialog_new();
     priv->window = window;
@@ -781,6 +844,11 @@ lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
                     }
                 }
 #endif
+                if (priv->theme_string_parametr1){
+                    g_free(priv->theme_string_parametr1);
+                    priv->theme_string_parametr1 = NULL;
+                }
+
                 if (priv->theme)
                     g_free(priv->theme);
                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
@@ -795,8 +863,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");
@@ -807,6 +873,14 @@ lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
                             priv->theme_bool_parametr1 = FALSE;
                     }
                 }
+                if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Flash"))){
+                    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)));
+                    }
+                }
                 /* Check external themes */
                 GSList *store = priv->extheme_list;
                 while (store){
@@ -815,15 +889,28 @@ lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
                        gchar *check_path = g_hash_table_lookup(store->data, "check_path");
                        if (check_path){
                                if (access(check_path, F_OK) != 0){
-                                       show_problem_package(button, g_hash_table_lookup(store->data, "name"));
                                        gchar * install_file = g_hash_table_lookup(store->data, "install_file");
                                        if (install_file){
-                                               gchar * cmd = g_strdup_printf("dbus-send --print-reply --dest=com.nokia.osso_browser /com/nokia/osso_browser/service com.nokia.osso_browser.open_new_window string:%s",
-                                                                                                                                       install_file);
-                                               fprintf(stderr, "system %s\n", cmd);
-                                               system(cmd);
-                                               g_free(cmd);
-                                       }
+                                    if (g_hash_table_lookup(store->data, "associated_package"))
+                                        text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),
+                                                (gchar *) g_hash_table_lookup(store->data, "associated_package"));
+                                    else
+                                        text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),
+                                                (gchar *)g_hash_table_lookup(store->data, "name"));
+                                    confirm = hildon_note_new_confirmation(GTK_WINDOW(window), text);
+                                    if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))){
+                                        gchar * cmd = g_strdup_printf("dbus-send --print-reply --dest=com.nokia.osso_browser /com/nokia/osso_browser/service com.nokia.osso_browser.open_new_window string:%s", install_file);
+                                        fprintf(stderr, "system %s\n", cmd);
+                                        system(cmd);
+                                        g_free(cmd);
+                                    }
+                                    g_free(text);
+                                    gtk_widget_destroy(confirm);
+                                       }else
+                                    if (g_hash_table_lookup(store->data, "associated_package"))
+                                               show_problem_package(button, g_hash_table_lookup(store->data, "associated_package"));
+                                    else
+                                               show_problem_package(button, g_hash_table_lookup(store->data, "name"));
                                        /* if not success exit from without saving */
                                        break;
                                }
@@ -894,7 +981,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));
@@ -915,7 +1002,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");
@@ -938,7 +1025,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");