1 /* vim: set sw=4 ts=4 et: */
3 * This file is part of Live Wallpaper (livewp)
5 * Copyright (C) 2010 Vlad Vasiliev
6 * Copyright (C) 2010 Tanya Makova
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.
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.
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
24 /*******************************************************************************/
25 #include "livewp-settings.h"
26 /*******************************************************************************/
29 GtkWidget *window = 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 \
42 Finnish - Marko Vertainen\n \
43 Spain - Alejandro López\n \
44 Russian - Tanya Makova \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),
49 gtk_widget_show (label_about);
50 gtk_widget_show (vbox);
51 gtk_widget_show (window);
52 gtk_dialog_run(GTK_DIALOG(window));
55 /*******************************************************************************/
57 create_theme_selector (void){
60 selector = hildon_touch_selector_new_text ();
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"));
69 /*******************************************************************************/
71 theme_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
73 lw_theme_settings(GTK_WIDGET(button), priv);
75 /********************************************************************************/
77 set_button_image(GtkWidget * button, gchar *theme, gboolean enable){
78 GtkWidget * image = NULL;
79 GdkPixbuf * pixbuf = NULL;
82 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
85 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
87 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
94 image = gtk_image_new_from_pixbuf (pixbuf);
95 g_object_unref(G_OBJECT(pixbuf));
98 hildon_button_set_image (HILDON_BUTTON (button), image);
100 /********************************************************************************/
102 create_image_button (gint view, DBusConnection *conn_sess){
105 Animation_WallpaperPrivate *priv = g_new0(Animation_WallpaperPrivate, 1);
107 priv->theme_string_parametr1 = NULL;
108 priv->dbus_conn_session = conn_sess;
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);
120 /********************************************************************************/
122 changed_value_theme_cb (HildonPickerButton *picker, Animation_WallpaperPrivate *priv)
124 const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
125 GtkWidget *vbox = NULL;
127 vbox = g_object_get_data(G_OBJECT(priv->window), "custom_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);
135 if (!strcmp(choice, "Berlin")){
136 rich_animation_additional_parametr(vbox,priv);
138 if (!strcmp(choice, "Modern")){
139 rich_animation_additional_parametr(vbox,priv);
141 if (!strcmp(choice, "Matrix")){
142 rich_animation_additional_parametr(vbox,priv);
144 if (!strcmp(choice, "Accel")){
145 rich_animation_additional_parametr(vbox,priv);
147 if (!strcmp(choice, "Video")){
148 additional_parametr_for_theme_video(vbox, priv);
151 gtk_widget_show(vbox);
154 /********************************************************************************/
156 create_themes_button (gchar *theme){
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));
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"));
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"));
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"));
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"));
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"));
194 /*******************************************************************************/
196 create_rich_animation_button (gboolean active, gchar *name)
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);
204 /*******************************************************************************/
206 create_enable_button (gboolean active)
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);
215 /*******************************************************************************/
217 show_settings(GtkWidget *widget, Animation_WallpaperPrivate *priv){
218 lw_main_settings(priv, NULL);
220 /*******************************************************************************/
222 lw_main_settings(Animation_WallpaperPrivate *priv, gpointer data){
224 GtkWidget *window = NULL;
225 GtkWidget *theme_button1;
226 GtkWidget *theme_button2;
227 GtkWidget *theme_button3;
228 GtkWidget *theme_button4;
230 Animation_WallpaperPrivate *priv_temp = NULL;
232 window = gtk_dialog_new();
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);
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);
262 result = gtk_dialog_run(GTK_DIALOG(window));
264 priv_temp = g_object_get_data(G_OBJECT(theme_button1), "priv");
269 priv_temp = g_object_get_data(G_OBJECT(theme_button2), "priv");
274 priv_temp = g_object_get_data(G_OBJECT(theme_button3), "priv");
279 priv_temp = g_object_get_data(G_OBJECT(theme_button4), "priv");
287 case GTK_RESPONSE_NO:
288 gtk_widget_destroy(window);
296 gtk_widget_destroy(window);
298 /*******************************************************************************/
300 file_button_clicked(GtkButton *button, Animation_WallpaperPrivate *priv){
302 GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW (priv->window), GTK_FILE_CHOOSER_ACTION_OPEN);
304 if (priv->theme_string_parametr1)
305 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), priv->theme_string_parametr1);
307 gtk_widget_show_all (GTK_WIDGET (dialog));
309 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
311 hildon_button_set_value (HILDON_BUTTON(button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
313 gtk_widget_destroy (dialog);
316 /*******************************************************************************/
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);
327 /*******************************************************************************/
329 additional_parametr_for_theme_video(GtkWidget *vbox, Animation_WallpaperPrivate *priv){
331 GtkWidget *file_button;
332 GtkWidget *rich_animation_button;
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);
338 file_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,HILDON_BUTTON_ARRANGEMENT_VERTICAL,
341 g_signal_connect (file_button, "clicked", G_CALLBACK (file_button_clicked), priv);
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);
351 gtk_widget_show (file_button);
352 gtk_widget_show (rich_animation_button);
355 /*******************************************************************************/
357 lw_theme_settings(GtkWidget *button, Animation_WallpaperPrivate *priv) {
359 GtkWidget *window = NULL;
360 GtkWidget *save_button;
361 GtkWidget *theme_button;
362 GtkWidget *enable_button;
364 GtkWidget *button1 = NULL;
365 GtkWidget *rich_animation_button = NULL;
366 gint view = priv->view;
368 window = gtk_dialog_new();
369 priv->window = window;
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);
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);
396 if (!strcmp(hildon_button_get_value(HILDON_BUTTON (theme_button)), _("Video"))){
397 additional_parametr_for_theme_video(vbox, priv);
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);
406 result = gtk_dialog_run(GTK_DIALOG(window));
409 case GTK_RESPONSE_YES:
411 if (hildon_button_get_value(HILDON_BUTTON (theme_button))){
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");
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)));
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;
442 priv->rich_animation = FALSE;
446 /* action with applet */
447 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON(enable_button))){
448 if (!check_applet_state(view)){
451 send_dbus_signal (priv,
452 LIVEWP_SIGNAL_INTERFACE,
454 LIVEWP_RELOAD_CONFIG);
457 if (check_applet_state(view))
460 set_button_image(button, priv->theme, check_applet_state(view));
463 case GTK_RESPONSE_OK:
465 case GTK_RESPONSE_NO:
466 gtk_widget_destroy(window);
472 gtk_widget_destroy(window);
474 /*******************************************************************************/
476 check_applet_state(gint number){
478 HDConfigFile *config_file = NULL;
479 GKeyFile *gkey_file = NULL;
481 gboolean result = FALSE;
482 if (number > 4 || number < 1)
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");
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);
495 FILE *file_in = NULL;
498 file_in = fopen("/home/user/.config/hildon-desktop/home.plugins","r");
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);
506 "X-Desktop-File=/usr/share/applications/hildon-home/livewp-home-widget.desktop\n")){
515 /*******************************************************************************/
517 start_applet(gint number){
519 HDConfigFile *config_file = NULL;
520 GKeyFile *gkey_file = NULL;
523 if (number > 4 || number < 1)
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");
528 gkey_file = hd_config_file_load_file(config_file, FALSE);
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);
534 fprintf(stderr, "Problem with config file");
537 g_object_unref(config_file);
539 /*******************************************************************************/
541 stop_applet(gint number){
542 HDConfigFile *config_file = NULL;
543 GKeyFile *gkey_file = NULL;
546 if (number > 4 || number < 1)
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");
551 gkey_file = hd_config_file_load_file(config_file, FALSE);
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);
557 fprintf(stderr, "Problem with config file");
560 g_object_unref(config_file);
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);
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);
594 unlink ("/tmp/livewallpaper.plugins");