started slideshow
[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 General Public License
11  * as published by the Free Software Foundation; either version 2 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 themes Matrix, Fifteen \nand for icons Andrew Zhilin\n \
42 Translators:\n \
43 Finnish - Marko Vertainen\n \
44 Spain  - Alejandro López\n \
45 Italian  - Emanuele Cassioli\n \
46 Dutch - Roland van Tilburg (aka ROLAN900D) \n \
47 Russian - Tanya Makova \n \
48           Vlad Vasiliev\n"), VERSION);
49
50     label_about = gtk_label_new (about_string);
51     gtk_box_pack_start (GTK_BOX (vbox), label_about, FALSE, FALSE, 0);
52     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
53                                    vbox, TRUE, TRUE, 0);
54     gtk_widget_show (label_about);
55     gtk_widget_show (vbox);
56     gtk_widget_show (window);
57     gtk_dialog_run(GTK_DIALOG(window));
58
59 }
60 /*******************************************************************************/
61 GtkWidget *
62 create_category_selector (Animation_WallpaperPrivate *priv){
63     GtkWidget *selector;
64     GSList *store = priv->extheme_list;
65     GHashTable *result_table = NULL;
66
67     selector = hildon_touch_selector_new_text();
68
69
70     result_table = g_hash_table_new(g_str_hash, g_str_equal);
71     while (store){
72         if (!g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category"))){
73             g_hash_table_insert(result_table, g_hash_table_lookup(store->data, "category"), (gint *)1);
74             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), g_hash_table_lookup(store->data, "category"));
75         }
76         store = g_slist_next(store);
77     }
78
79     /* Add Xscreensaver for install message */
80     if (!g_hash_table_lookup(result_table,"Xscreensaver")){
81             g_hash_table_insert(result_table, "Xscreensaver", (gint *)1);
82             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "Xscreensaver");
83     }
84     /* Add LiveWallpaper to selector */
85     if (!g_hash_table_lookup(result_table,"LiveWallpaper")){
86         hildon_touch_selector_prepend_text (HILDON_TOUCH_SELECTOR (selector), "LiveWallpaper" );
87     }
88
89     return selector;
90 }
91
92 /*******************************************************************************/
93 void
94 theme_button_clicked(GtkWidget *button, GdkEventButton *event, Animation_WallpaperPrivate *priv){
95     lw_theme_settings(GTK_WIDGET(button), priv);
96 }
97 /********************************************************************************/
98 void
99 set_button_image(GtkWidget * button, Animation_WallpaperPrivate *priv, gboolean enable){
100     GtkWidget * image = NULL;
101     GdkPixbuf * pixbuf = NULL;
102     gchar *str = NULL;
103     gchar *icon_on = NULL;
104     gchar *icon_off = NULL;
105     GSList *store = priv->extheme_list;
106
107     while (store){
108         if (!strcmp(priv->theme, g_hash_table_lookup(store->data, "name"))){
109             icon_on = g_strdup(g_hash_table_lookup(store->data, "icon_on"));
110             icon_off = g_strdup(g_hash_table_lookup(store->data, "icon_off"));
111             break;
112         }
113         store = (GSList *)g_list_next(store);
114     }
115     if (enable){
116         if (icon_on)
117             str = g_strdup_printf("%s", icon_on);
118         else
119             str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
120                             priv->theme, "icon.png");
121             if (access(str, F_OK) != 0){
122                 g_free(str);
123                 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
124                             "Video", "icon.png");
125             }
126
127     }else {
128         if (icon_off)
129             str = g_strdup_printf("%s", icon_off);
130         else
131             str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
132                             priv->theme, "icond.png");
133             if (access(str, F_OK) != 0){
134                 g_free(str);
135                 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
136                             "Video", "icond.png");
137             }
138     }
139     pixbuf = gdk_pixbuf_new_from_file_at_size (str,
140                                                  124,
141                                                  79,
142                                                  NULL);
143     if (str)
144         g_free(str);
145     if (icon_on)
146         g_free(icon_on);
147     if (icon_off)
148         g_free(icon_off);
149     if (pixbuf){
150         image = gtk_image_new_from_pixbuf (pixbuf);
151         g_object_unref(G_OBJECT(pixbuf));
152     }
153
154     //hildon_button_set_image (HILDON_BUTTON (button), image);
155     GList *list = gtk_container_get_children(GTK_CONTAINER (button));
156     if (list){
157         gtk_container_remove(GTK_CONTAINER (button), list->data);
158     }
159     gtk_container_add(GTK_CONTAINER (button), image);
160     gtk_widget_show(image);
161     gtk_widget_show(button);
162
163 }
164 /********************************************************************************/
165 GtkWidget *
166 create_image_button (gint view, DBusConnection *conn_sess){
167     GtkWidget *event_box;
168
169     Animation_WallpaperPrivate *priv = g_new0(Animation_WallpaperPrivate, 1);
170     /* Add external themes to priv */
171     priv->extheme_list = get_list_exthemes();
172
173     priv->view = view;
174     priv->theme_string_parametr1 = NULL;
175     priv->dbus_conn_session = conn_sess;
176     read_config(priv);
177
178     event_box = gtk_event_box_new();
179     g_object_set_data(G_OBJECT(event_box), "view", GINT_TO_POINTER(view));
180     g_object_set_data(G_OBJECT(event_box), "priv", priv);
181     set_button_image(event_box, priv, check_applet_state(view));
182     g_signal_connect(G_OBJECT (event_box), "button_release_event", G_CALLBACK(theme_button_clicked), priv);
183     return event_box;
184 #if 0
185     button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
186                                     HILDON_BUTTON_ARRANGEMENT_VERTICAL);
187     g_object_set_data(G_OBJECT(button), "view", GINT_TO_POINTER(view));
188     g_object_set_data(G_OBJECT(button), "priv", priv);
189     set_button_image(button, priv, check_applet_state(view));
190     g_signal_connect(button, "clicked", G_CALLBACK(theme_button_clicked), priv);
191     hildon_button_set_image_position (HILDON_BUTTON (button), GTK_POS_RIGHT);
192     return button;
193 #endif
194 }
195 /********************************************************************************/
196 void
197 changed_value_one_in_all_cb (GtkWidget *toggle, Animation_WallpaperPrivate *priv)
198 {
199     priv->one_in_all_view = hildon_check_button_get_active((HildonCheckButton *)toggle);
200     create_themes_buttons_hbox(priv);
201     fprintf(stderr, "changed_value_one_in_all_cb\n");
202 }
203 /********************************************************************************/
204 void
205 changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
206 {
207     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
208     GtkWidget *vbox = NULL;
209     GtkWidget *area_vbox = NULL;
210
211     area_vbox = g_object_get_data(G_OBJECT(priv->window), "area_vbox");
212     if (!area_vbox)
213         return;
214     vbox = g_object_get_data(G_OBJECT(priv->window), "custom_vbox");
215     if (vbox){
216         gtk_widget_destroy(vbox);
217     }
218     vbox = gtk_vbox_new (TRUE, 5);
219     g_object_set_data(G_OBJECT(priv->window), "custom_vbox", vbox);
220     gtk_box_pack_start(GTK_BOX(area_vbox),
221                                    vbox, FALSE, FALSE, 5);
222     if (choice) {
223         if (!strcmp(choice, _("Berlin"))){
224             rich_animation_additional_parametr(vbox,priv);
225         }
226         if (!strcmp(choice, _("Modern"))){
227             rich_animation_additional_parametr(vbox,priv);
228         }
229         if (!strcmp(choice, _("Matrix"))){
230             rich_animation_additional_parametr(vbox,priv);
231         }
232
233         if (!strcmp(choice, _("Accel"))){
234             rich_animation_additional_parametr(vbox,priv);
235         }
236         if (!strcmp(choice, _("Video"))){
237             additional_parametr_for_theme_video(vbox, priv);
238         }
239         if (!strcmp(choice, _("Flash"))){
240             additional_parametr_for_theme_flash(vbox, priv);
241         }
242         if (!strcmp(choice, _("Slideshow"))){
243             additional_parametr_for_theme_slideshow(vbox, priv);
244         }
245
246     }
247     gtk_widget_show(vbox);
248 }
249 /********************************************************************************/
250 void
251 changed_value_category_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
252 {
253     GtkWidget *theme_button = NULL;
254     GtkWidget *confirm;
255     gchar *text;
256
257
258     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
259
260     theme_button = g_object_get_data(G_OBJECT(priv->window), "theme_button");
261     if (!theme_button)
262         return;
263     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) theme_button);
264     hildon_touch_selector_remove_column(selector, 0);
265     hildon_touch_selector_append_text_column(selector, (GtkTreeModel*)gtk_list_store_new (1, G_TYPE_STRING), TRUE);
266     fill_theme_button(priv, theme_button, (gchar *)hildon_button_get_value(HILDON_BUTTON (picker)));
267     /* check xscreensaver category */
268     if (choice){
269         if (!strcmp(choice,"Xscreensaver"))
270             if (access("/usr/bin/xscreensaver", F_OK) != 0){
271                 text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),  "Xscreensaver");
272                 confirm = hildon_note_new_confirmation(GTK_WINDOW(priv->window), text);
273                 if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))){
274                      gchar * cmd = g_strdup_printf("dbus-send --print-reply --dest=com.nokia.osso_browser /com/nokia/osso_browser/service com.nokia.osso_browser.open_new_window string:%s", "http://maemo.org/downloads/product/raw/Maemo5/xscreensaver/?get_installfile");
275                      fprintf(stderr, "system %s\n", cmd);
276                      system(cmd);
277                      g_free(cmd);
278                  }
279                  g_free(text);
280                  gtk_widget_destroy(confirm);
281             }
282     }
283 }
284 /********************************************************************************/
285 void
286 fill_theme_button (Animation_WallpaperPrivate *priv, GtkWidget *button, gchar *category){
287
288     gchar *theme = priv->theme;
289     gboolean flag = False;
290     gint num=0;
291         hildon_button_set_value(HILDON_BUTTON (button), NULL);
292     if (!category){
293         changed_value_theme_cb(HILDON_PICKER_BUTTON (button), priv);
294         return;
295     }
296     GSList *store = priv->extheme_list;
297     HildonTouchSelector * selector =  hildon_picker_button_get_selector((HildonPickerButton *) button);
298     if (!selector)
299         selector = (HildonTouchSelector *)hildon_touch_selector_new_text ();
300
301     hildon_button_set_value(HILDON_BUTTON(button), NULL);
302     if (!strcmp(category, "LiveWallpaper")){
303         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Berlin"));
304         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Modern"));
305         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Matrix"));
306         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Accel"));
307         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Video"));
308         hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Slideshow"));
309         num = 6;
310         if (theme){
311             if (!strcmp(theme, "Berlin")){
312                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
313                 hildon_button_set_value(HILDON_BUTTON(button), _("Berlin"));
314             }
315             if (!strcmp(theme, "Modern")){
316                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 1);
317                 hildon_button_set_value(HILDON_BUTTON(button), _("Modern"));
318             }
319             if (!strcmp(theme, "Matrix")){
320                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 2);
321                 hildon_button_set_value(HILDON_BUTTON(button), _("Matrix"));
322             }
323             if (!strcmp(theme, "Accel")){
324                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 3);
325                 hildon_button_set_value(HILDON_BUTTON(button), _("Accel"));
326             }
327             if (!strcmp(theme, "Video")){
328                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 4);
329                 hildon_button_set_value(HILDON_BUTTON(button), _("Video"));
330             }
331             if (!strcmp(theme, "Slideshow")){
332                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 4);
333                 hildon_button_set_value(HILDON_BUTTON(button), _("Slideshow"));
334             }
335        }
336     }
337     while (store){
338         if (!g_hash_table_lookup(store->data, "category"))
339             continue;
340         if (!strcmp(g_hash_table_lookup(store->data, "category"), category)){
341             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), g_hash_table_lookup(store->data, "name"));
342             if (!strcmp(theme, g_hash_table_lookup(store->data, "name"))){
343                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, num);
344                 hildon_button_set_value(HILDON_BUTTON(button), _(g_hash_table_lookup(store->data, "name")));
345             }
346             num++;
347         }
348         store = g_slist_next(store);
349     }
350     /* Added Shreman's Aquarium for message */
351     if (!strcmp(category, "Unknown")){
352         store = priv->extheme_list;
353         while (store){
354             if (!strcmp("Shermans Aquarium" , g_hash_table_lookup(store->data, "name"))){
355                 flag = TRUE;
356                 break;
357             }
358             store = g_slist_next(store);
359         }
360         if (!flag)
361             hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "Shermans Aquarium");
362     }
363
364         hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
365                                                        HILDON_TOUCH_SELECTOR (selector));
366
367     changed_value_theme_cb(HILDON_PICKER_BUTTON (button), priv);
368 }
369 /********************************************************************************/
370 GtkWidget *
371 create_themes_button (Animation_WallpaperPrivate *priv, gchar *category){
372
373     GtkWidget *button;
374     button = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
375     hildon_button_set_title (HILDON_BUTTON (button), _("Theme"));
376
377
378     return button;
379 }
380 /********************************************************************************/
381 GtkWidget *
382 create_categories_button (Animation_WallpaperPrivate *priv){
383
384     GtkWidget *button;
385     GtkWidget *selector;
386     gchar *theme = priv->theme;
387     gint num=0;
388     GHashTable *result_table = NULL;
389
390     result_table = g_hash_table_new(g_str_hash, g_str_equal);
391     selector = create_category_selector(priv);
392     button = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
393     hildon_button_set_title (HILDON_BUTTON (button), _("Category"));
394     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
395                                                        HILDON_TOUCH_SELECTOR (selector));
396     if (theme) {
397         if (!strcmp(theme, "Berlin")){
398             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
399             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
400         }
401         if (!strcmp(theme, "Modern")){
402             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
403             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
404         }
405         if (!strcmp(theme, "Matrix")){
406             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
407             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
408         }
409         if (!strcmp(theme, "Accel")){
410             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
411             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
412         }
413         if (!strcmp(theme, "Video")){
414             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
415             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
416         }
417         if (!strcmp(theme, "Slideshow")){
418                 hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
419             hildon_button_set_value(HILDON_BUTTON(button), "LiveWallpaper");
420         }
421         GSList *store = priv->extheme_list;
422         num = 1;
423         while (store){
424             if (g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category")) == NULL){
425                 g_hash_table_insert(result_table, g_hash_table_lookup(store->data, "category"), (gint *)num);
426                 num++;
427             }
428             if (!strcmp(theme, g_hash_table_lookup(store->data, "name"))){
429                 if (g_hash_table_lookup(store->data, "category")){
430                     hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0,
431                     (gint)g_hash_table_lookup(result_table, g_hash_table_lookup(store->data, "category")));
432                     hildon_button_set_value(HILDON_BUTTON(button), g_hash_table_lookup(store->data, "category"));
433                 }
434                 break;
435             }
436
437             store = g_slist_next(store);
438         }
439     }
440     return button;
441 }
442
443 /*******************************************************************************/
444 GtkWidget *
445 create_bool_button (gboolean active, gchar *name)
446 {
447     GtkWidget *button;
448     button = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
449     gtk_button_set_label (GTK_BUTTON (button), name);
450     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
451     return button;
452 }
453 /*******************************************************************************/
454 GtkWidget *
455 create_enable_button (gboolean active)
456 {
457     GtkWidget *button;
458     button = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
459     gtk_button_set_label (GTK_BUTTON (button), _("Enable"));
460     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
461     return button;
462 }
463
464 /*******************************************************************************/
465 void
466 show_settings(GtkWidget *widget, Animation_WallpaperPrivate *priv){
467     lw_main_settings(priv, NULL);
468 }
469 /*******************************************************************************/
470 void
471 create_themes_buttons_hbox(Animation_WallpaperPrivate *priv){
472     GtkWidget *hbox = NULL;
473     GtkWidget *area_hbox = NULL;
474     GtkWidget *theme_button;
475     GSList *stlist = NULL;
476     GConfClient *gconf_client = NULL;
477     GConfValue *value = NULL;
478     guint count_of_view = 1;
479     guint i;
480
481
482     area_hbox = g_object_get_data(G_OBJECT(priv->window), "area_hbox");
483     if (!area_hbox)
484         return;
485     hbox = g_object_get_data(G_OBJECT(priv->window), "custom_hbox");
486     if (hbox){
487         gtk_widget_destroy(hbox);
488     }
489
490     hbox = gtk_hbox_new(FALSE, 0);
491     g_object_set_data(G_OBJECT(priv->window), "custom_hbox", hbox);
492     gtk_box_pack_start(GTK_BOX(area_hbox),
493                                    hbox, FALSE, FALSE, 5);
494     /* Create Theme buttons */
495     theme_button = create_image_button(1, priv->dbus_conn_session);
496     gtk_box_pack_start(GTK_BOX(hbox),
497                                    theme_button, TRUE, TRUE, 10);
498     gtk_widget_show (theme_button);
499     gtk_widget_show (hbox);
500     if (priv->one_in_all_view)
501         return;
502
503     gconf_client = gconf_client_get_default();
504     if (!gconf_client)
505         return;
506
507     stlist = gconf_client_get_list(gconf_client,
508                                        "/apps/osso/hildon-desktop/views/active",
509                                        GCONF_VALUE_INT, NULL);
510     if (stlist){
511         count_of_view = g_slist_length(stlist);
512         g_slist_free(stlist);
513     }else
514         count_of_view = 4;
515     g_object_unref(gconf_client);
516     for (i = 2; i < count_of_view + 1; i++){
517         theme_button = create_image_button(i, priv->dbus_conn_session);
518         gtk_box_pack_start(GTK_BOX(hbox),
519                                    theme_button, TRUE, TRUE, 10);
520         gtk_widget_show (theme_button);
521     }
522 }
523 /*******************************************************************************/
524 void
525 lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
526     gint result;
527     GtkWidget *window = NULL;
528     GtkWidget *banner = NULL;
529     GtkWidget *area_hbox;
530     GtkWidget *scrolled_window;
531     GtkWidget *one_in_all_view_button;
532     gboolean one_in_all_view;
533     gint i;
534
535     window = gtk_dialog_new();
536     priv->window = window;
537
538     one_in_all_view = priv->one_in_all_view;
539     gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
540     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
541     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
542     one_in_all_view_button = create_bool_button(priv->one_in_all_view, _("One theme in all views"));
543     g_signal_connect (G_OBJECT (one_in_all_view_button), "toggled",  G_CALLBACK (changed_value_one_in_all_cb), priv);
544     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), one_in_all_view_button, TRUE, TRUE, 5);
545     area_hbox = gtk_vbox_new(FALSE, 2);
546     g_object_set_data(G_OBJECT(window), "area_hbox", area_hbox);
547
548     create_themes_buttons_hbox(priv);
549     scrolled_window = hildon_pannable_area_new ();
550     g_object_set (G_OBJECT (scrolled_window), "mov-mode", HILDON_MOVEMENT_MODE_HORIZ, NULL);
551     g_object_set (G_OBJECT (scrolled_window), "hscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
552     g_object_set (G_OBJECT (scrolled_window), "scrollbar-fade-delay", 27000, NULL);
553     g_object_set (G_OBJECT (scrolled_window), "indicator-width", 28, NULL);
554     gtk_widget_set_size_request(scrolled_window, -1, 120);
555     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (scrolled_window), GTK_WIDGET (area_hbox));
556
557     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
558                                    scrolled_window, TRUE, TRUE, 0);
559
560     gtk_widget_show(scrolled_window);
561     gtk_widget_show(one_in_all_view_button);
562     gtk_widget_show_all(area_hbox);
563     gtk_widget_show(window);
564     gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
565
566     result = gtk_dialog_run(GTK_DIALOG(window));
567
568     switch(result){
569         case GTK_RESPONSE_NO:
570             gtk_widget_destroy(window);
571             window = NULL;
572             lw_about();
573         break;
574     }
575
576     if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(one_in_all_view_button)) != one_in_all_view){
577         save_one_in_all_views_to_config(hildon_check_button_get_active (HILDON_CHECK_BUTTON(one_in_all_view_button)));
578         //fprintf(stderr,"CHECK!!!!!!!!!!!!!!\n");
579         banner = hildon_banner_show_information (window, NULL, _("Livewallpaper is reloading..."));
580         hildon_banner_set_timeout(HILDON_BANNER(banner), 3000);
581         for (i=1;i<10;i++)
582             stop_applet(i);
583         g_timeout_add(3000, (GSourceFunc)cb_timeout_settings, window);
584     }else{
585         if (window)
586             gtk_widget_destroy(window);
587     }
588 }
589 /*******************************************************************************/
590 gboolean
591 cb_timeout_settings(GtkWidget *window){
592
593     gint i;
594     for (i=1;i<10;i++)
595         start_applet(i);
596
597     if (window)
598         gtk_widget_destroy(window);
599     return FALSE;
600 }
601 /*******************************************************************************/
602 void
603 file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
604
605     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
606
607     if (priv->theme_string_parametr1)
608         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
609
610     gtk_widget_show_all (GTK_WIDGET (dialog));
611
612     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
613     {
614       hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
615     }
616     gtk_widget_destroy (dialog);
617
618 }
619 /*******************************************************************************/
620 void
621 folder_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
622
623     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
624
625     if (priv->theme_string_parametr1)
626         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
627
628     gtk_widget_show_all (GTK_WIDGET (dialog));
629
630     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
631     {
632         hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
633     }
634     gtk_widget_destroy (dialog);
635
636 }
637 /*******************************************************************************/
638 void
639 rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
640     GtkWidget *rich_animation_button;
641
642     /* Create rich animation button */
643     rich_animation_button = create_bool_button(priv->rich_animation, _("Rich Animation"));
644     gtk_box_pack_start(GTK_BOX(vbox),
645                                    rich_animation_button, TRUE, TRUE, 5);
646     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
647     gtk_widget_show (rich_animation_button);
648 }
649 /*******************************************************************************/
650 void
651 link_button_clicked(GtkButton *button, gchar *url){
652
653   gchar * cmd = g_strdup_printf("dbus-send --print-reply --dest=com.nokia.osso_browser \
654          /com/nokia/osso_browser/service com.nokia.osso_browser.open_new_window string:%s", url);
655   fprintf(stderr, "system %s\n", cmd);
656   system(cmd);
657   g_free(cmd);
658 }
659 /*******************************************************************************/
660 void
661 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
662
663     GtkWidget *file_button;
664     GtkWidget *link_button;
665     GtkWidget *smoothing_button;
666     GtkWidget *rich_animation_button;
667
668     if (priv->theme_string_parametr1)
669         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
670                                                    _("Play file"), priv->theme_string_parametr1);
671     else
672         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
673                                                    _("Play file")," ");
674
675     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
676
677     gtk_box_pack_start(GTK_BOX(vbox),
678                                    file_button, TRUE, TRUE, 5);
679     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);
680     /* Create rich animation button */
681     rich_animation_button = create_bool_button(priv->rich_animation, _("Loop"));
682     gtk_box_pack_start(GTK_BOX(vbox),
683                                    rich_animation_button, TRUE, TRUE, 5);
684     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
685     /* Create Smoothing button */
686
687     smoothing_button = create_bool_button(priv->theme_bool_parametr1, _("Smoothing (Need more memory)"));
688     gtk_box_pack_start(GTK_BOX(vbox),
689                                    smoothing_button, TRUE, TRUE, 5);
690     g_object_set_data(G_OBJECT(priv->window), "smoothing_button", smoothing_button);
691
692     link_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
693                                                    _("Press me for"), _("download more videos"));
694
695     g_signal_connect (link_button, "clicked", G_CALLBACK (link_button_clicked), "http://talk.maemo.org/showthread.php?t=60185");
696     gtk_box_pack_start(GTK_BOX(vbox),
697                                    link_button, TRUE, TRUE, 5);
698
699     gtk_widget_show (smoothing_button);
700     gtk_widget_show (file_button);
701     gtk_widget_show (rich_animation_button);
702     gtk_widget_show (link_button);
703
704 }
705 /*******************************************************************************/
706 void
707 additional_parametr_for_theme_flash(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
708
709     GtkWidget *file_button;
710     GtkWidget *link_button;
711     GtkWidget *smoothing_button;
712     GtkWidget *rich_animation_button;
713
714     if (priv->theme_string_parametr1)
715         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
716                                                    _("Play file"), priv->theme_string_parametr1);
717     else
718         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
719                                                    _("Play file")," ");
720
721     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
722
723     gtk_box_pack_start(GTK_BOX(vbox),
724                                    file_button, TRUE, TRUE, 5);
725     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);
726     gtk_widget_show (file_button);
727 }
728 /*******************************************************************************/
729 void
730 additional_parametr_for_theme_slideshow(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
731
732     GtkWidget *file_button;
733     GtkWidget *link_button;
734     GtkWidget *smoothing_button;
735     GtkWidget *rich_animation_button;
736
737     if (priv->theme_string_parametr1)
738         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
739                                                    _("Folder with images"), priv->theme_string_parametr1);
740     else
741         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
742                                                    _("Folder with images")," ");
743
744     g_signal_connect (file_button, "clicked", G_CALLBACK (folder_button_clicked), priv);
745
746     gtk_box_pack_start(GTK_BOX(vbox),
747                                    file_button, TRUE, TRUE, 5);
748     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);
749     gtk_widget_show (file_button);
750 }
751 /*******************************************************************************/
752
753 void
754 show_problem_package (GtkWidget *widget, gchar *package_name){
755     gchar *text;
756     text = g_strdup_printf(_("You haven't got the installed package %s. Please install it via using Application Manager"), package_name);
757     hildon_banner_show_information(GTK_WIDGET(widget), NULL, text);
758     g_free(text);
759 }
760 /*******************************************************************************/
761 void
762 show_duplicate_theme (GtkWidget *widget, gchar *theme_name){
763     gchar *text;
764     text = g_strdup_printf(_("Theme %s has already been selected"), theme_name);
765     hildon_banner_show_information(GTK_WIDGET(widget), NULL, text);
766     g_free(text);
767 }
768
769 /*******************************************************************************/
770 void
771 lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
772     gint result;
773     GtkWidget *window = NULL;
774     GtkWidget *scrolled_window = NULL;
775     GtkWidget *save_button;
776     GtkWidget *theme_button;
777     GtkWidget *category_button;
778     GtkWidget *enable_button;
779     GtkWidget *vbox;
780     GtkWidget *area_vbox;
781     GtkWidget *temp_button;
782     GtkWidget *button1 = NULL;
783     GtkWidget *rich_animation_button = NULL;
784     GtkWidget *confirm;
785     gint view = priv->view;
786     gint count;
787     gchar *text;
788
789     window = gtk_dialog_new();
790     priv->window = window;
791
792     gtk_window_set_title(GTK_WINDOW(window), _("View Settings"));
793     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
794     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
795
796     /* Create panarea */
797     area_vbox = gtk_vbox_new(FALSE, 2);
798     g_object_set_data(G_OBJECT(window), "area_vbox", area_vbox);
799     scrolled_window = hildon_pannable_area_new ();
800     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (scrolled_window), GTK_WIDGET (area_vbox));
801     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
802                                    scrolled_window, FALSE, FALSE, 0);
803
804     gtk_widget_set_size_request(scrolled_window, -1, 370);
805
806     /* Create Enable button */
807     enable_button = create_enable_button(check_applet_state(view));
808     gtk_box_pack_start(GTK_BOX(area_vbox),
809                                    enable_button, FALSE, FALSE, 5);
810     /* Create Category button */
811     category_button = create_categories_button(priv);
812     g_object_set_data(G_OBJECT(window), "category_button", category_button);
813     g_signal_connect (G_OBJECT (category_button), "value-changed",  G_CALLBACK (changed_value_category_cb), priv);
814     gtk_box_pack_start(GTK_BOX(area_vbox),
815                                    category_button, FALSE, FALSE, 5);
816     /* Create Custom vbox */
817     vbox = gtk_vbox_new (FALSE, 5);
818     g_object_set_data(G_OBJECT(window), "custom_vbox", vbox);
819
820     /* Create Theme button */
821     theme_button = create_themes_button(priv, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
822     g_object_set_data(G_OBJECT(window), "theme_button", theme_button);
823     g_signal_connect (G_OBJECT (theme_button), "value-changed",  G_CALLBACK (changed_value_theme_cb), priv);
824     gtk_box_pack_start(GTK_BOX(area_vbox),
825                                    theme_button, FALSE, FALSE, 5);
826     fill_theme_button(priv, theme_button, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
827
828     /* Pack custom vbox. It must be last widget */
829     gtk_box_pack_start(GTK_BOX(area_vbox),
830                                    vbox, FALSE, FALSE, 5);
831
832     gtk_widget_show (enable_button);
833     gtk_widget_show (category_button);
834     gtk_widget_show (theme_button);
835     gtk_widget_show (vbox);
836     gtk_widget_show (area_vbox);
837     gtk_widget_show (scrolled_window);
838     gtk_widget_show (window);
839
840     save_button = gtk_dialog_add_button(GTK_DIALOG(window), _("Save"), GTK_RESPONSE_YES);
841
842     result = gtk_dialog_run(GTK_DIALOG(window));
843
844     switch(result){
845         case GTK_RESPONSE_YES:
846             /* Check theme */
847             if (hildon_button_get_value(HILDON_BUTTON (theme_button)) &&
848                 strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "")){
849
850                 if (priv->theme_string_parametr1){
851                     g_free(priv->theme_string_parametr1);
852                     priv->theme_string_parametr1 = NULL;
853                 }
854
855                 if (priv->theme)
856                     g_free(priv->theme);
857                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
858                     priv->theme = g_strdup("Berlin");
859                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern")))
860                     priv->theme = g_strdup("Modern");
861                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix")))
862                     priv->theme = g_strdup("Matrix");
863                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel")))
864                     priv->theme = g_strdup("Accel");
865                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
866                     priv->theme = g_strdup("Video");
867                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
868                     if (button1){
869                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
870                     }
871                     temp_button = g_object_get_data(G_OBJECT(priv->window), "smoothing_button");
872                     if (temp_button){
873                         if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(temp_button)))
874                             priv->theme_bool_parametr1 = TRUE;
875                         else
876                             priv->theme_bool_parametr1 = FALSE;
877                     }
878                 }
879                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Flash"))){
880                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
881                     if (button1){
882                         if (priv->theme_string_parametr1)
883                             g_free(priv->theme_string_parametr1);
884                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
885                     }
886                 }
887                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Slideshow"))){
888                         priv->theme = g_strdup("Slideshow");
889                         button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
890                         if (button1){
891                                 if (priv->theme_string_parametr1)
892                                         g_free(priv->theme_string_parametr1);
893                                                 priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
894                         }
895                 }
896                 /* Check external themes */
897                 GSList *store = priv->extheme_list;
898                 while (store){
899                     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _(g_hash_table_lookup(store->data, "name")))){
900                         //check if theme installed
901                         gchar *check_path = g_hash_table_lookup(store->data, "check_path");
902                         if (check_path){
903                                 if (access(check_path, F_OK) != 0){
904                                         gchar * install_file = g_hash_table_lookup(store->data, "install_file");
905                                         if (install_file){
906                                     if (g_hash_table_lookup(store->data, "associated_package"))
907                                         text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),
908                                                 (gchar *) g_hash_table_lookup(store->data, "associated_package"));
909                                     else
910                                         text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),
911                                                 (gchar *)g_hash_table_lookup(store->data, "name"));
912                                     confirm = hildon_note_new_confirmation(GTK_WINDOW(window), text);
913                                     if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))){
914                                         gchar * cmd = g_strdup_printf("dbus-send --print-reply --dest=com.nokia.osso_browser /com/nokia/osso_browser/service com.nokia.osso_browser.open_new_window string:%s", install_file);
915                                         fprintf(stderr, "system %s\n", cmd);
916                                         system(cmd);
917                                         g_free(cmd);
918                                     }
919                                     g_free(text);
920                                     gtk_widget_destroy(confirm);
921                                         }else
922                                     if (g_hash_table_lookup(store->data, "associated_package"))
923                                                 show_problem_package(button, g_hash_table_lookup(store->data, "associated_package"));
924                                     else
925                                                 show_problem_package(button, g_hash_table_lookup(store->data, "name"));
926                                         /* if not success exit from without saving */
927                                         break;
928                                 }
929                         }
930
931
932                         //check if theme already selected
933                         gchar *copies = g_hash_table_lookup(store->data, "copies");
934                         //fprintf(stderr, "copies = %s\n", copies);
935                         if (copies){
936                             count = atoi(copies);
937                         }else count = 10;
938                         if (count > get_count_themes_from_config(g_hash_table_lookup(store->data, "name")))
939                             priv->theme = g_strdup(g_hash_table_lookup(store->data, "name"));
940                         else
941                             show_duplicate_theme(button, g_hash_table_lookup(store->data, "name"));
942                         //priv->hash_theme = store->data;
943                         break;
944                     }
945                     store = g_slist_next(store);
946                 }
947                                 fprintf(stderr, "theme = %s\n", priv->theme);
948             }
949
950             rich_animation_button = g_object_get_data(G_OBJECT(priv->window), "rich_animation_button");
951             if (rich_animation_button){
952                 /* Check rich animation */
953                 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(rich_animation_button)))
954                     priv->rich_animation = TRUE;
955                 else
956                     priv->rich_animation = FALSE;
957             }
958             /* Save config */
959             save_config(priv);
960             /* action with applet */
961             if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(enable_button))){
962                     if (!check_applet_state(view)){
963                         start_applet(view);
964                     }else {
965                         send_dbus_signal (priv,
966                               LIVEWP_SIGNAL_INTERFACE,
967                               LIVEWP_SIGNAL_PATH,
968                               LIVEWP_RELOAD_CONFIG);
969                     }
970             }else
971                     if (check_applet_state(view))
972                         stop_applet(view);
973
974             set_button_image(button, priv, check_applet_state(view));
975             break;
976         default:
977         case GTK_RESPONSE_OK:
978         break;
979         case GTK_RESPONSE_NO:
980             gtk_widget_destroy(window);
981             window = NULL;
982             lw_about();
983         break;
984     }
985     if (window)
986         gtk_widget_destroy(window);
987 }
988 /*******************************************************************************/
989 gboolean
990 check_applet_state(gint number){
991
992     HDConfigFile *config_file = NULL;
993     GKeyFile *gkey_file = NULL;
994     gchar *str = NULL;
995     gboolean result = FALSE;
996     if (number > 9 || number < 1)
997         return FALSE;
998
999     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
1000     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
1001
1002     gkey_file = hd_config_file_load_file(config_file, FALSE);
1003     if (gkey_file && str){
1004         result = g_key_file_has_group(gkey_file, str);
1005         g_free(str);
1006     }
1007     return result;
1008 }
1009 /*******************************************************************************/
1010 void
1011 start_applet(gint number){
1012
1013     HDConfigFile *config_file = NULL;
1014     GKeyFile *gkey_file = NULL;
1015     gchar *str = NULL;
1016
1017     if (number > 9 || number < 1)
1018         return;
1019     str = g_strdup_printf("livewp-home-widget.desktop-%i",(number - 1));
1020     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
1021
1022     gkey_file = hd_config_file_load_file(config_file, FALSE);
1023     if (gkey_file){
1024         g_key_file_set_string (gkey_file, str, "X-Desktop-File", "/usr/share/applications/hildon-home/livewp-home-widget.desktop");
1025         hd_config_file_save_file( config_file, gkey_file);
1026         g_key_file_free(gkey_file);
1027     }else
1028         fprintf(stderr, "Problem with config file");
1029     if (str)
1030         g_free(str);
1031     g_object_unref(config_file);
1032 }
1033 /*******************************************************************************/
1034 void
1035 stop_applet(gint number){
1036     HDConfigFile *config_file = NULL;
1037     GKeyFile *gkey_file = NULL;
1038     gchar *str = NULL;
1039
1040     if (number > 9 || number < 1)
1041         return;
1042     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
1043     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
1044
1045     gkey_file = hd_config_file_load_file(config_file, FALSE);
1046     if (gkey_file){
1047          g_key_file_remove_group(gkey_file, str, NULL);
1048         hd_config_file_save_file( config_file, gkey_file);
1049         g_key_file_free(gkey_file);
1050     }else
1051         fprintf(stderr, "Problem with config file");
1052     if (str)
1053         g_free(str);
1054     g_object_unref(config_file);
1055
1056 }