Begiun theme conky
[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 Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1 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     GtkWidget *window = NULL,
30     *vbox = NULL,
31     *label_about = NULL;
32     window = gtk_dialog_new();
33     gtk_window_set_title(GTK_WINDOW(window), _("About"));
34     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
35     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
36     vbox = gtk_vbox_new (FALSE, 5);
37     label_about = gtk_label_new (_("Live Wallpaper Version 0.8.6 \n Copyright(c) 2010\n \
38 Tanya Makova\n Vlad Vasiliev\n \
39 Copyright(c) 2010 for design themes Berlin, Modern and Accel Vasya Bobrikov\n \
40 Copyright(c) 2010 for design theme Matrix and icons Andrew Zhilin\n \
41 Translators:\n \
42 Finnish - Marko Vertainen\n \
43 Spain  - Alejandro López\n \
44 Russian - Tanya Makova \n \
45           Vlad Vasiliev\n")); 
46     gtk_box_pack_start (GTK_BOX (vbox), label_about, FALSE, FALSE, 0);
47     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
48                                    vbox, TRUE, TRUE, 0);
49     gtk_widget_show (label_about);
50     gtk_widget_show (vbox);
51     gtk_widget_show (window);
52     gtk_dialog_run(GTK_DIALOG(window));
53
54 }
55 /*******************************************************************************/
56 GtkWidget *
57 create_category_selector (Animation_WallpaperPrivate *priv){
58     GtkWidget *selector;
59     GSList *store = priv->extheme_list;
60     GList *category_list;
61     GHashTable *result_table = NULL;
62
63     result_table = g_hash_table_new(g_str_hash, g_str_equal);
64     while (store){  
65         if (!g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category")))
66             g_hash_table_insert(result_table, g_hash_table_lookup(store->data, "category"), (gint *)1);     
67         store = g_slist_next(store);
68     }
69     
70     /* Add Xscreensaver for install message */
71     if (!g_hash_table_lookup(result_table,"Xscreensaver"))
72             g_hash_table_insert(result_table, "Xscreensaver", (gint *)1);
73    
74
75     category_list = g_hash_table_get_keys (result_table);
76     selector = hildon_touch_selector_new_text();
77
78     hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "LiveWallpaper" );
79     while (category_list){  
80         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),category_list->data );
81         category_list = g_list_next(category_list);
82     }
83
84     return selector;
85 }
86
87 /*******************************************************************************/
88 void
89 theme_button_clicked(GtkWidget *button, GdkEventButton *event, Animation_WallpaperPrivate *priv){
90     lw_theme_settings(GTK_WIDGET(button), priv);
91 }
92 /********************************************************************************/
93 void
94 set_button_image(GtkWidget * button, Animation_WallpaperPrivate *priv, gboolean enable){
95     GtkWidget * image = NULL; 
96     GdkPixbuf * pixbuf = NULL;
97     gchar *str = NULL;
98     gchar *icon_on = NULL;
99     gchar *icon_off = NULL;
100     GSList *store = priv->extheme_list;
101
102     while (store){
103         if (!strcmp(priv->theme, g_hash_table_lookup(store->data, "name"))){
104             icon_on = g_strdup(g_hash_table_lookup(store->data, "icon_on"));
105             icon_off = g_strdup(g_hash_table_lookup(store->data, "icon_off"));
106             break;
107         }
108         store = (GSList *)g_list_next(store);
109     }
110     if (enable){
111         if (icon_on)
112             str = g_strdup_printf("%s", icon_on);
113         else 
114             str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
115                             priv->theme, "icon.png");
116             if (access(str, F_OK) != 0){
117                 g_free(str);
118                 str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
119                             "Video", "icon.png");
120             }
121
122     }else {
123         if (icon_off)
124             str = g_strdup_printf("%s", icon_off);
125         else 
126             str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
127                             priv->theme, "icond.png");
128             if (access(str, F_OK) != 0){
129                 g_free(str);
130                 str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
131                             "Video", "icond.png");
132             }
133     }
134     pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
135                                                  124, 
136                                                  79, 
137                                                  NULL);
138     if (str)
139         g_free(str);
140     if (icon_on)
141         g_free(icon_on);
142     if (icon_off)
143         g_free(icon_off);
144     if (pixbuf){
145         image = gtk_image_new_from_pixbuf (pixbuf);
146         g_object_unref(G_OBJECT(pixbuf));
147     }
148
149     //hildon_button_set_image (HILDON_BUTTON (button), image);
150     GList *list = gtk_container_get_children(GTK_CONTAINER (button));
151     if (list){
152         gtk_container_remove(GTK_CONTAINER (button), list->data);
153     }
154     gtk_container_add(GTK_CONTAINER (button), image);
155     gtk_widget_show(image);
156     gtk_widget_show(button);
157
158 }
159 /********************************************************************************/
160 GtkWidget *
161 create_image_button (gint view, DBusConnection *conn_sess){
162     GtkWidget *event_box;
163
164     Animation_WallpaperPrivate *priv = g_new0(Animation_WallpaperPrivate, 1);
165     /* Add external themes to priv */
166     priv->extheme_list = get_list_exthemes();
167
168     priv->view = view;
169     priv->theme_string_parametr1 = NULL;
170     priv->dbus_conn_session = conn_sess;
171     read_config(priv);
172
173     event_box = gtk_event_box_new();
174     g_object_set_data(G_OBJECT(event_box), "view", GINT_TO_POINTER(view));
175     g_object_set_data(G_OBJECT(event_box), "priv", priv);
176     set_button_image(event_box, priv, check_applet_state(view));
177     g_signal_connect(G_OBJECT (event_box), "button_press_event", G_CALLBACK(theme_button_clicked), priv);
178     return event_box;
179 #if 0
180     button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
181                                     HILDON_BUTTON_ARRANGEMENT_VERTICAL);
182     g_object_set_data(G_OBJECT(button), "view", GINT_TO_POINTER(view));
183     g_object_set_data(G_OBJECT(button), "priv", priv);
184     set_button_image(button, priv, check_applet_state(view));
185     g_signal_connect(button, "clicked", G_CALLBACK(theme_button_clicked), priv);
186     hildon_button_set_image_position (HILDON_BUTTON (button), GTK_POS_RIGHT);
187     return button;
188 #endif
189 }
190 /********************************************************************************/
191 void
192 changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
193 {
194     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
195     GtkWidget *vbox = NULL;
196     GtkWidget *area_vbox = NULL;
197         
198     area_vbox = g_object_get_data(G_OBJECT(priv->window), "area_vbox");
199     if (!area_vbox)
200         return;
201     vbox = g_object_get_data(G_OBJECT(priv->window), "custom_vbox");
202     if (vbox){
203         gtk_widget_destroy(vbox);
204     }
205     vbox = gtk_vbox_new (TRUE, 5);
206     g_object_set_data(G_OBJECT(priv->window), "custom_vbox", vbox);
207     gtk_box_pack_start(GTK_BOX(area_vbox),
208                                    vbox, FALSE, FALSE, 5);
209     if (choice) {
210         if (!strcmp(choice, _("Berlin"))){
211             rich_animation_additional_parametr(vbox,priv);
212         }
213         if (!strcmp(choice, _("Modern"))){
214             rich_animation_additional_parametr(vbox,priv);
215         }
216         if (!strcmp(choice, _("Matrix"))){
217             rich_animation_additional_parametr(vbox,priv);
218         }
219
220         if (!strcmp(choice, _("Accel"))){
221             rich_animation_additional_parametr(vbox,priv);
222         }
223         if (!strcmp(choice, _("Video"))){
224             additional_parametr_for_theme_video(vbox, priv);
225         }
226     }
227     gtk_widget_show(vbox);
228 }
229 /********************************************************************************/
230 void
231 changed_value_category_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
232 {
233     GtkWidget *theme_button = NULL;
234     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
235
236     theme_button = g_object_get_data(G_OBJECT(priv->window), "theme_button");
237     if (!theme_button) 
238         return;
239     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) theme_button);
240     hildon_touch_selector_remove_column(selector, 0); 
241     hildon_touch_selector_append_text_column(selector, (GtkTreeModel*)gtk_list_store_new (1, G_TYPE_STRING), TRUE);
242     fill_theme_button(priv, theme_button, (gchar *)hildon_button_get_value(HILDON_BUTTON (picker)));
243     /* check xscreensaver category */
244     if (choice){
245         if (!strcmp(choice,"Xscreensaver"))
246             if (access("/usr/bin/xscreensaver", F_OK) != 0){
247                 show_problem_package((GtkWidget *)picker, "Xscreensaver");
248             }
249
250     }
251 }
252 /********************************************************************************/
253 void
254 fill_theme_button (Animation_WallpaperPrivate *priv, GtkWidget *button, gchar *category){
255
256     gchar *theme = priv->theme;
257     gboolean flag = False;
258     gint num=0;
259         hildon_button_set_value(HILDON_BUTTON (button), NULL);
260     if (!category){
261         changed_value_theme_cb(HILDON_PICKER_BUTTON (button), priv);
262         return;
263     }
264     GSList *store = priv->extheme_list;
265     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) button);
266     if (!selector)
267         selector = (HildonTouchSelector *)hildon_touch_selector_new_text ();
268     
269     hildon_button_set_value(HILDON_BUTTON(button), NULL);
270     if (!strcmp(category, "LiveWallpaper")){
271         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Berlin"));
272         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Modern"));
273         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Matrix"));
274         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Accel"));
275         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Video"));
276         num = 5;        
277         if (theme){ 
278             if (!strcmp(theme, "Berlin")){
279                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
280                 hildon_button_set_value(HILDON_BUTTON(button), _("Berlin"));
281             }
282             if (!strcmp(theme, "Modern")){
283                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 1);
284                 hildon_button_set_value(HILDON_BUTTON(button), _("Modern"));
285             }
286             if (!strcmp(theme, "Matrix")){
287                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 2);
288                 hildon_button_set_value(HILDON_BUTTON(button), _("Matrix"));
289             }
290             if (!strcmp(theme, "Accel")){
291                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 3);
292                 hildon_button_set_value(HILDON_BUTTON(button), _("Accel"));
293             }
294             if (!strcmp(theme, "Video")){
295                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 4);
296                 hildon_button_set_value(HILDON_BUTTON(button), _("Video"));
297             }
298        }
299     }
300     while (store){  
301         if (!g_hash_table_lookup(store->data, "category"))
302             continue;
303         if (!strcmp(g_hash_table_lookup(store->data, "category"), category)){
304             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), g_hash_table_lookup(store->data, "name"));
305             if (!strcmp(theme, g_hash_table_lookup(store->data, "name"))){
306                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, num);
307                 hildon_button_set_value(HILDON_BUTTON(button), _(g_hash_table_lookup(store->data, "name")));
308             }
309             num++;
310         }
311         store = g_slist_next(store);
312     }
313     /* Added Shreman's Aquarium for message */
314     if (!strcmp(category, "Unknown")){
315         store = priv->extheme_list;
316         while (store){  
317             if (!strcmp("Shermans Aquarium" , g_hash_table_lookup(store->data, "name"))){
318                 flag = TRUE;
319                 break;
320             }
321             store = g_slist_next(store);
322         }
323         if (!flag)
324             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "Shermans Aquarium");
325     }
326
327         hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
328                                                        HILDON_TOUCH_SELECTOR (selector));
329
330     changed_value_theme_cb(HILDON_PICKER_BUTTON (button), priv);
331 }
332 /********************************************************************************/
333 GtkWidget *
334 create_themes_button (Animation_WallpaperPrivate *priv, gchar *category){
335
336     GtkWidget *button;
337     button = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
338     hildon_button_set_title (HILDON_BUTTON (button), _("Theme"));
339
340    
341     return button;
342 }
343 /********************************************************************************/
344 GtkWidget *
345 create_categories_button (Animation_WallpaperPrivate *priv){
346
347     GtkWidget *button;
348     GtkWidget *selector;
349     gchar *theme = priv->theme;
350     gint num=0;
351     GHashTable *result_table = NULL;
352
353     result_table = g_hash_table_new(g_str_hash, g_str_equal);
354     selector = create_category_selector(priv);
355     button = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
356     hildon_button_set_title (HILDON_BUTTON (button), _("Category"));
357     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
358                                                        HILDON_TOUCH_SELECTOR (selector));
359     if (theme) {
360         if (!strcmp(theme, "Berlin")){
361             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
362             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
363         }
364         if (!strcmp(theme, "Modern")){
365             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
366             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
367         }
368         if (!strcmp(theme, "Matrix")){
369             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
370             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
371         }
372         if (!strcmp(theme, "Accel")){
373             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
374             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
375         }
376         if (!strcmp(theme, "Video")){
377             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
378             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
379         }
380         GSList *store = priv->extheme_list;
381         num = 1;
382         while (store){
383             if (g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category")) == NULL){
384                 g_hash_table_insert(result_table, g_hash_table_lookup(store->data, "category"), (gint *)num);     
385                 num++;
386             }
387             if (!strcmp(theme, g_hash_table_lookup(store->data, "name"))){
388                 if (g_hash_table_lookup(store->data, "category"))
389                     hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 
390                     (gint)g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category"))); 
391                     hildon_button_set_value(HILDON_BUTTON(button), g_hash_table_lookup(store->data, "category"));
392                 break;
393             }
394
395             store = g_slist_next(store);
396         }
397     }
398     return button;
399 }
400
401 /*******************************************************************************/
402 GtkWidget *
403 create_bool_button (gboolean active, gchar *name)
404 {
405     GtkWidget *button;
406     button = hildon_check_button_new (HILDON_SIZE_AUTO);
407     gtk_button_set_label (GTK_BUTTON (button), name);
408     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
409     return button;
410 }
411 /*******************************************************************************/
412 GtkWidget *
413 create_enable_button (gboolean active)
414 {
415     GtkWidget *button;
416     button = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
417     gtk_button_set_label (GTK_BUTTON (button), _("Enable"));
418     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
419     return button;
420 }
421
422 /*******************************************************************************/
423 void
424 show_settings(GtkWidget *widget, Animation_WallpaperPrivate *priv){
425     lw_main_settings(priv, NULL);
426 }
427 /*******************************************************************************/
428 void 
429 lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
430     gint result;
431     GtkWidget *window = NULL;
432     GtkWidget *theme_button1;
433     GtkWidget *theme_button2;
434     GtkWidget *theme_button3;
435     GtkWidget *theme_button4;
436     GtkWidget *hbox;
437     Animation_WallpaperPrivate *priv_temp = NULL;
438
439     window = gtk_dialog_new();
440
441     gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
442     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
443     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
444     /* Create Theme button */
445     hbox = gtk_hbox_new(FALSE, 0);
446     theme_button1 = create_image_button(1, priv->dbus_conn_session);
447     gtk_box_pack_start(GTK_BOX(hbox),
448                                    theme_button1, TRUE, TRUE, 0);
449     theme_button2 = create_image_button(2, priv->dbus_conn_session);
450     gtk_box_pack_start(GTK_BOX(hbox),
451                                    theme_button2, TRUE, TRUE, 0);
452     theme_button3 = create_image_button(3, priv->dbus_conn_session);
453     gtk_box_pack_start(GTK_BOX(hbox),
454                                    theme_button3, TRUE, TRUE, 0);
455     theme_button4 = create_image_button(4, priv->dbus_conn_session);
456     gtk_box_pack_start(GTK_BOX(hbox),
457                                    theme_button4, TRUE, TRUE, 0);
458     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
459                                    hbox, TRUE, TRUE, 5);
460
461     gtk_widget_show (theme_button1);
462     gtk_widget_show (theme_button2);
463     gtk_widget_show (theme_button3);
464     gtk_widget_show (theme_button4);
465     gtk_widget_show_all (hbox);
466     gtk_widget_show (window);
467     gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
468
469     result = gtk_dialog_run(GTK_DIALOG(window));
470
471     priv_temp = g_object_get_data(G_OBJECT(theme_button1), "priv");
472     if (priv_temp){
473         g_free(priv_temp);
474         priv_temp =NULL;
475     }
476     priv_temp = g_object_get_data(G_OBJECT(theme_button2), "priv");
477     if (priv_temp){
478         g_free(priv_temp);
479         priv_temp =NULL;
480     }
481     priv_temp = g_object_get_data(G_OBJECT(theme_button3), "priv");
482     if (priv_temp){
483         g_free(priv_temp);
484         priv_temp =NULL;
485     }
486     priv_temp = g_object_get_data(G_OBJECT(theme_button4), "priv");
487     if (priv_temp){
488         g_free(priv_temp);
489         priv_temp =NULL;
490     }
491
492
493     switch(result){
494         case GTK_RESPONSE_NO:
495             gtk_widget_destroy(window);
496             window = NULL;
497             lw_about();
498         break;
499     }
500
501
502     if (window)
503         gtk_widget_destroy(window);
504 }
505 /*******************************************************************************/
506 void
507 file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
508
509     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
510
511     if (priv->theme_string_parametr1)
512         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
513
514     gtk_widget_show_all (GTK_WIDGET (dialog));
515
516     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
517     {
518       hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
519     }
520     gtk_widget_destroy (dialog);
521
522 }
523 /*******************************************************************************/
524 void
525 rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
526     GtkWidget *rich_animation_button;
527
528     /* Create rich animation button */  
529     rich_animation_button = create_bool_button(priv->rich_animation, _("Rich Animation"));
530     gtk_box_pack_start(GTK_BOX(vbox),
531                                    rich_animation_button, TRUE, TRUE, 5);
532     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
533     gtk_widget_show (rich_animation_button);
534 }
535 /*******************************************************************************/
536 void
537 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
538
539     GtkWidget *file_button;
540     GtkWidget *rich_animation_button;
541
542     if (priv->theme_string_parametr1)
543         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
544                                                    _("Play file"), priv->theme_string_parametr1);
545     else
546         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
547                                                    _("Play file")," ");
548
549     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
550
551     gtk_box_pack_start(GTK_BOX(vbox),
552                                    file_button, TRUE, TRUE, 5);
553     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);    
554     /* Create rich animation button */  
555     rich_animation_button = create_bool_button(priv->rich_animation, _("Loop"));
556     gtk_box_pack_start(GTK_BOX(vbox),
557                                    rich_animation_button, TRUE, TRUE, 5);
558     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
559     /* Create sound button */  
560 #if 0
561
562     /* Doesn't work in real device. Hardware volume buttons can to change volume for mutted track */
563     sound_button = create_bool_button(priv->theme_bool_parametr1, _("Sound"));
564     gtk_box_pack_start(GTK_BOX(vbox),
565                                    sound_button, TRUE, TRUE, 5);
566     g_object_set_data(G_OBJECT(priv->window), "sound_button", sound_button);
567     gtk_widget_show (sound_button);
568 #endif
569     gtk_widget_show (file_button);
570     gtk_widget_show (rich_animation_button);
571
572 }
573 /*******************************************************************************/
574 void
575 show_problem_package (GtkWidget *widget, gchar *package_name){
576     gchar *text;
577     text = g_strdup_printf(_("You haven't got the installed package %s. Please install it via using Application Manager"), package_name);
578     hildon_banner_show_information(GTK_WIDGET(widget), NULL, text);
579     g_free(text);
580 }
581 /*******************************************************************************/
582 void 
583 lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
584     gint result;
585     GtkWidget *window = NULL;
586     GtkWidget *scrolled_window = NULL;
587     GtkWidget *save_button;
588     GtkWidget *theme_button;
589     GtkWidget *category_button;
590     GtkWidget *enable_button;
591     GtkWidget *vbox;
592     GtkWidget *area_vbox;
593     GtkWidget *button1 = NULL;
594     GtkWidget *rich_animation_button = NULL;
595     gint view = priv->view;
596
597     window = gtk_dialog_new();
598     priv->window = window;
599
600     gtk_window_set_title(GTK_WINDOW(window), _("View Settings"));
601     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
602     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
603
604     /* Create panarea */
605     area_vbox = gtk_vbox_new(FALSE, 2);
606     g_object_set_data(G_OBJECT(window), "area_vbox", area_vbox);
607     scrolled_window = hildon_pannable_area_new ();
608     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (scrolled_window), GTK_WIDGET (area_vbox));
609     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
610                                    scrolled_window, FALSE, FALSE, 0);
611
612     gtk_widget_set_size_request(scrolled_window, -1, 370);
613
614     /* Create Enable button */
615     enable_button = create_enable_button(check_applet_state(view)); 
616     gtk_box_pack_start(GTK_BOX(area_vbox),
617                                    enable_button, FALSE, FALSE, 5);
618     /* Create Category button */
619     category_button = create_categories_button(priv);
620     g_object_set_data(G_OBJECT(window), "category_button", category_button);
621     g_signal_connect (G_OBJECT (category_button), "value-changed",  G_CALLBACK (changed_value_category_cb), priv);
622     gtk_box_pack_start(GTK_BOX(area_vbox),
623                                    category_button, FALSE, FALSE, 5);
624     /* Create Custom vbox */
625     vbox = gtk_vbox_new (FALSE, 5);
626     g_object_set_data(G_OBJECT(window), "custom_vbox", vbox);
627
628     /* Create Theme button */
629     theme_button = create_themes_button(priv, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
630     g_object_set_data(G_OBJECT(window), "theme_button", theme_button);
631     g_signal_connect (G_OBJECT (theme_button), "value-changed",  G_CALLBACK (changed_value_theme_cb), priv);
632     gtk_box_pack_start(GTK_BOX(area_vbox),
633                                    theme_button, FALSE, FALSE, 5);
634     fill_theme_button(priv, theme_button, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
635
636     /* Pack custom vbox. It must be last widget */
637     gtk_box_pack_start(GTK_BOX(area_vbox),
638                                    vbox, FALSE, FALSE, 5);
639
640     gtk_widget_show (enable_button);
641     gtk_widget_show (category_button);
642     gtk_widget_show (theme_button);
643     gtk_widget_show (vbox);
644     gtk_widget_show (area_vbox);
645     gtk_widget_show (scrolled_window);
646     gtk_widget_show (window);
647
648     save_button = gtk_dialog_add_button(GTK_DIALOG(window), _("Save"), GTK_RESPONSE_YES);
649
650     result = gtk_dialog_run(GTK_DIALOG(window));
651
652     switch(result){
653         case GTK_RESPONSE_YES:
654             /* Check theme */
655             if (hildon_button_get_value(HILDON_BUTTON (theme_button)) &&
656                 strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "")){
657                 /* Check Xsnow program */
658                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Xsnow"))){
659                     if (access("/usr/bin/xsnow", F_OK) != 0){
660                         show_problem_package(button, "Xsnow");
661                         /* if not scuccess exit from wthout saving */ 
662                         break;
663                     }
664                 }
665                 /* Check Shermans program */
666                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Shermans Aquarium")){
667                     if (access("/usr/bin/shermans", F_OK) != 0){
668                         show_problem_package(button,"'Sherman's Aquarium'");
669                         /* if not scuccess exit from wthout saving */ 
670                         break;
671                     }
672                 }
673                 /* Check Conky program */
674                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Conky")){
675                     if (access("/usr/bin/conky", F_OK) != 0){
676                         show_problem_package(button,"'Conky'");
677                         /* if not scuccess exit from wthout saving */ 
678                         break;
679                     }
680                 }
681
682                 if (priv->theme)
683                     g_free(priv->theme);
684                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
685                     priv->theme = g_strdup("Berlin");
686                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern")))
687                     priv->theme = g_strdup("Modern");
688                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix")))
689                     priv->theme = g_strdup("Matrix");
690                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel")))
691                     priv->theme = g_strdup("Accel");
692                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
693                     priv->theme = g_strdup("Video");
694                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
695                     if (button1){
696                         if (priv->theme_string_parametr1)
697                             g_free(priv->theme_string_parametr1);
698                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
699                     }
700                     /* 
701                     temp_button = g_object_get_data(G_OBJECT(priv->window), "sound_button");
702                     if (temp_button){
703                         if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(temp_button)))
704                             priv->theme_bool_parametr1 = TRUE;
705                         else
706                             priv->theme_bool_parametr1 = FALSE;
707                     }
708                     */
709                 }
710                 /* Check external themes */
711                 GSList *store = priv->extheme_list;
712                 while (store){
713                     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _(g_hash_table_lookup(store->data, "name")))){
714                         priv->theme = g_strdup(g_hash_table_lookup(store->data, "name"));
715                         //priv->hash_theme = store->data;
716                         break;
717                     }
718                     store = g_slist_next(store);
719                 }
720
721             }
722
723             rich_animation_button = g_object_get_data(G_OBJECT(priv->window), "rich_animation_button");
724             if (rich_animation_button){
725                 /* Check rich animation */
726                 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(rich_animation_button)))
727                     priv->rich_animation = TRUE;
728                 else
729                     priv->rich_animation = FALSE;
730             }
731             /* Save config */
732             save_config(priv);
733             /* action with applet */
734             if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(enable_button))){
735                     if (!check_applet_state(view)){
736                         start_applet(view);
737                     }else {
738                         send_dbus_signal (priv,
739                               LIVEWP_SIGNAL_INTERFACE,
740                               LIVEWP_SIGNAL_PATH,
741                               LIVEWP_RELOAD_CONFIG);
742                     }
743             }else
744                     if (check_applet_state(view))
745                         stop_applet(view);
746
747             set_button_image(button, priv, check_applet_state(view));
748             break;
749         default:
750         case GTK_RESPONSE_OK:
751         break;
752         case GTK_RESPONSE_NO:
753             gtk_widget_destroy(window);
754             window = NULL;
755             lw_about();
756         break;
757     }
758     if (window)
759         gtk_widget_destroy(window);
760 }
761 /*******************************************************************************/
762 gboolean
763 check_applet_state(gint number){
764
765     HDConfigFile *config_file = NULL;
766     GKeyFile *gkey_file = NULL;
767     gchar *str = NULL;
768     gboolean result = FALSE;
769     if (number > 4 || number < 1)
770         return FALSE;
771
772     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
773     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
774     
775     gkey_file = hd_config_file_load_file(config_file, FALSE);
776     if (gkey_file && str){
777         result = g_key_file_has_group(gkey_file, str);
778         g_free(str);
779     }
780     return result;
781 }
782 /*******************************************************************************/
783 void
784 start_applet(gint number){
785
786     HDConfigFile *config_file = NULL;
787     GKeyFile *gkey_file = NULL;
788     gchar *str = NULL;
789
790     if (number > 4 || number < 1)
791         return;
792     str = g_strdup_printf("livewp-home-widget.desktop-%i",(number - 1));
793     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
794     
795     gkey_file = hd_config_file_load_file(config_file, FALSE);
796     if (gkey_file){
797         g_key_file_set_string (gkey_file, str, "X-Desktop-File", "/usr/share/applications/hildon-home/livewp-home-widget.desktop");
798         hd_config_file_save_file( config_file, gkey_file);
799         g_key_file_free(gkey_file);
800     }else
801         fprintf(stderr, "Problem with config file");
802     if (str)
803         g_free(str);
804     g_object_unref(config_file);
805 }
806 /*******************************************************************************/
807 void
808 stop_applet(gint number){
809     HDConfigFile *config_file = NULL;
810     GKeyFile *gkey_file = NULL;
811     gchar *str = NULL;
812
813     if (number > 4 || number < 1)
814         return;
815     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
816     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
817     
818     gkey_file = hd_config_file_load_file(config_file, FALSE);
819     if (gkey_file){
820          g_key_file_remove_group(gkey_file, str, NULL);  
821         hd_config_file_save_file( config_file, gkey_file);
822         g_key_file_free(gkey_file);
823     }else
824         fprintf(stderr, "Problem with config file");
825     if (str)
826         g_free(str);
827     g_object_unref(config_file);
828
829 }