File: xpostit.c

package info (click to toggle)
xpostitplus 2.3.1-10
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 464 kB
  • ctags: 661
  • sloc: ansic: 4,831; makefile: 527; sh: 70
file content (306 lines) | stat: -rw-r--r-- 8,346 bytes parent folder | download | duplicates (3)
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#ifndef lint
static char	*RCSid = "$Id: xpostit.c,v 2.0 1995/03/27 18:56:22 mjhammel Exp $";
#endif

/*
 * xpostit.c - Post-It Notes for the X Window System.
 *
 * Based on an X10R4 application.  This one is for X11R4 and uses the
 * Xt toolkit and the Athena widgets.
 *
 * David A. Curry
 * SRI International
 * 333 Ravenswood Avenue
 * Menlo Park, CA 94025
 * davy@itstd.sri.com
 *
 * Modified by
 * Michael J. Hammel (03/01/95)
 * Contractor
 * 1150 Inca St. TH 70
 * Denver, CO 80204
 * mjhammel@csn.org
 *
 * $Log: xpostit.c,v $
 * Revision 2.0  1995/03/27  18:56:22  mjhammel
 * Initial update to 2.0
 *
 *
 * Revision 1.2  90/06/14  11:21:24  davy
 * Ported to X11 Release 4.
 * 
 * Revision 1.1  90/06/13  09:48:51  davy
 * Initial revision
 * 
 */
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/Xaw/SimpleMenu.h>
#include <signal.h>
#include <stdio.h>

#include "xpostit.h"
#include "version.h"

/*
 * Command line options and the resources they set.
 */
static XrmOptionDescRec options[] = {
    { "-bs",	".bufSize",		XrmoptionSepArg,	NULL },
    { "-dir",	".noteDir",		XrmoptionSepArg,	NULL },
    { "-interval",	".interval",	XrmoptionSepArg,	NULL },
    { "-sb",	".scrollBar",		XrmoptionNoArg,		"true" },
    { "-sv",	".saveNotes",		XrmoptionNoArg,		"true" },
    { "-c",	".compatibility",	XrmoptionNoArg,		"true" },
    { "-nw",	".nameWidth",		XrmoptionSepArg,	NULL },
    { "-ns",	".noSave",		XrmoptionNoArg,		"true" },
    { "-na",	".noAlarm",		XrmoptionNoArg,		"true" },
    { "-help",	".help",		XrmoptionNoArg,		"true" },
    { "-version",	".version",		XrmoptionNoArg,		"true" },
    { "-?",	".help",		XrmoptionNoArg,		"true" },
    { "-ao",	".anchorOffset",	XrmoptionSepArg,	NULL },
    { "-tmpdir",	".tmpDir",	XrmoptionSepArg,	NULL },
    { "-printcmd",	".printCmd",	XrmoptionSepArg,	NULL },
    { "-calendarcmd",	".calendarCmd",	XrmoptionSepArg,	NULL },
    { "-emailcmd",	".emailCmd",	XrmoptionSepArg,	NULL },
    { "-homedir",	".homeDir",	XrmoptionSepArg,	NULL },
};

/*
 * Fallback resources.
 */
static String fallback_resources[] = {
#include "app_defaults.h"
    NULL
};
	
/*
 * Resources we maintain besides those maintained by the toolkit.
 */
static XtResource resources[] = {
#define offset(field)	XtOffset(AppResPtr,field)
    { "bufSize", "BufSize", XtRInt, sizeof(int),
      offset(buf_size), XtRImmediate, (caddr_t) DefaultBufSize },
    { "noteDir", "NoteDir", XtRString, sizeof(String),
      offset(note_dir), XtRString, DefaultNoteDir },
    { "interval", "Interval", XtRInt, sizeof(int),
      offset(interval), XtRImmediate, (caddr_t)DefaultInterval },
    { "saveNotes", "SaveNotes", XtRBoolean, sizeof(Boolean),
      offset(save_notes), XtRImmediate, (caddr_t) False },
    { "scrollBar", "Scroll", XtRBoolean, sizeof(Boolean),
      offset(scroll_bar), XtRImmediate, (caddr_t) False },
    { "compatibility", "Compatibility", XtRBoolean, sizeof(Boolean),
      offset(compatibility), XtRImmediate, (caddr_t) False },
    { "nameWidth", "NameWidth", XtRInt, sizeof(int),
      offset(name_width), XtRImmediate, (caddr_t) DefaultNameWidth },
    { "noSave", "NoSave", XtRBoolean, sizeof(Boolean),
      offset(nosave), XtRImmediate, (caddr_t) False },
    { "noAlarm", "NoAlarm", XtRBoolean, sizeof(Boolean),
      offset(noalarm), XtRImmediate, (caddr_t) False },
    { "help", "Help", XtRBoolean, sizeof(Boolean),
      offset(help), XtRImmediate, (caddr_t) False },
    { "version", "Version", XtRBoolean, sizeof(Boolean),
      offset(version), XtRImmediate, (caddr_t) False },
    { "anchorOffset", "AnchorOffset", XtRInt, sizeof(int),
      offset(anchor_offset), XtRImmediate, (caddr_t) DefaultAnchorOffset },
    { "tmpDir", "TmpDir", XtRString, sizeof(String),
      offset(tmp_dir), XtRString, (caddr_t) DefaultTmpDir },
    { "printCmd", "PrintCmd", XtRString, sizeof(String),
      offset(print_cmd), XtRString, (caddr_t) DefaultPrintCmd },
    { "calendarCmd", "CalendarCmd", XtRString, sizeof(String),
      offset(calendar_cmd), XtRString, (caddr_t) DefaultCalendarCmd },
    { "emailCmd", "EmailCmd", XtRString, sizeof(String),
      offset(email_cmd), XtRString, (caddr_t) DefaultEmailCmd },
    { "homeDir", "HomeDir", XtRString, sizeof(String),
      offset(home_dir), XtRString, NULL },
#undef offset
};


