Last of the spelling fixed
[oweals/cde.git] / cde / programs / dtstyle / SaveRestore.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*$XConsortium: SaveRestore.c /main/5 1996/03/25 00:53:19 pascale $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  **
27  **   File:        SaveRestore.c
28  **
29  **   Project:     DT 3.0
30  **
31  **   Description: Controls the Dtstyle Save/Restore functionality
32  **
33  **
34  ****************************************************************************
35  ************************************<+>*************************************/
36 /*
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.
44  */
45
46 /*+++++++++++++++++++++++++++++++++++++++*/
47 /* include files                         */
48 /*+++++++++++++++++++++++++++++++++++++++*/
49
50 #include <stdio.h>
51
52 #include <X11/Xlib.h>
53
54 #include <Xm/Xm.h>
55 #include <Xm/XmP.h>
56 #include <Xm/Form.h>
57 #include <Xm/LabelG.h>
58 #include <Xm/PushBG.h>
59 #include <Xm/Scale.h>
60
61 #include <Dt/DialogBox.h>
62
63 #include <Dt/HourGlass.h>
64 #include <Dt/UserMsg.h>
65
66 #include "Main.h"
67
68 /*+++++++++++++++++++++++++++++++++++++++*/
69 /* include extern functions              */
70 /*+++++++++++++++++++++++++++++++++++++++*/
71 #include "SaveRestore.h"
72
73 /*+++++++++++++++++++++++++++++++++++++++*/
74 /* Local #defines                        */
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"))
78
79
80 /************************************************************************
81  *
82  *  saveSessionCB
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.
87  *
88  ************************************************************************/
89 void 
90 saveSessionCB(
91         Widget w,
92         XtPointer client_data,
93         XtPointer call_data )
94 {
95   char *longpath, *name;
96   int fd, n; 
97   char *xa_CommandStr[3];
98   unsigned char *data = NULL;
99   char *tmpStr;
100
101 #ifdef _SUN_OS
102   char *noCommands = NULL;
103 #endif /*  _SUN_OS */
104
105   /* get the root window property of SaveMode */
106   GetSessionSaveMode(&data );
107   
108   /* if the property is "home" don't save dtstyle */
109   if(strcmp((char *)data, "home") == 0)
110   {
111 #ifdef _SUN_OS   /*  Sun doesn't like "NULL" when expecting "char **" */
112      XSetCommand(style.display, XtWindow(w), &noCommands, 0);
113 #else
114      XSetCommand(style.display, XtWindow(w), NULL, 0);
115 #endif /* _SUN_OS */
116      return;
117   }
118
119   /* Xt may not pass a widget as advertised */
120   if(!XtIsShell(w))
121     DtSessionSavePath(XtParent(w), &longpath, &name);
122   else
123     DtSessionSavePath(w, &longpath, &name);
124
125   /*  Create the session file  */
126   if ((fd = creat (longpath, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
127     {
128       tmpStr = (char *)XtMalloc(strlen(MSG2) + strlen(longpath)+ 1);
129       sprintf(tmpStr, MSG2, longpath);
130       _DtSimpleErrnoError(progName,DtError, MSG1, tmpStr, NULL);   
131       XtFree(tmpStr);
132       XtFree ((char *)longpath);
133       XtFree ((char *)name);
134       return;
135     }
136
137   /*write out each needed resource*/
138   saveMain(fd);
139   saveColor(fd);
140   saveColorEdit(fd);
141   saveFonts(fd);
142   saveBackdrop(fd);
143   saveKeybd(fd);
144   saveMouse(fd);
145   saveAudio(fd);
146   saveScreen(fd);
147   saveDtwm(fd);
148   saveStartup(fd);
149   saveI18n(fd);
150   
151   close (fd);
152
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.*/
156   callCancels();
157
158   n = 0;
159   xa_CommandStr[n] = style.execName; n++;
160   xa_CommandStr[n] =  "-session"; n++;
161   xa_CommandStr[n] = name; n++;
162
163   XSetCommand(style.display, XtWindow(w), xa_CommandStr, n);
164   XtFree ((char *)longpath);
165   XtFree ((char *)name);
166
167 /*  Don't exit yet, SM needs time to get the new commandStr.*/
168 }
169
170
171 /************************************************************************
172  *
173  *  RestoreSession
174  *      Open the file as a resource data base, and use the data to
175  *      set the dialog position and (optionally) size.
176  *
177  ************************************************************************/
178
179 Boolean 
180 restoreSession(
181         Widget shell,
182         char *name )
183 {
184   XrmDatabase db;
185   char *tmpStr;
186   char *longpath;
187   Boolean status;
188
189   status = DtSessionRestorePath(shell, &longpath, name);
190   if (!status)
191       return(1);
192   
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);   
198     XtFree(tmpStr);
199     XtFree(longpath);
200     return(1);
201   }
202
203   restoreMain(shell, db);   /* Must happen first */
204
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);
217
218   XrmDestroyDatabase(db);
219
220   XtFree(longpath);
221   return(0);
222 }