[nautilus] file-operations: open unsupported archives in another application



commit 1686ce84fb398a36c3df659afe37be7545f42e3e
Author: Razvan Chitu <razvan ch95 gmail com>
Date:   Tue Aug 30 18:37:39 2016 +0300

    file-operations: open unsupported archives in another application
    
    The library used for managing compressed files does not yet support all use
    cases such as encrypted archives. In order to fix this, attempt to open
    unsupported archives in other applications.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=770605

 src/nautilus-file-operations.c       |    8 ++++
 src/nautilus-operations-ui-manager.c |   70 ++++++++++++++++++++++++++++++++++
 src/nautilus-operations-ui-manager.h |    3 +
 3 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index 48847a5..0dd84b4 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -8263,6 +8263,14 @@ extract_job_on_error (AutoarExtractor *extractor,
 
     source_file = autoar_extractor_get_source_file (extractor);
 
+    if (IS_IO_ERROR (error, NOT_SUPPORTED))
+    {
+        handle_unsupported_compressed_file (extract_job->common.parent_window,
+                                            source_file);
+
+        return;
+    }
+
     nautilus_progress_info_take_status (extract_job->common.progress,
                                         f (_("Error extracting “%B”"),
                                            source_file));
diff --git a/src/nautilus-operations-ui-manager.c b/src/nautilus-operations-ui-manager.c
index dfbb13b..cb1ae0d 100644
--- a/src/nautilus-operations-ui-manager.c
+++ b/src/nautilus-operations-ui-manager.c
@@ -5,6 +5,8 @@
 #include "nautilus-file.h"
 #include "nautilus-file-operations.h"
 #include "nautilus-file-conflict-dialog.h"
+#include "nautilus-mime-actions.h"
+#include "nautilus-program-choosing.h"
 
 typedef struct
 {
@@ -487,3 +489,71 @@ copy_move_conflict_ask_user_action (GtkWindow *parent_window,
 
     return data->response;
 }
+
+typedef struct {
+    GtkWindow *parent_window;
+    NautilusFile *file;
+} HandleUnsupportedFileData;
+
+static gboolean
+open_file_in_application (gpointer user_data)
+{
+    HandleUnsupportedFileData *data;
+    g_autoptr (GAppInfo) application  = NULL;
+
+    data = user_data;
+
+    application = nautilus_mime_get_default_application_for_file (data->file);
+
+    if (!application)
+    {
+        GtkWidget *dialog;
+        g_autofree gchar *mime_type = NULL;
+
+        mime_type = nautilus_file_get_mime_type (data->file);
+
+        dialog = gtk_app_chooser_dialog_new_for_content_type (data->parent_window,
+                                                              GTK_DIALOG_MODAL |
+                                                              GTK_DIALOG_DESTROY_WITH_PARENT |
+                                                              GTK_DIALOG_USE_HEADER_BAR,
+                                                              mime_type);
+        if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+        {
+            application = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (dialog));
+        }
+
+        gtk_widget_destroy (dialog);
+    }
+
+    if (application)
+    {
+        g_autoptr (GList) files = NULL;
+
+        files = g_list_append (NULL, data->file);
+
+        nautilus_launch_application (application, files, data->parent_window);
+    }
+
+    return G_SOURCE_REMOVE;
+}
+
+/* This is used to open compressed files that are not supported by gnome-autoar
+ * in another application
+ */
+void
+handle_unsupported_compressed_file (GtkWindow *parent_window,
+                                    GFile     *compressed_file)
+{
+    HandleUnsupportedFileData *data;
+
+    data = g_slice_new0 (HandleUnsupportedFileData);
+    data->parent_window = parent_window;
+    data->file = nautilus_file_get (compressed_file);
+
+    invoke_main_context_sync (NULL, open_file_in_application, data);
+
+    nautilus_file_unref (data->file);
+    g_slice_free (HandleUnsupportedFileData, data);
+
+    return;
+}
diff --git a/src/nautilus-operations-ui-manager.h b/src/nautilus-operations-ui-manager.h
index 8c9102c..edfcbe7 100644
--- a/src/nautilus-operations-ui-manager.h
+++ b/src/nautilus-operations-ui-manager.h
@@ -24,4 +24,7 @@ enum
     CONFLICT_RESPONSE_RENAME = 3,
 };
 
+void handle_unsupported_compressed_file (GtkWindow *parent_window,
+                                         GFile     *compressed_file);
+
 #endif /* NAUTILUS_OPERATIONS_UI_MANAGER */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]