source: view.c @ c3ab155

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since c3ab155 was c3ab155, checked in by James M. Kretchmar <kretch@mit.edu>, 17 years ago
Really use just one view now, named 'main' and recalculate messages when its filter is changed. This is in preperation for other design changes Added the 'default_style' variable Added the 'toggle-oneline' command the 'o' key is bound to 'toggle-oneline'
  • Property mode set to 100644
File size: 2.7 KB
Line 
1#include <stdlib.h>
2#include "owl.h"
3
4static const char fileIdent[] = "$Id$";
5
6void owl_view_create(owl_view *v, char *name, owl_filter *f, owl_style *s)
7{
8  v->name=owl_strdup(name);
9  v->filter=f;
10  v->style=s;
11  owl_messagelist_create(&(v->ml));
12  owl_view_recalculate(v);
13}
14
15
16/* if the message matches the filter then add to view */
17void owl_view_consider_message(owl_view *v, owl_message *m)
18{
19  if (owl_filter_message_match(v->filter, m)) {
20    owl_messagelist_append_element(&(v->ml), m);
21  }
22}
23
24/* remove all messages, add all the global messages that match the
25 * filter.
26 */
27void owl_view_recalculate(owl_view *v)
28{
29  int i, j;
30  owl_messagelist *gml;
31  owl_messagelist *ml;
32  owl_message *m;
33
34  gml=owl_global_get_msglist(&g);
35  ml=&(v->ml);
36
37  /* nuke the old list */
38  owl_list_free_simple((owl_list *) ml);
39  owl_messagelist_create(&(v->ml));
40
41  /* find all the messages we want */
42  j=owl_messagelist_get_size(gml);
43  for (i=0; i<j; i++) {
44    m=owl_messagelist_get_element(gml, i);
45    if (owl_filter_message_match(v->filter, m)) {
46      owl_messagelist_append_element(ml, m);
47    }
48  }
49}
50
51void owl_view_new_filter(owl_view *v, owl_filter *f)
52{
53  v->filter=f;
54  owl_view_recalculate(v);
55}
56
57void owl_view_set_style(owl_view *v, owl_style *s)
58{
59  v->style=s;
60}
61
62owl_message *owl_view_get_element(owl_view *v, int index)
63{
64  return(owl_messagelist_get_element(&(v->ml), index));
65}
66
67void owl_view_delete_element(owl_view *v, int index)
68{
69  owl_messagelist_delete_element(&(v->ml), index);
70}
71
72void owl_view_undelete_element(owl_view *v, int index)
73{
74  owl_messagelist_undelete_element(&(v->ml), index);
75}
76
77int owl_view_get_size(owl_view *v)
78{
79  return(owl_messagelist_get_size(&(v->ml)));
80}
81
82/* Returns the position in the view with a message closest
83 * to the passed msgid. */
84int owl_view_get_nearest_to_msgid(owl_view *v, int targetid)
85{
86  int i, bestdist=-1, bestpos=0, curid, curdist;
87
88  for (i=0; i<owl_view_get_size(v); i++) {
89    curid = owl_message_get_id(owl_view_get_element(v, i));
90    curdist = abs(targetid-curid);
91    if (bestdist<0 || curdist<bestdist) {
92      bestdist = curdist;
93      bestpos = i;
94    }
95  }
96  return (bestpos);
97}
98
99int owl_view_get_nearest_to_saved(owl_view *v)
100{
101  int cachedid;
102
103  cachedid=owl_filter_get_cachedmsgid(v->filter);
104  if (cachedid<0) return(0);
105  return (owl_view_get_nearest_to_msgid(v, cachedid));
106}
107
108/* saves the current message position in the filter so it can
109 * be restored later if we switch back to this filter. */
110void owl_view_save_curmsgid(owl_view *v, int curid)
111{
112  owl_filter_set_cachedmsgid(v->filter, curid);
113}
114
115char *owl_view_get_filtname(owl_view *v)
116{
117  return(owl_filter_get_name(v->filter));
118}
119
120void owl_view_free(owl_view *v)
121{
122  owl_list_free_simple((owl_list *) &(v->ml));
123  if (v->name) owl_free(v->name);
124}
Note: See TracBrowser for help on using the repository browser.