Changeset 399
- Timestamp:
- 05/27/06 12:43:53
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libtinymailui-gtk/tny-msg-header-list-model.c
r380 r399 39 39 gint length; 40 40 gint stamp; 41 42 guint last_nth; 43 GList *last_iter; 41 44 }; 42 45 … … 93 96 } 94 97 98 static GList* 99 g_list_travel_to_nth (GList *list, guint cur, guint nth) 100 { 101 if (cur == nth) 102 return list; 103 104 if (cur < nth) 105 while ((cur++ < nth) && list) 106 list = list->next; 107 else if (cur > nth) 108 while ((cur-- > nth) && list) 109 list = list->prev; 110 111 return list; 112 } 113 95 114 static gboolean 96 115 tny_msg_header_list_model_get_iter (GtkTreeModel *self, GtkTreeIter *iter, GtkTreePath *path) … … 103 122 104 123 g_mutex_lock (list_model->folder_lock); 105 106 headers = (GList*)tny_msg_folder_iface_get_headers (list_model->folder, FALSE);107 124 108 125 i = gtk_tree_path_get_indices (path)[0]; 109 list = g_list_nth (G_LIST (headers), i); 126 127 128 if (list_model->last_iter) 129 { /* This is a little speed hack */ 130 list_model->last_iter = g_list_travel_to_nth (list_model->last_iter, list_model->last_nth, i); 131 list_model->last_nth = i; 132 list = list_model->last_iter; 133 } else { 134 headers = (GList*)tny_msg_folder_iface_get_headers (list_model->folder, FALSE); 135 list_model->last_nth = i; 136 list = g_list_nth (G_LIST (headers), i); 137 list_model->last_iter = list; 138 } 139 110 140 111 141 if (G_UNLIKELY (i >= list_model->length)) … … 359 389 { 360 390 self->length = 0; 391 self->last_iter = NULL; 392 self->last_nth = 0; 361 393 362 394 return; … … 386 418 387 419 /* We have to unreference all */ 388 if (self->folder) { 420 if (self->folder) 421 { 389 422 headers = tny_msg_folder_iface_get_headers (self->folder, FALSE); 390 423 g_list_foreach ((GList*)headers, unref_header, NULL); … … 420 453 self->folder = NULL; 421 454 self->folder_lock = g_mutex_new (); 455 destroy_internal_list (self); 422 456 423 457 return; … … 443 477 g_mutex_lock (self->folder_lock); 444 478 479 destroy_internal_list (self); 480 445 481 headers = tny_msg_folder_iface_get_headers (folder, refresh); 446 482 … … 479 515 480 516 model = g_object_new (TNY_TYPE_MSG_HEADER_LIST_MODEL, NULL); 481 517 482 518 return GTK_TREE_MODEL (model); 483 519 }
