Changeset 1746

Show
Ignore:
Timestamp:
03/25/07 13:55:19
Author:
pvanhoof
Message:

Filling up the summary or headers view while downloading information is taking place

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1743 r1746  
     12007-03-25  Philip Van Hoof  <pvanhoof@gnome.org> 
     2 
     3        * Support for filling up the header view (a.k.a. the summary view) 
     4        with already or recently downloaded information while downloading is 
     5        taking place. Take a look at the demo user interface's code to learn 
     6        how to leverage this feature: You basically need to register the list 
     7        (which will for example be a TnyGtkHeaderListModel instance) with the 
     8        TnyFolderMonitor before launching the tny_folder_refresh_async method. 
     9 
     10        * This ain't an API change, but this new feature does make more 
     11        possible with the same API. It might also change behaviour a little 
     12        bit (although it shouldn't for the old-style of using the TnyFolderMonitor, 
     13        or at least not as far as I know and tested). 
     14 
    1152007-03-23  Philip Van Hoof  <pvanhoof@gnome.org> 
    216 
  • trunk/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c

    r1743 r1746  
    29772977        gboolean did_hack = FALSE; 
    29782978        gint hcnt = 0; 
     2979        CamelFolderChangeInfo *mchanges; 
    29792980 
    29802981        imap_folder->need_rescan = TRUE; 
     
    30813082                qsort (needheaders->pdata, needheaders->len, 
    30823083                        sizeof (void *), uid_compar); 
     3084 
     3085                mchanges = camel_folder_change_info_new (); 
    30833086 
    30843087                while (uid < needheaders->len)  
     
    31503153                                                for (r = curlen-1; r >= sequence -1; r--) 
    31513154                                                {  
    3152                                                         printf ("curlen=%d, r=%d, seq=%d\n", curlen, r, sequence); 
     3155                                                        g_warning ("Problem with your local summary store (too much), correcting: curlen=%d, r=%d, seq=%d\n", curlen, r, sequence); 
    31533156                                                        CamelMessageInfo *ri = g_ptr_array_index (folder->summary->messages, r); 
    31543157                                                        if (ri) { 
    3155  
    3156                                                                 /* CamelFolderChangeInfo *uchange = camel_folder_change_info_new (); 
    3157                                                                 camel_folder_change_info_remove_uid (uchange, camel_message_info_uid (mi)); 
    3158                                                                 if (camel_folder_change_info_changed (uchange)) 
    3159                                                                         camel_object_trigger_event (CAMEL_OBJECT (folder), "folder_changed", uchange); 
    3160                                                                 camel_folder_change_info_free (uchange); */ 
    3161  
     3158                                                                /* camel_folder_change_info_remove_uid (mchange, camel_message_info_uid (mi)); */ 
    31623159                                                                ((CamelMessageInfoBase*)ri)->flags |= CAMEL_MESSAGE_EXPUNGED; 
    31633160                                                                ((CamelMessageInfoBase*)ri)->flags |= CAMEL_MESSAGE_FREED; 
     
    31693166                                                { 
    31703167                                                        CamelMessageInfo *ni = camel_message_info_clone (mi); 
    3171                                                         if (ni) 
     3168                                                        if (ni) { 
     3169                                                                g_warning ("Problem with your local summary store (too few), correcting: curlen=%d, r=%d, seq=%d\n", curlen, r, sequence); 
    31723170                                                                camel_folder_summary_add (folder->summary, (CamelMessageInfo *)ni); 
     3171                                                                /* camel_folder_change_info_add_uid (mchanges, camel_message_info_uid (ni)); */ 
     3172                                                        } 
    31733173                                                } 
    31743174                                        } 
     
    31773177 
    31783178                                  camel_folder_summary_add (folder->summary, (CamelMessageInfo *)mi); 
    3179                                   camel_folder_change_info_add_uid (changes, camel_message_info_uid (mi)); 
     3179 
     3180                                  /* printf ("Change: %s!\n", camel_message_info_uid (mi)); */ 
     3181                                  camel_folder_change_info_add_uid (mchanges, camel_message_info_uid (mi)); 
    31803182                                   if ((mi->info.flags & CAMEL_IMAP_MESSAGE_RECENT)) 
    3181                                         camel_folder_change_info_recent_uid(changes, camel_message_info_uid (mi)); 
     3183                                        camel_folder_change_info_recent_uid(mchanges, camel_message_info_uid (mi)); 
    31823184                                } 
    31833185 
     
    32113213 
    32123214                } 
     3215 
     3216                 
     3217                if (camel_folder_change_info_changed (mchanges)) { 
     3218                        camel_object_trigger_event (CAMEL_OBJECT (folder), "folder_changed", mchanges); 
     3219                        /* printf ("Changes!\n"); */ 
     3220                } 
     3221                camel_folder_change_info_free (mchanges); 
     3222 
    32133223        } 
    32143224 
  • trunk/libtinymail-camel/tny-camel-folder.c

    r1737 r1746  
    134134        gboolean need_unread_sync; 
    135135 
     136        /* printf ("want changes: %s, have folder: %s\n",  
     137                priv->want_changes?"yes":"no", 
     138                priv->folder?"yes":"no"); 
     139 
    136140        if (!priv->want_changes) 
    137                 return; 
     141                return; */ 
    138142 
    139143        g_static_rec_mutex_lock (priv->folder_lock); 
     
    145149 
    146150        summary = priv->folder->summary; 
     151 
     152        /* printf ("%d added\n", info->uid_added?info->uid_added->len:-1); */ 
    147153 
    148154        for (i = 0; i< info->uid_added->len; i++) 
  • trunk/libtinymailui-gtk/tny-gtk-header-list-model.c

    r1740 r1746  
    9494        g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE); 
    9595 
    96         g_mutex_lock (list_model->folder_lock); 
    9796        g_static_rec_mutex_lock (list_model->iterator_lock); 
    9897 
     
    112111 
    113112        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    114         g_mutex_unlock (list_model->folder_lock); 
    115113 
    116114        return retval; 
     
    125123 
    126124        /* Return the path of an existing GtkTreeIter */ 
    127  
    128125        if  (!(iter->stamp == TNY_GTK_HEADER_LIST_MODEL (self)->stamp)) 
    129126                return NULL; 
    130127 
    131         g_mutex_lock (list_model->folder_lock); 
    132128        g_static_rec_mutex_lock (list_model->iterator_lock); 
    133129 
     
    136132        if (i < 0 || i >= list_model->items->len) { 
    137133                g_static_rec_mutex_unlock (list_model->iterator_lock); 
    138                 g_mutex_unlock (list_model->folder_lock); 
    139134                return NULL; 
    140135        } 
     
    144139 
    145140        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    146         g_mutex_unlock (list_model->folder_lock); 
    147141 
    148142        return tree_path; 
     
    234228                return; 
    235229 
    236         g_mutex_lock (list_model->folder_lock); 
    237230        g_static_rec_mutex_lock (list_model->iterator_lock); 
    238231 
     
    317310 
    318311        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    319         g_mutex_unlock (list_model->folder_lock); 
    320312 
    321313        return; 
     
    332324                return FALSE; 
    333325 
    334         g_mutex_lock (list_model->folder_lock); 
    335326        g_static_rec_mutex_lock (list_model->iterator_lock); 
    336327 
     
    347338 
    348339        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    349         g_mutex_unlock (list_model->folder_lock); 
    350340 
    351341        return retval; 
     
    368358           return the full length. */ 
    369359 
    370         g_mutex_lock (list_model->folder_lock); 
    371360        g_static_rec_mutex_lock (list_model->iterator_lock); 
    372361 
     
    375364 
    376365        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    377         g_mutex_unlock (list_model->folder_lock); 
    378366 
    379367        return retval; 
     
    389377                return FALSE; 
    390378 
    391         g_mutex_lock (list_model->folder_lock); 
    392379        g_static_rec_mutex_lock (list_model->iterator_lock); 
    393380 
     
    403390 
    404391        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    405         g_mutex_unlock (list_model->folder_lock); 
    406392 
    407393        return retval; 
     
    427413 
    428414 
     415typedef struct 
     416{ 
     417        TnyGtkHeaderListModel *self; 
     418        GtkTreePath *path; 
     419        GtkTreeIter iter; 
     420} notify_views_data_t; 
     421 
     422static gboolean 
     423notify_views (gpointer data) 
     424{ 
     425        notify_views_data_t *stuff = data; 
     426 
     427        gtk_tree_model_row_inserted (GTK_TREE_MODEL (stuff->self), stuff->path, &(stuff->iter)); 
     428        gtk_tree_path_free (stuff->path); 
     429        g_object_unref (G_OBJECT (stuff->self)); 
     430        g_slice_free (notify_views_data_t, data); 
     431 
     432        return FALSE; 
     433} 
     434 
    429435static void 
    430436tny_gtk_header_list_model_prepend (TnyList *self, GObject* item) 
     
    432438        TnyGtkHeaderListModel *me = (TnyGtkHeaderListModel*)self; 
    433439        GtkTreePath *path; 
    434         GtkTreeIter iter
     440        notify_views_data_t *stuff
    435441 
    436442        g_static_rec_mutex_lock (me->iterator_lock); 
    437443 
    438         path = gtk_tree_path_new (); 
    439         gtk_tree_path_append_index (path, 0); 
    440         iter.stamp = me->stamp; 
     444        stuff = g_slice_new (notify_views_data_t); 
     445        stuff->self = g_object_ref (G_OBJECT (self)); 
     446        stuff->path = gtk_tree_path_new (); 
     447        gtk_tree_path_append_index (stuff->path, 0); 
     448        stuff->iter.stamp = me->stamp; 
    441449 
    442450        /* Prepend something to the list */ 
    443  
    444451        g_object_ref (G_OBJECT (item)); 
    445452        g_ptr_array_add (me->items, item); 
    446         iter.user_data = (gpointer) (me->items->len - 1); 
    447  
    448         /* Letting the observers know about this (the GtkTreeView) */ 
    449         gtk_tree_model_row_inserted (GTK_TREE_MODEL (me), path, &iter); 
    450         gtk_tree_path_free (path); 
     453        stuff->iter.user_data = (gpointer) (me->items->len - 1); 
     454 
     455        /* Letting the model observers know about this (the GtkTreeViews). The  
     456         * g_timeout_add stuff keeps it possible to launch the prepender in a  
     457         * thread. Else wouldn't the GtkTreeViews like this. */ 
     458 
     459        if (stuff->path) 
     460                g_timeout_add (0, notify_views, stuff); 
     461        else { 
     462                g_object_unref (G_OBJECT (stuff->self)); 
     463                g_slice_free (notify_views_data_t, stuff); 
     464        } 
    451465 
    452466        g_static_rec_mutex_unlock (me->iterator_lock); 
     
    479493{ 
    480494        TnyGtkHeaderListModel *me = (TnyGtkHeaderListModel*)self; 
    481         GtkTreePath *path
     495        GtkTreePath *path = NULL
    482496        gint i; gboolean found = FALSE; 
    483497 
     
    502516                iter.user_data = (gpointer) i; 
    503517                path = tny_gtk_header_list_model_get_path (GTK_TREE_MODEL (me), &iter); 
     518                if (path) 
     519                { 
     520                        /* Letting the observers know about this (the GtkTreeView) */ 
     521                        gtk_tree_model_row_deleted (GTK_TREE_MODEL (me), path); 
     522                        gtk_tree_path_free (path); 
     523                } 
    504524                g_ptr_array_remove (me->items, item); 
    505                 /* Letting the observers know about this (the GtkTreeView) */ 
    506                 gtk_tree_model_row_deleted (GTK_TREE_MODEL (me), path); 
    507                 gtk_tree_path_free (path); 
    508         } 
     525        } 
     526 
     527        g_static_rec_mutex_unlock (me->iterator_lock); 
    509528 
    510529        g_object_unref (G_OBJECT (item)); 
    511530 
    512         g_static_rec_mutex_unlock (me->iterator_lock); 
    513531} 
    514532 
  • trunk/tests/c-demo/tny-demoui-summary-view.c

    r1677 r1746  
    264264        TnyDevice *device = tny_account_store_get_device (account_store); 
    265265 
    266         if (G_UNLIKELY (priv->account_store)) 
    267         { /* You typically set it once, so unlikely */ 
    268  
     266        if (priv->account_store) 
     267        {  
    269268                TnyDevice *odevice = tny_account_store_get_device (priv->account_store); 
    270269 
     
    434433{ 
    435434        TnyDemouiSummaryViewPriv *priv = user_data; 
     435        GtkTreeModel *select_model; 
    436436 
    437437        if (!cancelled) 
    438438        { 
    439                 GtkTreeView *header_view = GTK_TREE_VIEW (priv->header_view); 
    440                 GtkTreeModel *sortable; 
    441                 GtkTreeModel *select_model; 
    442                 GtkTreeModel *model = tny_gtk_header_list_model_new (); 
    443                 gboolean refresh = FALSE; 
    444  
    445 #ifndef ASYNC_HEADERS 
    446                 refresh = TRUE; 
    447 #endif 
    448  
    449                 tny_gtk_header_list_model_set_folder (TNY_GTK_HEADER_LIST_MODEL (model), folder, refresh); 
    450                 sortable = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model)); 
    451  
    452                 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable), 
    453                         TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_COLUMN, 
    454                         tny_gtk_header_list_model_received_date_sort_func,  
    455                         NULL, NULL); 
    456  
    457                 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable), 
    458                         TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_COLUMN, 
    459                         tny_gtk_header_list_model_sent_date_sort_func,  
    460                         NULL, NULL); 
    461  
    462                 g_mutex_lock (priv->monitor_lock); 
    463                 { 
    464  
    465                         if (priv->monitor) 
    466                         { 
    467                                 tny_folder_monitor_stop (priv->monitor); 
    468                                 g_object_unref (G_OBJECT (priv->monitor)); 
    469                         } 
    470  
    471                         priv->monitor = TNY_FOLDER_MONITOR (tny_folder_monitor_new (folder)); 
    472                         tny_folder_monitor_add_list (priv->monitor, TNY_LIST (model)); 
    473                         tny_folder_monitor_start (priv->monitor); 
    474                 } 
    475                 g_mutex_unlock (priv->monitor_lock); 
    476  
    477                 set_header_view_model (header_view, sortable); 
    478  
    479439                g_idle_add (cleanup_statusbar, priv); 
    480440 
     
    525485        GtkTreeIter iter; 
    526486        GtkTreeModel *model; 
     487        GtkTreeModel *hmodel; 
     488        GtkTreeView *header_view = GTK_TREE_VIEW (priv->header_view); 
     489        GtkTreeModel *sortable; 
     490        gboolean refresh = FALSE; 
     491 
     492#ifndef ASYNC_HEADERS 
     493        refresh = TRUE; 
     494#endif 
     495 
    527496 
    528497        if (gtk_tree_selection_get_selected (selection, &model, &iter)) 
     
    557526                        gtk_widget_show (GTK_WIDGET (priv->progress)); 
    558527                        gtk_widget_set_sensitive (GTK_WIDGET (priv->header_view), FALSE); 
    559                  
     528 
     529                        hmodel = tny_gtk_header_list_model_new (); 
     530                        tny_gtk_header_list_model_set_folder (TNY_GTK_HEADER_LIST_MODEL (hmodel), folder, FALSE); 
     531 
     532                        g_mutex_lock (priv->monitor_lock); 
     533                        { 
     534 
     535                                if (priv->monitor) 
     536                                { 
     537                                        tny_folder_monitor_stop (priv->monitor); 
     538                                        g_object_unref (G_OBJECT (priv->monitor)); 
     539                                } 
     540 
     541                                priv->monitor = TNY_FOLDER_MONITOR (tny_folder_monitor_new (folder)); 
     542                                tny_folder_monitor_add_list (priv->monitor, TNY_LIST (hmodel)); 
     543                                tny_folder_monitor_start (priv->monitor); 
     544                        } 
     545                        g_mutex_unlock (priv->monitor_lock); 
     546 
     547                        sortable = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (hmodel)); 
     548 
     549                        gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable), 
     550                                TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_COLUMN, 
     551                                tny_gtk_header_list_model_received_date_sort_func,  
     552                                NULL, NULL); 
     553 
     554                        gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable), 
     555                                TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_COLUMN, 
     556                                tny_gtk_header_list_model_sent_date_sort_func,  
     557                                NULL, NULL); 
     558 
     559                        set_header_view_model (header_view, sortable); 
     560 
    560561#ifdef ASYNC_HEADERS 
    561  
    562562                        tny_folder_refresh_async (folder,  
    563563                                refresh_current_folder,  
     
    566566                        refresh_current_folder (folder, FALSE, NULL, user_data); 
    567567#endif 
    568          
     568 
    569569                        g_object_unref (G_OBJECT (folder)); 
    570570                }