cleanups, notification timeout fix
[nowplayingd] / nowplaying.c
index 8dfbe8d..ff0f811 100644 (file)
@@ -28,13 +28,6 @@ static void sig_handler( int sig G_GNUC_UNUSED )
        }
 }
 
-static gboolean close_notification( gpointer n )
-{
-       notify_notification_close( NOTIFY_NOTIFICATION( n ), NULL );
-
-       return FALSE;
-}
-
 static void metadata_callback(
        const MafwRenderer *self G_GNUC_UNUSED,
        const gchar *object_id G_GNUC_UNUSED,
@@ -66,9 +59,9 @@ static void metadata_callback(
                "open_mp_now_playing",
                G_TYPE_NONE, NULL,
                -1 );
-               
+
+       notify_notification_set_timeout( NOTIFY_NOTIFICATION( n ), 4500 /* 4.5s */ );
        notify_notification_show( NOTIFY_NOTIFICATION( n ), NULL );
-       g_timeout_add_seconds( 5, close_notification, n );
 }
 
 static void state_changed_cb(
@@ -89,6 +82,20 @@ static void state_changed_cb(
   }
 }
 
+static void renderer_removed_cb(
+       const MafwRegistry *registry2 G_GNUC_UNUSED,
+       GObject *renderer,
+       gconstpointer user_data G_GNUC_UNUSED)
+{
+       if ( MAFW_IS_RENDERER( renderer ) ) {
+               const gchar *name = mafw_extension_get_name( MAFW_EXTENSION( renderer ) );
+
+               if ( !strcmp( name, WANTED_RENDERER ) ) {
+                       g_signal_handlers_disconnect_by_func( renderer, G_CALLBACK( state_changed_cb ), NULL );
+               }
+       }
+}
+
 static void renderer_added_cb(
        const MafwRegistry *registry2 G_GNUC_UNUSED,
        GObject *renderer,
@@ -103,6 +110,18 @@ static void renderer_added_cb(
        }
 }
 
+static void mafw_deinit( void )
+{
+    GList *renderers = NULL;
+
+       g_signal_handlers_disconnect_by_func( registry, G_CALLBACK( renderer_removed_cb ), NULL );
+       renderers = mafw_registry_get_renderers( registry );
+       while ( renderers ) {
+               renderer_removed_cb( registry, G_OBJECT( renderers->data ), NULL );
+               renderers = g_list_next( renderers );
+       }
+}
+
 static void mafw_init( void )
 {
     GList *renderers = NULL;
@@ -140,8 +159,12 @@ int main (void)
 
        g_main_loop_unref( loop );
 
+       mafw_deinit();
+
        mafw_shared_deinit();
 
+       notify_uninit();
+
        return EXIT_SUCCESS;
 }