fixed bug with theme settings
[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
63     result_table = g_hash_table_new(g_str_hash, g_str_equal);
64     while (store){  
65         if (!g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category")))
66             g_hash_table_insert(result_table, g_hash_table_lookup(store->data, "category"), (gint *)1);     
67         store = g_slist_next(store);
68     }
69
70     category_list = g_hash_table_get_keys (result_table);
71     selector = hildon_touch_selector_new_text();
72
73     hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "LiveWallpaper" );
74     while (category_list){  
75         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),category_list->data );
76         category_list = g_list_next(category_list);
77     }
78
79     return selector;
80 }
81
82 /*******************************************************************************/
83 void
84 theme_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
85
86     lw_theme_settings(GTK_WIDGET(button), priv);
87 }
88 /********************************************************************************/
89 void
90 set_button_image(GtkWidget * button, Animation_WallpaperPrivate *priv, gboolean enable){
91     GtkWidget * image = NULL; 
92     GdkPixbuf * pixbuf = NULL;
93     gchar *str = NULL;
94     gchar *icon_on = NULL;
95     gchar *icon_off = NULL;
96     GSList *store = priv->extheme_list;
97     while (store){
98         if (!strcmp(priv->theme, g_hash_table_lookup(store->data, "name"))){
99             icon_on = g_strdup(g_hash_table_lookup(store->data, "icon_on"));
100             icon_off = g_strdup(g_hash_table_lookup(store->data, "icon_off"));
101             break;
102         }
103         store = (GSList *)g_list_next(store);
104     }
105     if (enable){
106         if (icon_on)
107             str = g_strdup_printf("%s", icon_on);
108         else 
109             str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
110                             priv->theme, "icon.png");
111     }else {
112         if (icon_off)
113             str = g_strdup_printf("%s", icon_off);
114         else
115             str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
116                             priv->theme, "icond.png");
117     }
118     pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
119                                                  100, 
120                                                  60, 
121                                                  NULL);
122     if (str)
123         g_free(str);
124     if (icon_on)
125         g_free(icon_on);
126     if (icon_off)
127         g_free(icon_off);
128     if (pixbuf){
129         image = gtk_image_new_from_pixbuf (pixbuf);
130         g_object_unref(G_OBJECT(pixbuf));
131     }
132
133    hildon_button_set_image (HILDON_BUTTON (button), image);
134 }
135 /********************************************************************************/
136 GtkWidget *
137 create_image_button (gint view, DBusConnection *conn_sess){
138     GtkWidget *button;
139     
140     Animation_WallpaperPrivate *priv = g_new0(Animation_WallpaperPrivate, 1);
141     /* Add external themes to priv */
142     priv->extheme_list = get_list_exthemes();
143
144     priv->view = view;
145     priv->theme_string_parametr1 = NULL;
146     priv->dbus_conn_session = conn_sess;
147     read_config(priv);
148     button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
149                                     HILDON_BUTTON_ARRANGEMENT_VERTICAL);
150     g_object_set_data(G_OBJECT(button), "view", GINT_TO_POINTER(view));
151     g_object_set_data(G_OBJECT(button), "priv", priv);
152     set_button_image(button, priv, check_applet_state(view));
153     g_signal_connect(button, "clicked", G_CALLBACK(theme_button_clicked), priv);
154     hildon_button_set_image_position (HILDON_BUTTON (button), GTK_POS_RIGHT);
155     return button;
156
157 }
158 /********************************************************************************/
159 void
160 changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
161 {
162     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
163     GtkWidget *vbox = NULL;
164         
165     vbox = g_object_get_data(G_OBJECT(priv->window), "custom_vbox");
166     if (vbox){
167         gtk_widget_destroy(vbox);
168     }
169     vbox = gtk_vbox_new (FALSE, 5);
170     g_object_set_data(G_OBJECT(priv->window), "custom_vbox", vbox);
171     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(priv->window)->vbox),
172                                    vbox, TRUE, TRUE, 5);
173     if (choice) {
174         if (!strcmp(choice, _("Berlin"))){
175             rich_animation_additional_parametr(vbox,priv);
176         }
177         if (!strcmp(choice, _("Modern"))){
178             rich_animation_additional_parametr(vbox,priv);
179         }
180         if (!strcmp(choice, _("Matrix"))){
181             rich_animation_additional_parametr(vbox,priv);
182         }
183
184         if (!strcmp(choice, _("Accel"))){
185             rich_animation_additional_parametr(vbox,priv);
186         }
187         if (!strcmp(choice, _("Video"))){
188             additional_parametr_for_theme_video(vbox, priv);
189         }
190     }
191     gtk_widget_show(vbox);
192 }
193 /********************************************************************************/
194 void
195 changed_value_category_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
196 {
197     GtkWidget *theme_button = NULL;
198
199     theme_button = g_object_get_data(G_OBJECT(priv->window), "theme_button");
200     if (!theme_button) 
201         return;
202     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) theme_button);
203     hildon_touch_selector_remove_column(selector, 0); 
204     hildon_touch_selector_append_text_column(selector, (GtkTreeModel*)gtk_list_store_new (1, G_TYPE_STRING), TRUE);
205     fill_theme_button(priv, theme_button, (gchar *)hildon_button_get_value(HILDON_BUTTON (picker)));
206 }
207 /********************************************************************************/
208 void
209 fill_theme_button (Animation_WallpaperPrivate *priv, GtkWidget *button, gchar *category){
210
211     gchar *theme = priv->theme;
212     gint num=0;
213         hildon_button_set_value(HILDON_BUTTON (button), NULL);
214     if (!category){
215         changed_value_theme_cb(HILDON_PICKER_BUTTON (button), priv);
216         return;
217     }
218     GSList *store = priv->extheme_list;
219     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) button);
220     if (!selector)
221         selector = (HildonTouchSelector *)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     changed_value_theme_cb(HILDON_PICKER_BUTTON (button), priv);
272 }
273 /********************************************************************************/
274 GtkWidget *
275 create_themes_button (Animation_WallpaperPrivate *priv, gchar *category){
276
277     GtkWidget *button;
278     button = hildon_picker_button_new (HILDON_SIZE_AUTO, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
279     hildon_button_set_title (HILDON_BUTTON (button), _("Theme"));
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         num = 1;
323         while (store){
324             if (g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category")) == NULL){
325                 g_hash_table_insert(result_table, g_hash_table_lookup(store->data, "category"), (gint *)num);     
326                 num++;
327             }
328             if (!strcmp(theme, g_hash_table_lookup(store->data, "name"))){
329                 if (g_hash_table_lookup(store->data, "category"))
330                     hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 
331                     (gint)g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category"))); 
332                     hildon_button_set_value(HILDON_BUTTON(button), g_hash_table_lookup(store->data, "category"));
333                 break;
334             }
335
336             store = g_slist_next(store);
337         }
338     }
339     return button;
340 }
341
342 /*******************************************************************************/
343 GtkWidget *
344 create_rich_animation_button (gboolean active, gchar *name)
345 {
346     GtkWidget *button;
347     button = hildon_check_button_new (HILDON_SIZE_AUTO);
348     gtk_button_set_label (GTK_BUTTON (button), name);
349     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
350     return button;
351 }
352 /*******************************************************************************/
353 GtkWidget *
354 create_enable_button (gboolean active)
355 {
356     GtkWidget *button;
357     button = hildon_check_button_new (HILDON_SIZE_AUTO);
358     gtk_button_set_label (GTK_BUTTON (button), _("Enable"));
359     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
360     return button;
361 }
362
363 /*******************************************************************************/
364 void
365 show_settings(GtkWidget *widget, Animation_WallpaperPrivate *priv){
366     lw_main_settings(priv, NULL);
367 }
368 /*******************************************************************************/
369 void 
370 lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
371     gint result;
372     GtkWidget *window = NULL;
373     GtkWidget *theme_button1;
374     GtkWidget *theme_button2;
375     GtkWidget *theme_button3;
376     GtkWidget *theme_button4;
377     GtkWidget *hbox;
378     Animation_WallpaperPrivate *priv_temp = NULL;
379
380     window = gtk_dialog_new();
381
382     gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
383     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
384     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
385     /* Create Theme button */
386     hbox = gtk_hbox_new(FALSE, 5);
387     theme_button1 = create_image_button(1, priv->dbus_conn_session);
388     gtk_box_pack_start(GTK_BOX(hbox),
389                                    theme_button1, TRUE, TRUE, 5);
390     theme_button2 = create_image_button(2, priv->dbus_conn_session);
391     gtk_box_pack_start(GTK_BOX(hbox),
392                                    theme_button2, TRUE, TRUE, 5);
393     theme_button3 = create_image_button(3, priv->dbus_conn_session);
394     gtk_box_pack_start(GTK_BOX(hbox),
395                                    theme_button3, TRUE, TRUE, 5);
396     theme_button4 = create_image_button(4, priv->dbus_conn_session);
397     gtk_box_pack_start(GTK_BOX(hbox),
398                                    theme_button4, TRUE, TRUE, 5);
399     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
400                                    hbox, TRUE, TRUE, 5);
401
402     gtk_widget_show (theme_button1);
403     gtk_widget_show (theme_button2);
404     gtk_widget_show (theme_button3);
405     gtk_widget_show (theme_button4);
406     gtk_widget_show_all (hbox);
407     gtk_widget_show (window);
408     gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
409
410     result = gtk_dialog_run(GTK_DIALOG(window));
411
412     priv_temp = g_object_get_data(G_OBJECT(theme_button1), "priv");
413     if (priv_temp){
414         g_free(priv_temp);
415         priv_temp =NULL;
416     }
417     priv_temp = g_object_get_data(G_OBJECT(theme_button2), "priv");
418     if (priv_temp){
419         g_free(priv_temp);
420         priv_temp =NULL;
421     }
422     priv_temp = g_object_get_data(G_OBJECT(theme_button3), "priv");
423     if (priv_temp){
424         g_free(priv_temp);
425         priv_temp =NULL;
426     }
427     priv_temp = g_object_get_data(G_OBJECT(theme_button4), "priv");
428     if (priv_temp){
429         g_free(priv_temp);
430         priv_temp =NULL;
431     }
432
433
434     switch(result){
435         case GTK_RESPONSE_NO:
436             gtk_widget_destroy(window);
437             window = NULL;
438             lw_about();
439         break;
440     }
441
442
443     if (window)
444         gtk_widget_destroy(window);
445 }
446 /*******************************************************************************/
447 void
448 file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
449
450     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
451
452     if (priv->theme_string_parametr1)
453         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
454
455     gtk_widget_show_all (GTK_WIDGET (dialog));
456
457     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
458     {
459       hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
460     }
461     gtk_widget_destroy (dialog);
462
463 }
464 /*******************************************************************************/
465 void
466 rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
467     GtkWidget *rich_animation_button;
468
469     /* Create rich animation button */  
470     rich_animation_button = create_rich_animation_button(priv->rich_animation, _("Rich Animation"));
471     gtk_box_pack_start(GTK_BOX(vbox),
472                                    rich_animation_button, TRUE, TRUE, 5);
473     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
474     gtk_widget_show (rich_animation_button);
475 }
476 /*******************************************************************************/
477 void
478 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
479
480     GtkWidget *file_button;
481     GtkWidget *rich_animation_button;
482
483     if (priv->theme_string_parametr1)
484         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
485                                                    _("Play file"), priv->theme_string_parametr1);
486     else
487         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
488                                                    _("Play file")," ");
489
490     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
491
492     gtk_box_pack_start(GTK_BOX(vbox),
493                                    file_button, TRUE, TRUE, 5);
494     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);    /* Create rich animation button */  
495     rich_animation_button = create_rich_animation_button(priv->rich_animation, _("Loop"));
496     gtk_box_pack_start(GTK_BOX(vbox),
497                                    rich_animation_button, TRUE, TRUE, 5);
498     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
499
500     gtk_widget_show (file_button);
501     gtk_widget_show (rich_animation_button);
502
503 }
504 /*******************************************************************************/
505 void 
506 lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
507     gint result;
508     GtkWidget *window = NULL;
509     GtkWidget *save_button;
510     GtkWidget *theme_button;
511     GtkWidget *category_button;
512     GtkWidget *enable_button;
513     GtkWidget *vbox;
514     GtkWidget *button1 = NULL;
515     GtkWidget *rich_animation_button = NULL;
516     gint view = priv->view;
517
518     window = gtk_dialog_new();
519     priv->window = window;
520
521     gtk_window_set_title(GTK_WINDOW(window), _("View Settings"));
522     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
523     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
524
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, (gchar *)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, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
546
547     /* Pack custom vbox. It must be last widget */
548     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
549                                    vbox, TRUE, TRUE, 5);
550
551     gtk_widget_show (enable_button);
552     gtk_widget_show (category_button);
553     gtk_widget_show (theme_button);
554     gtk_widget_show (vbox);
555     gtk_widget_show (window);
556
557     save_button = gtk_dialog_add_button(GTK_DIALOG(window), _("Save"), GTK_RESPONSE_YES);
558
559     result = gtk_dialog_run(GTK_DIALOG(window));
560
561     switch(result){
562         case GTK_RESPONSE_YES:
563             /* Check theme */
564             if (hildon_button_get_value(HILDON_BUTTON (theme_button)) &&
565                 strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "")){
566                 /* Check Xsnow program */
567                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Xsnow"))){
568                     if (access("/usr/bin/xsnow", F_OK) != 0){
569                         hildon_banner_show_information(GTK_WIDGET(button), NULL, 
570                         _("You haven't got the installed package Xsnow. Please install it via using Application Manager"));
571                         /* if not scuccess exit from wthout saving */ 
572                         break;
573                     }
574                 }
575
576                 if (priv->theme)
577                     g_free(priv->theme);
578                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
579                     priv->theme = g_strdup("Berlin");
580                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern")))
581                     priv->theme = g_strdup("Modern");
582                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix")))
583                     priv->theme = g_strdup("Matrix");
584                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel")))
585                     priv->theme = g_strdup("Accel");
586                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
587                     priv->theme = g_strdup("Video");
588                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
589                     if (button1){
590                         if (priv->theme_string_parametr1)
591                             g_free(priv->theme_string_parametr1);
592                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
593                     }
594                 }
595                 /* Check external themes */
596                 GSList *store = priv->extheme_list;
597                 while (store){
598                     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _(g_hash_table_lookup(store->data, "name")))){
599                         priv->theme = g_strdup(g_hash_table_lookup(store->data, "name"));
600                         //priv->hash_theme = store->data;
601                         break;
602                     }
603                     store = g_slist_next(store);
604                 }
605
606             }
607
608             rich_animation_button = g_object_get_data(G_OBJECT(priv->window), "rich_animation_button");
609             if (rich_animation_button){
610                 /* Check rich animation */
611                 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(rich_animation_button)))
612                     priv->rich_animation = TRUE;
613                 else
614                     priv->rich_animation = FALSE;
615             }
616             /* Save config */
617             save_config(priv);
618             /* action with applet */
619             if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(enable_button))){
620                     if (!check_applet_state(view)){
621                         start_applet(view);
622                     }else {
623                         send_dbus_signal (priv,
624                               LIVEWP_SIGNAL_INTERFACE,
625                               LIVEWP_SIGNAL_PATH,
626                               LIVEWP_RELOAD_CONFIG);
627                     }
628             }else
629                     if (check_applet_state(view))
630                         stop_applet(view);
631
632             set_button_image(button, priv, check_applet_state(view));
633             break;
634         default:
635         case GTK_RESPONSE_OK:
636         break;
637         case GTK_RESPONSE_NO:
638             gtk_widget_destroy(window);
639             window = NULL;
640             lw_about();
641         break;
642     }
643     if (window)
644         gtk_widget_destroy(window);
645 }
646 /*******************************************************************************/
647 gboolean
648 check_applet_state(gint number){
649
650     HDConfigFile *config_file = NULL;
651     GKeyFile *gkey_file = NULL;
652     gchar *str = NULL;
653     gboolean result = FALSE;
654     if (number > 4 || number < 1)
655         return FALSE;
656
657     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
658     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
659     
660     gkey_file = hd_config_file_load_file(config_file, FALSE);
661     if (gkey_file && str){
662         result = g_key_file_has_group(gkey_file, str);
663         g_free(str);
664     }
665     return result;
666 }
667 /*******************************************************************************/
668 void
669 start_applet(gint number){
670
671     HDConfigFile *config_file = NULL;
672     GKeyFile *gkey_file = NULL;
673     gchar *str = NULL;
674
675     if (number > 4 || number < 1)
676         return;
677     str = g_strdup_printf("livewp-home-widget.desktop-%i",(number - 1));
678     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
679     
680     gkey_file = hd_config_file_load_file(config_file, FALSE);
681     if (gkey_file){
682         g_key_file_set_string (gkey_file, str, "X-Desktop-File", "/usr/share/applications/hildon-home/livewp-home-widget.desktop");
683         hd_config_file_save_file( config_file, gkey_file);
684         g_key_file_free(gkey_file);
685     }else
686         fprintf(stderr, "Problem with config file");
687     if (str)
688         g_free(str);
689     g_object_unref(config_file);
690 }
691 /*******************************************************************************/
692 void
693 stop_applet(gint number){
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_remove_group(gkey_file, str, NULL);  
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 }