2 * This file is part of Live Wallpaper (livewp)
4 * Copyright (C) 2010 Vlad Vasiliev
5 * Copyright (C) 2010 Tanya Makova
8 * This software is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This software is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this software; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 /*******************************************************************************/
25 #include <hildon/hildon.h>
26 #include "livewp-home-widget.h"
27 #include <libhildondesktop/libhildondesktop.h>
28 #include <gconf/gconf-client.h>
29 #include "livewp-astro.h"
31 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
32 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
33 #define GCONF_KEY_MODIFIED "/apps/osso/hildon-desktop/applets/%s/modified"
34 #define GCONF_KEY_VIEW "/apps/osso/hildon-desktop/applets/%s/view"
36 HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
38 #define Xstartposition 795
39 #define Ystartposition 430
41 gint xapplet = 0, yapplet = 0;
42 GSList * objects_list = NULL;
45 expose_event (GtkWidget *widget,GdkEventExpose *event,
49 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
51 cr = gdk_cairo_create(widget->window);
52 gdk_cairo_region(cr, event->region);
53 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
54 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
60 realize (GtkWidget *widget)
63 screen = gtk_widget_get_screen (widget);
64 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
68 init_applet_position(void)
70 /* To Do Must be Only 1 per secund */
71 GSList *position = NULL;
76 GConfClient *gconf_client = gconf_client_get_default ();
77 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
78 position = gconf_client_get_list (gconf_client,
82 if (position && position->data && position->next->data){
83 xapplet = GPOINTER_TO_INT (position->data);
84 yapplet = GPOINTER_TO_INT (position->next->data);
86 fprintf(stderr,"Not position \n");
87 position = g_slist_prepend (g_slist_prepend (NULL,
88 GINT_TO_POINTER (Ystartposition)),
89 GINT_TO_POINTER (Xstartposition));
90 gconf_client_set_list (gconf_client,
95 xapplet = Xstartposition;
96 yapplet = Ystartposition;
98 g_free (position_key);
99 modified = g_strdup_printf ("%ld", 0);
100 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
101 gconf_client_set_string (gconf_client,
105 fprintf(stderr,"position %i %i\n",xapplet, yapplet);
106 gconf_client_clear_cache(gconf_client);
107 g_object_unref(gconf_client);
110 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
112 fprintf(stderr, "actor_set_position_full\n");
113 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
116 GtkWidget* init_object(gchar * name, gint x, gint y, gint z, gint width, gint height)
122 actor = hildon_animation_actor_new();
124 snprintf(str, 255, "/usr/share/anwall/%s.png", name);
125 //fprintf(stderr, "!!!init object !!!!\nname = %s file = %s\n", name, str);
126 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
131 image = gtk_image_new_from_pixbuf (pixbuf);
132 g_object_unref(G_OBJECT(pixbuf));
134 g_signal_connect(G_OBJECT(image), "expose_event",
135 G_CALLBACK(expose_event), pixbuf);
137 gtk_container_add (GTK_CONTAINER (actor), image);
138 actor_set_position_full(actor, x, y, z);
139 hildon_animation_actor_set_show (actor, 1);
141 gtk_widget_show_all(actor);
142 g_object_set_data(G_OBJECT(actor), "name", name);
143 g_object_set_data(G_OBJECT(actor), "posX", x);
144 g_object_set_data(G_OBJECT(actor), "posY", y);
146 objects_list = g_slist_append(objects_list, G_OBJECT(actor));
151 init_scene(GtkWidget *window)
159 get_sun_pos(&alt, &azm);
160 get_sun_screen_pos(alt, azm, &x, &y);
161 if (x > 800) x = 700;
162 if (y > 480) y = 400;
163 actor = init_object("sun", x, y, 1, 88, 88);
164 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
165 actor = init_object("sky", 0, 0, 0, 800, 480);
166 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
167 actor = init_object("town", 0, 0, 10, 800, 480);
168 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
170 // actor = init_object("cloud1", 450, 100, 2, 200, 150);
171 // hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
177 example_label_home_applet_realize (GtkWidget *widget)
180 void get_coord(double * lat, double * lon)
185 void get_sun_pos(double * alt, double * azm)
190 get_coord(&lat, &lon);
192 localtime_r(&timet, &nowtime);
193 //fprintf(stderr, "plugin on timeout %i.%i.%i (%i) %i:%i:%i\n", nowtime.tm_mday, nowtime.tm_mon+1, nowtime.tm_year+1900, abs(nowtime.tm_gmtoff/3600), nowtime.tm_hour, nowtime.tm_min, nowtime.tm_sec);
194 fprintf(stderr, "before altitude\n");
195 *alt = altitude(lon, lat, nowtime.tm_year+1900, nowtime.tm_mon+1, nowtime.tm_mday, nowtime.tm_hour, nowtime.tm_min, nowtime.tm_gmtoff/3600);
197 *azm = azimuth(lon, lat, nowtime.tm_year+1900, nowtime.tm_mon+1, nowtime.tm_mday, nowtime.tm_hour, nowtime.tm_min, nowtime.tm_gmtoff/3600);
200 *azm = 90 + (90 - *azm);
201 *azm = fmod(*azm, 360);
203 *azm = (*azm - 90) / 180;
204 //fprintf(stderr, "alt=%5.6f azm=%5.6f\n", alt, azm);
208 void get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
210 gint y0 = 400;// - уровень горизонта
213 *x = (int)(azm * 800) - 64;
214 *y = (int)((1 - alt) * y0) - 64;
218 plugin_on_timeout (gpointer data)
224 get_sun_pos(&alt, &azm);
226 GSList * tmp = objects_list;
228 str = g_object_get_data(G_OBJECT(tmp->data), "name");
229 fprintf(stderr, "object: %s\n", str);
231 get_sun_screen_pos(alt, azm, &x, &y);
232 actor_set_position_full(tmp->data, x, y, 0);
233 fprintf(stderr, "x = %i, y = %i\n", x, y);
234 //g_object_set_data(G_OBJECT(tmp->data), "posX", x);
235 //g_object_set_data(G_OBJECT(tmp->data), "posY", y);
236 fprintf(stderr, "x = %d y = %d\n", x, y);
238 tmp = g_slist_next(tmp);
241 return TRUE; /* keep running this event */
245 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
248 label = gtk_label_new ("");
249 gtk_widget_show (label);
250 gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
251 init_applet_position();
252 init_scene(desktop_plugin);
253 desktop_plugin->timer = g_timeout_add(1000*60*1, plugin_on_timeout, desktop_plugin);
257 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {}
260 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {}