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