OSDN Git Service

[Win32][UI][Qt] Fix character encoding of recent files.
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / util_cmt.cpp
1 /*
2  * UI->Qt->MainWindow : CMT Utils.
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  * License: GPLv2
5  *
6  * History:
7  * Jan 24, 2014 : Moved from some files.
8  */
9
10
11 #include "commonclasses.h"
12 #include "mainwidget.h"
13 #include "qt_dialogs.h"
14 #include "emu.h"
15 #include "agar_logger.h"
16
17 #include "menu_cmt.h"
18
19
20 void Object_Menu_Control::start_insert_play_cmt(void) {
21         //AGAR_DebugLog(AGAR_LOG_DEBUG, "%d", play);
22         emit sig_insert_play_cmt(play);
23 }
24 void Object_Menu_Control::eject_cmt(void) {
25         emit sig_eject_cmt();
26 }
27 void Object_Menu_Control::on_recent_cmt(){
28         emit sig_recent_cmt(s_num);
29 }
30 void Object_Menu_Control::do_set_write_protect_cmt(void) {
31          write_protect = true;
32          emit sig_set_write_protect_cmt(write_protect);
33 }
34 void Object_Menu_Control::do_unset_write_protect_cmt(void) {
35         write_protect = false;
36         emit sig_set_write_protect_cmt(write_protect);
37 }
38
39
40 void Ui_MainWindow::CreateCMTMenu(void)
41 {
42 #if defined(USE_TAPE)
43         QString ext_play;
44         QString ext_rec;
45         QString desc_play;
46         QString desc_rec;
47         
48         listCMT.clear();
49         menu_CMT = new Menu_CMTClass(emu, menubar, "Object_CMT_Menu", this, 0);
50         menu_CMT->setObjectName(QString::fromUtf8("menuCMT", -1));
51         
52         menu_CMT->create_pulldown_menu();       
53         // Translate Menu
54         SETUP_HISTORY(config.recent_tape_path, listCMT);
55         menu_CMT->do_set_write_protect(false);
56         menu_CMT->do_update_histories(listCMT);
57         menu_CMT->do_set_initialize_directory(config.initial_tape_dir);
58         
59 #if defined(_PC6001) || defined(_PC6001MK2) || defined(_PC6001MK2SR) || defined(_PC6601) || defined(_PC6601SR)
60         ext_play = "*.wav *.p6 *.cas";
61         ext_rec = "*.wav *.p6 *.cas";
62 #elif defined(_PC8001SR) || defined(_PC8801MA) || defined(_PC98DO)
63         ext_play = "*.cas *.cmt *.n80 *.t88";
64         ext_rec  = "*.cas *.cmt";
65 #elif defined(_MZ80A) || defined(_MZ80K) || defined(_MZ1200) || defined(_MZ700) || defined(_MZ800) || defined(_MZ1500)
66         ext_play = "*.wav *.cas *.mzt *.m12 *.t77";
67         ext_rec = "*.wav *.cas";
68 #elif defined(_MZ80B) || defined(_MZ2000) || defined(_MZ2200)
69         ext_play = "*.wav *.cas *.mzt *.mti *.mtw *.dat";
70         ext_rec =  "*.wav *.cas";
71 #elif defined(_X1) || defined(_X1TWIN) || defined(_X1TURBO) || defined(_X1TURBOZ)
72         ext_play = "*.wav *.cas *.tap *.t77";
73         ext_rec =  "*.wav *.cas";
74 #elif defined(_FM8) || defined(_FM7) || defined(_FMNEW7) || defined(_FM77_VARIANTS) || defined(_FM77AV_VARIANTS)
75         ext_play = "*.wav *.t77";
76         ext_rec = "*.wav *.t77";
77 #elif defined(TAPE_BINARY_ONLY)
78         ext_play = "*.cas *.cmt";
79         ext_rec = "*.cas *.cmt";
80 #else
81         ext_play = "*.wav *.cas";
82         ext_rec = "*.wav *.cas";
83 #endif
84         desc_play = "Data Recorder Tape [Play]";
85         desc_rec  = "Data Recorder Tape [Rec]";
86
87         menu_CMT->do_add_media_extension(ext_play, desc_play);
88         menu_CMT->do_add_rec_media_extension(ext_rec, desc_rec);
89 #endif // USE_TAPE
90 }
91
92 void Ui_MainWindow::CreateCMTPulldownMenu(void)
93 {
94 }
95
96
97 #ifdef USE_TAPE
98 int Ui_MainWindow::set_recent_cmt(int drv, int num) 
99 {
100         QString s_path;
101         char path_shadow[PATH_MAX];
102         int i;
103         if((num < 0) || (num >= MAX_HISTORY)) return -1;
104     
105         s_path = QString::fromLocal8Bit(config.recent_tape_path[num]);
106         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX);
107         UPDATE_HISTORY(path_shadow, config.recent_tape_path, listCMT);
108    
109         get_parent_dir(path_shadow);
110         strcpy(config.initial_tape_dir, path_shadow);
111         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX);
112         AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open READ");
113         
114         emit sig_close_tape();
115         emit sig_play_tape(s_path);
116         menu_CMT->do_update_histories(listCMT);
117         menu_CMT->do_set_initialize_directory(config.initial_tape_dir);
118         return 0;
119 }
120
121 void Ui_MainWindow::do_write_protect_cmt(int drv, bool flag)
122 {
123         cmt_write_protect = flag;
124         //menu_CMT->do_set_write_protect(flag);
125 }
126
127
128 # ifdef USE_TAPE_BUTTON
129 void Ui_MainWindow::do_push_play_tape(void)
130 {
131         // Do notify?
132         emit sig_cmt_push_play();
133 }
134
135 void Ui_MainWindow::do_push_stop_tape(void)
136 {
137         // Do notify?
138         emit sig_cmt_push_stop();
139 }
140
141 void Ui_MainWindow::do_display_tape_play(bool flag)
142 {
143         //if(flag) {
144         //      actionPlay_Start->setChecked(true);
145         //} else {
146         //      actionPlay_Stop->setChecked(true);
147         //}
148 }
149  
150 void Ui_MainWindow::do_push_fast_forward_tape(void)
151 {
152         // Do notify?
153         emit sig_cmt_push_fast_forward();
154 }
155 void Ui_MainWindow::do_push_rewind_tape(void)
156 {
157         // Do notify?
158         emit sig_cmt_push_fast_rewind();
159 }
160 void Ui_MainWindow::do_push_apss_forward_tape(void)
161 {
162         // Do notify?
163         emit sig_cmt_push_apss_forward();
164 }
165 void Ui_MainWindow::do_push_apss_rewind_tape(void)
166 {
167         // Do notify?
168         emit sig_cmt_push_apss_rewind();
169 }
170 # endif
171 #endif
172
173 #ifdef USE_TAPE
174 void Ui_MainWindow::set_wave_shaper(bool f)
175 {
176         if(f) {
177                 config.wave_shaper = 1;
178         } else {
179                 config.wave_shaper = 0;
180         }
181 }
182
183 bool Ui_MainWindow::get_wave_shaper(void)
184 {
185         if(config.wave_shaper == 0) return false;
186         return true;
187 }
188 #endif // USE_TAPE
189
190 #ifdef USE_TAPE
191 void Ui_MainWindow::set_direct_load_from_mzt(bool f)
192 {
193         if(f) {
194                 config.direct_load_mzt = 1;
195         } else {
196                 config.direct_load_mzt = 0;
197         }
198 }
199
200 bool Ui_MainWindow::get_direct_load_mzt(void)
201 {
202         if(config.direct_load_mzt == 0) return false;
203         return true;
204 }
205 #endif // USE_TAPE
206
207 void Ui_MainWindow::_open_cmt(bool mode, const QString path)
208 {
209 }
210
211 void Ui_MainWindow::eject_cmt(void) 
212 {
213 #ifdef USE_TAPE
214         emit sig_close_tape();
215 #endif
216 }
217
218 void Ui_MainWindow::ConfigCMTMenuSub(void)
219 {
220 }
221
222 #ifdef USE_TAPE
223 void Ui_MainWindow::do_open_read_cmt(int dummy, QString path) 
224 {
225         char path_shadow[PATH_MAX];
226         int i;
227
228         if(path.length() <= 0) return;
229         strncpy(path_shadow, path.toLocal8Bit().constData(), PATH_MAX);
230         UPDATE_HISTORY(path_shadow, config.recent_tape_path, listCMT);
231         get_parent_dir(path_shadow);
232         strcpy(config.initial_tape_dir, path_shadow);
233         // Copy filename again.
234         strncpy(path_shadow, path.toLocal8Bit().constData(), PATH_MAX);
235
236         emit sig_close_tape();
237         AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open READ : filename = %s", path_shadow);
238         emit sig_play_tape(path);
239         menu_CMT->do_update_histories(listCMT);
240         menu_CMT->do_set_initialize_directory(config.initial_tape_dir);
241 }
242
243 void Ui_MainWindow::do_open_write_cmt(QString path) 
244 {
245         char path_shadow[PATH_MAX];
246         int i;
247
248         if(path.length() <= 0) return;
249         strncpy(path_shadow, path.toLocal8Bit().constData(), PATH_MAX);
250         UPDATE_HISTORY(path_shadow, config.recent_tape_path, listCMT);
251         get_parent_dir(path_shadow);
252         strcpy(config.initial_tape_dir, path_shadow);
253         // Copy filename again.
254         strncpy(path_shadow, path.toLocal8Bit().constData(), PATH_MAX);
255
256         emit sig_close_tape();
257         if(menu_CMT->getWriteProtect() != false) {
258                 AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open READ : filename = %s", path_shadow);
259                 emit sig_play_tape(path);
260         } else {
261                 AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open Write : filename = %s", path_shadow);
262                 emit sig_rec_tape(path);
263         }
264         menu_CMT->do_update_histories(listCMT);
265         menu_CMT->do_set_initialize_directory(config.initial_tape_dir);
266 }
267 #endif
268
269
270 void Ui_MainWindow::retranslateCMTMenu(void)
271 {
272 #ifdef USE_TAPE
273         menu_CMT->retranslateUi();
274 #endif  
275 }
276
277 void Ui_MainWindow::ConfigCMTMenu(void)
278 {
279 #if defined(USE_TAPE)
280         ConfigCMTMenuSub(); 
281 #endif
282 }