fork is done
[livewp] / applet / src / livewp-main.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-common.h"
26 #include "livewp-scene.h"
27 #include "livewp-settings.h"
28 #include "livewp-home-widget.h"
29 /*******************************************************************************/
30 #include <X11/extensions/Xrender.h>
31 #include <gdk/gdkx.h>
32
33 #include <X11/Xatom.h>
34
35 void 
36 btn_setting_clicked(HildonButton *btn, gpointer data)
37 {
38     Animation_WallpaperPrivate *priv = data;
39     // open settings dialog
40     fprintf(stderr, "btn setting clicked, %s\n", priv->theme);
41     lw_main_settings(priv, NULL);
42     fprintf(stderr, "btn setting clicked, %s\n", priv->theme);
43 }
44 void
45 btn_power_clicked(HildonButton *btn, gpointer data)
46 {
47     const gchar *value; 
48     value = hildon_button_get_value(btn);
49     fprintf(stderr, "applet must be %s\n", value);
50     if (!strcmp(value, "stop"))
51         hildon_button_set_text(HILDON_BUTTON(btn), _("Start"), "start");
52     else 
53         hildon_button_set_text(HILDON_BUTTON(btn), _("Stop"), "stop");
54 }
55 static void set_live_bg (Display *display, Window xwindow, int mode)
56 {
57         Atom atom;
58
59         atom = XInternAtom (display, "_HILDON_LIVE_DESKTOP_BACKGROUND", False);
60         fprintf (stderr, "XID: 0x%x\n", (unsigned)xwindow);
61
62         XChangeProperty (display,
63                        xwindow,
64                        atom,
65                        XA_INTEGER, 32, PropModeReplace,
66                        (unsigned char *) &mode, 1);
67 }
68 void
69 quit_from_program (Animation_WallpaperPrivate *priv)
70 {
71      if (priv){
72              livewp_deinitialize_dbus(priv);
73              if (priv->long_timer){
74                     g_source_remove(priv->long_timer);
75                 priv->long_timer = 0;
76              }
77              if (priv->short_timer){
78                     g_source_remove(priv->short_timer);
79                     priv->short_timer = 0;
80              }
81              destroy_scene(priv->desktop_plugin);
82      }
83      gtk_main_quit();;
84 }
85
86 int
87 main(int argc, char *argv[])
88 {
89     GtkWidget *main_widget = NULL;
90     GtkWidget *window;
91     GtkWidget *btn_setting, *vbox, *btn_power;
92     gint result;
93     HildonProgram       *app;
94     int view = 1;
95
96      
97     if (argc == 2) 
98         view = atoi(argv[1]);
99     if (view < 1 || view > 4)
100         view = 1;
101
102     AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
103     Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
104     desktop_plugin->priv = priv; 
105
106
107     /* Ininitializing */
108     hildon_gtk_init (&argc, &argv);
109     app = HILDON_PROGRAM (hildon_program_get_instance());
110     g_set_application_name (PACKAGE);
111  
112     priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL);
113     if(!priv->osso){
114         fprintf(stderr,"osso_initialize failed\n");
115         return 1;
116     }
117
118 #ifdef ENABLE_NLS
119     setlocale(LC_ALL, "");
120     bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
121     bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
122     textdomain(GETTEXT_PACKAGE);
123 #endif
124 /* Create Main GUI */
125     main_widget = hildon_window_new ();
126     gtk_window_set_title(GTK_WINDOW(main_widget), PACKAGE);
127     
128     gtk_widget_show_all(GTK_WIDGET(main_widget));
129
130     priv->hash_scene_func = g_hash_table_new(g_str_hash, g_str_equal);
131     g_hash_table_insert(priv->hash_scene_func, g_strdup("Berlin"), (gpointer)&init_scene_Berlin);
132     g_hash_table_insert(priv->hash_scene_func, g_strdup("Modern"), (gpointer)&init_scene_Modern);
133     g_hash_table_insert(priv->hash_scene_func, g_strdup("Matrix"), (gpointer)&init_scene_Matrix);
134
135     priv->scene = NULL;
136     priv->window = main_widget;
137
138     priv->view = view;
139     /* Load config */
140     read_config(priv);
141     /* Initialize DBUS */
142     livewp_initialize_dbus(priv);
143     set_live_bg(GDK_WINDOW_XDISPLAY (main_widget->window), GDK_WINDOW_XID (main_widget->window), view);
144     if (current_active_view() == view) 
145         priv->visible = TRUE;
146     else 
147         priv->visible = FALSE;
148
149     fprintf(stderr,"VISIBLE %i %i\n",priv->visible, current_active_view());
150     init_scene_theme(desktop_plugin);
151         
152     priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
153
154     gtk_main();
155 }