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),
102 set_actor_rotation(Actor *actor, gint axis, double degrees, gint x, gint y, gint z)
104 hildon_animation_actor_set_rotation(
105 HILDON_ANIMATION_ACTOR(actor->widget),
114 set_actor_visible(Actor *actor, gboolean visible)
116 hildon_animation_actor_set_show(HILDON_ANIMATION_ACTOR(actor->widget), visible);
120 set_actor_position(Actor *actor, gint x, gint y, gint z, AWallpaperPlugin *desktop_plugin)
122 hildon_animation_actor_set_position_full(HILDON_ANIMATION_ACTOR (actor->widget),
123 x-desktop_plugin->priv->xapplet,
124 y-desktop_plugin->priv->yapplet,
128 int get_notify_count(gchar *notify_type)
131 sqlite3_stmt *res = NULL;
132 gint rc = 0, result = 0;
135 rc = sqlite3_open("/home/user/.config/hildon-desktop/notifications.db", &db);
137 fprintf(stderr, "error open db %d %s\n", rc, sqlite3_errmsg(db));
139 snprintf(sql, sizeof(sql)-1, "select count(id) from notifications where icon_name='%s'", notify_type);
140 rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
141 if (rc != SQLITE_OK){
142 fprintf(stderr, "error prepare %d %s\n", rc, sql);
144 if (sqlite3_step(res) != SQLITE_ROW){
145 fprintf(stderr, "not sqlite_row\n");
147 result = sqlite3_column_int(res, 0);
148 //fprintf(stderr, "count missing calls = %d\n", call_count);
149 sqlite3_finalize(res);
155 gchar * read_notification()
160 fprintf(stderr, "read notification \n");
161 count = get_notify_count("general_missed");
163 message = g_strdup_printf("%s: %d", _("Missed calls"), count);
165 count = get_notify_count("general_sms");
168 message = g_strdup_printf("%s \n%s: %d", message, _("Missed sms"), count);
170 message = g_strdup_printf("%s: %d", _("Missed sms"), count);
173 count = get_notify_count("general_chat");
176 message = g_strdup_printf("%s \n%s: %d", message, _("Missed chat"), count);
178 message = g_strdup_printf("%s: %d", _("Missed chat"), count);
181 count = get_notify_count("qgn_list_messagin");
184 message = g_strdup_printf("%s \n%s: %d", message, _("Missed mail"), count);
186 message = g_strdup_printf("%s: %d", _("Missed mail"), count);
189 fprintf(stderr, "notify=%s\n", message);
194 change_obj(Actor *actor, AWallpaperPlugin *desktop_plugin)
196 char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
197 //char * accel_filename = "/home/tanya/coord";
200 int rs, ax, ay, az, dx, dy;
201 fd = fopen(accel_filename, "r");
203 fprintf(stderr, "cannot open file\n");
206 rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
209 fprintf(stderr, "cannot read information from file\n");
213 fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
217 actor->x = actor->x + dx;
218 actor->y = actor->y + dy;
220 if (actor->x > 800) actor->x = 0;
221 if (actor->x < 0) actor->x = 800;
223 if (actor->y > 480) actor->y = 0;
224 if (actor->y < 0) actor->y = 480;
226 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
232 change_billboard(Actor * actor, AWallpaperPlugin *desktop_plugin)
237 //fprintf(stderr, "change_billboard\n");
239 if (desktop_plugin->priv->scene->notification < time(NULL)){
240 count = get_notify_count("general_missed");
241 a = g_ptr_array_index(actor->child, 0);
243 set_actor_visible(a, TRUE);
245 set_actor_visible(a, FALSE);
247 count = get_notify_count("general_sms");
248 a = g_ptr_array_index(actor->child, 3);
250 set_actor_visible(a, TRUE);
252 set_actor_visible(a, FALSE);
254 count = get_notify_count("general_chat");
255 a = g_ptr_array_index(actor->child, 1);
257 set_actor_visible(a, TRUE);
259 set_actor_visible(a, FALSE);
261 count = get_notify_count("qgn_list_messagin");
262 a = g_ptr_array_index(actor->child, 2);
264 set_actor_visible(a, TRUE);
266 set_actor_visible(a, FALSE);
269 desktop_plugin->priv->scene->notification = FALSE;
271 actor->time_start_animation = time(NULL) + 20;
276 change_billboard1(Actor * actor, AWallpaperPlugin *desktop_plugin)
280 sqlite3_stmt *res = NULL;
281 gchar *errMsg = NULL, *message;
283 gint call_count=0, sms_count=0, rc=0;
284 GtkListStore *list = NULL;
285 PangoFontDescription *pfd = NULL;
287 rc = sqlite3_open("/home/user/.rtcom-eventlogger/el.db", &db);
289 fprintf(stderr, "error open db %d %s\n", rc, sqlite3_errmsg(db));
291 snprintf(sql, sizeof(sql)-1, "select count(id) from Events where event_type_id=%d", 3);
293 rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
294 if (rc != SQLITE_OK){
295 fprintf(stderr, "error prepare %d %s\n", rc, sql);
297 if (sqlite3_step(res) != SQLITE_ROW){
298 fprintf(stderr, "not sqlite_row\n");
300 call_count = sqlite3_column_int(res, 0);
301 //fprintf(stderr, "count missing calls = %d\n", call_count);
302 sqlite3_finalize(res);
304 snprintf(sql, sizeof(sql)-1, "select count(id) from Events where event_type_id=%d and is_read=%d", 7, 0);
305 rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
306 if (rc != SQLITE_OK){
307 fprintf(stderr, "error prepare %d %s\n", rc, sql);
309 if (sqlite3_step(res) != SQLITE_ROW){
310 fprintf(stderr, "not sqlite_row\n");
312 sms_count = sqlite3_column_int(res, 0);
313 //fprintf(stderr, "count sms = %d\n", sms_count);
314 sqlite3_finalize(res);
319 label = actor->image;
320 message = g_markup_printf_escaped("<span bgcolor=\"%s\" foreground=\"%s\">Missed calls: %d Unread sms: %d</span>", "#FFFFFF", "#000000", call_count, sms_count);
321 gtk_label_set_markup(GTK_LABEL(label), message);
323 pfd = pango_font_description_from_string("Sans 14");
324 gtk_widget_modify_font(GTK_WIDGET(label), NULL);
325 gtk_widget_modify_font(GTK_WIDGET(label), pfd);
326 pango_font_description_free(pfd);
327 actor->time_start_animation = time(NULL) + 20;
332 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
346 a = (double)(y2 - (double)(x2*(y1-y0) + x1*y0 - x0*y1)/(x1-x0))/(x2*(x2-x0-x1)+x0*x1);
347 b = (double)(y1-y0)/(x1-x0) - (double)a*(x0+x1);
348 c = (double)(x1*y0 - x0*y1)/(x1-x0) + (double)a*x0*x1;
349 fprintf(stderr, "a=%f, b=%f, c=%f\n", a, b, c);
351 gettimeofday(&tvb, NULL);
357 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
358 if (!actor->visible){
359 actor->visible = TRUE;
360 phase = get_moon_phase();
361 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
363 g_free(actor->filename);
364 actor->filename = newfile;
365 actor->time_start_animation = sec - fast_rnd(60 * 60);
366 actor->duration_animation = 1 * 60 * 60;
367 create_hildon_actor(actor, desktop_plugin);
370 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
372 x = path_line(x0, x1, t);
374 x = path_line(x1, x0, t-1);
375 y = 0.001920*x*x - 1.536*x + 337.2;
376 //y = a*x*x + b*x + c;
378 set_actor_position(actor, x, y, actor->z, desktop_plugin);
381 actor->time_start_animation = sec;
384 }else if (actor->visible){
385 actor->visible = FALSE;
386 fprintf(stderr, "destroy moon \n");
387 destroy_hildon_actor(actor);
388 actor->time_start_animation = 0;
395 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
400 //fprintf(stderr, "change sun\n");
402 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
403 if (!actor->visible){
404 actor->visible = TRUE;
405 create_hildon_actor(actor, desktop_plugin);
407 get_sun_pos(&alt, &azm);
408 get_sun_screen_pos(alt, azm, &x, &y);
411 set_actor_position(actor, x, y, actor->z, desktop_plugin);
412 actor->time_start_animation = time(NULL) + 60;
413 }else if (actor->visible){
414 actor->visible = FALSE;
415 destroy_hildon_actor(actor);
416 actor->time_start_animation = 0;
423 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
425 gint x0 = -300, y0 = 225, scale0 = 100,
426 x1 = 800, y1 = 162, scale1 = 130,
433 //fprintf(stderr, "change tram\n");
434 gettimeofday(&tvb, NULL);
439 if (!actor->visible){
440 actor->visible = TRUE;
441 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
443 g_free(actor->filename);
444 actor->filename = g_strdup("tram_dark.png");
447 g_free(actor->filename);
448 actor->filename = g_strdup("tram.png");
450 create_hildon_actor(actor, desktop_plugin);
452 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
453 x = path_line(x0, x1, t);
454 y = path_line(y0, y1, t);
455 scale = path_line(scale0, scale1, t);
456 set_actor_position(actor, x, y, actor->z, desktop_plugin);
457 set_actor_scale(actor, (double)scale/100, (double)scale/100);
460 actor->visible = FALSE;
461 destroy_hildon_actor(actor);
462 actor->time_start_animation = sec + fast_rnd(60);
467 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
469 gint x0 = 620, y0 = 233,
477 gettimeofday(&tvb, NULL);
481 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
483 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
484 if (actor->time_start_animation == 0){
485 actor->time_start_animation = sec + fast_rnd(180);
489 if (!actor->visible){
490 actor->visible = TRUE;
491 create_hildon_actor(actor, desktop_plugin);
493 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
494 x = path_line(x0, x1, t);
495 y = path_line(y0, y1, t);
496 //scale = path_line(scale0, scale1, t);
497 set_actor_position(actor, x, y, actor->z, desktop_plugin);
500 actor->visible = FALSE;
501 destroy_hildon_actor(actor);
502 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
503 actor->time_start_animation = 0;
505 actor->time_start_animation = sec + fast_rnd(180);
511 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
513 gint x0 = -actor->width, y0 = 45,
521 gettimeofday(&tvb, NULL);
525 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
526 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
527 if (actor->time_start_animation == 0){
528 actor->time_start_animation = sec + fast_rnd(180);
532 if (!actor->visible){
533 actor->visible = TRUE;
534 create_hildon_actor(actor, desktop_plugin);
537 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
538 x = path_line(x0, x1, t);
539 y = path_line(y0, y1, t);
540 //scale = path_line(scale0, scale1, t);
541 set_actor_position(actor, x, y, actor->z, desktop_plugin);
544 actor->visible = FALSE;
545 destroy_hildon_actor(actor);
546 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
547 actor->time_start_animation = 0;
549 actor->time_start_animation = sec + fast_rnd(180);
555 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
557 gint x0, y0 = 300, scale0 = 100,
558 x1, y1 = -actor->height, scale1 = 150,
566 //fprintf(stderr, "change cloud\n");
567 gettimeofday(&tvb, NULL);
572 if (!actor->visible){
573 actor->visible = TRUE;
574 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
575 newfile = g_strdup_printf("%s_dark.png", actor->name);
577 newfile = g_strdup_printf("%s.png", actor->name);
580 g_free(actor->filename);
581 actor->filename = newfile;
583 create_hildon_actor(actor, desktop_plugin);
585 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
587 if (desktop_plugin->priv->scene->wind_orientation == 1){
596 x = path_line(x0, x1, t);
597 y = -desktop_plugin->priv->scene->wind_angle * (x - x0) + actor->y;
598 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
600 set_actor_position(actor, x, y, actor->z, desktop_plugin);
601 set_actor_scale(actor, (double)scale/100, (double)scale/100);
602 if ((y < y1 || y > y0) || t >= 1){
604 actor->visible = FALSE;
605 destroy_hildon_actor(actor);
606 actor->time_start_animation = sec + fast_rnd(300);
607 actor->y = fast_rnd(300);
613 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
615 desktop_plugin->priv->scene->wind_orientation = fast_rnd(2);
616 if (desktop_plugin->priv->scene->wind_orientation == 0) desktop_plugin->priv->scene->wind_orientation = -1;
617 desktop_plugin->priv->scene->wind_angle = (double)(fast_rnd(200) - 100) / 100;
618 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
619 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
623 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
625 gint now = time(NULL);
626 if (desktop_plugin->priv->scene->daytime == TIME_DAY){
628 actor->visible = FALSE;
629 destroy_hildon_actor(actor);
631 actor->time_start_animation = 0;
635 create_hildon_actor(actor, desktop_plugin);
636 if (actor->time_start_animation == 0){
637 actor->time_start_animation = now + fast_rnd(30);
643 actor->visible = TRUE;
645 actor->visible = FALSE;
646 set_actor_visible(actor, actor->visible);
647 actor->time_start_animation = now + fast_rnd(60) + 10;
652 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
654 gint now = time(NULL);
656 a = g_ptr_array_index(actor->child, 0);
661 set_actor_visible(a, a->visible);
663 a = g_ptr_array_index(actor->child, 1);
668 set_actor_visible(a, a->visible);
670 actor->time_start_animation = now + fast_rnd(30) + 10;
674 change_tape(Actor *actor, AWallpaperPlugin *desktop_plugin)
677 speed[4] = {7, 10, 5, 14},
683 char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
684 //char * accel_filename = "/home/tanya/coord";
688 fd = fopen(accel_filename, "r");
690 //fprintf(stderr, "cannot open file\n");
691 fd = fopen("/home/user/coord", "r");
693 rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
696 fprintf(stderr, "cannot read information from file\n");
701 //fprintf(stderr, "change obj %i %i %i angle rad=%f, deg=%f\n", ax, ay, az, atan2(ax, -ay), atan2(ax, -ay)*180/M_PI);
702 angle = atan2(ay, ax);
704 if (!desktop_plugin->priv->rich_animation) return;
706 for (i=0; i<24; i++){
707 a = g_ptr_array_index(actor->child, i);
708 //x = a->x - cos(angle*M_PI/180)*a->z;
709 //y = a->y - sin(angle*M_PI/180)*a->z;
710 x = a->x - cos(angle)*a->z;
711 y = a->y - sin(angle)*a->z;
716 if (x > 800+a->width)
718 if (y > 480+a->width)
720 set_actor_rotation(a, HILDON_AA_Z_AXIS, angle*180/M_PI, 0, 0, 0);
721 set_actor_position(a, x, y, a->z, desktop_plugin);
729 change_layer(Actor * actor, AWallpaperPlugin *desktop_plugin)
731 gint y, speed1 = 8, speed2 = 16;
734 if (!desktop_plugin->priv->rich_animation) return;
736 a = g_ptr_array_index(actor->child, 0);
738 if (y > 480) y = -480;
739 set_actor_position(a, a->x, y, a->z, desktop_plugin);
742 a = g_ptr_array_index(actor->child, 1);
744 if (y > 480) y = -480;
745 set_actor_position(a, a->x, y, a->z, desktop_plugin);
748 a = g_ptr_array_index(actor->child, 2);
750 if (y > 480) y = -480;
751 set_actor_position(a, a->x, y, a->z, desktop_plugin);
754 a = g_ptr_array_index(actor->child, 3);
756 if (y > 480) y = -480;
757 set_actor_position(a, a->x, y, a->z, desktop_plugin);
762 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
765 newfile = g_strdup_printf("%s%d.png", actor->name, desktop_plugin->priv->scene->daytime);
767 g_free(actor->filename);
768 actor->filename = newfile;
769 change_hildon_actor(actor, desktop_plugin);
773 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
777 if (desktop_plugin->priv->right_corner)
778 gtk_widget_destroy(desktop_plugin->priv->right_corner);
779 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
780 THEME_PATH, desktop_plugin->priv->theme, desktop_plugin->priv->scene->daytime);
781 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
782 if (desktop_plugin->priv->right_corner){
783 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
784 gtk_widget_show (desktop_plugin->priv->right_corner);
786 change_static_actor(actor, desktop_plugin);