static int action_start_playlist_association(unsigned type, const char *label) { int found; char new_playlist_cores[PATH_MAX_LENGTH]; struct string_list *stnames = NULL; struct string_list *stcores = NULL; core_info_list_t *list = NULL; settings_t *settings = config_get_ptr(); const char *path = path_basename(label); core_info_get_list(&list); if (!list) return -1; new_playlist_cores[0] = '\0'; stnames = string_split(settings->arrays.playlist_names, ";"); stcores = string_split(settings->arrays.playlist_cores, ";"); found = string_list_find_elem(stnames, path); if (found) string_list_set(stcores, found-1, file_path_str(FILE_PATH_DETECT)); string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); strlcpy(settings->arrays.playlist_cores, new_playlist_cores, sizeof(settings->arrays.playlist_cores)); string_list_free(stcores); string_list_free(stnames); return 0; }
static int action_start_playlist_association(unsigned type, const char *label) { int found; char new_playlist_cores[PATH_MAX_LENGTH] = {0}; struct string_list *stnames = NULL; struct string_list *stcores = NULL; core_info_list_t *list = NULL; settings_t *settings = config_get_ptr(); const char *path = path_basename(label); core_info_ctl(CORE_INFO_CTL_LIST_GET, &list); if (!list) return -1; stnames = string_split(settings->playlist_names, ";"); stcores = string_split(settings->playlist_cores, ";"); found = string_list_find_elem(stnames, path); if (found) string_list_set(stcores, found-1, "DETECT"); string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); strlcpy(settings->playlist_cores, new_playlist_cores, sizeof(settings->playlist_cores)); return 0; }
/** * config_get_menu_driver_options: * * Get an enumerated list of all menu driver names, * separated by '|'. * * Returns: string listing of all menu driver names, * separated by '|'. **/ const char* config_get_menu_driver_options(void) { union string_list_elem_attr attr; unsigned i; char *options = NULL; int options_len = 0; struct string_list *options_l = string_list_new(); attr.i = 0; if (!options_l) return NULL; for (i = 0; menu_driver_find_handle(i); i++) { const char *opt = menu_driver_find_ident(i); options_len += strlen(opt) + 1; string_list_append(options_l, opt, attr); } options = (char*)calloc(options_len, sizeof(char)); if (options) string_list_join_concat(options, options_len, options_l, "|"); string_list_free(options_l); options_l = NULL; return options; }
static int playlist_association_right(unsigned type, const char *label, bool wraparound) { char core_path[PATH_MAX_LENGTH]; char new_playlist_cores[PATH_MAX_LENGTH]; size_t i, next, found, current = 0; core_info_t *info = NULL; struct string_list *stnames = NULL; struct string_list *stcores = NULL; core_info_list_t *list = NULL; settings_t *settings = config_get_ptr(); const char *path = path_basename(label); core_info_get_list(&list); if (!list) return menu_cbs_exit(); core_path[0] = new_playlist_cores[0] = '\0'; stnames = string_split(settings->arrays.playlist_names, ";"); stcores = string_split(settings->arrays.playlist_cores, ";"); if (!menu_content_playlist_find_associated_core(path, core_path, sizeof(core_path))) strlcpy(core_path, file_path_str(FILE_PATH_DETECT), sizeof(core_path)); for (i = 0; i < list->count; i++) { core_info_t *info = core_info_get(list, i); if (string_is_equal(info->path, core_path)) current = i; } next = current + 1; if (next >= list->count) { if (wraparound) next = 0; else next = list->count-1; } info = core_info_get(list, next); found = string_list_find_elem(stnames, path); if (found && info) string_list_set(stcores, (unsigned)(found-1), info->path); string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); strlcpy(settings->arrays.playlist_cores, new_playlist_cores, sizeof(settings->arrays.playlist_cores)); string_list_free(stnames); string_list_free(stcores); return 0; }
static int playlist_association_left(unsigned type, const char *label, bool wraparound) { unsigned i; int next, found, current = 0; core_info_t *info = NULL; struct string_list *stnames = NULL; struct string_list *stcores = NULL; char core_path[PATH_MAX_LENGTH] = {0}; char new_playlist_cores[PATH_MAX_LENGTH] = {0}; settings_t *settings = config_get_ptr(); const char *path = path_basename(label); core_info_list_t *list = NULL; core_info_ctl(CORE_INFO_CTL_LIST_GET, &list); if (!list) return menu_cbs_exit(); stnames = string_split(settings->playlist_names, ";"); stcores = string_split(settings->playlist_cores, ";"); if (!menu_playlist_find_associated_core(path, core_path, sizeof(core_path))) strlcpy(core_path, "DETECT", sizeof(core_path)); for (i = 0; i < list->count; i++) { core_info_t *info = core_info_get(list, i); if (string_is_equal(info->path, core_path)) current = i; } next = current - 1; if (next < 0) { if (wraparound) next = list->count; else next = 0; } info = core_info_get(list, next); found = string_list_find_elem(stnames, path); if (found) string_list_set(stcores, found-1, info->path); string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); strlcpy(settings->playlist_cores, new_playlist_cores, sizeof(settings->playlist_cores)); return 0; }
const char *char_list_new_special(enum string_list_type type, void *data) { unsigned len = 0; size_t list_size; struct string_list *s = string_list_new_special(type, data, &len, &list_size); char *options = (len > 0) ? (char*)calloc(len, sizeof(char)): NULL; if (options && s) string_list_join_concat(options, len, s, "|"); string_list_free(s); s = NULL; return options; }
static int action_ok_rdb_entry_submenu(const char *path, const char *label, unsigned type, size_t idx) { int ret; union string_list_elem_attr attr; char new_label[PATH_MAX_LENGTH]; char *rdb = NULL; int len = 0; struct string_list *str_list = NULL; struct string_list *str_list2 = NULL; menu_handle_t *menu = menu_driver_get_ptr(); if (!menu) return -1; if (!label) return -1; str_list = string_split(label, "|"); if (!str_list) return -1; str_list2 = string_list_new(); if (!str_list2) { string_list_free(str_list); return -1; } /* element 0 : label * element 1 : value * element 2 : database path */ attr.i = 0; len += strlen(str_list->elems[1].data) + 1; string_list_append(str_list2, str_list->elems[1].data, attr); len += strlen(str_list->elems[2].data) + 1; string_list_append(str_list2, str_list->elems[2].data, attr); rdb = (char*)calloc(len, sizeof(char)); if (!rdb) { string_list_free(str_list); string_list_free(str_list2); return -1; } string_list_join_concat(rdb, len, str_list2, "|"); strlcpy(new_label, "deferred_cursor_manager_list_", sizeof(new_label)); strlcat(new_label, str_list->elems[0].data, sizeof(new_label)); ret = menu_list_push_stack_refresh( menu->menu_list, rdb, new_label, 0, idx); string_list_free(str_list); string_list_free(str_list2); return ret; }
void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&) { settings_t *settings = config_get_ptr(); QScopedPointer<QMenu> menu; QScopedPointer<QMenu> associateMenu; QScopedPointer<QMenu> hiddenPlaylistsMenu; QScopedPointer<QAction> hideAction; QScopedPointer<QAction> newPlaylistAction; QScopedPointer<QAction> deletePlaylistAction; QPointer<QAction> selectedAction; QPoint cursorPos = QCursor::pos(); QListWidgetItem *selectedItem = m_listWidget->itemAt(m_listWidget->viewport()->mapFromGlobal(cursorPos)); QDir playlistDir(settings->paths.directory_playlist); QString playlistDirAbsPath = playlistDir.absolutePath(); QString currentPlaylistDirPath; QString currentPlaylistPath; QString currentPlaylistFileName; QFile currentPlaylistFile; QByteArray currentPlaylistFileNameArray; QFileInfo currentPlaylistFileInfo; QMap<QString, const core_info_t*> coreList; core_info_list_t *core_info_list = NULL; union string_list_elem_attr attr = {0}; struct string_list *stnames = NULL; struct string_list *stcores = NULL; unsigned i = 0; int j = 0; size_t found = 0; const char *currentPlaylistFileNameData = NULL; char new_playlist_names[PATH_MAX_LENGTH]; char new_playlist_cores[PATH_MAX_LENGTH]; bool specialPlaylist = false; bool foundHiddenPlaylist = false; new_playlist_names[0] = new_playlist_cores[0] = '\0'; stnames = string_split(settings->arrays.playlist_names, ";"); stcores = string_split(settings->arrays.playlist_cores, ";"); if (selectedItem) { currentPlaylistPath = selectedItem->data(Qt::UserRole).toString(); currentPlaylistFile.setFileName(currentPlaylistPath); currentPlaylistFileInfo = QFileInfo(currentPlaylistPath); currentPlaylistFileName = currentPlaylistFileInfo.fileName(); currentPlaylistDirPath = currentPlaylistFileInfo.absoluteDir().absolutePath(); currentPlaylistFileNameArray.append(currentPlaylistFileName); currentPlaylistFileNameData = currentPlaylistFileNameArray.constData(); } menu.reset(new QMenu(this)); menu->setObjectName("menu"); hiddenPlaylistsMenu.reset(new QMenu(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_HIDDEN_PLAYLISTS), this)); newPlaylistAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST)) + "...", this)); hiddenPlaylistsMenu->setObjectName("hiddenPlaylistsMenu"); menu->addAction(newPlaylistAction.data()); if (currentPlaylistFile.exists()) { deletePlaylistAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DELETE_PLAYLIST)) + "...", this)); menu->addAction(deletePlaylistAction.data()); } if (selectedItem) { hideAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_HIDE), this)); menu->addAction(hideAction.data()); } for (j = 0; j < m_listWidget->count(); j++) { QListWidgetItem *item = m_listWidget->item(j); bool hidden = m_listWidget->isItemHidden(item); if (hidden) { QAction *action = hiddenPlaylistsMenu->addAction(item->text()); action->setProperty("row", j); action->setProperty("core_path", item->data(Qt::UserRole).toString()); foundHiddenPlaylist = true; } } if (!foundHiddenPlaylist) { QAction *action = hiddenPlaylistsMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NONE)); action->setProperty("row", -1); } menu->addMenu(hiddenPlaylistsMenu.data()); if (currentPlaylistDirPath != playlistDirAbsPath) { /* special playlists like history etc. can't have an association */ specialPlaylist = true; } if (!specialPlaylist) { associateMenu.reset(new QMenu(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ASSOCIATE_CORE), this)); associateMenu->setObjectName("associateMenu"); core_info_get_list(&core_info_list); for (i = 0; i < core_info_list->count && core_info_list->count > 0; i++) { const core_info_t *core = &core_info_list->list[i]; coreList[core->core_name] = core; } { QMapIterator<QString, const core_info_t*> coreListIterator(coreList); QVector<QHash<QString, QString> > cores; while (coreListIterator.hasNext()) { QString key; const core_info_t *core = NULL; QString name; QHash<QString, QString> hash; coreListIterator.next(); key = coreListIterator.key(); core = coreList.value(key); if (string_is_empty(core->core_name)) name = core->display_name; else name = core->core_name; if (name.isEmpty()) continue; hash["name"] = name; hash["core_path"] = core->path; cores.append(hash); } std::sort(cores.begin(), cores.end(), comp_hash_name_key_lower); for (j = 0; j < cores.count(); j++) { const QHash<QString, QString> &hash = cores.at(j); QAction *action = associateMenu->addAction(hash.value("name")); action->setProperty("core_path", hash.value("core_path")); } } menu->addMenu(associateMenu.data()); } selectedAction = menu->exec(cursorPos); if (!selectedAction) goto end; if (!specialPlaylist && selectedAction->parent() == associateMenu.data()) { found = string_list_find_elem(stnames, currentPlaylistFileNameData); if (found) string_list_set(stcores, static_cast<unsigned>(found - 1), selectedAction->property("core_path").toString().toUtf8().constData()); else { string_list_append(stnames, currentPlaylistFileNameData, attr); string_list_append(stcores, "DETECT", attr); found = string_list_find_elem(stnames, currentPlaylistFileNameData); if (found) string_list_set(stcores, static_cast<unsigned>(found - 1), selectedAction->property("core_path").toString().toUtf8().constData()); } string_list_join_concat(new_playlist_names, sizeof(new_playlist_names), stnames, ";"); string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); strlcpy(settings->arrays.playlist_names, new_playlist_names, sizeof(settings->arrays.playlist_names)); strlcpy(settings->arrays.playlist_cores, new_playlist_cores, sizeof(settings->arrays.playlist_cores)); } else if (selectedItem && selectedAction == deletePlaylistAction.data()) { if (currentPlaylistFile.exists()) { if (showMessageBox(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST)).arg(selectedItem->text()), MainWindow::MSGBOX_TYPE_QUESTION_YESNO, Qt::ApplicationModal, false)) { if (currentPlaylistFile.remove()) reloadPlaylists(); else showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_DELETE_FILE), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); } } } else if (selectedAction == newPlaylistAction.data()) { QString name = QInputDialog::getText(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ENTER_NEW_PLAYLIST_NAME)); QString newPlaylistPath = playlistDirAbsPath + "/" + name + file_path_str(FILE_PATH_LPL_EXTENSION); QFile file(newPlaylistPath); if (file.open(QIODevice::WriteOnly)) file.close(); reloadPlaylists(); } else if (selectedItem && selectedAction == hideAction.data()) { int row = m_listWidget->row(selectedItem); if (row >= 0) { QStringList hiddenPlaylists = m_settings->value("hidden_playlists").toStringList(); if (!hiddenPlaylists.contains(currentPlaylistFileName)) { hiddenPlaylists.append(currentPlaylistFileName); m_settings->setValue("hidden_playlists", hiddenPlaylists); } m_listWidget->setRowHidden(row, true); } } else if (selectedAction->parent() == hiddenPlaylistsMenu.data()) { QVariant rowVariant = selectedAction->property("row"); if (rowVariant.isValid()) { QStringList hiddenPlaylists = m_settings->value("hidden_playlists").toStringList(); int row = rowVariant.toInt(); if (row >= 0) { QString playlistPath = selectedAction->property("core_path").toString(); QFileInfo playlistFileInfo(playlistPath); QString playlistFileName = playlistFileInfo.fileName(); if (hiddenPlaylists.contains(playlistFileName)) { hiddenPlaylists.removeOne(playlistFileName); m_settings->setValue("hidden_playlists", hiddenPlaylists); } m_listWidget->setRowHidden(row, false); } } } setCoreActions(); end: if (stnames) string_list_free(stnames); if (stcores) string_list_free(stcores); }
struct string_list *dir_list_new_special(const char *input_dir, enum dir_list_type type, const char *filter) { char ext_shaders[PATH_MAX_LENGTH] = {0}; char ext_name[PATH_MAX_LENGTH] = {0}; const char *dir = NULL; const char *exts = NULL; bool include_dirs = false; (void)input_dir; switch (type) { case DIR_LIST_AUTOCONFIG: dir = input_dir; exts = filter; break; case DIR_LIST_CORES: dir = input_dir; if (!frontend_driver_get_core_extension(ext_name, sizeof(ext_name))) return NULL; exts = ext_name; break; case DIR_LIST_CORE_INFO: { core_info_list_t *list = NULL; core_info_get_list(&list); dir = input_dir; exts = list->all_ext; } break; case DIR_LIST_SHADERS: { union string_list_elem_attr attr = {0}; struct string_list *str_list = string_list_new(); if (!str_list) return NULL; dir = input_dir; #ifdef HAVE_CG string_list_append(str_list, "cg", attr); string_list_append(str_list, "cgp", attr); #endif #ifdef HAVE_GLSL string_list_append(str_list, "glsl", attr); string_list_append(str_list, "glslp", attr); #endif #ifdef HAVE_VULKAN string_list_append(str_list, "slang", attr); string_list_append(str_list, "slangp", attr); #endif string_list_join_concat(ext_shaders, sizeof(ext_shaders), str_list, "|"); string_list_free(str_list); exts = ext_shaders; } break; case DIR_LIST_COLLECTIONS: dir = input_dir; exts = "lpl"; break; case DIR_LIST_DATABASES: dir = input_dir; exts = "rdb"; break; case DIR_LIST_PLAIN: dir = input_dir; exts = filter; break; case DIR_LIST_NONE: default: return NULL; } return dir_list_new(dir, exts, include_dirs, type == DIR_LIST_CORE_INFO); }