2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*$XConsortium: SaveRestore.c /main/5 1996/03/25 00:53:19 pascale $ */
24 /************************************<+>*************************************
25 ****************************************************************************
27 ** File: SaveRestore.c
31 ** Description: Controls the Dtstyle Save/Restore functionality
34 ****************************************************************************
35 ************************************<+>*************************************/
37 * (c) Copyright 1996 Digital Equipment Corporation.
38 * (c) Copyright 1990, 1996 Hewlett-Packard Company.
39 * (c) Copyright 1996 International Business Machines Corp.
40 * (c) Copyright 1996 Sun Microsystems, Inc.
41 * (c) Copyright 1996 Novell, Inc.
42 * (c) Copyright 1996 FUJITSU LIMITED.
43 * (c) Copyright 1996 Hitachi.
46 /*+++++++++++++++++++++++++++++++++++++++*/
48 /*+++++++++++++++++++++++++++++++++++++++*/
57 #include <Xm/LabelG.h>
58 #include <Xm/PushBG.h>
61 #include <Dt/DialogBox.h>
63 #include <Dt/HourGlass.h>
64 #include <Dt/UserMsg.h>
68 /*+++++++++++++++++++++++++++++++++++++++*/
69 /* include extern functions */
70 /*+++++++++++++++++++++++++++++++++++++++*/
71 #include "SaveRestore.h"
73 /*+++++++++++++++++++++++++++++++++++++++*/
75 /*+++++++++++++++++++++++++++++++++++++++*/
76 #define MSG1 ((char *)GETMESSAGE(10, 1, "Check file permissions."))
77 #define MSG2 ((char *)GETMESSAGE(10, 3, "%s is the file that would have been used to save your session\n"))
80 /************************************************************************
83 * Creates a file as a resource data base, and writes out all
84 * info needed to save our current state. This info will be used
85 * later by restoreSession to start up the help system in the exact
86 * state in which we saved the session.
88 ************************************************************************/
92 XtPointer client_data,
95 char *longpath, *name;
97 char *xa_CommandStr[3];
98 unsigned char *data = NULL;
102 char *noCommands = NULL;
105 /* get the root window property of SaveMode */
106 GetSessionSaveMode(&data );
108 /* if the property is "home" don't save dtstyle */
109 if(strcmp((char *)data, "home") == 0)
111 #ifdef _SUN_OS /* Sun doesn't like "NULL" when expecting "char **" */
112 XSetCommand(style.display, XtWindow(w), &noCommands, 0);
114 XSetCommand(style.display, XtWindow(w), NULL, 0);
119 /* Xt may not pass a widget as advertised */
121 DtSessionSavePath(XtParent(w), &longpath, &name);
123 DtSessionSavePath(w, &longpath, &name);
125 /* Create the session file */
126 if ((fd = creat (longpath, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
128 tmpStr = (char *)XtMalloc(strlen(MSG2) + strlen(longpath)+ 1);
129 sprintf(tmpStr, MSG2, longpath);
130 _DtSimpleErrnoError(progName,DtError, MSG1, tmpStr, NULL);
132 XtFree ((char *)longpath);
133 XtFree ((char *)name);
137 /*write out each needed resource*/
153 /*If this is a session manager requested saveYrSlf, need to put dialogs in*/
154 /*recoverable state, and make them consistent with server (etc) state.*/
155 /*Have to do it before exit so SM gets corrected server state.*/
159 xa_CommandStr[n] = style.execName; n++;
160 xa_CommandStr[n] = "-session"; n++;
161 xa_CommandStr[n] = name; n++;
163 XSetCommand(style.display, XtWindow(w), xa_CommandStr, n);
164 XtFree ((char *)longpath);
165 XtFree ((char *)name);
167 /* Don't exit yet, SM needs time to get the new commandStr.*/
171 /************************************************************************
174 * Open the file as a resource data base, and use the data to
175 * set the dialog position and (optionally) size.
177 ************************************************************************/
189 status = DtSessionRestorePath(shell, &longpath, name);
193 /* Open the file as a resource database */
194 if ((db = XrmGetFileDatabase (longpath)) == NULL) {
195 tmpStr = (char *)XtMalloc(strlen(MSG2) + strlen(longpath)+ 1);
196 sprintf(tmpStr, MSG2, longpath);
197 _DtSimpleErrnoError(progName, DtError, MSG1, tmpStr, NULL);
203 restoreMain(shell, db); /* Must happen first */
205 /* Now, Restore the dialogs */
206 restoreColor(shell, db);
207 restoreColorEdit(shell, db);
208 restoreFonts(shell, db);
209 restoreBackdrop(shell, db);
210 restoreKeybd(shell, db);
211 restoreMouse(shell, db);
212 restoreAudio(shell, db);
213 restoreScreen(shell, db);
214 restoreDtwm(shell, db);
215 restoreStartup(shell, db);
216 restoreI18n(shell, db);
218 XrmDestroyDatabase(db);