From 5486a2614516daec62327431c511099728d14b2b Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Sun, 18 Aug 2013 00:02:35 +0800 Subject: Add properties and widgets to support archive extraction --- e-util/e-attachment-store.c | 74 +++++++++++++++++++++++++++++++++++++-- e-util/e-attachment-view.c | 1 + e-util/e-attachment.c | 85 +++++++++++++++++++++++++++++++++++++++++++++ e-util/e-attachment.h | 6 ++++ 4 files changed, 164 insertions(+), 2 deletions(-) diff --git a/e-util/e-attachment-store.c b/e-util/e-attachment-store.c index 08d7dc49e8..0f0ddf2138 100644 --- a/e-util/e-attachment-store.c +++ b/e-util/e-attachment-store.c @@ -28,6 +28,7 @@ #include #include +#include #include "e-mktemp.h" @@ -522,6 +523,20 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store, GtkFileChooser *file_chooser; GtkFileChooserAction action; GtkWidget *dialog; + + GtkBox *extra_box; + GtkWidget *extra_box_widget; + + GtkBox *extract_box; + GtkWidget *extract_box_widget; + + GSList *extract_group; + GtkWidget *extract_only, *extract_org; + GtkToggleButton *extract_only_toggle; + + GtkWidget *extract_yes; + GtkToggleButton *extract_yes_toggle; + GFile *destination; const gchar *title; gint response; @@ -552,10 +567,42 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store, gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); gtk_window_set_icon_name (GTK_WINDOW (dialog), "mail-attachment"); + extra_box_widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + extra_box = GTK_BOX (extra_box_widget); + + extract_yes = gtk_check_button_new_with_mnemonic ( + _("E_xtract files from the attachment if it is an archive")); + extract_yes_toggle = GTK_TOGGLE_BUTTON (extract_yes); + gtk_box_pack_start (extra_box, extract_yes, FALSE, FALSE, 0); + + extract_box_widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + extract_box = GTK_BOX (extract_box_widget); + gtk_box_pack_start (extra_box, extract_box_widget, FALSE, FALSE, 5); + + extract_only = gtk_radio_button_new_with_mnemonic (NULL, + _("Save extracted files only")); + extract_only_toggle = GTK_TOGGLE_BUTTON (extract_only); + extract_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (extract_only)); + gtk_box_pack_start (extract_box, extract_only, FALSE, FALSE, 0); + + extract_org = gtk_radio_button_new_with_mnemonic (extract_group, + _("Save extracted files and the original archive")); + gtk_box_pack_start (extract_box, extract_org, FALSE, FALSE, 0); + + g_object_bind_property (extract_yes, "active", extract_box, "visible", 0); + gtk_toggle_button_set_active (extract_yes_toggle, TRUE); + gtk_toggle_button_set_active (extract_only_toggle, TRUE); + + gtk_widget_show_all (extra_box_widget); + gtk_file_chooser_set_extra_widget (file_chooser, extra_box_widget); + if (action == GTK_FILE_CHOOSER_ACTION_SAVE) { EAttachment *attachment; + AutoarPref *arpref; + GSettings *settings; GFileInfo *file_info; const gchar *name = NULL; + gchar *mime_type; attachment = attachment_list->data; file_info = e_attachment_ref_file_info (attachment); @@ -569,15 +616,38 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store, gtk_file_chooser_set_current_name (file_chooser, name); + mime_type = e_attachment_dup_mime_type (attachment); + settings = g_settings_new (AUTOAR_PREF_DEFAULT_GSCHEMA_ID); + arpref = autoar_pref_new_with_gsettings (settings); + if (!autoar_pref_check_file_name (arpref, name) && + !autoar_pref_check_mime_type_d (arpref, mime_type)) { + gtk_toggle_button_set_active (extract_yes_toggle, FALSE); + } + g_clear_object (&file_info); + g_clear_object (&settings); + g_clear_object (&arpref); + g_free (mime_type); } response = gtk_dialog_run (GTK_DIALOG (dialog)); - if (response == GTK_RESPONSE_OK) + if (response == GTK_RESPONSE_OK) { + GList *iter; + gboolean save_self, save_extracted; + destination = gtk_file_chooser_get_file (file_chooser); - else + save_self = !gtk_toggle_button_get_active (extract_yes_toggle) || + !gtk_toggle_button_get_active (extract_only_toggle); + save_extracted = gtk_toggle_button_get_active (extract_yes_toggle); + + for (iter = attachment_list; iter != NULL; iter = iter->next) { + e_attachment_set_save_self (iter->data, save_self); + e_attachment_set_save_extracted (iter->data, save_extracted); + } + } else { destination = NULL; + } gtk_widget_destroy (dialog); diff --git a/e-util/e-attachment-view.c b/e-util/e-attachment-view.c index 2d6e090dd1..6e7c4849b2 100644 --- a/e-util/e-attachment-view.c +++ b/e-util/e-attachment-view.c @@ -257,6 +257,7 @@ action_save_all_cb (GtkAction *action, GList *list, *iter; GFile *destination; gpointer parent; + gboolean save_attachments, save_extracted_files; store = e_attachment_view_get_store (view); diff --git a/e-util/e-attachment.c b/e-util/e-attachment.c index bfde09d900..b34cc0aa4a 100644 --- a/e-util/e-attachment.c +++ b/e-util/e-attachment.c @@ -74,6 +74,9 @@ struct _EAttachmentPrivate { guint saving : 1; guint shown : 1; + guint save_self : 1; + guint save_extracted : 1; + camel_cipher_validity_encrypt_t encrypted; camel_cipher_validity_sign_t signed_; @@ -103,6 +106,8 @@ enum { PROP_MIME_PART, PROP_PERCENT, PROP_REFERENCE, + PROP_SAVE_SELF, + PROP_SAVE_EXTRACTED, PROP_SAVING, PROP_SHOWN, PROP_SIGNED @@ -672,6 +677,18 @@ attachment_set_property (GObject *object, E_ATTACHMENT (object), g_value_get_int (value)); return; + + case PROP_SAVE_SELF: + e_attachment_set_save_self ( + E_ATTACHMENT (object), + g_value_get_boolean (value)); + return; + + case PROP_SAVE_EXTRACTED: + e_attachment_set_save_extracted ( + E_ATTACHMENT (object), + g_value_get_boolean (value)); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -761,6 +778,20 @@ attachment_get_property (GObject *object, E_ATTACHMENT (object))); return; + case PROP_SAVE_SELF: + g_value_set_boolean ( + value, + e_attachment_get_save_self ( + E_ATTACHMENT (object))); + return; + + case PROP_SAVE_EXTRACTED: + g_value_set_boolean ( + value, + e_attachment_get_save_extracted ( + E_ATTACHMENT (object))); + return; + case PROP_SAVING: g_value_set_boolean ( value, @@ -952,6 +983,26 @@ e_attachment_class_init (EAttachmentClass *class) GTK_TYPE_TREE_ROW_REFERENCE, G_PARAM_READWRITE)); + g_object_class_install_property ( + object_class, + PROP_SAVE_SELF, + g_param_spec_boolean ( + "save-self", + "Save self", + NULL, + TRUE, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_SAVE_EXTRACTED, + g_param_spec_boolean ( + "save-extracted", + "Save extracted", + NULL, + FALSE, + G_PARAM_READWRITE)); + g_object_class_install_property ( object_class, PROP_SAVING, @@ -1527,6 +1578,40 @@ e_attachment_set_shown (EAttachment *attachment, g_object_notify (G_OBJECT (attachment), "shown"); } +gboolean +e_attachment_get_save_self (EAttachment *attachment) +{ + g_return_val_if_fail (E_IS_ATTACHMENT (attachment), TRUE); + + return attachment->priv->save_self; +} + +void +e_attachment_set_save_self (EAttachment *attachment, + gboolean save_self) +{ + g_return_if_fail (E_IS_ATTACHMENT (attachment)); + + attachment->priv->save_self = save_self; +} + +gboolean +e_attachment_get_save_extracted (EAttachment *attachment) +{ + g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE); + + return attachment->priv->save_extracted; +} + +void +e_attachment_set_save_extracted (EAttachment *attachment, + gboolean save_extracted) +{ + g_return_if_fail (E_IS_ATTACHMENT (attachment)); + + attachment->priv->save_extracted = save_extracted; +} + camel_cipher_validity_encrypt_t e_attachment_get_encrypted (EAttachment *attachment) { diff --git a/e-util/e-attachment.h b/e-util/e-attachment.h index b21a0f2899..2942d042de 100644 --- a/e-util/e-attachment.h +++ b/e-util/e-attachment.h @@ -100,6 +100,12 @@ gboolean e_attachment_get_saving (EAttachment *attachment); gboolean e_attachment_get_shown (EAttachment *attachment); void e_attachment_set_shown (EAttachment *attachment, gboolean shown); +gboolean e_attachment_get_save_self (EAttachment *attachment); +void e_attachment_set_save_self (EAttachment *attachment, + gboolean save_self); +gboolean e_attachment_get_save_extracted (EAttachment *attachment); +void e_attachment_set_save_extracted (EAttachment *attachment, + gboolean save_extracted); camel_cipher_validity_encrypt_t e_attachment_get_encrypted (EAttachment *attachment); void e_attachment_set_encrypted (EAttachment *attachment, -- cgit v1.2.3