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