source: view.c @ 8f44c6b

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8f44c6b was 3a2daac, checked in by James M. Kretchmar <kretch@mit.edu>, 22 years ago
viewwin will now say "End" instead of "More" when at the end Added a debugging message indicating the result of topmsg calculations
  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[5f37310]1#include <stdlib.h>
[7d4fbcd]2#include "owl.h"
3
[1aee7d9]4static const char fileIdent[] = "$Id$";
5
[7d4fbcd]6void owl_view_create(owl_view *v, owl_filter *f) {
7  v->filter=f;
8  owl_messagelist_create(&(v->ml));
9  owl_view_recalculate(v);
10}
11
12void owl_view_consider_message(owl_view *v, owl_message *m) {
13  /* if the message matches the filter then add to view */
14  if (owl_filter_message_match(v->filter, m)) {
15    owl_messagelist_append_element(&(v->ml), m);
16  }
17}
18
19void owl_view_recalculate(owl_view *v) {
20  /* add all the global messages that match the filter */
21  int i, j;
22  owl_messagelist *gml;
23  owl_messagelist *ml;
24  owl_message *m;
25
26  gml=owl_global_get_msglist(&g);
27  ml=&(v->ml);
28
29  /* nuke the old list */
30  owl_list_free_simple((owl_list *) ml);
31  owl_messagelist_create(&(v->ml));
32
33  /* find all the messages we want */
34  j=owl_messagelist_get_size(gml);
35  for (i=0; i<j; i++) {
36    m=owl_messagelist_get_element(gml, i);
37    if (owl_filter_message_match(v->filter, m)) {
38      owl_messagelist_append_element(ml, m);
39    }
40  }
41}
42
43owl_message *owl_view_get_element(owl_view *v, int index) {
44  return(owl_messagelist_get_element(&(v->ml), index));
45}
46
47void owl_view_delete_element(owl_view *v, int index) {
48  owl_messagelist_delete_element(&(v->ml), index);
49}
50
51void owl_view_undelete_element(owl_view *v, int index) {
52  owl_messagelist_undelete_element(&(v->ml), index);
53}
54
55int owl_view_get_size(owl_view *v) {
56  return(owl_messagelist_get_size(&(v->ml)));
57}
58
[59cf91c]59/* Returns the position in the view with a message closest
60 * to the passed msgid. */
61int owl_view_get_nearest_to_msgid(owl_view *v, int targetid) {
62  int i, bestdist=-1, bestpos=0, curid, curdist;
63
64  for (i=0; i<owl_view_get_size(v); i++) {
65    curid = owl_message_get_id(owl_view_get_element(v, i));
66    curdist = abs(targetid-curid);
67    if (bestdist<0 || curdist<bestdist) {
68      bestdist = curdist;
69      bestpos = i;
70    }
71  }
[3a2daac]72  return (bestpos);
[59cf91c]73}
74
75int owl_view_get_nearest_to_saved(owl_view *v) {
[3a2daac]76  int cachedid;
77
78  cachedid=owl_filter_get_cachedmsgid(v->filter);
[59cf91c]79  if (cachedid<0) return(0);
[3a2daac]80  return (owl_view_get_nearest_to_msgid(v, cachedid));
[59cf91c]81}
82
83/* saves the current message position in the filter so it can
84 * be restored later if we switch back to this filter. */
85void owl_view_save_curmsgid(owl_view *v, int curid) {
86  owl_filter_set_cachedmsgid(v->filter, curid);
87}
88
[7d4fbcd]89char *owl_view_get_filtname(owl_view *v) {
90  return(owl_filter_get_name(v->filter));
91}
92
93void owl_view_free(owl_view *v) {
94  owl_list_free_simple((owl_list *) &(v->ml));
95}
Note: See TracBrowser for help on using the repository browser.