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