2
0

SaveRestore.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. /* include files */
  47. /*+++++++++++++++++++++++++++++++++++++++*/
  48. #include <stdio.h>
  49. #include <X11/Xlib.h>
  50. #include <Xm/Xm.h>
  51. #include <Xm/XmP.h>
  52. #include <Xm/Form.h>
  53. #include <Xm/LabelG.h>
  54. #include <Xm/PushBG.h>
  55. #include <Xm/Scale.h>
  56. #include <Dt/DialogBox.h>
  57. #include <Dt/HourGlass.h>
  58. #include <Dt/UserMsg.h>
  59. #include "Main.h"
  60. /*+++++++++++++++++++++++++++++++++++++++*/
  61. /* include extern functions */
  62. /*+++++++++++++++++++++++++++++++++++++++*/
  63. #include "SaveRestore.h"
  64. /*+++++++++++++++++++++++++++++++++++++++*/
  65. /* Local #defines */
  66. /*+++++++++++++++++++++++++++++++++++++++*/
  67. #define MSG1 ((char *)GETMESSAGE(10, 1, "Check file permissions."))
  68. #define MSG2 ((char *)GETMESSAGE(10, 3, "%s is the file that would have been used to save your session\n"))
  69. /************************************************************************
  70. *
  71. * saveSessionCB
  72. * Creates a file as a resource data base, and writes out all
  73. * info needed to save our current state. This info will be used
  74. * later by restoreSession to start up the help system in the exact
  75. * state in which we saved the session.
  76. *
  77. ************************************************************************/
  78. void
  79. saveSessionCB(
  80. Widget w,
  81. XtPointer client_data,
  82. XtPointer call_data )
  83. {
  84. char *longpath, *name;
  85. int fd, n;
  86. char *xa_CommandStr[3];
  87. unsigned char *data = NULL;
  88. char *tmpStr;
  89. #ifdef _SUN_OS
  90. char *noCommands = NULL;
  91. #endif /* _SUN_OS */
  92. /* get the root window property of SaveMode */
  93. GetSessionSaveMode(&data );
  94. /* if the property is "home" don't save dtstyle */
  95. if(strcmp((char *)data, "home") == 0)
  96. {
  97. #ifdef _SUN_OS /* Sun doesn't like "NULL" when expecting "char **" */
  98. XSetCommand(style.display, XtWindow(w), &noCommands, 0);
  99. #else
  100. XSetCommand(style.display, XtWindow(w), NULL, 0);
  101. #endif /* _SUN_OS */
  102. return;
  103. }
  104. /* Xt may not pass a widget as advertised */
  105. if(!XtIsShell(w))
  106. DtSessionSavePath(XtParent(w), &longpath, &name);
  107. else
  108. DtSessionSavePath(w, &longpath, &name);
  109. /* Create the session file */
  110. if ((fd = creat (longpath, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
  111. {
  112. tmpStr = (char *)XtMalloc(strlen(MSG2) + strlen(longpath)+ 1);
  113. sprintf(tmpStr, MSG2, longpath);
  114. _DtSimpleErrnoError(progName,DtError, MSG1, tmpStr, NULL);
  115. XtFree(tmpStr);
  116. XtFree ((char *)longpath);
  117. XtFree ((char *)name);
  118. return;
  119. }
  120. /*write out each needed resource*/
  121. saveMain(fd);
  122. saveColor(fd);
  123. saveColorEdit(fd);
  124. saveFonts(fd);
  125. saveBackdrop(fd);
  126. saveKeybd(fd);
  127. saveMouse(fd);
  128. saveAudio(fd);
  129. saveScreen(fd);
  130. saveDtwm(fd);
  131. saveStartup(fd);
  132. saveI18n(fd);
  133. close (fd);
  134. /*If this is a session manager requested saveYrSlf, need to put dialogs in*/
  135. /*recoverable state, and make them consistent with server (etc) state.*/
  136. /*Have to do it before exit so SM gets corrected server state.*/
  137. callCancels();
  138. n = 0;
  139. xa_CommandStr[n] = style.execName; n++;
  140. xa_CommandStr[n] = "-session"; n++;
  141. xa_CommandStr[n] = name; n++;
  142. XSetCommand(style.display, XtWindow(w), xa_CommandStr, n);
  143. XtFree ((char *)longpath);
  144. XtFree ((char *)name);
  145. /* Don't exit yet, SM needs time to get the new commandStr.*/
  146. }
  147. /************************************************************************
  148. *
  149. * RestoreSession
  150. * Open the file as a resource data base, and use the data to
  151. * set the dialog position and (optionally) size.
  152. *
  153. ************************************************************************/
  154. Boolean
  155. restoreSession(
  156. Widget shell,
  157. char *name )
  158. {
  159. XrmDatabase db;
  160. char *tmpStr;
  161. char *longpath;
  162. Boolean status;
  163. status = DtSessionRestorePath(shell, &longpath, name);
  164. if (!status)
  165. return(1);
  166. /* Open the file as a resource database */
  167. if ((db = XrmGetFileDatabase (longpath)) == NULL) {
  168. tmpStr = (char *)XtMalloc(strlen(MSG2) + strlen(longpath)+ 1);
  169. sprintf(tmpStr, MSG2, longpath);
  170. _DtSimpleErrnoError(progName, DtError, MSG1, tmpStr, NULL);
  171. XtFree(tmpStr);
  172. XtFree(longpath);
  173. return(1);
  174. }
  175. restoreMain(shell, db); /* Must happen first */
  176. /* Now, Restore the dialogs */
  177. restoreColor(shell, db);
  178. restoreColorEdit(shell, db);
  179. restoreFonts(shell, db);
  180. restoreBackdrop(shell, db);
  181. restoreKeybd(shell, db);
  182. restoreMouse(shell, db);
  183. restoreAudio(shell, db);
  184. restoreScreen(shell, db);
  185. restoreDtwm(shell, db);
  186. restoreStartup(shell, db);
  187. restoreI18n(shell, db);
  188. XrmDestroyDatabase(db);
  189. XtFree(longpath);
  190. return(0);
  191. }