root/trunk/libtinymailui/tny-mime-part-saver.c
| Revision 3666 (checked in by jdapena, 7 months ago) |
|---|
| Line | |
|---|---|
| 1 | /* libtinymailui - The Tiny Mail UI library |
| 2 | * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org> |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | /** |
| 21 | * TnyMimePartSaver: |
| 22 | * |
| 23 | * A type that can save a #TnyMimePart |
| 24 | * |
| 25 | * free-function: g_object_unref |
| 26 | **/ |
| 27 | |
| 28 | #include <config.h> |
| 29 | |
| 30 | #include <tny-mime-part-saver.h> |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * tny_mime_part_saver_set_save_strategy: |
| 35 | * @self: a #TnyMimePartSaver |
| 36 | * @strategy: a #TnyMimePartSaveStrategy |
| 37 | * |
| 38 | * Set the strategy for saving mime-parts |
| 39 | * |
| 40 | * Devices can have a specific strategy for storing a #TnyMimePart. For example |
| 41 | * a strategy that sends it to another computer or a strategy that saves it to |
| 42 | * a flash disk. In the message view component, you don't care about that: You |
| 43 | * only care about the API of the save-strategy interface. |
| 44 | * |
| 45 | * For more information take a look at tny_mime_part_save_strategy_perform_save() |
| 46 | * of #TnyMimePartSaveStrategy. |
| 47 | * |
| 48 | * |
| 49 | * Example: |
| 50 | * <informalexample><programlisting> |
| 51 | * static void |
| 52 | * tny_my_msg_view_set_save_strategy (TnyMimePartSaver *self_i, TnyMimePartSaveStrategy *strat) |
| 53 | * { |
| 54 | * TnyMyMsgView *self = TNY_MY_MSG_VIEW (self_i); |
| 55 | * if (self->save_strategy) |
| 56 | * g_object_unref (self->save_strategy); |
| 57 | * self->save_strategy = g_object_ref (strat); |
| 58 | * } |
| 59 | * static void |
| 60 | * tny_my_msg_view_finalize (TnyMyMsgView *self) |
| 61 | * { |
| 62 | * if (self->save_strategy)) |
| 63 | * g_object_unref (self->save_strategy); |
| 64 | * } |
| 65 | * </programlisting></informalexample> |
| 66 | * |
| 67 | * since: 1.0 |
| 68 | * audience: application-developer, type-implementer |
| 69 | **/ |
| 70 | void |
| 71 | tny_mime_part_saver_set_save_strategy (TnyMimePartSaver *self, TnyMimePartSaveStrategy *strategy) |
| 72 | { |
| 73 | #ifdef DEBUG |
| 74 | if (!TNY_MIME_PART_SAVER_GET_IFACE (self)->set_save_strategy) |
| 75 | g_critical ("You must implement tny_mime_part_saver_set_save_strategy\n"); |
| 76 | #endif |
| 77 | |
| 78 | TNY_MIME_PART_SAVER_GET_IFACE (self)->set_save_strategy(self, strategy); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | |
| 84 | /** |
| 85 | * tny_mime_part_saver_get_save_strategy: |
| 86 | * @self: a #TnyMsgView |
| 87 | * |
| 88 | * Get the strategy for saving mime-parts. The returned value must be |
| 89 | * unreferenced after use. |
| 90 | * |
| 91 | * For more information take a look at tny_mime_part_save_strategy_perform_save() |
| 92 | * of #TnyMimePartSaveStrategy. |
| 93 | * |
| 94 | * Example: |
| 95 | * <informalexample><programlisting> |
| 96 | * static void |
| 97 | * tny_my_msg_view_on_save_clicked (TnyMimePartSaver *self, TnyMimePart *attachment) |
| 98 | * { |
| 99 | * TnyMimePartSaveStrategy *strategy = tny_mime_part_saver_get_save_strategy (self); |
| 100 | * tny_save_strategy_save (strategy, attachment); |
| 101 | * g_object_unref (strategy); |
| 102 | * } |
| 103 | * </programlisting></informalexample> |
| 104 | * |
| 105 | * returns: (caller-owns): the #TnyMimePartSaveStrategy for @self |
| 106 | * since: 1.0 |
| 107 | * audience: application-developer, type-implementer |
| 108 | **/ |
| 109 | TnyMimePartSaveStrategy* |
| 110 | tny_mime_part_saver_get_save_strategy (TnyMimePartSaver *self) |
| 111 | { |
| 112 | #ifdef DEBUG |
| 113 | if (!TNY_MIME_PART_SAVER_GET_IFACE (self)->get_save_strategy) |
| 114 | g_critical ("You must implement tny_mime_part_saver_get_save_strategy\n"); |
| 115 | #endif |
| 116 | |
| 117 | return TNY_MIME_PART_SAVER_GET_IFACE (self)->get_save_strategy(self); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | /** |
| 122 | * tny_mime_part_saver_save: |
| 123 | * @self: a #TnyMimePartSaver |
| 124 | * @part: a #TnyMimePart |
| 125 | * |
| 126 | * Saves @mime_part using the save strategy of @self. |
| 127 | * |
| 128 | * since: 1.0 |
| 129 | * audience: application-developer, type-implementer |
| 130 | **/ |
| 131 | void |
| 132 | tny_mime_part_saver_save (TnyMimePartSaver *self, TnyMimePart *part) |
| 133 | { |
| 134 | #ifdef DEBUG |
| 135 | if (!TNY_MIME_PART_SAVER_GET_IFACE (self)->save) |
| 136 | g_critical ("You must implement tny_mime_part_saver_save\n"); |
| 137 | #endif |
| 138 | |
| 139 | TNY_MIME_PART_SAVER_GET_IFACE (self)->save(self, part); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | static void |
| 144 | tny_mime_part_saver_base_init (gpointer g_class) |
| 145 | { |
| 146 | static gboolean initialized = FALSE; |
| 147 | |
| 148 | if (!initialized) { |
| 149 | /* create interface signals here. */ |
| 150 | initialized = TRUE; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | static gpointer |
| 155 | tny_mime_part_saver_register_type (gpointer notused) |
| 156 | { |
| 157 | GType type = 0; |
| 158 | |
| 159 | static const GTypeInfo info = |
| 160 | { |
| 161 | sizeof (TnyMimePartSaverIface), |
| 162 | tny_mime_part_saver_base_init, /* base_init */ |
| 163 | NULL, /* base_finalize */ |
| 164 | NULL, /* class_init */ |
| 165 | NULL, /* class_finalize */ |
| 166 | NULL, /* class_data */ |
| 167 | 0, |
| 168 | 0, /* n_preallocs */ |
| 169 | NULL /* instance_init */ |
| 170 | }; |
| 171 | type = g_type_register_static (G_TYPE_INTERFACE, |
| 172 | "TnyMimePartSaver", &info, 0); |
| 173 | |
| 174 | return GUINT_TO_POINTER (type); |
| 175 | } |
| 176 | |
| 177 | GType |
| 178 | tny_mime_part_saver_get_type (void) |
| 179 | { |
| 180 | static GOnce once = G_ONCE_INIT; |
| 181 | g_once (&once, tny_mime_part_saver_register_type, NULL); |
| 182 | return GPOINTER_TO_UINT (once.retval); |
| 183 | } |
Note: See TracBrowser for help on using the browser.
