source: stylefunc.c @ c3ab155

barnowl_perlaimdebianowlrelease-1.10release-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>, 21 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: 16.8 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5void owl_stylefunc_basic(owl_fmtext *fm, owl_message *m)
6{
7  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
8  ZNotice_t *n;
9
10  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
11    n=owl_message_get_notice(m);
12
13    /* get the body */
14    body=owl_strdup(owl_message_get_body(m));
15    body=realloc(body, strlen(body)+30);
16
17    /* add a newline if we need to */
18    if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
19      strcat(body, "\n");
20    }
21   
22    /* do the indenting into indent */
23    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
24    owl_text_indent(indent, body, OWL_MSGTAB);
25   
26    /* edit the from addr for printing */
27    strcpy(frombuff, owl_message_get_sender(m));
28    ptr=strchr(frombuff, '@');
29    if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
30      *ptr='\0';
31    }
32   
33    /* set the message for printing */
34    owl_fmtext_append_normal(fm, OWL_TABSTR);
35   
36    if (owl_message_is_ping(m)) {
37      owl_fmtext_append_bold(fm, "PING");
38      owl_fmtext_append_normal(fm, " from ");
39      owl_fmtext_append_bold(fm, frombuff);
40      owl_fmtext_append_normal(fm, "\n");
41    } else if (owl_message_is_loginout(m)) {
42      char *ptr, host[LINE], tty[LINE];
43      int len;
44     
45      ptr=owl_zephyr_get_field(n, 1, &len);
46      strncpy(host, ptr, len);
47      host[len]='\0';
48      ptr=owl_zephyr_get_field(n, 3, &len);
49      strncpy(tty, ptr, len);
50      tty[len]='\0';
51
52      if (owl_message_is_login(m)) {
53        owl_fmtext_append_bold(fm, "LOGIN");
54      } else if (owl_message_is_logout(m)) {
55        owl_fmtext_append_bold(fm, "LOGOUT");
56      }
57      owl_fmtext_append_normal(fm, " for ");
58      ptr=short_zuser(owl_message_get_instance(m));
59      owl_fmtext_append_bold(fm, ptr);
60      owl_free(ptr);
61      owl_fmtext_append_normal(fm, " at ");
62      owl_fmtext_append_normal(fm, host);
63      owl_fmtext_append_normal(fm, " ");
64      owl_fmtext_append_normal(fm, tty);
65      owl_fmtext_append_normal(fm, "\n");
66    } else {
67      owl_fmtext_append_normal(fm, "From: ");
68      if (strcasecmp(owl_message_get_class(m), "message")) {
69        owl_fmtext_append_normal(fm, "Class ");
70        owl_fmtext_append_normal(fm, owl_message_get_class(m));
71        owl_fmtext_append_normal(fm, " / Instance ");
72        owl_fmtext_append_normal(fm, owl_message_get_instance(m));
73        owl_fmtext_append_normal(fm, " / ");
74      }
75      owl_fmtext_append_normal(fm, frombuff);
76      if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
77        owl_fmtext_append_normal(fm, " {");
78        owl_fmtext_append_normal(fm, owl_message_get_realm(m));
79        owl_fmtext_append_normal(fm, "} ");
80      }
81     
82      /* stick on the zsig */
83      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
84      owl_message_pretty_zsig(m, zsigbuff);
85      owl_fmtext_append_normal(fm, "    (");
86      owl_fmtext_append_ztext(fm, zsigbuff);
87      owl_fmtext_append_normal(fm, ")");
88      owl_fmtext_append_normal(fm, "\n");
89      owl_free(zsigbuff);
90     
91      /* then the indented message */
92      owl_fmtext_append_ztext(fm, indent);
93     
94      /* make personal messages bold for smaat users */
95      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
96        if (owl_message_is_personal(m)) {
97          owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
98        }
99      }
100    }
101   
102    owl_free(body);
103    owl_free(indent);
104  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
105    char *indent, *text, *zsigbuff, *foo;
106     
107    text=owl_message_get_body(m);
108   
109    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
110    owl_text_indent(indent, text, OWL_MSGTAB);
111    owl_fmtext_init_null(fm);
112    owl_fmtext_append_normal(fm, OWL_TABSTR);
113    owl_fmtext_append_normal(fm, "To: ");
114    foo=short_zuser(owl_message_get_recipient(m));
115    owl_fmtext_append_normal(fm, foo);
116    owl_free(foo);
117    owl_fmtext_append_normal(fm, "  (Zsig: ");
118   
119    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
120    owl_message_pretty_zsig(m, zsigbuff);
121    owl_fmtext_append_ztext(fm, zsigbuff);
122    owl_free(zsigbuff);
123   
124    owl_fmtext_append_normal(fm, ")");
125    owl_fmtext_append_normal(fm, "\n");
126    owl_fmtext_append_ztext(fm, indent);
127    if (text[strlen(text)-1]!='\n') {
128      owl_fmtext_append_normal(fm, "\n");
129    }
130   
131    owl_free(indent);
132  } else if (owl_message_is_type_aim(m)) {
133    char *indent;
134   
135    if (owl_message_is_loginout(m)) {
136      owl_fmtext_init_null(fm);
137      owl_fmtext_append_normal(fm, OWL_TABSTR);
138      if (owl_message_is_login(m)) {
139        owl_fmtext_append_bold(fm, "AIM LOGIN");
140      } else {
141        owl_fmtext_append_bold(fm, "AIM LOGOUT");
142      }
143      owl_fmtext_append_normal(fm, " for ");
144      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
145      owl_fmtext_append_normal(fm, "\n");
146    } else if (owl_message_is_direction_in(m)) {
147      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
148      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
149      owl_fmtext_init_null(fm);
150      owl_fmtext_append_bold(fm, OWL_TABSTR);
151      owl_fmtext_append_bold(fm, "AIM from ");
152      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
153      owl_fmtext_append_bold(fm, "\n");
154      owl_fmtext_append_bold(fm, indent);
155      if (indent[strlen(indent)-1]!='\n') {
156        owl_fmtext_append_normal(fm, "\n");
157      }
158      owl_free(indent);
159    } else if (owl_message_is_direction_out(m)) {
160      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
161      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
162      owl_fmtext_init_null(fm);
163      owl_fmtext_append_normal(fm, OWL_TABSTR);
164      owl_fmtext_append_normal(fm, "AIM sent to ");
165      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
166      owl_fmtext_append_normal(fm, "\n");
167      owl_fmtext_append_ztext(fm, indent);
168      if (indent[strlen(indent)-1]!='\n') {
169        owl_fmtext_append_normal(fm, "\n");
170      }
171      owl_free(indent);
172    }
173  } else if (owl_message_is_type_admin(m)) {
174    char *text, *header, *indent;
175   
176    text=owl_message_get_body(m);
177    header=owl_message_get_attribute_value(m, "adminheader");
178   
179    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
180    owl_text_indent(indent, text, OWL_MSGTAB);
181    owl_fmtext_init_null(fm);
182    owl_fmtext_append_normal(fm, OWL_TABSTR);
183    owl_fmtext_append_bold(fm, "OWL ADMIN ");
184    owl_fmtext_append_ztext(fm, header);
185    owl_fmtext_append_normal(fm, "\n");
186    owl_fmtext_append_ztext(fm, indent);
187    if (text[strlen(text)-1]!='\n') {
188      owl_fmtext_append_normal(fm, "\n");
189    }
190   
191    owl_free(indent);
192  }
193}
194
195void owl_stylefunc_default(owl_fmtext *fm, owl_message *m)
196{
197  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
198  ZNotice_t *n;
199
200  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
201    n=owl_message_get_notice(m);
202 
203    /* get the body */
204    body=owl_malloc(strlen(owl_message_get_body(m))+30);
205    strcpy(body, owl_message_get_body(m));
206   
207    /* add a newline if we need to */
208    if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
209      strcat(body, "\n");
210    }
211   
212    /* do the indenting into indent */
213    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
214    owl_text_indent(indent, body, OWL_MSGTAB);
215   
216    /* edit the from addr for printing */
217    strcpy(frombuff, owl_message_get_sender(m));
218    ptr=strchr(frombuff, '@');
219    if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
220      *ptr='\0';
221    }
222   
223    /* set the message for printing */
224    owl_fmtext_init_null(fm);
225    owl_fmtext_append_normal(fm, OWL_TABSTR);
226   
227    if (owl_message_is_ping(m) && owl_message_is_private(m)) {
228      owl_fmtext_append_bold(fm, "PING");
229      owl_fmtext_append_normal(fm, " from ");
230      owl_fmtext_append_bold(fm, frombuff);
231      owl_fmtext_append_normal(fm, "\n");
232    } else if (owl_message_is_loginout(m)) {
233      char *ptr, host[LINE], tty[LINE];
234      int len;
235     
236      ptr=owl_zephyr_get_field(n, 1, &len);
237      strncpy(host, ptr, len);
238      host[len]='\0';
239      ptr=owl_zephyr_get_field(n, 3, &len);
240      strncpy(tty, ptr, len);
241      tty[len]='\0';
242     
243      if (owl_message_is_login(m)) {
244        owl_fmtext_append_bold(fm, "LOGIN");
245      } else if (owl_message_is_logout(m)) {
246        owl_fmtext_append_bold(fm, "LOGOUT");
247      }
248      owl_fmtext_append_normal(fm, " for ");
249      ptr=short_zuser(n->z_class_inst);
250      owl_fmtext_append_bold(fm, ptr);
251      owl_free(ptr);
252      owl_fmtext_append_normal(fm, " at ");
253      owl_fmtext_append_normal(fm, host);
254      owl_fmtext_append_normal(fm, " ");
255      owl_fmtext_append_normal(fm, tty);
256      owl_fmtext_append_normal(fm, "\n");
257    } else {
258      owl_fmtext_append_normal(fm, owl_message_get_class(m));
259      owl_fmtext_append_normal(fm, " / ");
260      owl_fmtext_append_normal(fm, owl_message_get_instance(m));
261      owl_fmtext_append_normal(fm, " / ");
262      owl_fmtext_append_bold(fm, frombuff);
263      if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
264        owl_fmtext_append_normal(fm, " {");
265        owl_fmtext_append_normal(fm, owl_message_get_realm(m));
266        owl_fmtext_append_normal(fm, "} ");
267      }
268      if (n->z_opcode[0]!='\0') {
269        owl_fmtext_append_normal(fm, " [");
270        owl_fmtext_append_normal(fm, owl_message_get_opcode(m));
271        owl_fmtext_append_normal(fm, "] ");
272      }
273     
274      /* stick on the zsig */
275      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
276      owl_message_pretty_zsig(m, zsigbuff);
277      owl_fmtext_append_normal(fm, "    (");
278      owl_fmtext_append_ztext(fm, zsigbuff);
279      owl_fmtext_append_normal(fm, ")");
280      owl_fmtext_append_normal(fm, "\n");
281      owl_free(zsigbuff);
282     
283      /* then the indented message */
284      owl_fmtext_append_ztext(fm, indent);
285     
286      /* make private messages bold for smaat users */
287      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
288        if (owl_message_is_personal(m)) {
289          owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
290        }
291      }
292    }
293   
294    owl_free(body);
295    owl_free(indent);
296  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
297    char *indent, *text, *zsigbuff, *foo;
298   
299    text=owl_message_get_body(m);
300   
301    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
302    owl_text_indent(indent, text, OWL_MSGTAB);
303    owl_fmtext_init_null(fm);
304    owl_fmtext_append_normal(fm, OWL_TABSTR);
305    owl_fmtext_append_normal(fm, "Zephyr sent to ");
306    foo=short_zuser(owl_message_get_recipient(m));
307    owl_fmtext_append_normal(fm, foo);
308    owl_free(foo);
309    owl_fmtext_append_normal(fm, "  (Zsig: ");
310   
311    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
312    owl_message_pretty_zsig(m, zsigbuff);
313    owl_fmtext_append_ztext(fm, zsigbuff);
314    owl_free(zsigbuff);
315   
316    owl_fmtext_append_normal(fm, ")");
317    owl_fmtext_append_normal(fm, "\n");
318    owl_fmtext_append_ztext(fm, indent);
319    if (text[strlen(text)-1]!='\n') {
320      owl_fmtext_append_normal(fm, "\n");
321    }
322   
323    owl_free(indent);
324  } else if (owl_message_is_type_aim(m)) {
325    char *indent;
326   
327    if (owl_message_is_loginout(m)) {
328      owl_fmtext_init_null(fm);
329      owl_fmtext_append_normal(fm, OWL_TABSTR);
330      if (owl_message_is_login(m)) {
331        owl_fmtext_append_bold(fm, "AIM LOGIN");
332      } else {
333        owl_fmtext_append_bold(fm, "AIM LOGOUT");
334      }
335      owl_fmtext_append_normal(fm, " for ");
336      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
337      owl_fmtext_append_normal(fm, "\n");
338    } else if (owl_message_is_direction_in(m)) {
339      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
340      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
341      owl_fmtext_init_null(fm);
342      owl_fmtext_append_bold(fm, OWL_TABSTR);
343      owl_fmtext_append_bold(fm, "AIM from ");
344      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
345      owl_fmtext_append_bold(fm, "\n");
346      owl_fmtext_append_bold(fm, indent);
347      if (indent[strlen(indent)-1]!='\n') {
348        owl_fmtext_append_normal(fm, "\n");
349      }
350      owl_free(indent);
351    } else if (owl_message_is_direction_out(m)) {
352      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
353      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
354      owl_fmtext_init_null(fm);
355      owl_fmtext_append_normal(fm, OWL_TABSTR);
356      owl_fmtext_append_normal(fm, "AIM sent to ");
357      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
358      owl_fmtext_append_normal(fm, "\n");
359      owl_fmtext_append_ztext(fm, indent);
360      if (indent[strlen(indent)-1]!='\n') {
361        owl_fmtext_append_normal(fm, "\n");
362      }
363      owl_free(indent);
364    }
365  } else if (owl_message_is_type_admin(m)) {
366    char *text, *header, *indent;
367   
368    text=owl_message_get_body(m);
369    header=owl_message_get_attribute_value(m, "adminheader");
370   
371    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
372    owl_text_indent(indent, text, OWL_MSGTAB);
373    owl_fmtext_init_null(fm);
374    owl_fmtext_append_normal(fm, OWL_TABSTR);
375    owl_fmtext_append_bold(fm, "OWL ADMIN ");
376    owl_fmtext_append_ztext(fm, header);
377    owl_fmtext_append_normal(fm, "\n");
378    owl_fmtext_append_ztext(fm, indent);
379    if (text[strlen(text)-1]!='\n') {
380      owl_fmtext_append_normal(fm, "\n");
381    }
382   
383    owl_free(indent);
384  }
385}
386
387void owl_stylefunc_oneline(owl_fmtext *fm, owl_message *m)
388{
389  char *tmp;
390  char *baseformat="%s %-13.13s %-11.11s %-12.12s ";
391  char *sender, *recip;
392
393  sender=short_zuser(owl_message_get_sender(m));
394  recip=short_zuser(owl_message_get_recipient(m));
395 
396  if (owl_message_is_type_zephyr(m)) {
397    owl_fmtext_append_spaces(fm, OWL_TAB);
398    if (owl_message_is_login(m)) {
399      tmp=owl_sprintf(baseformat, "<", "LOGIN", "", sender);
400      owl_fmtext_append_normal(fm, tmp);
401      owl_fmtext_append_normal(fm, "\n");
402      owl_free(tmp);
403    } else if (owl_message_is_logout(m)) {
404      tmp=owl_sprintf(baseformat, "<", "LOGOUT", "", sender);
405      owl_fmtext_append_normal(fm, tmp);
406      owl_fmtext_append_normal(fm, "\n");
407      owl_free(tmp);
408    } else if (owl_message_is_ping(m)) {
409      tmp=owl_sprintf(baseformat, "<", "PING", "", sender);
410      owl_fmtext_append_normal(fm, tmp);
411      owl_fmtext_append_normal(fm, "\n");
412      owl_free(tmp);
413    } else {
414      if (owl_message_is_direction_in(m)) {
415        tmp=owl_sprintf(baseformat, "<", owl_message_get_class(m), owl_message_get_instance(m), sender);
416      } else if (owl_message_is_direction_out(m)) {
417        tmp=owl_sprintf(baseformat, ">", owl_message_get_class(m), owl_message_get_instance(m), recip);
418      } else {
419        tmp=owl_sprintf(baseformat, "-", owl_message_get_class(m), owl_message_get_instance(m), sender);
420      }
421      owl_fmtext_append_normal(fm, tmp);
422      if (tmp) owl_free(tmp);
423     
424      tmp=owl_strdup(owl_message_get_body(m));
425      owl_util_tr(tmp, '\n', ' ');
426      owl_fmtext_append_ztext(fm, tmp);
427      owl_fmtext_append_normal(fm, "\n");
428      if (tmp) owl_free(tmp);
429    }
430     
431    /* make personal messages bold for smaat users */
432    if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) &&
433        owl_message_is_personal(m) &&
434        owl_message_is_direction_in(m)) {
435      owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
436    }
437
438    owl_free(sender);
439    owl_free(recip);
440   
441  } else if (owl_message_is_type_aim(m)) {
442    owl_fmtext_append_spaces(fm, OWL_TAB);
443    if (owl_message_is_login(m)) {
444      tmp=owl_sprintf(baseformat, "<", "AIM LOGIN", "", owl_message_get_sender(m));
445      owl_fmtext_append_normal(fm, tmp);
446      owl_fmtext_append_normal(fm, "\n");
447      if (tmp) owl_free(tmp);
448    } else if (owl_message_is_logout(m)) {
449      tmp=owl_sprintf(baseformat, "<", "AIM LOGOUT", "", owl_message_get_sender(m));
450      owl_fmtext_append_normal(fm, tmp);
451      owl_fmtext_append_normal(fm, "\n");
452      if (tmp) owl_free(tmp);
453    } else {
454      if (owl_message_is_direction_in(m)) {
455        tmp=owl_sprintf(baseformat, "<", "AIM", "", owl_message_get_sender(m));
456        owl_fmtext_append_normal(fm, tmp);
457        if (tmp) owl_free(tmp);
458      } else if (owl_message_is_direction_out(m)) {
459        tmp=owl_sprintf(baseformat, ">", "AIM", "", owl_message_get_recipient(m));
460        owl_fmtext_append_normal(fm, tmp);
461        if (tmp) owl_free(tmp);
462      }
463     
464      tmp=owl_strdup(owl_message_get_body(m));
465      owl_util_tr(tmp, '\n', ' ');
466      owl_fmtext_append_normal(fm, tmp);
467      owl_fmtext_append_normal(fm, "\n");
468      if (tmp) owl_free(tmp);
469    }
470
471    /* make personal messages bold for smaat users */
472    if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
473      owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
474    }
475  } else if (owl_message_is_type_admin(m)) {
476    owl_fmtext_append_spaces(fm, OWL_TAB);
477    owl_fmtext_append_normal(fm, "< ADMIN                                        ");
478   
479    tmp=owl_strdup(owl_message_get_body(m));
480    owl_util_tr(tmp, '\n', ' ');
481    owl_fmtext_append_normal(fm, tmp);
482    owl_fmtext_append_normal(fm, "\n");
483    if (tmp) owl_free(tmp);
484  }
485
486}
Note: See TracBrowser for help on using the repository browser.