OSDN Git Service

[Qt][GUI][WIN32] Fix linkage error building libCSPgui.dll.
[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
8 #include "menu_flags.h"
9
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 int Ui_MainWindowBase::set_d88_slot(int drive, int num)
26 {
27         QString path;
28         if((num < 0) || (num >= 64)) return -1;
29 #if 0
30         path = QString::fromUtf8(emu->d88_file[drive].path);
31         menu_fds[drive]->do_select_inner_media(num);
32         if(emu && emu->d88_file[drive].cur_bank != num) {
33                 emit sig_open_disk(drive, path, num);
34                 if(emu->is_floppy_disk_protected(drive)) {
35                         menu_fds[drive]->do_set_write_protect(true);
36                 } else {
37                         menu_fds[drive]->do_set_write_protect(false);
38                 }
39         }
40 #else
41         if(hRunEmu != NULL) {
42                 path = hRunEmu->get_d88_file_path(drive);
43                 menu_fds[drive]->do_select_inner_media(num);
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         }
53 #endif
54         return 0;
55 }
56
57 void Ui_MainWindowBase::do_update_recent_disk(int drv)
58 {
59         if(hRunEmu == NULL) return;
60         menu_fds[drv]->do_update_histories(listFDs[drv]);
61         menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
62         if(hRunEmu != NULL) {
63 //              if(hRunEmu->get_d88_file_cur_bank(drv) != num) {
64                         if(hRunEmu->is_floppy_disk_protected(drv)) {
65                                 menu_fds[drv]->do_set_write_protect(true);
66                         } else {
67                                 menu_fds[drv]->do_set_write_protect(false);
68                         }
69 //              }
70         }
71 }
72
73
74 extern const _TCHAR* DLL_PREFIX_I get_parent_dir(const _TCHAR* file);
75
76 int Ui_MainWindowBase::set_recent_disk(int drv, int num) 
77 {
78         QString s_path;
79         char path_shadow[PATH_MAX];
80         if((num < 0) || (num >= MAX_HISTORY)) return -1;
81         s_path = QString::fromLocal8Bit(p_config->recent_floppy_disk_path[drv][num]);
82         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1);
83         UPDATE_HISTORY(path_shadow, p_config->recent_floppy_disk_path[drv], listFDs[drv]);
84    
85         strncpy(p_config->initial_floppy_disk_dir,      get_parent_dir((const _TCHAR *)path_shadow), _MAX_PATH - 1);
86         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1);
87
88 //      if(emu) {
89                 emit sig_close_disk(drv);
90                 emit sig_open_disk(drv, s_path, 0);
91                 menu_fds[drv]->do_update_histories(listFDs[drv]);
92                 menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
93                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
94                         UPDATE_D88_LIST(drv, listD88[drv]);
95                         menu_fds[drv]->do_update_inner_media(listD88[drv], 0);
96                 } else {
97                         menu_fds[drv]->do_clear_inner_media();
98                 }
99                 if(using_flags->get_max_drive() >= 2) {
100                         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1);
101                         if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
102                                 if(((drv & 1) == 0) && (drv + 1 < using_flags->get_max_drive()) && (1 < hRunEmu->get_d88_file_bank_num(drv))) {
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                 //emu->LockVM();
131                 emit sig_open_disk(drv, fname, 0);
132                 menu_fds[drv]->do_update_histories(listFDs[drv]);
133                 menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
134                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
135                         UPDATE_D88_LIST(drv, listD88[drv]);
136                         menu_fds[drv]->do_update_inner_media(listD88[drv], 0);
137                 } else {
138                         menu_fds[drv]->do_clear_inner_media();
139                 }
140 //      }
141         if(using_flags->get_max_drive() >= 2) {
142                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
143                         if(((drv & 1) == 0) && (drv + 1 < using_flags->get_max_drive()) && (1 < hRunEmu->get_d88_file_bank_num(drv))) {
144                                 int drv2 = drv + 1;
145                                 emit sig_close_disk(drv2);
146                                 //emu->LockVM();
147                                 strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1);
148                                 emit sig_open_disk(drv2, fname, 1);
149                                 menu_fds[drv2]->do_update_histories(listFDs[drv2]);
150                                 menu_fds[drv2]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
151                                 UPDATE_D88_LIST(drv2, listD88[drv2]);
152                                 menu_fds[drv2]->do_update_inner_media(listD88[drv2], 1);
153                         }
154                 }
155         }
156 }
157
158