[nautilus/wip/razvan/compression-support: 13/13] general: add preference for automatic decompression of archives



commit 9c6dcb0215cb86373587b0ce5edd60365d341c92
Author: Razvan Chitu <razvan ch95 gmail com>
Date:   Fri Aug 19 20:07:12 2016 +0300

    general: add preference for automatic decompression of archives
    
    With the extract operation being handled internally, compressed files can be
    automatically extracted instead of being opened in file-roller. In order to
    implement this, make extraction the default action for activating selected
    archives.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768646

 data/org.gnome.nautilus.gschema.xml             |    5 ++
 src/nautilus-files-view.c                       |   65 ++++++++++++++++++-----
 src/nautilus-global-preferences.h               |    3 +
 src/nautilus-mime-actions.c                     |   18 ++++++
 src/nautilus-mime-actions.h                     |    1 +
 src/nautilus-preferences-window.c               |    5 ++
 src/resources/ui/nautilus-preferences-window.ui |   46 ++++++++++++++++
 7 files changed, 129 insertions(+), 14 deletions(-)
---
diff --git a/data/org.gnome.nautilus.gschema.xml b/data/org.gnome.nautilus.gschema.xml
index 4be43d2..4128180 100644
--- a/data/org.gnome.nautilus.gschema.xml
+++ b/data/org.gnome.nautilus.gschema.xml
@@ -103,6 +103,11 @@
       <summary>Whether to ask for confirmation when deleting files, or emptying the Trash</summary>
       <description>If set to true, then Nautilus will ask for confirmation when you attempt to delete files, 
or empty the Trash.</description>
     </key>
+    <key type="b" name="automatic-decompression">
+      <default>true</default>
+      <summary>Whether to extract compressed files instead of opening them</summary>
+      <description>If set to true, then Nautilus will automatically extract compressed files instead of 
opening them in another application</description>
+    </key>
     <key name="show-directory-item-counts" enum="org.gnome.nautilus.SpeedTradeoff">
       <aliases><alias value='local_only' target='local-only'/></aliases>
       <default>'local-only'</default>
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 3127e4a..d68871d 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -311,6 +311,12 @@ static void     nautilus_files_view_select_file                      (NautilusFi
 
 static void     update_templates_directory                     (NautilusFilesView *view);
 
+static void     extract_files                                  (NautilusFilesView *view,
+                                                                GList             *files,
+                                                                GFile             *destination_directory);
+static void     extract_files_to_chosen_location               (NautilusFilesView *view,
+                                                                GList             *files);
+
 static void     nautilus_files_view_check_empty_states         (NautilusFilesView *view);
 
 static gboolean nautilus_files_view_is_searching               (NautilusView      *view);
@@ -1121,17 +1127,33 @@ nautilus_files_view_activate_files (NautilusFilesView       *view,
                                     NautilusWindowOpenFlags  flags,
                                     gboolean                 confirm_multiple)
 {
+        GList *files_to_extract;
+        GList *files_to_activate;
         char *path;
 
+        files_to_extract = nautilus_file_list_filter (files,
+                                                      &files_to_activate,
+                                                      (NautilusFileFilterFunc)nautilus_file_is_archive,
+                                                      NULL);
+
+        if (nautilus_files_view_supports_extract_here (view)) {
+                extract_files (view, files_to_extract,
+                               nautilus_view_get_location (NAUTILUS_VIEW (view)));
+        } else {
+                extract_files_to_chosen_location (view, files_to_extract);
+        }
+
         path = get_view_directory (view);
         nautilus_mime_activate_files (nautilus_files_view_get_containing_window (view),
                                       view->details->slot,
-                                      files,
+                                      files_to_activate,
                                       path,
                                       flags,
                                       confirm_multiple);
 
         g_free (path);
+        g_list_free (files_to_extract);
+        g_list_free (files_to_activate);
 }
 
 static void
@@ -1139,16 +1161,13 @@ nautilus_files_view_activate_file (NautilusFilesView       *view,
                                    NautilusFile            *file,
                                    NautilusWindowOpenFlags  flags)
 {
-        char *path;
+        GList *files = NULL;
 
-        path = get_view_directory (view);
-        nautilus_mime_activate_file (nautilus_files_view_get_containing_window (view),
-                                     view->details->slot,
-                                     file,
-                                     path,
-                                     flags);
+        files = g_list_prepend (files, file);
 
-        g_free (path);
+        nautilus_files_view_activate_files (view, files, flags, FALSE);
+
+        g_list_free (files);
 }
 
 static void
@@ -6306,6 +6325,7 @@ real_update_actions_state (NautilusFilesView *view)
         gboolean show_detect_media;
         gboolean settings_show_delete_permanently;
         gboolean settings_show_create_link;
+        gboolean settings_automatic_decompression;
         GDriveStartStopType start_stop_type;
 
         view_action_group = view->details->view_action_group;
@@ -6348,6 +6368,8 @@ real_update_actions_state (NautilusFilesView *view)
                                                                     
NAUTILUS_PREFERENCES_SHOW_DELETE_PERMANENTLY);
          settings_show_create_link = g_settings_get_boolean (nautilus_preferences,
                                                              NAUTILUS_PREFERENCES_SHOW_CREATE_LINK);
