OSDN Git Service

[VM] Floppy / CMT : Add Write protection feature, but testing is not enough X-)
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / menu_cmt.cpp
1 /*
2  * Qt / Tape Menu, Utilities
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  * License : GPLv2
5  *   History : 
6  *     Jan 13 2015 : Start
7  */
8
9 #include "menuclasses.h"
10 #include "emu_utils.h"
11 #include "qt_dialogs.h"
12 #include "emu.h"
13 #include "agar_logger.h"
14
15 QT_BEGIN_NAMESPACE
16 void Object_Menu_Control::start_insert_play_cmt(void) {
17   printf("%d", play);
18    emit sig_insert_play_cmt(play);
19 }
20 void Object_Menu_Control::eject_cmt(void) {
21    emit sig_eject_cmt();
22 }
23 void Object_Menu_Control::on_recent_cmt(){
24    emit sig_recent_cmt(s_num);
25 }
26 void Object_Menu_Control::do_set_write_protect_cmt(void) {
27    write_protect = true;
28    emit sig_set_write_protect_cmt(write_protect);
29 }
30 void Object_Menu_Control::do_unset_write_protect_cmt(void) {
31     write_protect = false;
32     emit sig_set_write_protect_cmt(write_protect);
33 }
34
35
36 // Common Routine
37
38 #ifdef USE_TAPE  
39 void Ui_MainWindow::do_write_protect_cmt(bool flag)
40 {
41    write_protect = flag;
42 }
43
44
45 int Ui_MainWindow::set_recent_cmt(int num) 
46  {
47     std::string path;
48     int i;
49     if((num < 0) || (num >= MAX_HISTORY)) return;
50     
51     path = config.recent_tape_path[num];
52     for(int i = num; i > 0; i--) {
53        strcpy(config.recent_tape_path[i], config.recent_tape_path[i - 1]);
54     }
55     strcpy(config.recent_tape_path[0], path.c_str());
56     if(emu) {
57       AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open READ");
58       emu->play_tape(path.c_str()); // Play Readonly, to safety.
59     }
60     for(i = 0; i < MAX_HISTORY; i++) {
61        if(action_Recent_List_CMT[i] != NULL) { 
62           action_Recent_List_CMT[i]->setText(config.recent_tape_path[i]);
63           //emit action_Recent_List_FD[drive][i]->changed();
64        }
65     }
66  }
67
68
69 void Ui_MainWindow::open_cmt_dialog(bool play)
70 {
71   QString ext;
72   QString desc1;
73   QString desc2;
74   CSP_DiskDialog dlg;
75   QString dirname;
76   
77 #if defined(_PC6001) || defined(_PC6001MK2) || defined(_PC6001MK2SR) || defined(_PC6601) || defined(_PC6601SR)
78   ext = "*.wav *.p6 *.cas";
79 #elif defined(_PC8001SR) || defined(_PC8801MA) || defined(_PC98DO)
80   ext = play ? "*.cas *.cmt *.n80 *.t88" : "*.cas *.cmt";
81 #elif defined(_MZ80A) || defined(_MZ80K) || defined(_MZ1200) || defined(_MZ700) || defined(_MZ800) || defined(_MZ1500)
82   ext = play ? "*.wav *.cas *.mzt *.m12" :"*.wav *.cas";
83 #elif defined(_MZ80B) || defined(_MZ2000) || defined(_MZ2200)
84   ext = play ? "*.wav *.cas *.mzt *.mti *.mtw *.dat" : "*.wav *.cas";
85 #elif defined(_X1) || defined(_X1TWIN) || defined(_X1TURBO) || defined(_X1TURBOZ)
86   ext = play ? "*.wav *.cas *.tap" : "*.wav *.cas";
87 #elif defined(_FM7) || defined(_FM77) || defined(_FM77AV) || defined(_FM77AV40)
88   ext = "*.wav *.t77";
89 #elif defined(TAPE_BINARY_ONLY)
90   ext = "*.cas *.cmt";
91 #else
92   ext = "*.wav;*.cas";
93 #endif
94   desc1 = play ? "Data Recorder Tape [Play]" : "Data Recorder Tape [Rec]";
95   if(play) {
96     dlg.setWindowTitle("Open Tape");
97   } else {
98     dlg.setWindowTitle("Record Tape");
99   }
100   desc2 = desc1 + " (" + ext.toLower() + ")";
101   desc1 = desc1 + " (" + ext.toUpper() + ")";
102   if(config.initial_tape_dir != NULL) {
103     dirname = config.initial_tape_dir;          
104   } else {
105     char app[PATH_MAX];
106     QDir df;
107     dirname = df.currentPath();
108     strncpy(app, dirname.toUtf8().constData(), PATH_MAX);
109     dirname = get_parent_dir(app);
110   }
111   QStringList filter;
112   filter << desc1 << desc2;
113   dlg.param->setRecMode(play);
114   dlg.setNameFilters(filter); 
115   QObject::connect(&dlg, SIGNAL(fileSelected(QString)), dlg.param, SLOT(_open_cmt(QString))); 
116   QObject::connect(dlg.param, SIGNAL(do_open_cmt(bool, QString)), this, SLOT(_open_cmt(bool, QString))); 
117   dlg.show();
118   dlg.exec();
119   return;
120 }
121
122 #endif
123
124 void Ui_MainWindow::set_wave_shaper(bool f)
125 {
126   config.wave_shaper = f;
127 }
128 bool Ui_MainWindow::get_wave_shaper(void)
129 {
130   if(config.wave_shaper == 0) return false;
131   return true;
132 }
133
134 void Ui_MainWindow::set_direct_load_from_mzt(bool f)
135 {
136   config.direct_load_mzt = f;
137 }
138 bool Ui_MainWindow::get_direct_load_mzt(void)
139 {
140   if(config.direct_load_mzt == 0) return false;
141   return true;
142 }
143
144 #ifdef USE_TAPE_BUTTON
145 void Ui_MainWindow::OnPushPlayButton(void)
146 {
147   if(emu) emu->push_play();
148 }
149 void Ui_MainWindow::OnPushStopButton(void)
150 {
151   if(emu) emu->push_stop();
152 }
153
154 #endif
155
156 void Ui_MainWindow::_open_cmt(bool mode, const QString path)
157 {
158   char path_shadow[PATH_MAX];
159   int play;
160    
161    play = (mode == false)? 0 : 1;
162 #ifdef USE_TAPE
163   if(path.length() <= 0) return;
164   strncpy(path_shadow, path.toUtf8().constData(), PATH_MAX);
165   UPDATE_HISTORY(path_shadow, config.recent_tape_path);
166   get_parent_dir(path_shadow);
167   strcpy(config.initial_tape_dir, path_shadow);
168   // Copy filename again.
169   strncpy(path_shadow, path.toUtf8().constData(), PATH_MAX);
170   if((play != false) || (write_protect != false)) {
171     AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open READ : filename = %s", path_shadow);
172       emu->play_tape(path_shadow);
173   } else {
174     AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open Write : filename = %s", path_shadow);
175      emu->rec_tape(path_shadow);
176   }
177 #endif
178 }
179
180 void Ui_MainWindow::eject_cmt(void) 
181 {
182   if(emu) emu->close_tape();
183 }
184
185 void Ui_MainWindow::CreateCMTMenu(Ui_MainWindow *p)
186 {
187   menuCMT = new QMenu(menubar);
188   menuCMT->setObjectName(QString::fromUtf8("menuCMT", -1));
189   menuWrite_Protection_CMT = new QMenu(menuCMT);
190   menuWrite_Protection_CMT->setObjectName(QString::fromUtf8("menuWrite_Protection_CMT", -1));
191   //CreateCMTPulldownMenu(p);
192 }
193
194 void Ui_MainWindow::CreateCMTPulldownMenu(Ui_MainWindow *p)
195 {
196   
197   menuCMT->addAction(actionInsert_CMT);
198   menuCMT->addAction(actionEject_CMT);
199   menuCMT->addSeparator();
200   menuCMT->addAction(actionPlay_Start);
201   menuCMT->addAction(actionPlay_Stop);
202   
203   menuCMT->addSeparator();
204   menuCMT_Recent = new QMenu(menuCMT);
205   menuCMT_Recent->setObjectName(QString::fromUtf8("Recent_CMT", -1));
206   menuCMT->addAction(menuCMT_Recent->menuAction());
207   //        menuCMT->addAction(actionRecent_Opened_FD[0]);
208   {
209     int ii;
210     for(ii = 0; ii < MAX_HISTORY; ii++) {
211       menuCMT_Recent->addAction(action_Recent_List_CMT[ii]);
212       action_Recent_List_CMT[ii]->setVisible(true);
213     }
214     
215   }
216   menuCMT->addSeparator();
217   menuCMT->addAction(menuWrite_Protection_CMT->menuAction());
218   menuWrite_Protection_CMT->addAction(actionProtection_ON_CMT);
219   menuWrite_Protection_CMT->addAction(actionProtection_OFF_CMT);
220
221 }
222
223 void Ui_MainWindow::ConfigCMTMenuSub(Ui_MainWindow *p)
224 {
225   
226   actionInsert_CMT = new Action_Control(p);
227   actionInsert_CMT->setObjectName(QString::fromUtf8("actionInsert_CMT"));
228   actionInsert_CMT->binds->setPlay(true);
229   actionInsert_CMT->binds->setNumber(0);
230   
231   actionEject_CMT = new Action_Control(p);
232   actionEject_CMT->setObjectName(QString::fromUtf8("actionEject_CMT"));
233   actionEject_CMT->binds->setPlay(true);
234
235   actionPlay_Start = new Action_Control(p);
236   actionPlay_Start->setObjectName(QString::fromUtf8("actionPlay_Start"));
237   actionPlay_Start->binds->setPlay(true);
238
239   actionPlay_Stop = new Action_Control(p);
240   actionPlay_Stop->setObjectName(QString::fromUtf8("actionPlay_Stop"));
241   actionPlay_Stop->binds->setPlay(true);
242
243   actionRecording = new Action_Control(p);
244   actionRecording->setObjectName(QString::fromUtf8("actionRecording"));
245   actionRecording->binds->setPlay(false);
246   actionRecording->binds->setNumber(0);
247   
248   actionGroup_Opened_CMT = new QActionGroup(p);
249   actionRecent_Opened_CMT = new Action_Control(p);
250   actionRecent_Opened_CMT->setObjectName(QString::fromUtf8("actionRecent_Opened_CMT"));
251   actionRecent_Opened_CMT->binds->setPlay(true);
252   
253   {
254     int ii;
255     actionGroup_Opened_CMT = new QActionGroup(p);
256     actionGroup_Opened_CMT->setExclusive(true);
257     
258     actionRecent_Opened_CMT = new Action_Control(p);
259     actionRecent_Opened_CMT->setObjectName(QString::fromUtf8("actionSelect_Recent_CMT"));
260     actionRecent_Opened_CMT->binds->setPlay(true); // For safety
261     for(ii = 0; ii < MAX_HISTORY; ii++) {
262       action_Recent_List_CMT[ii] = new Action_Control(p);
263       action_Recent_List_CMT[ii]->binds->setPlay(true);
264       action_Recent_List_CMT[ii]->binds->setNumber(ii);
265       action_Recent_List_CMT[ii]->setText(QString::fromUtf8(config.recent_tape_path[ii]));
266       actionGroup_Opened_CMT->addAction(action_Recent_List_CMT[ii]);
267       connect(action_Recent_List_CMT[ii], SIGNAL(triggered()),
268               action_Recent_List_CMT[ii]->binds, SLOT(on_recent_cmt()));
269       connect(action_Recent_List_CMT[ii]->binds, SIGNAL(sig_recent_cmt(int)),
270               this, SLOT(set_recent_cmt(int)));
271     }
272   }
273   
274   {
275     int ii;
276     actionProtection_ON_CMT = new Action_Control(p);
277     actionProtection_ON_CMT->setObjectName(QString::fromUtf8("actionProtection_ON_CMT"));
278     actionProtection_ON_CMT->setCheckable(true);
279     actionProtection_ON_CMT->setChecked(true);
280     actionProtection_OFF_CMT = new Action_Control(p);
281     actionProtection_OFF_CMT->setObjectName(QString::fromUtf8("actionProtection_OFF_CMT"));
282     actionProtection_OFF_CMT->setCheckable(true);
283     actionProtection_OFF_CMT->setChecked(false);
284     connect(actionProtection_OFF_CMT, SIGNAL(triggered()), actionProtection_OFF_CMT->binds, SLOT(do_unset_write_protect_cmt()));
285     connect(actionProtection_OFF_CMT->binds, SIGNAL(sig_set_write_protect_cmt(bool)), this, SLOT(do_write_protect_cmt(bool)));
286
287     connect(actionProtection_ON_CMT, SIGNAL(triggered()), actionProtection_ON_CMT->binds, SLOT(do_set_write_protect_cmt()));
288     connect(actionProtection_ON_CMT->binds, SIGNAL(sig_set_write_protect_cmt(bool)), this, SLOT(do_write_protect_cmt(bool)));
289
290     actionGroup_Protect_CMT = new QActionGroup(p);
291     //actionGroup_Protect_CMT->setExclusive(true);
292     actionGroup_Protect_CMT->addAction(actionProtection_ON_CMT);
293     actionGroup_Protect_CMT->addAction(actionProtection_OFF_CMT);
294     actionProtection_ON_CMT->setActionGroup(actionGroup_Protect_CMT);
295     actionProtection_OFF_CMT->setActionGroup(actionGroup_Protect_CMT);
296     
297   }
298   
299   connect(actionRecording, SIGNAL(triggered()), actionRecording->binds, SLOT(start_insert_play_cmt()));
300   connect(actionRecording->binds, SIGNAL(sig_insert_play_cmt(bool)), this, SLOT(open_cmt_dialog(bool)));
301   connect(actionInsert_CMT, SIGNAL(triggered()), actionInsert_CMT->binds, SLOT(start_insert_play_cmt()));
302   connect(actionInsert_CMT->binds, SIGNAL(sig_insert_play_cmt(bool)), this, SLOT(open_cmt_dialog(bool)));
303   connect(actionEject_CMT, SIGNAL(triggered()), actionEject_CMT->binds, SLOT(eject_cmt()));
304   // Translate Menu
305
306
307 }
308
309 void Ui_MainWindow::retranslateCMTMenu(Ui_MainWindow *p)
310 {
311
312   actionInsert_CMT->setText(QApplication::translate("MainWindow", "Insert", 0, QApplication::UnicodeUTF8));
313   actionEject_CMT->setText(QApplication::translate("MainWindow", "Eject", 0, QApplication::UnicodeUTF8));
314
315   menuCMT_Recent->setTitle(QApplication::translate("MainWindow", "Recent Opened", 0, QApplication::UnicodeUTF8));
316   
317   actionProtection_ON_CMT->setText(QApplication::translate("MainWindow", "Protection ON", 0, QApplication::UnicodeUTF8));
318   actionProtection_OFF_CMT->setText(QApplication::translate("MainWindow", "Protection OFF", 0, QApplication::UnicodeUTF8));
319
320   menuCMT->setTitle(QApplication::translate("MainWindow", "Casette tape" , 0, QApplication::UnicodeUTF8));
321   menuWrite_Protection_CMT->setTitle(QApplication::translate("MainWindow", "Write Protection", 0, QApplication::UnicodeUTF8));
322 }
323                                                                  
324
325
326
327 void Ui_MainWindow::ConfigCMTMenu(Ui_MainWindow *p)
328 {
329   
330 #if defined(USE_TAPE)
331   write_protect = true;
332   ConfigCMTMenuSub(p); 
333 #endif
334    
335 }
336 QT_END_NAMESPACE