refactoried of code
[livewp] / applet / src / livewp-main.c
index dd43f03..ba880b9 100644 (file)
@@ -31,6 +31,9 @@
 static void set_live_bg (Display *display, Window xwindow, int mode);
 void quit_from_program (Animation_WallpaperPrivate *priv);
 void view_state_changed (Animation_WallpaperPrivate *priv);
+static gboolean short_timeout (AWallpaperPlugin *desktop_plugin);
+void run_long_timeout(AWallpaperPlugin *desktop_plugin);
+gboolean long_timeout (AWallpaperPlugin *desktop_plugin);
 
 static 
 void set_live_bg (Display *display, Window xwindow, int mode)
@@ -141,6 +144,127 @@ quit_from_program (Animation_WallpaperPrivate *priv)
      gtk_main_quit();;
 }
 /*******************************************************************************/
+static gboolean
+short_timeout (AWallpaperPlugin *desktop_plugin)
+{
+    //gint daytime = get_daytime();
+    GSList * tmp;
+    void (*pfunc)(gpointer, gpointer);
+    time_t now;
+    Actor *actor;
+    gboolean stop_flag = TRUE;
+
+    if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
+        desktop_plugin->priv->short_timer = 0;
+        return FALSE;
+    }
+
+    now = time(NULL);
+    //scene.daytime = daytime;
+    /* fprintf(stderr, "Short timer %d\n", now); */
+    tmp = desktop_plugin->priv->scene->actors;
+    while (tmp != NULL){
+           actor = tmp->data;
+           if (now >= actor->time_start_animation  
+               && actor->time_start_animation > 0
+               /* && now - actor->time_start_animation <= actor->duration_animation*/){
+                pfunc = actor->func_change;
+                if (pfunc){ 
+                    (*pfunc)(actor, desktop_plugin);
+                    stop_flag = FALSE;
+                }
+            }
+            tmp = g_slist_next(tmp);
+    }
+    if (stop_flag){
+         desktop_plugin->priv->short_timer = 0;
+         return FALSE;
+    }else
+         return TRUE; /* keep running this event */
+}
+
+void
+run_long_timeout(AWallpaperPlugin *desktop_plugin)
+{
+
+    gint daytime = get_daytime();
+    GSList * tmp;
+    void (*pfunc)(gpointer, gpointer);
+    time_t now;
+    Actor *actor;
+
+    if (!desktop_plugin->priv->scene)
+       return;
+    /*ifprintf(stderr, "!!!run long timeout short_timer=%d\n", desktop_plugin->priv->short_timer); */
+    if (desktop_plugin->priv->scene->daytime != daytime){
+        desktop_plugin->priv->scene->daytime = daytime;
+        tmp = desktop_plugin->priv->scene->actors;
+        while (tmp != NULL){
+            //change_actor(tmp->data);
+            pfunc =((Actor*)tmp->data)->func_change;
+            if (pfunc){
+                (*pfunc)(tmp->data, desktop_plugin);
+            }
+            tmp = g_slist_next(tmp);
+        }
+    }
+   
+    now = time(NULL);
+    //fprintf(stderr, "Now  %d\n", now);
+    tmp = desktop_plugin->priv->scene->actors;
+    while (tmp != NULL){
+        actor = tmp->data;
+        if (now >= actor->time_start_animation  
+            && actor->time_start_animation > 0
+            && desktop_plugin->priv->short_timer == 0){
+            /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
+            if (desktop_plugin->priv->rich_animation){
+                actor->time_start_animation = now;
+                desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
+            }
+            else {
+                (*actor->func_change)(actor, desktop_plugin);
+            }
+        }
+        tmp = g_slist_next(tmp);
+    }
+}
+
+gboolean
+long_timeout (AWallpaperPlugin *desktop_plugin)
+{
+    GstFormat fmt = GST_FORMAT_TIME;
+    gint64 p;
+
+    /*fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
+    if (desktop_plugin->priv->pipeline){
+       if (!desktop_plugin->priv->visible){
+               gst_element_query_position(desktop_plugin->priv->pipeline, &fmt, &p);
+               desktop_plugin->priv->theme_int_parametr1 = p / GST_SECOND;
+               gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_NULL);
+               gst_object_unref (GST_OBJECT (desktop_plugin->priv->pipeline));
+               desktop_plugin->priv->pipeline = NULL;
+       }
+       return TRUE;  
+    }
+
+    if (desktop_plugin->priv->long_timer == 0 )
+        return FALSE;
+    if (!desktop_plugin->priv->visible){
+        if(desktop_plugin->priv->short_timer != 0){
+            g_source_remove(desktop_plugin->priv->short_timer);
+            desktop_plugin->priv->short_timer = 0;
+        }
+        desktop_plugin->priv->long_timer = 0;
+        return FALSE;
+    }
+
+    run_long_timeout(desktop_plugin);
+    return TRUE; /* keep running this event */
+}
+
+/*******************************************************************************/
 int
 main(int argc, char *argv[])
 {