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



commit 63732b22efddea4817ffd3070081e2e93edcb000
Author: Razvan Chitu <razvan ch95 gmail com>
Date:   Mon Jul 25 09:20:39 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                       |   17 ++++++--
 src/nautilus-global-preferences.h               |    3 +
 src/nautilus-mime-actions.c                     |   38 +++++++++++++++++++
 src/nautilus-mime-actions.h                     |    1 +
 src/nautilus-preferences-window.c               |    5 ++
 src/resources/ui/nautilus-preferences-window.ui |   46 +++++++++++++++++++++++
 7 files changed, 111 insertions(+), 4 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 98bc731..14179a3 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -6462,6 +6462,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;
@@ -6506,6 +6507,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 */
@@ -6791,7 +6794,7 @@ update_selection_menu (NautilusFilesView *view)
         GList *selection, *l;
         NautilusFile *file;
         gint selection_count;
-        gboolean show_app, show_run;
+        gboolean show_extract, show_app, show_run;
         gboolean item_opens_in_view;
         gchar *item_label;
         GAppInfo *app;
@@ -6829,11 +6832,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;
@@ -6847,7 +6854,7 @@ update_selection_menu (NautilusFilesView *view)
                         item_opens_in_view = FALSE;
                 }
 
-                if (!show_app && !show_run && !item_opens_in_view) {
+                if (!show_extract && !show_app && !show_run && !item_opens_in_view) {
                         break;
                 }
         }
@@ -6873,6 +6880,8 @@ update_selection_menu (NautilusFilesView *view)
                 g_object_unref (app);
         } else if (show_run) {
                 item_label = g_strdup (_("Run"));
+        } else if (show_extract) {
+                item_label = g_strdup (_("Extract Here"));
         } 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..68d6270 100644
--- a/src/nautilus-mime-actions.c
+++ b/src/nautilus-mime-actions.c
@@ -43,6 +43,7 @@
 #include "nautilus-program-choosing.h"
 #include "nautilus-global-preferences.h"
 #include "nautilus-signaller.h"
+#include "nautilus-application.h"
 
 #define DEBUG_FLAG NAUTILUS_DEBUG_MIME
 #include "nautilus-debug.h"
@@ -54,6 +55,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 +679,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 +724,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;
@@ -1506,6 +1521,7 @@ activate_files (ActivateParameters *parameters)
        GList *open_in_app_uris;
        GList *open_in_app_parameters;
        GList *unhandled_open_in_app_uris;
+        GList *extract_files;
        ApplicationLaunchParameters *one_parameters;
        GList *open_in_view_files;
        GList *l;
@@ -1528,6 +1544,7 @@ activate_files (ActivateParameters *parameters)
        launch_in_terminal_files = NULL;
        open_in_app_uris = NULL;
        open_in_view_files = NULL;
+        extract_files = NULL;
 
        for (l = parameters->locations; l != NULL; l = l->next) {
                location = l->data;
@@ -1560,6 +1577,9 @@ activate_files (ActivateParameters *parameters)
                case ACTIVATION_ACTION_OPEN_IN_VIEW :
                        open_in_view_files = g_list_prepend (open_in_view_files, file);
                        break;
+                case ACTIVATION_ACTION_EXTRACT :
+                        extract_files = g_list_prepend (extract_files, file);
+                        break;
                case ACTIVATION_ACTION_OPEN_IN_APPLICATION :
                        open_in_app_uris = g_list_prepend (open_in_app_uris, location->uri);
                        break;
@@ -1674,6 +1694,24 @@ activate_files (ActivateParameters *parameters)
                }
        }
 
+        extract_files = g_list_reverse (extract_files);
+        if (extract_files) {
+                for (l = extract_files; l != NULL; l = l->next) {
+                        file = NAUTILUS_FILE (l->data);
+                        g_autoptr (GFile) source;
+                        g_autoptr (GFile) output;
+
+                        source = nautilus_file_get_location (file);
+                        output = nautilus_file_get_parent_location (file);
+
+                        nautilus_file_operations_extract (source,
+                                                          output,
+                                                          parameters->parent_window,
+                                                          NULL,
+                                                          NULL);
+                }
+        }
+
        open_in_app_parameters = NULL;
        unhandled_open_in_app_uris = NULL;
 
diff --git a/src/nautilus-mime-actions.h b/src/nautilus-mime-actions.h
index f96ca66..c3f9f87 100644
--- a/src/nautilus-mime-actions.h
+++ b/src/nautilus-mime-actions.h
@@ -38,6 +38,7 @@ GList *                nautilus_mime_get_applications_for_file            (Nauti
 GAppInfo *             nautilus_mime_get_default_application_for_files    (GList                   *files);
 
 gboolean               nautilus_mime_file_opens_in_external_app           (NautilusFile            *file);
+gboolean               nautilus_mime_file_extracts                        (NautilusFile            *file);
 gboolean               nautilus_mime_file_launches                        (NautilusFile            *file);
 void                   nautilus_mime_activate_files                       (GtkWindow               
*parent_window,
                                                                           NautilusWindowSlot      *slot,
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]