OSDN Git Service

[UI][Qt] Implement new feature of upstream 2018-12-28.
[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(hRunEmu->get_d88_file_cur_bank(drive) != num) {
35                 emit sig_open_disk(drive, path, num);
36                 if(hRunEmu->is_floppy_disk_protected(drive)) {
37                         menu_fds[drive]->do_set_write_protect(true);
38                 } else {
39                         menu_fds[drive]->do_set_write_protect(false);
40                 }
41         }
42         return 0;
43 }
44
45 void Ui_MainWindowBase::do_update_recent_disk(int drv)
46 {
47         if(hRunEmu == NULL) return;
48         menu_fds[drv]->do_update_histories(listFDs[drv]);
49         menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
50         if(hRunEmu != NULL) {
51 //              if(hRunEmu->get_d88_file_cur_bank(drv) != num) {
52                         if(hRunEmu->is_floppy_disk_protected(drv)) {
53                                 menu_fds[drv]->do_set_write_protect(true);
54                         } else {
55                                 menu_fds[drv]->do_set_write_protect(false);
56                         }
57 //              }
58         }
59 }
60
61
62 extern const _TCHAR* DLL_PREFIX_I get_parent_dir(const _TCHAR* file);
63
64 int Ui_MainWindowBase::set_recent_disk(int drv, int num) 
65 {
66         QString s_path;
67         char path_shadow[PATH_MAX];
68         if((num < 0) || (num >= MAX_HISTORY)) return -1;
69         s_path = QString::fromLocal8Bit(p_config->recent_floppy_disk_path[drv][num]);
70         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1);
71         UPDATE_HISTORY(path_shadow, p_config->recent_floppy_disk_path[drv], listFDs[drv]);
72    
73         strncpy(p_config->initial_floppy_disk_dir,      get_parent_dir((const _TCHAR *)path_shadow), _MAX_PATH - 1);
74         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1);
75
76 //      if(emu) {
77                 emit sig_close_disk(drv);
78                 emit sig_open_disk(drv, s_path, 0);
79                 menu_fds[drv]->do_update_histories(listFDs[drv]);
80                 menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
81                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
82                         UPDATE_D88_LIST(drv, listD88[drv]);
83                         menu_fds[drv]->do_update_inner_media(listD88[drv], 0);
84                 } else {
85                         menu_fds[drv]->do_clear_inner_media();
86                 }
87                 if(using_flags->get_max_drive() >= 2) {
88                         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1);
89                         if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
90                                 if(((drv & 1) == 0) && ((drv + 1) < using_flags->get_max_drive()) && (1 < hRunEmu->get_d88_file_bank_num(drv))) {
91
92                                         int drv2 = drv + 1;
93                                         emit sig_close_disk(drv2);
94                                         emit sig_open_disk(drv2, s_path, 1);
95                                         menu_fds[drv2]->do_update_histories(listFDs[drv2]);
96                                         menu_fds[drv2]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
97                                         UPDATE_D88_LIST(drv2, listD88[drv2]);
98                                         menu_fds[drv2]->do_update_inner_media(listD88[drv2], 1);
99                                 }
100                         }
101                 }
102 //      }
103         return 0;
104 }
105
106 void Ui_MainWindowBase::_open_disk(int drv, const QString fname)
107 {
108         char path_shadow[PATH_MAX];
109
110         if(fname.length() <= 0) return;
111         drv = drv & 7;
112         strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1);
113         UPDATE_HISTORY(path_shadow, p_config->recent_floppy_disk_path[drv], listFDs[drv]);
114         strcpy(p_config->initial_floppy_disk_dir,       get_parent_dir((const _TCHAR *)path_shadow));
115         // Update List
116         strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1);
117 //      if(emu) {
118                 emit sig_close_disk(drv);
119                 emit sig_open_disk(drv, fname, 0);
120                 menu_fds[drv]->do_update_histories(listFDs[drv]);
121                 menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
122                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
123                         UPDATE_D88_LIST(drv, listD88[drv]);
124                         menu_fds[drv]->do_update_inner_media(listD88[drv], 0);
125                 } else {
126                         menu_fds[drv]->do_clear_inner_media();
127                 }
128 //      }
129         if(using_flags->get_max_drive() >= 2) {
130                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
131                         if(((drv & 1) == 0) && (drv + 1 < using_flags->get_max_drive()) && (1 < hRunEmu->get_d88_file_bank_num(drv))) {
132                                 int drv2 = drv + 1;
133                                 emit sig_close_disk(drv2);
134                                 strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1);
135                                 emit sig_open_disk(drv2, fname, 1);
136                                 menu_fds[drv2]->do_update_histories(listFDs[drv2]);
137                                 menu_fds[drv2]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
138                                 UPDATE_D88_LIST(drv2, listD88[drv2]);
139                                 menu_fds[drv2]->do_update_inner_media(listD88[drv2], 1);
140                         }
141                 }
142         }
143 }
144
145 //#endif