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