fixed problen with gst
[livewp] / applet / src / livewp-actor.c
index f169e0b..ad6ffcd 100644 (file)
@@ -98,7 +98,18 @@ set_actor_scale(Actor *actor, double scalex, double scaley)
     );
 
 }
-
+void
+set_actor_rotation(Actor *actor, gint axis, double degrees, gint x, gint y, gint z)
+{
+    hildon_animation_actor_set_rotation(
+            HILDON_ANIMATION_ACTOR(actor->widget),
+            axis,
+            degrees,
+            x,
+            y,
+            z
+    );
+}
 void 
 set_actor_visible(Actor *actor, gboolean visible)
 {
@@ -117,7 +128,7 @@ set_actor_position(Actor *actor, gint x, gint y, gint z, AWallpaperPlugin *deskt
 int get_notify_count(gchar *notify_type)
 {
     sqlite3 *db = NULL;
-    sqlite3 *res = NULL;
+    sqlite3_stmt *res = NULL;
     gint rc = 0, result = 0;
     gchar sql[1024];
 
@@ -179,16 +190,51 @@ gchar * read_notification()
     return message;
 }
 
+void
+change_obj(Actor *actor, AWallpaperPlugin *desktop_plugin)
+{
+    char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
+    //char * accel_filename = "/home/tanya/coord";
+
+    FILE *fd = NULL;
+    int rs, ax, ay, az, dx, dy;
+    fd = fopen(accel_filename, "r");
+    if (fd == NULL){
+        fprintf(stderr, "cannot open file\n");
+        return;
+    }
+    rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
+    fclose(fd);
+    if (rs != 3){
+        fprintf(stderr, "cannot read information from file\n");
+        return;
+    }
+
+    fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
+    dx = -ax / 100;
+    dy = -ay / 100;
+
+    actor->x = actor->x + dx;
+    actor->y = actor->y + dy;
+
+    if (actor->x > 800) actor->x = 0;
+    if (actor->x < 0) actor->x = 800;
+
+    if (actor->y > 480) actor->y = 0;
+    if (actor->y < 0) actor->y = 480;
+
+    set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
+
+
+}
+
 void 
 change_billboard(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
-    GtkWidget *label;
-    gchar *mes = NULL, *message = NULL;
-    PangoFontDescription *pfd = NULL;
     gint count = 0;
     Actor *a = NULL;
      
-    fprintf(stderr, "change_billboard\n");   
+    //fprintf(stderr, "change_billboard\n");   
     
     if (desktop_plugin->priv->scene->notification < time(NULL)){
         count = get_notify_count("general_missed");
@@ -220,22 +266,12 @@ change_billboard(Actor * actor, AWallpaperPlugin *desktop_plugin)
             set_actor_visible(a, FALSE);
         }
 
-        #if 0
-        message = read_notification();
-        label = actor->image;
-        mes = g_markup_printf_escaped("<span bgcolor=\"%s\" foreground=\"%s\">%s</span>", "#FFFFFF", "#000000", message);
-        gtk_label_set_markup(GTK_LABEL(label), mes);
-        pfd = pango_font_description_from_string("Sans 16");
-        gtk_widget_modify_font(GTK_WIDGET(label), NULL);
-        gtk_widget_modify_font(GTK_WIDGET(label), pfd);
-        pango_font_description_free(pfd);
-#endif
         desktop_plugin->priv->scene->notification = FALSE;
     }
     actor->time_start_animation = time(NULL) + 20;    
 }
 
-
+#if 0
 void 
 change_billboard1(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
@@ -253,7 +289,7 @@ change_billboard1(Actor * actor, AWallpaperPlugin *desktop_plugin)
         fprintf(stderr, "error open db %d %s\n", rc, sqlite3_errmsg(db));
     }else {
         snprintf(sql, sizeof(sql)-1, "select count(id) from Events where event_type_id=%d", 3);
-//#if 0
+
         rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
         if (rc != SQLITE_OK){
             fprintf(stderr, "error prepare %d %s\n", rc, sql);
@@ -277,7 +313,7 @@ change_billboard1(Actor * actor, AWallpaperPlugin *desktop_plugin)
         //fprintf(stderr, "count sms = %d\n", sms_count);
         sqlite3_finalize(res);
 
-//#endif
+
         sqlite3_close(db);
     }
     label = actor->image;
@@ -290,7 +326,7 @@ change_billboard1(Actor * actor, AWallpaperPlugin *desktop_plugin)
     pango_font_description_free(pfd);
     actor->time_start_animation = time(NULL) + 20;    
 }
-
+#endif
 
 void 
 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
@@ -635,6 +671,85 @@ change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
 }
 
 void
