void menu_selector::handle() { // process the menu const event *menu_event = process(0); if (menu_event != nullptr && menu_event->itemref != nullptr) { if (menu_event->iptkey == IPT_UI_SELECT) { for (size_t idx = 0; idx < m_str_items.size(); ++idx) if ((void*)&m_str_items[idx] == menu_event->itemref) m_selector = idx; switch (m_category) { case INIFILE: mame_machine_manager::instance()->inifile().set_file(m_selector); mame_machine_manager::instance()->inifile().set_cat(0); reset_parent(reset_options::REMEMBER_REF); break; case CATEGORY: mame_machine_manager::instance()->inifile().set_cat(m_selector); reset_parent(reset_options::REMEMBER_REF); break; case GAME: main_filters::actual = m_hover; reset_parent(reset_options::SELECT_FIRST); break; case SOFTWARE: sw_filters::actual = m_hover; reset_parent(reset_options::SELECT_FIRST); break; default: reset_parent(reset_options::REMEMBER_REF); break; } ui_globals::switch_image = true; stack_pop(); } else if (menu_event->iptkey == IPT_SPECIAL) { if (input_character(m_search, menu_event->unichar, uchar_is_printable)) reset(reset_options::SELECT_FIRST); } // escape pressed with non-empty text clears the text else if (menu_event->iptkey == IPT_UI_CANCEL && m_search[0] != 0) { m_search.clear(); reset(reset_options::SELECT_FIRST); } } }
void menu_remove_folder::handle() { // process the menu const event *menu_event = process(0); if (menu_event != nullptr && menu_event->itemref != nullptr && menu_event->iptkey == IPT_UI_SELECT) { std::string tmppath, error_string; m_folders.erase(m_folders.begin() + selected_index()); for (int x = 0; x < m_folders.size(); ++x) { tmppath.append(m_folders[x]); if (x < m_folders.size() - 1) tmppath.append(";"); } if (ui().options().exists(s_folders[m_ref].option)) ui().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string); else if (strcmp(machine().options().value(s_folders[m_ref].option),tmppath.c_str())!=0) { machine().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string); machine().options().mark_changed(s_folders[m_ref].option); } reset_parent(reset_options::REMEMBER_REF); stack_pop(); } }
qml_node::~qml_node() { disconnect(this, &QQuickItem::parentChanged, this, &qml_node::resetNode); if (m_device) m_device->remove(this); reset_parent(); }
void qml_node::node_destroyed() { reset_parent(); disconnect(this, &QQuickItem::parentChanged, this, &qml_node::resetNode); if (m_device) m_device->remove(this); m_was_destroyed = true; deleteLater(); }
void menu_audit::handle() { process(PROCESS_CUSTOM_ONLY); if (m_first) { ui().draw_text_box(container(), _("Audit in progress..."), ui::text_layout::CENTER, 0.5f, 0.5f, UI_GREEN_COLOR); m_first = false; return; } if (m_audit_mode == 1) { vptr_game::iterator iter = m_unavailablesorted.begin(); while (iter != m_unavailablesorted.end()) { driver_enumerator enumerator(machine().options(), (*iter)->name); enumerator.next(); media_auditor auditor(enumerator); media_auditor::summary summary = auditor.audit_media(AUDIT_VALIDATE_FAST); // if everything looks good, include the driver if (summary == media_auditor::CORRECT || summary == media_auditor::BEST_AVAILABLE || summary == media_auditor::NONE_NEEDED) { m_availablesorted.push_back((*iter)); iter = m_unavailablesorted.erase(iter); } else ++iter; } } else { driver_enumerator enumerator(machine().options()); media_auditor auditor(enumerator); while (enumerator.next()) { media_auditor::summary summary = auditor.audit_media(AUDIT_VALIDATE_FAST); // if everything looks good, include the driver if (summary == media_auditor::CORRECT || summary == media_auditor::BEST_AVAILABLE || summary == media_auditor::NONE_NEEDED) m_availablesorted.push_back(&enumerator.driver()); else m_unavailablesorted.push_back(&enumerator.driver()); } } // sort std::stable_sort(m_availablesorted.begin(), m_availablesorted.end(), sorted_game_list); std::stable_sort(m_unavailablesorted.begin(), m_unavailablesorted.end(), sorted_game_list); save_available_machines(); reset_parent(reset_options::SELECT_FIRST); stack_pop(); }
void menu_selector::handle() { // process the menu const event *menu_event = process(0); if (menu_event != nullptr && menu_event->itemref != nullptr) { if (menu_event->iptkey == IPT_UI_SELECT) { for (size_t idx = 0; idx < m_str_items.size(); ++idx) if ((void*)&m_str_items[idx] == menu_event->itemref) m_selector = idx; switch (m_category) { case INIFILE: mame_machine_manager::instance()->inifile().set_file(m_selector); mame_machine_manager::instance()->inifile().set_cat(0); reset_parent(reset_options::REMEMBER_REF); break; case CATEGORY: mame_machine_manager::instance()->inifile().set_cat(m_selector); reset_parent(reset_options::REMEMBER_REF); break; case GAME: main_filters::actual = m_hover; reset_parent(reset_options::SELECT_FIRST); break; case SOFTWARE: sw_filters::actual = m_hover; reset_parent(reset_options::SELECT_FIRST); break; default: reset_parent(reset_options::REMEMBER_REF); break; } ui_globals::switch_image = true; stack_pop(); } else if (menu_event->iptkey == IPT_SPECIAL) { auto const buflen = strlen(m_search); if ((menu_event->unichar == 8) || (menu_event->unichar == 0x7f)) { // if it's a backspace and we can handle it, do so if (0 < buflen) { *const_cast<char *>(utf8_previous_char(&m_search[buflen])) = 0; reset(reset_options::SELECT_FIRST); } } else if (menu_event->is_char_printable()) { // if it's any other key and we're not maxed out, update if (menu_event->append_char(m_search, buflen)) reset(reset_options::SELECT_FIRST); } } // escape pressed with non-empty text clears the text else if (menu_event->iptkey == IPT_UI_CANCEL && m_search[0] != 0) { m_search[0] = '\0'; reset(reset_options::SELECT_FIRST); } } }
void menu_add_change_folder::handle() { // process the menu const event *menu_event = process(0); if (menu_event != nullptr && menu_event->itemref != nullptr) { if (menu_event->iptkey == IPT_UI_SELECT) { int index = (uintptr_t)menu_event->itemref - 1; const menu_item &pitem = item[index]; // go up to the parent path if (!strcmp(pitem.text.c_str(), "..")) { size_t first_sep = m_current_path.find_first_of(PATH_SEPARATOR[0]); size_t last_sep = m_current_path.find_last_of(PATH_SEPARATOR[0]); if (first_sep != last_sep) m_current_path.erase(++last_sep); } else { // if isn't a drive, appends the directory if (strcmp(pitem.subtext.c_str(), "[DRIVE]") != 0) { if (m_current_path[m_current_path.length() - 1] == PATH_SEPARATOR[0]) m_current_path.append(pitem.text); else m_current_path.append(PATH_SEPARATOR).append(pitem.text); } else m_current_path = pitem.text; } // reset the char buffer also in this case m_search[0] = '\0'; reset(reset_options::SELECT_FIRST); } else if (menu_event->iptkey == IPT_SPECIAL) { bool update_selected = false; if (menu_event->unichar == 0x09) { // Tab key, save current path std::string error_string; if (m_change) { if (ui().options().exists(s_folders[m_ref].option)) ui().options().set_value(s_folders[m_ref].option, m_current_path.c_str(), OPTION_PRIORITY_CMDLINE, error_string); else if (strcmp(machine().options().value(s_folders[m_ref].option), m_current_path.c_str()) != 0) { machine().options().set_value(s_folders[m_ref].option, m_current_path.c_str(), OPTION_PRIORITY_CMDLINE, error_string); machine().options().mark_changed(s_folders[m_ref].option); } } else { m_folders.push_back(m_current_path); std::string tmppath; for (int x = 0; x < m_folders.size(); ++x) { tmppath.append(m_folders[x]); if (x != m_folders.size() - 1) tmppath.append(";"); } if (ui().options().exists(s_folders[m_ref].option)) ui().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string); else if (strcmp(machine().options().value(s_folders[m_ref].option), tmppath.c_str()) != 0) { machine().options().set_value(s_folders[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string); machine().options().mark_changed(s_folders[m_ref].option); } } reset_parent(reset_options::SELECT_FIRST); stack_pop(); } else { // if it's any other key and we're not maxed out, update update_selected = input_character(m_search, menu_event->unichar, uchar_is_printable); } // check for entries which matches our search buffer if (update_selected) { const int cur_selected = selected_index(); int entry, bestmatch = 0; // from current item to the end for (entry = cur_selected; entry < item.size(); entry++) if (item[entry].ref != nullptr && !m_search.empty()) { int match = 0; for (int i = 0; i < m_search.size() + 1; i++) { if (core_strnicmp(item[entry].text.c_str(), m_search.data(), i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected = entry; } } // and from the first item to current one for (entry = 0; entry < cur_selected; entry++) { if (item[entry].ref != nullptr && !m_search.empty()) { int match = 0; for (int i = 0; i < m_search.size() + 1; i++) { if (core_strnicmp(item[entry].text.c_str(), m_search.data(), i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected = entry; } } } centre_selection(); } } else if (menu_event->iptkey == IPT_UI_CANCEL) { // reset the char buffer also in this case m_search.clear(); } } }
void qml_node::resetNode() { if(m_was_destroyed) return; m_node.clear(); nodeChanged(m_node); const bool reading = m_device ? m_device->readPreset() : false; reset_parent(); // Creation may not have finished yet. if (m_parentNode && !m_parentNode->ossiaNode()) { m_parentNode->resetNode(); } if (m_device) { // Utility function to set-up a node. auto setup_valid_node = [&] { m_ossia_node->about_to_be_deleted .connect<&qml_node::on_node_deleted>(this); m_node = QString::fromStdString(m_ossia_node->get_name()); nodeChanged(m_node); setPath(QString::fromStdString( ossia::net::address_string_from_node(*m_ossia_node))); applyNodeAttributes(); }; std::string node_name; bool relative = false; // Naming logic if (m_userRequestedNode.isEmpty()) { if (auto par = this->parent()) { node_name = par->objectName().toStdString(); if (node_name.empty()) node_name = par->metaObject()->className(); } if (node_name.empty()) node_name = "Object"; relative = true; } else if (m_userRequestedNode[0] != '/') { relative = true; node_name = m_userRequestedNode.toStdString(); } else if (m_userRequestedNode == QStringLiteral("/")) { m_ossia_node = &m_device->device().get_root_node(); setup_valid_node(); return; } else { node_name = m_userRequestedNode.toStdString(); } // Find the node auto get_parent = [&]() -> ossia::net::node_base& { if (m_parentNode && m_parentNode->ossiaNode()) return *m_parentNode->ossiaNode(); if (relative) { return findClosestParent( this->parent(), m_device->device().get_root_node()); } else { return m_device->device().get_root_node(); } }; ossia::net::node_base& parent = get_parent(); if (reading) { m_ossia_node = ossia::net::find_node(parent, node_name); if (m_ossia_node) { setup_valid_node(); } else { setPath({}); } } else { m_ossia_node = &ossia::net::create_node(parent, node_name); setup_valid_node(); } return; } // In case something went wrong... setPath({}); }