![]() |
![]() |
![]() |
Reference Manual of the tinymail framework | ![]() |
---|---|---|---|---|
TnyMimePartSaveStrategy; TnyMimePartSaveStrategyIface; void tny_mime_part_save_strategy_perform_save (TnyMimePartSaveStrategy *self, TnyMimePart *part);
A type typically used by a TnyMsgView implementation for saving a TnyMimePart or a TnyMsg (which inherits from TnyMimePart) to a file.
typedef struct _TnyMimePartSaveStrategy TnyMimePartSaveStrategy;
A strategy for saving a TnyMimePart
free-function: g_object_unref
typedef struct { GTypeInterface parent; void (*perform_save) (TnyMimePartSaveStrategy *self, TnyMimePart *part); } TnyMimePartSaveStrategyIface;
void tny_mime_part_save_strategy_perform_save (TnyMimePartSaveStrategy *self, TnyMimePart *part);
With self
being a delegate of a TnyMimePartSaver, this method performs the
saving of part
.
A save strategy for a mime part is used with a type that implements the TnyMimePartSaver interface. Very often are such types also implementing the TnyMsgView and/or TnyMimePartView interfaces (although it's not a requirement). When implementing TnyMimePartSaver you say that the view has functionality for saving mime parts.
Example:
static void tny_my_msg_view_save (TnyMimePartView *self_i, TnyMimePart *attachment) { TnyMyMsgView *self = TNY_MY_MSG_VIEW (self_i); tny_mime_part_save_strategy_perform_save (self->mime_part_save_strategy, attachment); }
Devices can have specific strategies that are changed at runtime. For example a save-strategy that sends the content of the mime part it to another computer and/or a save-strategy that saves it to a flash disk. Configurable at runtime by simply switching the save-strategy property of a TnyMimePartSaver.
Example:
static void tny_gtk_mime_part_save_strategy_perform_save (TnyMimePartSaveStrategy *self, TnyMimePart *part) { GtkFileChooserDialog *dialog; dialog = GTK_FILE_CHOOSER_DIALOG (gtk_file_chooser_dialog_new (_("Save attachment"), NULL, GTK_FILE_CHOOSER_ACTION_MIME_PART_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_MIME_PART_SAVE, GTK_RESPONSE_ACCEPT, NULL)); gtk_file_chooser_set_current_name (dialog, tny_mime_part_get_filename (part)); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { gchar *uri; int fd; uri = gtk_file_chooser_get_filename (dialog); fd = open (uri, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); if (fd != -1) { TnyStream *stream = tny_fs_stream_new (fd); tny_mime_part_decode_to_stream (part, stream, NULL); g_object_unref (stream); } } gtk_widget_destroy (GTK_WIDGET (dialog)); }
An example when to use this method is in a clicked handler of a popup menu of a attachment TnyMimePartView in your TnyMsgView.
Note that a mime part can mean both the entire message (without its headers) and one individual mime part in such a message or a message in a message (in case of a messge/rfc822 mime part).
self : |
a TnyMimePartSaveStrategy |
part : |
a TnyMimePart that must be saved |
Since 1.0 audience: application-developer, type-implementer