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-common.h"
26 #include "livewp-scene.h"
27 #include "livewp-settings.h"
28 #include "livewp-home-widget.h"
29 /*******************************************************************************/
32 btn_setting_clicked(HildonButton *btn, gpointer data)
34 Animation_WallpaperPrivate *priv = data;
35 // open settings dialog
36 fprintf(stderr, "btn setting clicked, %s\n", priv->theme);
37 lw_main_settings(priv, NULL);
38 fprintf(stderr, "btn setting clicked, %s\n", priv->theme);
40 /*******************************************************************************/
42 btn_power_clicked(HildonButton *btn, gpointer data)
45 value = hildon_button_get_value(btn);
46 fprintf(stderr, "applet must be %s\n", value);
47 if (!strcmp(value, "stop"))
48 hildon_button_set_text(HILDON_BUTTON(btn), _("Start"), "start");
50 hildon_button_set_text(HILDON_BUTTON(btn), _("Stop"), "stop");
52 /*******************************************************************************/
53 static void set_live_bg (Display *display, Window xwindow, int mode);
55 void set_live_bg (Display *display, Window xwindow, int mode)
59 atom = XInternAtom (display, "_HILDON_LIVE_DESKTOP_BACKGROUND", False);
60 fprintf (stderr, "XID: 0x%x\n", (unsigned)xwindow);
62 XChangeProperty (display,
65 XA_INTEGER, 32, PropModeReplace,
66 (unsigned char *) &mode, 1);
68 /*******************************************************************************/
70 view_state_changed (Animation_WallpaperPrivate *priv)
73 if (priv->long_timer == 0 ){
74 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, priv->desktop_plugin);
75 run_long_timeout(priv->desktop_plugin);
78 if (priv->long_timer != 0 ){
79 g_source_remove(priv->long_timer);
84 /*******************************************************************************/
86 check_alive_event(Animation_WallpaperPrivate *priv)
88 if ( time(NULL) - priv->last_alive_event > 10*60) /* If last event later 10 minute */
89 quit_from_program(priv);
93 /*******************************************************************************/
95 view_changed (GConfClient *client, guint cnxn_id,
96 GConfEntry *entry, Animation_WallpaperPrivate *priv)
98 if (entry->value->type == GCONF_VALUE_INT) {
99 if (priv->view == gconf_value_get_int(entry->value)){
100 if (priv->visible != TRUE){
101 priv->visible = TRUE;
102 view_state_changed(priv);
105 if (priv->visible != FALSE){
106 priv->visible = FALSE;
107 view_state_changed(priv);
112 /*******************************************************************************/
114 quit_from_program (Animation_WallpaperPrivate *priv)
116 fprintf(stderr,"quit_from_program\n");
118 livewp_deinitialize_dbus(priv);
119 if (priv->view_notify != 0) {
120 gconf_client_notify_remove (gconf_client_get_default (), priv->view_notify);
121 priv->view_notify = 0;
123 if (priv->long_timer){
124 g_source_remove(priv->long_timer);
125 priv->long_timer = 0;
127 if (priv->short_timer){
128 g_source_remove(priv->short_timer);
129 priv->short_timer = 0;
131 destroy_scene(priv->desktop_plugin);
132 osso_deinitialize(priv->osso);
133 g_hash_table_destroy(priv->hash_scene_func);
134 g_free(priv->desktop_plugin);
135 priv->desktop_plugin = NULL;
141 /*******************************************************************************/
143 main(int argc, char *argv[])
145 GtkWidget *main_widget = NULL;
151 view = atoi(argv[1]);
152 if (view < 1 || view > 4)
155 AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
156 Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
157 desktop_plugin->priv = priv;
159 gst_init (NULL, NULL);
162 hildon_gtk_init (&argc, &argv);
163 app = HILDON_PROGRAM (hildon_program_get_instance());
164 g_set_application_name (PACKAGE);
166 priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL);
168 fprintf(stderr,"osso_initialize failed\n");
173 setlocale(LC_ALL, "");
174 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
175 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
176 textdomain(GETTEXT_PACKAGE);
178 /* Create Main GUI */
179 main_widget = hildon_window_new ();
180 gtk_window_set_title(GTK_WINDOW(main_widget), PACKAGE);
181 gtk_window_fullscreen(GTK_WINDOW(main_widget));
183 gtk_widget_show_all(GTK_WIDGET(main_widget));
185 priv->hash_scene_func = g_hash_table_new(g_str_hash, g_str_equal);
186 g_hash_table_insert(priv->hash_scene_func, g_strdup("Accel"), (gpointer)&init_scene_Accel);
187 g_hash_table_insert(priv->hash_scene_func, g_strdup("Berlin"), (gpointer)&init_scene_Berlin);
188 g_hash_table_insert(priv->hash_scene_func, g_strdup("Modern"), (gpointer)&init_scene_Modern);
189 g_hash_table_insert(priv->hash_scene_func, g_strdup("Matrix"), (gpointer)&init_scene_Matrix);
190 g_hash_table_insert(priv->hash_scene_func, g_strdup("Video"), (gpointer)&init_scene_Video);
193 priv->window = main_widget;
194 fprintf(stderr,"XWINDOW %i\n",GDK_WINDOW_XID (main_widget->window));
195 priv->desktop_plugin = desktop_plugin;
200 /* Initialize DBUS */
201 livewp_initialize_dbus(priv);
202 set_live_bg(GDK_WINDOW_XDISPLAY (main_widget->window), GDK_WINDOW_XID (main_widget->window), view);
203 if (current_active_view() == view)
204 priv->visible = TRUE;
206 priv->visible = FALSE;
208 priv->view_notify = 0;
209 fprintf(stderr,"VISIBLE %i %i\n",priv->visible, current_active_view());
210 gconf_client_add_dir(gconf_client_get_default (), "/apps/osso/hildon-desktop/views", GCONF_CLIENT_PRELOAD_NONE, NULL);
211 priv->view_notify = gconf_client_notify_add(gconf_client_get_default (),"/apps/osso/hildon-desktop/views/current",
212 (GConfClientNotifyFunc)view_changed, priv, NULL, NULL);
214 init_scene_theme(desktop_plugin);
216 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
218 priv->alive_timer = g_timeout_add(60000*10, (GtkFunction)check_alive_event, priv); /* One per 10 minute */