OSDN Git Service

1bdf94b3c3031805adf2d9ae869f14bdc7ea6ccd
[csp-qt/common_source_project-fm7.git] / source / src / qt / common / qt_dialogs.cpp
1 /*
2         Skelton for retropc emulator
3
4         Author : K.Ohta <whatisthis.sowhat _at_ gmail.com>
5         Date   : 2015.01.07
6
7         [agar dialogs]
8 */
9
10 #include <stdio.h>
11 #include <string>
12 #include <vector>
13 #include "common.h"
14 #include "emu.h"
15 #include "qt_main.h"
16
17
18 void CSP_DiskParams::_open_disk(QString s) {
19    int d = getDrive();
20    printf("Tray to open disk: %s", s.toUtf8().constData());
21    printf("Drive = %d\n", d);
22    emit do_open_disk(d, s);
23 }
24 void CSP_DiskParams::_open_cart(QString s) {
25    int d = getDrive();
26    emit do_open_cart(d, s);
27 }
28 void CSP_DiskParams::_open_cmt(QString s) {
29    emit do_open_cmt(s);
30 }
31
32 extern "C" 
33 {
34    
35 #ifdef USE_CART1
36
37    
38 void open_cart_dialog(QWidget *hWnd, int drv)
39 {
40                CSP_DiskDialog dlg(hWnd);
41    
42 #if defined(_GAMEGEAR)
43                 QString ext = "*.rom,*.bin,*.gg,*.col";
44                 QString desc = "Game Cartridge";
45 #elif defined(_MASTERSYSTEM)
46                 QString ext = "*.rom,*.bin,*.sms";
47                 QString desc = "Game Cartridge";
48 #elif defined(_PC6001) || defined(_PC6001MK2) || defined(_PC6001MK2SR) || defined(_PC6601) || defined(_PC6601SR)
49                 QString ext = "*.rom,*.bin,*.60";
50                 QString desc = "Game Cartridge";
51 #elif defined(_PCENGINE) || defined(_X1TWIN)
52                 QString ext = "*.rom,*.bin,*.pce";
53                 QString desc = "HuCARD";
54 #else
55                 QString ext = "*.rom,*.bin"; 
56                 QString desc = "Game Cartridge";
57 #endif
58                 QString dirname;
59                 desc = desc + " (" + ext + ")";
60                 QStringList filter(desc);
61                 if(config.initial_cart_dir != NULL) {
62                    dirname = config.initial_cart_dir;           
63                 } else {
64                    _TCHAR app[PATH_MAX];
65                    getcwd(app, PATH_MAX);
66                    dirname = get_parent_dir(app);
67                 }
68                 dlg.param.setDrive(drv);
69                 dlg.setDirectory(dirname);
70                 dlg.setNameFilters(filter); 
71                 QObject::connect(&dlg, SIGNAL(fileSelected(const QString)), dlg.param, SLOT(dlg.param->_open_cart(const QString))); 
72                 dlg.exec();
73 }
74 #endif
75
76
77 #ifdef USE_QD1
78 void OnOpenQDSub(AG_Event *event)
79 {
80   AG_FileType *filetype = (AG_FileType *)AG_PTR(3);
81   char *path = AG_STRING(2);
82   int drv = AG_INT(1);
83   AG_FileDlg *my = (AG_FileDlg *)AG_SELF();
84   if(path) {
85     if(strlen(path) <= 0) return;
86     strncpy(path_shadow, path, AG_PATHNAME_MAX);
87     UPDATE_HISTORY(path, config.recent_quickdisk_path[drv]);
88     get_parent_dir(path_shadow);
89     strcpy(config.initial_quickdisk_dir, path_shadow);
90     if(emu) emu->open_quickdisk(drv, path, 0);
91   }
92 }
93
94 void open_quickdisk_dialog(AG_Widget *hWnd, int drv)
95 {
96    char path_shadow[AG_PATHNAME_MAX];
97   const char *ext = "*.mzt,*.q20,*qdf";
98   char *desc = _N("Quick Disk");
99   QString dirname;
100   AG_Window *win;
101    
102   win = AG_WindowNew(0);
103  
104   dlg = AG_FileDlgNew(win, AG_FILEDLG_MASK_EXT | AG_FILEDLG_ASYNC | AG_FILEDLG_CLOSEWIN);
105   if(dlg == NULL) return;
106   
107   if(config.initial_quickdisk_dir != NULL) {
108     AG_FileDlgSetDirectory(dlg, "%s", config.initial_quickdisk_dir);            
109   } else {
110     char app[PATH_MAX];
111     QDir df;
112     dirname = df.currentPath();
113     strncpy(app, dirname.toUtf8().constData(), PATH_MAX);
114     dirname = get_parent_dir(app);
115   }
116   AG_FileDlgAddType(dlg, desc, ext, OnOpenQDSub, "%i", drv);
117   AG_WindowShow(win);
118   return;
119 }
120 #endif
121
122 #ifdef USE_TAPE
123 void open_tape_dialog(QWidget *hWnd, bool play)
124 {
125   int playf = play ? 1 : 0;
126   QString ext;
127   QString dirname;
128   QString desc;
129   QStringList filter(desc);
130   if(config.initial_tape_dir != NULL) {
131      dirname = config.initial_tape_dir;         
132   } else {
133     char app[PATH_MAX];
134     QDir df;
135     dirname = df.currentPath();
136     strncpy(app, dirname.toUtf8().constData(), PATH_MAX);
137      dirname = get_parent_dir(app);
138   }
139    CSP_DiskDialog dlg(hWnd);
140    dlg.param->setRecMode(play);
141    dlg.setDirectory(dirname);
142    dlg.setNameFilters(filter); 
143    QObject::connect(&dlg, SIGNAL(fileSelected(QString)), dlg.param, SLOT(dlg.param->_open_cmt(QString))); 
144    dlg.exec();
145 }
146 #endif
147 }
148 #if 0 // !
149 #ifdef USE_LASER_DISC
150 void OnOpenLaserDiscSub(AG_Event *event)
151 {
152   AG_FileType *filetype = (AG_FileType *)AG_PTR(2);
153   char *path = AG_STRING(1);
154   char path_shadow[AG_PATHNAME_MAX];
155   AG_FileDlg *my = (AG_FileDlg *)AG_SELF();
156   if(path) {
157     if(strlen(path) <= 0) return;
158     strncpy(path_shadow, path, AG_PATHNAME_MAX);
159     UPDATE_HISTORY(path, config.recent_laser_disc_path);
160     get_parent_dir(path_shadow);
161     strcpy(config.initial_laser_disc_dir, path_shadow);
162     if(emu) emu->open_laser_disc(path);
163   }
164 }
165
166 void open_laser_disc_dialog(AG_Widget *hWnd)
167 {
168   const char *ext = "*.avi,*.mpg,*.mpeg,*.wmv,*.ogv";
169   char *desc = "Laser Disc";
170   AG_Window *win;
171    
172   win = AG_WindowNew(0);
173  
174   AG_FileDlg *dlg = AG_FileDlgNew(win, AG_FILEDLG_MASK_EXT | AG_FILEDLG_ASYNC | AG_FILEDLG_CLOSEWIN);
175   if(dlg == NULL) return;
176   
177   if(config.initial_laser_disc_dir != NULL) {
178     AG_FileDlgSetDirectory(dlg, "%s", config.initial_laser_disc_dir);           
179   } else {
180     _TCHAR app[AG_PATHNAME_MAX];
181     AG_GetCWD(app, AG_PATHNAME_MAX);
182     AG_FileDlgSetDirectory(dlg, "%s", get_parent_dir(app));
183   }
184   AG_FileDlgAddType(dlg, desc, ext, OnOpenLaserDiscSub, "%p", NULL);
185   AG_WindowShow(win);
186   return;
187 }
188 #endif
189
190 #ifdef USE_BINARY_FILE1
191
192 void OnOpenBinarySub(AG_Event *event)
193 {
194   AG_FileType *filetype = (AG_FileType *)AG_PTR(4);
195   char *path = AG_STRING(3);
196   char path_shadow[AG_PATHNAME_MAX];
197   int drv = AG_INT(1);
198   int load = AG_INT(2);
199   AG_FileDlg *my = (AG_FileDlg *)AG_SELF();
200   if(path) {
201     strncpy(path_shadow, path, AG_PATHNAME_MAX);
202     UPDATE_HISTORY(path, config.recent_binary_path[drv]);
203     get_parent_dir(path_shadow);
204     strcpy(config.initial_binary_dir, path_shadow);
205     if(load != 0) {
206       emu->load_binary(drv, path);
207     } else {
208       emu->save_binary(drv, path);
209     }
210   }
211 }
212
213 void open_binary_dialog(AG_Widget *hWnd, int drv, bool load)
214 {
215   const char ext = "*.ram,*.bin";
216   AG_Window *win;
217    
218   int loadf = load ? 1 : 0;
219 #if defined(_PASOPIA) || defined(_PASOPIA7)
220   char *desc = "RAM Pack Cartridge";
221 #else
222   char *desc = "Memory Dump";
223 #endif
224   win = AG_WIndowNew(0);
225   AG_FileDlg *dlg = AG_FileDlgNew(win, AG_FILEDLG_MASK_EXT | AG_FILEDLG_ASYNC | AG_FILEDLG_CLOSEWIN);
226   if(dlg == NULL) return;
227   
228   if(config.initial_binary_dir != NULL) {
229     AG_FileDlgSetDirectory(dlg, "%s", config.initial_binary_dir);               
230   } else {
231     _TCHAR app[AG_PATHNAME_MAX];
232     AG_GetCWD(app, AG_PATHNAME_MAX);
233     AG_FileDlgSetDirectory(dlg, "%s", get_parent_dir(app));
234   }
235   AG_FileDlgAddType(dlg, desc, ext, OnOpenBinarySub, "%i,%i", drv, loadf);
236   AG_WindowShow(win);
237   return;
238
239 }
240 #endif
241 #endif // !
242
243 #ifdef SUPPORT_DRAG_DROP
244 void open_any_file(_TCHAR* path)
245 {
246 #if defined(USE_CART1)
247         if(check_file_extension(path, _T(".rom")) || 
248            check_file_extension(path, _T(".bin")) || 
249            check_file_extension(path, _T(".gg" )) || 
250            check_file_extension(path, _T(".col")) || 
251            check_file_extension(path, _T(".sms")) || 
252            check_file_extension(path, _T(".60" )) || 
253            check_file_extension(path, _T(".pce"))) {
254                 UPDATE_HISTORY(path, config.recent_cart_path[0]);
255                 strcpy(config.initial_cart_dir, get_parent_dir(path));
256                 emu->open_cart(0, path);
257                 return;
258         }
259 #endif
260 #if defined(USE_FD1)
261         if(check_file_extension(path, _T(".d88")) || 
262            check_file_extension(path, _T(".d77")) || 
263            check_file_extension(path, _T(".td0")) || 
264            check_file_extension(path, _T(".imd")) || 
265            check_file_extension(path, _T(".dsk")) || 
266            check_file_extension(path, _T(".fdi")) || 
267            check_file_extension(path, _T(".hdm")) || 
268            check_file_extension(path, _T(".tfd")) || 
269            check_file_extension(path, _T(".xdf")) || 
270            check_file_extension(path, _T(".2d" )) || 
271            check_file_extension(path, _T(".sf7"))) {
272                 UPDATE_HISTORY(path, config.recent_disk_path[0]);
273                 strcpy(config.initial_disk_dir, get_parent_dir(path));
274                 open_disk(0, path, 0);
275                 return;
276         }
277 #endif
278 #if defined(USE_TAPE)
279         if(check_file_extension(path, _T(".wav")) || 
280            check_file_extension(path, _T(".cas")) || 
281            check_file_extension(path, _T(".p6" )) || 
282            check_file_extension(path, _T(".cmt")) || 
283            check_file_extension(path, _T(".n80")) || 
284            check_file_extension(path, _T(".t88")) || 
285            check_file_extension(path, _T(".mzt")) || 
286            check_file_extension(path, _T(".m12")) || 
287            check_file_extension(path, _T(".mti")) || 
288            check_file_extension(path, _T(".mtw")) || 
289            check_file_extension(path, _T(".tap"))) {
290                 UPDATE_HISTORY(path, config.recent_tape_path);
291                 strcpy(config.initial_tape_dir, get_parent_dir(path));
292                 emu->play_tape(path);
293                 return;
294         }
295 #endif
296 #if defined(USE_BINARY_FILE1)
297         if(check_file_extension(path, _T(".ram")) || 
298            check_file_extension(path, _T(".bin"))) {
299                 UPDATE_HISTORY(path, config.recent_binary_path[0]);
300                 strcpy(config.initial_binary_dir, get_parent_dir(path));
301                 emu->load_binary(0, path);
302                 return;
303         }
304 #endif
305 }
306 #endif
307