-
Notifications
You must be signed in to change notification settings - Fork 165
Fix decrypt context menu not appearing for .gpg files in Nemo #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
the78mole
wants to merge
1
commit into
linuxmint:master
Choose a base branch
from
the78mole:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,34 @@ sign_callback (NemoMenuItem *item, gpointer user_data) | |
| g_string_free (cmd, TRUE); | ||
| } | ||
|
|
||
| static void | ||
| decrypt_callback (NemoMenuItem *item, gpointer user_data) | ||
| { | ||
| GList *files, *scan; | ||
| char *uri, *t; | ||
| GString *cmd; | ||
|
|
||
| files = g_object_get_data (G_OBJECT (item), "files"); | ||
| g_assert (files != NULL); | ||
|
|
||
| cmd = g_string_new ("nemo-seahorse-tool"); | ||
| g_string_append_printf (cmd, " --decrypt"); | ||
|
|
||
| for (scan = files; scan; scan = scan->next) { | ||
| uri = nemo_file_info_get_uri ((NemoFileInfo*)scan->data); | ||
| t = g_shell_quote (uri); | ||
| g_free (uri); | ||
|
|
||
| g_string_append_printf (cmd, " %s", t); | ||
| g_free (t); | ||
| } | ||
|
|
||
| g_print ("EXEC: %s\n", cmd->str); | ||
| g_spawn_command_line_async (cmd->str, NULL); | ||
|
|
||
| g_string_free (cmd, TRUE); | ||
| } | ||
|
|
||
| static char *pgp_encrypted_types[] = { | ||
| "application/pgp", | ||
| "application/pgp-encrypted", | ||
|
|
@@ -122,6 +150,43 @@ is_all_mime_types (GList *files, char* types[]) | |
| return TRUE; | ||
| } | ||
|
|
||
| static gboolean | ||
| is_encrypted_file (NemoFileInfo *file) | ||
| { | ||
| char *name; | ||
| gboolean result = FALSE; | ||
|
|
||
| /* Check MIME type first */ | ||
| if (is_mime_types (file, pgp_encrypted_types)) | ||
| return TRUE; | ||
|
|
||
| /* Check file extension for .gpg and .asc files */ | ||
| name = nemo_file_info_get_name (file); | ||
| if (name != NULL) { | ||
| int len = strlen (name); | ||
| if ((len > 4 && g_ascii_strcasecmp (name + len - 4, ".gpg") == 0) || | ||
| (len > 4 && g_ascii_strcasecmp (name + len - 4, ".asc") == 0) || | ||
| (len > 4 && g_ascii_strcasecmp (name + len - 4, ".sig") == 0)) { | ||
| result = TRUE; | ||
| } | ||
| } | ||
| g_free (name); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| static gboolean | ||
| is_all_encrypted_files (GList *files) | ||
| { | ||
| while (files) { | ||
| if (!is_encrypted_file ((NemoFileInfo*)(files->data))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could just call |
||
| return FALSE; | ||
| files = g_list_next (files); | ||
| } | ||
|
|
||
| return TRUE; | ||
| } | ||
|
|
||
| static GList* | ||
| seahorse_nemo_get_file_items (NemoMenuProvider *provider, | ||
| GtkWidget *window, GList *files) | ||
|
|
@@ -147,15 +212,22 @@ seahorse_nemo_get_file_items (NemoMenuProvider *provider, | |
| return NULL; | ||
| } | ||
|
|
||
| /* A single encrypted file, no menu items */ | ||
| if (num == 1 && | ||
| is_mime_types ((NemoFileInfo*)files->data, pgp_encrypted_types)) | ||
| return NULL; | ||
|
|
||
| /* All 'no display' types, no menu items */ | ||
| if (is_all_mime_types (files, no_display_types)) | ||
| return NULL; | ||
|
|
||
| /* Encrypted files get decrypt menu */ | ||
| if (is_all_encrypted_files (files)) { | ||
| item = nemo_menu_item_new ("NemoSh::decrypt", _("Decrypt..."), | ||
| ngettext ("Decrypt the selected file", "Decrypt the selected files", num), NULL); | ||
| g_object_set_data_full (G_OBJECT (item), "files", nemo_file_info_list_copy (files), | ||
| (GDestroyNotify) nemo_file_info_list_free); | ||
| g_signal_connect (item, "activate", G_CALLBACK (decrypt_callback), provider); | ||
| items = g_list_append (items, item); | ||
| return items; | ||
| } | ||
|
|
||
| /* Regular files get encrypt and sign menu */ | ||
| item = nemo_menu_item_new ("NemoSh::crypt", _("Encrypt..."), | ||
| ngettext ("Encrypt (and optionally sign) the selected file", "Encrypt the selected files", num), NULL); | ||
| g_object_set_data_full (G_OBJECT (item), "files", nemo_file_info_list_copy (files), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is useful - those extensions are used by many files that are not encrypted also, and the function that
nemo_file_info_is_mime_type()eventually resolves to -g_content_type_is_a()- already does this sort of thing for us. We should just trust it.