Changeset 556
- Timestamp:
- 07/05/06 11:39:03
- Files:
-
- trunk/libtinymailui-gtk/Makefile.am (modified) (1 diff)
- trunk/libtinymailui-gtk/tny-account-tree-model-iterator-priv.h (added)
- trunk/libtinymailui-gtk/tny-account-tree-model-iterator.c (added)
- trunk/libtinymailui-gtk/tny-account-tree-model-priv.h (added)
- trunk/libtinymailui-gtk/tny-account-tree-model.c (modified) (7 diffs)
- trunk/libtinymailui-gtk/tny-account-tree-model.h (modified) (2 diffs)
- trunk/tinymail/tny-summary-window.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libtinymailui-gtk/Makefile.am
r429 r556 20 20 tny-msg-header-view.h 21 21 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 \ 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-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 \ 35 38 tny-msg-header-view.c 36 39 trunk/libtinymailui-gtk/tny-account-tree-model.c
r550 r556 29 29 #include <tny-msg-folder-iface.h> 30 30 31 #include "tny-account-tree-model-priv.h" 32 31 33 static GObjectClass *parent_class = NULL; 32 34 35 typedef void (*treeaddfunc) (GtkTreeStore *tree_store, GtkTreeIter *iter, GtkTreeIter *parent); 33 36 34 37 static void … … 83 86 } 84 87 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 89 static void 90 tny_account_tree_model_add (TnyAccountTreeModel *self, TnyStoreAccountIface *account, treeaddfunc func) 95 91 { 96 92 GtkTreeStore *model = GTK_TREE_STORE (self); … … 101 97 TNY_STORE_ACCOUNT_FOLDER_TYPE_SUBSCRIBED); 102 98 103 gtk_tree_store_append(model, &name_iter, NULL);99 func (model, &name_iter, NULL); 104 100 105 101 gtk_tree_store_set (model, &name_iter, … … 135 131 tny_account_tree_model_finalize (GObject *object) 136 132 { 133 TnyAccountTreeModel *me = (TnyAccountTreeModel*) object; 134 135 g_mutex_free (me->iterator_lock); 136 me->iterator_lock = NULL; 137 137 138 (*parent_class->finalize) (object); 138 139 } … … 155 156 { 156 157 GtkTreeStore *store = (GtkTreeStore*) instance; 158 TnyAccountTreeModel *me = (TnyAccountTreeModel*) instance; 157 159 static GType types[] = { G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_POINTER }; 160 161 me->iterator_lock = g_mutex_new (); 158 162 159 163 gtk_tree_store_set_column_types (store, … … 163 167 } 164 168 169 170 171 static TnyIteratorIface* 172 tny_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 183 static void 184 tny_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 197 static void 198 tny_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 212 static guint 213 tny_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 227 static void 228 tny_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 265 static TnyListIface* 266 tny_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 287 static void 288 tny_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 302 static void 303 tny_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 } 165 315 166 316 GType … … 186 336 type = g_type_register_static (GTK_TYPE_TREE_STORE, "TnyAccountTreeModel", 187 337 &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); 188 347 } 189 348 trunk/libtinymailui-gtk/tny-account-tree-model.h
r549 r556 47 47 }; 48 48 49 struct _TnyAccountTreeModel50 {51 GtkTreeStore parent;52 };53 54 struct _TnyAccountTreeModelClass55 {56 GtkTreeStoreClass parent_class;57 };58 49 59 50 … … 61 52 TnyAccountTreeModel* tny_account_tree_model_new (void); 62 53 63 void tny_account_tree_model_add (TnyAccountTreeModel *self, TnyStoreAccountIface *account);64 65 54 G_END_DECLS 66 55 trunk/tinymail/tny-summary-window.c
r550 r556 101 101 { 102 102 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 */ 108 112 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)); 115 114 set_header_view_model (GTK_TREE_VIEW (priv->header_view), empty_model); 116 115 … … 121 120 } 122 121 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); 144 124 145 125 sortable = gtk_tree_model_sort_new_with_model (mailbox_model);
