Annotation of hatari/src/gui-sdl/dlgFloppy.c, revision 1.1.1.3

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

unix.superglobalmegacorp.com

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