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