next step for optiion one theme in all views
[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 create_themes_buttons_hbox(Animation_WallpaperPrivate *priv){
441     GtkWidget *hbox = NULL;
442     GtkWidget *area_hbox = NULL;
443     GtkWidget *theme_button1;
444     GtkWidget *theme_button2;
445     GtkWidget *theme_button3;
446     GtkWidget *theme_button4;    
447
448         
449     area_hbox = g_object_get_data(G_OBJECT(priv->window), "area_hbox");
450     if (!area_hbox)
451         return;
452     hbox = g_object_get_data(G_OBJECT(priv->window), "custom_hbox");
453     if (hbox){
454         gtk_widget_destroy(hbox);
455     }
456     hbox = gtk_hbox_new(FALSE, 0);
457     g_object_set_data(G_OBJECT(priv->window), "custom_hbox", hbox);
458     gtk_box_pack_start(GTK_BOX(area_hbox),
459                                    hbox, FALSE, FALSE, 5);
460     /* Create Theme buttons */
461     theme_button1 = create_image_button(1, priv->dbus_conn_session);
462     gtk_box_pack_start(GTK_BOX(hbox),
463                                    theme_button1, TRUE, TRUE, 0);
464     gtk_widget_show (theme_button1);
465     gtk_widget_show (hbox);
466     if (priv->one_in_all_view)
467         return;
468     theme_button2 = create_image_button(2, priv->dbus_conn_session);
469     gtk_box_pack_start(GTK_BOX(hbox),
470                                    theme_button2, TRUE, TRUE, 0);
471     gtk_widget_show (theme_button2);
472     theme_button3 = create_image_button(3, priv->dbus_conn_session);
473     gtk_box_pack_start(GTK_BOX(hbox),
474                                    theme_button3, TRUE, TRUE, 0);
475     gtk_widget_show (theme_button3);
476     theme_button4 = create_image_button(4, priv->dbus_conn_session);
477     gtk_box_pack_start(GTK_BOX(hbox),
478                                    theme_button4, TRUE, TRUE, 0);
479     gtk_widget_show (theme_button4);
480  
481 }
482 /*******************************************************************************/
483 void 
484 lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
485     gint result;
486     GtkWidget *window = NULL;
487     GtkWidget *area_hbox;
488     GtkWidget *one_in_all_view_button; 
489     gboolean one_in_all_view;
490     Animation_WallpaperPrivate *priv_temp = NULL;
491
492     window = gtk_dialog_new();
493     priv->window = window;
494
495     one_in_all_view_button = priv->one_in_all_view;
496     gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
497     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
498     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
499     one_in_all_view_button = create_bool_button(priv->one_in_all_view, _("One theme in all views"));
500     g_signal_connect (G_OBJECT (one_in_all_view_button), "toggled",  G_CALLBACK (changed_value_one_in_all_cb), priv);
501     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), one_in_all_view_button, TRUE, TRUE, 5);
502     area_hbox = gtk_vbox_new(FALSE, 2);
503     g_object_set_data(G_OBJECT(window), "area_hbox", area_hbox);
504     create_themes_buttons_hbox(priv);
505     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
506                                    area_hbox, TRUE, TRUE, 0);
507
508     gtk_widget_show (one_in_all_view_button);
509     gtk_widget_show_all (area_hbox);
510     gtk_widget_show (window);
511     gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
512
513     result = gtk_dialog_run(GTK_DIALOG(window));
514 /*
515     priv_temp = g_object_get_data(G_OBJECT(theme_button1), "priv");
516     if (priv_temp){
517         g_free(priv_temp);
518         priv_temp =NULL;
519     }
520     priv_temp = g_object_get_data(G_OBJECT(theme_button2), "priv");
521     if (priv_temp){
522         g_free(priv_temp);
523         priv_temp =NULL;
524     }
525     priv_temp = g_object_get_data(G_OBJECT(theme_button3), "priv");
526     if (priv_temp){
527         g_free(priv_temp);
528         priv_temp =NULL;
529     }
530     priv_temp = g_object_get_data(G_OBJECT(theme_button4), "priv");
531     if (priv_temp){
532         g_free(priv_temp);
533         priv_temp =NULL;
534     }
535 */
536
537     switch(result){
538         case GTK_RESPONSE_NO:
539             gtk_widget_destroy(window);
540             window = NULL;
541             lw_about();
542         break;
543     }
544
545     if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(one_in_all_view_button)) != one_in_all_view){
546         save_one_in_all_views_to_config(hildon_check_button_get_active (HILDON_CHECK_BUTTON(one_in_all_view_button)));
547         if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(one_in_all_view_button))){
548             stop_applet(2);
549             stop_applet(3);
550             stop_applet(4);
551         }
552         send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, LIVEWP_SIGNAL_PATH, LIVEWP_RELOAD_CONFIG);
553     }
554     if (window)
555         gtk_widget_destroy(window);
556 }
557 /*******************************************************************************/
558 void
559 file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
560
561     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
562
563     if (priv->theme_string_parametr1)
564         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
565
566     gtk_widget_show_all (GTK_WIDGET (dialog));
567
568     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
569     {
570       hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
571     }
572     gtk_widget_destroy (dialog);
573
574 }
575 /*******************************************************************************/
576 void
577 rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
578     GtkWidget *rich_animation_button;
579
580     /* Create rich animation button */  
581     rich_animation_button = create_bool_button(priv->rich_animation, _("Rich Animation"));
582     gtk_box_pack_start(GTK_BOX(vbox),
583                                    rich_animation_button, TRUE, TRUE, 5);
584     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
585     gtk_widget_show (rich_animation_button);
586 }
587 /*******************************************************************************/
588 void
589 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
590
591     GtkWidget *file_button;
592     GtkWidget *rich_animation_button;
593
594     if (priv->theme_string_parametr1)
595         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
596                                                    _("Play file"), priv->theme_string_parametr1);
597     else
598         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
599                                                    _("Play file")," ");
600
601     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
602
603     gtk_box_pack_start(GTK_BOX(vbox),
604                                    file_button, TRUE, TRUE, 5);
605     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);    
606     /* Create rich animation button */  
607     rich_animation_button = create_bool_button(priv->rich_animation, _("Loop"));
608     gtk_box_pack_start(GTK_BOX(vbox),
609                                    rich_animation_button, TRUE, TRUE, 5);
610     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
611     /* Create sound button */  
612 #if 0
613
614     /* Doesn't work in real device. Hardware volume buttons can to change volume for mutted track */
615     sound_button = create_bool_button(priv->theme_bool_parametr1, _("Sound"));
616     gtk_box_pack_start(GTK_BOX(vbox),
617                                    sound_button, TRUE, TRUE, 5);
618     g_object_set_data(G_OBJECT(priv->window), "sound_button", sound_button);
619     gtk_widget_show (sound_button);
620 #endif
621     gtk_widget_show (file_button);
622     gtk_widget_show (rich_animation_button);
623
624 }
625 /*******************************************************************************/
626 void
627 show_problem_package (GtkWidget *widget, gchar *package_name){
628     gchar *text;
629     text = g_strdup_printf(_("You haven't got the installed package %s. Please install it via using Application Manager"), package_name);
630     hildon_banner_show_information(GTK_WIDGET(widget), NULL, text);
631     g_free(text);
632 }
633 /*******************************************************************************/
634 void 
635 lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
636     gint result;
637     GtkWidget *window = NULL;
638     GtkWidget *scrolled_window = NULL;
639     GtkWidget *save_button;
640     GtkWidget *theme_button;
641     GtkWidget *category_button;
642     GtkWidget *enable_button;
643     GtkWidget *vbox;
644     GtkWidget *area_vbox;
645     GtkWidget *button1 = NULL;
646     GtkWidget *rich_animation_button = NULL;
647     gint view = priv->view;
648
649     window = gtk_dialog_new();
650     priv->window = window;
651
652     gtk_window_set_title(GTK_WINDOW(window), _("View Settings"));
653     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
654     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
655
656     /* Create panarea */
657     area_vbox = gtk_vbox_new(FALSE, 2);
658     g_object_set_data(G_OBJECT(window), "area_vbox", area_vbox);
659     scrolled_window = hildon_pannable_area_new ();
660     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (scrolled_window), GTK_WIDGET (area_vbox));
661     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
662                                    scrolled_window, FALSE, FALSE, 0);
663
664     gtk_widget_set_size_request(scrolled_window, -1, 370);
665
666     /* Create Enable button */
667     enable_button = create_enable_button(check_applet_state(view)); 
668     gtk_box_pack_start(GTK_BOX(area_vbox),
669                                    enable_button, FALSE, FALSE, 5);
670     /* Create Category button */
671     category_button = create_categories_button(priv);
672     g_object_set_data(G_OBJECT(window), "category_button", category_button);
673     g_signal_connect (G_OBJECT (category_button), "value-changed",  G_CALLBACK (changed_value_category_cb), priv);
674     gtk_box_pack_start(GTK_BOX(area_vbox),
675                                    category_button, FALSE, FALSE, 5);
676     /* Create Custom vbox */
677     vbox = gtk_vbox_new (FALSE, 5);
678     g_object_set_data(G_OBJECT(window), "custom_vbox", vbox);
679
680     /* Create Theme button */
681     theme_button = create_themes_button(priv, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
682     g_object_set_data(G_OBJECT(window), "theme_button", theme_button);
683     g_signal_connect (G_OBJECT (theme_button), "value-changed",  G_CALLBACK (changed_value_theme_cb), priv);
684     gtk_box_pack_start(GTK_BOX(area_vbox),
685                                    theme_button, FALSE, FALSE, 5);
686     fill_theme_button(priv, theme_button, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
687
688     /* Pack custom vbox. It must be last widget */
689     gtk_box_pack_start(GTK_BOX(area_vbox),
690                                    vbox, FALSE, FALSE, 5);
691
692     gtk_widget_show (enable_button);
693     gtk_widget_show (category_button);
694     gtk_widget_show (theme_button);
695     gtk_widget_show (vbox);
696     gtk_widget_show (area_vbox);
697     gtk_widget_show (scrolled_window);
698     gtk_widget_show (window);
699
700     save_button = gtk_dialog_add_button(GTK_DIALOG(window), _("Save"), GTK_RESPONSE_YES);
701
702     result = gtk_dialog_run(GTK_DIALOG(window));
703
704     switch(result){
705         case GTK_RESPONSE_YES:
706             /* Check theme */
707             if (hildon_button_get_value(HILDON_BUTTON (theme_button)) &&
708                 strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "")){
709                 /* Check Xsnow program */
710                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Xsnow"))){
711                     if (access("/usr/bin/xsnow", F_OK) != 0){
712                         show_problem_package(button, "Xsnow");
713                         /* if not scuccess exit from wthout saving */ 
714                         break;
715                     }
716                 }
717                 /* Check Shermans program */
718                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Shermans Aquarium")){
719                     if (access("/usr/bin/shermans", F_OK) != 0){
720                         show_problem_package(button,"'Sherman's Aquarium'");
721                         /* if not scuccess exit from wthout saving */ 
722                         break;
723                     }
724                 }
725                 /* Check Conky program */
726                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Conky")){
727                     if (access("/usr/bin/conky", F_OK) != 0){
728                         show_problem_package(button,"'Conky'");
729                         /* if not scuccess exit from wthout saving */ 
730                         break;
731                     }
732                 }
733                 /* Check Orrery program */
734                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Orrery")){
735                     if (access("/opt/maemo/usr/bin/orrery", F_OK) != 0){
736                         show_problem_package(button,"'Orrery'");
737                         /* if not scuccess exit from wthout saving */ 
738                         break;
739                     }
740                 }
741                 /* Check Colorflood program */
742                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "Colorflood")){
743                     if (access("/usr/bin/colorflood", F_OK) != 0){
744                         show_problem_package(button,"'Colorflood'");
745                         /* if not scuccess exit from wthout saving */ 
746                         break;
747                     }
748                 }
749
750                 if (priv->theme)
751                     g_free(priv->theme);
752                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
753                     priv->theme = g_strdup("Berlin");
754                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern")))
755                     priv->theme = g_strdup("Modern");
756                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix")))
757                     priv->theme = g_strdup("Matrix");
758                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel")))
759                     priv->theme = g_strdup("Accel");
760                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
761                     priv->theme = g_strdup("Video");
762                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
763                     if (button1){
764                         if (priv->theme_string_parametr1)
765                             g_free(priv->theme_string_parametr1);
766                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
767                     }
768                     /* 
769                     temp_button = g_object_get_data(G_OBJECT(priv->window), "sound_button");
770                     if (temp_button){
771                         if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(temp_button)))
772                             priv->theme_bool_parametr1 = TRUE;
773                         else
774                             priv->theme_bool_parametr1 = FALSE;
775                     }
776                     */
777                 }
778                 /* Check external themes */
779                 GSList *store = priv->extheme_list;
780                 while (store){
781                     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _(g_hash_table_lookup(store->data, "name")))){
782                         priv->theme = g_strdup(g_hash_table_lookup(store->data, "name"));
783                         //priv->hash_theme = store->data;
784                         break;
785                     }
786                     store = g_slist_next(store);
787                 }
788
789             }
790
791             rich_animation_button = g_object_get_data(G_OBJECT(priv->window), "rich_animation_button");
792             if (rich_animation_button){
793                 /* Check rich animation */
794                 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(rich_animation_button)))
795                     priv->rich_animation = TRUE;
796                 else
797                     priv->rich_animation = FALSE;
798             }
799             /* Save config */
800             save_config(priv);
801             /* action with applet */
802             if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(enable_button))){
803                     if (!check_applet_state(view)){
804                         start_applet(view);
805                     }else {
806                         send_dbus_signal (priv,
807                               LIVEWP_SIGNAL_INTERFACE,
808                               LIVEWP_SIGNAL_PATH,
809                               LIVEWP_RELOAD_CONFIG);
810                     }
811             }else
812                     if (check_applet_state(view))
813                         stop_applet(view);
814
815             set_button_image(button, priv, check_applet_state(view));
816             break;
817         default:
818         case GTK_RESPONSE_OK:
819         break;
820         case GTK_RESPONSE_NO:
821             gtk_widget_destroy(window);
822             window = NULL;
823             lw_about();
824         break;
825     }
826     if (window)
827         gtk_widget_destroy(window);
828 }
829 /*******************************************************************************/
830 gboolean
831 check_applet_state(gint number){
832
833     HDConfigFile *config_file = NULL;
834     GKeyFile *gkey_file = NULL;
835     gchar *str = NULL;
836     gboolean result = FALSE;
837     if (number > 4 || number < 1)
838         return FALSE;
839
840     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
841     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
842     
843     gkey_file = hd_config_file_load_file(config_file, FALSE);
844     if (gkey_file && str){
845         result = g_key_file_has_group(gkey_file, str);
846         g_free(str);
847     }
848     return result;
849 }
850 /*******************************************************************************/
851 void
852 start_applet(gint number){
853
854     HDConfigFile *config_file = NULL;
855     GKeyFile *gkey_file = NULL;
856     gchar *str = NULL;
857
858     if (number > 4 || number < 1)
859         return;
860     str = g_strdup_printf("livewp-home-widget.desktop-%i",(number - 1));
861     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
862     
863     gkey_file = hd_config_file_load_file(config_file, FALSE);
864     if (gkey_file){
865         g_key_file_set_string (gkey_file, str, "X-Desktop-File", "/usr/share/applications/hildon-home/livewp-home-widget.desktop");
866         hd_config_file_save_file( config_file, gkey_file);
867         g_key_file_free(gkey_file);
868     }else
869         fprintf(stderr, "Problem with config file");
870     if (str)
871         g_free(str);
872     g_object_unref(config_file);
873 }
874 /*******************************************************************************/
875 void
876 stop_applet(gint number){
877     HDConfigFile *config_file = NULL;
878     GKeyFile *gkey_file = NULL;
879     gchar *str = NULL;
880
881     if (number > 4 || number < 1)
882         return;
883     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
884     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
885     
886     gkey_file = hd_config_file_load_file(config_file, FALSE);
887     if (gkey_file){
888          g_key_file_remove_group(gkey_file, str, NULL);  
889         hd_config_file_save_file( config_file, gkey_file);
890         g_key_file_free(gkey_file);
891     }else
892         fprintf(stderr, "Problem with config file");
893     if (str)
894         g_free(str);
895     g_object_unref(config_file);
896
897 }