1 | /* |
---|
2 | * xquota - X window system quota display program. |
---|
3 | * |
---|
4 | * $Athena: widgets.c,v 1.3 89/03/28 16:43:36 kit Locked $ |
---|
5 | * |
---|
6 | * Copyright 1989 Massachusetts Institute of Technology |
---|
7 | * |
---|
8 | * Permission to use, copy, modify, and distribute this software and its |
---|
9 | * documentation for any purpose and without fee is hereby granted, provided |
---|
10 | * that the above copyright notice appear in all copies and that both that |
---|
11 | * copyright notice and this permission notice appear in supporting |
---|
12 | * documentation, and that the name of M.I.T. not be used in advertising or |
---|
13 | * publicity pertaining to distribution of the software without specific, |
---|
14 | * written prior permission. M.I.T. makes no representations about the |
---|
15 | * suitability of this software for any purpose. It is provided "as is" |
---|
16 | * without express or implied warranty. |
---|
17 | * |
---|
18 | * Author: Chris D. Peterson, MIT Project Athena |
---|
19 | * Created: March 5, 1989 |
---|
20 | */ |
---|
21 | |
---|
22 | #if ( !defined(lint) && !defined(SABER)) |
---|
23 | static char rcs_version[] = "$Athena: widgets.c,v 1.3 89/03/28 16:43:36 kit Locked $"; |
---|
24 | #endif |
---|
25 | |
---|
26 | #include <stdio.h> |
---|
27 | #include <X11/Intrinsic.h> |
---|
28 | #include <X11/StringDefs.h> |
---|
29 | |
---|
30 | #include <X11/Xaw/AsciiText.h> |
---|
31 | #include <X11/Xaw/Command.h> |
---|
32 | #include <X11/Xaw/Label.h> |
---|
33 | #include <X11/Xaw/Scrollbar.h> |
---|
34 | #include <X11/Shell.h> |
---|
35 | #include <X11/Xaw/Paned.h> |
---|
36 | |
---|
37 | #include "xquota.h" |
---|
38 | |
---|
39 | static void CheckProc(), DoneProc(), QuitProc(), TopHelpProc(); |
---|
40 | static void FlipColors(), TimeOutProc(), PopupHelpProc(), KillHelpProc(); |
---|
41 | static void CreateButtonPane(), CreateQuotaDisplay(); |
---|
42 | static void QuitAction(), PopInfoAction(), QuotaCheckAction(); |
---|
43 | static void PrintHelpAction(); |
---|
44 | static void LoadApplicationResources(); |
---|
45 | static Widget CreateHelpWidget(); |
---|
46 | static void ShowTopHelp(), ShowPopupHelp(); |
---|
47 | |
---|
48 | extern Info info; /* external for action proc only. */ |
---|
49 | |
---|
50 | #define Offset(field) (XtOffset(Info *, field)) |
---|
51 | |
---|
52 | static XtResource quota_resources[] = { |
---|
53 | {"warning", "Warning", XtRInt, sizeof(int), |
---|
54 | Offset(warn), XtRImmediate, (caddr_t) DEFAULT_WARNING}, |
---|
55 | {"update", "Update", XtRInt, sizeof(int), |
---|
56 | Offset(minutes), XtRImmediate, (caddr_t) DEFAULT_UPDATE}, |
---|
57 | {"numbers", "Numbers", XtRBoolean, sizeof(Boolean), |
---|
58 | Offset(numbers), XtRImmediate, (caddr_t) TRUE}, |
---|
59 | {"spaceSaver", "SpaceSaver", XtRBoolean, sizeof(Boolean), |
---|
60 | Offset(space_saver), XtRImmediate, (caddr_t) FALSE}, |
---|
61 | {"topHelpFile", "TopHelpFile", XtCString, sizeof(String), |
---|
62 | Offset(top_help_file), XtRString, (caddr_t) TOP_HELP_FILE}, |
---|
63 | {"popupHelpFile", "PopupHelpFile", XtCString, sizeof(String), |
---|
64 | Offset(popup_help_file), XtRString, (caddr_t) POPUP_HELP_FILE}, |
---|
65 | }; |
---|
66 | |
---|
67 | static XrmOptionDescRec quota_options[] = { |
---|
68 | {"-warning", ".warning", XrmoptionSepArg, (caddr_t) NULL}, |
---|
69 | {"-update", ".update", XrmoptionSepArg, (caddr_t) NULL}, |
---|
70 | {"-nonumbers", ".numbers", XrmoptionNoArg, (caddr_t) "off"}, |
---|
71 | {"-spacesaver", ".spaceSaver", XrmoptionNoArg, (caddr_t) "on"}, |
---|
72 | }; |
---|
73 | |
---|
74 | static XtActionsRec actions[] = { |
---|
75 | { "PopInfo", PopInfoAction }, |
---|
76 | { "QuotaCheck", QuotaCheckAction }, |
---|
77 | { "PrintHelp", PrintHelpAction }, |
---|
78 | { "Quit", QuitAction } |
---|
79 | }; |
---|
80 | |
---|
81 | /* Function Name: InitializeWorld |
---|
82 | * Description: Initializes everything for the quota check program. |
---|
83 | * In preparation for createing widgets. |
---|
84 | * Arguments: info - the psuedo globals struct. |
---|
85 | * argc, and argv - command line args. |
---|
86 | * Returns: the top level shell widget. |
---|
87 | * |
---|
88 | * NOTES: sets the applications context. |
---|
89 | */ |
---|
90 | |
---|
91 | Widget |
---|
92 | InitializeWorld(info, argc, argv) |
---|
93 | Info * info; |
---|
94 | int * argc; |
---|
95 | char ** argv; |
---|
96 | { |
---|
97 | Widget shell; |
---|
98 | Display * disp; |
---|
99 | |
---|
100 | XtToolkitInitialize(); |
---|
101 | info->appcon = XtCreateApplicationContext(); |
---|
102 | disp = XtOpenDisplay(info->appcon, NULL, NULL, APP_CLASS, quota_options, |
---|
103 | XtNumber(quota_options), argc, argv); |
---|
104 | if (disp == NULL) |
---|
105 | XtAppError(info->appcon, "Xquota: Could not open the display."); |
---|
106 | |
---|
107 | LoadApplicationResources(DEFAULTS_FILE, disp); |
---|
108 | shell = XtAppCreateShell(NULL, APP_CLASS, applicationShellWidgetClass, |
---|
109 | disp, NULL, (Cardinal) 0); |
---|
110 | XtGetApplicationResources(shell, (caddr_t) info, |
---|
111 | quota_resources, XtNumber(quota_resources), |
---|
112 | NULL, (Cardinal) 0); |
---|
113 | |
---|
114 | XtAppAddActions(info->appcon, actions, XtNumber(actions)); |
---|
115 | |
---|
116 | /* |
---|
117 | * A few final checks. |
---|
118 | */ |
---|
119 | |
---|
120 | info->flipped = FALSE; |
---|
121 | info->timeout = NULL; |
---|
122 | info->top_help = info->popup_help = NULL; |
---|
123 | |
---|
124 | if (info->minutes < MIN_UPDATE) { |
---|
125 | printf("The minimum update time is every %d minutes.\n", MIN_UPDATE); |
---|
126 | info->minutes = MIN_UPDATE; |
---|
127 | } |
---|
128 | |
---|
129 | return(shell); |
---|
130 | } |
---|
131 | |
---|
132 | /* Function Name: CreateWidgets |
---|
133 | * Description: Creates all widgets that are decendants of the shell. |
---|
134 | * Arguments: shell - the shell widget that all these are decended from. |
---|
135 | * info - structure with psuedo global info. |
---|
136 | * Returns: none. |
---|
137 | */ |
---|
138 | |
---|
139 | void |
---|
140 | CreateWidgets(shell, info) |
---|
141 | Widget shell; |
---|
142 | Info * info; |
---|
143 | { |
---|
144 | Arg arglist[2]; |
---|
145 | Cardinal num_args; |
---|
146 | Widget pane; |
---|
147 | |
---|
148 | pane = XtCreateManagedWidget("topPane", panedWidgetClass, shell, |
---|
149 | NULL, (Cardinal) 0); |
---|
150 | |
---|
151 | if (info->numbers && !info->space_saver) { |
---|
152 | info->quota_top = XtCreateManagedWidget("quota", labelWidgetClass, pane, |
---|
153 | NULL, (Cardinal) 0); |
---|
154 | |
---|
155 | info->used_top = XtCreateManagedWidget("used", labelWidgetClass, pane, |
---|
156 | NULL, (Cardinal) 0); |
---|
157 | } |
---|
158 | |
---|
159 | num_args = 0; |
---|
160 | XtSetArg( arglist[num_args], XtNtranslations, |
---|
161 | XtParseTranslationTable("")); num_args++; |
---|
162 | info->graph = XtCreateManagedWidget("graph", scrollbarWidgetClass, pane, |
---|
163 | arglist, num_args); |
---|
164 | |
---|
165 | if (!info->space_saver) { |
---|
166 | Widget help; |
---|
167 | num_args = 0; |
---|
168 | XtSetArg( arglist[num_args], XtNskipAdjust, TRUE); num_args++; |
---|
169 | help = XtCreateManagedWidget("help", commandWidgetClass, pane, |
---|
170 | arglist, num_args); |
---|
171 | XtAddCallback(help, XtNcallback, TopHelpProc, (caddr_t) info); |
---|
172 | } |
---|
173 | |
---|
174 | CreateInfoPopup(info); |
---|
175 | ShowQuota(info); |
---|
176 | } |
---|
177 | |
---|
178 | /* Function Name: CreateInfoPopup |
---|
179 | * Description: Creates the popup that will scream at you. |
---|
180 | * Arguments: info - the info structure. |
---|
181 | * Returns: none. |
---|
182 | */ |
---|
183 | |
---|
184 | void |
---|
185 | CreateInfoPopup(info) |
---|
186 | Info * info; |
---|
187 | { |
---|
188 | Widget pane; |
---|
189 | Arg arglist[7]; |
---|
190 | Cardinal num_args; |
---|
191 | Dimension width, height; |
---|
192 | Position x, y; |
---|
193 | char buf[BUFSIZ], *string; |
---|
194 | |
---|
195 | info->info_popup = XtCreatePopupShell("quotaInfo", transientShellWidgetClass, |
---|
196 | info->graph, NULL, 0); |
---|
197 | |
---|
198 | pane = XtCreateManagedWidget("infoPane", panedWidgetClass, info->info_popup, |
---|
199 | NULL, 0); |
---|
200 | |
---|
201 | num_args = 0; |
---|
202 | XtSetArg( arglist[num_args], XtNlabel, buf); num_args++; |
---|
203 | |
---|
204 | sprintf(buf, "%s - %s", VERSION, AUTHOR); |
---|
205 | (void) XtCreateManagedWidget("version", labelWidgetClass, pane, |
---|
206 | arglist, num_args); |
---|
207 | |
---|
208 | sprintf(buf, "Machine: %s - Filesystem: %s ", info->host, info->path); |
---|
209 | (void) XtCreateManagedWidget("machine", labelWidgetClass, pane, |
---|
210 | arglist, num_args); |
---|
211 | |
---|
212 | CreateQuotaDisplay(info, pane); |
---|
213 | |
---|
214 | info->last_widget = XtCreateManagedWidget("last", labelWidgetClass, pane, |
---|
215 | NULL, (Cardinal) 0); |
---|
216 | |
---|
217 | string = XtMalloc( sizeof(char) * TEXT_BUFFER_LENGTH); |
---|
218 | strcpy(string, SAFE_MESSAGE); |
---|
219 | |
---|
220 | num_args = 0; |
---|
221 | XtSetArg( arglist[num_args], XtNscrollVertical, XawtextScrollWhenNeeded); |
---|
222 | num_args++; |
---|
223 | XtSetArg( arglist[num_args], XtNwrap, XawtextWrapWord); num_args++; |
---|
224 | XtSetArg( arglist[num_args], XtNeditType, XawtextEdit); num_args++; |
---|
225 | XtSetArg( arglist[num_args], XtNlength, TEXT_BUFFER_LENGTH); num_args++; |
---|
226 | XtSetArg( arglist[num_args], XtNstring, string); num_args++; |
---|
227 | XtSetArg( arglist[num_args], XtNuseStringInPlace, TRUE); num_args++; |
---|
228 | info->message_widget = XtCreateManagedWidget("message", |
---|
229 | asciiTextWidgetClass, pane, |
---|
230 | arglist, num_args); |
---|
231 | |
---|
232 | CreateButtonPane(info, pane); |
---|
233 | XtRealizeWidget(info->info_popup); |
---|
234 | |
---|
235 | num_args = 0; |
---|
236 | XtSetArg( arglist[num_args], XtNwidth, &width); num_args++; |
---|
237 | XtSetArg( arglist[num_args], XtNheight, &height);num_args++; |
---|
238 | XtGetValues(info->info_popup, arglist, num_args); |
---|
239 | |
---|
240 | x = (Position) (XtScreen(info->info_popup)->width - width)/2; |
---|
241 | y = (Position) (XtScreen(info->info_popup)->height - height)/2; |
---|
242 | |
---|
243 | num_args = 0; |
---|
244 | XtSetArg( arglist[num_args], XtNx, x); num_args++; |
---|
245 | XtSetArg( arglist[num_args], XtNy, y); num_args++; |
---|
246 | XtSetValues(info->info_popup, arglist, num_args); |
---|
247 | } |
---|
248 | |
---|
249 | /* Function Name: CreateQuotaDisplay |
---|
250 | * Description: Displays quota information. |
---|
251 | * Arguments: info - the info struct. |
---|
252 | * parent - its parent. |
---|
253 | * Returns: none |
---|
254 | */ |
---|
255 | |
---|
256 | static void |
---|
257 | CreateQuotaDisplay(info, parent) |
---|
258 | Info * info; |
---|
259 | Widget parent; |
---|
260 | { |
---|
261 | char buf[BUFSIZ]; |
---|
262 | Widget pane; |
---|
263 | Arg arglist[10]; |
---|
264 | Cardinal num_args; |
---|
265 | |
---|
266 | pane = XtCreateManagedWidget("quotaPane", panedWidgetClass, parent, |
---|
267 | NULL, (Cardinal) 0); |
---|
268 | |
---|
269 | sprintf(buf, "%12s %10s %10s", "", "Kilobytes", "Files"); |
---|
270 | num_args = 0; |
---|
271 | XtSetArg( arglist[num_args], XtNlabel, buf); num_args++; |
---|
272 | (void) XtCreateManagedWidget("Types", labelWidgetClass, pane, |
---|
273 | arglist, num_args); |
---|
274 | |
---|
275 | info->hard_widget = XtCreateManagedWidget("hard", labelWidgetClass, pane, |
---|
276 | NULL, (Cardinal) 0); |
---|
277 | info->soft_widget = XtCreateManagedWidget("soft", labelWidgetClass, pane, |
---|
278 | NULL, (Cardinal) 0); |
---|
279 | info->used_widget = XtCreateManagedWidget("used", labelWidgetClass, pane, |
---|
280 | NULL, (Cardinal) 0); |
---|
281 | } |
---|
282 | |
---|
283 | /* Function Name: CreateButtonPane |
---|
284 | * Description: Create the pane with the command buttons in it. |
---|
285 | * Arguments: info - info struct. |
---|
286 | * parent - parent widget. |
---|
287 | * Returns: none. |
---|
288 | */ |
---|
289 | |
---|
290 | static void |
---|
291 | CreateButtonPane(info, parent) |
---|
292 | Info * info; |
---|
293 | Widget parent; |
---|
294 | { |
---|
295 | Widget hpane, check, help, done, quit; |
---|
296 | Arg arglist[2]; |
---|
297 | Cardinal num_args; |
---|
298 | |
---|
299 | num_args = 0; |
---|
300 | XtSetArg( arglist[num_args], XtNorientation, XtorientHorizontal); |
---|
301 | num_args++; |
---|
302 | XtSetArg( arglist[num_args], XtNskipAdjust, TRUE); num_args++; |
---|
303 | hpane = XtCreateManagedWidget("hPane", panedWidgetClass, parent, |
---|
304 | arglist, num_args); |
---|
305 | |
---|
306 | done = XtCreateManagedWidget("done", commandWidgetClass, hpane, |
---|
307 | NULL, (Cardinal) 0); |
---|
308 | |
---|
309 | help = XtCreateManagedWidget("help", commandWidgetClass, hpane, |
---|
310 | NULL, (Cardinal) 0); |
---|
311 | |
---|
312 | check = XtCreateManagedWidget("check", commandWidgetClass, hpane, |
---|
313 | NULL, (Cardinal) 0); |
---|
314 | num_args = 0; |
---|
315 | XtSetArg( arglist[num_args], XtNmappedWhenManaged, FALSE); num_args++; |
---|
316 | (void) XtCreateManagedWidget("spacer", labelWidgetClass, hpane, |
---|
317 | arglist, num_args); |
---|
318 | num_args = 0; |
---|
319 | XtSetArg( arglist[num_args], XtNskipAdjust, TRUE); num_args++; |
---|
320 | quit = XtCreateManagedWidget("quit", commandWidgetClass, hpane, |
---|
321 | arglist, num_args); |
---|
322 | |
---|
323 | XtAddCallback(help, XtNcallback, PopupHelpProc, (caddr_t) info); |
---|
324 | XtAddCallback(check, XtNcallback, CheckProc, (caddr_t) info); |
---|
325 | XtAddCallback(done, XtNcallback, DoneProc, (caddr_t) info); |
---|
326 | XtAddCallback(quit, XtNcallback, QuitProc, (caddr_t) NULL); |
---|
327 | } |
---|
328 | |
---|
329 | /* Function Name: CreateHelpWidget |
---|
330 | * Description: Creates a help widget. |
---|
331 | * Arguments: filename - name of file to load. |
---|
332 | * parent - its parent widget. |
---|
333 | * Returns: the help widget we just created. |
---|
334 | */ |
---|
335 | |
---|
336 | static Widget |
---|
337 | CreateHelpWidget(filename, parent) |
---|
338 | String filename; |
---|
339 | Widget parent; |
---|
340 | { |
---|
341 | Widget shell, pane, kill; |
---|
342 | Arg arglist[4]; |
---|
343 | Cardinal num_args = 0; |
---|
344 | |
---|
345 | shell = XtCreatePopupShell("help", topLevelShellWidgetClass, |
---|
346 | parent, NULL, 0); |
---|
347 | |
---|
348 | pane = XtCreateManagedWidget("helpPane", panedWidgetClass, shell, |
---|
349 | arglist, num_args); |
---|
350 | |
---|
351 | kill = XtCreateManagedWidget("killHelp", commandWidgetClass, pane, |
---|
352 | arglist, num_args); |
---|
353 | |
---|
354 | XtAddCallback(kill, XtNcallback, KillHelpProc, (caddr_t) shell); |
---|
355 | |
---|
356 | num_args = 0; |
---|
357 | XtSetArg( arglist[num_args], XtNscrollVertical, XawtextScrollWhenNeeded); |
---|
358 | num_args++; |
---|
359 | XtSetArg( arglist[num_args], XtNwrap, XawtextWrapWord); num_args++; |
---|
360 | XtSetArg( arglist[num_args], XtNstring, filename ) ; num_args++; |
---|
361 | XtSetArg( arglist[num_args], XtNtype, XawAsciiFile ) ; num_args++; |
---|
362 | (void) XtCreateManagedWidget("text", asciiTextWidgetClass, pane, |
---|
363 | arglist, num_args); |
---|
364 | return(shell); |
---|
365 | } |
---|
366 | |
---|
367 | /* Function Name: ShowTopHelp |
---|
368 | * Description: Show the top help. |
---|
369 | * Arguments: info - the info struct. |
---|
370 | * Returns: none |
---|
371 | */ |
---|
372 | |
---|
373 | static void |
---|
374 | ShowTopHelp(info) |
---|
375 | Info * info; |
---|
376 | { |
---|
377 | if (info->top_help == NULL) |
---|
378 | info->top_help = CreateHelpWidget(info->top_help_file, info->graph); |
---|
379 | |
---|
380 | XtPopup(info->top_help, XtGrabNone); |
---|
381 | } |
---|
382 | |
---|
383 | /* Function Name: ShowPopupHelp |
---|
384 | * Description: Show the popup help. |
---|
385 | * Arguments: info - the info struct. |
---|
386 | * Returns: none. |
---|
387 | */ |
---|
388 | |
---|
389 | static void |
---|
390 | ShowPopupHelp(info) |
---|
391 | Info * info; |
---|
392 | { |
---|
393 | if (info->popup_help == NULL) |
---|
394 | info->popup_help = CreateHelpWidget(info->popup_help_file, |
---|
395 | info->info_popup); |
---|
396 | |
---|
397 | XtPopup(info->popup_help, XtGrabNone); |
---|
398 | } |
---|
399 | |
---|
400 | |
---|
401 | /************************************************************ |
---|
402 | * |
---|
403 | * Action Proceedures. |
---|
404 | * |
---|
405 | ************************************************************/ |
---|
406 | |
---|
407 | /* Function Name: PopInfoAction |
---|
408 | * Description: Pops information window. |
---|
409 | * Arguments: w - the widget that got the proceedure. ** NOT USED ** |
---|
410 | * event - the event that caused the actions. ** NOT USED ** |
---|
411 | * params, num_params - args passed to proc. |
---|
412 | * Returns: none. |
---|
413 | */ |
---|
414 | |
---|
415 | /* ARGSUSED */ |
---|
416 | static void |
---|
417 | PopInfoAction(w, event, params, num_params) |
---|
418 | Widget w; |
---|
419 | XEvent * event; |
---|
420 | String * params; |
---|
421 | Cardinal * num_params; |
---|
422 | { |
---|
423 | if (*num_params != 1) { |
---|
424 | printf("PopInfo: number of parameters passed was not 1.\n"); |
---|
425 | return; |
---|
426 | } |
---|
427 | switch (params[0][0]) { |
---|
428 | case 'U': |
---|
429 | case 'u': |
---|
430 | XtPopup(info.info_popup, XtGrabNone); |
---|
431 | break; |
---|
432 | case 'D': |
---|
433 | case 'd': |
---|
434 | XtPopdown(info.info_popup); |
---|
435 | break; |
---|
436 | default: |
---|
437 | printf("PopInfo: specify either 'Up' or 'Down'.\n"); |
---|
438 | break; |
---|
439 | } |
---|
440 | } |
---|
441 | |
---|
442 | /* Function Name: QuitAction |
---|
443 | * Description: exits |
---|
444 | * Arguments: w - the widget that got the proceedure. ** NOT USED ** |
---|
445 | * event - the event that caused the actions. ** NOT USED ** |
---|
446 | * params, num_params - args passed to proc. ** NOT USED ** |
---|
447 | * Returns: none. |
---|
448 | */ |
---|
449 | |
---|
450 | /* ARGSUSED */ |
---|
451 | static void |
---|
452 | QuitAction(w, event, params, num_params) |
---|
453 | Widget w; |
---|
454 | XEvent * event; |
---|
455 | String * params; |
---|
456 | Cardinal * num_params; |
---|
457 | { |
---|
458 | exit(0); |
---|
459 | } |
---|
460 | |
---|
461 | /* Function Name: QuotaCheckAction |
---|
462 | * Description: checks the quota |
---|
463 | * Arguments: w - the widget that got the proceedure. ** NOT USED ** |
---|
464 | * event - the event that caused the actions. ** NOT USED ** |
---|
465 | * params, num_params - args passed to proc. ** NOT USED ** |
---|
466 | * Returns: none. |
---|
467 | */ |
---|
468 | |
---|
469 | /* ARGSUSED */ |
---|
470 | static void |
---|
471 | QuotaCheckAction(w, event, params, num_params) |
---|
472 | Widget w; |
---|
473 | XEvent * event; |
---|
474 | String * params; |
---|
475 | Cardinal * num_params; |
---|
476 | { |
---|
477 | ShowQuota( &info); |
---|
478 | } |
---|
479 | |
---|
480 | /* Function Name: PrintHelpAction |
---|
481 | * Description: Prints help. |
---|
482 | * Arguments: w - the widget that got the proceedure. ** NOT USED ** |
---|
483 | * event - the event that caused the actions. ** NOT USED ** |
---|
484 | * params, num_params - args passed to proc. ** NOT USED ** |
---|
485 | * Returns: none. |
---|
486 | */ |
---|
487 | |
---|
488 | /* ARGSUSED */ |
---|
489 | static void |
---|
490 | PrintHelpAction(w, event, params, num_params) |
---|
491 | Widget w; |
---|
492 | XEvent * event; |
---|
493 | String * params; |
---|
494 | Cardinal * num_params; |
---|
495 | { |
---|
496 | if (*num_params != 1) { |
---|
497 | printf("PrintHelp: number of parameters passed was not 1.\n"); |
---|
498 | return; |
---|
499 | } |
---|
500 | switch (params[0][0]) { |
---|
501 | case 'T': |
---|
502 | case 't': |
---|
503 | ShowTopHelp( &info ); |
---|
504 | break; |
---|
505 | case 'P': |
---|
506 | case 'p': |
---|
507 | ShowPopupHelp( &info ); |
---|
508 | break; |
---|
509 | default: |
---|
510 | printf("PrintHelp: specify either 'Top' or 'Popup'.\n"); |
---|
511 | break; |
---|
512 | } |
---|
513 | } |
---|
514 | |
---|
515 | /************************************************************ |
---|
516 | * |
---|
517 | * Callback Proceedures. |
---|
518 | * |
---|
519 | ************************************************************/ |
---|
520 | |
---|
521 | /* Function Name: CheckProc |
---|
522 | * Description: Checks the user's quota. |
---|
523 | * Arguments: w - the widget that actived this proc. ** NOT USED **. |
---|
524 | * info - a pointer the info structure. |
---|
525 | * garbage - ** NOT USED **. |
---|
526 | * Returns: none. |
---|
527 | */ |
---|
528 | |
---|
529 | /* ARGSUSED */ |
---|
530 | static void |
---|
531 | CheckProc(w, info_ptr, garbage) |
---|
532 | Widget w; |
---|
533 | caddr_t info_ptr, garbage; |
---|
534 | { |
---|
535 | ShowQuota( (Info *) info_ptr); |
---|
536 | } |
---|
537 | |
---|
538 | /* Function Name: QuitProc |
---|
539 | * Description: exits |
---|
540 | * Arguments: w - the widget that actived this proc. ** NOT USED **. |
---|
541 | * junk, garbage - ** NOT USED **. |
---|
542 | * Returns: none. |
---|
543 | */ |
---|
544 | |
---|
545 | /* ARGSUSED */ |
---|
546 | static void |
---|
547 | QuitProc(w, junk, garbage) |
---|
548 | Widget w; |
---|
549 | caddr_t junk, garbage; |
---|
550 | { |
---|
551 | exit(0); |
---|
552 | } |
---|
553 | |
---|
554 | /* Function Name: DoneProc |
---|
555 | * Description: pops down info widget |
---|
556 | * Arguments: w - the widget that actived this proc. ** NOT USED **. |
---|
557 | * info - a pointer the info structure. |
---|
558 | * garbage - ** NOT USED **. |
---|
559 | * Returns: none. |
---|
560 | */ |
---|
561 | |
---|
562 | /* ARGSUSED */ |
---|
563 | |
---|
564 | static void |
---|
565 | DoneProc(w, info_ptr, garbage) |
---|
566 | Widget w; |
---|
567 | caddr_t info_ptr, garbage; |
---|
568 | { |
---|
569 | Info * info = (Info *) info_ptr; |
---|
570 | XtPopdown(info->info_popup); |
---|
571 | } |
---|
572 | |
---|
573 | /* Function Name: TopHelpProc |
---|
574 | * Description: Print Top pane help info. |
---|
575 | * Arguments: w - the widget that actived this proc. ** NOT USED **. |
---|
576 | * info - a pointer the info structure. |
---|
577 | * garbage - ** NOT USED **. |
---|
578 | * Returns: none. |
---|
579 | */ |
---|
580 | |
---|
581 | /* ARGSUSED */ |
---|
582 | static void |
---|
583 | TopHelpProc(w, info_ptr, garbage) |
---|
584 | Widget w; |
---|
585 | caddr_t info_ptr, garbage; |
---|
586 | { |
---|
587 | ShowTopHelp( (Info *) info_ptr); |
---|
588 | } |
---|
589 | |
---|
590 | /* Function Name: PopupHelpProc |
---|
591 | * Description: Print Top pane help info. |
---|
592 | * Arguments: w - the widget that actived this proc. ** NOT USED **. |
---|
593 | * info - a pointer the info structure. |
---|
594 | * garbage - ** NOT USED **. |
---|
595 | * Returns: none. |
---|
596 | */ |
---|
597 | |
---|
598 | /* ARGSUSED */ |
---|
599 | static void |
---|
600 | PopupHelpProc(w, info_ptr, garbage) |
---|
601 | Widget w; |
---|
602 | caddr_t info_ptr, garbage; |
---|
603 | { |
---|
604 | ShowPopupHelp( (Info *) info_ptr); |
---|
605 | } |
---|
606 | |
---|
607 | /* Function Name: KillHelpProc |
---|
608 | * Description: removes the help window. |
---|
609 | * Arguments: w - the widget that actived this proc. ** NOT USED **. |
---|
610 | * help - a pointer the help shell. |
---|
611 | * garbage - ** NOT USED **. |
---|
612 | * Returns: none. |
---|
613 | */ |
---|
614 | |
---|
615 | /* ARGSUSED */ |
---|
616 | static void |
---|
617 | KillHelpProc(w, help, garbage) |
---|
618 | Widget w; |
---|
619 | caddr_t help, garbage; |
---|
620 | { |
---|
621 | XtPopdown( (Widget) help); |
---|
622 | } |
---|
623 | |
---|
624 | /************************************************************ |
---|
625 | * |
---|
626 | * Timeout proccedures. |
---|
627 | * |
---|
628 | ************************************************************/ |
---|
629 | |
---|
630 | /* Function Name: SetTimeout |
---|
631 | * Description: Sets the timeout for next quota check. |
---|
632 | * Arguments: info - the psuedo global structure. |
---|
633 | * Returns: none. |
---|
634 | */ |
---|
635 | |
---|
636 | #define MILLIES_PER_MINUTE 60000L |
---|
637 | |
---|
638 | void |
---|
639 | SetTimeOut(info) |
---|
640 | Info * info; |
---|
641 | { |
---|
642 | long time; |
---|
643 | |
---|
644 | if (info->timeout != NULL) /* remove old timeout. */ |
---|
645 | XtRemoveTimeOut(info->timeout); |
---|
646 | |
---|
647 | time = ((long) info->minutes ) * MILLIES_PER_MINUTE; |
---|
648 | info->timeout = XtAppAddTimeOut(info->appcon, time, |
---|
649 | TimeOutProc, (caddr_t) info); |
---|
650 | } |
---|
651 | |
---|
652 | /* Function Name: TimeOutProc |
---|
653 | * Description: This proceedure gets called when the timer times out. |
---|
654 | * Arguments: info_ptr - pointer to info structure. |
---|
655 | * id - id of timeout ** NOT USED **. |
---|
656 | * Returns: none |
---|
657 | */ |
---|
658 | |
---|
659 | /* ARGSUSED */ |
---|
660 | static void |
---|
661 | TimeOutProc(info_ptr, id) |
---|
662 | caddr_t info_ptr; |
---|
663 | XtIntervalId *id; |
---|
664 | { |
---|
665 | Info * info = (Info *) info_ptr; |
---|
666 | info->timeout = NULL; |
---|
667 | ShowQuota(info); |
---|
668 | } |
---|
669 | |
---|
670 | /************************************************************ |
---|
671 | * |
---|
672 | * Widget Utility Functions. |
---|
673 | * |
---|
674 | ************************************************************/ |
---|
675 | |
---|
676 | /* Function Name: SetLabel |
---|
677 | * Description: Sets the label in a widget. |
---|
678 | * Arguments: w - the widget who's label we are changing. |
---|
679 | * str - string to change it to. |
---|
680 | * Returns: none. |
---|
681 | */ |
---|
682 | |
---|
683 | void |
---|
684 | SetLabel(w, string) |
---|
685 | Widget w; |
---|
686 | char * string; |
---|
687 | { |
---|
688 | Arg arglist[1]; |
---|
689 | |
---|
690 | XtSetArg(arglist[0], XtNlabel, string); |
---|
691 | XtSetValues(w, arglist, (Cardinal) 1); |
---|
692 | } |
---|
693 | |
---|
694 | /* Function Name: FlipColors |
---|
695 | * Description: Swaps fg and bg colors. |
---|
696 | * Arguments: w - widget to flip. |
---|
697 | * Returns: none. |
---|
698 | */ |
---|
699 | |
---|
700 | static void |
---|
701 | FlipColors(w) |
---|
702 | Widget w; |
---|
703 | { |
---|
704 | Arg arglist[2]; |
---|
705 | Pixel fg, bg; |
---|
706 | Cardinal num_args; |
---|
707 | |
---|
708 | num_args = 0; |
---|
709 | XtSetArg(arglist[num_args], XtNforeground, &fg); num_args++; |
---|
710 | XtSetArg(arglist[num_args], XtNbackground, &bg); num_args++; |
---|
711 | XtGetValues(w, arglist, num_args); |
---|
712 | |
---|
713 | num_args = 0; |
---|
714 | XtSetArg(arglist[num_args], XtNforeground, bg); num_args++; |
---|
715 | XtSetArg(arglist[num_args], XtNbackground, fg); num_args++; |
---|
716 | XtSetValues(w, arglist, num_args); |
---|
717 | } |
---|
718 | |
---|
719 | /* Function Name: SetGraph |
---|
720 | * Description: Sets the quota graph. |
---|
721 | * Arguments: w - the graph widget. |
---|
722 | * quota - quota in kilobytes. |
---|
723 | * used - amount of space used in kilobytes. |
---|
724 | * Returns: none. |
---|
725 | */ |
---|
726 | |
---|
727 | void |
---|
728 | SetGraph(info, w, quota, used) |
---|
729 | Info * info; |
---|
730 | Widget w; |
---|
731 | int quota, used; |
---|
732 | { |
---|
733 | float temp; |
---|
734 | |
---|
735 | temp = ( (float) used ) / ( (float) quota); |
---|
736 | if ( temp > 1.0 ) temp = 1.0; |
---|
737 | XawScrollbarSetThumb( w, 1.0 - temp, temp ); |
---|
738 | temp *= 100; |
---|
739 | if ( (((int) temp) >= info->warn && !info->flipped) || |
---|
740 | (((int) temp) < info->warn && info->flipped) ) { |
---|
741 | FlipColors(w); |
---|
742 | if (info->numbers && !info->space_saver) |
---|
743 | FlipColors(info->used_top); |
---|
744 | FlipColors(info->used_widget); |
---|
745 | info->flipped = !info->flipped; |
---|
746 | } |
---|
747 | } |
---|
748 | |
---|
749 | /* Function Name: SetTextMessage |
---|
750 | * Description: Sets the text in the text widget to be "string". |
---|
751 | * Arguments: w - the text widget. |
---|
752 | * string - string to show in text widget. |
---|
753 | * Returns: none. |
---|
754 | */ |
---|
755 | |
---|
756 | void |
---|
757 | SetTextMessage(w, string) |
---|
758 | Widget w; |
---|
759 | char * string; |
---|
760 | { |
---|
761 | XawTextBlock t_block; |
---|
762 | |
---|
763 | t_block.firstPos = 0; |
---|
764 | t_block.length = strlen(string); |
---|
765 | t_block.ptr = string; |
---|
766 | t_block.format = FMT8BIT; |
---|
767 | |
---|
768 | if (XawTextReplace(w, 0, TEXT_BUFFER_LENGTH, &t_block) != XawEditDone) |
---|
769 | printf("Xquota Error: could not replace text string.\n"); |
---|
770 | } |
---|
771 | |
---|
772 | /************************************************************ |
---|
773 | * |
---|
774 | * Get Alternate Application Resources. |
---|
775 | * |
---|
776 | * Since I cannot write to /usr/lib/X11/app-defaults |
---|
777 | * I have to get my application resources from somewhere else. |
---|
778 | * Here is one method. |
---|
779 | * |
---|
780 | ************************************************************/ |
---|
781 | |
---|
782 | /* Function Name: LoadApplicationResources |
---|
783 | * Description: Loads in my own personal app-defaults file |
---|
784 | * Arguments: file - name of the defaults file. |
---|
785 | * disp - the display. |
---|
786 | * Returns: none. |
---|
787 | */ |
---|
788 | |
---|
789 | static void |
---|
790 | LoadApplicationResources(file, disp) |
---|
791 | char * file; |
---|
792 | Display * disp; |
---|
793 | { |
---|
794 | XrmDatabase my_database, db = XrmGetDatabase(disp); |
---|
795 | |
---|
796 | if (file == NULL || streq(file, "") ) return; |
---|
797 | |
---|
798 | if ( (my_database = XrmGetFileDatabase(file)) == NULL ) { |
---|
799 | printf("Could not open file %s to read resources.\n", file); |
---|
800 | return; |
---|
801 | } |
---|
802 | |
---|
803 | XrmMergeDatabases(my_database, &db); |
---|
804 | XrmSetDatabase(disp, db); |
---|
805 | } |
---|