1
/* libtinymail - The Tiny Mail base library
2
* Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with self library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
22
#include <tny-mime-part-save-strategy.h>
25
* tny_mime_part_save_strategy_perform_save:
26
* @self: A #TnyMimePartSaveStrategy instance
27
* @part: The #TnyMimePart instance that must be saved
29
* With @self being a delegate of a #TnyMimePartSaver, this method performs the
32
* A save strategy for a mime part is used with a type that implements the
33
* #TnyMimePartSaver interface. Types that do, will often also implement the
34
* #TnyMsgView or #TnyMimePartView interface (it's not a requirement). In this
35
* case they say that the view has functionality for saving mime parts.
37
* You can for example inherit an implementation of a #TnyMsgView, like the
38
* #TnyGtkMsgView one, and let yours also implement #TnyMimePartSaver. The
39
* example shown here is for example such a situation.
42
* <informalexample><programlisting>
44
* tny_my_msg_view_save (TnyMimePartView *self_i, TnyMimePart *attachment)
46
* TnyMyMsgView *self = TNY_MY_MSG_VIEW (self_i);
47
* tny_mime_part_save_strategy_perform_save (self->mime_part_save_strategy, attachment);
49
* </programlisting></informalexample>
51
* Implementors: The idea is that devices can have specific strategies that can
52
* be changed at runtime.
54
* For example a strategy that sends it to another computer and/or a strategy
55
* that saves it to a flash disk. Configurable at runtime by simply switching
56
* the strategy property of a #TnyMimePartSaver.
58
* The implementation shown in this example implements it using the gtk+ toolkit.
59
* If your device doesn't support saving mime parts, saving a mime part can also
60
* be implemented by doing nothing. For example a #TnyMyDoNothingSaveStrategy.
61
* Maybe you will implement it by letting it contact a service and sending the
62
* mime part to it? It's up to you.
65
* <informalexample><programlisting>
67
* tny_gtk_mime_part_save_strategy_perform_save (TnyMimePartSaveStrategy *self, TnyMimePart *part)
69
* GtkFileChooserDialog *dialog;
70
* dialog = GTK_FILE_CHOOSER_DIALOG
71
* (gtk_file_chooser_dialog_new (_("MimePartSave File"), NULL,
72
* GTK_FILE_CHOOSER_ACTION_MIME_PART_SAVE,
73
* GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_MIME_PART_SAVE,
74
* GTK_RESPONSE_ACCEPT, NULL));
75
* gtk_file_chooser_set_current_name (dialog,
76
* tny_mime_part_get_filename (part));
77
* if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
80
* uri = gtk_file_chooser_get_filename (dialog);
81
* fd = open (uri, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
83
* TnyStream *stream = tny_fs_stream_new (fd);
84
* tny_mime_part_decode_to_stream (part, TNY_STREAM (stream));
85
* g_object_unref (G_OBJECT (stream));
88
* gtk_widget_destroy (GTK_WIDGET (dialog));
90
* </programlisting></informalexample>
92
* The method is typically called by the implementation of a #TnyMsgView.
93
* For example a clicked handler of a popup menu of a attachment view in your
94
* #TnyMsgView implementation.
96
* Note that a mime part can mean both the entire message (without its headers)
97
* and one individual mime part in such a message or a message in a message (in
98
* case of a messge/rfc822 mime part).
100
* A #TnyMsg inherits from #TnyMimePart which means that if you use the message
101
* instance with a #TnyMimePartSaveStrategy instance that the strategy for
102
* saving it must save the entire message. Whereas when you pass it just one
103
* individual mime part instance, the strategy must save only that part.
106
tny_mime_part_save_strategy_perform_save (TnyMimePartSaveStrategy *self, TnyMimePart *part)
109
if (!TNY_MIME_PART_SAVE_STRATEGY_GET_IFACE (self)->perform_save_func)
110
g_critical ("You must implement tny_mime_part_save_strategy_perform_save\n");
113
TNY_MIME_PART_SAVE_STRATEGY_GET_IFACE (self)->perform_save_func (self, part);
118
tny_mime_part_save_strategy_base_init (gpointer g_class)
120
static gboolean initialized = FALSE;
127
tny_mime_part_save_strategy_get_type (void)
129
static GType type = 0;
131
if (G_UNLIKELY(type == 0))
133
static const GTypeInfo info =
135
sizeof (TnyMimePartSaveStrategyIface),
136
tny_mime_part_save_strategy_base_init, /* base_init */
137
NULL, /* base_finalize */
138
NULL, /* class_init */
139
NULL, /* class_finalize */
140
NULL, /* class_data */
143
NULL /* instance_init */
145
type = g_type_register_static (G_TYPE_INTERFACE,
146
"TnyMimePartSaveStrategy", &info, 0);
148
g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);