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 /*******************************************************************************
27 ** $TOG: session.c /main/6 1997/06/18 17:28:49 samborn $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company
45 * (c) Copyright 1993, 1994 International Business Machines Corp.
46 * (c) Copyright 1993, 1994 Novell, Inc.
47 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
56 #include <Xm/AtomMgr.h>
58 #include <Dt/Session.h>
62 extern Calendar *calendar;
64 /* Structure used on a save session to see if a dt is iconic */
70 /***************************************************************************
72 * Routine: CMSaveSessionCB *
74 * Purpose: save state information for session management *
75 **************************************************************************/
80 XtPointer callbackArg)
91 Dimension width, height;
93 Atom wmStateAtom, actualType;
98 if (!DtSessionSavePath(calendar->frame, &path, &name))
103 /* Create the session file */
104 if (!(fp = fopen(path, "w+"))) {
105 printf("fopen of %s failed. %p \n", path, fp);
106 XtFree ((char *)path);
107 XtFree ((char *)name);
111 chmod(path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP);
113 /* The initial set up is done on the file. From here on
114 out the application should write out a set of resource
115 definitions that will later be read in. These resource
116 definitions will be used to restore the syate of the tool
117 when the session is restarted. */
119 /* Getting the WM_STATE property to see if iconified or not */
120 wmStateAtom = XmInternAtom(XtDisplay(calendar->frame),
123 XGetWindowProperty(XtDisplay(calendar->frame),
124 XtWindow(calendar->frame),
125 wmStateAtom, 0L, (long)BUFSIZ, False,
126 wmStateAtom, &actualType, &actualFormat,
127 &nitems, &leftover, (unsigned char **) &wmState);
129 if (wmState->state == IconicState)
130 fprintf(fp, "*iconic: True\n");
132 fprintf(fp, "*iconic: False\n");
134 /*** Get and write out the geometry info for our Window ***/
135 x = XtX(calendar->frame);
136 y = XtY(calendar->frame);
137 width = XtWidth(calendar->frame);
138 height = XtHeight(calendar->frame);
140 fprintf(fp, "*x: %d\n", x);
141 fprintf(fp, "*y: %d\n", y);
142 fprintf(fp, "*width: %d\n", width);
143 fprintf(fp, "*height: %d\n", height);
145 if (calendar->view->glance == dayGlance)
146 fprintf (fp, "*defaultView: day\n");
147 else if (calendar->view->glance == weekGlance)
148 fprintf (fp, "*defaultView: week\n");
149 else if (calendar->view->glance == monthGlance)
150 fprintf (fp, "*defaultView: month\n");
152 fprintf (fp, "*defaultView: year\n");
154 /* This is the end of client resource writing. At this point
155 the client will reset the WM_COMMAND property on it's top
156 level window to include the original starting parameters as
157 well as the -session flag and the file to restore with. */
160 command_atom = XA_WM_COMMAND;
161 /* Generate the reinvoking command and add it as the
165 command_len = calendar->view->wm_cmdstrlen +
166 strlen("-session") + strlen(name) + 2;
168 command_len = calendar->view->wm_cmdstrlen + 2;
170 command = XtMalloc (sizeof (char) * command_len);
172 memcpy(command, calendar->view->wm_cmdstr,
173 calendar->view->wm_cmdstrlen);
174 command_len = calendar->view->wm_cmdstrlen;
177 memcpy(command + command_len, "-session", 8);
179 command[command_len] = NULL;
181 memcpy(command + command_len, name, strlen(name));
182 command_len += strlen(name);
185 XChangeProperty(XtDisplay(calendar->frame), XtWindow(calendar->frame),
186 command_atom, XA_STRING, 8, PropModeReplace,
187 (unsigned char *)command,
192 /* Note the bogus use of XtFree here. DtSessionSavePath requires that
193 the returned strings be freed this way. Yick. */
196 XtFree((char *)path);
197 XtFree((char *)name);
202 /***************************************************************************
204 * Routine: GetSessionInfo *
206 * Purpose: get dticon session information *
207 **************************************************************************/
216 XrmRepresentation rep_type;
219 if (c->app_data->session_file == NULL)
222 /*** Open the resource database file ***/
224 if (DtSessionRestorePath(c->frame, &path, c->app_data->session_file)
226 /* XXX: Should generate error about not being able to restore session.*/
230 if ((c->view->sessiondb = XrmGetFileDatabase (path)) == NULL) {
231 if (path) XtFree(path);
235 if (path) XtFree(path);
239 /* get default view */
240 xrm_name[0] = XrmStringToQuark ("defaultView");
241 if (XrmQGetResource(c->view->sessiondb, xrm_name, xrm_name,
242 &rep_type, &value)) {
244 c->app_data->default_view = strdup(value.addr);