2 * Widget: Meta Menu Class.
3 * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
5 * History: 2015-11-11 Initial.
10 #include "qt_dialogs.h"
11 #include "menu_metaclass.h"
12 #include "commonclasses.h"
13 #include "mainwidget.h"
14 #include "commonclasses.h"
18 Menu_MetaClass::Menu_MetaClass(EMU *ep, QMenuBar *root_entry, QString desc, QWidget *parent, int drv) : QMenu(root_entry)
24 menu_root = root_entry;
30 object_desc.append(tmps);
32 for(ii = 0; ii < MAX_D88_BANKS; ii++) {
33 action_select_media_list[ii] = NULL;
36 use_write_protect = true;
37 use_d88_menus = false;
38 initial_dir = QString::fromUtf8("");
42 inner_media_list.clear();
43 window_title = QString::fromUtf8("");
46 Menu_MetaClass::~Menu_MetaClass()
51 // This is virtual function, pls. override.
52 void Menu_MetaClass::do_set_write_protect(bool f)
56 action_write_protect_on->setChecked(true);
58 action_write_protect_off->setChecked(true);
62 void Menu_MetaClass::do_set_initialize_directory(const char *s)
64 initial_dir = QString::fromUtf8(s);
67 void Menu_MetaClass::do_open_media(int drv, QString name) {
68 //write_protect = false; // Right? On D88, May be writing entry exists.
69 emit sig_open_media(drv, name);
72 void Menu_MetaClass::do_insert_media(void) {
73 //write_protect = false; // Right? On D88, May be writing entry exists.
74 emit sig_insert_media(media_drive);
76 void Menu_MetaClass::do_eject_media(void) {
77 write_protect = false;
78 emit sig_eject_media(media_drive);
81 void Menu_MetaClass::do_open_inner_media(int drv, int s_num) {
82 emit sig_set_inner_slot(media_drive, s_num);
85 void Menu_MetaClass::do_open_recent_media(int drv, int s_num){
86 // write_protect = false; // Right? On D88, May be writing entry exists.
87 emit sig_set_recent_media(media_drive, s_num);
89 void Menu_MetaClass::do_write_protect_media(void) {
92 action_write_protect_on->setChecked(true);
94 action_write_protect_off->setChecked(true);
96 emit sig_write_protect_media(media_drive, write_protect);
99 void Menu_MetaClass::do_write_unprotect_media(void) {
100 write_protect = false;
102 action_write_protect_on->setChecked(true);
104 action_write_protect_off->setChecked(true);
106 emit sig_write_protect_media(media_drive, write_protect);
109 void Menu_MetaClass::do_set_window_title(QString s) {
113 void Menu_MetaClass::do_add_media_extension(QString ext, QString description)
115 QString tmps = description;
116 QString all = QString::fromUtf8("All Files (*.*)");
118 tmps.append(QString::fromUtf8(" ("));
119 tmps.append(ext.toLower());
120 tmps.append(QString::fromUtf8(" "));
121 tmps.append(ext.toUpper());
122 tmps.append(QString::fromUtf8(")"));
127 ext_filter.removeDuplicates();
130 void Menu_MetaClass::do_select_inner_media(int num)
133 if(use_d88_menus && (num < MAX_D88_BANKS)) {
134 if(action_select_media_list[num] != NULL) {
135 action_select_media_list[num]->setChecked(true);
141 void Menu_MetaClass::do_open_dialog()
145 if(initial_dir.isEmpty()) {
148 initial_dir = dir.currentPath();
149 strncpy(app, initial_dir.toLocal8Bit().constData(), PATH_MAX);
150 initial_dir = QString::fromLocal8Bit(get_parent_dir(app));
152 dlg.setOption(QFileDialog::ReadOnly, false);
153 dlg.setOption(QFileDialog::DontUseNativeDialog, true);
154 //dlg.setAcceptMode(QFileDialog::AcceptSave);
155 dlg.setFileMode(QFileDialog::AnyFile);
156 //dlg.setLabelText(QFileDialog::Accept, QApplication::translate("MainWindow", "Open File", 0));
158 dlg.param->setDrive(media_drive);
159 dlg.param->setPlay(true);
160 dlg.setDirectory(initial_dir);
161 dlg.setNameFilters(ext_filter);
164 tmps = QApplication::translate("MainWindow", "Open", 0);
165 if(!window_title.isEmpty()) {
166 tmps = tmps + QString::fromUtf8(" ") + window_title;
168 tmps = tmps + QString::fromUtf8(" ") + this->title();
170 dlg.setWindowTitle(tmps);
172 QObject::connect(&dlg, SIGNAL(fileSelected(QString)),
173 dlg.param, SLOT(_open_disk(QString)));
174 QObject::connect(dlg.param, SIGNAL(do_open_disk(int, QString)),
175 this, SLOT(do_open_media(int, QString)));
182 void Menu_MetaClass::do_update_histories(QStringList lst)
188 for(ii = 0; ii < MAX_HISTORY; ii++) {
189 tmps = QString::fromUtf8("");
190 if(ii < lst.size()) tmps = lst.value(ii);
192 action_recent_list[ii]->setText(tmps);
193 if(!tmps.isEmpty()) {
194 action_recent_list[ii]->setVisible(true);
196 action_recent_list[ii]->setVisible(false);
201 void Menu_MetaClass::do_clear_inner_media(void)
204 inner_media_list.clear();
207 for(ii = 0; ii < MAX_D88_BANKS; ii++) {
208 if(action_select_media_list[ii] != NULL) {
209 action_select_media_list[ii]->setText(QString::fromUtf8(""));
210 action_select_media_list[ii]->setVisible(false);
218 void Menu_MetaClass::do_update_inner_media(QStringList lst, int num)
222 inner_media_list.clear();
224 for(ii = 0; ii < MAX_D88_BANKS; ii++) {
225 if(ii < p_emu->d88_file[media_drive].bank_num) {
226 inner_media_list << lst.value(ii);
227 action_select_media_list[ii]->setText(lst.value(ii));
228 action_select_media_list[ii]->setVisible(true);
229 if(ii == num) action_select_media_list[ii]->setChecked(true);
231 if(action_select_media_list[ii] != NULL) {
232 action_select_media_list[ii]->setText(QString::fromUtf8(""));
233 action_select_media_list[ii]->setVisible(false);
240 void Menu_MetaClass::create_pulldown_menu_sub(void)
242 action_insert = new Action_Control(p_wid);
243 action_insert->setObjectName(QString::fromUtf8("action_insert_") + object_desc);
244 action_insert->binds->setDrive(media_drive);
245 connect(action_insert, SIGNAL(triggered()), this, SLOT(do_open_dialog()));
247 action_eject = new Action_Control(p_wid);
248 action_eject->setObjectName(QString::fromUtf8("action_eject_") + object_desc);
249 action_eject->binds->setDrive(media_drive);
250 connect(action_eject, SIGNAL(triggered()), this, SLOT(do_eject_media()));
256 action_group_recent = new QActionGroup(p_wid);
257 action_group_recent->setExclusive(true);
259 for(ii = 0; ii < MAX_HISTORY; ii++) {
260 tmps = history.value(ii, "");
261 action_recent_list[ii] = new Action_Control(p_wid);
262 action_recent_list[ii]->binds->setDrive(media_drive);
263 action_recent_list[ii]->binds->setNumber(ii);
265 action_recent_list[ii]->setText(tmps);
266 action_group_recent->addAction(action_recent_list[ii]);
267 if(!tmps.isEmpty()) {
268 action_recent_list[ii]->setVisible(true);
270 action_recent_list[ii]->setVisible(false);
278 action_group_inner_media = new QActionGroup(p_wid);
279 action_group_inner_media->setExclusive(true);
281 for(ii = 0; ii < MAX_D88_BANKS; ii++) {
282 tmps = history.value(ii, "");
283 action_select_media_list[ii] = new Action_Control(p_wid);
284 action_select_media_list[ii]->binds->setDrive(media_drive);
285 action_select_media_list[ii]->binds->setNumber(ii);
286 action_select_media_list[ii]->setText(tmps);
287 action_select_media_list[ii]->setCheckable(true);
288 if(ii == 0) action_select_media_list[ii]->setChecked(true);
289 action_group_inner_media->addAction(action_select_media_list[ii]);
290 if(!tmps.isEmpty()) {
291 action_select_media_list[ii]->setVisible(true);
293 action_select_media_list[ii]->setVisible(false);
298 if(use_write_protect) {
299 action_group_protect = new QActionGroup(p_wid);
300 action_group_protect->setExclusive(true);
302 action_write_protect_on = new Action_Control(p_wid);
303 action_write_protect_on->setObjectName(QString::fromUtf8("action_write_protect_on_") + object_desc);
304 action_write_protect_on->setCheckable(true);
305 action_write_protect_on->setChecked(true);
306 action_write_protect_on->binds->setDrive(media_drive);
307 action_write_protect_on->binds->setNumber(0);
309 action_write_protect_off = new Action_Control(p_wid);
310 action_write_protect_off->setObjectName(QString::fromUtf8("action_write_protect_off_") + object_desc);
311 action_write_protect_off->setCheckable(true);
312 action_write_protect_off->binds->setDrive(media_drive);
313 action_write_protect_off->binds->setNumber(0);
315 action_group_protect->addAction(action_write_protect_on);
316 action_group_protect->addAction(action_write_protect_off);
317 connect(action_write_protect_on, SIGNAL(triggered()), this, SLOT(do_write_protect_media()));
318 connect(action_write_protect_off, SIGNAL(triggered()), this, SLOT(do_write_unprotect_media()));
322 // This is virtual function, pls.apply
323 void Menu_MetaClass::create_pulldown_menu_device_sub(void)
325 // Create device specific entries.
328 // This is virtual function, pls.apply
329 void Menu_MetaClass::connect_menu_device_sub(void)
334 //void Menu_MetaClass::setTitle(QString s)
336 // QMenu::setTitle(s);
339 //QAction *Menu_MetaClass::menuAction()
341 // return QMenu::menuAction();
344 void Menu_MetaClass::create_pulldown_menu(void)
348 create_pulldown_menu_sub();
349 create_pulldown_menu_device_sub();
352 menu_history = new QMenu(this);
353 menu_history->setObjectName(QString::fromUtf8("menu_history_") + object_desc);
357 menu_inner_media = new QMenu(this);
358 menu_inner_media->setObjectName(QString::fromUtf8("menu_inner_media_") + object_desc);
359 for(ii = 0; ii < MAX_D88_BANKS; ii++) menu_inner_media->addAction(action_select_media_list[ii]);
360 this->addAction(menu_inner_media->menuAction());
364 menu_history = new QMenu(this);
365 menu_history->setObjectName(QString::fromUtf8("menu_history_") + object_desc);
366 for(ii = 0; ii < MAX_HISTORY; ii++) menu_history->addAction(action_recent_list[ii]);
367 this->addAction(menu_history->menuAction());
369 if(use_write_protect) {
370 this->addSeparator();
371 menu_write_protect = new QMenu(this);
373 // Belows are setup of menu.
374 this->addAction(action_insert);
375 this->addAction(action_eject);
377 // Connect extra menus to this.
378 connect_menu_device_sub();
379 this->addSeparator();
382 this->addAction(menu_history->menuAction());
385 this->addAction(menu_inner_media->menuAction());
388 if(use_write_protect) {
389 this->addSeparator();
390 this->addAction(menu_write_protect->menuAction());
391 menu_write_protect->addAction(action_write_protect_on);
392 menu_write_protect->addAction(action_write_protect_off);
396 for(ii = 0; ii < MAX_HISTORY; ii++) {
397 connect(action_recent_list[ii], SIGNAL(triggered()),
398 action_recent_list[ii]->binds, SLOT(on_recent_disk()));
399 connect(action_recent_list[ii]->binds, SIGNAL(set_recent_disk(int, int)),
400 this, SLOT(do_open_recent_media(int, int)));
404 for(ii = 0; ii < MAX_D88_BANKS; ii++) {
405 connect(action_select_media_list[ii], SIGNAL(triggered()),
406 action_select_media_list[ii]->binds, SLOT(on_d88_slot()));
407 connect(action_select_media_list[ii]->binds, SIGNAL(set_d88_slot(int, int)),
408 this, SLOT(do_open_inner_media(int, int)));
414 void Menu_MetaClass::retranslate_pulldown_menu_sub(void)
416 action_insert->setText(QApplication::translate("MainWindow", "Insert", 0));
417 action_eject->setText(QApplication::translate("MainWindow", "Eject", 0));
418 if(use_write_protect) {
419 menu_write_protect->setTitle(QApplication::translate("MainWindow", "Write protection", 0));
420 action_write_protect_on->setText(QApplication::translate("MainWindow", "On", 0));
421 action_write_protect_off->setText(QApplication::translate("MainWindow", "Off", 0));
426 menu_inner_media->setTitle(QApplication::translate("MainWindow", "Select D88 image", 0));
428 //menu_inner_media->setVisible(false);
431 menu_history->setTitle(QApplication::translate("MainWindow", "Recent opened", 0));
434 void Menu_MetaClass::retranslate_pulldown_menu_device_sub(void)
438 void Menu_MetaClass::retranslateUi(void)
440 retranslate_pulldown_menu_sub();
441 retranslate_pulldown_menu_device_sub();
444 void Menu_MetaClass::setEmu(EMU *p)