+        settings_automatic_decompression = g_settings_get_boolean (nautilus_preferences,
+                                                                   
NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION);
 
         /* Right click actions */
         /* Selection menu actions */
@@ -6370,11 +6392,16 @@ real_update_actions_state (NautilusFilesView *view)
         action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
                                              "extract-here");
         g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
-                                     can_extract_files && can_extract_here);
+                                     can_extract_files &&
+                                     !settings_automatic_decompression &&
+                                     can_extract_here);
 
         action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
                                              "extract-to");
-        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_extract_files);
+        g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+                                     can_extract_files &&
+                                     (!settings_automatic_decompression ||
+                                      can_extract_here));
 
         action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
                                              "open-item-location");
@@ -6633,7 +6660,9 @@ update_selection_menu (NautilusFilesView *view)
         GList *selection, *l;
         NautilusFile *file;
         gint selection_count;
-        gboolean show_app, show_run;
+        gboolean show_app;
+        gboolean show_run;
+        gboolean show_extract;
         gboolean item_opens_in_view;
         gchar *item_label;
         GAppInfo *app;
@@ -6671,11 +6700,15 @@ update_selection_menu (NautilusFilesView *view)
         g_free (item_label);
 
         /* Open With <App> menu item */
-        show_app = show_run = item_opens_in_view = selection_count != 0;
+        show_extract = show_app = show_run = item_opens_in_view = selection_count != 0;
         for (l = selection; l != NULL; l = l->next) {
                 NautilusFile *file;
 
-                file = NAUTILUS_FILE (selection->data);
+                file = NAUTILUS_FILE (l->data);
+
+                if (!nautilus_mime_file_extracts (file)) {
+                        show_extract = FALSE;
+                }
 
                 if (!nautilus_mime_file_opens_in_external_app (file)) {
                         show_app = FALSE;
@@ -6715,6 +6748,10 @@ update_selection_menu (NautilusFilesView *view)
                 g_object_unref (app);
         } else if (show_run) {
                 item_label = g_strdup (_("Run"));
+        } else if (show_extract) {
+                item_label = nautilus_files_view_supports_extract_here (view) ?
+                             g_strdup (_("Extract Here")) :
+                             g_strdup (_("Extract to…"));
         } else {
                 item_label = g_strdup (_("Open"));
         }
diff --git a/src/nautilus-global-preferences.h b/src/nautilus-global-preferences.h
index ef1f8aa..bd665e3 100644
--- a/src/nautilus-global-preferences.h
+++ b/src/nautilus-global-preferences.h
@@ -32,6 +32,9 @@ G_BEGIN_DECLS
 /* Trash options */
 #define NAUTILUS_PREFERENCES_CONFIRM_TRASH                     "confirm-trash"
 
+/* Automatic decompression */
+#define NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION            "automatic-decompression"
+
 /* Display  */
 #define NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES                 "show-hidden"
 
diff --git a/src/nautilus-mime-actions.c b/src/nautilus-mime-actions.c
index e196dce..0599dca 100644
--- a/src/nautilus-mime-actions.c
+++ b/src/nautilus-mime-actions.c
@@ -54,6 +54,7 @@ typedef enum {
        ACTIVATION_ACTION_LAUNCH_IN_TERMINAL,
        ACTIVATION_ACTION_OPEN_IN_VIEW,
        ACTIVATION_ACTION_OPEN_IN_APPLICATION,
+        ACTIVATION_ACTION_EXTRACT,
        ACTIVATION_ACTION_DO_NOTHING,
 } ActivationAction;
 
@@ -677,6 +678,13 @@ get_activation_action (NautilusFile *file)
 {
        ActivationAction action;
        char *activation_uri;
+        gboolean can_extract;
+        can_extract =  g_settings_get_boolean (nautilus_preferences,
+                                               NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION);
+
+        if (can_extract && nautilus_file_is_archive (file)) {
+                return ACTIVATION_ACTION_EXTRACT;
+        }
 
        if (nautilus_file_is_nautilus_link (file)) {
                return ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE;
@@ -715,6 +723,12 @@ get_activation_action (NautilusFile *file)
 }
 
 gboolean
+nautilus_mime_file_extracts (NautilusFile *file)
+{
+        return get_activation_action (file) == ACTIVATION_ACTION_EXTRACT;
+}
+
+gboolean
 nautilus_mime_file_launches (NautilusFile *file)
 {
        ActivationAction activation_action;
@@ -1565,6 +1579,10 @@ activate_files (ActivateParameters *parameters)
                        break;
                case ACTIVATION_ACTION_DO_NOTHING :
                        break;
+                case ACTIVATION_ACTION_EXTRACT :
+                        /* Extraction of files should be handled in the view */
+                        g_assert_not_reached ();
+                        break;
                case ACTIVATION_ACTION_ASK :
                        g_assert_not_reached ();
                        break;
diff --git a/src/nautilus-mime-actions.h b/src/nautilus-mime-actions.h
index f96ca66..9347564 100644
--- a/src/nautilus-mime-actions.h
+++ b/src/nautilus-mime-actions.h
@@ -37,6 +37,7 @@ GList *                nautilus_mime_get_applications_for_file            (Nauti
 
 GAppInfo *             nautilus_mime_get_default_application_for_files    (GList                   *files);
 
+gboolean               nautilus_mime_file_extracts                        (NautilusFile            *file);
 gboolean               nautilus_mime_file_opens_in_external_app           (NautilusFile            *file);
 gboolean               nautilus_mime_file_launches                        (NautilusFile            *file);
 void                   nautilus_mime_activate_files                       (GtkWindow               
*parent_window,
diff --git a/src/nautilus-preferences-window.c b/src/nautilus-preferences-window.c
index 5fe783b..875b233 100644
--- a/src/nautilus-preferences-window.c
+++ b/src/nautilus-preferences-window.c
@@ -58,6 +58,8 @@
   "use_tree_view_checkbutton"
 #define NAUTILUS_PREFERENCES_DIALOG_TRASH_CONFIRM_WIDGET                       \
   "trash_confirm_checkbutton"
+#define NAUTILUS_PREFERENCES_DIALOG_AUTOMATIC_DECOMPRESSION_WIDGET             \
+  "automatic_decompression_checkbutton"
 
 /* int enums */
 #define NAUTILUS_PREFERENCES_DIALOG_THUMBNAIL_LIMIT_WIDGET                     \
@@ -432,6 +434,9 @@ static void nautilus_preferences_window_setup(GtkBuilder *builder,
   bind_builder_bool(builder, nautilus_preferences,
                     NAUTILUS_PREFERENCES_DIALOG_TRASH_CONFIRM_WIDGET,
                     NAUTILUS_PREFERENCES_CONFIRM_TRASH);
+  bind_builder_bool (builder, nautilus_preferences,
+                     NAUTILUS_PREFERENCES_DIALOG_AUTOMATIC_DECOMPRESSION_WIDGET,
+                     NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION);
   bind_builder_bool(builder, nautilus_list_view_preferences,
                     NAUTILUS_PREFERENCES_DIALOG_LIST_VIEW_USE_TREE_WIDGET,
                     NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
diff --git a/src/resources/ui/nautilus-preferences-window.ui b/src/resources/ui/nautilus-preferences-window.ui
index 17c32b2..90ae4d7 100644
--- a/src/resources/ui/nautilus-preferences-window.ui
+++ b/src/resources/ui/nautilus-preferences-window.ui
@@ -756,6 +756,52 @@ More information will appear when zooming closer.</property>
                 <property name="position">3</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkBox" id="vbox10">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="label17">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Compressed Files</property>
+                    <property name="xalign">0</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkCheckButton" id="automatic_decompression_checkbutton">
+                    <property name="label" translatable="yes">E_xtract compressed files instead of opening 
them</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <property name="xalign">0</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">4</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="position">1</property>


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