+change_tape(Actor *actor, AWallpaperPlugin *desktop_plugin)
+{
+    gint x, y, i;
+    Actor *a;
+
+    if (!desktop_plugin->priv->rich_animation) return;
+    
+    char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
+    //char * accel_filename = "/home/tanya/coord";
+
+    FILE *fd = NULL;
+    int rs, ax, ay, az;
+    fd = fopen(accel_filename, "r");
+    if (fd == NULL){
+        //fprintf(stderr, "cannot open file\n");
+        fd = fopen("/home/user/coord", "r"); 
+    }
+    rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
+    fclose(fd);
+    if (rs != 3){
+        fprintf(stderr, "cannot read information from file\n");
+        return;
+
+    }
+
+    //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);
+    int ang = (int)floor(atan2(ay, ax)*180/M_PI);
+    if (ang < 0) ang = 360+ang;
+
+    if (!desktop_plugin->priv->rich_animation) return;
+
+    for (i=0; i<16; i++){
+        a = g_ptr_array_index(actor->child, i);
+        if (a->scale == 100) a->scale = ang;
+        if (abs(a->scale - ang) > 10){
+            if (a->scale > ang){
+                if ((a->scale - ang) < (ang + (360-a->scale))) a->scale--;
+                else a->scale++;
+            }
+            if (a->scale < ang) {
+                if (ang - a->scale < (a->scale+(360-ang))) a->scale++;
+                else a->scale--;
+            }
+            if (a->scale > 360) a->scale = 0;
+            if (a->scale < 0) a->scale = 360;
+        }
+    
+        x = a->x - (float)cos(a->scale*M_PI/180)*a->z;
+        y = a->y - (float)sin(a->scale*M_PI/180)*a->z;
+        //x = round(a->x - (float)cos(a->scale*M_PI/180)*a->z);
+        //y = round(a->y - (float)sin(a->scale*M_PI/180)*a->z);
+        //x = a->x - cos(angle)*a->z;
+        //y = a->y - sin(angle)*a->z;
+        if ((a->scale > 270 || a->scale < 90) && x < -a->width*cos(a->scale*M_PI/180)){ 
+            x = 800; 
+            y = fast_rnd(480);
+        } 
+        if ((a->scale > 90 && a->scale < 270) && x > 800 - a->width*cos(a->scale*M_PI/180)){
+            x = 0;
+            y = fast_rnd(480);
+        }
+        if (a->scale > 0 && a->scale < 180 && y < -a->width*sin(a->scale*M_PI/180)){
+            y = 480;
+            x = fast_rnd(800);
+        }
+        if (a->scale < 360 && a->scale > 180 && y > 480 - a->width*sin(a->scale*M_PI/180)){
+            y = 0;
+            x = fast_rnd(800);
+        }
+        //if (i ==0) fprintf(stderr, "x=%d y=%d ang=%d speed=%d\n", x, y, a->scale, a->z);
+        set_actor_rotation(a, HILDON_AA_Z_AXIS, a->scale, 0, 0, 0);
+        set_actor_position(a, x, y, a->z, desktop_plugin);
+        a->x = x;
+        a->y = y;
+    }
+    
+}
+
+void
 change_layer(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
     gint y, speed1 = 8, speed2 = 16;