updated translation
[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, 5);
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 GtkWidget *
444 create_time_button (guint *active, gchar *name)
445 {
446         GtkWidget *button;
447         GtkWidget *selector;
448         guint values[5] = {20, 40, 60, 120, 300};
449         int i, num = 0;
450         gchar *str;
451
452         button = hildon_picker_button_new (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
453         hildon_button_set_title (HILDON_BUTTON (button), name);
454
455         selector = hildon_touch_selector_new_text();
456         for (i=0; i<5; i++){
457                 str = g_strdup_printf("%d", values[i]);
458                 hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), str);
459                 if (values[i] == active) num = i;
460         }
461         hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
462                         HILDON_TOUCH_SELECTOR (selector));
463         hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, num);
464         if (active){
465         str = g_strdup_printf("%d", active);
466                 hildon_button_set_value(HILDON_BUTTON(button), str);
467     }else
468                 hildon_button_set_value(HILDON_BUTTON(button), "");
469         return button;
470 }
471 /*******************************************************************************/
472 GtkWidget *
473 create_bool_button (gboolean active, gchar *name)
474 {
475     GtkWidget *button;
476     button = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
477     gtk_button_set_label (GTK_BUTTON (button), name);
478     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
479     return button;
480 }
481 /*******************************************************************************/
482 GtkWidget *
483 create_enable_button (gboolean active)
484 {
485     GtkWidget *button;
486     button = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
487     gtk_button_set_label (GTK_BUTTON (button), _("Enable"));
488     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
489     return button;
490 }
491
492 /*******************************************************************************/
493 void
494 show_settings(GtkWidget *widget, Animation_WallpaperPrivate *priv){
495     lw_main_settings(priv, NULL);
496 }
497 /*******************************************************************************/
498 void
499 create_themes_buttons_hbox(Animation_WallpaperPrivate *priv){
500     GtkWidget *hbox = NULL;
501     GtkWidget *area_hbox = NULL;
502     GtkWidget *theme_button;
503     GSList *stlist = NULL;
504     GConfClient *gconf_client = NULL;
505     GConfValue *value = NULL;
506     guint count_of_view = 1;
507     guint i;
508
509
510     area_hbox = g_object_get_data(G_OBJECT(priv->window), "area_hbox");
511     if (!area_hbox)
512         return;
513     hbox = g_object_get_data(G_OBJECT(priv->window), "custom_hbox");
514     if (hbox){
515         gtk_widget_destroy(hbox);
516     }
517
518     hbox = gtk_hbox_new(FALSE, 0);
519     g_object_set_data(G_OBJECT(priv->window), "custom_hbox", hbox);
520     gtk_box_pack_start(GTK_BOX(area_hbox),
521                                    hbox, FALSE, FALSE, 5);
522     /* Create Theme buttons */
523     theme_button = create_image_button(1, priv->dbus_conn_session);
524     gtk_box_pack_start(GTK_BOX(hbox),
525                                    theme_button, TRUE, TRUE, 10);
526     gtk_widget_show (theme_button);
527     gtk_widget_show (hbox);
528     if (priv->one_in_all_view)
529         return;
530
531     gconf_client = gconf_client_get_default();
532     if (!gconf_client)
533         return;
534
535     stlist = gconf_client_get_list(gconf_client,
536                                        "/apps/osso/hildon-desktop/views/active",
537                                        GCONF_VALUE_INT, NULL);
538     if (stlist){
539         count_of_view = g_slist_length(stlist);
540         g_slist_free(stlist);
541     }else
542         count_of_view = 4;
543     g_object_unref(gconf_client);
544     for (i = 2; i < count_of_view + 1; i++){
545         theme_button = create_image_button(i, priv->dbus_conn_session);
546         gtk_box_pack_start(GTK_BOX(hbox),
547                                    theme_button, TRUE, TRUE, 10);
548         gtk_widget_show (theme_button);
549     }
550 }
551 /*******************************************************************************/
552 void
553 lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
554     gint result;
555     GtkWidget *window = NULL;
556     GtkWidget *banner = NULL;
557     GtkWidget *area_hbox;
558     GtkWidget *scrolled_window;
559     GtkWidget *one_in_all_view_button;
560     gboolean one_in_all_view;
561     gint i;
562
563     window = gtk_dialog_new();
564     priv->window = window;
565
566     one_in_all_view = priv->one_in_all_view;
567     gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
568     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
569     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
570     one_in_all_view_button = create_bool_button(priv->one_in_all_view, _("One theme in all views"));
571     g_signal_connect (G_OBJECT (one_in_all_view_button), "toggled",  G_CALLBACK (changed_value_one_in_all_cb), priv);
572     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), one_in_all_view_button, TRUE, TRUE, 5);
573     area_hbox = gtk_vbox_new(FALSE, 2);
574     g_object_set_data(G_OBJECT(window), "area_hbox", area_hbox);
575
576     create_themes_buttons_hbox(priv);
577     scrolled_window = hildon_pannable_area_new ();
578     g_object_set (G_OBJECT (scrolled_window), "mov-mode", HILDON_MOVEMENT_MODE_HORIZ, NULL);
579     g_object_set (G_OBJECT (scrolled_window), "hscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
580     g_object_set (G_OBJECT (scrolled_window), "scrollbar-fade-delay", 27000, NULL);
581     g_object_set (G_OBJECT (scrolled_window), "indicator-width", 28, NULL);
582     gtk_widget_set_size_request(scrolled_window, -1, 120);
583     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (scrolled_window), GTK_WIDGET (area_hbox));
584
585     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
586                                    scrolled_window, TRUE, TRUE, 0);
587
588     gtk_widget_show(scrolled_window);
589     gtk_widget_show(one_in_all_view_button);
590     gtk_widget_show_all(area_hbox);
591     gtk_widget_show(window);
592     gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
593
594     result = gtk_dialog_run(GTK_DIALOG(window));
595
596     switch(result){
597         case GTK_RESPONSE_NO:
598             gtk_widget_destroy(window);
599             window = NULL;
600             lw_about();
601         break;
602     }
603
604     if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(one_in_all_view_button)) != one_in_all_view){
605         save_one_in_all_views_to_config(hildon_check_button_get_active (HILDON_CHECK_BUTTON(one_in_all_view_button)));
606         //fprintf(stderr,"CHECK!!!!!!!!!!!!!!\n");
607         banner = hildon_banner_show_information (window, NULL, _("Livewallpaper is reloading..."));
608         hildon_banner_set_timeout(HILDON_BANNER(banner), 3000);
609         for (i=1;i<10;i++)
610             stop_applet(i);
611         g_timeout_add(3000, (GSourceFunc)cb_timeout_settings, window);
612     }else{
613         if (window)
614             gtk_widget_destroy(window);
615     }
616 }
617 /*******************************************************************************/
618 gboolean
619 cb_timeout_settings(GtkWidget *window){
620
621     gint i;
622     for (i=1;i<10;i++)
623         start_applet(i);
624
625     if (window)
626         gtk_widget_destroy(window);
627     return FALSE;
628 }
629 /*******************************************************************************/
630 void
631 file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
632
633     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
634
635     if (priv->theme_string_parametr1)
636         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
637
638     gtk_widget_show_all (GTK_WIDGET (dialog));
639
640     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
641     {
642       hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
643     }
644     gtk_widget_destroy (dialog);
645
646 }
647 /*******************************************************************************/
648 void
649 folder_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
650
651     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
652
653     if (priv->theme_string_parametr1)
654         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
655
656     gtk_widget_show_all (GTK_WIDGET (dialog));
657
658     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
659     {
660         hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
661     }
662     gtk_widget_destroy (dialog);
663
664 }
665 /*******************************************************************************/
666 void
667 rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
668     GtkWidget *rich_animation_button;
669
670     /* Create rich animation button */
671     rich_animation_button = create_bool_button(priv->rich_animation, _("Rich Animation"));
672     gtk_box_pack_start(GTK_BOX(vbox),
673                                    rich_animation_button, TRUE, TRUE, 5);
674     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
675     gtk_widget_show (rich_animation_button);
676 }
677 /*******************************************************************************/
678 void
679 link_button_clicked(GtkButton *button, gchar *url){
680
681   gchar * cmd = g_strdup_printf("dbus-send --print-reply --dest=com.nokia.osso_browser \
682          /com/nokia/osso_browser/service com.nokia.osso_browser.open_new_window string:%s", url);
683   fprintf(stderr, "system %s\n", cmd);
684   system(cmd);
685   g_free(cmd);
686 }
687 /*******************************************************************************/
688 void
689 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
690
691     GtkWidget *file_button;
692     GtkWidget *link_button;
693     GtkWidget *smoothing_button;
694     GtkWidget *rich_animation_button;
695
696     if (priv->theme_string_parametr1)
697         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
698                                                    _("Play file"), priv->theme_string_parametr1);
699     else
700         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
701                                                    _("Play file")," ");
702
703     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
704
705     gtk_box_pack_start(GTK_BOX(vbox),
706                                    file_button, TRUE, TRUE, 5);
707     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);
708     /* Create rich animation button */
709     rich_animation_button = create_bool_button(priv->rich_animation, _("Loop"));
710     gtk_box_pack_start(GTK_BOX(vbox),
711                                    rich_animation_button, TRUE, TRUE, 5);
712     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
713     /* Create Smoothing button */
714
715     smoothing_button = create_bool_button(priv->theme_bool_parametr1, _("Smoothing (Need more memory)"));
716     gtk_box_pack_start(GTK_BOX(vbox),
717                                    smoothing_button, TRUE, TRUE, 5);
718     g_object_set_data(G_OBJECT(priv->window), "smoothing_button", smoothing_button);
719
720     link_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
721                                                    _("Press me for"), _("download more videos"));
722
723     g_signal_connect (link_button, "clicked", G_CALLBACK (link_button_clicked), "http://talk.maemo.org/showthread.php?t=60185");
724     gtk_box_pack_start(GTK_BOX(vbox),
725                                    link_button, TRUE, TRUE, 5);
726
727     gtk_widget_show (smoothing_button);
728     gtk_widget_show (file_button);
729     gtk_widget_show (rich_animation_button);
730     gtk_widget_show (link_button);
731
732 }
733 /*******************************************************************************/
734 void
735 additional_parametr_for_theme_flash(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
736
737     GtkWidget *file_button;
738     GtkWidget *link_button;
739     GtkWidget *smoothing_button;
740     GtkWidget *rich_animation_button;
741
742     if (priv->theme_string_parametr1)
743         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
744                                                    _("Play file"), priv->theme_string_parametr1);
745     else
746         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
747                                                    _("Play file")," ");
748
749     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
750
751     gtk_box_pack_start(GTK_BOX(vbox),
752                                    file_button, TRUE, TRUE, 5);
753     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);
754     gtk_widget_show (file_button);
755 }
756 /*******************************************************************************/
757 void
758 additional_parametr_for_theme_slideshow(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
759
760     GtkWidget *file_button;
761     GtkWidget *time_button;
762
763     if (priv->theme_string_parametr1)
764         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
765                                                    _("Folder with images"), priv->theme_string_parametr1);
766     else
767         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
768                                                    _("Folder with images")," ");
769
770     g_signal_connect (file_button, "clicked", G_CALLBACK (folder_button_clicked), priv);
771
772     gtk_box_pack_start(GTK_BOX(vbox), file_button, TRUE, TRUE, 5);
773     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);
774
775     if (priv->theme_int_parametr1)
776         time_button = create_time_button(priv->theme_int_parametr1, _("Time to change image"));
777     else
778         time_button = create_time_button(0, _("Time to change image"));
779     gtk_box_pack_start(GTK_BOX(vbox), time_button, TRUE, TRUE, 5);
780     g_object_set_data(G_OBJECT(priv->window), "time_button", time_button);
781
782     gtk_widget_show (time_button);
783     gtk_widget_show (file_button);
784 }
785 /*******************************************************************************/
786
787 void
788 show_problem_package (GtkWidget *widget, gchar *package_name){
789     gchar *text;
790     text = g_strdup_printf(_("You haven't got the installed package %s. Please install it via using Application Manager"), package_name);
791     hildon_banner_show_information(GTK_WIDGET(widget), NULL, text);
792     g_free(text);
793 }
794 /*******************************************************************************/
795 void
796 show_duplicate_theme (GtkWidget *widget, gchar *theme_name){
797     gchar *text;
798     text = g_strdup_printf(_("Theme %s has already been selected"), theme_name);
799     hildon_banner_show_information(GTK_WIDGET(widget), NULL, text);
800     g_free(text);
801 }
802
803 /*******************************************************************************/
804 void
805 lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
806     gint result;
807     GtkWidget *window = NULL;
808     GtkWidget *scrolled_window = NULL;
809     GtkWidget *save_button;
810     GtkWidget *theme_button;
811     GtkWidget *category_button;
812     GtkWidget *enable_button;
813     GtkWidget *vbox;
814     GtkWidget *area_vbox;
815     GtkWidget *temp_button;
816     GtkWidget *button1 = NULL, *button2 = NULL;
817     GtkWidget *rich_animation_button = NULL;
818     GtkWidget *confirm;
819     gint view = priv->view;
820     gint count, int_param;
821     gchar *text;
822
823     window = gtk_dialog_new();
824     priv->window = window;
825
826     gtk_window_set_title(GTK_WINDOW(window), _("View Settings"));
827     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
828     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
829
830     /* Create panarea */
831     area_vbox = gtk_vbox_new(FALSE, 2);
832     g_object_set_data(G_OBJECT(window), "area_vbox", area_vbox);
833     scrolled_window = hildon_pannable_area_new ();
834     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (scrolled_window), GTK_WIDGET (area_vbox));
835     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
836                                    scrolled_window, FALSE, FALSE, 0);
837
838     gtk_widget_set_size_request(scrolled_window, -1, 370);
839
840     /* Create Enable button */
841     enable_button = create_enable_button(check_applet_state(view));
842     gtk_box_pack_start(GTK_BOX(area_vbox),
843                                    enable_button, FALSE, FALSE, 5);
844     /* Create Category button */
845     category_button = create_categories_button(priv);
846     g_object_set_data(G_OBJECT(window), "category_button", category_button);
847     g_signal_connect (G_OBJECT (category_button), "value-changed",  G_CALLBACK (changed_value_category_cb), priv);
848     gtk_box_pack_start(GTK_BOX(area_vbox),
849                                    category_button, FALSE, FALSE, 5);
850     /* Create Custom vbox */
851     vbox = gtk_vbox_new (FALSE, 5);
852     g_object_set_data(G_OBJECT(window), "custom_vbox", vbox);
853
854     /* Create Theme button */
855     theme_button = create_themes_button(priv, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
856     g_object_set_data(G_OBJECT(window), "theme_button", theme_button);
857     g_signal_connect (G_OBJECT (theme_button), "value-changed",  G_CALLBACK (changed_value_theme_cb), priv);
858     gtk_box_pack_start(GTK_BOX(area_vbox),
859                                    theme_button, FALSE, FALSE, 5);
860     fill_theme_button(priv, theme_button, (gchar *)hildon_button_get_value(HILDON_BUTTON (category_button)));
861
862     /* Pack custom vbox. It must be last widget */
863     gtk_box_pack_start(GTK_BOX(area_vbox),
864                                    vbox, FALSE, FALSE, 5);
865
866     gtk_widget_show (enable_button);
867     gtk_widget_show (category_button);
868     gtk_widget_show (theme_button);
869     gtk_widget_show (vbox);
870     gtk_widget_show (area_vbox);
871     gtk_widget_show (scrolled_window);
872     gtk_widget_show (window);
873
874     save_button = gtk_dialog_add_button(GTK_DIALOG(window), _("Save"), GTK_RESPONSE_YES);
875
876     result = gtk_dialog_run(GTK_DIALOG(window));
877
878     switch(result){
879         case GTK_RESPONSE_YES:
880             /* Check theme */
881             if (hildon_button_get_value(HILDON_BUTTON (theme_button)) &&
882                 strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), "")){
883
884                 if (priv->theme_string_parametr1){
885                     g_free(priv->theme_string_parametr1);
886                     priv->theme_string_parametr1 = NULL;
887                 }
888
889                 if (priv->theme)
890                     g_free(priv->theme);
891                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
892                     priv->theme = g_strdup("Berlin");
893                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern")))
894                     priv->theme = g_strdup("Modern");
895                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix")))
896                     priv->theme = g_strdup("Matrix");
897                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel")))
898                     priv->theme = g_strdup("Accel");
899                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
900                     priv->theme = g_strdup("Video");
901                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
902                     if (button1){
903                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
904                     }
905                     temp_button = g_object_get_data(G_OBJECT(priv->window), "smoothing_button");
906                     if (temp_button){
907                         if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(temp_button)))
908                             priv->theme_bool_parametr1 = TRUE;
909                         else
910                             priv->theme_bool_parametr1 = FALSE;
911                     }
912                 }
913                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Flash"))){
914                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
915                     if (button1){
916                         if (priv->theme_string_parametr1)
917                             g_free(priv->theme_string_parametr1);
918                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
919                     }
920                 }
921                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Slideshow"))){
922                         priv->theme = g_strdup("Slideshow");
923                         button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
924                         if (button1){
925                                 if (priv->theme_string_parametr1)
926                                         g_free(priv->theme_string_parametr1);
927                                                 priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
928                         }
929                         button2 = g_object_get_data(G_OBJECT(priv->window), "time_button");
930                         if (button2){
931                                 //if (priv->theme_int_parametr1)
932                                 //      g_free(priv->theme_int_parametr1);
933                         int_param = atoi(hildon_button_get_value (HILDON_BUTTON(button2)));
934                                 priv->theme_int_parametr1 = int_param;
935                         }
936                 }
937                 /* Check external themes */
938                 GSList *store = priv->extheme_list;
939                 while (store){
940                     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _(g_hash_table_lookup(store->data, "name")))){
941                         //check if theme installed
942                         gchar *check_path = g_hash_table_lookup(store->data, "check_path");
943                         if (check_path){
944                                 if (access(check_path, F_OK) != 0){
945                                         gchar * install_file = g_hash_table_lookup(store->data, "install_file");
946                                         if (install_file){
947                                     if (g_hash_table_lookup(store->data, "associated_package"))
948                                         text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),
949                                                 (gchar *) g_hash_table_lookup(store->data, "associated_package"));
950                                     else
951                                         text = g_strdup_printf(_("You haven't got the installed package %s. Do you want to install it via using Application Manager?"),
952                                                 (gchar *)g_hash_table_lookup(store->data, "name"));
953                                     confirm = hildon_note_new_confirmation(GTK_WINDOW(window), text);
954                                     if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))){
955                                         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);
956                                         fprintf(stderr, "system %s\n", cmd);
957                                         system(cmd);
958                                         g_free(cmd);
959                                     }
960                                     g_free(text);
961                                     gtk_widget_destroy(confirm);
962                                         }else
963                                     if (g_hash_table_lookup(store->data, "associated_package"))
964                                                 show_problem_package(button, g_hash_table_lookup(store->data, "associated_package"));
965                                     else
966                                                 show_problem_package(button, g_hash_table_lookup(store->data, "name"));
967                                         /* if not success exit from without saving */
968                                         break;
969                                 }
970                         }
971
972
973                         //check if theme already selected
974                         gchar *copies = g_hash_table_lookup(store->data, "copies");
975                         //fprintf(stderr, "copies = %s\n", copies);
976                         if (copies){
977                             count = atoi(copies);
978                         }else count = 10;
979                         if (count > get_count_themes_from_config(g_hash_table_lookup(store->data, "name")))
980                             priv->theme = g_strdup(g_hash_table_lookup(store->data, "name"));
981                         else
982                             show_duplicate_theme(button, g_hash_table_lookup(store->data, "name"));
983                         //priv->hash_theme = store->data;
984                         break;
985                     }
986                     store = g_slist_next(store);
987                 }
988                                 fprintf(stderr, "theme = %s\n", priv->theme);
989             }
990
991             rich_animation_button = g_object_get_data(G_OBJECT(priv->window), "rich_animation_button");
992             if (rich_animation_button){
993                 /* Check rich animation */
994                 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(rich_animation_button)))
995                     priv->rich_animation = TRUE;
996                 else
997                     priv->rich_animation = FALSE;
998             }
999             /* Save config */
1000             save_config(priv);
1001             /* action with applet */
1002             if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(enable_button))){
1003                     if (!check_applet_state(view)){
1004                         start_applet(view);
1005                     }else {
1006                         send_dbus_signal (priv,
1007                               LIVEWP_SIGNAL_INTERFACE,
1008                               LIVEWP_SIGNAL_PATH,
1009                               LIVEWP_RELOAD_CONFIG);
1010                     }
1011             }else
1012                     if (check_applet_state(view))
1013                         stop_applet(view);
1014
1015             set_button_image(button, priv, check_applet_state(view));
1016             break;
1017         default:
1018         case GTK_RESPONSE_OK:
1019         break;
1020         case GTK_RESPONSE_NO:
1021             gtk_widget_destroy(window);
1022             window = NULL;
1023             lw_about();
1024         break;
1025     }
1026     if (window)
1027         gtk_widget_destroy(window);
1028 }
1029 /*******************************************************************************/
1030 gboolean
1031 check_applet_state(gint number){
1032
1033     HDConfigFile *config_file = NULL;
1034     GKeyFile *gkey_file = NULL;
1035     gchar *str = NULL;
1036     gboolean result = FALSE;
1037     if (number > 9 || number < 1)
1038         return FALSE;
1039
1040     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
1041     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
1042
1043     gkey_file = hd_config_file_load_file(config_file, FALSE);
1044     if (gkey_file && str){
1045         result = g_key_file_has_group(gkey_file, str);
1046         g_free(str);
1047     }
1048     return result;
1049 }
1050 /*******************************************************************************/
1051 void
1052 start_applet(gint number){
1053
1054     HDConfigFile *config_file = NULL;
1055     GKeyFile *gkey_file = NULL;
1056     gchar *str = NULL;
1057
1058     if (number > 9 || number < 1)
1059         return;
1060     str = g_strdup_printf("livewp-home-widget.desktop-%i",(number - 1));
1061     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
1062
1063     gkey_file = hd_config_file_load_file(config_file, FALSE);
1064     if (gkey_file){
1065         g_key_file_set_string (gkey_file, str, "X-Desktop-File", "/usr/share/applications/hildon-home/livewp-home-widget.desktop");
1066         hd_config_file_save_file( config_file, gkey_file);
1067         g_key_file_free(gkey_file);
1068     }else
1069         fprintf(stderr, "Problem with config file");
1070     if (str)
1071         g_free(str);
1072     g_object_unref(config_file);
1073 }
1074 /*******************************************************************************/
1075 void
1076 stop_applet(gint number){
1077     HDConfigFile *config_file = NULL;
1078     GKeyFile *gkey_file = NULL;
1079     gchar *str = NULL;
1080
1081     if (number > 9 || number < 1)
1082         return;
1083     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
1084     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
1085
1086     gkey_file = hd_config_file_load_file(config_file, FALSE);
1087     if (gkey_file){
1088          g_key_file_remove_group(gkey_file, str, NULL);
1089         hd_config_file_save_file( config_file, gkey_file);
1090         g_key_file_free(gkey_file);
1091     }else
1092         fprintf(stderr, "Problem with config file");
1093     if (str)
1094         g_free(str);
1095     g_object_unref(config_file);
1096
1097 }