int dialog_select_game(char * isofilename, char *isoDir, int *videoPlugin, int *disableSound){ char path[MAXPATHLEN]; int i, rc; rc = snprintf(path, MAXPATHLEN, "%s", isoDir); if ((rc == -1) || (rc >= MAXPATHLEN)) { return -1; } dialog_instance_t dialog = 0; bps_event_t *event; dialog_create_popuplist(&dialog); DIR *dirp; struct dirent* direntp; int count=0, domain=0; const char ** list = 0; const char * label; dirp = opendir(isoDir); if( dirp != NULL ) { for(;;) { direntp = readdir( dirp ); if( direntp == NULL ) break; printf( "%s\n", direntp->d_name ); count++; } rewinddir(dirp); if(count==2){ printf("No ISO's found!"); } list = (const char**)malloc(count*sizeof(char*)); count = 0; for(;;){ direntp = readdir( dirp ); if( direntp == NULL ) break; list[count] = (char*)direntp->d_name; count++; } int j = 0, m; int disabled[count]; //If a cue exists, disable the bin for easier readability for(i=0; i<count;i++){ if( strcmp(list[i], ".") == 0 || strcmp(list[i], "..") == 0 ){ disabled[j++] = i; continue; } //Check if current index is a valid rom, .n64, .v64, .z64 if( strncasecmp(list[i]+strlen(list[i])-4, ".n64", 4) != 0 && strncasecmp(list[i]+strlen(list[i])-4, ".v64", 4) != 0 && strncasecmp(list[i]+strlen(list[i])-4, ".z64", 4) != 0) { disabled[j++] = i; continue; } } int k = 0; char * compact[count-j+6]; compact[k++] = "Video Plugin"; compact[k++] = "Video Rice"; compact[k++] = "GLES2N64"; compact[k++] = "Audio Plugin"; compact[k++] = "Disable Sound"; compact[k++] = "Roms"; //For each index for(i=0;i<count;i++){ //search disabled for a match for(m=0;m<j;m++){ if(i==disabled[m]){ //If we do find that i is disabled don't copy break; } } if(m==j){ compact[k++] = list[i]; } } //Sort compact list qsort( compact+6, k-6, sizeof(char *), compare ); int indice[] = {0,3,5}; dialog_set_popuplist_items(dialog, compact, k); dialog_set_popuplist_separator_indices(dialog, (int*)&indice, 3); indice[0] = 1; dialog_set_popuplist_selected_indices(dialog, (int*)&indice, 1); char* cancel_button_context = "Canceled"; char* okay_button_context = "Okay"; dialog_add_button(dialog, DIALOG_CANCEL_LABEL, true, cancel_button_context, true); dialog_add_button(dialog, DIALOG_OK_LABEL, true, okay_button_context, true); dialog_set_popuplist_multiselect(dialog, true); dialog_show(dialog); while(1){ bps_get_event(&event, -1); if (event) { domain = bps_event_get_domain(event); if (domain == dialog_get_domain()) { int *response = NULL; int num = 0; int videoOption = 0; label = dialog_event_get_selected_label(event); if(strcmp(label, DIALOG_OK_LABEL) == 0){ dialog_event_get_popuplist_selected_indices(event, (int**)&response, &num); if(num > 0){ for(i=0;i<num;i++){ if( (response[i] == 1) || (response[i] == 2) ) { videoOption +=1; } } if(videoOption != 1){ printf("Must pick only 1 video Plugin...\n");fflush(stdout); return -1; } } int vid = 0, sound = 0, rom = 0; switch(num){ case 0: case 1: printf("Must pick at least a video plugin and rom...\n"); return -1; break; case 2: if(response[1] == 4 || response[0] == 4){ printf("Must pick a Rom...\n"); return -1; } *disableSound = 0; if(response[0] == 2 || response[1] == 2){ *videoPlugin = VIDEO_PLUGIN_GLES2N64; } else { *videoPlugin = VIDEO_PLUGIN_RICE; } if(response[0] == 2 || response[0] == 1){ strcpy(isofilename, compact[response[1]]); }else { strcpy(isofilename, compact[response[0]]); } break; case 3: for(i=0;i<num;i++){ if(response[i] == 1){ vid = 1; *videoPlugin = VIDEO_PLUGIN_RICE; } else if (response[i] == 2){ vid = 1; *videoPlugin = VIDEO_PLUGIN_GLES2N64; } else if (response[i] == 4){ sound = 1; } else if( response[i] > 5){ rom = 1; strcpy(isofilename, compact[response[i]]); } } if(vid != 1 || sound != 1 || rom != 1){ printf("Must pick a rom...");fflush(stdout); return -1; } *disableSound = 1; break; } bps_free(response); } else { printf("User has canceled ISO dialog."); free(list); closedir(dirp); return -1; } break; } } } free(list); closedir(dirp); } if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) { strcat(path, isofilename); strcpy(isofilename, path); } else isofilename[0] = 0; return 0; }
void PromptDialog::run() { bps_initialize(); //request all dialog events dialog_request_events(0); if (dialog_create_prompt(&m_dialog) != BPS_SUCCESS) { qDebug() << "Failed to create prompt dialog."; emit cancel(); return; } //set the prompt message if (!m_promptMessage.trimmed().isEmpty() && dialog_set_prompt_message_text(m_dialog, m_promptMessage.toAscii()) != BPS_SUCCESS) { qDebug() << "Failed to set prompt dialog message text."; destroyDialog(); emit cancel(); return; } //set the prompt input field if (!m_inputField.trimmed().isEmpty() && dialog_set_prompt_input_field(m_dialog, m_inputField.toAscii()) != BPS_SUCCESS) { qDebug() << "Failed to set prompt dialog input field."; destroyDialog(); emit cancel(); return; } //set the input placeholder text if (!m_placeholderText.trimmed().isEmpty() && dialog_set_prompt_input_placeholder(m_dialog, m_placeholderText.toAscii()) != BPS_SUCCESS) { qDebug() << "Failed to set prompt dialog placeholder text."; destroyDialog(); emit cancel(); return; } if (!setTitle()) { destroyDialog(); emit cancel(); return; } if (!addButtons()) { destroyDialog(); emit cancel(); return; } if (!showDialog()) { qDebug() << "Failed to show prompt dialog."; destroyDialog(); emit cancel(); return; } bool shutdown = false; while (!shutdown) { bps_event_t* event = NULL; // -1 means that the function waits for an event before returning bps_get_event(&event, -1); if (event) { if (bps_event_get_domain(event) == dialog_get_domain()) { int selectedIndex = dialog_event_get_selected_index(event); const char* label = dialog_event_get_selected_label(event); const char* context = dialog_event_get_selected_context(event); const char* inputfield = dialog_event_get_prompt_input_field(event); if (inputfield != NULL) { m_inputField = inputfield; } if (label != NULL && context != NULL) { if (QString::compare(context, getCancelButtonContext()) == 0) { emit cancel(); } else if (QString::compare(context, getOkButtonContext()) == 0) { emit ok(); } else { emit customButton(selectedIndex, label, context); } } qDebug() << "Got prompt dialog click"; shutdown = true; } } } destroyDialog(); }