general: Add mime type support for archives

Until now archives were managed only if activated from Nautilus itself
and if a setting was set.

There are two main problems with this.
1- Archives opened in other apps cannot be handled by Nautilus
2- Users cannot use the regular mime type handling for setting Nautilus
as the app handling archives, or unsetting it.

This patch add support for archives mime types handled by gnome-autoar
and removes the UI and setting used in the previous version.

https://bugzilla.gnome.org/show_bug.cgi?id=771424
This commit is contained in:
Carlos Soriano 2017-08-09 16:32:09 +02:00
parent 3a353db6f8
commit 1bdc404245
10 changed files with 70 additions and 113 deletions

View file

@ -11,7 +11,7 @@ Type=Application
DBusActivatable=true
StartupNotify=true
Categories=GNOME;GTK;Utility;Core;FileManager;
MimeType=inode/directory;
MimeType=inode/directory; application/x-7z-compressed; application/x-7z-compressed-tar; application/x-bzip; application/x-bzip-compressed-tar; application/x-compress; application/x-compressed-tar; application/x-cpio; application/x-gzip; application/x-lha; application/x-lzip; application/x-lzip-compressed-tar; application/x-lzma; application/x-lzma-compressed-tar; application/x-tar; application/x-tarz; application/x-xar; application/x-xz; application/x-xz-compressed-tar; application/zip; application/gzip; application/bzip2;
X-GNOME-UsesNotifications=true
Actions=new-window;

View file

@ -111,11 +111,6 @@
<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 in another application</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>

View file

@ -26,6 +26,8 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
#define NAUTILUS_DESKTOP_ID "org.gnome.Nautilus.desktop"
/* These functions all return something something that needs to be
* freed with g_free, is not NULL, and is guaranteed to exist.
*/

View file

@ -1237,53 +1237,15 @@ nautilus_files_view_activate_files (NautilusFilesView *view,
g_list_free (files_to_activate);
}
static void
void
nautilus_files_view_activate_file (NautilusFilesView *view,
NautilusFile *file,
NautilusWindowOpenFlags flags)
{
NautilusFilesViewPrivate *priv;
char *path;
g_autoptr (GList) files = NULL;
priv = nautilus_files_view_get_instance_private (view);
if (nautilus_mime_file_extracts (file))
{
GList *files = NULL;
files = g_list_prepend (files, file);
if (nautilus_files_view_supports_extract_here (view))
{
g_autoptr (GFile) location = NULL;
g_autoptr (GFile) parent = NULL;
location = nautilus_file_get_location (file);
/* Get a parent from a random file. We assume all files has a common parent.
* But don't assume the parent is the view location, since that's not the
* case in list view when expand-folder setting is set
*/
parent = g_file_get_parent (location);
extract_files (view, files, parent);
}
else
{
extract_files_to_chosen_location (view, files);
}
g_list_free (files);
return;
}
path = get_view_directory (view);
nautilus_mime_activate_file (nautilus_files_view_get_containing_window (view),
priv->slot,
file,
path,
flags);
g_free (path);
files = g_list_append (files, file);
nautilus_files_view_activate_files (view, files, flags, FALSE);
}
static void
@ -7344,6 +7306,23 @@ can_extract_all (GList *files)
return TRUE;
}
static gboolean
nautilus_handles_all_files_to_extract (GList *files)
{
NautilusFile *file;
GList *l;
for (l = files; l != NULL; l = l->next)
{
file = l->data;
if (!nautilus_mime_file_extracts (file))
{
return FALSE;
}
}
return TRUE;
}
GActionGroup *
nautilus_files_view_get_action_group (NautilusFilesView *view)
{
@ -7377,6 +7356,7 @@ real_update_actions_state (NautilusFilesView *view)
gboolean can_copy_files;
gboolean can_paste_files_into;
gboolean can_extract_files;
gboolean handles_all_files_to_extract;
gboolean can_extract_here;
gboolean item_opens_in_view;
gboolean is_read_only;
@ -7390,7 +7370,6 @@ 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;
priv = nautilus_files_view_get_instance_private (view);
@ -7430,13 +7409,11 @@ real_update_actions_state (NautilusFilesView *view)
can_extract_files = selection_count != 0 &&
can_extract_all (selection);
can_extract_here = nautilus_files_view_supports_extract_here (view);
handles_all_files_to_extract = nautilus_handles_all_files_to_extract (selection);
settings_show_delete_permanently = g_settings_get_boolean (nautilus_preferences,
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 */
action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
@ -7470,14 +7447,14 @@ real_update_actions_state (NautilusFilesView *view)
"extract-here");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
can_extract_files &&
!settings_automatic_decompression &&
!handles_all_files_to_extract &&
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 &&
(!settings_automatic_decompression ||
(!handles_all_files_to_extract ||
can_extract_here));
action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),

View file

@ -267,6 +267,9 @@ void nautilus_files_view_activate_files (Nautil
GList *files,
NautilusWindowOpenFlags flags,
gboolean confirm_multiple);
void nautilus_files_view_activate_file (NautilusFilesView *view,
NautilusFile *file,
NautilusWindowOpenFlags flags);
void nautilus_files_view_preview_files (NautilusFilesView *view,
GList *files,
GArray *locations);

View file

