[Xfce4-commits] <squeeze:peter/libsqueeze> Pick a support app if none is given

Peter de Ridder noreply at xfce.org
Sun Feb 3 21:46:04 CET 2013


Updating branch refs/heads/peter/libsqueeze
         to 502e288247fee04515fec09b630bfc8e2fbad663 (commit)
       from cb2820bac787558ef5c81c18f1c1a7e14a2f58ab (commit)

commit 502e288247fee04515fec09b630bfc8e2fbad663
Author: Peter de Ridder <peter at xfce.org>
Date:   Sun Mar 11 18:37:10 2012 +0100

    Pick a support app if none is given

 libsqueeze/archive.c            |   54 ++++++++++++++++++++++++++++++--------
 libsqueeze/libsqueeze-support.h |   12 ++++++++
 libsqueeze/support-app.c        |   30 +++++++++++++++++++++
 libsqueeze/support-info.c       |   28 +++++++++++++++++++-
 4 files changed, 111 insertions(+), 13 deletions(-)

diff --git a/libsqueeze/archive.c b/libsqueeze/archive.c
index fb2c876..763e065 100644
--- a/libsqueeze/archive.c
+++ b/libsqueeze/archive.c
@@ -427,6 +427,29 @@ lsq_archive_get_support_mask ( const LSQArchive *archive )
 }
 */
 
