fixed additional string
[livewp] / applet / src / livewp-settings.c
1 /* vim: set sw=4 ts=4 et: */
2 /*
3  * This file is part of Live Wallpaper (livewp)
4  *
5  * Copyright (C) 2010 Vlad Vasiliev
6  * Copyright (C) 2010 Tanya Makova
7  *       for the code
8  *
9  * This software is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This software is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this software; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23 */
24 /*******************************************************************************/
25 #include "livewp-settings.h"
26 /*******************************************************************************/
27 void lw_about(void){
28
29     gchar *about_string;
30     GtkWidget *window = NULL,
31     *vbox = NULL,
32     *label_about = NULL;
33     window = gtk_dialog_new();
34     gtk_window_set_title(GTK_WINDOW(window), _("About"));
35     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
36     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
37     vbox = gtk_vbox_new (FALSE, 5);
38     about_string = g_strdup_printf(_("Live Wallpaper Version %s \n Copyright(c) 2010\n \
39 Tanya Makova\n Vlad Vasiliev\n \
40 Copyright(c) 2010 for design themes Berlin, Modern and Accel Vasya Bobrikov\n \
41 Copyright(c) 2010 for design themes Matrix, Fifteen \nand for icons Andrew Zhilin\n \
42 Translators:\n \
43 Finnish - Marko Vertainen\n \
44 Spain  - Alejandro López\n \
45 Italian  - Emanuele Cassioli\n \
46 Dutch - Roland van Tilburg (aka ROLAN900D) \n \
47 Russian - Tanya Makova \n \
48           Vlad Vasiliev\n"), VERSION);
49
50     label_about = gtk_label_new (about_string);
51     gtk_box_pack_start (GTK_BOX (vbox), label_about, FALSE, FALSE, 0);
52     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
53                                    vbox, TRUE, TRUE, 0);
54     gtk_widget_show (label_about);
55     gtk_widget_show (vbox);
56     gtk_widget_show (window);
57     gtk_dialog_run(GTK_DIALOG(window));
58
59 }
60 /*******************************************************************************/
61 GtkWidget *
62 create_category_selector (Animation_WallpaperPrivate *priv){
63     GtkWidget *selector;
64     GSList *store = priv->extheme_list;
65     GHashTable *result_table = NULL;
66
67     selector = hildon_touch_selector_new_text();
68
69
70     result_table = g_hash_table_new(g_str_hash, g_str_equal);
71     while (store){
72         if (!g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category"))){
73             g_hash_table_insert(result_table, g_hash_table_lookup(store->data, "category"), (gint *)1);
74             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), g_hash_table_lookup(store->data, "category"));
75         }
76         store = g_slist_next(store);
77     }
78
79     /* Add Xscreensaver for install message */
80     if (!g_hash_table_lookup(result_table,"Xscreensaver")){
81             g_hash_table_insert(result_table, "Xscreensaver", (gint *)1);
82             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "Xscreensaver");
83     }
84     /* Add LiveWallpaper to selector */
85     if (!g_hash_table_lookup(result_table,"LiveWallpaper")){
86         hildon_touch_selector_prepend_text (HILDON_TOUCH_SELECTOR (selector), "LiveWallpaper" );
87     }
88
89     return selector;
90 }
91
92 /*******************************************************************************/
93 void
94 theme_button_clicked(GtkWidget *button, GdkEventButton *event, Animation_WallpaperPrivate *priv){
95     lw_theme_settings(GTK_WIDGET(button), priv);
96 }
97 /********************************************************************************/
98 void
99 set_button_image(GtkWidget * button, Animation_WallpaperPrivate *priv, gboolean enable){
100     GtkWidget * image = NULL;
101     GdkPixbuf * pixbuf = NULL;
102     gchar *str = NULL;
103     gchar *icon_on = NULL;
104     gchar *icon_off = NULL;
105     GSList *store = priv->extheme_list;
106
107     while (store){
108         if (!strcmp(priv->theme, g_hash_table_lookup(store->data, "name"))){
109             icon_on = g_strdup(g_hash_table_lookup(store->data, "icon_on"));
110             icon_off = g_strdup(g_hash_table_lookup(store->data, "icon_off"));
111             break;
112         }
113         store = (GSList *)g_list_next(store);
114     }
115     if (enable){
116         if (icon_on)
117             str = g_strdup_printf("%s", icon_on);
118         else
119             str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
120                             priv->theme, "icon.png");
121             if (access(str, F_OK) != 0){
122                 g_free(str);
123                 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
124                             "Video", "icon.png");
125             }
126
127     }else {
128         if (icon_off)
129             str = g_strdup_printf("%s", icon_off);
130         else
131             str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
132                             priv->theme, "icond.png");
133             if (access(str, F_OK) != 0){
134                 g_free(str);
135                 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
136                             "Video", "icond.png");
137             }
138     }
139     pixbuf = gdk_pixbuf_new_from_file_at_size (str,
140                                                  124,
141                                                  79,
142                                                  NULL);
143     if (str)
144         g_free(str);
145     if (icon_on)
146         g_free(icon_on);
147     if (icon_off)
148         g_free(icon_off);
149     if (pixbuf){
150         image = gtk_image_new_from_pixbuf (pixbuf);
151         g_object_unref(G_OBJECT(pixbuf));
152     }
153
154     //hildon_button_set_image (HILDON_BUTTON (button), image);
155     GList *list = gtk_container_get_children(GTK_CONTAINER (button));
156     if (list){
157         gtk_container_remove(GTK_CONTAINER (button), list->data);
158     }
159     gtk_container_add(GTK_CONTAINER (button), image);
160     gtk_widget_show(image);
161     gtk_widget_show(button);
162
163 }
164 /********************************************************************************/
165 GtkWidget *
166 create_image_button (gint view, DBusConnection *conn_sess){
167     GtkWidget *event_box;
168
169     Animation_WallpaperPrivate *priv = g_new0(Animation_WallpaperPrivate, 1);
170     /* Add external themes to priv */
171     priv->extheme_list = get_list_exthemes();
172
173     priv->view = view;
174     priv->theme_string_parametr1 = NULL;
175     priv->dbus_conn_session = conn_sess;
176     read_config(priv);
177
178     event_box = gtk_event_box_new();
179     g_object_set_data(G_OBJECT(event_box), "view", GINT_TO_POINTER(view));
180     g_object_set_data(G_OBJECT(event_box), "priv", priv);
181     set_button_image(event_box, priv, check_applet_state(view));
182     g_signal_connect(G_OBJECT (event_box), "button_release_event", G_CALLBACK(theme_button_clicked), priv);
183     return event_box;
184 #if 0
185     button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
186                                     HILDON_BUTTON_ARRANGEMENT_VERTICAL);
187     g_object_set_data(G_OBJECT(button), "view", GINT_TO_POINTER(view));
188     g_object_set_data(G_OBJECT(button), "priv", priv);
189     set_button_image(button, priv, check_applet_state(view));
190     g_signal_connect(button, "clicked", G_CALLBACK(theme_button_clicked), priv);
191     hildon_button_set_image_position (HILDON_BUTTON (button), GTK_POS_RIGHT);
192     return button;
193 #endif
194 }
195 /********************************************************************************/
196 void
197 changed_value_one_in_all_cb (GtkWidget *toggle, Animation_WallpaperPrivate *priv)
198 {
199     priv->one_in_all_view = hildon_check_button_get_active((HildonCheckButton *)toggle);
200     create_themes_buttons_hbox(priv);
201     fprintf(stderr, "changed_value_one_in_all_cb\n");
202 }
203 /********************************************************************************/
204 void
205 changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
206 {
207     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
208     GtkWidget *vbox = NULL;
209     GtkWidget *area_vbox = NULL;
210
211     area_vbox = g_object_get_data(G_OBJECT(priv->window), "area_vbox");
212     if (!area_vbox)
213         return;
214     vbox = g_object_get_data(G_OBJECT(priv->window), "custom_vbox");
215     if (vbox){
216         gtk_widget_destroy(vbox);
217     }
218     vbox = gtk_vbox_new (TRUE, 5);
219     g_object_set_data(G_OBJECT(priv->window), "custom_vbox", vbox);
220     gtk_box_pack_start(GTK_BOX(area_vbox),
221                                    vbox, FALSE, FALSE, 5);
222     if (choice) {
223         if (!strcmp(choice, _("Berlin"))){
224             rich_animation_additional_parametr(vbox,priv);
225         }
226         if (!strcmp(choice, _("Modern"))){
227             rich_animation_additional_parametr(vbox,priv);
228         }
229         if (!strcmp(choice, _("Matrix"))){
230             rich_animation_additional_parametr(vbox,priv);
231         }
232
233         if (!strcmp(choice, _("Accel"))){
234             rich_animation_additional_parametr(vbox,priv);
235         }
236         if (!strcmp(choice, _("Video"))){
237             additional_parametr_for_theme_video(vbox, priv);
238         }
239         if (!strcmp(choice, _("Flash"))){
240             additional_parametr_for_theme_flash(vbox, priv);
241         }
242
243     }
244     gtk_widget_show(vbox);
245 }
246 /********************************************************************************/
247 void
248 changed_value_category_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
249 {
250     GtkWidget *theme_button = NULL;
251     GtkWidget *confirm;
252     gchar *text;
253
254
255     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
256
257     theme_button = g_object_get_data(G_OBJECT(priv->window), "theme_button");
258     if (!theme_button)
259         return;
260     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) theme_button);
261     hildon_touch_selector_remove_column(selector, 0);
262     hildon_touch_selector_append_text_column(selector, (GtkTreeModel*)gtk_list_store_new (1, G_TYPE_STRING), TRUE);
263     fill_theme_button(priv, theme_button, (gchar *)hildon_button_get_value(HILDON_BUTTON (picker)));
264     /* check xscreensaver category */
265     if (choice){
266         if (!strcmp(choice,"Xscreensaver"))
267             if (access("/usr/bin/xscreensaver", F_OK) != 0){
268                 text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),  "Xscreensaver");
269                 confirm = hildon_note_new_confirmation(GTK_WINDOW(priv->window), text);
270                 if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))){
271                      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");
272                      fprintf(stderr, "system %s\n", cmd);
273                      system(cmd);
274                      g_free(cmd);
275                  }
276                  g_free(text);
277                  gtk_widget_destroy(confirm);
278             }
279     }
280 }
281 /********************************************************************************/
282 void
283 fill_theme_button (Animation_WallpaperPrivate *priv, GtkWidget *button, gchar *category){
284
285     gchar *theme = priv->theme;
286     gboolean flag = False;
287     gint num=0;
288         hildon_button_set_value(HILDON_BUTTON (button), NULL);
289     if (!category){
290         changed_value_theme_cb(HILDON_PICKER_BUTTON (button), priv);
291         return;
292     }
293     GSList *store = priv->extheme_list;
294     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) button);
295     if (!selector)
296         selector = (HildonTouchSelector *)hildon_touch_selector_new_text ();
297
298     hildon_button_set_value(HILDON_BUTTON(button), NULL);
299     if (!strcmp(category, "LiveWallpaper")){
300         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Berlin"));
301         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Modern"));
302         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Matrix"));
303         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Accel"));
304         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Video"));
305         num = 5;
306         if (theme){
307             if (!strcmp(theme, "Berlin")){
308                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
309                 hildon_button_set_value(HILDON_BUTTON(button), _("Berlin"));
310             }
311             if (!strcmp(theme, "Modern")){
312                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 1);
313                 hildon_button_set_value(HILDON_BUTTON(button), _("Modern"));
314             }
315             if (!strcmp(theme, "Matrix")){
316                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 2);
317                 hildon_button_set_value(HILDON_BUTTON(button), _("Matrix"));
318             }
319             if (!strcmp(theme, "Accel")){
320                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 3);
321                 hildon_button_set_value(HILDON_BUTTON(button), _("Accel"));
322             }
323             if (!strcmp(theme, "Video")){
324                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 4);
325                 hildon_button_set_value(HILDON_BUTTON(button), _("Video"));
326             }
327        }
328     }
329     while (store){
330         if (!g_hash_table_lookup(store->data, "category"))
331             continue;
332         if (!strcmp(g_hash_table_lookup(store->data, "category"), category)){
333             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), g_hash_table_lookup(store->data, "name"));
334             if (!strcmp(theme, g_hash_table_lookup(store->data, "name"))){
335                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, num);
336                 hildon_button_set_value(HILDON_BUTTON(button), _(g_hash_table_lookup(store->data, "name")));
337             }
338             num++;
339         }
340         store = g_slist_next(store);
341     }
342     /* Added Shreman's Aquarium for message */
343     if (!strcmp(category, "Unknown")){
344         store = priv->extheme_list;
345         while (store){
346             if (!strcmp("Shermans Aquarium" , g_hash_table_lookup(store->data, "name"))){
347                 flag = TRUE;
348                 break;
349             }
350             store = g_slist_next(store);
351         }
352         if (!flag)
353             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "Shermans Aquarium");
354     }
355
356         hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
357                                                        HILDON_TOUCH_SELECTOR (selector));
358
359     changed_value_theme_cb(HILDON_PICKER_BUTTON (button), priv);
360 }
361 /********************************************************************************/
362 GtkWidget *
363 create_themes_button (Animation_WallpaperPrivate *priv, gchar *category){
364
365     GtkWidget *button;
366     button = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
367     hildon_button_set_title (HILDON_BUTTON (button), _("Theme"));
368
369
370     return button;
371 }
372 /********************************************************************************/
373 GtkWidget *
374 create_categories_button (Animation_WallpaperPrivate *priv){
375
376     GtkWidget *button;
377     GtkWidget *selector;
378     gchar *theme = priv->theme;
379     gint num=0;
380     GHashTable *result_table = NULL;
381
382     result_table = g_hash_table_new(g_str_hash, g_str_equal);
383     selector = create_category_selector(priv);
384     button = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
385     hildon_button_set_title (HILDON_BUTTON (button), _("Category"));
386     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
387                                                        HILDON_TOUCH_SELECTOR (selector));
388     if (theme) {
389         if (!strcmp(theme, "Berlin")){
390             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
391             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
392         }
393         if (!strcmp(theme, "Modern")){
394             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
395             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
396         }
397         if (!strcmp(theme, "Matrix")){
398             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
399             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
400         }
401         if (!strcmp(theme, "Accel")){
402             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
403             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
404         }
405         if (!strcmp(theme, "Video")){
406             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
407             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
408         }
409         GSList *store = priv->extheme_list;
410         num = 1;
411         while (store){
412             if (g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category")) == NULL){
413                 g_hash_table_insert(result_table, g_hash_table_lookup(store->data, "category"), (gint *)num);
414                 num++;
415             }
416             if (!strcmp(theme, g_hash_table_lookup(store->data, "name"))){
417                 if (g_hash_table_lookup(store->data, "category")){
418                     hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0,
419                     (gint)g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category")));
420                     hildon_button_set_value(HILDON_BUTTON(button), g_hash_table_lookup(store->data, "category"));
421                 }
422                 break;
423             }
424
425             store = g_slist_next(store);
426         }
427     }
428     return button;
429 }
430
431 /*******************************************************************************/
432 GtkWidget *
433 create_bool_button (gboolean active, gchar *name)
434 {
435     GtkWidget *button;
436     button = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
437     gtk_button_set_label (GTK_BUTTON (button), name);
438     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
439     return button;
440 }
441 /*******************************************************************************/
442 GtkWidget *
443 create_enable_button (gboolean active)
444 {
445     GtkWidget *button;
446     button = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
447     gtk_button_set_label (GTK_BUTTON (button), _("Enable"));
448     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
449     return button;
450 }
451
452 /*******************************************************************************/
453 void
454 show_settings(GtkWidget *widget, Animation_WallpaperPrivate *priv){
455     lw_main_settings(priv, NULL);
456 }
457 /*******************************************************************************/
458 void
459 create_themes_buttons_hbox(Animation_WallpaperPrivate *priv){
460     GtkWidget *hbox = NULL;
461     GtkWidget *area_hbox = NULL;
462     GtkWidget *theme_button;
463     GSList *stlist = NULL;
464     GConfClient *gconf_client = NULL;
465     GConfValue *value = NULL;
466     guint count_of_view = 1; 
467     guint i;
468
469
470     area_hbox = g_object_get_data(G_OBJECT(priv->window), "area_hbox");
471     if (!area_hbox)
472         return;
473     hbox = g_object_get_data(G_OBJECT(priv->window), "custom_hbox");
474     if (hbox){
475         gtk_widget_destroy(hbox);
476     }
477    
478     hbox = gtk_hbox_new(FALSE, 0);
479     g_object_set_data(G_OBJECT(priv->window), "custom_hbox", hbox);
480     gtk_box_pack_start(GTK_BOX(area_hbox),
481                                    hbox, FALSE, FALSE, 5);
482     /* Create Theme buttons */
483     theme_button = create_image_button(1, priv->dbus_conn_session);
484     gtk_box_pack_start(GTK_BOX(hbox),
485                                    theme_button, TRUE, TRUE, 10);
486     gtk_widget_show (theme_button);
487     gtk_widget_show (hbox);
488     if (priv->one_in_all_view)
489         return;
490
491     gconf_client = gconf_client_get_default();
492     if (!gconf_client)
493         return;
494
495     stlist = gconf_client_get_list(gconf_client,
496                                        "/apps/osso/hildon-desktop/views/active",
497                                        GCONF_VALUE_INT, NULL);
498     if (stlist){
499         count_of_view = g_slist_length(stlist);
500         g_slist_free(stlist);
501     }else
502         count_of_view = 4;
503     g_object_unref(gconf_client);
504     for (i = 2; i < count_of_view + 1; i++){
505         theme_button = create_image_button(i, priv->dbus_conn_session);
506         gtk_box_pack_start(GTK_BOX(hbox),
507                                    theme_button, TRUE, TRUE, 10);
508         gtk_widget_show (theme_button);
509     } 
510 }
511 /*******************************************************************************/
512 void
513 lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
514     gint result;
515     GtkWidget *window = NULL;
516     GtkWidget *banner = NULL;
517     GtkWidget *area_hbox;
518     GtkWidget *scrolled_window;
519     GtkWidget *one_in_all_view_button;
520     gboolean one_in_all_view;
521     gint i;
522
523     window = gtk_dialog_new();
524     priv->window = window;
525
526     one_in_all_view = priv->one_in_all_view;
527     gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
528     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
529     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
530     one_in_all_view_button = create_bool_button(priv->one_in_all_view, _("One theme in all views"));
531     g_signal_connect (G_OBJECT (one_in_all_view_button), "toggled",  G_CALLBACK (changed_value_one_in_all_cb), priv);
532     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), one_in_all_view_button, TRUE, TRUE, 5);
533     area_hbox = gtk_vbox_new(FALSE, 2);
534     g_object_set_data(G_OBJECT(window), "area_hbox", area_hbox);
535
536     create_themes_buttons_hbox(priv);
537     scrolled_window = hildon_pannable_area_new ();
538     g_object_set (G_OBJECT (scrolled_window), "mov-mode", HILDON_MOVEMENT_MODE_HORIZ, NULL);
539     g_object_set (G_OBJECT (scrolled_window), "hscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
540     g_object_set (G_OBJECT (scrolled_window), "scrollbar-fade-delay", 27000, NULL);
541     g_object_set (G_OBJECT (scrolled_window), "indicator-width", 28, NULL);
542     gtk_widget_set_size_request(scrolled_window, -1, 120);
543     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (scrolled_window), GTK_WIDGET (area_hbox));
544
545     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
546                                    scrolled_window, TRUE, TRUE, 0);
547
548     gtk_widget_show(scrolled_window);
549     gtk_widget_show(one_in_all_view_button);
550     gtk_widget_show_all(area_hbox);
551     gtk_widget_show(window);
552     gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
553
554     result = gtk_dialog_run(GTK_DIALOG(window));
555
556     switch(result){
557         case GTK_RESPONSE_NO:
558             gtk_widget_destroy(window);
559             window = NULL;
560             lw_about();
561         break;
562     }
563
564     if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(one_in_all_view_button)) != one_in_all_view){
565         save_one_in_all_views_to_config(hildon_check_button_get_active (HILDON_CHECK_BUTTON(one_in_all_view_button)));
566         //fprintf(stderr,"CHECK!!!!!!!!!!!!!!\n");
567         banner = hildon_banner_show_information (window, NULL, _("Livewallpaper is reloading..."));
568         hildon_banner_set_timeout(HILDON_BANNER(banner), 3000);
569         for (i=1;i<10;i++)
570             stop_applet(i);
571         g_timeout_add(3000, (GSourceFunc)cb_timeout_settings, window);
572     }else{
573         if (window)
574             gtk_widget_destroy(window);
575     }
576 }
577 /*******************************************************************************/
578 gboolean
579 cb_timeout_settings(GtkWidget *window){
580
581     gint i;
582     for (i=1;i<10;i++)
583         start_applet(i);
584
585     if (window)
586         gtk_widget_destroy(window);
587     return FALSE;
588 }
589 /*******************************************************************************/
590 void
591 file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
592
593     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
594
595     if (priv->theme_string_parametr1)
596         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
597
598     gtk_widget_show_all (GTK_WIDGET (dialog));
599
600     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
601     {
602       hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
603     }
604     gtk_widget_destroy (dialog);
605
606 }
607 /*******************************************************************************/
608 void
609 rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
610     GtkWidget *rich_animation_button;
611
612     /* Create rich animation button */
613     rich_animation_button = create_bool_button(priv->rich_animation, _("Rich Animation"));
614     gtk_box_pack_start(GTK_BOX(vbox),
615                                    rich_animation_button, TRUE, TRUE, 5);
616     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
617     gtk_widget_show (rich_animation_button);
618 }
619 /*******************************************************************************/
620 void
621 link_button_clicked(GtkButton *button, gchar *url){
622
623   gchar * cmd = g_strdup_printf("dbus-send --print-reply --dest=com.nokia.osso_browser \
624          /com/nokia/osso_browser/service com.nokia.osso_browser.open_new_window string:%s", url);
625   fprintf(stderr, "system %s\n", cmd);
626   system(cmd);
627   g_free(cmd);
628 }
629 /*******************************************************************************/
630 void
631 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
632
633     GtkWidget *file_button;
634     GtkWidget *link_button;
635     GtkWidget *smoothing_button;
636     GtkWidget *rich_animation_button;
637
638     if (priv->theme_string_parametr1)
639         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
640                                                    _("Play file"), priv->theme_string_parametr1);
641     else
642         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
643                                                    _("Play file")," ");
644
645     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
646
647     gtk_box_pack_start(GTK_BOX(vbox),
648                                    file_button, TRUE, TRUE, 5);
649     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);
650     /* Create rich animation button */
651     rich_animation_button = create_bool_button(priv->rich_animation, _("Loop"));
652     gtk_box_pack_start(GTK_BOX(vbox),
653                                    rich_animation_button, TRUE, TRUE, 5);
654     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
655     /* Create Smoothing button */
656
657     smoothing_button = create_bool_button(priv->theme_bool_parametr1, _("Smoothing (Need more memory)"));
658     gtk_box_pack_start(GTK_BOX(vbox),
659                                    smoothing_button, TRUE, TRUE, 5);
660     g_object_set_data(G_OBJECT(priv->window), "smoothing_button", smoothing_button);
661
662     link_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
663                                                    _("Press me for"), _("download more videos"));
664
665     g_signal_connect (link_button, "clicked", G_CALLBACK (link_button_clicked), "http://talk.maemo.org/showthread.php?t=60185");
666     gtk_box_pack_start(GTK_BOX(vbox),
667                                    link_button, TRUE, TRUE, 5);
668
669     gtk_widget_show (smoothing_button);
670     gtk_widget_show (file_button);
671     gtk_widget_show (rich_animation_button);
672     gtk_widget_show (link_button);
673
674 }
675 /*******************************************************************************/
676 void
677 additional_parametr_for_theme_flash(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
678
679     GtkWidget *file_button;
680     GtkWidget *link_button;
681     GtkWidget *smoothing_button;
682     GtkWidget *rich_animation_button;
683
684     if (priv->theme_string_parametr1)
685         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
686                                                    _("Play file"), priv->theme_string_parametr1);
687     else
688         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
689                                                    _("Play file")," ");
690
691     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
692
693     gtk_box_pack_start(GTK_BOX(vbox),
694                                    file_button, TRUE, TRUE, 5);
695     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);
696     gtk_widget_show (file_button);
697 }
698 /*******************************************************************************/
699
700 void
701 show_problem_package (GtkWidget *widget, gchar *package_name){
702     gchar *text;
703     text = g_strdup_printf(_("You haven't got the installed package %s. Please install it via using Application Manager"), package_name);
704     hildon_banner_show_information(GTK_WIDGET(widget), NULL, text);
705     g_free(text);
706 }
707 /*******************************************************************************/
708 void
709 show_duplicate_theme (GtkWidget *widget, gchar *theme_name){
710     gchar *text;
711     text = g_strdup_printf(_("Theme %s has already been selected"), theme_name);
712     hildon_banner_show_information(GTK_WIDGET(widget), NULL, text);
713     g_free(text);
714 }
715
716 /*******************************************************************************/
717 void
718 lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
719     gint result;
720     GtkWidget *window = NULL;
721     GtkWidget *scrolled_window = NULL;
722     GtkWidget *save_button;
723     GtkWidget *theme_button;
724     GtkWidget *category_button;
725     GtkWidget *enable_button;
726     GtkWidget *vbox;
727     GtkWidget *area_vbox;
728     GtkWidget *temp_button;
729     GtkWidget *button1 = NULL;
730     GtkWidget *rich_animation_button = NULL;
731     GtkWidget *confirm;
732     gint view = priv->view;
733     gint count;
734     gchar *text;
735
736     window = gtk_dialog_new();
737     priv->window = window;
738
739     gtk_window_set_title(GTK_WINDOW(window), _("View Settings"));
740     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
741     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
742
743     /* Create panarea */
744     area_vbox = gtk_vbox_new(FALSE, 2);
745     g_object_set_data(G_OBJECT(window), "area_vbox", area_vbox);
746     scrolled_window = hildon_pannable_area_new ();
747     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (scrolled_window), GTK_WIDGET (area_vbox));
748     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
749                                    scrolled_window, FALSE, FALSE, 0);
750
751     gtk_widget_set_size_request(scrolled_window, -1, 370);
752
753     /* Create Enable button */
754     enable_button = create_enable_button(check_applet_state(view));
755     gtk_box_pack_start(GTK_BOX(area_vbox),
756                                    enable_button, FALSE, FALSE, 5);
757     /* Create Category button */
758     category_button = create_categories_button(priv);
759     g_object_set_data(G_OBJECT(window), "category_button", category_button);
760     g_signal_connect (G_OBJECT (category_button), "value-changed",  G_CALLBACK (changed_value_category_cb), priv);
761     gtk_box_pack_start(GTK_BOX(area_vbox),
762                                    category_button, FALSE, FALSE, 5);
763     /* Create Custom vbox */
764     vbox = gtk_vbox_new (FALSE, 5);
765     g_object_set_data(G_OBJECT(window), "custom_vbox", vbox);
766
767     /* Create Theme button */
768     theme_button = create_themes_button(priv, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
769     g_object_set_data(G_OBJECT(window), "theme_button", theme_button);
770     g_signal_connect (G_OBJECT (theme_button), "value-changed",  G_CALLBACK (changed_value_theme_cb), priv);
771     gtk_box_pack_start(GTK_BOX(area_vbox),
772                                    theme_button, FALSE, FALSE, 5);
773     fill_theme_button(priv, theme_button, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
774
775     /* Pack custom vbox. It must be last widget */
776     gtk_box_pack_start(GTK_BOX(area_vbox),
777                                    vbox, FALSE, FALSE, 5);
778
779     gtk_widget_show (enable_button);
780     gtk_widget_show (category_button);
781     gtk_widget_show (theme_button);
782     gtk_widget_show (vbox);
783     gtk_widget_show (area_vbox);
784     gtk_widget_show (scrolled_window);
785     gtk_widget_show (window);
786
787     save_button = gtk_dialog_add_button(GTK_DIALOG(window), _("Save"), GTK_RESPONSE_YES);
788
789     result = gtk_dialog_run(GTK_DIALOG(window));
790
791     switch(result){
792         case GTK_RESPONSE_YES:
793             /* Check theme */
794             if (hildon_button_get_value(HILDON_BUTTON (theme_button)) &&
795                 strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "")){
796 #if 0
797                 /* Check Xsnow program */
798                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Xsnow"))){
799                     if (access("/usr/bin/xsnow", F_OK) != 0){
800                         show_problem_package(button, "Xsnow");
801                         /* if not scuccess exit from wthout saving */
802                         break;
803                     }
804                 }
805                 /* Check Shermans program */
806                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Shermans Aquarium")){
807                     if (access("/usr/bin/shermans", F_OK) != 0){
808                         show_problem_package(button,"'Sherman's Aquarium'");
809                         /* if not scuccess exit from wthout saving */
810                         break;
811                     }
812                 }
813                 /* Check Conky program */
814                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Conky")){
815                     if (access("/usr/bin/conky", F_OK) != 0){
816                         show_problem_package(button,"'Conky'");
817                         /* if not scuccess exit from wthout saving */
818                         break;
819                     }
820                 }
821                 /* Check Orrery program */
822                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Orrery")){
823                     if (access("/opt/maemo/usr/bin/orrery", F_OK) != 0){
824                         show_problem_package(button,"'Orrery'");
825                         /* if not scuccess exit from wthout saving */
826                         break;
827                     }
828                 }
829                 /* Check CrazyChickens program */
830                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "CrazyChickens")){
831                     if (access("/usr/bin/crazychickens", F_OK) != 0){
832                         show_problem_package(button,"'Crazy Chickens'");
833                         /* if not scuccess exit from wthout saving */
834                         break;
835                     }
836                 }
837
838                 /* Check Colorflood program */
839                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Colorflood")){
840                     if (access("/usr/bin/colorflood", F_OK) != 0){
841                         show_problem_package(button,"'Colorflood'");
842                         /* if not scuccess exit from wthout saving */
843                         break;
844                     }
845                 }
846 #endif
847                 if (priv->theme_string_parametr1){
848                     g_free(priv->theme_string_parametr1);
849                     priv->theme_string_parametr1 = NULL;
850                 }
851
852                 if (priv->theme)
853                     g_free(priv->theme);
854                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
855                     priv->theme = g_strdup("Berlin");
856                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern")))
857                     priv->theme = g_strdup("Modern");
858                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix")))
859                     priv->theme = g_strdup("Matrix");
860                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel")))
861                     priv->theme = g_strdup("Accel");
862                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
863                     priv->theme = g_strdup("Video");
864                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
865                     if (button1){
866                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
867                     }
868                     temp_button = g_object_get_data(G_OBJECT(priv->window), "smoothing_button");
869                     if (temp_button){
870                         if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(temp_button)))
871                             priv->theme_bool_parametr1 = TRUE;
872                         else
873                             priv->theme_bool_parametr1 = FALSE;
874                     }
875                 }
876                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Flash"))){
877                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
878                     if (button1){
879                         if (priv->theme_string_parametr1)
880                             g_free(priv->theme_string_parametr1);
881                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
882                     }
883                 }
884                 /* Check external themes */
885                 GSList *store = priv->extheme_list;
886                 while (store){
887                     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _(g_hash_table_lookup(store->data, "name")))){
888                         //check if theme installed
889                         gchar *check_path = g_hash_table_lookup(store->data, "check_path");
890                         if (check_path){
891                                 if (access(check_path, F_OK) != 0){
892                                         gchar * install_file = g_hash_table_lookup(store->data, "install_file");
893                                         if (install_file){
894                                     if (g_hash_table_lookup(store->data, "associated_package"))
895                                         text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),
896                                                 (gchar *) g_hash_table_lookup(store->data, "associated_package"));
897                                     else
898                                         text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),
899                                                 (gchar *)g_hash_table_lookup(store->data, "name"));
900                                     confirm = hildon_note_new_confirmation(GTK_WINDOW(window), text);
901                                     if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))){
902                                         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);
903                                         fprintf(stderr, "system %s\n", cmd);
904                                         system(cmd);
905                                         g_free(cmd);
906                                     }
907                                     g_free(text);
908                                     gtk_widget_destroy(confirm);
909                                         }else
910                                     if (g_hash_table_lookup(store->data, "associated_package"))
911                                                 show_problem_package(button, g_hash_table_lookup(store->data, "associated_package"));
912                                     else
913                                                 show_problem_package(button, g_hash_table_lookup(store->data, "name"));
914                                         /* if not success exit from without saving */
915                                         break;
916                                 }
917                         }
918
919
920                         //check if theme already selected
921                         gchar *copies = g_hash_table_lookup(store->data, "copies");
922                         //fprintf(stderr, "copies = %s\n", copies);
923                         if (copies){
924                             count = atoi(copies);
925                         }else count = 10;
926                         if (count > get_count_themes_from_config(g_hash_table_lookup(store->data, "name")))
927                             priv->theme = g_strdup(g_hash_table_lookup(store->data, "name"));
928                         else
929                             show_duplicate_theme(button, g_hash_table_lookup(store->data, "name"));
930                         //priv->hash_theme = store->data;
931                         break;
932                     }
933                     store = g_slist_next(store);
934                 }
935
936             }
937
938             rich_animation_button = g_object_get_data(G_OBJECT(priv->window), "rich_animation_button");
939             if (rich_animation_button){
940                 /* Check rich animation */
941                 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(rich_animation_button)))
942                     priv->rich_animation = TRUE;
943                 else
944                     priv->rich_animation = FALSE;
945             }
946             /* Save config */
947             save_config(priv);
948             /* action with applet */
949             if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(enable_button))){
950                     if (!check_applet_state(view)){
951                         start_applet(view);
952                     }else {
953                         send_dbus_signal (priv,
954                               LIVEWP_SIGNAL_INTERFACE,
955                               LIVEWP_SIGNAL_PATH,
956                               LIVEWP_RELOAD_CONFIG);
957                     }
958             }else
959                     if (check_applet_state(view))
960                         stop_applet(view);
961
962             set_button_image(button, priv, check_applet_state(view));
963             break;
964         default:
965         case GTK_RESPONSE_OK:
966         break;
967         case GTK_RESPONSE_NO:
968             gtk_widget_destroy(window);
969             window = NULL;
970             lw_about();
971         break;
972     }
973     if (window)
974         gtk_widget_destroy(window);
975 }
976 /*******************************************************************************/
977 gboolean
978 check_applet_state(gint number){
979
980     HDConfigFile *config_file = NULL;
981     GKeyFile *gkey_file = NULL;
982     gchar *str = NULL;
983     gboolean result = FALSE;
984     if (number > 9 || number < 1)
985         return FALSE;
986
987     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
988     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
989
990     gkey_file = hd_config_file_load_file(config_file, FALSE);
991     if (gkey_file && str){
992         result = g_key_file_has_group(gkey_file, str);
993         g_free(str);
994     }
995     return result;
996 }
997 /*******************************************************************************/
998 void
999 start_applet(gint number){
1000
1001     HDConfigFile *config_file = NULL;
1002     GKeyFile *gkey_file = NULL;
1003     gchar *str = NULL;
1004
1005     if (number > 9 || number < 1)
1006         return;
1007     str = g_strdup_printf("livewp-home-widget.desktop-%i",(number - 1));
1008     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
1009
1010     gkey_file = hd_config_file_load_file(config_file, FALSE);
1011     if (gkey_file){
1012         g_key_file_set_string (gkey_file, str, "X-Desktop-File", "/usr/share/applications/hildon-home/livewp-home-widget.desktop");
1013         hd_config_file_save_file( config_file, gkey_file);
1014         g_key_file_free(gkey_file);
1015     }else
1016         fprintf(stderr, "Problem with config file");
1017     if (str)
1018         g_free(str);
1019     g_object_unref(config_file);
1020 }
1021 /*******************************************************************************/
1022 void
1023 stop_applet(gint number){
1024     HDConfigFile *config_file = NULL;
1025     GKeyFile *gkey_file = NULL;
1026     gchar *str = NULL;
1027
1028     if (number > 9 || number < 1)
1029         return;
1030     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
1031     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
1032
1033     gkey_file = hd_config_file_load_file(config_file, FALSE);
1034     if (gkey_file){
1035          g_key_file_remove_group(gkey_file, str, NULL);
1036         hd_config_file_save_file( config_file, gkey_file);
1037         g_key_file_free(gkey_file);
1038     }else
1039         fprintf(stderr, "Problem with config file");
1040     if (str)
1041         g_free(str);
1042     g_object_unref(config_file);
1043
1044 }