OSDN Git Service

881b8e126bbe34375e30dec6c2df853f8c12d16b
[csp-qt/common_source_project-fm7.git] / source / src / qt / common / util_fd2.cpp
1 #include "emu_thread_tmpl.h"
2 #include "mainwidget_base.h"
3 #include "commonclasses.h"
4 #include "menu_disk.h"
5 #include "qt_dialogs.h"
6
7 #include "menu_flags.h"
8
9 //#if defined(USE_FLOPPY_DISK)
10
11 #ifndef UPDATE_D88_LIST
12 #define UPDATE_D88_LIST(__d, lst) { \
13         lst.clear(); \
14         QString __tmps; \
15         for(int iii = 0; iii < 64; iii++) { \
16                 __tmps = QString::fromUtf8(""); \
17                 if(iii < hRunEmu->get_d88_file_bank_num(__d)) {         \
18                         __tmps = hRunEmu->get_d88_file_disk_name(__d, iii); \
19                 } \
20         lst << __tmps; \
21         } \
22 }
23 #endif
24
25
26 //extern DLL_PREFIX_I EMU *emu;
27 int Ui_MainWindowBase::set_d88_slot(int drive, int num)
28 {
29         QString path;
30         if((num < 0) || (num >= 64)) return -1;
31         //path = QString::fromUtf8(emu->d88_file[drive].path);
32         path = hRunEmu->get_d88_file_path(drive);
33         menu_fds[drive]->do_select_inner_media(num);
34 #if 0   
35         if(emu && emu->d88_file[drive].cur_bank != num) {
36                 emit sig_open_disk(drive, path, num);
37                 if(emu->is_floppy_disk_protected(drive)) {
38                         menu_fds[drive]->do_set_write_protect(true);
39                 } else {
40                         menu_fds[drive]->do_set_write_protect(false);
41                 }
42         }
43 #else
44         if(hRunEmu->get_d88_file_cur_bank(drive) != num) {
45                 emit sig_open_disk(drive, path, num);
46                 if(hRunEmu->is_floppy_disk_protected(drive)) {
47                         menu_fds[drive]->do_set_write_protect(true);
48                 } else {
49                         menu_fds[drive]->do_set_write_protect(false);
50                 }
51         }
52 #endif          
53         return 0;
54 }
55
56 void Ui_MainWindowBase::do_update_recent_disk(int drv)
57 {
58         if(hRunEmu == NULL) return;
59         menu_fds[drv]->do_update_histories(listFDs[drv]);
60         menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
61         if(hRunEmu != NULL) {
62 //              if(hRunEmu->get_d88_file_cur_bank(drv) != num) {
63                         if(hRunEmu->is_floppy_disk_protected(drv)) {
64                                 menu_fds[drv]->do_set_write_protect(true);
65                         } else {
66                                 menu_fds[drv]->do_set_write_protect(false);
67                         }
68 //              }
69         }
70 }
71
72
73 extern const _TCHAR* DLL_PREFIX_I get_parent_dir(const _TCHAR* file);
74
75 int Ui_MainWindowBase::set_recent_disk(int drv, int num) 
76 {
77         QString s_path;
78         char path_shadow[PATH_MAX];
79         if((num < 0) || (num >= MAX_HISTORY)) return -1;
80         s_path = QString::fromLocal8Bit(p_config->recent_floppy_disk_path[drv][num]);
81         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1);
82         UPDATE_HISTORY(path_shadow, p_config->recent_floppy_disk_path[drv], listFDs[drv]);
83    
84         strncpy(p_config->initial_floppy_disk_dir,      get_parent_dir((const _TCHAR *)path_shadow), _MAX_PATH - 1);
85         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1);
86
87 //      if(emu) {
88                 emit sig_close_disk(drv);
89                 emit sig_open_disk(drv, s_path, 0);
90                 menu_fds[drv]->do_update_histories(listFDs[drv]);
91                 menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
92                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
93                         UPDATE_D88_LIST(drv, listD88[drv]);
94                         menu_fds[drv]->do_update_inner_media(listD88[drv], 0);
95                 } else {
96                         menu_fds[drv]->do_clear_inner_media();
97                 }
98                 if(using_flags->get_max_drive() >= 2) {
99                         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1);
100                         if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
101                                 if(((drv & 1) == 0) && ((drv + 1) < using_flags->get_max_drive()) && (1 < hRunEmu->get_d88_file_bank_num(drv))) {
102
103                                         int drv2 = drv + 1;
104                                         emit sig_close_disk(drv2);
105                                         emit sig_open_disk(drv2, s_path, 1);
106                                         menu_fds[drv2]->do_update_histories(listFDs[drv2]);
107                                         menu_fds[drv2]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
108                                         UPDATE_D88_LIST(drv2, listD88[drv2]);
109                                         menu_fds[drv2]->do_update_inner_media(listD88[drv2], 1);
110                                 }
111                         }
112                 }
113 //      }
114         return 0;
115 }
116
117 void Ui_MainWindowBase::_open_disk(int drv, const QString fname)
118 {
119         char path_shadow[PATH_MAX];
120
121         if(fname.length() <= 0) return;
122         drv = drv & 7;
123         strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1);
124         UPDATE_HISTORY(path_shadow, p_config->recent_floppy_disk_path[drv], listFDs[drv]);
125         strcpy(p_config->initial_floppy_disk_dir,       get_parent_dir((const _TCHAR *)path_shadow));
126         // Update List
127         strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1);
128 //      if(emu) {
129                 emit sig_close_disk(drv);
130                 emit sig_open_disk(drv, fname, 0);
131                 menu_fds[drv]->do_update_histories(listFDs[drv]);
132                 menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
133                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
134                         UPDATE_D88_LIST(drv, listD88[drv]);
135                         menu_fds[drv]->do_update_inner_media(listD88[drv], 0);
136                 } else {
137                         menu_fds[drv]->do_clear_inner_media();
138                 }
139 //      }
140         if(using_flags->get_max_drive() >= 2) {
141                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
142                         if(((drv & 1) == 0) && (drv + 1 < using_flags->get_max_drive()) && (1 < hRunEmu->get_d88_file_bank_num(drv))) {
143                                 int drv2 = drv + 1;
144                                 emit sig_close_disk(drv2);
145                                 strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1);
146                                 emit sig_open_disk(drv2, fname, 1);
147                                 menu_fds[drv2]->do_update_histories(listFDs[drv2]);
148                                 menu_fds[drv2]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
149                                 UPDATE_D88_LIST(drv2, listD88[drv2]);
150                                 menu_fds[drv2]->do_update_inner_media(listD88[drv2], 1);
151                         }
152                 }
153         }
154 }
155
156 //#endif