diff --git a/src/main.c b/src/main.c index 3a14264..76034be 100644 --- a/src/main.c +++ b/src/main.c @@ -277,9 +277,6 @@ int main (int argc, char *argv[]) /* initialize System Status */ sysState.isConnected = NO; - /* get some preferences */ - getStartupPrefs(mainWindow); - /* set focus to input area */ /* For Motif 1.0 we should use _XmGrabTheFocus(target) according to FAQ */ XmProcessTraversal(commandInput, XmTRAVERSE_CURRENT); diff --git a/src/preferences.c b/src/preferences.c index 83417b4..24b0a1e 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -77,164 +77,8 @@ Widget nameTextForm; Widget serverTextForm; 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() -{ + { char *nick; char *name; char *server; @@ -259,18 +103,18 @@ void okButtStartupCbk() strcpy(theServer, ""); printf("port: %s, %d\n", port, atoi(port)); if (strlen(port) > 0 && strlen(port) <= 5) - { + { sysState.port = atoi(port); if (sysState.port <= 0) sysState.port = 6666; - } else + } else sysState.port = 6666; connectToServer(theServer, sysState.port); -} + } void helpButtStartupCbk() -{ + { XmString theXmString, theXmString2; Arg args[8]; int argcount; @@ -293,13 +137,13 @@ void helpButtStartupCbk() remove = XmMessageBoxGetChild(startupPrefsHelpDlgBox, XmDIALOG_CANCEL_BUTTON); XtUnmanageChild(remove); XtManageChild(startupPrefsHelpDlgBox); -} + } /* ---- set preferences ----- */ void setPreferences(Widget mainWin) -{ + { Widget prefForm; Widget portLabel; Widget child; @@ -327,76 +171,76 @@ void setPreferences(Widget mainWin) XtUnmanageChild(child); prefForm = XtVaCreateWidget("form", xmFormWidgetClass, startPrefDiag, - XmNfractionBase, 18, NULL); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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, okButtPrefCbk, NULL);