1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399 |
- /* $Xorg: save.c,v 1.5 2001/02/09 02:06:01 xorgcvs Exp $ */
- /******************************************************************************
- Copyright 1993, 1998 The Open Group
- Permission to use, copy, modify, distribute, and sell this software and its
- documentation for any purpose is hereby granted without fee, provided that
- the above copyright notice appear in all copies and that both that
- copyright notice and this permission notice appear in supporting
- documentation.
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Except as contained in this notice, the name of The Open Group shall not be
- used in advertising or otherwise to promote the sale, use or other dealings
- in this Software without prior written authorization from The Open Group.
- ******************************************************************************/
- /* $XFree86: xc/programs/xsm/save.c,v 3.3 2001/01/17 23:46:30 dawes Exp $ */
- #include "xsm.h"
- #include "save.h"
- #include "saveutil.h"
- #include "popup.h"
- #include "info.h"
- #include "lock.h"
- #include "choose.h"
- #include <X11/Shell.h>
- #include <X11/Xaw/Form.h>
- #include <X11/Xaw/List.h>
- #include <X11/Xaw/Command.h>
- #include <X11/Xaw/Toggle.h>
- #include <X11/Xaw/AsciiText.h>
- static Widget savePopup;
- static Widget saveForm;
- static Widget saveMessageLabel;
- static Widget saveName;
- static Widget saveTypeLabel;
- static Widget saveTypeGlobal;
- static Widget saveTypeLocal;
- static Widget saveTypeBoth;
- static Widget interactStyleLabel;
- static Widget interactStyleNone;
- static Widget interactStyleErrors;
- static Widget interactStyleAny;
- static Widget saveOkButton;
- static Widget helpSaveButton;
- static Widget saveCancelButton;
- static Widget helpPopup;
- static Widget helpForm;
- static Widget helpSaveText;
- static Widget helpSaveOkButton;
- static Widget nameInUsePopup;
- static Widget nameInUseForm;
- static Widget nameInUseLabel;
- static Widget nameInUseOverwriteButton;
- static Widget nameInUseCancelButton;
- static Widget badSavePopup;
- static Widget badSaveForm;
- static Widget badSaveLabel;
- static Widget badSaveOkButton;
- static Widget badSaveCancelButton;
- static Widget badSaveListWidget;
- static int saveTypeData[] = {
- SmSaveLocal,
- SmSaveGlobal,
- SmSaveBoth
- };
- static int interactStyleData[] = {
- SmInteractStyleNone,
- SmInteractStyleErrors,
- SmInteractStyleAny
- };
- static String *failedNames = NULL;
- static int numFailedNames = 0;
- static Bool help_visible = False;
- static String name_in_use = NULL;
- static Bool name_locked = False;
- static void
- MakeCurrentSession(String new_name, Bool name_changed)
- {
- char title[256];
- List *cl;
- if (session_name)
- {
- /*
- * In the old session, for any client that was not restarted by the
- * session manager (previous ID was NULL), if we did not issue a
- * checkpoint to this client after the initial startup, remove the
- * client's checkpoint file using the discard command.
- */
- for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
- {
- ClientRec *client = (ClientRec *) cl->thing;
- if (!client->restarted &&
- !client->userIssuedCheckpoint &&
- client->discardCommand)
- {
- execute_system_command (client->discardCommand);
- XtFree (client->discardCommand);
- client->discardCommand = NULL;
- }
- }
-
- /*
- * Unlock the old session.
- */
-
- if (!need_to_name_session)
- UnlockSession (session_name);
- }
- if (name_changed)
- {
- if (session_name)
- XtFree (session_name);
- session_name = XtNewString (new_name);
- }
- LockSession (session_name, True);
- snprintf (title, sizeof(title), "xsm: %s", session_name);
- XtVaSetValues (topLevel,
- XtNtitle, title,
- NULL);
- set_session_save_file_name (session_name);
- /*
- * For each client, set the DiscardCommand ptr to NULL.
- * This is so when we do a checkpoint with the new session
- * name, we don't wipe out the checkpoint files needed by
- * the previous session. We also set the userIssuedCheckpoint
- * flag to false for each client in the new session.
- */
- for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
- {
- ClientRec *client = (ClientRec *) cl->thing;
- client->userIssuedCheckpoint = False;
- if (client->discardCommand)
- {
- XtFree (client->discardCommand);
- client->discardCommand = NULL;
- }
- }
- need_to_name_session = False;
- }
- #define NAME_OK 0
- #define NAME_EMPTY 1
- #define NAME_EXISTS 2
- #define NAME_LOCKED 3
- static int
- GetSaveName(String *nameRet)
- {
- String new_name = NULL;
- Bool name_changed;
- /*
- * Get the name of the session for the save
- */
- XtVaGetValues (saveName,
- XtNstring, &new_name,
- NULL);
- *nameRet = new_name;
- if (!new_name || *new_name == '\0')
- return (NAME_EMPTY);
- /*
- * See if this is a new session. If not return.
- */
- name_changed = !session_name ||
- (session_name && strcmp (session_name, new_name) != 0);
- if (!need_to_name_session && !name_changed)
- return (NAME_OK);
- /*
- * Make sure the session name is unique.
- */
- if (GetSessionNames (&sessionNameCount,
- &sessionNamesShort, NULL, &sessionsLocked))
- {
- int i, no_good = 0, locked = 0;
- for (i = 0; i < sessionNameCount; i++)
- if (strcmp (new_name, sessionNamesShort[i]) == 0)
- {
- no_good = 1;
- locked = sessionsLocked[i];
- break;
- }
- FreeSessionNames (sessionNameCount,
- sessionNamesShort, NULL, sessionsLocked);
-
- if (no_good)
- return (locked ? NAME_LOCKED : NAME_EXISTS);
- }
- MakeCurrentSession (new_name, name_changed);
- return (NAME_OK);
- }
- static void
- GetSaveOptions(int *saveType, int *interactStyle, Bool *fast)
- {
- XtPointer ptr;
- if (help_visible)
- {
- XtPopdown (helpPopup);
- help_visible = 0;
- }
- ptr = XawToggleGetCurrent (saveTypeLocal /* just 1 of the group */);
- *saveType = *((int *) ptr);
- ptr = XawToggleGetCurrent (interactStyleNone /* just 1 of the group */);
- *interactStyle = *((int *) ptr);
- *fast = False;
- }
- void
- DoSave(int saveType, int interactStyle, Bool fast)
- {
- ClientRec *client;
- List *cl;
- const char *_saveType;
- const char *_shutdown;
- const char *_interactStyle;
- if (saveType == SmSaveLocal)
- _saveType = "Local";
- else if (saveType == SmSaveGlobal)
- _saveType = "Global";
- else
- _saveType = "Both";
- if (wantShutdown)
- _shutdown = "True";
- else
- _shutdown = "False";
- if (interactStyle == SmInteractStyleNone)
- _interactStyle = "None";
- else if (interactStyle == SmInteractStyleErrors)
- _interactStyle = "Errors";
- else
- _interactStyle = "Any";
- SetSaveSensitivity (False);
- saveInProgress = True;
-
- shutdownCancelled = False;
- phase2InProgress = False;
- if (ListCount (RunningList) == 0)
- FinishUpSave ();
- for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
- {
- client = (ClientRec *) cl->thing;
- SmsSaveYourself (client->smsConn,
- saveType, wantShutdown, interactStyle, fast);
- ListAddLast (WaitForSaveDoneList, (char *) client);
- client->userIssuedCheckpoint = True;
- client->receivedDiscardCommand = False;
- if (verbose)
- {
- printf ("Client Id = %s, sent SAVE YOURSELF [", client->clientId);
- printf ("Save Type = %s, Shutdown = %s, ", _saveType, _shutdown);
- printf ("Interact Style = %s, Fast = False]\n", _interactStyle);
- }
- }
- if (verbose)
- {
- printf ("\n");
- printf ("Sent SAVE YOURSELF to all clients. Waiting for\n");
- printf ("SAVE YOURSELF DONE, INTERACT REQUEST, or\n");
- printf ("SAVE YOURSELF PHASE 2 REQUEST from each client.\n");
- printf ("\n");
- }
- }
- static void
- SaveOkAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
- {
- XtCallCallbacks (saveOkButton, XtNcallback, NULL);
- }
- static void
- DelSaveWinAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
- {
- XtCallCallbacks (saveCancelButton, XtNcallback, NULL);
- }
- static void
- DelNameInUseWinAction(Widget w, XEvent *event, String *params,
- Cardinal *num_params)
- {
- XtCallCallbacks (nameInUseCancelButton, XtNcallback, NULL);
- }
- static void
- DelBadSaveWinAction(Widget w, XEvent *event, String *params,
- Cardinal *num_params)
- {
- if (XtIsManaged (badSaveCancelButton))
- XtCallCallbacks (badSaveCancelButton, XtNcallback, NULL);
- else
- XtCallCallbacks (badSaveOkButton, XtNcallback, NULL);
- }
- static void
- DelSaveHelpWinAction(Widget w, XEvent *event, String *params,
- Cardinal *num_params)
- {
- XtCallCallbacks (helpSaveOkButton, XtNcallback, NULL);
- }
- static void
- SaveOkXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- String name = NULL;
- char label[256];
- int status;
- static int first_time = 1;
- int saveType;
- int interactStyle;
- Bool fast;
- if ((status = GetSaveName (&name)) != NAME_OK)
- {
- #ifdef XKB
- XkbStdBell(XtDisplay(topLevel),XtWindow(topLevel),0,XkbBI_BadValue);
- #else
- XBell (XtDisplay (topLevel), 0);
- #endif
- if (status == NAME_EXISTS || status == NAME_LOCKED)
- {
- name_in_use = name;
- if (status == NAME_LOCKED)
- {
- name_locked = True;
- snprintf (label, sizeof(label), "Another session by the name '%s' is active.\nChoose another name for the session.", name);
- XtUnmanageChild (nameInUseOverwriteButton);
- XtVaSetValues (nameInUseCancelButton,
- XtNlabel, "OK",
- XtNfromHoriz, NULL,
- NULL);
- }
- else
- {
- name_locked = False;
- snprintf (label, sizeof(label), "Another session by the name '%s' already exists.\nWould you like to overwrite it?", name);
- XtManageChild (nameInUseOverwriteButton);
- XtVaSetValues (nameInUseCancelButton,
- XtNlabel, "Cancel",
- XtNfromHoriz, nameInUseOverwriteButton,
- NULL);
- }
- XtVaSetValues (nameInUseLabel,
- XtNlabel, label,
- NULL);
- XtPopdown (savePopup);
- PopupPopup (mainWindow, nameInUsePopup,
- True, first_time, 25, 100, "DelNameInUseWinAction()");
- if (first_time)
- first_time = 0;
- }
- return;
- }
- GetSaveOptions (&saveType, &interactStyle, &fast);
- DoSave (saveType, interactStyle, fast);
- }
- void
- LetClientInteract(List *cl)
- {
- ClientRec *client = (ClientRec *) cl->thing;
- SmsInteract (client->smsConn);
- ListSearchAndFreeOne (WaitForInteractList, (char *) client);
- if (verbose)
- {
- printf ("Client Id = %s, sent INTERACT\n", client->clientId);
- }
- }
- void
- StartPhase2(void)
- {
- List *cl;
- if (verbose)
- {
- printf ("\n");
- printf ("Starting PHASE 2 of SAVE YOURSELF\n");
- printf ("\n");
- }
- for (cl = ListFirst (WaitForPhase2List); cl; cl = ListNext (cl))
- {
- ClientRec *client = (ClientRec *) cl->thing;
- SmsSaveYourselfPhase2 (client->smsConn);
- if (verbose)
- {
- printf ("Client Id = %s, sent SAVE YOURSELF PHASE 2",
- client->clientId);
- }
- }
- ListFreeAllButHead (WaitForPhase2List);
- phase2InProgress = True;
- }
- void
- FinishUpSave(void)
- {
- ClientRec *client;
- List *cl;
- if (verbose)
- {
- printf ("\n");
- printf ("All clients issued SAVE YOURSELF DONE\n");
- printf ("\n");
- }
- saveInProgress = False;
- phase2InProgress = False;
- /*
- * Now execute discard commands
- */
- for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
- {
- client = (ClientRec *) cl->thing;
- if (!client->receivedDiscardCommand)
- continue;
- if (client->discardCommand)
- {
- execute_system_command (client->discardCommand);
- XtFree (client->discardCommand);
- client->discardCommand = NULL;
- }
-
- if (client->saveDiscardCommand)
- {
- client->discardCommand = client->saveDiscardCommand;
- client->saveDiscardCommand = NULL;
- }
- }
- /*
- * Write the save file
- */
-
- WriteSave (sm_id);
- if (wantShutdown && shutdownCancelled)
- {
- shutdownCancelled = False;
- }
- else if (wantShutdown)
- {
- if (ListCount (RunningList) == 0)
- EndSession (0);
- shutdownInProgress = True;
- for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
- {
- client = (ClientRec *) cl->thing;
- SmsDie (client->smsConn);
- if (verbose)
- {
- printf ("Client Id = %s, sent DIE\n", client->clientId);
- }
- }
- }
- else
- {
- for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
- {
- client = (ClientRec *) cl->thing;
- SmsSaveComplete (client->smsConn);
- if (verbose)
- {
- printf ("Client Id = %s, sent SAVE COMPLETE\n",
- client->clientId);
- }
- }
- }
- if (!shutdownInProgress)
- {
- XtPopdown (savePopup);
- SetAllSensitive (1);
- if (checkpoint_from_signal)
- checkpoint_from_signal = False;
- }
- }
- static void
- SaveCancelXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- XtPopdown (savePopup);
- if (help_visible)
- {
- XtPopdown (helpPopup);
- help_visible = 0;
- }
- SetAllSensitive (1);
- }
- /*
- * Add toggle button
- */
- static Widget
- AddToggle(char *widgetName, Widget parent, int state, Widget radioGroup,
- XtPointer radioData, Widget fromHoriz, Widget fromVert)
- {
- Widget toggle;
- toggle = XtVaCreateManagedWidget (
- widgetName, toggleWidgetClass, parent,
- XtNstate, state,
- XtNradioGroup, radioGroup,
- XtNradioData, radioData,
- XtNfromHoriz, fromHoriz,
- XtNfromVert, fromVert,
- NULL);
- return (toggle);
- }
- void
- SetSaveSensitivity(Bool on)
- {
- XtSetSensitive (savePopup, on);
- #if 0
- /*
- * When we turn of sensitivity in the save dialog, we want to keep
- * the cancel button sensitive (so the user can cancel in case of
- * a problem). Unfortunately, we can not turn off the sensitivity on
- * the save popup, and then just turn on sensitivity for the cancel
- * button. We must do each widget individually.
- */
- XtSetSensitive (saveTypeLabel, on);
- XtSetSensitive (saveTypeGlobal, on);
- XtSetSensitive (saveTypeLocal, on);
- XtSetSensitive (saveTypeBoth, on);
- XtSetSensitive (interactStyleLabel, on);
- XtSetSensitive (interactStyleNone, on);
- XtSetSensitive (interactStyleErrors, on);
- XtSetSensitive (interactStyleAny, on);
- XtSetSensitive (saveOkButton, on);
- #endif
- }
- void
- SavePopupStructureNotifyXtHandler(Widget w, XtPointer closure, XEvent *event,
- Boolean *continue_to_dispatch)
- {
- if (event->type == MapNotify)
- {
- /*
- * Now that the Save Dialog is back up, we can do the save.
- */
- int saveType;
- int interactStyle;
- Bool fast;
- if (name_locked)
- {
- /* Force shutdown */
- }
- DeleteSession (name_in_use);
- MakeCurrentSession (name_in_use, True);
- name_in_use = NULL;
- GetSaveOptions (&saveType, &interactStyle, &fast);
- DoSave (saveType, interactStyle, fast);
- XtRemoveEventHandler (savePopup, StructureNotifyMask, False,
- SavePopupStructureNotifyXtHandler, NULL);
- }
- }
- static void
- NameInUseOverwriteXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- if (name_locked)
- {
- /* force shutdown not implemented yet */
- return;
- }
- XtPopdown (nameInUsePopup);
- /*
- * We want to popup the Save dialog again. In order to avoid a race
- * condition with the BadSave handler trying to pop down the Save Dialog,
- * we wait for the MapNotify on the Save dialog, and then do the save.
- */
- XtAddEventHandler (savePopup, StructureNotifyMask, False,
- SavePopupStructureNotifyXtHandler, NULL);
- XtPopup (savePopup, XtGrabNone);
- }
- static void
- NameInUseCancelXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- XtPopdown (nameInUsePopup);
- XtPopup (savePopup, XtGrabNone);
- name_in_use = NULL;
- }
- static void
- BadSaveOkXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- ListFreeAllButHead (FailedSaveList);
- XtPopdown (badSavePopup);
- FinishUpSave ();
- }
- static void
- BadSaveCancelXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- ListFreeAllButHead (FailedSaveList);
- XtPopdown (badSavePopup);
- if (wantShutdown)
- {
- List *cl;
- shutdownCancelled = True;
- for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
- {
- ClientRec *client = (ClientRec *) cl->thing;
- SmsShutdownCancelled (client->smsConn);
- if (verbose)
- {
- printf ("Client Id = %s, sent SHUTDOWN CANCELLED\n",
- client->clientId);
- }
- }
- }
- FinishUpSave ();
- }
- static void
- BadSaveListXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- }
- static void
- HelpSaveXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- static int first_time = 1;
- if (help_visible)
- {
- /* Make sure it is visible */
- XMapRaised (XtDisplay (topLevel), XtWindow (helpPopup));
- }
- else
- {
- PopupPopup (savePopup, helpPopup,
- True, first_time, 50, 50, "DelSaveHelpWinAction()");
- help_visible = 1;
- if (first_time)
- first_time = 0;
- }
- }
- static void
- HelpSaveOkXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- XtPopdown (helpPopup);
- help_visible = 0;
- }
- void
- create_save_popup(void)
- {
- XtTranslations translations;
- static XtActionsRec actions[] = {
- {"SaveOkAction", SaveOkAction},
- {"DelSaveWinAction", DelSaveWinAction},
- {"DelNameInUseWinAction", DelNameInUseWinAction},
- {"DelBadSaveWinAction", DelBadSaveWinAction},
- {"DelSaveHelpWinAction", DelSaveHelpWinAction}
- };
- /*
- * Pop up for Save Yourself button.
- */
- savePopup = XtVaCreatePopupShell (
- "savePopup", transientShellWidgetClass, topLevel,
- XtNallowShellResize, True,
- NULL);
-
- saveForm = XtCreateManagedWidget (
- "saveForm", formWidgetClass, savePopup, NULL, 0);
- saveMessageLabel = XtVaCreateManagedWidget (
- "saveMessageLabel", labelWidgetClass, saveForm,
- XtNfromHoriz, NULL,
- XtNfromVert, NULL,
- XtNborderWidth, 0,
- NULL);
- saveName = XtVaCreateManagedWidget (
- "saveName", asciiTextWidgetClass, saveForm,
- XtNfromVert, NULL,
- XtNeditType, XawtextEdit,
- XtNresizable, True,
- XtNresize, XawtextResizeWidth,
- NULL);
- saveTypeLabel = XtVaCreateManagedWidget (
- "saveTypeLabel", labelWidgetClass, saveForm,
- XtNfromHoriz, NULL,
- XtNfromVert, saveMessageLabel,
- XtNborderWidth, 0,
- XtNvertDistance, 20,
- NULL);
- saveTypeLocal = AddToggle (
- "saveTypeLocal", /* widgetName */
- saveForm, /* parent */
- 0, /* state */
- NULL, /* radioGroup */
- (XtPointer) &saveTypeData[0], /* radioData */
- saveTypeLabel, /* fromHoriz */
- saveMessageLabel /* fromVert */
- );
- saveTypeGlobal = AddToggle (
- "saveTypeGlobal", /* widgetName */
- saveForm, /* parent */
- 0, /* state */
- saveTypeLocal, /* radioGroup */
- (XtPointer) &saveTypeData[1], /* radioData */
- saveTypeLocal, /* fromHoriz */
- saveMessageLabel /* fromVert */
- );
- saveTypeBoth = AddToggle (
- "saveTypeBoth", /* widgetName */
- saveForm, /* parent */
- 1, /* state */
- saveTypeLocal, /* radioGroup */
- (XtPointer) &saveTypeData[2], /* radioData */
- saveTypeGlobal, /* fromHoriz */
- saveMessageLabel /* fromVert */
- );
- XtVaSetValues (saveName, XtNfromHoriz, saveTypeLabel, NULL);
- XtVaSetValues (saveTypeLocal, XtNvertDistance, 20, NULL);
- XtVaSetValues (saveTypeGlobal, XtNvertDistance, 20, NULL);
- XtVaSetValues (saveTypeBoth, XtNvertDistance, 20, NULL);
- interactStyleLabel = XtVaCreateManagedWidget (
- "interactStyleLabel", labelWidgetClass, saveForm,
- XtNfromHoriz, NULL,
- XtNfromVert, saveTypeLabel,
- XtNborderWidth, 0,
- NULL);
- interactStyleNone = AddToggle (
- "interactStyleNone", /* widgetName */
- saveForm, /* parent */
- 0, /* state */
- NULL, /* radioGroup */
- (XtPointer) &interactStyleData[0], /* radioData */
- saveTypeLabel, /* fromHoriz */
- saveTypeLabel /* fromVert */
- );
- interactStyleErrors = AddToggle (
- "interactStyleErrors", /* widgetName */
- saveForm, /* parent */
- 0, /* state */
- interactStyleNone, /* radioGroup */
- (XtPointer) &interactStyleData[1], /* radioData */
- interactStyleNone, /* fromHoriz */
- saveTypeLabel /* fromVert */
- );
- interactStyleAny = AddToggle (
- "interactStyleAny", /* widgetName */
- saveForm, /* parent */
- 1, /* state */
- interactStyleNone, /* radioGroup */
- (XtPointer) &interactStyleData[2], /* radioData */
- interactStyleErrors, /* fromHoriz */
- saveTypeLabel /* fromVert */
- );
- saveOkButton = XtVaCreateManagedWidget (
- "saveOkButton", commandWidgetClass, saveForm,
- XtNfromHoriz, NULL,
- XtNfromVert, interactStyleLabel,
- XtNvertDistance, 20,
- XtNresizable, True,
- NULL);
- XtAddCallback (saveOkButton, XtNcallback, SaveOkXtProc, NULL);
- helpSaveButton = XtVaCreateManagedWidget (
- "helpSaveButton", commandWidgetClass, saveForm,
- XtNfromHoriz, saveOkButton,
- XtNfromVert, interactStyleLabel,
- XtNvertDistance, 20,
- NULL);
- XtAddCallback (helpSaveButton, XtNcallback, HelpSaveXtProc, NULL);
- saveCancelButton = XtVaCreateManagedWidget (
- "saveCancelButton", commandWidgetClass, saveForm,
- XtNfromHoriz, helpSaveButton,
- XtNfromVert, interactStyleLabel,
- XtNvertDistance, 20,
- NULL);
- XtAddCallback (saveCancelButton, XtNcallback, SaveCancelXtProc, NULL);
- XtSetKeyboardFocus (saveForm, saveName);
- XtAppAddActions (appContext, actions, XtNumber (actions));
- translations = XtParseTranslationTable
- ("<Key>Return: SaveOkAction()\n");
- XtOverrideTranslations(saveName, translations);
- XtInstallAllAccelerators (saveForm, saveForm);
- /*
- * Pop up when user tries to save the session under an
- * already used name.
- */
- nameInUsePopup = XtVaCreatePopupShell (
- "nameInUsePopup", transientShellWidgetClass, topLevel,
- XtNallowShellResize, True,
- NULL);
-
- nameInUseForm = XtVaCreateManagedWidget (
- "nameInUseForm", formWidgetClass, nameInUsePopup,
- NULL);
- nameInUseLabel = XtVaCreateManagedWidget (
- "nameInUseLabel", labelWidgetClass, nameInUseForm,
- XtNresizable, True,
- XtNfromHoriz, NULL,
- XtNfromVert, NULL,
- XtNborderWidth, 0,
- XtNtop, XawChainTop,
- XtNbottom, XawChainTop,
- NULL);
- nameInUseOverwriteButton = XtVaCreateManagedWidget (
- "nameInUseOverwriteButton", commandWidgetClass, nameInUseForm,
- XtNfromHoriz, NULL,
- XtNfromVert, nameInUseLabel,
- XtNtop, XawChainBottom,
- XtNbottom, XawChainBottom,
- NULL);
-
- XtAddCallback (nameInUseOverwriteButton, XtNcallback,
- NameInUseOverwriteXtProc, NULL);
- nameInUseCancelButton = XtVaCreateManagedWidget (
- "nameInUseCancelButton", commandWidgetClass, nameInUseForm,
- XtNresizable, True,
- XtNfromHoriz, nameInUseOverwriteButton,
- XtNfromVert, nameInUseLabel,
- XtNtop, XawChainBottom,
- XtNbottom, XawChainBottom,
- NULL);
-
- XtAddCallback (nameInUseCancelButton, XtNcallback,
- NameInUseCancelXtProc, NULL);
- /*
- * Pop up for help.
- */
- helpPopup = XtVaCreatePopupShell (
- "helpPopup", transientShellWidgetClass, topLevel,
- NULL);
-
- helpForm = XtVaCreateManagedWidget (
- "helpForm", formWidgetClass, helpPopup,
- NULL);
- helpSaveText = XtVaCreateManagedWidget (
- "helpSaveText", labelWidgetClass, helpForm,
- XtNfromHoriz, NULL,
- XtNfromVert, NULL,
- XtNtop, XawChainTop,
- XtNbottom, XawChainTop,
- NULL);
- helpSaveOkButton = XtVaCreateManagedWidget (
- "helpSaveOkButton", commandWidgetClass, helpForm,
- XtNfromHoriz, NULL,
- XtNfromVert, helpSaveText,
- XtNtop, XawChainBottom,
- XtNbottom, XawChainBottom,
- XtNvertDistance, 20,
- NULL);
-
- XtAddCallback (helpSaveOkButton, XtNcallback,
- HelpSaveOkXtProc, NULL);
- /*
- * Pop up when not all clients returned SaveSuccess
- */
- badSavePopup = XtVaCreatePopupShell (
- "badSavePopup", transientShellWidgetClass, topLevel,
- XtNallowShellResize, True,
- NULL);
-
- badSaveForm = XtVaCreateManagedWidget (
- "badSaveForm", formWidgetClass, badSavePopup,
- NULL);
- badSaveLabel = XtVaCreateManagedWidget (
- "badSaveLabel", labelWidgetClass, badSaveForm,
- XtNfromHoriz, NULL,
- XtNfromVert, NULL,
- XtNborderWidth, 0,
- XtNtop, XawChainTop,
- XtNbottom, XawChainTop,
- NULL);
- badSaveListWidget = XtVaCreateManagedWidget (
- "badSaveListWidget", listWidgetClass, badSaveForm,
- XtNresizable, True,
- XtNdefaultColumns, 1,
- XtNforceColumns, True,
- XtNfromHoriz, NULL,
- XtNfromVert, badSaveLabel,
- XtNtop, XawChainTop,
- XtNbottom, XawChainBottom,
- NULL);
- XtAddCallback (badSaveListWidget, XtNcallback, BadSaveListXtProc, NULL);
- badSaveOkButton = XtVaCreateManagedWidget (
- "badSaveOkButton", commandWidgetClass, badSaveForm,
- XtNfromHoriz, NULL,
- XtNfromVert, badSaveListWidget,
- XtNtop, XawChainBottom,
- XtNbottom, XawChainBottom,
- NULL);
- XtAddCallback (badSaveOkButton, XtNcallback, BadSaveOkXtProc, NULL);
- badSaveCancelButton = XtVaCreateManagedWidget (
- "badSaveCancelButton", commandWidgetClass, badSaveForm,
- XtNfromHoriz, badSaveOkButton,
- XtNfromVert, badSaveListWidget,
- XtNtop, XawChainBottom,
- XtNbottom, XawChainBottom,
- NULL);
- XtAddCallback (badSaveCancelButton, XtNcallback, BadSaveCancelXtProc, NULL);
- XtInstallAllAccelerators (badSaveForm, badSaveForm);
- }
- void
- PopupSaveDialog(void)
- {
- static int first_time = 1;
- XtSetSensitive (mainWindow, 0);
- XtSetSensitive (clientInfoPopup, 0);
- XtSetSensitive (clientPropPopup, 0);
- XawToggleSetCurrent (saveTypeBoth,
- (XtPointer) &saveTypeData[2]);
- XawToggleSetCurrent (interactStyleAny,
- (XtPointer) &interactStyleData[2]);
- XtVaSetValues (savePopup,
- XtNtitle, wantShutdown ? "Shutdown" : "Checkpoint",
- NULL);
- XtVaSetValues (saveName,
- XtNstring, need_to_name_session ? "" : session_name,
- NULL);
- XtVaSetValues (saveOkButton,
- XtNlabel, wantShutdown ? "Shutdown" : "Checkpoint",
- NULL);
- PopupPopup (mainWindow, savePopup,
- True, first_time, 25, 100, "DelSaveWinAction()");
- if (first_time)
- first_time = 0;
- }
- void
- CheckPointXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- wantShutdown = False;
- PopupSaveDialog ();
- }
- void
- ShutdownSaveXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- wantShutdown = True;
- PopupSaveDialog ();
- }
- void
- PopupBadSave(void)
- {
- ClientRec *client;
- char *progName, *hostname, *tmp1, *tmp2;
- String clientInfo;
- int maxlen1, maxlen2;
- char extraBuf1[80], extraBuf2[80];
- char *restart_service_prop;
- List *cl, *pl;
- int i, k;
- static int first_time = 1;
- if (failedNames)
- {
- /*
- * Free the previous list of names. Xaw doesn't make a copy of
- * our list, so we need to keep it around.
- */
- for (i = 0; i < numFailedNames; i++)
- XtFree (failedNames[i]);
- XtFree ((char *) failedNames);
- failedNames = NULL;
- }
- maxlen1 = maxlen2 = 0;
- numFailedNames = 0;
- for (cl = ListFirst (FailedSaveList); cl; cl = ListNext (cl))
- {
- client = (ClientRec *) cl->thing;
- progName = NULL;
- restart_service_prop = NULL;
- for (pl = ListFirst (client->props); pl; pl = ListNext (pl))
- {
- Prop *pprop = (Prop *) pl->thing;
- List *vl = ListFirst (pprop->values);
- PropValue *pval = (PropValue *) vl->thing;
- if (strcmp (pprop->name, SmProgram) == 0)
- {
- progName = GetProgramName ((char *) pval->value);
- if ((int) strlen (progName) > maxlen1)
- maxlen1 = strlen (progName);
- }
- else if (strcmp (pprop->name, "_XC_RestartService") == 0)
- {
- restart_service_prop = (char *) pval->value;
- }
- }
- if (!progName)
- continue;
- if (restart_service_prop)
- tmp1 = restart_service_prop;
- else if (client->clientHostname)
- tmp1 = client->clientHostname;
- else
- continue;
- if ((tmp2 = (char *) strchr (tmp1, '/')) == NULL)
- hostname = tmp1;
- else
- hostname = tmp2 + 1;
- if ((int) strlen (hostname) > maxlen2)
- maxlen2 = strlen (hostname);
- numFailedNames++;
- }
- failedNames = (String *) XtMalloc (
- numFailedNames * sizeof (String));
- i = 0;
- for (cl = ListFirst (FailedSaveList); cl; cl = ListNext (cl))
- {
- ClientRec *client = (ClientRec *) cl->thing;
- int extra1, extra2;
- progName = NULL;
- restart_service_prop = NULL;
- for (pl = ListFirst (client->props); pl; pl = ListNext (pl))
- {
- Prop *pprop = (Prop *) pl->thing;
- List *vl = ListFirst (pprop->values);
- PropValue *pval = (PropValue *) vl->thing;
- if (strcmp (pprop->name, SmProgram) == 0)
- {
- progName = GetProgramName ((char *) pval->value);
- }
- else if (strcmp (pprop->name, "_XC_RestartService") == 0)
- {
- restart_service_prop = (char *) pval->value;
- }
- }
- if (!progName)
- continue;
- if (restart_service_prop)
- tmp1 = restart_service_prop;
- else if (client->clientHostname)
- tmp1 = client->clientHostname;
- else
- continue;
- if ((tmp2 = (char *) strchr (tmp1, '/')) == NULL)
- hostname = tmp1;
- else
- hostname = tmp2 + 1;
- extra1 = maxlen1 - strlen (progName) + 5;
- extra2 = maxlen2 - strlen (hostname);
- for (k = 0; k < extra1; k++)
- extraBuf1[k] = ' ';
- extraBuf1[extra1] = '\0';
- for (k = 0; k < extra2; k++)
- extraBuf2[k] = ' ';
- extraBuf2[extra2] = '\0';
- XtAsprintf (&clientInfo, "%s%s (%s%s)", progName, extraBuf1,
- hostname, extraBuf2);
- failedNames[i++] = clientInfo;
- if (client->freeAfterBadSavePopup)
- {
- FreeClient (client, True /* free props */);
- }
- }
- XawListChange (badSaveListWidget,
- failedNames, numFailedNames, 0, True);
- XtPopdown (savePopup);
- if (wantShutdown && !shutdownCancelled)
- XtManageChild (badSaveCancelButton);
- else
- XtUnmanageChild (badSaveCancelButton);
- PopupPopup (mainWindow, badSavePopup,
- True, first_time, 25, 100, "DelBadSaveWinAction()");
- if (first_time)
- first_time = 0;
- }
- void
- ShutdownDontSaveXtProc(Widget w, XtPointer client_data, XtPointer callData)
- {
- List *cl;
- ClientRec *client;
- if (ListCount (RunningList) == 0)
- EndSession (0);
- /*
- * For any client that was not restarted by the session
- * manager (previous ID was NULL), if we did not issue a
- * checkpoint to this client, remove the client's checkpoint
- * file using the discard command.
- */
- for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
- {
- client = (ClientRec *) cl->thing;
- if (!client->restarted &&
- !client->userIssuedCheckpoint &&
- client->discardCommand)
- {
- execute_system_command (client->discardCommand);
- XtFree (client->discardCommand);
- client->discardCommand = NULL;
- }
- }
- shutdownInProgress = True;
- for (cl = ListFirst (RunningList); cl; cl = ListNext (cl))
- {
- client = (ClientRec *) cl->thing;
- SmsDie (client->smsConn);
- if (verbose)
- {
- printf ("Client Id = %s, sent DIE\n", client->clientId);
- }
- }
- }
|