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 /*******************************************************************************/
31 void set_live_bg (Display *display, Window xwindow, int mode);
32 void quit_from_program (Animation_WallpaperPrivate *priv);
33 void view_state_changed (Animation_WallpaperPrivate *priv);
34 static gboolean short_timeout (AWallpaperPlugin *desktop_plugin);
35 void run_long_timeout(AWallpaperPlugin *desktop_plugin);
36 gboolean long_timeout (AWallpaperPlugin *desktop_plugin);
37 void conky_visible(AWallpaperPlugin *desktop_plugin);
40 set_live_bg (Display *display, Window xwindow, int mode)
44 atom = XInternAtom (display, "_HILDON_LIVE_DESKTOP_BACKGROUND", False);
45 fprintf (stderr, "XID: 0x%x\n", (unsigned)xwindow);
47 XChangeProperty (display,
50 XA_INTEGER, 32, PropModeReplace,
51 (unsigned char *) &mode, 1);
53 /*******************************************************************************/
56 view_state_changed (Animation_WallpaperPrivate *priv)
58 fprintf(stderr," VIew %i State %i\n", priv->view, priv->visible);
60 /* ToDo make undependent function */
62 if (!strcmp(priv->theme,"Video")){
64 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
66 init_scene_Video(priv->desktop_plugin);
70 if (!strcmp(priv->theme,"Conky")&& priv->running){
71 conky_visible(priv->desktop_plugin);
76 if (g_hash_table_lookup(priv->hash_theme, "exec_path")){
77 init_scene_External(priv->desktop_plugin);
80 if (priv->long_timer == 0 ){
81 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, priv->desktop_plugin);
82 run_long_timeout(priv->desktop_plugin);
84 run_long_timeout(priv->desktop_plugin);
89 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
93 if (!strcmp(priv->theme,"Conky")){
94 conky_visible(priv->desktop_plugin);
97 if (priv->long_timer != 0 ){
98 g_source_remove(priv->long_timer);
103 /*******************************************************************************/
105 check_alive_event(Animation_WallpaperPrivate *priv)
107 if ( time(NULL) - priv->last_alive_event > 10*60) /* If last event later 10 minute */
108 quit_from_program(priv);
112 /*******************************************************************************/
114 view_changed (GConfClient *client, guint cnxn_id,
115 GConfEntry *entry, Animation_WallpaperPrivate *priv)
117 if (entry->value->type == GCONF_VALUE_INT) {
118 if (priv->view == gconf_value_get_int(entry->value)){
119 if (priv->visible != TRUE){
120 priv->visible = TRUE;
121 view_state_changed(priv);
124 if (priv->visible != FALSE){
125 priv->visible = FALSE;
126 view_state_changed(priv);
131 /*******************************************************************************/
133 quit_from_program (Animation_WallpaperPrivate *priv)
135 fprintf(stderr,"quit_from_program\n");
137 livewp_deinitialize_dbus(priv);
138 if (priv->view_notify != 0) {
139 gconf_client_notify_remove (gconf_client_get_default (), priv->view_notify);
140 priv->view_notify = 0;
142 if (priv->long_timer){
143 g_source_remove(priv->long_timer);
144 priv->long_timer = 0;
146 if (priv->short_timer){
147 g_source_remove(priv->short_timer);
148 priv->short_timer = 0;
150 destroy_scene(priv->desktop_plugin);
151 osso_deinitialize(priv->osso);
152 //g_hash_table_destroy(priv->hash_scene_func);
153 g_free(priv->desktop_plugin);
154 priv->desktop_plugin = NULL;
158 fprintf(stderr,"end of quit_from_program\n");
161 /*******************************************************************************/
163 short_timeout (AWallpaperPlugin *desktop_plugin)
165 //gint daytime = get_daytime();
167 void (*pfunc)(gpointer, gpointer);
170 gboolean stop_flag = TRUE;
172 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
173 desktop_plugin->priv->short_timer = 0;
178 //scene.daytime = daytime;
179 /* fprintf(stderr, "Short timer %d\n", now); */
180 tmp = desktop_plugin->priv->scene->actors;
183 if (now >= actor->time_start_animation
184 && actor->time_start_animation > 0
185 /* && now - actor->time_start_animation <= actor->duration_animation*/){
186 pfunc = actor->func_change;
188 (*pfunc)(actor, desktop_plugin);
192 tmp = g_slist_next(tmp);
195 desktop_plugin->priv->short_timer = 0;
198 return TRUE; /* keep running this event */
200 /*******************************************************************************/
202 run_long_timeout(AWallpaperPlugin *desktop_plugin)
205 gint daytime = get_daytime();
207 void (*pfunc)(gpointer, gpointer);
211 if (!desktop_plugin->priv->scene)
213 /*ifprintf(stderr, "!!!run long timeout short_timer=%d\n", desktop_plugin->priv->short_timer); */
214 if (desktop_plugin->priv->scene->daytime != daytime){
215 desktop_plugin->priv->scene->daytime = daytime;
216 tmp = desktop_plugin->priv->scene->actors;
218 //change_actor(tmp->data);
219 pfunc =((Actor*)tmp->data)->func_change;
221 (*pfunc)(tmp->data, desktop_plugin);
223 tmp = g_slist_next(tmp);
228 //fprintf(stderr, "Now %d\n", now);
229 tmp = desktop_plugin->priv->scene->actors;
232 if (now >= actor->time_start_animation
233 && actor->time_start_animation > 0
234 && desktop_plugin->priv->short_timer == 0){
235 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
236 if (desktop_plugin->priv->rich_animation){
237 actor->time_start_animation = now;
238 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
241 (*actor->func_change)(actor, desktop_plugin);
244 tmp = g_slist_next(tmp);
248 /*******************************************************************************/
250 long_timeout (AWallpaperPlugin *desktop_plugin)
252 GstFormat fmt = GST_FORMAT_TIME;
255 /*fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
256 if (desktop_plugin->priv->pipeline){
257 if (!desktop_plugin->priv->visible){
258 gst_element_query_position(desktop_plugin->priv->pipeline, &fmt, &p);
259 desktop_plugin->priv->theme_int_parametr1 = p / GST_SECOND;
260 gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL);
261 gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
262 desktop_plugin->priv->pipeline = NULL;
267 if (desktop_plugin->priv->long_timer == 0 )
269 if (!desktop_plugin->priv->visible){
270 if(desktop_plugin->priv->short_timer != 0){
271 g_source_remove(desktop_plugin->priv->short_timer);
272 desktop_plugin->priv->short_timer = 0;
274 desktop_plugin->priv->long_timer = 0;
278 run_long_timeout(desktop_plugin);
279 return TRUE; /* keep running this event */
281 /*******************************************************************************/
283 create_xwindow (Animation_WallpaperPrivate *priv){
284 GtkWidget *main_widget = NULL;
285 GtkWidget *label = NULL;
286 /* Create Main GUI */
287 main_widget = hildon_window_new ();
288 priv->window = main_widget;
289 gtk_window_set_title(GTK_WINDOW(main_widget), PACKAGE);
290 gtk_window_fullscreen(GTK_WINDOW(main_widget));
291 label = gtk_label_new(_("Loading Livewallpaper scene ..."));
292 gtk_container_add (GTK_CONTAINER (main_widget), label);
293 gtk_widget_show_all(GTK_WIDGET(main_widget));
294 if (priv->one_in_all_view)
295 set_live_bg(GDK_WINDOW_XDISPLAY (main_widget->window), GDK_WINDOW_XID (main_widget->window), -1);
297 set_live_bg(GDK_WINDOW_XDISPLAY (main_widget->window), GDK_WINDOW_XID (main_widget->window), priv->view);
299 /*******************************************************************************/
301 main(int argc, char *argv[])
308 view = atoi(argv[1]);
309 if (view < 1 || view > 4)
312 AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
313 Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
314 desktop_plugin->priv = priv;
318 hildon_gtk_init (&argc, &argv);
319 app = HILDON_PROGRAM (hildon_program_get_instance());
320 g_set_application_name (PACKAGE);
322 priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL);
324 fprintf(stderr,"osso_initialize failed\n");
329 setlocale(LC_ALL, "");
330 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
331 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
332 textdomain(GETTEXT_PACKAGE);
336 priv->pipeline = NULL;
338 priv->running = FALSE;
339 /* fprintf(stderr,"XWINDOW %i\n",GDK_WINDOW_XID (main_widget->window)); */
340 priv->desktop_plugin = desktop_plugin;
345 fprintf(stderr,"THEME %s\n", priv->theme);
347 /* Check activity of opition "One theme in all views" */
348 if (priv->one_in_all_view && view >1)
352 if (current_active_view() == view && !priv->one_in_all_view)
353 priv->visible = TRUE;
355 priv->visible = FALSE;
358 create_xwindow(priv);
359 /* Initialize DBUS */
360 livewp_initialize_dbus(priv);
362 priv->view_notify = 0;
363 /* fprintf(stderr,"VISIBLE %i %i\n",priv->visible, current_active_view()); */
364 gconf_client_add_dir(gconf_client_get_default (), "/apps/osso/hildon-desktop/views", GCONF_CLIENT_PRELOAD_NONE, NULL);
365 priv->view_notify = gconf_client_notify_add(gconf_client_get_default (),"/apps/osso/hildon-desktop/views/current",
366 (GConfClientNotifyFunc)view_changed, priv, NULL, NULL);
368 /* Set start position of Video to zero */
369 if (!strcmp(priv->theme,"Video")){
370 gst_init (NULL, NULL);
371 priv->theme_int_parametr1 = 0;
374 init_scene_theme(desktop_plugin);
376 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
378 priv->alive_timer = g_timeout_add(60000*10, (GtkFunction)check_alive_event, priv); /* One per 10 minute */