Remove functions responsible for the creation of startup preference manager.

This commit is contained in:
Mid Favila 2022-08-21 18:19:13 -04:00
parent 912c653000
commit 568d13677f
2 changed files with 52 additions and 211 deletions

View File

@ -277,9 +277,6 @@ int main (int argc, char *argv[])
/* initialize System Status */ /* initialize System Status */
sysState.isConnected = NO; sysState.isConnected = NO;
/* get some preferences */
getStartupPrefs(mainWindow);
/* set focus to input area */ /* set focus to input area */
/* For Motif 1.0 we should use _XmGrabTheFocus(target) according to FAQ */ /* For Motif 1.0 we should use _XmGrabTheFocus(target) according to FAQ */
XmProcessTraversal(commandInput, XmTRAVERSE_CURRENT); XmProcessTraversal(commandInput, XmTRAVERSE_CURRENT);

View File

@ -77,164 +77,8 @@ Widget nameTextForm;
Widget serverTextForm; Widget serverTextForm;
Widget portTextForm; Widget portTextForm;
void getStartupPrefs(Widget mainWin)
{
Widget prefForm;
Widget portLabel;
Widget child;
XmString labelString;
Arg args[4];
int argcount;
FILE *confFile;
char serverPortNum[6];
char *confFilePath;
argcount = 0;
labelString = XM_STRING_CREATE("Startup Prefs");
XtSetArg(args[argcount], XmNdialogTitle, labelString); argcount++;
XtSetArg(args[argcount], XmNautoUnmanage, True); argcount++;
startPrefDiag = XmCreatePromptDialog(mainWin, "startup_prefs", args, argcount);
XmStringFree(labelString);
/* Now get rid of the things we don't want */
child = XmSelectionBoxGetChild(startPrefDiag, XmDIALOG_SELECTION_LABEL);
XtUnmanageChild(child);
child = XmSelectionBoxGetChild(startPrefDiag, XmDIALOG_TEXT);
XtUnmanageChild(child);
prefForm = XtVaCreateWidget("form", xmFormWidgetClass, startPrefDiag,
XmNfractionBase, 18, NULL);
labelString = XM_STRING_CREATE("Name:");
XtVaCreateManagedWidget("name_label",
xmLabelWidgetClass, prefForm,
XmNlabelString, labelString,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 0,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 0,
NULL);
XmStringFree(labelString);
labelString = XM_STRING_CREATE("Nick:");
XtVaCreateManagedWidget("nick_label",
xmLabelWidgetClass, prefForm,
XmNlabelString, labelString,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 6,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 0,
NULL);
XmStringFree(labelString);
labelString = XM_STRING_CREATE("Server:");
XtVaCreateManagedWidget("server_label",
xmLabelWidgetClass, prefForm,
XmNlabelString, labelString,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 0,
NULL);
XmStringFree(labelString);
nameTextForm = XtVaCreateManagedWidget("name_form",
xmTextFieldWidgetClass, prefForm,
XmNmaxLength, MAX_NAME_LEN,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 0,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 4,
XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 18,
NULL);
nickTextForm = XtVaCreateManagedWidget("nick_form",
xmTextFieldWidgetClass, prefForm,
XmNmaxLength, MAX_NICK_LEN,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 6,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 4,
XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 18,
NULL);
portTextForm = XtVaCreateManagedWidget("port_form",
xmTextFieldWidgetClass, prefForm,
XmNmaxLength, 5,
XmNcolumns, 5,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12,
XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 18,
NULL);
labelString = XM_STRING_CREATE("Port: ");
portLabel = XtVaCreateManagedWidget("port_label",
xmLabelWidgetClass, prefForm,
XmNlabelString, labelString,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12,
XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, portTextForm,
NULL);
XmStringFree(labelString);
serverTextForm = XtVaCreateManagedWidget("server_form",
xmTextFieldWidgetClass, prefForm,
XmNmaxLength, MAX_SERVERNAME_LEN,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 4,
XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, portLabel,
NULL);
XtAddCallback(startPrefDiag, XmNokCallback, okButtStartupCbk, NULL);
XtAddCallback(startPrefDiag, XmNhelpCallback, helpButtStartupCbk, NULL);
XtManageChild(prefForm);
XtManageChild(startPrefDiag);
/* read configuration file */
if ((confFilePath = getPreferencesFilePath()))
{
confFile = fopen (confFilePath, "r");
if (confFile)
{
char buff[FILE_BUFF_SIZE];
char *pos;
fgets(buff, FILE_BUFF_SIZE, confFile);
if (buff[strlen(buff)-1] == '\n')
buff[strlen(buff)-1] = '\0';
if(!strncmp(buff, "DefaultNick", strlen("DefaultNick")))
if ((pos = strchr(buff, ' ')))
strcpy(sysState.myNick, pos+1);
fgets(buff, FILE_BUFF_SIZE, confFile);
if (buff[strlen(buff)-1] == '\n')
buff[strlen(buff)-1] = '\0';
if(!strncmp(buff, "DefaultName", strlen("DefaultName")))
if ((pos = strchr(buff, ' ')))
strcpy(sysState.myName, pos+1);
fgets(buff, FILE_BUFF_SIZE, confFile);
if (buff[strlen(buff)-1] == '\n')
buff[strlen(buff)-1] = '\0';
if(!strncmp(buff, "DefaultServer", strlen("DefaultServer")))
if ((pos = strchr(buff, ' ')))
strcpy(sysState.serverName, pos+1);
fgets(buff, FILE_BUFF_SIZE, confFile);
if (buff[strlen(buff)-1] == '\n')
buff[strlen(buff)-1] = '\0';
if(!strncmp(buff, "DefaultPortNum", strlen("DefaultPortNum")))
if ((pos = strchr(buff, ' ')))
strcpy(serverPortNum, pos+1);
fclose(confFile);
} else
{
printf("config file not found.\n");
strcpy(sysState.myNick, "");
strcpy(sysState.myName, "");
strcpy(sysState.serverName, "");
strcpy(serverPortNum, "");
}
free(confFilePath);
}
XmTextSetString(nickTextForm, sysState.myNick);
XmTextSetString(nameTextForm, sysState.myName);
XmTextSetString(serverTextForm, sysState.serverName);
XmTextSetString(portTextForm, serverPortNum);
}
void okButtStartupCbk() void okButtStartupCbk()
{ {
char *nick; char *nick;
char *name; char *name;
char *server; char *server;
@ -259,18 +103,18 @@ void okButtStartupCbk()
strcpy(theServer, ""); strcpy(theServer, "");
printf("port: %s, %d\n", port, atoi(port)); printf("port: %s, %d\n", port, atoi(port));
if (strlen(port) > 0 && strlen(port) <= 5) if (strlen(port) > 0 && strlen(port) <= 5)
{ {
sysState.port = atoi(port); sysState.port = atoi(port);
if (sysState.port <= 0) if (sysState.port <= 0)
sysState.port = 6666; sysState.port = 6666;
} else } else
sysState.port = 6666; sysState.port = 6666;
connectToServer(theServer, sysState.port); connectToServer(theServer, sysState.port);
} }
void helpButtStartupCbk() void helpButtStartupCbk()
{ {
XmString theXmString, theXmString2; XmString theXmString, theXmString2;
Arg args[8]; Arg args[8];
int argcount; int argcount;
@ -293,13 +137,13 @@ void helpButtStartupCbk()
remove = XmMessageBoxGetChild(startupPrefsHelpDlgBox, XmDIALOG_CANCEL_BUTTON); remove = XmMessageBoxGetChild(startupPrefsHelpDlgBox, XmDIALOG_CANCEL_BUTTON);
XtUnmanageChild(remove); XtUnmanageChild(remove);
XtManageChild(startupPrefsHelpDlgBox); XtManageChild(startupPrefsHelpDlgBox);
} }
/* ---- set preferences ----- */ /* ---- set preferences ----- */
void setPreferences(Widget mainWin) void setPreferences(Widget mainWin)
{ {
Widget prefForm; Widget prefForm;
Widget portLabel; Widget portLabel;
Widget child; Widget child;
@ -327,76 +171,76 @@ void setPreferences(Widget mainWin)
XtUnmanageChild(child); XtUnmanageChild(child);
prefForm = XtVaCreateWidget("form", xmFormWidgetClass, startPrefDiag, prefForm = XtVaCreateWidget("form", xmFormWidgetClass, startPrefDiag,
XmNfractionBase, 18, NULL); XmNfractionBase, 18, NULL);
labelString = XM_STRING_CREATE("Name:"); labelString = XM_STRING_CREATE("Name:");
XtVaCreateManagedWidget("name_label", XtVaCreateManagedWidget("name_label",
xmLabelWidgetClass, prefForm, xmLabelWidgetClass, prefForm,
XmNlabelString, labelString, XmNlabelString, labelString,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 0, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 0,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 0, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 0,
NULL); NULL);
XmStringFree(labelString); XmStringFree(labelString);
labelString = XM_STRING_CREATE("Nick:"); labelString = XM_STRING_CREATE("Nick:");
XtVaCreateManagedWidget("nick_label", XtVaCreateManagedWidget("nick_label",
xmLabelWidgetClass, prefForm, xmLabelWidgetClass, prefForm,
XmNlabelString, labelString, XmNlabelString, labelString,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 6, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 6,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 0, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 0,
NULL); NULL);
XmStringFree(labelString); XmStringFree(labelString);
labelString = XM_STRING_CREATE("Server:"); labelString = XM_STRING_CREATE("Server:");
XtVaCreateManagedWidget("server_label", XtVaCreateManagedWidget("server_label",
xmLabelWidgetClass, prefForm, xmLabelWidgetClass, prefForm,
XmNlabelString, labelString, XmNlabelString, labelString,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 0, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 0,
NULL); NULL);
XmStringFree(labelString); XmStringFree(labelString);
nameTextForm = XtVaCreateManagedWidget("name_form", nameTextForm = XtVaCreateManagedWidget("name_form",
xmTextFieldWidgetClass, prefForm, xmTextFieldWidgetClass, prefForm,
XmNmaxLength, MAX_NAME_LEN, XmNmaxLength, MAX_NAME_LEN,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 0, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 0,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 4, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 4,
XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 18, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 18,
NULL); NULL);
nickTextForm = XtVaCreateManagedWidget("nick_form", nickTextForm = XtVaCreateManagedWidget("nick_form",
xmTextFieldWidgetClass, prefForm, xmTextFieldWidgetClass, prefForm,
XmNmaxLength, MAX_NICK_LEN, XmNmaxLength, MAX_NICK_LEN,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 6, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 6,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 4, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 4,
XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 18, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 18,
NULL); NULL);
portTextForm = XtVaCreateManagedWidget("port_form", portTextForm = XtVaCreateManagedWidget("port_form",
xmTextFieldWidgetClass, prefForm, xmTextFieldWidgetClass, prefForm,
XmNmaxLength, 5, XmNmaxLength, 5,
XmNcolumns, 5, XmNcolumns, 5,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12,
XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 18, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 18,
NULL); NULL);
labelString = XM_STRING_CREATE("Port: "); labelString = XM_STRING_CREATE("Port: ");
portLabel = XtVaCreateManagedWidget("port_label", portLabel = XtVaCreateManagedWidget("port_label",
xmLabelWidgetClass, prefForm, xmLabelWidgetClass, prefForm,
XmNlabelString, labelString, XmNlabelString, labelString,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12,
XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, portTextForm, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, portTextForm,
NULL); NULL);
XmStringFree(labelString); XmStringFree(labelString);
serverTextForm = XtVaCreateManagedWidget("server_form", serverTextForm = XtVaCreateManagedWidget("server_form",
xmTextFieldWidgetClass, prefForm, xmTextFieldWidgetClass, prefForm,
XmNmaxLength, MAX_SERVERNAME_LEN, XmNmaxLength, MAX_SERVERNAME_LEN,
XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12, XmNtopAttachment, XmATTACH_POSITION, XmNtopPosition, 12,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 4, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 4,
XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, portLabel, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, portLabel,
NULL); NULL);
XtAddCallback(startPrefDiag, XmNokCallback, okButtPrefCbk, NULL); XtAddCallback(startPrefDiag, XmNokCallback, okButtPrefCbk, NULL);