AppRes	app_res;		/* xpostit application resources	*/
Widget	toplevel;		/* top level application shell widget	*/
Screen	*screen;		/* pointer to the screen of the display	*/
Display	*display;		/* pointer to the display we're on	*/
XtAppContext appcontext;	/* application context			*/
int curr_screenx, curr_screeny; /* size of current screen */
XtIntervalId timer;		/* used for auto-save feature */
XtIntervalId alarm_timer;	/* used for alarms feature */

unsigned long timer_interval; 	/* auto-save interval */
unsigned long alarm_interval; 	/* alarm check interval */

static Atom wm_delete_window;
static Atom wm_protocols;

void WMProtocols(w, ev, params, n)
	Widget	w;
	XEvent	*ev;
	String	*params;
	Cardinal	*n;
{
	if (ev->type == ClientMessage &&
			ev->xclient.message_type == wm_protocols &&
			ev->xclient.data.l[0] == wm_delete_window) {

		ByeBye();
	}
}

static XtActionsRec actions[] = {
	{ "WMProtocols", WMProtocols }
};


void
main(argc, argv)
char **argv;
int argc;
{
	char *appname;
	/* char *rindex();
	 */
	Boolean setsigs = False;

	/*
	 * Ignore signals for now, but record whether they were
	 * already ignored or not so we can catch them later if
	 * need be.
	 */
	if ((signal(SIGQUIT, SIG_IGN) != SIG_IGN) &&
	    (signal(SIGINT, SIG_IGN) != SIG_IGN))
		setsigs = True;

	/*
	 * Get application name.
	 */
	if ((appname = rindex(*argv, '/')) == NULL)
		appname = *argv;
	else
		appname++;

	/*
	 * Initialize the toolkit and create an application shell.
	 */
	toplevel = XtAppInitialize(&appcontext, PostItNoteClass, options,
			XtNumber(options), &argc, argv, fallback_resources,
			NULL, 0);

	display = XtDisplay(toplevel);
	screen = DefaultScreenOfDisplay(display);
	curr_screenx = HeightOfScreen(screen);
	curr_screeny = WidthOfScreen(screen);

	/*
	 * If we need to handle keyboard signals, do it now.
	 */
	if (setsigs) {
		signal(SIGQUIT, ByeBye);
		signal(SIGINT, ByeBye);
	}

	/*
	 * Always handle these.
	 */
	signal(SIGTERM, ByeBye);
	signal(SIGHUP, ByeBye);

	/*
	 * Send X errors to the exit routine.
	 */
	XSetErrorHandler((XErrorHandler) ByeBye);

	/*
	 * Now get any resources we're interested in.
	 */
	XtGetApplicationResources(toplevel, &app_res, resources,
				  XtNumber(resources), (ArgList)argv, (Cardinal)argc);

	XtAppAddActions (appcontext, actions, XtNumber (actions));

	/*
	 * if the user requested help, provide it
	 */
	if ( app_res.help )
	{
		printf( USAGE );
		exit ( 0 );
	}
	/*
	 * if the user requested the version, provide it
	 */
	if ( app_res.version )
	{
		printf( "xpostit+ v%s\n", VERSION );
		printf( "Copyright 1994-1996 Michael J. Hammel\n\n");
		exit ( 0 );
	}
 
	/*
	 * Construct the path to the directory notes are
	 * stored in.
	 */
	SetNoteDir();

	/*
	 * Create the plaid, menu, and list widgets.
	 */
	CreatePlaidWidget();
	CreateMenuWidget();

	/*
	 * Let the top level shell know about the menus.
	 */
	XawSimpleMenuAddGlobalActions(appcontext);
	XtRealizeWidget(menuwidget);

	/*
	 * Realize the top level and flush the server, which will
	 * let the user position the plaid window and map it.
	 */
	XtRealizeWidget(toplevel);
	XFlush(display);

	/*
	 * Load the notes the user has saved, and create widgets
	 * for them.
	 */
	LoadSavedNotes();

	/*
	 * Start the autosave timer, unless requested not to
	 */
	if ( !app_res.nosave )
	{
		timer_interval = app_res.interval * 60 * 1000;
		timer = XtAppAddTimeOut (
				XtWidgetToApplicationContext(toplevel),
				timer_interval,
				AutoSave,
				NULL );
	}

	/*
	 * Start the alarm timer (once a minute)
	 */
	if ( !app_res.noalarm )
	{
		alarm_interval = 60 * 1000;
		alarm_timer = XtAppAddTimeOut (
			XtWidgetToApplicationContext(toplevel),
			alarm_interval,
			AlarmCheck,
			NULL );
	}

	wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW",
		False);
	wm_protocols = XInternAtom(XtDisplay(toplevel), "WM_PROTOCOLS", False);
	(void) XSetWMProtocols(XtDisplay(toplevel), XtWindow(toplevel),
		&wm_delete_window, 1);

	/*
	 * Never returns.
	 */
	XtAppMainLoop(appcontext);
}