root/trunk/libtinymailui/tny-mime-part-view.c
| Revision 3666 (checked in by jdapena, 6 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 | * TnyMimePartView: |
| 22 | * |
| 23 | * A type that can view a #TnyMimePart |
| 24 | * |
| 25 | * free-function: g_object_unref |
| 26 | **/ |
| 27 | |
| 28 | #include <config.h> |
| 29 | |
| 30 | #include <tny-mime-part-view.h> |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * tny_mime_part_view_clear: |
| 35 | * @self: a #TnyMimePartView |
| 36 | * |
| 37 | * Clear @self, show nothing |
| 38 | * |
| 39 | * since: 1.0 |
| 40 | * audience: application-developer, type-implementer |
| 41 | **/ |
| 42 | void |
| 43 | tny_mime_part_view_clear (TnyMimePartView *self) |
| 44 | { |
| 45 | #ifdef DEBUG |
| 46 | if (!TNY_MIME_PART_VIEW_GET_IFACE (self)->clear) |
| 47 | g_critical ("You must implement tny_mime_part_view_clear\n"); |
| 48 | #endif |
| 49 | |
| 50 | TNY_MIME_PART_VIEW_GET_IFACE (self)->clear(self); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | /** |
| 56 | * tny_mime_part_view_get_part: |
| 57 | * @self: a #TnyMimePartView |
| 58 | * |
| 59 | * Get the current mime part of @self. If @self is not displaying any mime part, |
| 60 | * NULL will be returned. Else the return value must be unreferenced after use. |
| 61 | * |
| 62 | * Example: |
| 63 | * <informalexample><programlisting> |
| 64 | * static TnyMimePart* |
| 65 | * tny_gtk_text_mime_part_view_get_part (TnyMimePartView *self) |
| 66 | * { |
| 67 | * TnyGtkTextMimePartViewPriv *priv = TNY_GTK_TEXT_MIME_PART_VIEW_GET_PRIV (self); |
| 68 | * return priv->part?TNY_MIME_PART (g_object_ref (priv->part)):NULL; |
| 69 | * } |
| 70 | * </programlisting></informalexample> |
| 71 | * |
| 72 | * returns: (null-ok) (caller-owns): a #TnyMimePart instance or NULL |
| 73 | * since: 1.0 |
| 74 | * audience: application-developer, type-implementer |
| 75 | **/ |
| 76 | TnyMimePart* |
| 77 | tny_mime_part_view_get_part (TnyMimePartView *self) |
| 78 | { |
| 79 | #ifdef DEBUG |
| 80 | if (!TNY_MIME_PART_VIEW_GET_IFACE (self)->get_part) |
| 81 | g_critical ("You must implement tny_mime_part_view_get_part\n"); |
| 82 | #endif |
| 83 | |
| 84 | return TNY_MIME_PART_VIEW_GET_IFACE (self)->get_part(self); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * tny_mime_part_view_set_part: |
| 89 | * @self: a #TnyMimePartView |
| 90 | * @mime_part: a #TnyMimePart |
| 91 | * |
| 92 | * Set the MIME part which @self should display. Note that if possible, try to |
| 93 | * wait for as long as possible to call this API. As soon as this API is used, |
| 94 | * and the part's data is not available locally, will the part's data be |
| 95 | * requested from the service. |
| 96 | * |
| 97 | * If you can delay the need for calling this API, for example by offering the |
| 98 | * user a feature to make it visible rather than making the part always visible, |
| 99 | * then this is a smart thing to do to save bandwidth consumption in your final |
| 100 | * application. |
| 101 | * |
| 102 | * For example #GtkExpander and setting it when the child widget gets realized |
| 103 | * in case you are using libtinymailui-gtk. A convenient #TnyGtkExpanderMimePartView |
| 104 | * is available in libtinymailui-gtk that does exactly this. It will call for the |
| 105 | * API when you expand the expander (the user presses the expand-arrow). |
| 106 | * |
| 107 | * Note that it's recommended to use tny_mime_part_decode_to_stream_async() over |
| 108 | * tny_mime_part_decode_to_stream() if you want your user interface to remain |
| 109 | * responsive in case Tinymail's engine needs to pull data from a service. |
| 110 | * |
| 111 | * Example: |
| 112 | * <informalexample><programlisting> |
| 113 | * static void |
| 114 | * on_mime_part_decoded (TnyMimePart *part, TnyStream *dest, gboolean cancelled, GError *err, gpointer user_data) |
| 115 | * { |
| 116 | * TnyMimePartView *self = (TnyMimePartView *) user_data; |
| 117 | * if (!cancelled && !err) |
| 118 | * make_part_really_visible_now (self, part); |
| 119 | * g_object_unref (self); |
| 120 | * } |
| 121 | * static void |
| 122 | * on_status (GObject *part, TnyStatus *status, gpointer user_data) |
| 123 | * { |
| 124 | * TnyMimePartView *self = (TnyMimePartView *) user_data; |
| 125 | * move_progress_bar (self, tny_status_get_fraction (status)); |
| 126 | * } |
| 127 | * static void |
| 128 | * tny_gtk_text_mime_part_view_set_part (TnyMimePartView *self, TnyMimePart *part) |
| 129 | * { |
| 130 | * if (part) { |
| 131 | * GtkTextBuffer *buffer; |
| 132 | * TnyStream *dest; |
| 133 | * buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self)); |
| 134 | * if (buffer && GTK_IS_TEXT_BUFFER (buffer)) |
| 135 | * gtk_text_buffer_set_text (buffer, "", 0); |
| 136 | * dest = tny_gtk_text_buffer_stream_new (buffer); |
| 137 | * tny_stream_reset (dest); |
| 138 | * tny_mime_part_decode_to_stream_async (part, dest, on_mime_part_decoded, |
| 139 | * on_status, g_object_ref (self)); |
| 140 | * tny_stream_reset (dest); |
| 141 | * g_object_unref (dest); |
| 142 | * priv->part = TNY_MIME_PART (g_object_ref (part)); |
| 143 | * } |
| 144 | * } |
| 145 | * static void |
| 146 | * tny_gtk_text_mime_part_view_finalize (TnyGtkTextMimePartView *self) |
| 147 | * { |
| 148 | * if (priv->part)) |
| 149 | * g_object_unref (priv->part); |
| 150 | * } |
| 151 | * </programlisting></informalexample> |
| 152 | * |
| 153 | * since: 1.0 |
| 154 | * audience: application-developer, type-implementer |
| 155 | **/ |
| 156 | void |
| 157 | tny_mime_part_view_set_part (TnyMimePartView *self, TnyMimePart *mime_part) |
| 158 | { |
| 159 | #ifdef DEBUG |
| 160 | if (!TNY_MIME_PART_VIEW_GET_IFACE (self)->set_part) |
| 161 | g_critical ("You must implement tny_mime_part_view_set_part\n"); |
| 162 | #endif |
| 163 | |
| 164 | TNY_MIME_PART_VIEW_GET_IFACE (self)->set_part(self, mime_part); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | static void |
| 169 | tny_mime_part_view_base_init (gpointer g_class) |
| 170 | { |
| 171 | static gboolean initialized = FALSE; |
| 172 | |
| 173 | if (!initialized) { |
| 174 | /* create interface signals here. */ |
| 175 | initialized = TRUE; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | static gpointer |
| 180 | tny_mime_part_view_register_type (gpointer notused) |
| 181 | { |
| 182 | GType type = 0; |
| 183 | |
| 184 | static const GTypeInfo info = |
| 185 | { |
| 186 | sizeof (TnyMimePartViewIface), |
| 187 | tny_mime_part_view_base_init, /* base_init */ |
| 188 | NULL, /* base_finalize */ |
| 189 | NULL, /* class_init */ |
| 190 | NULL, /* class_finalize */ |
| 191 | NULL, /* class_data */ |
| 192 | 0, |
| 193 | 0, /* n_preallocs */ |
| 194 | NULL /* instance_init */ |
| 195 | }; |
| 196 | type = g_type_register_static (G_TYPE_INTERFACE, |
| 197 | "TnyMimePartView", &info, 0); |
| 198 | |
| 199 | return GUINT_TO_POINTER (type); |
| 200 | } |
| 201 | |
| 202 | GType |
| 203 | tny_mime_part_view_get_type (void) |
| 204 | { |
| 205 | static GOnce once = G_ONCE_INIT; |
| 206 | g_once (&once, tny_mime_part_view_register_type, NULL); |
| 207 | return GPOINTER_TO_UINT (once.retval); |
| 208 | } |
Note: See TracBrowser for help on using the browser.
