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