git.y1.nz

fbui

Framebuffer-based graphical environment
download: https://git.y1.nz/archives/fbui.tar.gz
README | Files | Log | Refs

libfbui/MailCheck/main.c

      1 
      2 /*=========================================================================
      3  *
      4  * fbcheck, a POP3 mail checker for FBUI (in-kernel framebuffer UI)
      5  * Copyright (C) 2004 Zachary T Smith, fbui@comcast.net
      6  *
      7  * This module is free software; you can redistribute it and/or modify
      8  * it under the terms of the GNU General Public License as published by
      9  * the Free Software Foundation; either version 2 of the License, or
     10  * (at your option) any later version.
     11  *
     12  * This module is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  * GNU General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU General Public License
     18  * along with this module; if not, write to the Free Software
     19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
     20  *
     21  * (See the file COPYING in the main directory of this archive for
     22  * more details.)
     23  *
     24  *=======================================================================*/
     25 
     26 
     27 typedef unsigned long u32;
     28 #include <stdio.h>
     29 #include <sys/types.h>
     30 #include <sys/stat.h>
     31 #include <fcntl.h>
     32 #include <sys/ioctl.h>
     33 #include <linux/fb.h>
     34 #include <sys/mman.h>
     35 #include <unistd.h>
     36 #include <string.h>
     37 
     38 #include <linux/vt.h>
     39 #include <linux/input.h>
     40 
     41 #include "libfbui.h"
     42 
     43 
     44 int
     45 main(int argc, char** argv)
     46 {
     47 	Display *dpy;
     48 	Window *win;
     49 	Font *pcf = font_new ();
     50 	u32 fg,bg;
     51 	char *server, *user, *pass;
     52 
     53 	char tmp[300];
     54 	sprintf (tmp, "%s/.fbcheckrc", getenv("HOME"));
     55 	FILE *f = fopen (tmp,"r");
     56 	if (!f)
     57 		FATAL("cannot open configuration file (~/.fbcheckrc)");
     58 	if (!fgets (tmp, 300, f))
     59 		FATAL("cannot read configuration file (~/.fbcheckrc)");
     60 	server = strdup(tmp);
     61 	if (!fgets (tmp, 300, f))
     62 		FATAL("cannot read configuration file (~/.fbcheckrc)");
     63 	user = strdup(tmp);
     64 	if (!fgets (tmp, 300, f))
     65 		FATAL("cannot read configuration file (~/.fbcheckrc)");
     66 	pass = strdup(tmp);
     67 
     68 	if (!pcf_read (pcf, "timR10.pcf")) {
     69 		font_free (pcf);
     70 		FATAL ("cannot load font");
     71 	}
     72 
     73 	short line_height = pcf->ascent + pcf->descent;
     74 
     75 	fg = RGB_YELLOW;
     76 	bg = RGB_BROWN;
     77 
     78 	short win_w, win_h;
     79 	dpy = fbui_display_open ();
     80 	if (!dpy) 
     81 		FATAL ("cannot open display");
     82 
     83 	win = fbui_window_open (dpy, 150,50, &win_w, &win_h, 250, 50,
     84 		300, -1, 
     85 		&fg, &bg, 
     86 		"fbcheck", "", 
     87 		FBUI_PROGTYPE_LAUNCHER, false,false, -1,false, 
     88 		false, false, argc,argv);
     89 	if (!win) 
     90 		FATAL ("cannot create window");
     91 
     92 	time_t t0 = time(NULL);
     93 	time_t t = t0 + 999;
     94 	while (1) {
     95 		int total;
     96 		int need_redraw=0;
     97 		Event ev;
     98 
     99 		usleep(50000);
    100 
    101 		if ((t - t0) >= 60) {
    102 			total = checkmail (server,user,pass);
    103 			t0 = t = time(NULL);
    104 			need_redraw=1;
    105 		}
    106 
    107 		int err;
    108 		if (err = fbui_poll_event (dpy, &ev,
    109                                 FBUI_EVENTMASK_ALL - FBUI_EVENTMASK_KEY))
    110 		{
    111 			if (err != FBUI_ERR_NOEVENT)
    112 				fbui_print_error (err);
    113 			continue;
    114 		}
    115 printf ("%s got event %s\n", argv[0], fbui_get_event_name (ev.type));
    116 
    117 		int num = ev.type;
    118 
    119 		switch (num) {
    120 		case FBUI_EVENT_EXPOSE:
    121 			need_redraw=1;
    122 			break;
    123 		
    124 		case FBUI_EVENT_MOVE_RESIZE:
    125 			win_w = ev.width;
    126 			win_h = ev.height;
    127 			break;
    128 		
    129 		}
    130 
    131 		if (!need_redraw)
    132 			continue;
    133 
    134 		int underline = 0;
    135 		char text[200];
    136 		if (total < 0) {
    137 			sprintf (text, "Mailserver unreachable");
    138 		} else if (total > 0) {
    139 			sprintf (text, "Messages: <<%d>>", total);
    140 			underline = 1;
    141 		} else {
    142 			sprintf (text, "~ No messages ~");
    143 		}
    144 
    145 		short w,a,d;
    146 		font_string_dims(pcf,text,&w,&a,&d);
    147 printf ("mc str dims %d %d %d\n",w,a,d);
    148 
    149 		int x, y;
    150 		x = (win_w - w) / 2;
    151 		if (d < 0)
    152 			d = -d;
    153 		y = (win_h - (a+d)) / 2;
    154 
    155 		fbui_clear (dpy, win);
    156 		fbui_draw_string (dpy, win, pcf, x,y, text, fg);
    157 		if (underline)
    158 			fbui_draw_hline (dpy, win, x, x+w-1, 2 + y + pcf->ascent, fg);
    159 		fbui_flush (dpy, win);
    160 	}
    161 
    162 	fbui_window_close(dpy, win);
    163 	fbui_display_close (dpy);
    164 
    165 	free(server);
    166 	free(user);
    167 	free(pass);
    168 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.