Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 77 additions & 5 deletions nemo-seahorse/nemo-ext/nemo-seahorse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Comment on lines +163 to +173
Copy link
Member

@mtwebster mtwebster Oct 30, 2025

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.


return result;
}

static gboolean
is_all_encrypted_files (GList *files)
{
while (files) {
if (!is_encrypted_file ((NemoFileInfo*)(files->data)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could just call is_mime_types() here instead, and get rid of is_encrypted_file()

return FALSE;
files = g_list_next (files);
}

return TRUE;
}

static GList*
seahorse_nemo_get_file_items (NemoMenuProvider *provider,
GtkWidget *window, GList *files)
Expand All @@ -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),
Expand Down