added alive dbus event
authorvlad <vlad@vlanout.(none)>
Mon, 26 Jul 2010 20:33:52 +0000 (23:33 +0300)
committervlad <vlad@vlanout.(none)>
Mon, 26 Jul 2010 20:33:52 +0000 (23:33 +0300)
applet/src/livewp-common.h
applet/src/livewp-dbus.c
applet/src/livewp-home-widget.c
applet/src/livewp-main.c

index 4a0bea8..7dfcdbf 100644 (file)
@@ -34,6 +34,7 @@
 #include <libhildondesktop/libhildondesktop.h>
 #include <libosso.h>
 #include <gconf/gconf-client.h>
+#include <time.h> 
 
 #define GETTEXT_PACKAGE "livewp"
 #include <glib/gi18n-lib.h>
@@ -92,6 +93,8 @@ struct _Animation_WallpaperPrivate
     gint view;
     pid_t  pid;
     guint view_notify;
+    guint alive_timer;
+    time_t last_alive_event;
 };
 
 struct _AWallpaperPlugin
@@ -116,6 +119,21 @@ struct _AWallpaperPluginClass
 #define LIVEWP_STOP_LIVEBG_ON_VIEW2 "stop_livebg_on_view2"
 #define LIVEWP_STOP_LIVEBG_ON_VIEW3 "stop_livebg_on_view3"
 #define LIVEWP_STOP_LIVEBG_ON_VIEW4 "stop_livebg_on_view4"
+#define LIVEWP_PAUSE_LIVEBG_ON_VIEW1 "pause_livebg_on_view1"
+#define LIVEWP_PAUSE_LIVEBG_ON_VIEW2 "pause_livebg_on_view2"
+#define LIVEWP_PAUSE_LIVEBG_ON_VIEW3 "pause_livebg_on_view3"
+#define LIVEWP_PAUSE_LIVEBG_ON_VIEW4 "pause_livebg_on_view4"
+#define LIVEWP_PLAY_LIVEBG_ON_VIEW1 "play_livebg_on_view1"
+#define LIVEWP_PLAY_LIVEBG_ON_VIEW2 "play_livebg_on_view2"
+#define LIVEWP_PLAY_LIVEBG_ON_VIEW3 "play_livebg_on_view3"
+#define LIVEWP_PLAY_LIVEBG_ON_VIEW4 "play_livebg_on_view4"
+#define LIVEWP_ALIVE_LIVEBG_ON_VIEW1 "alive_livebg_on_view1"
+#define LIVEWP_ALIVE_LIVEBG_ON_VIEW2 "alive_livebg_on_view2"
+#define LIVEWP_ALIVE_LIVEBG_ON_VIEW3 "alive_livebg_on_view3"
+#define LIVEWP_ALIVE_LIVEBG_ON_VIEW4 "alive_livebg_on_view4"
+
+
+
 
 /* For DBUS notification */
 #define NOTIFY_SIGNAL_INTERFACE "org.freedesktop.Notifications"
index 02a3cb3..9760d2c 100644 (file)
@@ -143,7 +143,7 @@ get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_Wallpaper
     START_FUNCTION;
 #endif
 
-#if 0
+//#if 0
 #if  defined APPLICATION 
     fprintf (stderr, "APPLICATION PATH11111111111111111111 %s %s %s\n",   dbus_message_get_path(msg),   dbus_message_get_interface (msg), dbus_message_get_member (msg)); 
 #endif
@@ -155,7 +155,7 @@ get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_Wallpaper
 #if !(defined CONTROLPANEL || defined APPLICATION) 
     fprintf (stderr, "APPLET PATH11111111111111111111 %s %s %s\n",   dbus_message_get_path(msg),   dbus_message_get_interface (msg), dbus_message_get_member (msg)); 
 #endif
-#endif
+//#endif
 
     if (!priv)
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -171,6 +171,7 @@ get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_Wallpaper
         }
     }
 #if  defined APPLICATION
+    /* QUIT FROM APPLICATION */
     if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW1))||
         (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW2))||   
         (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_STOP_LIVEBG_ON_VIEW3))||   
@@ -178,7 +179,36 @@ get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_Wallpaper
 
         quit_from_program(priv);
     }
