root/trunk/libtinymailui/tny-msg-view.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 | * TnyMsgView: |
| 22 | * |
| 23 | * A type that can view a #TnyMsg and usually inherits from #TnyMimePartView |
| 24 | * |
| 25 | * free-function: g_object_unref |
| 26 | **/ |
| 27 | |
| 28 | #include <config.h> |
| 29 | |
| 30 | #include <tny-msg-view.h> |
| 31 | |
| 32 | /** |
| 33 | * tny_msg_view_create_new_inline_viewer: |
| 34 | * @self: a #TnyMsgView |
| 35 | * |
| 36 | * Create a new #TnyMsgView that can be used to display an inline message, |
| 37 | * like a message/rfc822 MIME part. Usually it will return a new instance of |
| 38 | * the same type as @self. The returned instance must be unreferenced after |
| 39 | * use. |
| 40 | * |
| 41 | * Example: |
| 42 | * <informalexample><programlisting> |
| 43 | * static TnyMsgView* |
| 44 | * tny_my_html_msg_view_create_new_inline_viewer (TnyMsgView *self) |
| 45 | * { |
| 46 | * return tny_my_html_msg_view_new (); |
| 47 | * } |
| 48 | * </programlisting></informalexample> |
| 49 | * |
| 50 | * returns: (caller-owns): a #TnyMsgView instance |
| 51 | * since: 1.0 |
| 52 | * audience: application-developer, type-implementer |
| 53 | **/ |
| 54 | TnyMsgView* |
| 55 | tny_msg_view_create_new_inline_viewer (TnyMsgView *self) |
| 56 | { |
| 57 | #ifdef DEBUG |
| 58 | if (!TNY_MSG_VIEW_GET_IFACE (self)->create_new_inline_viewer) |
| 59 | g_critical ("You must implement tny_msg_view_create_new_inline_viewer\n"); |
| 60 | #endif |
| 61 | |
| 62 | return TNY_MSG_VIEW_GET_IFACE (self)->create_new_inline_viewer(self); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * tny_msg_view_create_mime_part_view_for: |
| 67 | * @self: a #TnyMsgView |
| 68 | * @part: a #TnyMimePart |
| 69 | * |
| 70 | * Create a #TnyMimePartView instance for viewing @part. The returned instance |
| 71 | * must be unreferenced after use. It's recommended to return the result of |
| 72 | * calling the function on the super of @self (like in the example below) in |
| 73 | * case your type's implementation can't display @part. |
| 74 | * |
| 75 | * Example: |
| 76 | * <informalexample><programlisting> |
| 77 | * static TnyMimePartView* |
| 78 | * tny_my_html_msg_view_create_mime_part_view_for (TnyMsgView *self, TnyMimePart *part) |
| 79 | * { |
| 80 | * TnyMimePartView *retval = NULL; |
| 81 | * if (tny_mime_part_content_type_is (part, "text/html")) { |
| 82 | * GtkWidget *widget = (GtkWidget *) self; |
| 83 | * retval = tny_my_html_mime_part_view_new (); |
| 84 | * } else |
| 85 | * retval = TNY_GTK_MSG_VIEW_CLASS (parent_class)->create_mime_part_view_for(self, part); |
| 86 | * return retval; |
| 87 | * } |
| 88 | * </programlisting></informalexample> |
| 89 | * |
| 90 | * ps. For a real and complete working example take a look at the implementation of |
| 91 | * #TnyMozEmbedMsgView in libtinymailui-mozembed. |
| 92 | * |
| 93 | * returns: (caller-owns): a #TnyMimePartView instance |
| 94 | * since: 1.0 |
| 95 | * audience: application-developer, type-implementer |
| 96 | **/ |
| 97 | TnyMimePartView* |
| 98 | tny_msg_view_create_mime_part_view_for (TnyMsgView *self, TnyMimePart *part) |
| 99 | { |
| 100 | #ifdef DEBUG |
| 101 | if (!TNY_MSG_VIEW_GET_IFACE (self)->create_mime_part_view_for) |
| 102 | g_critical ("You must implement tny_msg_view_create_mime_part_view_for\n"); |
| 103 | #endif |
| 104 | |
| 105 | return TNY_MSG_VIEW_GET_IFACE (self)->create_mime_part_view_for(self, part); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * tny_msg_view_clear: |
| 110 | * @self: A #TnyMsgView |
| 111 | * |
| 112 | * Clear @self, show nothing |
| 113 | * |
| 114 | * since: 1.0 |
| 115 | * audience: application-developer, type-implementer |
| 116 | **/ |
| 117 | void |
| 118 | tny_msg_view_clear (TnyMsgView *self) |
| 119 | { |
| 120 | #ifdef DEBUG |
| 121 | if (!TNY_MSG_VIEW_GET_IFACE (self)->clear) |
| 122 | g_critical ("You must implement tny_msg_view_clear\n"); |
| 123 | #endif |
| 124 | |
| 125 | TNY_MSG_VIEW_GET_IFACE (self)->clear(self); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | /** |
| 131 | * tny_msg_view_set_unavailable: |
| 132 | * @self: a #TnyMsgView |
| 133 | * |
| 134 | * Set @self to display that a message was unavailable. You can for example |
| 135 | * implement this method by simply calling tny_msg_view_clear(). |
| 136 | * |
| 137 | * since: 1.0 |
| 138 | * audience: application-developer, type-implementer |
| 139 | **/ |
| 140 | void |
| 141 | tny_msg_view_set_unavailable (TnyMsgView *self) |
| 142 | { |
| 143 | #ifdef DEBUG |
| 144 | if (!TNY_MSG_VIEW_GET_IFACE (self)->set_unavailable) |
| 145 | g_critical ("You must implement tny_msg_view_set_unavailable\n"); |
| 146 | #endif |
| 147 | |
| 148 | TNY_MSG_VIEW_GET_IFACE (self)->set_unavailable(self); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /** |
| 154 | * tny_msg_view_get_msg: |
| 155 | * @self: a #TnyMsgView |
| 156 | * |
| 157 | * Get the current message of @self. If @self is not displaying any message, |
| 158 | * NULL will be returned. Else the return value must be unreferenced after use. |
| 159 | * |
| 160 | * When inheriting from a #TnyMimePartView, this method is most likely going to |
| 161 | * be an alias for tny_mime_part_view_get_part(), with the returned #TnyMimePart |
| 162 | * casted to a #TnyMsg (in this case, the method in the #TnyMimePartView should |
| 163 | * return a #TnyMsg, indeed). |
| 164 | * |
| 165 | * returns: (null-ok) (caller-owns): A #TnyMsg instance or NULL |
| 166 | * since: 1.0 |
| 167 | * audience: application-developer, type-implementer |
| 168 | **/ |
| 169 | TnyMsg* |
| 170 | tny_msg_view_get_msg (TnyMsgView *self) |
| 171 | { |
| 172 | #ifdef DEBUG |
| 173 | if (!TNY_MSG_VIEW_GET_IFACE (self)->get_msg) |
| 174 | g_critical ("You must implement tny_msg_view_get_msg\n"); |
| 175 | #endif |
| 176 | |
| 177 | return TNY_MSG_VIEW_GET_IFACE (self)->get_msg(self); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * tny_msg_view_set_msg: |
| 182 | * @self: a #TnyMsgView |
| 183 | * @msg: a #TnyMsg |
| 184 | * |
| 185 | * Set the message which view @self must display. |
| 186 | * |
| 187 | * Note that you can get a list of mime parts using the tny_mime_part_get_parts() |
| 188 | * API of the #TnyMimePart type. You can use the tny_msg_view_create_mime_part_view_for() |
| 189 | * API to get a #TnyMimePartView that can view the mime part. |
| 190 | * |
| 191 | * When inheriting from a #TnyMimePartView this method is most likely going to |
| 192 | * decorate or alias tny_mime_part_view_set_part(), with the passed #TnyMsg |
| 193 | * casted to a #TnyMimePart. |
| 194 | * |
| 195 | * Example: |
| 196 | * <informalexample><programlisting> |
| 197 | * static void |
| 198 | * tny_my_msg_view_set_msg (TnyMsgView *self, TnyMsg *msg) |
| 199 | * { |
| 200 | * TnyIterator *iterator; |
| 201 | * TnyList *list = tny_simple_list_new (); |
| 202 | * tny_msg_view_clear (self); |
| 203 | * header = tny_msg_get_header (msg); |
| 204 | * tny_header_view_set_header (priv->headerview, header); |
| 205 | * g_object_unref (header); |
| 206 | * tny_mime_part_view_set_part (TNY_MIME_PART_VIEW (self), |
| 207 | * TNY_MIME_PART (msg)); |
| 208 | * tny_mime_part_get_parts (TNY_MIME_PART (msg), list); |
| 209 | * iterator = tny_list_create_iterator (list); |
| 210 | * while (!tny_iterator_is_done (iterator)) { |
| 211 | * TnyMimePart *part = tny_iterator_get_current (iterator); |
| 212 | * TnyMimePartView *mpview; |
| 213 | * mpview = tny_msg_view_create_mime_part_view_for (self, part); |
| 214 | * if (mpview) |
| 215 | * tny_mime_part_view_set_part (mpview, part); |
| 216 | * g_object_unref (part); |
| 217 | * tny_iterator_next (iterator); |
| 218 | * } |
| 219 | * g_object_unref (iterator); |
| 220 | * g_object_unref (list); |
| 221 | * } |
| 222 | * </programlisting></informalexample> |
| 223 | * |
| 224 | * ps. For a real and complete working example take a look at the implementation of |
| 225 | * #TnyGtkMsgView in libtinymailui-gtk. |
| 226 | * |
| 227 | * since: 1.0 |
| 228 | * audience: application-developer, type-implementer |
| 229 | **/ |
| 230 | void |
| 231 | tny_msg_view_set_msg (TnyMsgView *self, TnyMsg *msg) |
| 232 | { |
| 233 | #ifdef DEBUG |
| 234 | if (!TNY_MSG_VIEW_GET_IFACE (self)->set_msg) |
| 235 | g_critical ("You must implement tny_msg_view_set_msg\n"); |
| 236 | #endif |
| 237 | |
| 238 | TNY_MSG_VIEW_GET_IFACE (self)->set_msg(self, msg); |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | static void |
| 243 | tny_msg_view_base_init (gpointer g_class) |
| 244 | { |
| 245 | static gboolean initialized = FALSE; |
| 246 | |
| 247 | if (!initialized) { |
| 248 | /* create interface signals here. */ |
| 249 | initialized = TRUE; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | static gpointer |
| 254 | tny_msg_view_register_type (gpointer notused) |
| 255 | { |
| 256 | GType type = 0; |
| 257 | |
| 258 | static const GTypeInfo info = |
| 259 | { |
| 260 | sizeof (TnyMsgViewIface), |
| 261 | tny_msg_view_base_init, /* base_init */ |
| 262 | NULL, /* base_finalize */ |
| 263 | NULL, /* class_init */ |
| 264 | NULL, /* class_finalize */ |
| 265 | NULL, /* class_data */ |
| 266 | 0, |
| 267 | 0, /* n_preallocs */ |
| 268 | NULL /* instance_init */ |
| 269 | }; |
| 270 | type = g_type_register_static (G_TYPE_INTERFACE, |
| 271 | "TnyMsgView", &info, 0); |
| 272 | |
| 273 | g_type_interface_add_prerequisite (type, TNY_TYPE_MIME_PART_VIEW); |
| 274 | |
| 275 | return GUINT_TO_POINTER (type); |
| 276 | } |
| 277 | |
| 278 | GType |
| 279 | tny_msg_view_get_type (void) |
| 280 | { |
| 281 | static GOnce once = G_ONCE_INIT; |
| 282 | g_once (&once, tny_msg_view_register_type, NULL); |
| 283 | return GPOINTER_TO_UINT (once.retval); |
| 284 | } |
Note: See TracBrowser for help on using the browser.
