[7d4fbcd] | 1 | #include "owl.h" |
---|
| 2 | |
---|
[1aee7d9] | 3 | static const char fileIdent[] = "$Id$"; |
---|
| 4 | |
---|
[7d4fbcd] | 5 | void owl_view_create(owl_view *v, owl_filter *f) { |
---|
| 6 | v->filter=f; |
---|
| 7 | owl_messagelist_create(&(v->ml)); |
---|
| 8 | owl_view_recalculate(v); |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | void owl_view_consider_message(owl_view *v, owl_message *m) { |
---|
| 12 | /* if the message matches the filter then add to view */ |
---|
| 13 | if (owl_filter_message_match(v->filter, m)) { |
---|
| 14 | owl_messagelist_append_element(&(v->ml), m); |
---|
| 15 | } |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | void owl_view_recalculate(owl_view *v) { |
---|
| 19 | /* add all the global messages that match the filter */ |
---|
| 20 | int i, j; |
---|
| 21 | owl_messagelist *gml; |
---|
| 22 | owl_messagelist *ml; |
---|
| 23 | owl_message *m; |
---|
| 24 | |
---|
| 25 | gml=owl_global_get_msglist(&g); |
---|
| 26 | ml=&(v->ml); |
---|
| 27 | |
---|
| 28 | /* nuke the old list */ |
---|
| 29 | owl_list_free_simple((owl_list *) ml); |
---|
| 30 | owl_messagelist_create(&(v->ml)); |
---|
| 31 | |
---|
| 32 | /* find all the messages we want */ |
---|
| 33 | j=owl_messagelist_get_size(gml); |
---|
| 34 | for (i=0; i<j; i++) { |
---|
| 35 | m=owl_messagelist_get_element(gml, i); |
---|
| 36 | if (owl_filter_message_match(v->filter, m)) { |
---|
| 37 | owl_messagelist_append_element(ml, m); |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | owl_message *owl_view_get_element(owl_view *v, int index) { |
---|
| 43 | return(owl_messagelist_get_element(&(v->ml), index)); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | void owl_view_delete_element(owl_view *v, int index) { |
---|
| 47 | owl_messagelist_delete_element(&(v->ml), index); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | void owl_view_undelete_element(owl_view *v, int index) { |
---|
| 51 | owl_messagelist_undelete_element(&(v->ml), index); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | int owl_view_get_size(owl_view *v) { |
---|
| 55 | return(owl_messagelist_get_size(&(v->ml))); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | char *owl_view_get_filtname(owl_view *v) { |
---|
| 59 | return(owl_filter_get_name(v->filter)); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void owl_view_free(owl_view *v) { |
---|
| 63 | owl_list_free_simple((owl_list *) &(v->ml)); |
---|
| 64 | } |
---|