rework lists
[rmail.git] / src / utils / test_header_osd.c
blob117b1f6d0087894b5897453029ef4da3c6f0f010
1 #define _BSD_SOURCE
3 #include <stdio.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include <errno.h>
7 #include <fcntl.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
12 #include <X11/Xlib.h>
13 #include <X11/Xutil.h>
14 #include <X11/Xatom.h>
15 #include <X11/Xft/Xft.h>
17 #include "string_utils.h"
18 #include "file_utils.h"
19 #include "rfc5322.h"
20 #include "list.h"
21 #include "md5_utils.h"
22 #include "osd.h"
23 #include "icons_utils.h"
24 #include "mail.h"
26 static struct mail_entry mail;
28 void parse_file(const char *filename)
30 FILE *fh;
32 fh = fopen(filename, "r");
33 if (!fh)
34 return;
36 parse_mail_header(fh, &mail.hdr);
38 fclose(fh);
41 static void print_mail(struct mail_entry *mail)
43 if (!mail)
44 return;
46 print_mail_header(&mail->hdr);
49 void display_osd(int argc, char **argv)
51 struct notify_object no;
53 char *icon = NULL;
55 Display *dpy;
56 XEvent e;
58 int running = 1;
60 /* Open connection with the server */
61 dpy = XOpenDisplay(NULL);
62 if (dpy == NULL) {
63 fprintf(stderr, "Cannot open display\n");
64 return;
67 icon = icon_get_path((char *) mail.hdr.addr_md5);
69 osd_init(dpy, &no, mail.hdr.from, mail.hdr.subject, icon);
70 #if 0
71 if (osd_new_frame(argc, argv, &no)) {
72 goto out;
74 #endif
76 /* Select kind of events we are interested in */
77 XSelectInput(no.frame.display, no.frame.win,
78 ExposureMask | KeyPressMask | ButtonPressMask);
80 /* Create OSD object */
81 if (osd_new_notify_object(argc, argv, &no)) {
82 goto out;
85 /* Map (show) the window */
86 XMapWindow(no.frame.display, no.frame.win);
88 /* event loop */
89 while (running) {
90 XNextEvent(no.frame.display, &e);
92 switch (e.type) {
93 case Expose:
94 /* Draw or redraw the window */
95 osd_show_notify_object(&no);
96 break;
98 /* Exit on key press or mouse button press */
99 case KeyPress:
100 case ButtonPress:
101 running = 0;
102 break;
106 osd_delete_notify_object(&no);
108 out:
109 icon_free_path(icon);
111 /* Close connection to server */
112 XCloseDisplay(no.frame.display);
115 int main(int argc, char **argv)
117 const char *file;
119 if (argc < 2) {
120 fprintf(stderr, "%s <file>\n", argv[0]);
121 return -1;
124 file = argv[1];
126 if (file_type(file))
127 return -1;
129 parse_file(file);
131 print_mail(&mail);
133 display_osd(argc, argv);
135 return 0;