7 #include <X11/StringDefs.h>
8 #include <X11/Intrinsic.h>
10 #include <X11/cursorfont.h>
12 #include <Xm/MessageB.h>
16 static char rcsid[] = "$Header$";
18 void extra_help_callback();
19 extern EntryForm *MoiraForms[];
20 static DoMoiraSelect(), DoReference();
22 static Widget logwidget = NULL;
25 /* No-op action to mask built-in actions */
27 void noopACT(w, event, p, n)
36 /* Action to do a moira retrieve on what was clicked at */
38 void moiraRetrieveACT(w, event, p, n)
47 be = (XButtonEvent *)event;
49 pos = XmTextXYToPos(w, be->x, be->y);
50 DoMoiraSelect(pos, w, 0);
54 /* Action to modify the moira object that was clicked on */
56 void moiraModifyACT(w, event, p, n)
65 be = (XButtonEvent *)event;
67 pos = XmTextXYToPos(w, be->x, be->y);
68 DoMoiraSelect(pos, w, 1);
72 static XtActionsRec myactions[] = {
73 { "moiraRetrieve", moiraRetrieveACT },
74 { "moiraModify", moiraModifyACT },
79 /* Create the log window, and setup the translation table to taking
84 SetupLogWidget(parent)
95 XtSetArg(wargs[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
96 XtSetArg(wargs[n], XmNeditable, False); n++;
98 logwidget = XmCreateScrolledText( parent,
101 XtManageChild(logwidget);
103 XtAppAddActions(XtWidgetToApplicationContext(logwidget),
104 myactions, XtNumber(myactions));
105 trans = XtParseTranslationTable(resources.log_trans);
106 XtOverrideTranslations(logwidget, trans);
111 /* This actually does all of the work for handling mouse clicks. It
112 * finds the surrounding text and decides what to do with the click,
113 * the actually starts the moira query or pops up the form.
116 static DoMoiraSelect(pos, w, modify)
121 char *log, *p, *p1, *p2;
122 char name[256], type[256], type2[256];
124 log = XmTextGetString(w);
125 for (p = &log[pos]; p > log; p--)
126 if (isspace(*p) || *p == ':') break;
128 /* p now points to the beginning of the word on which the mouse was
129 * clicked. Begin gross hacking to find the name and type of object.
134 while (*p1 && !isspace(*p1)) *p2++ = *p1++;
136 /* backup two words before for type2 */
137 while (p >= log && isspace(*p) || *p == ':') p--;
138 while (p >= log && !isspace(*p)) p--;
139 while (p >= log && isspace(*p)) p--;
140 while (p >= log && !isspace(*p)) p--;
145 while (!isspace(*p)) *p2++ = *p++;
147 /* skip additional whitespace */
148 while (isspace(*p)) p++;
150 /* get type & rest of type2 */
152 while (*p && *p != ':' && !isspace(*p)) *p2++ = *p1++ = *p++;
156 printf("name \"%s\", type \"%s\" type2 \"%s\"\n", name, type, type2);
158 if (!strcasecmp(type, "USER") ||
159 !strcmp(type, "name") ||
160 !strcmp(type2, "Modified by") ||
161 !strcmp(type2, "User Ownership") ||
162 !strcmp(type2, "Login name") ||
163 !strcmp(type, "login")) {
164 DoReference(name, "select_user", MM_MOD_USER, MM_SHOW_USER,
165 "get_user_account_by_login", modify);
166 } else if (!strcasecmp(type, "LIST") ||
167 !strcmp(type2, "Group Ownership")) {
168 DoReference(name, "select_list", MM_MOD_LIST, MM_SHOW_LIST,
169 "get_list_info", modify);
170 } else if (!strcasecmp(type, "MACHINE") ||
171 !strcmp(type, "host") ||
172 !strcasecmp(type, "Server") ||
173 !strcmp(type, "on") ||
174 !strcmp(type, "Box")) {
175 DoReference(name, "select_machine", MM_MOD_MACH, MM_SHOW_MACH,
176 "get_machine", modify);
177 } else if (!strcasecmp(type, "CLUSTER")) {
178 DoReference(name, "select_cluster", MM_MOD_CLUSTER, MM_SHOW_CLUSTER,
179 "get_cluster", modify);
180 } else if (!strcasecmp(type, "FILESYSTEM") ||
181 !strcmp(type, "FILESYS") ||
182 !strcmp(type2, "syslib Data")) {
183 DoReference(name, "select_filsys", MM_MOD_FILSYS, MM_SHOW_FILSYS,
184 "get_filesys_by_label", modify);
185 } else if (!strcmp(type2, "Filesystem Group")) {
186 DoReference(name, "order_fsgroup", MM_MOV_FSGROUP, MM_SHOW_FSGROUP,
187 "get_filesys_by_label", modify);
188 } else if (!strcmp(type, "Printer") ||
189 !strcmp(type2, "lpr Data")) {
190 DoReference(name, "select_printer", MM_MOD_PCAP, MM_SHOW_PCAP,
191 "get_printcap_entry", modify);
192 } else if (!strcmp(type, "Service")) {
193 DoReference(name, "select_service", MM_MOD_SERVICE, MM_SHOW_SERVICE,
194 "get_server_info", modify);
195 /* This code isn't complete, and it's not clear that we really want it...
196 } else if (!strcmp(type, "Packname")) {
198 sprintf(name2, "%s:%s", type2, name);
199 p = rindex(name2, '/');
201 DoReference(name, "select_nfs", MM_MOD_NFS, MM_SHOW_NFS,
202 "get_nfsphys", modify);
204 XBell(XtDisplay(w), 100);
210 /* This is the heart of handling the reference once we have found out
211 * what type of reference it is.
214 static DoReference(name, formname, modop, showop, query, modify)
224 char *argv[2], **aargv;
228 form = GetAndClearForm(formname);
229 StoreField(form, 0, name);
234 if (showop == MM_SHOW_FSGROUP) {
236 MoiraValueChanged(form, form->inputlines[0]);
238 MoiraFormApply(0, form);
241 if (showop == MM_SHOW_FILSYS ||
242 showop == MM_SHOW_FSGROUP) f.extrastuff = (caddr_t) sq_create();
244 m.operation = showop;
245 status = MoiraQuery(query, 1, argv, DisplayCallback, &f);
246 if (showop == MM_SHOW_FILSYS ||
247 showop == MM_SHOW_FSGROUP) {
248 while (sq_get_data(f.extrastuff, &aargv)) {
251 sq_destroy(f.extrastuff);
254 com_err(program_name, status, " while looking up data");
262 ** PopupErrorMessage(text)
264 ** Given a char* pointing to an error message, possibly with imbedded
265 ** newlines, display the text in a popup window and put two buttons
266 ** at the bottom of the window, labelled "OK" and "Cancel." Pop down
267 ** when one of the buttons is pressed.
269 ** Return 0 if "OK" is pressed, 1 for "Cancel."
273 PopupErrorMessage(text, extrahelp)
280 static XmString label;
283 printf("%s\r\n", text);
289 XtDestroyWidget(child);
293 label = XmStringCreateLtoR( text, XmSTRING_DEFAULT_CHARSET);
296 XtSetArg(wargs[n], XmNmessageString, label); n++;
298 child = (Widget) XmCreateErrorDialog(logwidget, "errormessage", wargs, n);
300 XtAddCallback (child, XmNhelpCallback, extra_help_callback, extrahelp);
302 XtUnmanageChild(XmMessageBoxGetChild (child, XmDIALOG_HELP_BUTTON));
303 XtUnmanageChild(XmMessageBoxGetChild (child, XmDIALOG_CANCEL_BUTTON));
304 XtManageChild(child);
308 ** PopupHelpWindow(text)
310 ** Given a char* pointing to an help message, possibly with imbedded
311 ** newlines, display the text in a popup window and put a single button
312 ** at the bottom of the window, labelled "OK." Pop down when the
313 ** the buttons is pressed.
317 PopupHelpWindow(text)
324 static XmString label;
327 XtDestroyWidget(child);
330 label = XmStringCreateLtoR( text, XmSTRING_DEFAULT_CHARSET);
333 XtSetArg(wargs[n], XmNmessageString, label); n++;
335 child = (Widget) XmCreateMessageDialog(logwidget, "helpmessage", wargs, n);
336 XtUnmanageChild(XmMessageBoxGetChild (child, XmDIALOG_CANCEL_BUTTON));
337 XtUnmanageChild(XmMessageBoxGetChild (child, XmDIALOG_HELP_BUTTON));
339 XtManageChild(child);
343 ** Given a char* to a single line of text, append this line at the bottom
344 ** of the log window. Return 0 of the append was sucessful, non-zero
345 ** for an error condition.
360 string = XmTextGetString(logwidget);
361 pos = strlen(string);
364 XmTextReplace(logwidget, pos, pos, text);
365 XmTextSetCursorPosition(logwidget, pos + strlen(text));
366 if (pos > resources.maxlogsize) {
367 for (p = &string[pos-resources.maxlogsize]; *p && *p != '\n'; p++);
370 XmTextReplace(logwidget, 0, pos, "");
375 MakeWatchCursor(topW)
378 static Cursor mycursor = NULL;
385 mycursor = XCreateFontCursor (XtDisplay(topW), XC_watch);
387 XDefineCursor(XtDisplay(topW), XtWindow(topW), mycursor);
388 for (fp = MoiraForms; *fp; fp++)
389 if ((*fp)->formpointer && XtIsManaged((*fp)->formpointer))
390 XDefineCursor(XtDisplay(topW), XtWindow((*fp)->formpointer), mycursor);
394 MakeNormalCursor(topW)
402 XUndefineCursor(XtDisplay(topW), XtWindow(topW));
403 for (fp = MoiraForms; *fp; fp++)
404 if ((*fp)->formpointer && XtIsManaged((*fp)->formpointer))
405 XUndefineCursor(XtDisplay(topW), XtWindow((*fp)->formpointer));
409 ** Move through the fields of the spec and make certain that the
410 ** form's widgets actually reflect the current values.
417 UserPrompt **myinputlines = spec->inputlines;
423 if (tty || spec->formpointer == NULL) return;
425 for ( current = (*myinputlines);
427 myinputlines++, current = (*myinputlines)) {
429 if (current->changed) {
431 XtSetArg(wargs[n], XmNsensitive,
432 current->insensitive ? False : True); n++;
433 XtSetValues(current->mywidget, wargs, n);
434 current->changed = False;
437 switch (current->type) {
439 if (current->returnvalue.stringvalue) {
440 XmTextSetString (current->mywidget, current->returnvalue.stringvalue);
446 XtSetArg(wargs[n], XmNset,
447 current->returnvalue.booleanvalue ? True : False); n++;
448 XtSetValues (current->mywidget, wargs, n);
452 kidcount = NumChildren(current->mywidget);
455 kid = NthChild(current->mywidget, kidcount);
456 if (current->returnvalue.stringvalue &&
457 (!strcmp (XtName(kid), current->returnvalue.stringvalue))) {
458 XtSetArg(wargs[n], XmNset, True);
462 XtSetArg(wargs[n], XmNset, False);
465 XtSetValues (kid, wargs, n);
473 XtSetArg(wargs[n], XtNsensitive, !(current->insensitive)); n++;
474 XtSetValues (current->mywidget, wargs, n);
479 extra_help_callback(w, client_data, call_data)
482 XmAnyCallbackStruct *call_data;
488 int write_log_to_file(fn)
491 char *string, buf[256];
495 string = XmTextGetString(logwidget);
496 fd = open(fn, O_WRONLY|O_CREAT, 0666);
498 sprintf(buf, "opening output file \"%s\"", fn);
499 com_err(program_name, errno, buf);
502 if ((i = write(fd, string, strlen(string))) < 0) {
503 sprintf(buf, "writing output file \"%s\"", fn);
504 com_err(program_name, errno, buf);
507 if ((i = close(fd)) < 0) {
508 sprintf(buf, "closing output file \"%s\"", fn);
509 com_err(program_name, errno, buf);
516 void yesCallback(w, ret, dummy)
521 int *ip = (int *)ret;
525 void noCallback(w, ret, dummy)
530 int *ip = (int *)ret;
536 static XtCallbackRec yescb[] = { { yesCallback, (XtPointer) &value },
538 static XtCallbackRec nocb[] = { { noCallback, (XtPointer) &value },
541 Boolean AskQuestion(text, helpname)
542 char *text, *helpname;
547 static XmString label, yes = NULL, no;
549 XtAppContext _XtDefaultAppContext();
552 yes = XmStringCreate("Yes", XmSTRING_DEFAULT_CHARSET);
553 no = XmStringCreate("No", XmSTRING_DEFAULT_CHARSET);
557 XtDestroyWidget(child);
560 label = XmStringCreateLtoR( text, XmSTRING_DEFAULT_CHARSET);
563 XtSetArg(wargs[n], XmNmessageString, label); n++;
564 XtSetArg(wargs[n], XmNokLabelString, yes); n++;
565 XtSetArg(wargs[n], XmNcancelLabelString, no); n++;
566 XtSetArg(wargs[n], XmNokCallback, yescb); n++;
567 XtSetArg(wargs[n], XmNcancelCallback, nocb); n++;
569 child = (Widget) XmCreateQuestionDialog(logwidget, "question", wargs, n);
571 XtAddCallback (child, XmNhelpCallback, extra_help_callback, helpname);
573 XtUnmanageChild(XmMessageBoxGetChild (child, XmDIALOG_HELP_BUTTON));
575 XtManageChild(child);
578 XtAppNextEvent(_XtDefaultAppContext(), &event);
579 XtDispatchEvent(&event);
589 /******* temporary ********/
593 PopupErrorMessage(msg, "no_more_help");