+static const LSQSupportApp *
+lsq_archive_get_app_for_operation (
+        LSQArchive *archive,
+        LSQCommandType cmd
+    )
+{
+    const LSQSupportApp *app = NULL;
+    GSList *list;
+
+    g_return_val_if_fail( LSQ_IS_ARCHIVE( archive ), NULL );
+
+    /* Find the first supporting app */
+    list = lsq_support_info_get_apps_by_operation( archive->priv->s_info, cmd );
+
+    if ( NULL != list )
+    {
+        app = LSQ_SUPPORT_APP( list->data );
+        g_slist_free( list );
+    }
+
+    return app;
+}
+
 void
 lsq_archive_set_refresh_app (
         LSQArchive *archive,
@@ -442,6 +465,7 @@ lsq_archive_set_refresh_app (
          if ( NULL == app )
          {
              /* Find the first refresh supporting app */
+             app = lsq_archive_get_app_for_operation( archive, LSQ_COMMAND_TYPE_REFRESH );
          }
     }
     archive->priv->refresh_app = app;
@@ -476,32 +500,38 @@ lsq_archive_operate (
     {
         case LSQ_COMMAND_TYPE_ADD:
             g_return_val_if_fail( files, NULL );
-	    /*
-            if ( NULL != s_info->add_cmd_queue )
+            if ( NULL == app)
+            {
+                app = lsq_archive_get_app_for_operation( archive, LSQ_COMMAND_TYPE_ADD );
+            }
+            if ( NULL != app && NULL != app->add_cmd_queue )
             {
-                ctx = lsq_command_queue_execute( s_info->add_cmd_queue, archive, files, NULL, NULL, error );
+                ctx = lsq_command_queue_execute( app->add_cmd_queue, archive, files, NULL, NULL, error );
             }
-	    */
             break;
 
         case LSQ_COMMAND_TYPE_REMOVE:
             g_return_val_if_fail( files, NULL );
-	    /*
-            if ( NULL != s_info->remove_cmd_queue )
+            if ( NULL == app)
             {
-                ctx = lsq_command_queue_execute( s_info->remove_cmd_queue, archive, files, NULL, NULL, error );
+                app = lsq_archive_get_app_for_operation( archive, LSQ_COMMAND_TYPE_REMOVE );
+            }
+            if ( NULL != app && NULL != app->remove_cmd_queue )
+            {
+                ctx = lsq_command_queue_execute( app->remove_cmd_queue, archive, files, NULL, NULL, error );
             }
-	    */
             break;
 
         case LSQ_COMMAND_TYPE_EXTRACT:
             g_return_val_if_fail( directory, NULL );
-	    /*
-            if ( NULL != s_info->extract_cmd_queue )
+            if ( NULL == app)
+            {
+                app = lsq_archive_get_app_for_operation( archive, LSQ_COMMAND_TYPE_EXTRACT );
+            }
+            if ( NULL != app && NULL != app->extract_cmd_queue )
             {
-                ctx = lsq_command_queue_execute( s_info->extract_cmd_queue, archive, files, directory, NULL, error );
+                ctx = lsq_command_queue_execute( app->extract_cmd_queue, archive, files, directory, NULL, error );
             }
-	    */
             break;
 
         case LSQ_COMMAND_TYPE_REFRESH:
diff --git a/libsqueeze/libsqueeze-support.h b/libsqueeze/libsqueeze-support.h
index dedc7d4..9de8d93 100644
--- a/libsqueeze/libsqueeze-support.h
+++ b/libsqueeze/libsqueeze-support.h
@@ -89,6 +89,12 @@ lsq_support_info_get_contentype ( const LSQSupportInfo *info );
 GSList *
 lsq_support_info_get_apps ( const LSQSupportInfo *info ) G_GNUC_WARN_UNUSED_RESULT;
 
+GSList *
+lsq_support_info_get_apps_by_operation (
+        const LSQSupportInfo *info,
+        LSQCommandType cmd
+    ) G_GNUC_WARN_UNUSED_RESULT;
+
 const LSQSupportApp *
 lsq_support_info_get_app_by_id (
         const LSQSupportInfo *info,
@@ -98,6 +104,12 @@ lsq_support_info_get_app_by_id (
 const gchar *
 lsq_support_app_get_id ( const LSQSupportApp *app );
 
+gboolean
+lsq_support_app_has_operation (
+        const LSQSupportApp *app,
+        LSQCommandType cmd
+    );
+
 
 GList *
 lsq_support_info_get_all ( void ) G_GNUC_WARN_UNUSED_RESULT;
diff --git a/libsqueeze/support-app.c b/libsqueeze/support-app.c
index f29b44a..a31a56f 100644
--- a/libsqueeze/support-app.c
+++ b/libsqueeze/support-app.c
@@ -86,6 +86,36 @@ lsq_support_app_compare_id (
     return strcmp( app->id, id );
 }
 
+gboolean
+lsq_support_app_has_operation (
+        const LSQSupportApp *app,
+        LSQCommandType cmd
+    )
+{
+    g_return_val_if_fail( LSQ_IS_SUPPORT_APP( app ), FALSE );
+
+    switch ( cmd )
+    {
+        case LSQ_COMMAND_TYPE_ADD:
+            return NULL != app->add_cmd_queue;
+
+        case LSQ_COMMAND_TYPE_REMOVE:
+            return NULL != app->remove_cmd_queue;
+
+        case LSQ_COMMAND_TYPE_EXTRACT:
+            return NULL != app->extract_cmd_queue;
+
+        case LSQ_COMMAND_TYPE_REFRESH:
+            return NULL != app->refresh_cmd_queue;
+
+        default:
+	    DBG( "Unknown command type" );
+            break;
+    }
+
+    return FALSE;
+}
+
 
 GType
 lsq_support_app_get_property_type (
diff --git a/libsqueeze/support-info.c b/libsqueeze/support-info.c
index 3e3cf33..74071eb 100644
--- a/libsqueeze/support-info.c
+++ b/libsqueeze/support-info.c
@@ -114,7 +114,33 @@ lsq_support_info_get_contentype ( const LSQSupportInfo *info )
 GSList *
 lsq_support_info_get_apps ( const LSQSupportInfo *info )
 {
-    return g_slist_copy( info->apps );
+    GSList *list;
+
+    list = g_slist_copy( info->apps );
+
+    /* should this reverse? Currently it should see lsq_support_info_add_app */
+    return g_slist_reverse( list );
+}
+
+GSList *
+lsq_support_info_get_apps_by_operation (
+        const LSQSupportInfo *info,
+        LSQCommandType cmd
+    )
+{
+    GSList *list = NULL;
+    GSList *iter;
+
+    for ( iter = info->apps; iter; iter = g_slist_next( iter ) )
+    {
+        if ( TRUE == lsq_support_app_has_operation( iter->data, cmd ) )
+        {
+            /* shouldn't this append? Currently it shouldn't see lsq_support_info_add_app */
+            list = g_slist_prepend( list, iter->data );
+        }
+    }
+
+    return list;
 }
 
 static gint


More information about the Xfce4-commits mailing list