File: biff.c

package info (click to toggle)
xslideshow 3.1-7
  • links: PTS
  • area: non-free
  • in suites: sarge
  • size: 792 kB
  • ctags: 1,375
  • sloc: ansic: 14,006; makefile: 897; sh: 1
file content (221 lines) | stat: -rw-r--r-- 5,059 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
	biff.c - mail biff

	Author:   Susumu Shiohara (shiohara@tpp.epson.co.jp)

		Copyright 1993-1997 by Susumu Shiohara

				All Rights Reserved

*/

#include "xslideshow.h"
#include <sys/stat.h>

#if defined(__STDC__) || defined(__cplusplus)
# define P_(s) s
#else
# define P_(s) ()
#endif

extern void XSlideshowRemoveWorkProc P_((int));
extern int XSlideshowAddWorkProc P_((void (*)(), dword, caddr_t));

static Window biffWindow;
static off_t fsize=0;
static int biffWxd,biffWw,biffWx,biffWy;
static int biffProcId;
static int scrollBiffProcId = -1;
static int do_biff=False;
static int textwidth,textheight;
static char biffMessage[] = {"You have new mail .... "};
static char cbuf[MAX_TEXT_LEN];

/* Biff window */
void removeBiffWindow()
{
	if(biffWindow != (Window)0){
		XSlideshowRemoveWorkProc(scrollBiffProcId);
		scrollBiffProcId = -1;
		XUnmapWindow(theDisp,biffWindow);
	}
}

void replaceBiffWindow()
{
    if(biffWindow != (Window)0){
		biffWx  = windowWidth;
		biffWxd = windowWidth;	/* default x axis position */
		biffWy  = (windowHeight-textheight)/2;
    }
}

#if defined(__STDC__) || defined(__cplusplus)
void scrollBiff(caddr_t client_data)
#else
void scrollBiff(client_data)
caddr_t client_data;
#endif
{
	biffWx -= 2;			/* update x axis position */
	if(biffWx < -biffWw)
		biffWx = biffWxd;	/* reset x axis position */

	XRaiseWindow(theDisp,biffWindow);
	XMoveWindow(theDisp, biffWindow, biffWx, biffWy);
}

#if defined(__STDC__) || defined(__cplusplus)
void updateBiff(caddr_t client_data)
#else
void updateBiff(client_data)
caddr_t client_data;
#endif
{
struct stat fstatus;

	fstatus.st_size = 0;

	if((stat(cbuf,&fstatus))== -1) {
		removeBiffWindow();
		do_biff = False;
		return;
	}

	/* You have new mail */
	if(fstatus.st_size > fsize){

		fsize = fstatus.st_size;

		if(!do_biff){
    		if(app_data.verbose)
				fprintf(stderr,"xslideshow: You have new mail .... \n");

			biffWx = biffWxd;	/* reset xaxis position */
			XMoveWindow(theDisp, biffWindow, biffWx, biffWy);
			XMapWindow(theDisp,biffWindow);
			XRaiseWindow(theDisp,biffWindow);

			/* Scroll eatch 100 msec */
   			scrollBiffProcId = XSlideshowAddWorkProc(scrollBiff, 100000, 0);
			do_biff = True;
		}

	/* You have read the mail and remove it from the mail spool */
	}else if(fstatus.st_size < fsize){

		fsize = fstatus.st_size;
		if(do_biff){
    		removeBiffWindow();
			do_biff = False;
		}

	/* You have mail */
	}else if(fstatus.st_size == fsize && fsize > 0){

		if(!do_biff){
    		if(app_data.verbose) fprintf(stderr,"xslideshow: You have mail .... \n");
			biffWx = biffWxd;
			XMoveWindow(theDisp, biffWindow, biffWx, biffWy);
			XMapWindow(theDisp,biffWindow);
			XRaiseWindow(theDisp,biffWindow);

			/* Scroll eatch 100 msec */
   			scrollBiffProcId = XSlideshowAddWorkProc(scrollBiff, 100000, 0);
			do_biff = True;
		}

	}
}

void initBiff()
{
Pixmap pic;
int d_h,f_a,f_d,len;
XCharStruct overall;
XGCValues gcv;
GC gc;
XSetWindowAttributes xswa;
struct stat fstatus;
char *user;

	/* Get user login name */
	if((user = (char *)getlogin()) == NULL)
		if((user = (char *)getenv("USER")) == NULL)
			return;

	/* Get mail spool path */
	strcpy(cbuf,app_data.mail_spool);
	if((len = strlen(cbuf)) == 0)
		return;	/* You have no mail spool */

	if(cbuf[len-1] != '/')
		strcat(cbuf,"/");
	strcat(cbuf,user);

	if(app_data.verbose)
		fprintf(stderr,"xslideshow: mail spool is %s\n",cbuf);
	
	/* Check if mail is exist */
	if((stat(cbuf,&fstatus)) == 0)
	    fsize=fstatus.st_size;
	
	/* Get text and font information */
	XTextExtents(
				app_data.font,
				biffMessage, strlen(biffMessage),
				&d_h, &f_a, &f_d, &overall );

	textwidth = (overall.lbearing<0 ? -overall.lbearing : overall.lbearing) + overall.rbearing;
	textheight = overall.descent+overall.ascent;

	/* Create the biff message window */
	biffWindow = XCreateSimpleWindow(
								theDisp,
								theWindow,
								windowWidth,
								(windowHeight + textheight) / 2,
								textwidth,
								textheight,
								0, dbcol,dbcol );

	biffWw  = textwidth;
	biffWx  = windowWidth;
	biffWxd = windowWidth;	/* default x axis position */
	biffWy  = (windowHeight - textheight) / 2;

	xswa.override_redirect = True;
	XChangeWindowAttributes(theDisp,biffWindow,CWOverrideRedirect,&xswa);

	pic = XCreatePixmap(
					theDisp,
					biffWindow,
					textwidth,
					textheight,
					DefaultDepth(theDisp,theScreenNumber) );

	gcv.function=GXcopy;
	gcv.foreground=dbcol;
	gc = XCreateGC(theDisp,pic,GCForeground | GCFunction,&gcv);
	XFillRectangle(theDisp,pic,gc,0,0,textwidth,textheight);
	XFreeGC(theDisp,gc);

	/* Draw biff message string */
	XDrawImageString(
					theDisp,
					pic,
					fontGC,
					(overall.lbearing < 0 ? -overall.lbearing : overall.lbearing),
					overall.ascent,
					biffMessage, strlen(biffMessage) );

	XSetWindowBackgroundPixmap(theDisp,biffWindow,pic);
	XClearWindow(theDisp,biffWindow);

	XFreePixmap(theDisp,pic);
	XLowerWindow(theDisp,biffWindow);

	/* Exec updateBiff() after 1 sec */
	biffProcId = XSlideshowAddWorkProc(updateBiff, 1000000, 0);
}