-    //fprintf(stderr, "Type %i\n", dbus_message_get_type (msg));
+    /* PLAY SCENE */
+    if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW1))||
+        (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW2))||   
+        (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW3))||   
+        (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PLAY_LIVEBG_ON_VIEW4))){
+        if (priv->visible != TRUE){
+            priv->visible = TRUE;
+            view_state_changed(priv);
+        }
+    }
+    /* PAUSE SCENE */
+    if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW1))||
+        (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW2))||   
+        (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW3))||   
+        (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_PAUSE_LIVEBG_ON_VIEW4))){
+         if (priv->visible != FALSE){
+            priv->visible = FALSE;
+            view_state_changed(priv);
+         }
+    }
+    /* ALIVE APPLICATION */
+    if ((priv->view == 1 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW1))||
+        (priv->view == 2 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW2))||   
+        (priv->view == 3 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW3))||   
+        (priv->view == 4 && dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_ALIVE_LIVEBG_ON_VIEW4))){
+
+        priv->last_alive_event = time(NULL);
+    }
+
+  //fprintf(stderr, "Type %i\n", dbus_message_get_type (msg));
     if (dbus_message_is_method_call(msg, NOTIFY_SIGNAL_INTERFACE, NOTIFY_MEMBER)){
         //fprintf(stderr,"read notifications.db notify\n");    
         //read_notification(priv->desktop_plugin);
index 68077a1..7c76039 100644 (file)
@@ -435,8 +435,42 @@ desktop_plugin_visible_notify (GObject    *object,
                                           AWallpaperPlugin *desktop_plugin)
 {
     gboolean visible;
+    Animation_WallpaperPrivate *priv = desktop_plugin->priv;
     g_object_get (object, "is-on-current-desktop", &visible, NULL);
-    /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
+    fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); 
+    if (priv){
+            switch (priv->view + 1){
+               case 1: if (visible)
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW1);
+                       else
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW1);
+                       break;
+               case 2: if (visible)
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW2);
+                       else
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW2);
+                       break;
+               case 3: if (visible)
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW3);
+                       else
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW3);
+                       break;
+               case 4: if (visible)
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PLAY_LIVEBG_ON_VIEW4);
+                       else
+                               send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                         LIVEWP_SIGNAL_PATH, LIVEWP_PAUSE_LIVEBG_ON_VIEW4);
+                       break;
+            }
+     }
+
 }
 
 gboolean
@@ -445,6 +479,29 @@ rich_animation_press(GtkWidget *widget, GdkEvent *event,
     fprintf(stderr,"gggggggggggggggggggg2222\n");
     return FALSE;
 }    
+
+gboolean
+send_alive_event(Animation_WallpaperPrivate *priv) 
+{
+    fprintf(stderr, "send_alive_event\n");
+    switch (priv->view + 1){
+       case 1: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW1);
+               break;
+       case 2: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW2);
+               break;
+       case 3: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW3);
+               break;
+       case 4: send_dbus_signal (priv, LIVEWP_SIGNAL_INTERFACE, 
+                                 LIVEWP_SIGNAL_PATH, LIVEWP_ALIVE_LIVEBG_ON_VIEW4);
+               break;
+    }
+
+    return TRUE;
+}
+
 static void
 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
 {
@@ -504,8 +561,7 @@ animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
     g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
                    G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
 
-   
-    //sleep(2);
+    priv->alive_timer = g_timeout_add(60000*3, (GtkFunction)send_alive_event, priv);  /* One per 3 minute */ 
 }
 
 static void
@@ -549,6 +605,9 @@ fprintf(stderr,"lw_applet_finalize\n");
                        break;
             }
      }
+     if(priv->alive_timer > 0) 
+         g_source_remove(priv->alive_timer);
+
      livewp_deinitialize_dbus(priv);
      while (TRUE){
          wpid = wait(&status);
index e248337..1df8796 100644 (file)
@@ -71,25 +71,46 @@ void set_live_bg (Display *display, Window xwindow, int mode)
 }
 /*******************************************************************************/
 void
+view_state_changed (Animation_WallpaperPrivate *priv)
+{
+   if (priv->visible){
+       if (priv->long_timer == 0 ){
+            priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, priv->desktop_plugin);
+            run_long_timeout(priv->desktop_plugin);
+       }
+   }else{
+        if (priv->long_timer != 0 ){
+            g_source_remove(priv->long_timer);
+            priv->long_timer = 0;
+        }
+   }
+}
+/*******************************************************************************/
+gboolean
+check_alive_event(Animation_WallpaperPrivate *priv) 
+{
+    if ( time(NULL) - priv->last_alive_event > 10*60) /* If last event later 10 minute */
+        quit_from_program(priv);
+    return TRUE;
+}
+
+/*******************************************************************************/
+void
 view_changed (GConfClient *client, guint cnxn_id,
                  GConfEntry *entry, Animation_WallpaperPrivate *priv)
 {
    if (entry->value->type == GCONF_VALUE_INT) {
-       if (priv->view == gconf_value_get_int(entry->value))
-           priv->visible = TRUE;
-       else
-           priv->visible = FALSE;
-       if (priv->visible){
-           if (priv->long_timer == 0 ){
-                priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, priv->desktop_plugin);
-                run_long_timeout(priv->desktop_plugin);
-           }
-       }else{
-            if (priv->long_timer != 0 ){
-                g_source_remove(priv->long_timer);
-                priv->long_timer = 0;
+        if (priv->view == gconf_value_get_int(entry->value)){
+            if (priv->visible != TRUE){
+                priv->visible = TRUE;
+                view_state_changed(priv);
             }
-       }
+        }else{
+            if (priv->visible != FALSE){
+                priv->visible = FALSE;
+                view_state_changed(priv);
+            }
+        }
     }
 }
 /*******************************************************************************/
@@ -193,6 +214,7 @@ main(int argc, char *argv[])
         
     priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
 
+    priv->alive_timer = g_timeout_add(60000*10, (GtkFunction)check_alive_event, priv);  /* One per 10 minute */ 
     gtk_main();
     return 0;
 }