Changeset 556

Show
Ignore:
Timestamp:
07/05/06 11:39:03
Author:
pvanhoof
Message:

The TnyAccountTreeModel? as a TnyListIface?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymailui-gtk/Makefile.am

    r429 r556  
    2020        tny-msg-header-view.h 
    2121 
    22 libtinymailui_gtk_1_0_la_SOURCES =          \ 
    23         $(libtinymailui_gtk_1_0_headers)    \ 
    24         tny-save-strategy.c                 \ 
    25         tny-msg-view.c                      \ 
    26         tny-msg-window.c                    \ 
    27         tny-msg-header-list-model-priv.h    \ 
    28         tny-msg-header-list-iterator-priv.h \ 
    29         tny-msg-header-list-model.c         \ 
    30         tny-msg-header-list-iterator.c      \ 
    31         tny-account-tree-model.c            \ 
    32         tny-attach-list-model-priv.h        \ 
    33         tny-attach-list-model.c             \ 
    34         tny-text-buffer-stream.c            \ 
     22libtinymailui_gtk_1_0_la_SOURCES =             \ 
     23        $(libtinymailui_gtk_1_0_headers)       \ 
     24        tny-save-strategy.c                    \ 
     25        tny-msg-view.c                         \ 
     26        tny-msg-window.c                       \ 
     27        tny-msg-header-list-model-priv.h       \ 
     28        tny-msg-header-list-iterator-priv.h    \ 
     29        tny-account-tree-model-iterator-priv.h \ 
     30        tny-account-tree-model-iterator.c      \ 
     31        tny-account-tree-model-priv.h          \ 
     32        tny-msg-header-list-model.c            \ 
     33        tny-msg-header-list-iterator.c         \ 
     34        tny-account-tree-model.c               \ 
     35        tny-attach-list-model-priv.h           \ 
     36        tny-attach-list-model.c                \ 
     37        tny-text-buffer-stream.c               \ 
    3538        tny-msg-header-view.c 
    3639 
  • trunk/libtinymailui-gtk/tny-account-tree-model.c

    r550 r556  
    2929#include <tny-msg-folder-iface.h> 
    3030 
     31#include "tny-account-tree-model-priv.h" 
     32 
    3133static GObjectClass *parent_class = NULL; 
    3234 
     35typedef void (*treeaddfunc) (GtkTreeStore *tree_store, GtkTreeIter *iter, GtkTreeIter *parent); 
    3336 
    3437static void 
     
    8386} 
    8487 
    85 /** 
    86  * tny_account_tree_model_add: 
    87  * @self: A #TnyAccountTreeModel instance 
    88  * @account: A #TnyAccountIface instance 
    89  * 
    90  * Add an account to the list model 
    91  * 
    92  **/ 
    93 void 
    94 tny_account_tree_model_add (TnyAccountTreeModel *self, TnyStoreAccountIface *account) 
     88 
     89static void 
     90tny_account_tree_model_add (TnyAccountTreeModel *self, TnyStoreAccountIface *account, treeaddfunc func) 
    9591{ 
    9692        GtkTreeStore *model = GTK_TREE_STORE (self); 
     
    10197                TNY_STORE_ACCOUNT_FOLDER_TYPE_SUBSCRIBED); 
    10298 
    103         gtk_tree_store_append (model, &name_iter, NULL); 
     99        func (model, &name_iter, NULL); 
    104100 
    105101        gtk_tree_store_set (model, &name_iter, 
     
    135131tny_account_tree_model_finalize (GObject *object) 
    136132{ 
     133        TnyAccountTreeModel *me = (TnyAccountTreeModel*) object; 
     134 
     135        g_mutex_free (me->iterator_lock); 
     136        me->iterator_lock = NULL; 
     137 
    137138        (*parent_class->finalize) (object); 
    138139} 
     
    155156{ 
    156157        GtkTreeStore *store = (GtkTreeStore*) instance; 
     158        TnyAccountTreeModel *me = (TnyAccountTreeModel*) instance; 
    157159        static GType types[] = { G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_POINTER }; 
     160 
     161        me->iterator_lock = g_mutex_new (); 
    158162 
    159163        gtk_tree_store_set_column_types (store,  
     
    163167} 
    164168 
     169 
     170 
     171static TnyIteratorIface* 
     172tny_account_tree_model_create_iterator (TnyListIface *self) 
     173{ 
     174        TnyAccountTreeModel *me = (TnyAccountTreeModel*)self; 
     175 
     176        /* Return a new iterator */ 
     177 
     178        return TNY_ITERATOR_IFACE (_tny_account_tree_model_iterator_new (me)); 
     179} 
     180 
     181 
     182 
     183static void 
     184tny_account_tree_model_prepend (TnyListIface *self, gpointer item) 
     185{ 
     186        TnyAccountTreeModel *me = (TnyAccountTreeModel*)self; 
     187 
     188        g_mutex_lock (me->iterator_lock); 
     189 
     190        /* Prepend something to the list */ 
     191        me->first = g_list_prepend (me->first, item); 
     192        tny_account_tree_model_add (me, TNY_STORE_ACCOUNT_IFACE (item), gtk_tree_store_prepend); 
     193 
     194        g_mutex_unlock (me->iterator_lock); 
     195} 
     196 
     197static void 
     198tny_account_tree_model_append (TnyListIface *self, gpointer item) 
     199{ 
     200        TnyAccountTreeModel *me = (TnyAccountTreeModel*)self; 
     201 
     202        g_mutex_lock (me->iterator_lock); 
     203 
     204        /* Append something to the list */ 
     205        me->first = g_list_append (me->first, item); 
     206 
     207        tny_account_tree_model_add (me, TNY_STORE_ACCOUNT_IFACE (item), gtk_tree_store_append); 
     208 
     209        g_mutex_unlock (me->iterator_lock); 
     210} 
     211 
     212static guint 
     213tny_account_tree_model_length (TnyListIface *self) 
     214{ 
     215        TnyAccountTreeModel *me = (TnyAccountTreeModel*)self; 
     216        guint retval = 0; 
     217 
     218        g_mutex_lock (me->iterator_lock); 
     219 
     220        retval = me->first?g_list_length (me->first):0; 
     221 
     222        g_mutex_unlock (me->iterator_lock); 
     223 
     224        return retval; 
     225} 
     226 
     227static void 
     228tny_account_tree_model_remove (TnyListIface *self, gpointer item) 
     229{ 
     230        TnyAccountTreeModel *me = (TnyAccountTreeModel*)self; 
     231        GtkTreeModel *model = GTK_TREE_MODEL (me); 
     232        GtkTreeIter iter; 
     233 
     234        g_return_if_fail (G_IS_OBJECT (item)); 
     235        g_return_if_fail (G_IS_OBJECT (me)); 
     236 
     237        /* Remove something from the list */ 
     238 
     239        g_mutex_lock (me->iterator_lock); 
     240 
     241        me->first = g_list_remove (me->first, (gconstpointer)item); 
     242 
     243        gtk_tree_model_get_iter_first (model, &iter); 
     244        while (gtk_tree_model_iter_next (model, &iter)) 
     245        { 
     246                TnyAccountIface *curaccount; 
     247 
     248                gtk_tree_model_get (model, &iter,  
     249                        TNY_ACCOUNT_TREE_MODEL_INSTANCE_COLUMN,  
     250                        &curaccount, -1); 
     251 
     252                if (curaccount == item) 
     253                { 
     254                        gtk_tree_store_remove (GTK_TREE_STORE (me), &iter); 
     255                        g_object_unref (G_OBJECT (item)); 
     256 
     257                        break; 
     258                } 
     259        } 
     260 
     261        g_mutex_unlock (me->iterator_lock); 
     262} 
     263 
     264 
     265static TnyListIface* 
     266tny_account_tree_model_copy_the_list (TnyListIface *self) 
     267{ 
     268        TnyAccountTreeModel *me = (TnyAccountTreeModel*)self; 
     269        TnyAccountTreeModel *copy = g_object_new (TNY_TYPE_ACCOUNT_TREE_MODEL, NULL); 
     270 
     271        /* This only copies the TnyListIface pieces. The result is not a 
     272           correct or good TnyMsgHeaderListModel. But it will be a correct 
     273           TnyListIface instance. It is the only thing the user of this 
     274           method expects. 
     275 
     276           The new list will point to the same instances, of course. It's 
     277           only a copy of the list-nodes of course. */ 
     278 
     279        g_mutex_lock (me->iterator_lock); 
     280        GList *list_copy = g_list_copy (me->first); 
     281        copy->first = list_copy; 
     282        g_mutex_unlock (me->iterator_lock); 
     283 
     284        return TNY_LIST_IFACE (copy); 
     285} 
     286 
     287static void  
     288tny_account_tree_model_foreach_in_the_list (TnyListIface *self, GFunc func, gpointer user_data) 
     289{ 
     290        TnyAccountTreeModel *me = (TnyAccountTreeModel*)self; 
     291 
     292        /* Foreach item in the list (without using a slower iterator) */ 
     293 
     294        g_mutex_lock (me->iterator_lock); 
     295        g_list_foreach (me->first, func, user_data); 
     296        g_mutex_unlock (me->iterator_lock); 
     297 
     298        return; 
     299} 
     300 
     301 
     302static void 
     303tny_list_iface_init (TnyListIfaceClass *klass) 
     304{ 
     305        klass->length_func = tny_account_tree_model_length; 
     306        klass->prepend_func = tny_account_tree_model_prepend; 
     307        klass->append_func = tny_account_tree_model_append; 
     308        klass->remove_func = tny_account_tree_model_remove; 
     309        klass->create_iterator_func = tny_account_tree_model_create_iterator; 
     310        klass->copy_func = tny_account_tree_model_copy_the_list; 
     311        klass->foreach_func = tny_account_tree_model_foreach_in_the_list; 
     312 
     313        return; 
     314} 
    165315 
    166316GType 
     
    186336                type = g_type_register_static (GTK_TYPE_TREE_STORE, "TnyAccountTreeModel", 
    187337                                            &info, 0); 
     338 
     339                static const GInterfaceInfo tny_list_iface_info = { 
     340                        (GInterfaceInitFunc) tny_list_iface_init, 
     341                        NULL, 
     342                        NULL 
     343                }; 
     344 
     345                g_type_add_interface_static (type, TNY_TYPE_LIST_IFACE, 
     346                                             &tny_list_iface_info); 
    188347        } 
    189348 
  • trunk/libtinymailui-gtk/tny-account-tree-model.h

    r549 r556  
    4747}; 
    4848 
    49 struct _TnyAccountTreeModel 
    50 { 
    51         GtkTreeStore parent; 
    52 }; 
    53  
    54 struct _TnyAccountTreeModelClass 
    55 { 
    56         GtkTreeStoreClass parent_class; 
    57 }; 
    5849 
    5950 
     
    6152TnyAccountTreeModel*    tny_account_tree_model_new       (void); 
    6253 
    63 void                    tny_account_tree_model_add       (TnyAccountTreeModel *self, TnyStoreAccountIface *account); 
    64  
    6554G_END_DECLS 
    6655 
  • trunk/tinymail/tny-summary-window.c

    r550 r556  
    101101{ 
    102102        TnyAccountStoreIface *account_store = priv->account_store; 
    103         GtkTreeModel *sortable, *mailbox_model = GTK_TREE_MODEL (tny_account_tree_model_new ()); 
    104         TnyListIface *accounts = tny_list_new (); 
    105         gboolean next = FALSE; 
    106         TnyIteratorIface *iterator; 
    107  
     103        GtkTreeModel *sortable; 
     104 
     105        /* TnyAccountTreeModel is also a TnyListIface (it simply both the 
     106           TnyListIface and the GtkTreeModelIface interfaces interfaces) */ 
     107 
     108        GtkTreeModel *mailbox_model = GTK_TREE_MODEL (tny_account_tree_model_new ()); 
     109        TnyListIface *accounts = TNY_LIST_IFACE (mailbox_model); 
     110 
     111        /* Clear the header_view by giving it an empty model */ 
    108112        if (G_UNLIKELY (!empty_model)) 
    109         { 
    110                 empty_model = GTK_TREE_MODEL (gtk_list_store_new  
    111                         (1, G_TYPE_STRING)); 
    112         } 
    113  
    114         /* Clear the header_view by giving it an empty model */ 
     113                empty_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING)); 
    115114        set_header_view_model (GTK_TREE_VIEW (priv->header_view), empty_model); 
    116115 
     
    121120        } 
    122121 
    123         /* TODO: refactor the tree-model to a TnyListIface */ 
    124         tny_account_store_iface_get_accounts (account_store, accounts, TNY_ACCOUNT_STORE_IFACE_STORE_ACCOUNTS); 
    125  
    126         iterator = tny_list_iface_create_iterator (accounts); 
    127         next = tny_iterator_iface_has_first (iterator); 
    128  
    129         while (next) 
    130         { 
    131                 TnyStoreAccountIface *account = tny_iterator_iface_current (iterator); 
    132  
    133                 tny_account_tree_model_add (TNY_ACCOUNT_TREE_MODEL  
    134                         (mailbox_model), account); 
    135  
    136                 next = tny_iterator_iface_has_next (iterator); 
    137  
    138                 if (next) 
    139                         tny_iterator_iface_next (iterator); 
    140         } 
    141  
    142         g_object_unref (G_OBJECT (iterator)); 
    143         priv->current_accounts = accounts; 
     122        tny_account_store_iface_get_accounts (account_store, accounts, 
     123                TNY_ACCOUNT_STORE_IFACE_STORE_ACCOUNTS); 
    144124 
    145125        sortable = gtk_tree_model_sort_new_with_model (mailbox_model);