Annotation of previous/src/gui-sdl/dlgFloppy.c, revision 1.1

1.1     ! root        1: /*
        !             2:   Hatari - dlgFloppy.c
        !             3: 
        !             4:   This file is distributed under the GNU Public License, version 2 or at
        !             5:   your option any later version. Read the file gpl.txt for details.
        !             6: */
        !             7: const char DlgFloppy_fileid[] = "Hatari dlgFloppy.c : " __DATE__ " " __TIME__;
        !             8: 
        !             9: #include <assert.h>
        !            10: #include "main.h"
        !            11: #include "configuration.h"
        !            12: #include "dialog.h"
        !            13: #include "sdlgui.h"
        !            14: #include "file.h"
        !            15: 
        !            16: 
        !            17: #define FLOPPYDLG_EJECTA      3
        !            18: #define FLOPPYDLG_BROWSEA     4
        !            19: #define FLOPPYDLG_DISKA       5
        !            20: #define FLOPPYDLG_EJECTB      7
        !            21: #define FLOPPYDLG_BROWSEB     8
        !            22: #define FLOPPYDLG_DISKB       9
        !            23: #define FLOPPYDLG_IMGDIR      11
        !            24: #define FLOPPYDLG_BROWSEIMG   12
        !            25: #define FLOPPYDLG_AUTOB       13
        !            26: #define FLOPPYDLG_SLOWFLOPPY  14
        !            27: #define FLOPPYDLG_CREATEIMG   15
        !            28: #define FLOPPYDLG_PROTOFF     17
        !            29: #define FLOPPYDLG_PROTON      18
        !            30: #define FLOPPYDLG_PROTAUTO    19
        !            31: #define FLOPPYDLG_EXIT        20
        !            32: 
        !            33: 
        !            34: /* The floppy disks dialog: */
        !            35: static SGOBJ floppydlg[] =
        !            36: {
        !            37:        { SGBOX, 0, 0, 0,0, 64,20, NULL },
        !            38:        { SGTEXT, 0, 0, 25,1, 12,1, "Floppy disks" },
        !            39:        { SGTEXT, 0, 0, 2,3, 8,1, "Drive A:" },
        !            40:        { SGBUTTON, 0, 0, 46,3, 7,1, "Eject" },
        !            41:        { SGBUTTON, 0, 0, 54,3, 8,1, "Browse" },
        !            42:        { SGTEXT, 0, 0, 3,4, 58,1, NULL },
        !            43:        { SGTEXT, 0, 0, 2,6, 8,1, "Drive B:" },
        !            44:        { SGBUTTON, 0, 0, 46,6, 7,1, "Eject" },
        !            45:        { SGBUTTON, 0, 0, 54,6, 8,1, "Browse" },
        !            46:        { SGTEXT, 0, 0, 3,7, 58,1, NULL },
        !            47:        { SGTEXT, 0, 0, 2,9, 32,1, "Default floppy images directory:" },
        !            48:        { SGTEXT, 0, 0, 3,10, 58,1, NULL },
        !            49:        { SGBUTTON, 0, 0, 54,9, 8,1, "Browse" },
        !            50:        { SGCHECKBOX, 0, 0, 2,12, 16,1, "Auto insert B" },
        !            51:        { SGCHECKBOX, 0, 0, 2,14, 21,1, "Slow floppy access" },
        !            52:        { SGBUTTON, 0, 0, 42,14, 20,1, "Create blank image" },
        !            53:        { SGTEXT, 0, 0, 2,16, 17,1, "Write protection:" },
        !            54:        { SGRADIOBUT, 0, 0, 21,16, 5,1, "Off" },
        !            55:        { SGRADIOBUT, 0, 0, 28,16, 5,1, "On" },
        !            56:        { SGRADIOBUT, 0, 0, 34,16, 6,1, "Auto" },
        !            57:        { SGBUTTON, SG_DEFAULT, 0, 22,18, 20,1, "Back to main menu" },
        !            58:        { -1, 0, 0, 0,0, 0,0, NULL }
        !            59: };
        !            60: 
        !            61: 
        !            62: #define DLGMOUNT_A       2
        !            63: #define DLGMOUNT_B       3
        !            64: #define DLGMOUNT_CANCEL  4
        !            65: 
        !            66: /* The "Alert"-dialog: */
        !            67: static SGOBJ alertdlg[] =
        !            68: {
        !            69:        { SGBOX, 0, 0, 0,0, 40,6, NULL },
        !            70:        { SGTEXT, 0, 0, 3,1, 30,1, "Insert last created disk to?" },
        !            71:        { SGBUTTON, 0, 0, 3,4, 10,1, "Drive A:" },
        !            72:        { SGBUTTON, 0, 0, 15,4, 10,1, "Drive B:" },
        !            73:        { SGBUTTON, SG_CANCEL, 0, 27,4, 10,1, "Cancel" },
        !            74:        { -1, 0, 0, 0,0, 0,0, NULL }
        !            75: };
        !            76: 
        !            77: 
        !            78: /**
        !            79:  * Let user browse given disk, insert disk if one selected.
        !            80:  */
        !            81: static void DlgDisk_BrowseDisk(char *dlgname, int drive, int diskid)
        !            82: {
        !            83:        char *selname, *zip_path;
        !            84:        const char *tmpname, *realname;
        !            85: 
        !            86:        assert(drive >= 0 && drive < MAX_FLOPPYDRIVES);
        !            87:        if (ConfigureParams.DiskImage.szDiskFileName[drive][0])
        !            88:                tmpname = ConfigureParams.DiskImage.szDiskFileName[drive];
        !            89:        else
        !            90:                tmpname = ConfigureParams.DiskImage.szDiskImageDirectory;
        !            91: 
        !            92:        selname = SDLGui_FileSelect(tmpname, &zip_path, false);
        !            93:        if (!selname)
        !            94:                return;
        !            95: 
        !            96:        if (File_Exists(selname))
        !            97:        {
        !            98:                realname = Floppy_SetDiskFileName(drive, selname, zip_path);
        !            99:                if (realname)
        !           100:                        File_ShrinkName(dlgname, realname, floppydlg[diskid].w);
        !           101:        }
        !           102:        else
        !           103:        {
        !           104:                Floppy_SetDiskFileNameNone(drive);
        !           105:                dlgname[0] = '\0';
        !           106:        }
        !           107:        if (zip_path)
        !           108:                free(zip_path);
        !           109:        free(selname);
        !           110: }
        !           111: 
        !           112: 
        !           113: /**
        !           114:  * Let user browse given directory, set directory if one selected.
        !           115:  */
        !           116: static void DlgDisk_BrowseDir(char *dlgname, char *confname, int maxlen)
        !           117: {
        !           118:        char *str, *selname;
        !           119: 
        !           120:        selname = SDLGui_FileSelect(confname, NULL, false);
        !           121:        if (!selname)
        !           122:                return;
        !           123: 
        !           124:        strcpy(confname, selname);
        !           125:        free(selname);
        !           126: 
        !           127:        str = strrchr(confname, PATHSEP);
        !           128:        if (str != NULL)
        !           129:                str[1] = 0;
        !           130:        File_CleanFileName(confname);
        !           131:        File_ShrinkName(dlgname, confname, maxlen);
        !           132: }
        !           133: 
        !           134: 
        !           135: /**
        !           136:  * Ask whether new disk should be inserted to A: or B: and if yes, insert.
        !           137:  */
        !           138: static void DlgFloppy_QueryInsert(char *namea, int ida, char *nameb, int idb, const char *path)
        !           139: {
        !           140:        const char *realname;
        !           141:        int diskid, dlgid;
        !           142:        char *dlgname;
        !           143: 
        !           144:        SDLGui_CenterDlg(alertdlg);
        !           145:        switch (SDLGui_DoDialog(alertdlg, NULL))
        !           146:        {
        !           147:                case DLGMOUNT_A:
        !           148:                        dlgname = namea;
        !           149:                        dlgid = ida;
        !           150:                        diskid = 0;
        !           151:                        break;
        !           152:                case DLGMOUNT_B:
        !           153:                        dlgname = nameb;
        !           154:                        dlgid = idb;
        !           155:                        diskid = 1;
        !           156:                        break;
        !           157:                default:
        !           158:                        return;
        !           159:        }
        !           160: 
        !           161:        realname = Floppy_SetDiskFileName(diskid, path, NULL);
        !           162:        if (realname)
        !           163:                File_ShrinkName(dlgname, realname, floppydlg[dlgid].w);
        !           164: }
        !           165: 
        !           166: 
        !           167: /**
        !           168:  * Show and process the floppy disk image dialog.
        !           169:  */
        !           170: void DlgFloppy_Main(void)
        !           171: {
        !           172:        int but, i;
        !           173:        char *newdisk;
        !           174:        char dlgname[MAX_FLOPPYDRIVES][64], dlgdiskdir[64];
        !           175: 
        !           176:        SDLGui_CenterDlg(floppydlg);
        !           177: 
        !           178:        /* Set up dialog to actual values: */
        !           179: 
        !           180:        /* Disk name A: */
        !           181:        if (EmulationDrives[0].bDiskInserted)
        !           182:                File_ShrinkName(dlgname[0], ConfigureParams.DiskImage.szDiskFileName[0],
        !           183:                                floppydlg[FLOPPYDLG_DISKA].w);
        !           184:        else
        !           185:                dlgname[0][0] = '\0';
        !           186:        floppydlg[FLOPPYDLG_DISKA].txt = dlgname[0];
        !           187: 
        !           188:        /* Disk name B: */
        !           189:        if (EmulationDrives[1].bDiskInserted)
        !           190:                File_ShrinkName(dlgname[1], ConfigureParams.DiskImage.szDiskFileName[1],
        !           191:                                floppydlg[FLOPPYDLG_DISKB].w);
        !           192:        else
        !           193:                dlgname[1][0] = '\0';
        !           194:        floppydlg[FLOPPYDLG_DISKB].txt = dlgname[1];
        !           195: 
        !           196:        /* Default image directory: */
        !           197:        File_ShrinkName(dlgdiskdir, ConfigureParams.DiskImage.szDiskImageDirectory,
        !           198:                        floppydlg[FLOPPYDLG_IMGDIR].w);
        !           199:        floppydlg[FLOPPYDLG_IMGDIR].txt = dlgdiskdir;
        !           200: 
        !           201:        /* Auto insert disk B: */
        !           202:        if (ConfigureParams.DiskImage.bAutoInsertDiskB)
        !           203:                floppydlg[FLOPPYDLG_AUTOB].state |= SG_SELECTED;
        !           204:        else
        !           205:                floppydlg[FLOPPYDLG_AUTOB].state &= ~SG_SELECTED;
        !           206: 
        !           207:        /* Write protection */
        !           208:        for (i = FLOPPYDLG_PROTOFF; i <= FLOPPYDLG_PROTAUTO; i++)
        !           209:        {
        !           210:                floppydlg[i].state &= ~SG_SELECTED;
        !           211:        }
        !           212:        floppydlg[FLOPPYDLG_PROTOFF+ConfigureParams.DiskImage.nWriteProtection].state |= SG_SELECTED;
        !           213: 
        !           214:        /* Slow floppy access */
        !           215:        if (ConfigureParams.DiskImage.bSlowFloppy)
        !           216:                floppydlg[FLOPPYDLG_SLOWFLOPPY].state |= SG_SELECTED;
        !           217:        else
        !           218:                floppydlg[FLOPPYDLG_SLOWFLOPPY].state &= ~SG_SELECTED;
        !           219: 
        !           220:        /* Draw and process the dialog */
        !           221:        do
        !           222:        {
        !           223:                but = SDLGui_DoDialog(floppydlg, NULL);
        !           224:                switch (but)
        !           225:                {
        !           226:                 case FLOPPYDLG_EJECTA:                         /* Eject disk in drive A: */
        !           227:                        Floppy_SetDiskFileNameNone(0);
        !           228:                        dlgname[0][0] = '\0';
        !           229:                        break;
        !           230:                 case FLOPPYDLG_BROWSEA:                        /* Choose a new disk A: */
        !           231:                        DlgDisk_BrowseDisk(dlgname[0], 0, FLOPPYDLG_DISKA);
        !           232:                        break;
        !           233:                 case FLOPPYDLG_EJECTB:                         /* Eject disk in drive B: */
        !           234:                        Floppy_SetDiskFileNameNone(1);
        !           235:                        dlgname[1][0] = '\0';
        !           236:                        break;
        !           237:                case FLOPPYDLG_BROWSEB:                         /* Choose a new disk B: */
        !           238:                        DlgDisk_BrowseDisk(dlgname[1], 1, FLOPPYDLG_DISKB);
        !           239:                        break;
        !           240:                 case FLOPPYDLG_BROWSEIMG:
        !           241:                        DlgDisk_BrowseDir(dlgdiskdir,
        !           242:                                         ConfigureParams.DiskImage.szDiskImageDirectory,
        !           243:                                         floppydlg[FLOPPYDLG_IMGDIR].w);
        !           244:                        break;
        !           245:                 case FLOPPYDLG_CREATEIMG:
        !           246:                        newdisk = DlgNewDisk_Main();
        !           247:                        if (newdisk)
        !           248:                        {
        !           249:                                DlgFloppy_QueryInsert(dlgname[0], FLOPPYDLG_DISKA,
        !           250:                                                      dlgname[1], FLOPPYDLG_DISKB,
        !           251:                                                      newdisk);
        !           252:                                free(newdisk);
        !           253:                        }
        !           254:                        break;
        !           255:                }
        !           256:        }
        !           257:        while (but != FLOPPYDLG_EXIT && but != SDLGUI_QUIT
        !           258:                && but != SDLGUI_ERROR && !bQuitProgram);
        !           259: 
        !           260:        /* Read values from dialog: */
        !           261: 
        !           262:        for (i = FLOPPYDLG_PROTOFF; i <= FLOPPYDLG_PROTAUTO; i++)
        !           263:        {
        !           264:                if (floppydlg[i].state & SG_SELECTED)
        !           265:                {
        !           266:                        ConfigureParams.DiskImage.nWriteProtection = i-FLOPPYDLG_PROTOFF;
        !           267:                        break;
        !           268:                }
        !           269:        }
        !           270: 
        !           271:        ConfigureParams.DiskImage.bAutoInsertDiskB = (floppydlg[FLOPPYDLG_AUTOB].state & SG_SELECTED);
        !           272:        ConfigureParams.DiskImage.bSlowFloppy = (floppydlg[FLOPPYDLG_SLOWFLOPPY].state & SG_SELECTED);
        !           273: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.