source: view.c @ c7041b3

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since c7041b3 was f1e629d, checked in by Erik Nygren <nygren@mit.edu>, 21 years ago
New API for perl message formatting functions. Legacy variables are still supported for owl::format_msg and owl::receive_msg, but these functions are now also passed an owl::Message object which contains methods for accessing the contents of the message. See perlwrap.pm (and docs TBD) for the available methods. *** WARNING: The exact API for owl::Message has *** not yet stabilized. Added "style" command for creating new styles. Usage: style <name> perl <function_name> Added support for "show styles". Changed global style table from list to dictionary. Changed AIM password prompt from "Password:" to "AIM Password:". Messages are reformatted after a window resize to allow styles to take into account the width of the window. When perl throws an error, the message is put in the msgwin if possible. Added perl functions for: owl::getcurmsg() -- returns an owl::Message object for the active message in the current view. owl::getnumcols() -- returns the column width of the window owl::zephyr_getrealm() -- returns the zephyr realm owl::zephyr_getsender() -- returns the zephyr sender Made owl::COMMAND("foo"); be syntactic sugar for owl::command("COMMAND foo"); *** Is this a good or bad idea? *** This feature may be taken out before release. Added perlwrap.pm to contain perl code to be compiled into the binary. This is transformed into perlwrap.c by encapsulate.pl. Renamed readconfig.c to perlconfig.c and changed variables accordingly. Minor bugfixes in cmd.c and commands.c
  • Property mode set to 100644
File size: 3.4 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
15char *owl_view_get_name(owl_view *v)
16{
17  return(v->name);
18}
19
20/* if the message matches the filter then add to view */
21void owl_view_consider_message(owl_view *v, owl_message *m)
22{
23  if (owl_filter_message_match(v->filter, m)) {
24    owl_messagelist_append_element(&(v->ml), m);
25  }
26}
27
28/* remove all messages, add all the global messages that match the
29 * filter.
30 */
31void owl_view_recalculate(owl_view *v)
32{
33  int i, j;
34  owl_messagelist *gml;
35  owl_messagelist *ml;
36  owl_message *m;
37
38  gml=owl_global_get_msglist(&g);
39  ml=&(v->ml);
40
41  /* nuke the old list */
42  owl_list_free_simple((owl_list *) ml);
43  owl_messagelist_create(&(v->ml));
44
45  /* find all the messages we want */
46  j=owl_messagelist_get_size(gml);
47  for (i=0; i<j; i++) {
48    m=owl_messagelist_get_element(gml, i);
49    if (owl_filter_message_match(v->filter, m)) {
50      owl_messagelist_append_element(ml, m);
51    }
52  }
53}
54
55void owl_view_new_filter(owl_view *v, owl_filter *f)
56{
57  v->filter=f;
58  owl_view_recalculate(v);
59}
60
61void owl_view_set_style(owl_view *v, owl_style *s)
62{
63  v->style=s;
64}
65
66owl_style *owl_view_get_style(owl_view *v)
67{
68  return(v->style);
69}
70
71char *owl_view_get_style_name(owl_view *v) {
72  return(owl_style_get_name(v->style));
73}
74
75owl_message *owl_view_get_element(owl_view *v, int index)
76{
77  return(owl_messagelist_get_element(&(v->ml), index));
78}
79
80void owl_view_delete_element(owl_view *v, int index)
81{
82  owl_messagelist_delete_element(&(v->ml), index);
83}
84
85void owl_view_undelete_element(owl_view *v, int index)
86{
87  owl_messagelist_undelete_element(&(v->ml), index);
88}
89
90int owl_view_get_size(owl_view *v)
91{
92  return(owl_messagelist_get_size(&(v->ml)));
93}
94
95/* Returns the position in the view with a message closest
96 * to the passed msgid. */
97int owl_view_get_nearest_to_msgid(owl_view *v, int targetid)
98{
99  int i, bestdist=-1, bestpos=0, curid, curdist;
100
101  for (i=0; i<owl_view_get_size(v); i++) {
102    curid = owl_message_get_id(owl_view_get_element(v, i));
103    curdist = abs(targetid-curid);
104    if (bestdist<0 || curdist<bestdist) {
105      bestdist = curdist;
106      bestpos = i;
107    }
108  }
109  return (bestpos);
110}
111
112int owl_view_get_nearest_to_saved(owl_view *v)
113{
114  int cachedid;
115
116  cachedid=owl_filter_get_cachedmsgid(v->filter);
117  if (cachedid<0) return(0);
118  return (owl_view_get_nearest_to_msgid(v, cachedid));
119}
120
121/* saves the current message position in the filter so it can
122 * be restored later if we switch back to this filter. */
123void owl_view_save_curmsgid(owl_view *v, int curid)
124{
125  owl_filter_set_cachedmsgid(v->filter, curid);
126}
127
128/* fmtext should already be initialized */
129void owl_view_to_fmtext(owl_view *v, owl_fmtext *fm)
130{
131  owl_fmtext_append_normal(fm, "Name: ");
132  owl_fmtext_append_normal(fm, v->name);
133  owl_fmtext_append_normal(fm, "\n");
134
135  owl_fmtext_append_normal(fm, "Filter: ");
136  owl_fmtext_append_normal(fm, owl_filter_get_name(v->filter));
137  owl_fmtext_append_normal(fm, "\n");
138
139  owl_fmtext_append_normal(fm, "Style: ");
140  owl_fmtext_append_normal(fm, owl_style_get_name(v->style));
141  owl_fmtext_append_normal(fm, "\n");
142}
143
144char *owl_view_get_filtname(owl_view *v)
145{
146  return(owl_filter_get_name(v->filter));
147}
148
149void owl_view_free(owl_view *v)
150{
151  owl_list_free_simple((owl_list *) &(v->ml));
152  if (v->name) owl_free(v->name);
153}
Note: See TracBrowser for help on using the repository browser.