@ -32,9 +32,6 @@ 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"

View file

@ -37,6 +37,7 @@
#include "nautilus-file-attributes.h"
#include "nautilus-file.h"
#include "nautilus-file-utilities.h"
#include "nautilus-file-operations.h"
#include "nautilus-metadata.h"
#include "nautilus-program-choosing.h"
@ -709,11 +710,14 @@ 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);
gboolean handles_extract;
g_autoptr (GAppInfo) app_info = NULL;
const gchar* app_id;
if (can_extract && nautilus_file_is_archive (file))
app_info = nautilus_mime_get_default_application_for_file (file);
app_id = g_app_info_get_id (app_info);
handles_extract = g_strcmp0 (app_id, NAUTILUS_DESKTOP_ID) == 0;
if (handles_extract && nautilus_file_is_archive (file))
{
return ACTIVATION_ACTION_EXTRACT;
}

View file

@ -57,8 +57,6 @@
"use_tree_view_checkbutton"
#define NAUTILUS_PREFERENCES_DIALOG_TRASH_CONFIRM_WIDGET \
"trash_confirm_checkbutton"
#define NAUTILUS_PREFERENCES_DIALOG_AUTOMATIC_DECOMPRESSION_WIDGET \
"automatic_decompression_checkbutton"
#define NAUTILUS_PREFERENCES_DIALOG_USE_NEW_VIEWS_WIDGET \
"use_new_views_checkbutton"
#define NAUTILUS_PREFERENCES_FTS_DEFAULT_WIDGET \
@ -493,9 +491,6 @@ 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);

View file

@ -118,6 +118,7 @@ typedef struct
guint location_change_distance;
char *pending_scroll_to;
GList *pending_selection;
NautilusFile *pending_file_to_activate;
NautilusFile *determine_view_file;
GCancellable *mount_cancellable;
GError *mount_error;
@ -985,6 +986,7 @@ static gboolean setup_view (NautilusWindowSlot *self,
static void load_new_location (NautilusWindowSlot *slot,
GFile *location,
GList *selection,
NautilusFile *file_to_activate,
gboolean tell_current_content_view,
gboolean tell_new_content_view);
@ -1580,10 +1582,18 @@ handle_regular_file_if_needed (NautilusWindowSlot *self,
}
g_clear_object (&priv->pending_location);
g_clear_object (&priv->pending_file_to_activate);
g_free (priv->pending_scroll_to);
priv->pending_location = nautilus_file_get_parent_location (file);
priv->pending_selection = g_list_prepend (NULL, nautilus_file_ref (file));
if (nautilus_file_is_archive (file))
{
priv->pending_file_to_activate = nautilus_file_ref (file);
}
else
{
priv->pending_selection = g_list_prepend (NULL, nautilus_file_ref (file));
}
priv->determine_view_file = nautilus_file_ref (parent_file);
priv->pending_scroll_to = nautilus_file_get_uri (file);
@ -1777,6 +1787,7 @@ setup_view (NautilusWindowSlot *self,
load_new_location (self,
priv->pending_location,
priv->pending_selection,
priv->pending_file_to_activate,
FALSE,
TRUE);
@ -1792,6 +1803,7 @@ setup_view (NautilusWindowSlot *self,
load_new_location (self,
old_location,
selection,
NULL,
FALSE,
TRUE);
nautilus_file_list_free (selection);
@ -1815,6 +1827,7 @@ static void
load_new_location (NautilusWindowSlot *self,
GFile *location,
GList *selection,
NautilusFile *file_to_activate,
gboolean tell_current_content_view,
gboolean tell_new_content_view)
{
@ -1845,6 +1858,20 @@ load_new_location (NautilusWindowSlot *self,
if (view)
{
nautilus_view_set_selection (view, selection);
if (file_to_activate != NULL)
{
g_autoptr (GAppInfo) app_info = NULL;
const gchar *app_id;
g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
app_info = nautilus_mime_get_default_application_for_file (file_to_activate);
app_id = g_app_info_get_id (app_info);
if (g_strcmp0 (app_id, NAUTILUS_DESKTOP_ID) == 0)
{
nautilus_files_view_activate_file (NAUTILUS_FILES_VIEW (view),
file_to_activate, 0);
}
}
}
nautilus_profile_end (NULL);
@ -1882,6 +1909,7 @@ free_location_change (NautilusWindowSlot *self)
priv = nautilus_window_slot_get_instance_private (self);
g_clear_object (&priv->pending_location);
g_clear_object (&priv->pending_file_to_activate);
nautilus_file_list_free (priv->pending_selection);
priv->pending_selection = NULL;
@ -2769,6 +2797,7 @@ nautilus_window_slot_dispose (GObject *object)
nautilus_window_slot_set_viewed_file (self, NULL);
g_clear_object (&priv->location);
g_clear_object (&priv->pending_file_to_activate);
nautilus_file_list_free (priv->pending_selection);
priv->pending_selection = NULL;
@ -3066,6 +3095,7 @@ nautilus_window_slot_stop_loading (NautilusWindowSlot *self)
load_new_location (self,
location,
selection,
NULL,
TRUE,
FALSE);
nautilus_file_list_free (selection);

View file

@ -804,52 +804,6 @@
<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 the files on open</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>