const char* get_system_lang( ) { char* country = NULL; char* language = NULL; locale_get(&language, &country); bps_free(country); bps_free(language); return language; }
void sarm_del (simarm_t *sim) { if (sim == NULL) { return; } pci_ata_free (&sim->pciata); pci_ixp_del (sim->pci); dsks_del (sim->dsks); ser_del (sim->serport[1]); ser_del (sim->serport[0]); tmr_del (sim->timer); ict_del (sim->intc); arm_del (sim->cpu); mem_del (sim->mem); bps_free (&sim->bps); free (sim); }
bool LaunchBrowser (const char *inUtf8URL) { char* err = NULL; int result = navigator_invoke (inUtf8URL, &err); bps_free (err); return (result == BPS_SUCCESS); }
bool QQnxNavigatorBps::requestInvokeUrl(const QByteArray &encodedUrl) { char *error = 0; int ret = navigator_invoke(encodedUrl, &error); if (error) { qWarning() << Q_FUNC_INFO << "error=" << error; bps_free(error); } return (ret == BPS_SUCCESS); }
bool QQnxFileDialogHelper::handleEvent(bps_event_t *event) { qFileDialogHelperDebug() << Q_FUNC_INFO; // Check dialog event response type (OK vs CANCEL) // CANCEL => index = 0 // OK => index = 1 int index = dialog_event_get_selected_index(event); qFileDialogHelperDebug() << "Index =" << index; if (index == 1) { m_result = QPlatformDialogHelper::Accepted; if (m_acceptMode == QFileDialogOptions::AcceptOpen) { // File open dialog // ###TODO Check that this actually gets multiple paths and cleans up properly char **filePaths = 0; int pathCount = 0; int result = dialog_event_get_filebrowse_filepaths(event, &filePaths, &pathCount); if (result != BPS_SUCCESS) { qWarning() << "Could not get paths from native file dialog"; return false; } for (int i = 0; i < pathCount; ++i) { QString path = QFile::decodeName(filePaths[i]); m_paths.append(QUrl::fromLocalFile(path)); qFileDialogHelperDebug() << "path =" << path; } bps_free(filePaths); } else { // File save dialog const char *filePath = dialog_event_get_filesave_filepath(event); QString path = QFile::decodeName(filePath); qFileDialogHelperDebug() << "path =" << path; m_paths.append(QUrl::fromLocalFile(path)); } } else { // Cancel m_result = QPlatformDialogHelper::Rejected; } Q_EMIT dialogClosed(); return true; }
/** * A sample application that demonstrates the BlackBerry Native APIs for * managing locale. The sample queries for the current locale and then listens * for locale update events. */ int main(int argc, char *argv[]) { /* * Before we can listen for events from the BlackBerry Tablet OS platform * services, we need to initialize the BPS infrastructure */ bps_initialize(); if (setup_screen() != EXIT_SUCCESS) { printf("Unable to set up the screen. Exiting."); return 0; } /* * Once the BPS infrastructure has been initialized we can register for * events from the various BlackBerry Tablet OS platform services. The * Navigator service manages and delivers application life cycle and * visibility events. * For this sample, we request Navigator events so that we can track when * the system is terminating the application (NAVIGATOR_EXIT event) as well * as Locale events so we can be notified when the locale is updated */ navigator_request_events(0); locale_request_events(0); dialog_request_events(0); /* * Create and display the dialog. */ create_dialog(); /* * Retrieve and display the current Locale using the locale_get(...) API */ char* country = NULL; char* language = NULL; locale_get(&language, &country); display_locale(language, country); bps_free((char*)language); bps_free((char*)country); /* * Process Locale and Navigator events until we receive a NAVIGATOR_EXIT event. */ int exit_application = 0; while (!exit_application) { /* * Using a negative timeout (-1) in the call to bps_get_event(...) * ensures that we don't busy wait by blocking until an event is * available. */ bps_event_t *event = NULL; bps_get_event(&event, -1); if (event) { if (bps_event_get_domain(event) == locale_get_domain()) { /* * If it is a LOCALE_INFO event then display the updated locale * information */ if (LOCALE_INFO == bps_event_get_code(event)) { /* * The locale_event_get_language and locale_event_get_country * calls return pointers to data within the event. When * the event is destroyed below via the call to * bps_event_destroy(event), the returned pointers would * reference deallocated memory. * * To avoid potentially having pointers to dereferenced * memory, we'll use local variables to store the pointers * into the event data. This way, the pointers will go * out of scope and thus cannot be used after the event * is freed. */ const char* language = locale_event_get_language(event); const char* country = locale_event_get_country(event); display_locale(language, country); } } /* * If it is a NAVIGATOR_EXIT event then set the exit_application * flag so the application will stop processing events, clean up * and exit */ if (bps_event_get_domain(event) == navigator_get_domain()) { if (NAVIGATOR_EXIT == bps_event_get_code(event)) { exit_application = 1; } } } } /* * Destroy the dialog, if it exists and cleanup screen resources. */ destroy_dialog(); cleanup_screen(); /* * Clean up the BPS infrastructure and exit */ bps_shutdown(); return 0; }
static inline void cleanup(char *interface) { bps_free(interface); }
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 init() { #ifdef _WIN32 { char c[1024]; GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SISO639LANGNAME,c,1024); if(c[0]!='\0'){ locale=c; GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME,c,1024); if(c[0]!='\0') locale+=std::string("_")+c; } } #endif #ifdef __APPLE__ CFArrayRef localeIDs = CFLocaleCopyPreferredLanguages(); if (localeIDs) { CFStringRef localeID = (CFStringRef)CFArrayGetValueAtIndex(localeIDs, 0); char tmp[16]; if (CFStringGetCString(localeID, tmp, 16, kCFStringEncodingUTF8)) locale = std::string(tmp); CFRelease(localeIDs); } #endif #if defined(TARGET_OS_HARMATTAN) std::cerr << "Get GConf default client\n"; GConfClient *gconf = gconf_client_get_default(); locale = std::string(gconf_client_get_string(gconf, "/meegotouch/i18n/region", NULL)); #elif defined(TARGET_BLACKBERRY) char *language = 0; char *country = 0; if (BPS_SUCCESS == locale_get(&language, &country) && language!= NULL && country != NULL) { std::stringstream ss; ss << language << "_" << country; locale = ss.str(); bps_free(language); bps_free(country); } #else char *cstr = getenv("LANG"); if (cstr != NULL) locale = cstr; if (locale.size() < 2) { cstr = getenv("LC_ALL"); if (cstr != NULL) locale = cstr; } if (locale == "zh-Hans") locale = "zh_CN"; //hack to make it work on iOS if (locale == "zh-Hant") locale = "zh_TW"; #endif //strip the charset part of the country and language code, //e.g. "pt_BR.UTF8" --> "pt_BR" size_t found = locale.find("."); if (found != std::string::npos) { locale = locale.substr(0, found); } if (locale.size() < 2) return; std::string filename = "./locale/" + locale + "/LC_MESSAGES/frogatto.mo"; found = locale.find("@"); if (!sys::file_exists(filename) && found != std::string::npos) { locale = locale.substr(0, found); filename = "./locale/" + locale + "/LC_MESSAGES/frogatto.mo"; } //strip the country code, e.g. "de_DE" --> "de" found = locale.find("_"); if (!sys::file_exists(filename) && found != std::string::npos) { locale = locale.substr(0, found); filename = "./locale/" + locale + "/LC_MESSAGES/frogatto.mo"; } if (!sys::file_exists(filename)) return; const std::string content = sys::read_file(module::map_file(filename)); size_t size = content.size(); if (size < sizeof(mo_header)) return; mo_header* header = (mo_header*) content.c_str(); if (header->magic != 0x950412de || header->version != 0 || header->o_offset + 8*header->number > size || header->t_offset + 8*header->number > size) return; mo_entry* original = (mo_entry*) (content.c_str() + header->o_offset); mo_entry* translated = (mo_entry*) (content.c_str() + header->t_offset); for (int i = 0; i < header->number; ++i) { if (original[i].offset + original[i].length > size || translated[i].offset + translated[i].length > size) return; const std::string msgid = content.substr(original[i].offset, original[i].length); const std::string msgstr = content.substr(translated[i].offset, translated[i].length); hashmap[msgid] = msgstr; } }