Changeset 552

Show
Ignore:
Timestamp:
07/04/06 15:08:36
Author:
pvanhoof
Message:

The last GList

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymail-camel/tny-msg-priv.h

    r521 r552  
    3232        TnyMsgHeaderIface *header; 
    3333        GMutex *parts_lock; 
    34         GList *parts; 
     34        TnyListIface *parts; 
    3535        GMutex *folder_lock; 
    3636        TnyMsgFolderIface *folder; 
  • trunk/libtinymail-camel/tny-msg.c

    r536 r552  
    2424#include <time.h> 
    2525 
     26#include <tny-list.h> 
     27#include <tny-list-iface.h> 
     28#include <tny-iterator-iface.h> 
     29 
    2630#include <tny-msg.h> 
    2731#include <tny-msg-mime-part-iface.h> 
     
    104108 
    105109        g_mutex_lock (priv->parts_lock); 
    106         priv->parts = g_list_prepend (priv->parts, tpart); 
     110 
     111        if (!priv->parts) 
     112                priv->parts = tny_list_new (); 
     113 
     114        tny_list_iface_prepend (priv->parts, tpart); 
    107115        g_mutex_unlock (priv->parts_lock); 
    108116 
     
    124132 
    125133        if (G_LIKELY (priv->parts)) 
    126         { 
    127                 g_list_foreach (priv->parts,  
    128                         destroy_part, NULL); 
    129  
    130                 g_list_free (priv->parts); 
    131         } 
    132  
     134                g_object_unref (G_OBJECT (priv->parts)); 
    133135        priv->parts = NULL; 
    134136 
     
    199201} 
    200202 
    201 static const GList
     203static const TnyListIface
    202204tny_msg_get_parts (TnyMsgIface *self) 
    203205{ 
    204206        TnyMsgPriv *priv = TNY_MSG_GET_PRIVATE (TNY_MSG (self)); 
    205         const GList *retval; 
     207        const TnyListIface *retval; 
    206208 
    207209        g_mutex_lock (priv->parts_lock); 
     
    256258                camel_medium_set_content_object (medium, containee); 
    257259        } else { 
    258                 curl = g_list_length (priv->parts); curl++; 
     260                curl = priv->parts ? tny_list_iface_length (priv->parts) : 0; curl++; 
    259261        } 
    260262 
     
    266268        camel_multipart_add_part_at ((CamelMultipart*)containee,  
    267269                tny_msg_mime_part_get_part (TNY_MSG_MIME_PART (part)), curl); 
    268          
    269         priv->parts = g_list_prepend (priv->parts, part); curl++; 
     270 
     271        if (!priv->parts) 
     272                priv->parts = tny_list_new (); 
     273 
     274        tny_list_iface_prepend (priv->parts, part); curl++; 
    270275 
    271276        g_mutex_unlock (priv->parts_lock); 
     
    285290        TnyMsgPriv *priv = TNY_MSG_GET_PRIVATE (TNY_MSG (self)); 
    286291        TnyMsgMimePartPriv *ppriv = TNY_MSG_MIME_PART_GET_PRIVATE (self); 
    287         GList *remove; 
     292        gpointer remove; 
     293        TnyIteratorIface *iterator; 
    288294        CamelDataWrapper *containee; 
    289295 
     
    291297 
    292298        containee = camel_medium_get_content_object (CAMEL_MEDIUM (ppriv->part)); 
    293         remove = g_list_nth (priv->parts, id); 
    294         priv->parts = g_list_remove_link (priv->parts, remove); 
     299        if (priv->parts) 
     300        { 
     301                iterator = tny_list_iface_create_iterator (priv->parts); 
     302                remove = tny_iterator_iface_nth (iterator, id); 
     303                g_object_unref (G_OBJECT (iterator)); 
     304                tny_list_iface_remove (priv->parts, remove); 
     305        } 
    295306        camel_multipart_remove_part_at (CAMEL_MULTIPART (containee), id); 
    296307 
    297308        if (G_LIKELY (remove)) 
    298         { 
    299                 if (G_LIKELY (remove->data)) 
    300                         camel_object_unref (CAMEL_OBJECT (remove->data)); 
    301  
    302                 g_list_free (remove); 
    303         } 
     309                camel_object_unref (CAMEL_OBJECT (remove)); 
    304310 
    305311        /* Warning: large lock that locks code, not data */ 
     
    406412 
    407413        tny_msg_set_header (TNY_MSG_IFACE (self), header); 
    408  
    409         return self; 
    410 } 
    411  
    412 static void 
    413 tny_msg_set_parts (TnyMsg *self, const GList *parts) 
    414 { 
    415         TnyMsgPriv *priv = TNY_MSG_GET_PRIVATE (TNY_MSG (self)); 
    416         GList *list = (GList*)parts; 
    417         gint nth=0; 
    418  
    419         while (G_LIKELY (list)) 
    420         { 
    421                 if (TNY_IS_MSG_MIME_PART_IFACE (list->data)) 
    422                         tny_msg_add_part (TNY_MSG_IFACE (self), list->data); 
    423                 else 
    424                         g_warning (_("Item number %d isn't a TnyMsgMimePartIface\n"), nth); 
    425  
    426                 list = g_list_next (list); nth++; 
    427         } 
    428  
    429         return; 
    430 } 
    431  
    432 /** 
    433  * tny_msg_new_with_header_and_parts: 
    434  * @header: a #TnyMsgHeaderIface object 
    435  * @parts: A double linked list with #TnyMsgMimePartIface objects 
    436  * 
    437  * The #TnyMsg implementation is actually a proxy for #CamelMimeMessage (and 
    438  * a few other Camel types) 
    439  * 
    440  * Return value: A new #TnyMsgIface instance implemented for Camel 
    441  **/ 
    442 TnyMsg* 
    443 tny_msg_new_with_header_and_parts (TnyMsgHeaderIface *header, const GList *parts) 
    444 { 
    445         TnyMsg *self = g_object_new (TNY_TYPE_MSG, NULL); 
    446  
    447         tny_msg_set_header (TNY_MSG_IFACE (self), header); 
    448         tny_msg_set_parts (self, parts); 
    449414 
    450415        return self; 
  • trunk/libtinymail-camel/tny-msg.h

    r187 r552  
    5656TnyMsg*   tny_msg_new                       (void); 
    5757TnyMsg*   tny_msg_new_with_header           (TnyMsgHeaderIface *header); 
    58 TnyMsg*   tny_msg_new_with_header_and_parts (TnyMsgHeaderIface *header, const GList *parts); 
    5958 
    6059G_END_DECLS 
  • trunk/libtinymail/tny-list-iterator.c

    r550 r552  
    238238        klass->nth_func = tny_list_iterator_nth; 
    239239        klass->current_func = tny_list_iterator_current; 
    240         klass->has_first_func = tny_list_iterator_has_next; 
     240        klass->has_first_func = tny_list_iterator_has_first; 
    241241        klass->has_next_func = tny_list_iterator_has_next; 
    242242        klass->get_list_func = tny_list_iterator_get_list; 
  • trunk/libtinymail/tny-msg-iface.c

    r521 r552  
    4949 * Get a read-only list of mime-parts of this message 
    5050 * 
    51  * Return value: A read-only GList with #TnyMsgMimePartIface instances 
     51 * Return value: A read-only #TnyListIface with #TnyMsgMimePartIface instances 
    5252 **/ 
    53 const GList
     53const TnyListIface
    5454tny_msg_iface_get_parts (TnyMsgIface *self) 
    5555{ 
  • trunk/libtinymail/tny-msg-iface.h

    r546 r552  
    4242        GTypeInterface parent; 
    4343 
    44         const GList*             (*get_parts_func)        (TnyMsgIface *self); 
     44        const TnyListIface*      (*get_parts_func)        (TnyMsgIface *self); 
    4545        const TnyMsgHeaderIface* (*get_header_func)       (TnyMsgIface *self); 
    4646 
     
    5656GType                    tny_msg_iface_get_type         (void); 
    5757 
    58 const GList*             tny_msg_iface_get_parts        (TnyMsgIface *self); 
     58const TnyListIface*      tny_msg_iface_get_parts        (TnyMsgIface *self); 
    5959const TnyMsgHeaderIface* tny_msg_iface_get_header       (TnyMsgIface *self); 
    6060 
  • trunk/libtinymailui-gtk/tny-msg-view.c

    r497 r552  
    3131#include <string.h> 
    3232#include <gtk/gtk.h> 
     33 
     34#include <tny-list-iface.h> 
     35#include <tny-iterator-iface.h> 
     36 
    3337#include <tny-msg-view.h> 
    3438#include <tny-text-buffer-stream.h> 
     
    7276        TnyStreamIface *dest; 
    7377        TnyMsgHeaderIface *header; 
    74         GList *parts; 
     78        TnyListIface *parts; 
     79        TnyIteratorIface *iterator; 
    7580        const gchar *str = NULL; 
    76         gboolean first_attach = TRUE
     81        gboolean first_attach = TRUE, next = FALSE
    7782        TnyAttachListModel *model; 
    7883 
     
    8590        g_return_if_fail (header); 
    8691 
    87         parts = (GList*)tny_msg_iface_get_parts (priv->msg); 
     92        parts = (TnyListIface*)tny_msg_iface_get_parts (priv->msg); 
     93        iterator = tny_list_iface_create_iterator (parts); 
     94        next = tny_iterator_iface_has_first (iterator); 
    8895 
    8996        gtk_widget_hide (priv->attachview_sw); 
     
    94101        gtk_widget_show (GTK_WIDGET (priv->headerview)); 
    95102 
    96         while (G_LIKELY (parts)
    97         { 
    98                 TnyMsgMimePartIface *part = parts->data
     103        while (next
     104        { 
     105                TnyMsgMimePartIface *part = tny_iterator_iface_current (iterator)
    99106 
    100107                if (G_LIKELY (tny_msg_mime_part_iface_content_type_is (part, "text/*"))) 
     
    113120                } 
    114121 
    115                 parts = g_list_next (parts); 
    116         } 
     122                next = tny_iterator_iface_has_next (iterator); 
     123 
     124                if (next) 
     125                        tny_iterator_iface_next (iterator); 
     126 
     127        } 
     128 
     129        g_object_unref (G_OBJECT (iterator)); 
     130 
    117131 
    118132        if (G_LIKELY (!first_attach)) 
  • trunk/libtinymailui-mozembed/tny-moz-embed-msg-view.c

    r497 r552  
    3030#include <string.h> 
    3131#include <gtk/gtk.h> 
     32#include <tny-list-iface.h> 
     33#include <tny-iterator-iface.h> 
     34 
    3235#include <tny-moz-embed-msg-view.h> 
    3336#include <tny-moz-embed-stream.h> 
     
    8689        GtkTextIter hiter; 
    8790        TnyMsgHeaderIface *header; 
    88         GList *parts; 
     91        TnyListIface *parts; 
     92        TnyIteratorIface *iterator; 
    8993        const gchar *str = NULL; 
    9094        gboolean first_attach = TRUE; 
    9195        TnyAttachListModel *model; 
    92         gboolean have_html = FALSE
     96        gboolean have_html = FALSE, next = FALSE
    9397        GtkTextBuffer *buffer; 
    9498 
     
    99103        g_return_if_fail (header); 
    100104 
    101         parts =  (GList*)tny_msg_iface_get_parts (priv->msg); 
     105        parts = (TnyListIface*)tny_msg_iface_get_parts (priv->msg); 
     106        iterator = tny_list_iface_create_iterator (parts); 
     107        next = tny_iterator_iface_has_first (iterator); 
     108 
    102109        buffer = gtk_text_view_get_buffer (priv->textview); 
    103110 
     
    109116        gtk_text_buffer_set_text (buffer, "", 0); 
    110117 
    111         while (G_LIKELY (parts)) 
    112         { 
    113                 TnyMsgMimePartIface *part = parts->data; 
    114  
    115                 if (!part) 
    116                 { 
    117                         /* This shouldn't happen! ;-) */ 
    118                         g_warning (_("Mimepart problem\n")); 
    119                         parts = g_list_next (parts); 
    120                         continue; 
    121                 } 
     118        while (next) 
     119        { 
     120                TnyMsgMimePartIface *part = tny_iterator_iface_current (iterator); 
    122121 
    123122                if (!have_html && G_LIKELY (tny_msg_mime_part_iface_content_type_is (part, "text/plain"))) 
     
    164163                } 
    165164 
    166                 parts = g_list_next (parts); 
    167         } 
     165                 
     166                next = tny_iterator_iface_has_next (iterator); 
     167 
     168                if (next) 
     169                        tny_iterator_iface_next (iterator); 
     170        } 
     171 
     172        g_object_unref (G_OBJECT (iterator)); 
    168173 
    169174        if (G_LIKELY (!first_attach))