fixed problem with choosing of category
[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     hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("LiveWallpaper") );
76     while (category_list){  
77         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),category_list->data );
78         category_list = g_list_next(category_list);
79     }
80
81     return selector;
82 }
83
84 /*******************************************************************************/
85 void
86 theme_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
87
88     lw_theme_settings(GTK_WIDGET(button), priv);
89 }
90 /********************************************************************************/
91 void
92 set_button_image(GtkWidget * button, Animation_WallpaperPrivate *priv, gboolean enable){
93     GtkWidget * image = NULL; 
94     GdkPixbuf * pixbuf = NULL;
95     gchar *str = NULL;
96     gchar *icon_on = NULL;
97     gchar *icon_off = NULL;
98     GSList *store = priv->extheme_list;
99     while (store){
100         if (!strcmp(priv->theme, g_hash_table_lookup(store->data, "name"))){
101             icon_on = g_strdup(g_hash_table_lookup(store->data, "icon_on"));
102             icon_off = g_strdup(g_hash_table_lookup(store->data, "icon_off"));
103             break;
104         }
105         store = g_list_next(store);
106     }
107     if (enable){
108         if (icon_on)
109             str = g_strdup_printf("%s", icon_on);
110         else 
111             str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
112                             priv->theme, "icon.png");
113     }else {
114         if (icon_off)
115             str = g_strdup_printf("%s", icon_off);
116         else
117             str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
118                             priv->theme, "icond.png");
119     }
120     fprintf(stderr, "icon = %s\n", str);
121     pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
122                                                  100, 
123                                                  60, 
124                                                  NULL);
125     if (str)
126         g_free(str);
127     if (icon_on)
128         g_free(icon_on);
129     if (icon_off)
130         g_free(icon_off);
131     if (pixbuf){
132         image = gtk_image_new_from_pixbuf (pixbuf);
133         g_object_unref(G_OBJECT(pixbuf));
134     }
135
136    hildon_button_set_image (HILDON_BUTTON (button), image);
137 }
138 /********************************************************************************/
139 GtkWidget *
140 create_image_button (gint view, DBusConnection *conn_sess){
141     GtkWidget *button;
142     
143     Animation_WallpaperPrivate *priv = g_new0(Animation_WallpaperPrivate, 1);
144     /* Add external themes to priv */
145     priv->extheme_list = get_list_exthemes();
146
147     priv->view = view;
148     priv->theme_string_parametr1 = NULL;
149     priv->dbus_conn_session = conn_sess;
150     read_config(priv);
151     button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
152                                     HILDON_BUTTON_ARRANGEMENT_VERTICAL);
153     g_object_set_data(G_OBJECT(button), "view", GINT_TO_POINTER(view));
154     g_object_set_data(G_OBJECT(button), "priv", priv);
155     set_button_image(button, priv, check_applet_state(view));
156     g_signal_connect(button, "clicked", G_CALLBACK(theme_button_clicked), priv);
157     hildon_button_set_image_position (HILDON_BUTTON (button), GTK_POS_RIGHT);
158     return button;
159
160 }
161 /********************************************************************************/
162 void
163 changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
164 {
165     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
166     GtkWidget *vbox = NULL;
167         
168     vbox = g_object_get_data(G_OBJECT(priv->window), "custom_vbox");
169     if (vbox)
170         gtk_widget_destroy(vbox);
171     vbox = gtk_vbox_new (FALSE, 5);
172     g_object_set_data(G_OBJECT(priv->window), "custom_vbox", vbox);
173     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(priv->window)->vbox),
174                                    vbox, TRUE, TRUE, 5);
175     if (choice) {
176         if (!strcmp(choice, _("Berlin"))){
177             rich_animation_additional_parametr(vbox,priv);
178         }
179         if (!strcmp(choice, _("Modern"))){
180             rich_animation_additional_parametr(vbox,priv);
181         }
182         if (!strcmp(choice, _("Matrix"))){
183             rich_animation_additional_parametr(vbox,priv);
184         }
185
186         if (!strcmp(choice, _("Accel"))){
187             rich_animation_additional_parametr(vbox,priv);
188         }
189         if (!strcmp(choice, _("Video"))){
190             additional_parametr_for_theme_video(vbox, priv);
191         }
192     }
193     gtk_widget_show(vbox);
194 }
195 /********************************************************************************/
196 void
197 changed_value_category_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
198 {
199     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
200     GtkWidget *theme_button = NULL;
201
202     theme_button = g_object_get_data(G_OBJECT(priv->window), "theme_button");
203     if (!theme_button) 
204         return;
205     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) theme_button);
206     hildon_touch_selector_remove_column(selector, 0); 
207     hildon_touch_selector_append_text_column(selector, gtk_list_store_new (1, G_TYPE_STRING), TRUE);
208     fill_theme_button(priv, theme_button, hildon_button_get_value(HILDON_BUTTON (picker)));
209 }
210 /********************************************************************************/
211 void
212 fill_theme_button (Animation_WallpaperPrivate *priv, GtkWidget *button, gchar *category){
213
214     gchar *theme = priv->theme;
215     gint num=0;
216     if (!category)
217         return;
218     GSList *store = priv->extheme_list;
219     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) button);
220     if (!selector)
221         selector = hildon_touch_selector_new_text ();
222     
223     hildon_button_set_value(HILDON_BUTTON(button), NULL);
224     if (!strcmp(category, "LiveWallpaper")){
225         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Berlin"));
226         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Modern"));
227         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Matrix"));
228         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Accel"));
229         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Video"));
230         num = 5;        
231         if (theme){ 
232             if (!strcmp(theme, "Berlin")){
233                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
234                 hildon_button_set_value(HILDON_BUTTON(button), _("Berlin"));
235             }
236             if (!strcmp(theme, "Modern")){
237                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 1);
238                 hildon_button_set_value(HILDON_BUTTON(button), _("Modern"));
239             }
240             if (!strcmp(theme, "Matrix")){
241                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 2);
242                 hildon_button_set_value(HILDON_BUTTON(button), _("Matrix"));
243             }
244             if (!strcmp(theme, "Accel")){
245                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 3);
246                 hildon_button_set_value(HILDON_BUTTON(button), _("Accel"));
247             }
248             if (!strcmp(theme, "Video")){
249                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 4);
250                 hildon_button_set_value(HILDON_BUTTON(button), _("Video"));
251             }
252        }
253     }
254     while (store){  
255         if (!g_hash_table_lookup(store->data, "category"))
256             continue;
257         if (!strcmp(g_hash_table_lookup(store->data, "category"), category)){
258             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), g_hash_table_lookup(store->data, "name"));
259             if (!strcmp(theme, g_hash_table_lookup(store->data, "name"))){
260                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, num);
261                 hildon_button_set_value(HILDON_BUTTON(button), _(g_hash_table_lookup(store->data, "name")));
262             }
263             num++;
264         }
265         store = g_slist_next(store);
266     }
267        
268     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
269                                                        HILDON_TOUCH_SELECTOR (selector));
270
271 }
272 /********************************************************************************/
273 GtkWidget *
274 create_themes_button (Animation_WallpaperPrivate *priv, gchar *category){
275
276     GtkWidget *button;
277     button = hildon_picker_button_new (HILDON_SIZE_AUTO, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
278     hildon_button_set_title (HILDON_BUTTON (button), _("Theme"));
279     fill_theme_button(priv, button, category);
280
281    
282     return button;
283 }
284 /********************************************************************************/
285 GtkWidget *
286 create_categories_button (Animation_WallpaperPrivate *priv){
287
288     GtkWidget *button;
289     GtkWidget *selector;
290     gchar *theme = priv->theme;
291     gint num=0;
292     GHashTable *result_table = NULL;
293
294     result_table = g_hash_table_new(g_str_hash, g_str_equal);
295     selector = create_category_selector(priv);
296     button = hildon_picker_button_new (HILDON_SIZE_AUTO, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
297     hildon_button_set_title (HILDON_BUTTON (button), _("Category"));
298     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
299                                                        HILDON_TOUCH_SELECTOR (selector));
300     if (theme) {
301         if (!strcmp(theme, "Berlin")){
302             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
303             hildon_button_set_value(HILDON_BUTTON(button), _("LiveWallpaper"));
304         }
305         if (!strcmp(theme, "Modern")){
306             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
307             hildon_button_set_value(HILDON_BUTTON(button), _("LiveWallpaper"));
308         }
309         if (!strcmp(theme, "Matrix")){
310             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
311             hildon_button_set_value(HILDON_BUTTON(button), _("LiveWallpaper"));
312         }
313         if (!strcmp(theme, "Accel")){
314             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
315             hildon_button_set_value(HILDON_BUTTON(button), _("LiveWallpaper"));
316         }
317         if (!strcmp(theme, "Video")){
318             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0); 
319             hildon_button_set_value(HILDON_BUTTON(button), _("LiveWallpaper"));
320         }
321         GSList *store = priv->extheme_list;
322         while (store){
323             if (!g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category"))){
324                 g_hash_table_insert(result_table, g_hash_table_lookup(store->data, "category"), num);     
325                 num++;
326             }
327             if (!strcmp(theme, g_hash_table_lookup(store->data, "name"))){
328                 if (g_hash_table_lookup(store->data, "category"))
329                     hildon_button_set_value(HILDON_BUTTON(button), _(g_hash_table_lookup(store->data, "category")));
330                     hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category"))); 
331                 break;
332             }
333
334             store = g_slist_next(store);
335         }
336     }
337     return button;
338 }
339
340 /*******************************************************************************/
341 GtkWidget *
342 create_rich_animation_button (gboolean active, gchar *name)
343 {
344     GtkWidget *button;
345     button = hildon_check_button_new (HILDON_SIZE_AUTO);
346     gtk_button_set_label (GTK_BUTTON (button), name);
347     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
348     return button;
349 }
350 /*******************************************************************************/
351 GtkWidget *
352 create_enable_button (gboolean active)
353 {
354     GtkWidget *button;
355     button = hildon_check_button_new (HILDON_SIZE_AUTO);
356     gtk_button_set_label (GTK_BUTTON (button), _("Enable"));
357     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
358     return button;
359 }
360
361 /*******************************************************************************/
362 void
363 show_settings(GtkWidget *widget, Animation_WallpaperPrivate *priv){
364     lw_main_settings(priv, NULL);
365 }
366 /*******************************************************************************/
367 void 
368 lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
369     gint result;
370     GtkWidget *window = NULL;
371     GtkWidget *theme_button1;
372     GtkWidget *theme_button2;
373     GtkWidget *theme_button3;
374     GtkWidget *theme_button4;
375     GtkWidget *hbox;
376     Animation_WallpaperPrivate *priv_temp = NULL;
377
378     window = gtk_dialog_new();
379
380     gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
381     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
382     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
383     /* Create Theme button */
384     hbox = gtk_hbox_new(FALSE, 5);
385     theme_button1 = create_image_button(1, priv->dbus_conn_session);
386     gtk_box_pack_start(GTK_BOX(hbox),
387                                    theme_button1, TRUE, TRUE, 5);
388     theme_button2 = create_image_button(2, priv->dbus_conn_session);
389     gtk_box_pack_start(GTK_BOX(hbox),
390                                    theme_button2, TRUE, TRUE, 5);
391     theme_button3 = create_image_button(3, priv->dbus_conn_session);
392     gtk_box_pack_start(GTK_BOX(hbox),
393                                    theme_button3, TRUE, TRUE, 5);
394     theme_button4 = create_image_button(4, priv->dbus_conn_session);
395     gtk_box_pack_start(GTK_BOX(hbox),
396                                    theme_button4, TRUE, TRUE, 5);
397     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
398                                    hbox, TRUE, TRUE, 5);
399
400     gtk_widget_show (theme_button1);
401     gtk_widget_show (theme_button2);
402     gtk_widget_show (theme_button3);
403     gtk_widget_show (theme_button4);
404     gtk_widget_show_all (hbox);
405     gtk_widget_show (window);
406     gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
407
408     result = gtk_dialog_run(GTK_DIALOG(window));
409
410     priv_temp = g_object_get_data(G_OBJECT(theme_button1), "priv");
411     if (priv_temp){
412         g_free(priv_temp);
413         priv_temp =NULL;
414     }
415     priv_temp = g_object_get_data(G_OBJECT(theme_button2), "priv");
416     if (priv_temp){
417         g_free(priv_temp);
418         priv_temp =NULL;
419     }
420     priv_temp = g_object_get_data(G_OBJECT(theme_button3), "priv");
421     if (priv_temp){
422         g_free(priv_temp);
423         priv_temp =NULL;
424     }
425     priv_temp = g_object_get_data(G_OBJECT(theme_button4), "priv");
426     if (priv_temp){
427         g_free(priv_temp);
428         priv_temp =NULL;
429     }
430
431
432     switch(result){
433         case GTK_RESPONSE_NO:
434             gtk_widget_destroy(window);
435             window = NULL;
436             lw_about();
437         break;
438     }
439
440
441     if (window)
442         gtk_widget_destroy(window);
443 }
444 /*******************************************************************************/
445 void
446 file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
447
448     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
449
450     if (priv->theme_string_parametr1)
451         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
452
453     gtk_widget_show_all (GTK_WIDGET (dialog));
454
455     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
456     {
457       hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
458     }
459     gtk_widget_destroy (dialog);
460
461 }
462 /*******************************************************************************/
463 void
464 rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
465     GtkWidget *rich_animation_button;
466     /* Create rich animation button */  
467     rich_animation_button = create_rich_animation_button(priv->rich_animation, _("Rich Animation"));
468     gtk_box_pack_start(GTK_BOX(vbox),
469                                    rich_animation_button, TRUE, TRUE, 5);
470     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
471     gtk_widget_show (rich_animation_button);
472 }
473 /*******************************************************************************/
474 void
475 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
476
477     GtkWidget *file_button;
478     GtkWidget *rich_animation_button;
479
480     if (priv->theme_string_parametr1)
481         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
482                                                    _("Play file"), priv->theme_string_parametr1);
483     else
484         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
485                                                    _("Play file")," ");
486
487     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
488
489     gtk_box_pack_start(GTK_BOX(vbox),
490                                    file_button, TRUE, TRUE, 5);
491     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);    /* Create rich animation button */  
492     rich_animation_button = create_rich_animation_button(priv->rich_animation, _("Loop"));
493     gtk_box_pack_start(GTK_BOX(vbox),
494                                    rich_animation_button, TRUE, TRUE, 5);
495     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
496
497     gtk_widget_show (file_button);
498     gtk_widget_show (rich_animation_button);
499
500 }
501 /*******************************************************************************/
502 void 
503 lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
504     gint result;
505     GtkWidget *window = NULL;
506     GtkWidget *save_button;
507     GtkWidget *theme_button;
508     GtkWidget *category_button;
509     GtkWidget *enable_button;
510     GtkWidget *vbox;
511     GtkWidget *button1 = NULL;
512     GtkWidget *rich_animation_button = NULL;
513     gint view = priv->view;
514
515     window = gtk_dialog_new();
516     priv->window = window;
517
518     gtk_window_set_title(GTK_WINDOW(window), _("View Settings"));
519     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
520     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
521     /* Create Enable button */
522     enable_button = create_enable_button(check_applet_state(view)); 
523     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
524                                    enable_button, TRUE, TRUE, 5);
525     /* Create Category button */
526     category_button = create_categories_button(priv);
527     g_object_set_data(G_OBJECT(window), "category_button", category_button);
528     g_signal_connect (G_OBJECT (category_button), "value-changed",  G_CALLBACK (changed_value_category_cb), priv);
529     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
530                                    category_button, TRUE, TRUE, 5);
531
532     /* Create Theme button */
533     theme_button = create_themes_button(priv,hildon_button_get_value(HILDON_BUTTON (category_button)));
534     g_object_set_data(G_OBJECT(window), "theme_button", theme_button);
535     g_signal_connect (G_OBJECT (theme_button), "value-changed",  G_CALLBACK (changed_value_theme_cb), priv);
536     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
537                                    theme_button, TRUE, TRUE, 5);
538
539     /* Create custom vbox */
540     vbox = gtk_vbox_new (FALSE, 5);
541     g_object_set_data(G_OBJECT(window), "custom_vbox", vbox);
542     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
543                                    vbox, TRUE, TRUE, 5);
544     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin"))||
545         !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix"))||
546         !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel"))||
547         !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern"))){
548         rich_animation_additional_parametr(vbox, priv);
549     }
550
551     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
552         additional_parametr_for_theme_video(vbox, priv);
553     } 
554
555     gtk_widget_show (enable_button);
556     gtk_widget_show (category_button);
557     gtk_widget_show (theme_button);
558     gtk_widget_show (vbox);
559     gtk_widget_show (window);
560     save_button = gtk_dialog_add_button(GTK_DIALOG(window), _("Save"), GTK_RESPONSE_YES);
561
562     result = gtk_dialog_run(GTK_DIALOG(window));
563
564     switch(result){
565         case GTK_RESPONSE_YES:
566             /* Check theme */
567             if (hildon_button_get_value(HILDON_BUTTON (theme_button)) &&
568                 strcmp(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 }
670 /*******************************************************************************/
671 void
672 start_applet(gint number){
673
674     HDConfigFile *config_file = NULL;
675     GKeyFile *gkey_file = NULL;
676     gchar *str = NULL;
677
678     if (number > 4 || number < 1)
679         return;
680     str = g_strdup_printf("livewp-home-widget.desktop-%i",(number - 1));
681     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
682     
683     gkey_file = hd_config_file_load_file(config_file, FALSE);
684     if (gkey_file){
685         g_key_file_set_string (gkey_file, str, "X-Desktop-File", "/usr/share/applications/hildon-home/livewp-home-widget.desktop");
686         hd_config_file_save_file( config_file, gkey_file);
687         g_key_file_free(gkey_file);
688     }else
689         fprintf(stderr, "Problem with config file");
690     if (str)
691         g_free(str);
692     g_object_unref(config_file);
693 }
694 /*******************************************************************************/
695 void
696 stop_applet(gint number){
697     HDConfigFile *config_file = NULL;
698     GKeyFile *gkey_file = NULL;
699     gchar *str = NULL;
700
701     if (number > 4 || number < 1)
702         return;
703     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
704     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
705     
706     gkey_file = hd_config_file_load_file(config_file, FALSE);
707     if (gkey_file){
708          g_key_file_remove_group(gkey_file, str, NULL);  
709         hd_config_file_save_file( config_file, gkey_file);
710         g_key_file_free(gkey_file);
711     }else
712         fprintf(stderr, "Problem with config file");
713     if (str)
714         g_free(str);
715     g_object_unref(config_file);
716
717 }