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-actor.h"
28 init_object(AWallpaperPlugin *desktop_plugin,
40 void (*pfunc_change)(Actor*),
41 void (*pfunc_probability)(Actor*),
46 actor = g_new0(Actor, 1);
51 actor->height = height;
52 actor->visible = visible;
54 actor->opacity = opacity;
55 actor->filename = g_strdup(filename);
56 actor->name = g_strdup(name);
57 actor->func_change = (gpointer)pfunc_change;
58 actor->func_probability = (gpointer)pfunc_probability;
61 create_hildon_actor(actor, desktop_plugin);
64 actor->time_start_animation = 0;
65 actor->duration_animation = 0;
70 destroy_actor(Actor *actor)
74 g_ptr_array_free(actor->child, TRUE);
77 g_free(actor->filename);
80 gtk_widget_destroy(actor->widget);
81 //actor->widget = NULL;
86 path_line(gint x0, gint x1, double t)
89 return ((x1 - x0) * t + x0);
92 set_actor_scale(Actor *actor, double scalex, double scaley)
94 hildon_animation_actor_set_scale(
95 HILDON_ANIMATION_ACTOR(actor->widget),
103 set_actor_visible(Actor *actor, gboolean visible)
105 hildon_animation_actor_set_show(HILDON_ANIMATION_ACTOR(actor->widget), visible);
109 set_actor_position(Actor *actor, gint x, gint y, gint z, AWallpaperPlugin *desktop_plugin)
111 hildon_animation_actor_set_position_full(HILDON_ANIMATION_ACTOR (actor->widget),
112 x-desktop_plugin->priv->xapplet,
113 y-desktop_plugin->priv->yapplet,
117 int get_notify_count(gchar *notify_type)
121 gint rc = 0, result = 0;
124 rc = sqlite3_open("/home/user/.config/hildon-desktop/notifications.db", &db);
126 fprintf(stderr, "error open db %d %s\n", rc, sqlite3_errmsg(db));
128 snprintf(sql, sizeof(sql)-1, "select count(id) from notifications where icon_name='general_%s'", notify_type);
129 rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
130 if (rc != SQLITE_OK){
131 fprintf(stderr, "error prepare %d %s\n", rc, sql);
133 if (sqlite3_step(res) != SQLITE_ROW){
134 fprintf(stderr, "not sqlite_row\n");
136 result = sqlite3_column_int(res, 0);
137 //fprintf(stderr, "count missing calls = %d\n", call_count);
138 sqlite3_finalize(res);
144 gchar * read_notification()
149 fprintf(stderr, "read notification \n");
150 count = get_notify_count("missed");
152 message = g_strdup_printf("%s: %d", _("Missed calls"), count);
154 count = get_notify_count("sms");
157 message = g_strdup_printf("%s \n%s: %d", message, _("Missed sms"), count);
159 message = g_strdup_printf("%s: %d", _("Missed sms"), count);
162 count = get_notify_count("chat");
165 message = g_strdup_printf("%s \n%s: %d", message, _("Missed chat"), count);
167 message = g_strdup_printf("%s: %d", _("Missed chat"), count);
170 count = get_notify_count("mail");
173 message = g_strdup_printf("%s \n%s: %d", message, _("Missed mail"), count);
175 message = g_strdup_printf("%s: %d", _("Missed mail"), count);
182 change_billboard(Actor * actor, AWallpaperPlugin *desktop_plugin)
185 gchar *mes = NULL, *message = NULL;
186 PangoFontDescription *pfd = NULL;
188 fprintf(stderr, "change_billboard\n");
189 if (desktop_plugin->priv->scene->notification){
190 message = read_notification();
191 label = actor->image;
192 mes = g_markup_printf_escaped("<span bgcolor=\"%s\" foreground=\"%s\">%s</span>", "#FFFFFF", "#000000",
194 gtk_label_set_markup(GTK_LABEL(label), mes);
195 pfd = pango_font_description_from_string("Sans 16");
196 gtk_widget_modify_font(GTK_WIDGET(label), NULL);
197 gtk_widget_modify_font(GTK_WIDGET(label), pfd);
198 pango_font_description_free(pfd);
200 desktop_plugin->priv->scene->notification = FALSE;
202 actor->time_start_animation = time(NULL) + 20;
207 change_billboard1(Actor * actor, AWallpaperPlugin *desktop_plugin)
211 sqlite3_stmt *res = NULL;
212 gchar *errMsg = NULL, *message;
214 gint call_count=0, sms_count=0, rc=0;
215 GtkListStore *list = NULL;
216 PangoFontDescription *pfd = NULL;
218 rc = sqlite3_open("/home/user/.rtcom-eventlogger/el.db", &db);
220 fprintf(stderr, "error open db %d %s\n", rc, sqlite3_errmsg(db));
222 snprintf(sql, sizeof(sql)-1, "select count(id) from Events where event_type_id=%d", 3);
224 rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
225 if (rc != SQLITE_OK){
226 fprintf(stderr, "error prepare %d %s\n", rc, sql);
228 if (sqlite3_step(res) != SQLITE_ROW){
229 fprintf(stderr, "not sqlite_row\n");
231 call_count = sqlite3_column_int(res, 0);
232 //fprintf(stderr, "count missing calls = %d\n", call_count);
233 sqlite3_finalize(res);
235 snprintf(sql, sizeof(sql)-1, "select count(id) from Events where event_type_id=%d and is_read=%d", 7, 0);
236 rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
237 if (rc != SQLITE_OK){
238 fprintf(stderr, "error prepare %d %s\n", rc, sql);
240 if (sqlite3_step(res) != SQLITE_ROW){
241 fprintf(stderr, "not sqlite_row\n");
243 sms_count = sqlite3_column_int(res, 0);
244 //fprintf(stderr, "count sms = %d\n", sms_count);
245 sqlite3_finalize(res);
250 label = actor->image;
251 message = g_markup_printf_escaped("<span bgcolor=\"%s\" foreground=\"%s\">Missed calls: %d Unread sms: %d</span>", "#FFFFFF", "#000000", call_count, sms_count);
252 gtk_label_set_markup(GTK_LABEL(label), message);
254 pfd = pango_font_description_from_string("Sans 14");
255 gtk_widget_modify_font(GTK_WIDGET(label), NULL);
256 gtk_widget_modify_font(GTK_WIDGET(label), pfd);
257 pango_font_description_free(pfd);
258 actor->time_start_animation = time(NULL) + 20;
263 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
277 a = (double)(y2 - (double)(x2*(y1-y0) + x1*y0 - x0*y1)/(x1-x0))/(x2*(x2-x0-x1)+x0*x1);
278 b = (double)(y1-y0)/(x1-x0) - (double)a*(x0+x1);
279 c = (double)(x1*y0 - x0*y1)/(x1-x0) + (double)a*x0*x1;
280 fprintf(stderr, "a=%f, b=%f, c=%f\n", a, b, c);
282 gettimeofday(&tvb, NULL);
288 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
289 if (!actor->visible){
290 actor->visible = TRUE;
291 phase = get_moon_phase();
292 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
294 g_free(actor->filename);
295 actor->filename = newfile;
296 actor->time_start_animation = sec - fast_rnd(60 * 60);
297 actor->duration_animation = 1 * 60 * 60;
298 create_hildon_actor(actor, desktop_plugin);
301 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
303 x = path_line(x0, x1, t);
305 x = path_line(x1, x0, t-1);
306 y = 0.001920*x*x - 1.536*x + 337.2;
307 //y = a*x*x + b*x + c;
309 set_actor_position(actor, x, y, actor->z, desktop_plugin);
312 actor->time_start_animation = sec;
315 }else if (actor->visible){
316 actor->visible = FALSE;
317 fprintf(stderr, "destroy moon \n");
318 destroy_hildon_actor(actor);
319 actor->time_start_animation = 0;
326 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
331 //fprintf(stderr, "change sun\n");
333 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
334 if (!actor->visible){
335 actor->visible = TRUE;
336 create_hildon_actor(actor, desktop_plugin);
338 get_sun_pos(&alt, &azm);
339 get_sun_screen_pos(alt, azm, &x, &y);
342 set_actor_position(actor, x, y, actor->z, desktop_plugin);
343 actor->time_start_animation = time(NULL) + 60;
344 }else if (actor->visible){
345 actor->visible = FALSE;
346 destroy_hildon_actor(actor);
347 actor->time_start_animation = 0;
354 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
356 gint x0 = -300, y0 = 225, scale0 = 100,
357 x1 = 800, y1 = 162, scale1 = 130,
364 //fprintf(stderr, "change tram\n");
365 gettimeofday(&tvb, NULL);
370 if (!actor->visible){
371 actor->visible = TRUE;
372 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
374 g_free(actor->filename);
375 actor->filename = g_strdup("tram_dark.png");
378 g_free(actor->filename);
379 actor->filename = g_strdup("tram.png");
381 create_hildon_actor(actor, desktop_plugin);
383 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
384 x = path_line(x0, x1, t);
385 y = path_line(y0, y1, t);
386 scale = path_line(scale0, scale1, t);
387 set_actor_position(actor, x, y, actor->z, desktop_plugin);
388 set_actor_scale(actor, (double)scale/100, (double)scale/100);
391 actor->visible = FALSE;
392 destroy_hildon_actor(actor);
393 actor->time_start_animation = sec + fast_rnd(60);
398 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
400 gint x0 = 620, y0 = 233,
408 gettimeofday(&tvb, NULL);
412 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
414 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
415 if (actor->time_start_animation == 0){
416 actor->time_start_animation = sec + fast_rnd(180);
420 if (!actor->visible){
421 actor->visible = TRUE;
422 create_hildon_actor(actor, desktop_plugin);
424 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
425 x = path_line(x0, x1, t);
426 y = path_line(y0, y1, t);
427 //scale = path_line(scale0, scale1, t);
428 set_actor_position(actor, x, y, actor->z, desktop_plugin);
431 actor->visible = FALSE;
432 destroy_hildon_actor(actor);
433 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
434 actor->time_start_animation = 0;
436 actor->time_start_animation = sec + fast_rnd(180);
442 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
444 gint x0 = -actor->width, y0 = 45,
452 gettimeofday(&tvb, NULL);
456 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
457 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
458 if (actor->time_start_animation == 0){
459 actor->time_start_animation = sec + fast_rnd(180);
463 if (!actor->visible){
464 actor->visible = TRUE;
465 create_hildon_actor(actor, desktop_plugin);
468 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
469 x = path_line(x0, x1, t);
470 y = path_line(y0, y1, t);
471 //scale = path_line(scale0, scale1, t);
472 set_actor_position(actor, x, y, actor->z, desktop_plugin);
475 actor->visible = FALSE;
476 destroy_hildon_actor(actor);
477 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
478 actor->time_start_animation = 0;
480 actor->time_start_animation = sec + fast_rnd(180);
486 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
488 gint x0, y0 = 300, scale0 = 100,
489 x1, y1 = -actor->height, scale1 = 150,
497 //fprintf(stderr, "change cloud\n");
498 gettimeofday(&tvb, NULL);
503 if (!actor->visible){
504 actor->visible = TRUE;
505 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
506 newfile = g_strdup_printf("%s_dark.png", actor->name);
508 newfile = g_strdup_printf("%s.png", actor->name);
511 g_free(actor->filename);
512 actor->filename = newfile;
514 create_hildon_actor(actor, desktop_plugin);
516 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
518 if (desktop_plugin->priv->scene->wind_orientation == 1){
527 x = path_line(x0, x1, t);
528 y = -desktop_plugin->priv->scene->wind_angle * (x - x0) + actor->y;
529 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
531 set_actor_position(actor, x, y, actor->z, desktop_plugin);
532 set_actor_scale(actor, (double)scale/100, (double)scale/100);
533 if ((y < y1 || y > y0) || t >= 1){
535 actor->visible = FALSE;
536 destroy_hildon_actor(actor);
537 actor->time_start_animation = sec + fast_rnd(300);
538 actor->y = fast_rnd(300);
544 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
546 desktop_plugin->priv->scene->wind_orientation = fast_rnd(2);
547 if (desktop_plugin->priv->scene->wind_orientation == 0) desktop_plugin->priv->scene->wind_orientation = -1;
548 desktop_plugin->priv->scene->wind_angle = (double)(fast_rnd(200) - 100) / 100;
549 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
550 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
554 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
556 gint now = time(NULL);
557 if (desktop_plugin->priv->scene->daytime == TIME_DAY){
559 actor->visible = FALSE;
560 destroy_hildon_actor(actor);
562 actor->time_start_animation = 0;
566 create_hildon_actor(actor, desktop_plugin);
567 if (actor->time_start_animation == 0){
568 actor->time_start_animation = now + fast_rnd(30);
574 actor->visible = TRUE;
576 actor->visible = FALSE;
577 set_actor_visible(actor, actor->visible);
578 actor->time_start_animation = now + fast_rnd(60) + 10;
583 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
585 gint now = time(NULL);
587 a = g_ptr_array_index(actor->child, 0);
592 set_actor_visible(a, a->visible);
594 a = g_ptr_array_index(actor->child, 1);
599 set_actor_visible(a, a->visible);
601 actor->time_start_animation = now + fast_rnd(30) + 10;
605 change_layer(Actor * actor, AWallpaperPlugin *desktop_plugin)
607 gint y, speed1 = 8, speed2 = 16;
610 if (!desktop_plugin->priv->rich_animation) return;
612 a = g_ptr_array_index(actor->child, 0);
614 if (y > 480) y = -480;
615 set_actor_position(a, a->x, y, a->z, desktop_plugin);
618 a = g_ptr_array_index(actor->child, 1);
620 if (y > 480) y = -480;
621 set_actor_position(a, a->x, y, a->z, desktop_plugin);
624 a = g_ptr_array_index(actor->child, 2);
626 if (y > 480) y = -480;
627 set_actor_position(a, a->x, y, a->z, desktop_plugin);
630 a = g_ptr_array_index(actor->child, 3);
632 if (y > 480) y = -480;
633 set_actor_position(a, a->x, y, a->z, desktop_plugin);
638 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
641 newfile = g_strdup_printf("%s%d.png", actor->name, desktop_plugin->priv->scene->daytime);
643 g_free(actor->filename);
644 actor->filename = newfile;
645 change_hildon_actor(actor, desktop_plugin);
649 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
653 if (desktop_plugin->priv->right_corner)
654 gtk_widget_destroy(desktop_plugin->priv->right_corner);
655 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
656 THEME_PATH, desktop_plugin->priv->theme, desktop_plugin->priv->scene->daytime);
657 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
658 if (desktop_plugin->priv->right_corner){
659 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
660 gtk_widget_show (desktop_plugin->priv->right_corner);
662 change_static_actor(actor, desktop_plugin);