adapted for theme Accel
[livewp] / applet / src / livewp-settings.c
1 /* vim: set sw=4 ts=4 et: */
2 /*
3  * This file is part of Live Wallpaper (livewp)
4  * 
5  * Copyright (C) 2010 Vlad Vasiliev
6  * Copyright (C) 2010 Tanya Makova
7  *       for the code
8  * 
9  * This software is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1 of
12  * the License, or (at your option) any later version.
13  * 
14  * This software is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this software; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23 */
24 /*******************************************************************************/
25 #include "livewp-settings.h"
26 /*******************************************************************************/
27 void lw_about(void){
28
29     GtkWidget *window = NULL,
30     *vbox = NULL,
31     *label_about = NULL;
32     window = gtk_dialog_new();
33     gtk_window_set_title(GTK_WINDOW(window), _("About"));
34     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
35     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
36     vbox = gtk_vbox_new (FALSE, 5);
37     label_about = gtk_label_new (_("Live Wallpaper Version 0.7 \n Copyright(c) 2010\n \
38 Tanya Makova\n Vlad Vasiliev\n \
39 Copyright(c) 2010 for design themes Berlin and Modern Vasya Bobrikov\n \
40 Copyright(c) 2010 for design theme Matrix Andrew Zhilin\n \
41 Translators:\n \
42 Finnish - Marko Vertainen\n \
43 Spain  - Alejandro López\n \
44 Russian - Tanya Makova \n \
45           Vlad Vasiliev\n")); 
46     gtk_box_pack_start (GTK_BOX (vbox), label_about, FALSE, FALSE, 0);
47     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
48                                    vbox, TRUE, TRUE, 0);
49     gtk_widget_show (label_about);
50     gtk_widget_show (vbox);
51     gtk_widget_show (window);
52     gtk_dialog_run(GTK_DIALOG(window));
53
54 }
55 /*******************************************************************************/
56 GtkWidget *
57 create_theme_selector (void){
58       GtkWidget *selector;
59
60       selector = hildon_touch_selector_new_text ();
61
62       hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Berlin"));
63       hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Modern"));
64       hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Matrix"));
65       hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Accel"));
66       hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), _("Video"));
67       return selector;
68 }
69 /*******************************************************************************/
70 void
71 theme_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
72
73     lw_theme_settings(GTK_WIDGET(button), priv);
74 }
75 /********************************************************************************/
76 void
77 set_button_image(GtkWidget * button, gchar *theme, gboolean enable){
78     GtkWidget * image = NULL; 
79     GdkPixbuf * pixbuf = NULL;
80     gchar *str = NULL;
81     if (enable)
82         str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
83                         theme, "icon.png");
84     else 
85         str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
86                         theme, "icond.png");
87     pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
88                                              100, 
89                                              60, 
90                                              NULL);
91     if (str)
92         g_free(str);
93     if (pixbuf){
94         image = gtk_image_new_from_pixbuf (pixbuf);
95         g_object_unref(G_OBJECT(pixbuf));
96     }
97
98    hildon_button_set_image (HILDON_BUTTON (button), image);
99 }
100 /********************************************************************************/
101 GtkWidget *
102 create_image_button (gint view, DBusConnection *conn_sess){
103     GtkWidget *button;
104     
105     Animation_WallpaperPrivate *priv = g_new0(Animation_WallpaperPrivate, 1);
106     priv->view = view;
107     priv->theme_string_parametr1 = NULL;
108     priv->dbus_conn_session = conn_sess;
109     read_config(priv);
110     button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
111                                     HILDON_BUTTON_ARRANGEMENT_VERTICAL);
112     g_object_set_data(G_OBJECT(button), "view", GINT_TO_POINTER(view));
113     g_object_set_data(G_OBJECT(button), "priv", priv);
114     set_button_image(button, priv->theme, check_applet_state(view));
115     g_signal_connect(button, "clicked", G_CALLBACK(theme_button_clicked), priv);
116     hildon_button_set_image_position (HILDON_BUTTON (button), GTK_POS_RIGHT);
117     return button;
118
119 }
120 /********************************************************************************/
121 void
122 changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
123 {
124     const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
125     GtkWidget *vbox = NULL;
126         
127     vbox = g_object_get_data(G_OBJECT(priv->window), "custom_vbox");
128     if (vbox)
129         gtk_widget_destroy(vbox);
130     vbox = gtk_vbox_new (FALSE, 5);
131     g_object_set_data(G_OBJECT(priv->window), "custom_vbox", vbox);
132     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(priv->window)->vbox),
133                                    vbox, TRUE, TRUE, 5);
134     if (choice) {
135         if (!strcmp(choice, "Berlin")){
136             rich_animation_additional_parametr(vbox,priv);
137         }
138         if (!strcmp(choice, "Modern")){
139             rich_animation_additional_parametr(vbox,priv);
140         }
141         if (!strcmp(choice, "Matrix")){
142             rich_animation_additional_parametr(vbox,priv);
143         }
144         if (!strcmp(choice, "Accel")){
145             rich_animation_additional_parametr(vbox,priv);
146         }
147         if (!strcmp(choice, "Video")){
148             additional_parametr_for_theme_video(vbox, priv);
149         }
150     }
151     gtk_widget_show(vbox);
152 }
153
154 /********************************************************************************/
155 GtkWidget *
156 create_themes_button (gchar *theme){
157
158     GtkWidget *button;
159     GtkWidget *selector;
160
161     selector = create_theme_selector();
162     button = hildon_picker_button_new (HILDON_SIZE_AUTO, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
163     hildon_button_set_title (HILDON_BUTTON (button), _("Theme"));
164     hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
165                                                        HILDON_TOUCH_SELECTOR (selector));
166     if (theme) {
167         if (!strcmp(theme, "Berlin")){
168             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 0);
169             hildon_button_set_value(HILDON_BUTTON(button), _("Berlin"));
170         }
171         if (!strcmp(theme, "Modern")){
172             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 1);
173             hildon_button_set_value(HILDON_BUTTON(button), _("Modern"));
174         }
175         if (!strcmp(theme, "Matrix")){
176             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 2);
177             hildon_button_set_value(HILDON_BUTTON(button), _("Matrix"));
178         }
179         if (!strcmp(theme, "Accel")){
180             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 3);
181             hildon_button_set_value(HILDON_BUTTON(button), _("Accel"));
182         }
183
184         if (!strcmp(theme, "Video")){
185             hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, 4);
186             hildon_button_set_value(HILDON_BUTTON(button), _("Video"));
187         }
188
189     }
190     
191     return button;
192 }
193
194 /*******************************************************************************/
195 GtkWidget *
196 create_rich_animation_button (gboolean active, gchar *name)
197 {
198     GtkWidget *button;
199     button = hildon_check_button_new (HILDON_SIZE_AUTO);
200     gtk_button_set_label (GTK_BUTTON (button), name);
201     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
202     return button;
203 }
204 /*******************************************************************************/
205 GtkWidget *
206 create_enable_button (gboolean active)
207 {
208     GtkWidget *button;
209     button = hildon_check_button_new (HILDON_SIZE_AUTO);
210     gtk_button_set_label (GTK_BUTTON (button), _("Enable"));
211     hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
212     return button;
213 }
214
215 /*******************************************************************************/
216 void
217 show_settings(GtkWidget *widget, Animation_WallpaperPrivate *priv){
218     lw_main_settings(priv, NULL);
219 }
220 /*******************************************************************************/
221 void 
222 lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
223     gint result;
224     GtkWidget *window = NULL;
225     GtkWidget *theme_button1;
226     GtkWidget *theme_button2;
227     GtkWidget *theme_button3;
228     GtkWidget *theme_button4;
229     GtkWidget *hbox;
230     Animation_WallpaperPrivate *priv_temp = NULL;
231
232     window = gtk_dialog_new();
233
234     gtk_window_set_title(GTK_WINDOW(window), _("Live Wallpaper Settings"));
235     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
236     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
237     /* Create Theme button */
238     hbox = gtk_hbox_new(FALSE, 5);
239     theme_button1 = create_image_button(1, priv->dbus_conn_session);
240     gtk_box_pack_start(GTK_BOX(hbox),
241                                    theme_button1, TRUE, TRUE, 5);
242     theme_button2 = create_image_button(2, priv->dbus_conn_session);
243     gtk_box_pack_start(GTK_BOX(hbox),
244                                    theme_button2, TRUE, TRUE, 5);
245     theme_button3 = create_image_button(3, priv->dbus_conn_session);
246     gtk_box_pack_start(GTK_BOX(hbox),
247                                    theme_button3, TRUE, TRUE, 5);
248     theme_button4 = create_image_button(4, priv->dbus_conn_session);
249     gtk_box_pack_start(GTK_BOX(hbox),
250                                    theme_button4, TRUE, TRUE, 5);
251     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
252                                    hbox, TRUE, TRUE, 5);
253
254     gtk_widget_show (theme_button1);
255     gtk_widget_show (theme_button2);
256     gtk_widget_show (theme_button3);
257     gtk_widget_show (theme_button4);
258     gtk_widget_show_all (hbox);
259     gtk_widget_show (window);
260     gtk_dialog_add_button(GTK_DIALOG(window), _("About"), GTK_RESPONSE_NO);
261
262     result = gtk_dialog_run(GTK_DIALOG(window));
263
264     priv_temp = g_object_get_data(G_OBJECT(theme_button1), "priv");
265     if (priv_temp){
266         g_free(priv_temp);
267         priv_temp =NULL;
268     }
269     priv_temp = g_object_get_data(G_OBJECT(theme_button2), "priv");
270     if (priv_temp){
271         g_free(priv_temp);
272         priv_temp =NULL;
273     }
274     priv_temp = g_object_get_data(G_OBJECT(theme_button3), "priv");
275     if (priv_temp){
276         g_free(priv_temp);
277         priv_temp =NULL;
278     }
279     priv_temp = g_object_get_data(G_OBJECT(theme_button4), "priv");
280     if (priv_temp){
281         g_free(priv_temp);
282         priv_temp =NULL;
283     }
284
285
286     switch(result){
287         case GTK_RESPONSE_NO:
288             gtk_widget_destroy(window);
289             window = NULL;
290             lw_about();
291         break;
292     }
293
294
295     if (window)
296         gtk_widget_destroy(window);
297 }
298 /*******************************************************************************/
299 void
300 file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
301
302     GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
303
304     if (priv->theme_string_parametr1)
305         gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
306
307     gtk_widget_show_all (GTK_WIDGET (dialog));
308
309     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
310     {
311       hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
312     }
313     gtk_widget_destroy (dialog);
314
315 }
316 /*******************************************************************************/
317 void
318 rich_animation_additional_parametr(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
319     GtkWidget *rich_animation_button;
320     /* Create rich animation button */  
321     rich_animation_button = create_rich_animation_button(priv->rich_animation, _("Rich Animation"));
322     gtk_box_pack_start(GTK_BOX(vbox),
323                                    rich_animation_button, TRUE, TRUE, 5);
324     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
325     gtk_widget_show (rich_animation_button);
326 }
327 /*******************************************************************************/
328 void
329 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
330
331     GtkWidget *file_button;
332     GtkWidget *rich_animation_button;
333
334     if (priv->theme_string_parametr1)
335         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL,
336                                                    _("Play file"), priv->theme_string_parametr1);
337     else
338         file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
339                                                    _("Play file")," ");
340
341     g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
342
343     gtk_box_pack_start(GTK_BOX(vbox),
344                                    file_button, TRUE, TRUE, 5);
345     g_object_set_data(G_OBJECT(priv->window), "filename_button", file_button);    /* Create rich animation button */  
346     rich_animation_button = create_rich_animation_button(priv->rich_animation, _("Loop"));
347     gtk_box_pack_start(GTK_BOX(vbox),
348                                    rich_animation_button, TRUE, TRUE, 5);
349     g_object_set_data(G_OBJECT(priv->window), "rich_animation_button", rich_animation_button);
350
351     gtk_widget_show (file_button);
352     gtk_widget_show (rich_animation_button);
353
354 }
355 /*******************************************************************************/
356 void 
357 lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
358     gint result;
359     GtkWidget *window = NULL;
360     GtkWidget *save_button;
361     GtkWidget *theme_button;
362     GtkWidget *enable_button;
363     GtkWidget *vbox;
364     GtkWidget *button1 = NULL;
365     GtkWidget *rich_animation_button = NULL;
366     gint view = priv->view;
367
368     window = gtk_dialog_new();
369     priv->window = window;
370
371     gtk_window_set_title(GTK_WINDOW(window), _("View Settings"));
372     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
373     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
374     /* Create Enable button */
375     enable_button = create_enable_button(check_applet_state(view)); 
376     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
377                                    enable_button, TRUE, TRUE, 5);
378     /* Create Theme button */
379     theme_button = create_themes_button(priv->theme);
380     g_signal_connect (G_OBJECT (theme_button), "value-changed",  G_CALLBACK (changed_value_theme_cb), priv);
381     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
382                                    theme_button, TRUE, TRUE, 5);
383
384     /* Create custom vbox */
385     vbox = gtk_vbox_new (FALSE, 5);
386     g_object_set_data(G_OBJECT(window), "custom_vbox", vbox);
387     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),
388                                    vbox, TRUE, TRUE, 5);
389     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin"))||
390         !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix"))||
391         !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel"))||
392         !strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern"))){
393         rich_animation_additional_parametr(vbox, priv);
394     }
395
396     if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
397         additional_parametr_for_theme_video(vbox, priv);
398     } 
399
400     gtk_widget_show (enable_button);
401     gtk_widget_show (theme_button);
402     gtk_widget_show (vbox);
403     gtk_widget_show (window);
404     save_button = gtk_dialog_add_button(GTK_DIALOG(window), _("Save"), GTK_RESPONSE_YES);
405
406     result = gtk_dialog_run(GTK_DIALOG(window));
407
408     switch(result){
409         case GTK_RESPONSE_YES:
410             /* Check theme */
411             if (hildon_button_get_value(HILDON_BUTTON (theme_button))){
412
413                 if (priv->theme)
414                     g_free(priv->theme);
415
416                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Berlin")))
417                     priv->theme = g_strdup("Berlin");
418                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Modern")))
419                     priv->theme = g_strdup("Modern");
420                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Matrix")))
421                     priv->theme = g_strdup("Matrix");
422                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Accel")))
423                     priv->theme = g_strdup("Accel");
424                 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
425                     priv->theme = g_strdup("Video");
426                     button1 = g_object_get_data(G_OBJECT(priv->window), "filename_button");
427                     if (button1){
428                         if (priv->theme_string_parametr1)
429                             g_free(priv->theme_string_parametr1);
430                         priv->theme_string_parametr1 = g_strdup((gchar*)hildon_button_get_value (HILDON_BUTTON(button1)));
431                     }
432                 }
433
434             }
435
436             rich_animation_button = g_object_get_data(G_OBJECT(priv->window), "rich_animation_button");
437             if (rich_animation_button){
438                 /* Check rich animation */
439                 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(rich_animation_button)))
440                     priv->rich_animation = TRUE;
441                 else
442                     priv->rich_animation = FALSE;
443             }
444             /* Save config */
445             save_config(priv);
446             /* action with applet */
447             if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(enable_button))){
448                     if (!check_applet_state(view)){
449                         start_applet(view);
450                     }else {
451                         send_dbus_signal (priv,
452                               LIVEWP_SIGNAL_INTERFACE,
453                               LIVEWP_SIGNAL_PATH,
454                               LIVEWP_RELOAD_CONFIG);
455                     }
456             }else
457                     if (check_applet_state(view))
458                         stop_applet(view);
459
460             set_button_image(button, priv->theme, check_applet_state(view));
461             break;
462         default:
463         case GTK_RESPONSE_OK:
464         break;
465         case GTK_RESPONSE_NO:
466             gtk_widget_destroy(window);
467             window = NULL;
468             lw_about();
469         break;
470     }
471     if (window)
472         gtk_widget_destroy(window);
473 }
474 /*******************************************************************************/
475 gboolean
476 check_applet_state(gint number){
477
478     HDConfigFile *config_file = NULL;
479     GKeyFile *gkey_file = NULL;
480     gchar *str = NULL;
481     gboolean result = FALSE;
482     if (number > 4 || number < 1)
483         return FALSE;
484
485     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
486     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
487     
488     gkey_file = hd_config_file_load_file(config_file, FALSE);
489     if (gkey_file && str){
490         result = g_key_file_has_group(gkey_file, str);
491         g_free(str);
492     }
493     return result;
494 #if 0
495     FILE    *file_in = NULL;
496     gchar buffer[2048];
497
498     file_in = fopen("/home/user/.config/hildon-desktop/home.plugins","r");
499     if (file_in){
500
501         fprintf(stderr,"Check applet state\n");
502         while (!feof(file_in)) {
503                 memset(buffer, 0, sizeof(buffer));
504                 fgets(buffer, sizeof(buffer) - 1, file_in);
505                 if (!strcmp(buffer, 
506                             "X-Desktop-File=/usr/share/applications/hildon-home/livewp-home-widget.desktop\n")){
507                     result = TRUE;
508                     break;
509                 }
510        }
511         fclose(file_in);
512     }
513 #endif
514 }
515 /*******************************************************************************/
516 void
517 start_applet(gint number){
518
519     HDConfigFile *config_file = NULL;
520     GKeyFile *gkey_file = NULL;
521     gchar *str = NULL;
522
523     if (number > 4 || number < 1)
524         return;
525     str = g_strdup_printf("livewp-home-widget.desktop-%i",(number - 1));
526     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
527     
528     gkey_file = hd_config_file_load_file(config_file, FALSE);
529     if (gkey_file){
530         g_key_file_set_string (gkey_file, str, "X-Desktop-File", "/usr/share/applications/hildon-home/livewp-home-widget.desktop");
531         hd_config_file_save_file( config_file, gkey_file);
532         g_key_file_free(gkey_file);
533     }else
534         fprintf(stderr, "Problem with config file");
535     if (str)
536         g_free(str);
537     g_object_unref(config_file);
538 }
539 /*******************************************************************************/
540 void
541 stop_applet(gint number){
542     HDConfigFile *config_file = NULL;
543     GKeyFile *gkey_file = NULL;
544     gchar *str = NULL;
545
546     if (number > 4 || number < 1)
547         return;
548     str = g_strdup_printf("livewp-home-widget.desktop-%i", (number - 1));
549     config_file = hd_config_file_new(NULL, "/home/user/.config/hildon-desktop/", "home.plugins");
550     
551     gkey_file = hd_config_file_load_file(config_file, FALSE);
552     if (gkey_file){
553          g_key_file_remove_group(gkey_file, str, NULL);  
554         hd_config_file_save_file( config_file, gkey_file);
555         g_key_file_free(gkey_file);
556     }else
557         fprintf(stderr, "Problem with config file");
558     if (str)
559         g_free(str);
560     g_object_unref(config_file);
561
562 #if 0    
563     FILE    *file_in;
564     FILE    *file_out;
565     gchar buffer[2048];
566     gchar * str = NULL;
567
568     file_in = fopen("/home/user/.config/hildon-desktop/home.plugins","r");
569     file_out = fopen("/tmp/livewallpaper.plugins","w");
570     if (file_in && file_out){
571         while (!feof(file_in)) {
572             memset(buffer, 0, sizeof(buffer));
573             fgets(buffer, sizeof(buffer) - 1, file_in);
574             str = g_strdup_printf("[livewp-home-widget.desktop-%i]\n", number);
575             if (strcmp(buffer, str) &&
576                 strcmp(buffer, "X-Desktop-File=/usr/share/applications/hildon-home/livewp-home-widget.desktop\n"))
577                 fputs(buffer, file_out);
578         }
579         if (str){
580             g_free(str);
581         }
582         fclose(file_out);
583         fclose(file_in);
584         file_in = fopen("/tmp/livewallpaper.plugins","r");
585         file_out = fopen("/home/user/.config/hildon-desktop/home.plugins","w");
586         if (file_in && file_out){
587             while (!feof(file_in)){
588                 memset(buffer, 0, sizeof(buffer));
589                 fgets(buffer, sizeof(buffer) - 1, file_in);
590                 fputs(buffer, file_out);
591             }
592             fclose(file_out);
593             fclose(file_in);
594             unlink ("/tmp/livewallpaper.plugins");
595         }
596     }
597 #endif
598 }