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 libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: Main.c /main/5 1999/09/20 14:08:17 mgreess $ */
25 cc -g -o Main Main.c -I/usr/dt/include -I/usr/openwin/include -R/export2/build/SunOS/lib1/DtSvc:/usr/dt/lib:/usr/openwin/lib -L/export2/build/SunOS/lib1/DtSvc -L/usr/dt/lib -L/usr/openwin/lib -lDtSvc -lXt
29 #include <X11/Intrinsic.h>
30 #include <Xm/MessageB.h>
34 #include <Dt/UserMsg.h>
35 #include <Dt/EnvControlP.h>
37 static void DbCacheCreateError(Widget toplevel);
38 static void DbCacheCreateErrorCallback(Widget, XtPointer, XtPointer);
39 static void DieFromToolTalkError(char*, Tt_status);
41 #define ApplicationClass "dtdtscache"
42 #define RebuildMsg "DtDtsCache"
47 main(int argc, char **argv)
49 XtAppContext appContext;
50 Widget toplevel, form;
60 char *locale = setlocale(LC_ALL, "");
67 _DtEnvControl(DT_ENV_SET);
69 if(strcmp(argv[1], "-init") == 0)
80 status = tt_ptr_error(tt_open());
82 "Could not connect to ToolTalk:\n%s\nExiting",
87 status = tt_ptype_declare("SDTDTSCACHE");
89 "Could not declare SDTDTSCACHE ptype:\n%s\nExiting",
93 toplevel = XtAppInitialize(&appContext, ApplicationClass, NULL, 0,
94 &argc, argv, NULL, NULL, 0);
96 if (DtAppInitialize(appContext, XtDisplay(toplevel), toplevel, argv[0],
97 ApplicationClass) == False)
99 _DtSimpleError(ApplicationClass,
102 "%s: Couldn't initialize Dt\n",
106 while(!init_flag && more)
108 msg = tt_message_receive();
111 char *op = tt_message_op(msg);
113 if(strcmp(op, RebuildMsg) != 0)
115 tt_message_reject(msg);
121 if (!_DtDtsMMInit(1))
123 tt_message_reply(msg);
124 DbCacheCreateError(toplevel);
130 tt_message_reply(msg);
132 m = tt_message_create();
133 tt_message_scope_set(m, TT_SESSION);
134 tt_message_class_set(m, TT_NOTICE);
135 tt_message_op_set(m, "DtTypes_Reloaded");
136 tt_message_address_set(m, TT_PROCEDURE);
159 if (!_DtDtsMMInit(1))
162 * Log an error message. Cannot post a dialog because
163 * there is a good chance system is starting up.
165 _DtSimpleError(ApplicationClass, DtFatalError, NULL,
166 "Couldn't create the Desktop Action/DataTypes Database.\n\
167 Check disk space and/or permissions.\n");
174 DbCacheCreateErrorCallback(Widget w, XtPointer userData, XtPointer callData)
177 XFlush(XtDisplay(w));
179 _DtSimpleError(ApplicationClass, DtFatalError, NULL,
180 "Couldn't recreate the Desktop Action/DataTypes Database.\n\
181 Check disk space and/or permissions.\n");
185 * This function posts an error dialog informing the user that creation
186 * of the Actions/DataTypes Database failed.
187 * Wait for the user to acknowledge the error, log a message, and then exit.
190 DbCacheCreateError(Widget toplevel)
199 Dimension dialogWd, dialogHt;
201 title = "dtdbcache failure";
202 messagein = "Couldn't recreate the Desktop Actions/DataTypes Database.\n\
203 Check disk space and/or permissions.";
204 message = XmStringCreateLocalized(messagein);
205 okLabel = XmStringCreateLocalized("OK");
207 /* Post an error dialog */
209 XtSetArg(args[n], XmNtitle, title); n++;
210 XtSetArg(args[n], XmNmessageString, message); n++;
211 XtSetArg(args[n], XmNokLabelString, okLabel); n++;
212 XtSetArg(args[n], XmNdefaultPosition, False); n++;
213 XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
214 err = XmCreateErrorDialog(toplevel, "err", args, n);
216 XmStringFree(okLabel);
217 XmStringFree(message);
219 XtUnmanageChild(XmMessageBoxGetChild(err, XmDIALOG_CANCEL_BUTTON));
220 XtUnmanageChild(XmMessageBoxGetChild(err, XmDIALOG_HELP_BUTTON));
222 /* Center the dialog */
223 XtRealizeWidget(err);
224 XtVaGetValues(err, XmNwidth, &dialogWd, XmNheight, &dialogHt, NULL);
225 XtSetArg(args[0], XmNx,
226 (WidthOfScreen(XtScreen(err)) - dialogWd) / 2);
227 XtSetArg(args[1], XmNy,
228 (HeightOfScreen(XtScreen(err)) - dialogHt) / 2);
229 XtSetValues (err, args, 2);
232 XtSetMappedWhenManaged(err, True);
233 XtAddCallback(err, XmNokCallback, DbCacheCreateErrorCallback,
236 XtAppMainLoop(XtWidgetToApplicationContext(err));
240 DieFromToolTalkError(char *errfmt, Tt_status status)
244 if (! tt_is_err(status)) return;
246 statmsg = tt_status_message(status);
247 _DtSimpleError(ApplicationClass, DtFatalError, NULL, errfmt, statmsg);