1 /*******************************************************************************
5 ** $TOG: session.c /main/6 1997/06/18 17:28:49 samborn $
7 ** RESTRICTED CONFIDENTIAL INFORMATION:
9 ** The information in this document is subject to special
10 ** restrictions in a confidential disclosure agreement between
11 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
12 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
13 ** Sun's specific written approval. This document and all copies
14 ** and derivative works thereof must be returned or destroyed at
17 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
19 *******************************************************************************/
22 * (c) Copyright 1993, 1994 Hewlett-Packard Company
23 * (c) Copyright 1993, 1994 International Business Machines Corp.
24 * (c) Copyright 1993, 1994 Novell, Inc.
25 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
34 #include <Xm/AtomMgr.h>
36 #include <Dt/Session.h>
40 extern Calendar *calendar;
42 /* Structure used on a save session to see if a dt is iconic */
48 /***************************************************************************
50 * Routine: CMSaveSessionCB *
52 * Purpose: save state information for session management *
53 **************************************************************************/
58 XtPointer callbackArg)
69 Dimension width, height;
71 Atom wmStateAtom, actualType;
76 if (!DtSessionSavePath(calendar->frame, &path, &name))
81 /* Create the session file */
82 if (!(fp = fopen(path, "w+"))) {
83 printf("fopen of %s failed. %p \n", path, fp);
84 XtFree ((char *)path);
85 XtFree ((char *)name);
89 chmod(path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP);
91 /* The initial set up is done on the file. From here on
92 out the application should write out a set of resource
93 definitions that will later be read in. These resource
94 definitions will be used to restore the syate of the tool
95 when the session is restarted. */
97 /* Getting the WM_STATE property to see if iconified or not */
98 wmStateAtom = XmInternAtom(XtDisplay(calendar->frame),
101 XGetWindowProperty(XtDisplay(calendar->frame),
102 XtWindow(calendar->frame),
103 wmStateAtom, 0L, (long)BUFSIZ, False,
104 wmStateAtom, &actualType, &actualFormat,
105 &nitems, &leftover, (unsigned char **) &wmState);
107 if (wmState->state == IconicState)
108 fprintf(fp, "*iconic: True\n");
110 fprintf(fp, "*iconic: False\n");
112 /*** Get and write out the geometry info for our Window ***/
113 x = XtX(calendar->frame);
114 y = XtY(calendar->frame);
115 width = XtWidth(calendar->frame);
116 height = XtHeight(calendar->frame);
118 fprintf(fp, "*x: %d\n", x);
119 fprintf(fp, "*y: %d\n", y);
120 fprintf(fp, "*width: %d\n", width);
121 fprintf(fp, "*height: %d\n", height);
123 if (calendar->view->glance == dayGlance)
124 fprintf (fp, "*defaultView: day\n");
125 else if (calendar->view->glance == weekGlance)
126 fprintf (fp, "*defaultView: week\n");
127 else if (calendar->view->glance == monthGlance)
128 fprintf (fp, "*defaultView: month\n");
130 fprintf (fp, "*defaultView: year\n");
132 /* This is the end of client resource writing. At this point
133 the client will reset the WM_COMMAND property on it's top
134 level window to include the original starting parameters as
135 well as the -session flag and the file to restore with. */
138 command_atom = XA_WM_COMMAND;
139 /* Generate the reinvoking command and add it as the
143 command_len = calendar->view->wm_cmdstrlen +
144 strlen("-session") + strlen(name) + 2;
146 command_len = calendar->view->wm_cmdstrlen + 2;
148 command = XtMalloc (sizeof (char) * command_len);
150 memcpy(command, calendar->view->wm_cmdstr,
151 calendar->view->wm_cmdstrlen);
152 command_len = calendar->view->wm_cmdstrlen;
155 memcpy(command + command_len, "-session", 8);
157 command[command_len] = NULL;
159 memcpy(command + command_len, name, strlen(name));
160 command_len += strlen(name);
163 XChangeProperty(XtDisplay(calendar->frame), XtWindow(calendar->frame),
164 command_atom, XA_STRING, 8, PropModeReplace,
165 (unsigned char *)command,
170 /* Note the bogus use of XtFree here. DtSessionSavePath requires that
171 the returned strings be freed this way. Yick. */
174 XtFree((char *)path);
175 XtFree((char *)name);
180 /***************************************************************************
182 * Routine: GetSessionInfo *
184 * Purpose: get dticon session information *
185 **************************************************************************/
194 XrmRepresentation rep_type;
197 if (c->app_data->session_file == NULL)
200 /*** Open the resource database file ***/
202 if (DtSessionRestorePath(c->frame, &path, c->app_data->session_file)
204 /* XXX: Should generate error about not being able to restore session.*/
208 if ((c->view->sessiondb = XrmGetFileDatabase (path)) == NULL) {
209 if (path) XtFree(path);
213 if (path) XtFree(path);
217 /* get default view */
218 xrm_name[0] = XrmStringToQuark ("defaultView");
219 if (XrmQGetResource(c->view->sessiondb, xrm_name, xrm_name,
220 &rep_type, &value)) {
222 c->app_data->default_view = strdup(value.addr);