bool QQnxVirtualKeyboardBps::handleLocaleEvent(bps_event_t *event) { if (bps_event_get_code(event) == LOCALE_INFO) { const QString language = QString::fromLatin1(locale_event_get_language(event)); const QString country = QString::fromLatin1(locale_event_get_country(event)); const QLocale newLocale(language + QLatin1Char('_') + country); qVirtualKeyboardDebug() << Q_FUNC_INFO << "current locale" << locale() << "new locale=" << newLocale; setLocale(newLocale); return true; } qVirtualKeyboardDebug() << Q_FUNC_INFO << "Unhandled locale event. code=" << bps_event_get_code(event); return false; }
bool QBBVirtualKeyboardBps::handleLocaleEvent(bps_event_t *event) { if (bps_event_get_code(event) == LOCALE_INFO) { const QString language = QString::fromAscii(locale_event_get_language(event)); const QString country = QString::fromAscii(locale_event_get_country(event)); #if defined(QBBVIRTUALKEYBOARD_DEBUG) qDebug() << Q_FUNC_INFO << "current language/country" << languageId() << "/" << countryId() << "new language/country=" << language << "/" << country; #endif setLanguage(language); setCountry(country); return true; } #if defined(QBBVIRTUALKEYBOARD_DEBUG) qDebug() << "QBB: Unhandled locale event. code=" << bps_event_get_code(event); #endif return false; }
/** * 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; }
void StatusEventHandler::event(bps_event_t *event) { bool status = false; const char* language = ""; const char* country = ""; const char* locale = ""; const char* interface = ""; const char* type = "none"; double latitude = 0; double longitude= 0; if (bps_event_get_domain(event) == geolocation_get_domain()) { if(event == NULL || bps_event_get_code(event) != GEOLOCATION_INFO) { qDebug() << "NO INFORMATION PROVIDED"; return; } latitude = geolocation_event_get_latitude(event); longitude = geolocation_event_get_longitude(event); double accuracy = geolocation_event_get_accuracy(event); double altitude = geolocation_event_get_altitude(event); bool altitude_valid = geolocation_event_is_altitude_valid(event); double altitude_accuracy = geolocation_event_get_altitude_accuracy(event); bool altitude_accuracy_valid = geolocation_event_is_altitude_accuracy_valid(event); double heading = geolocation_event_get_heading(event); bool heading_valid = geolocation_event_is_heading_valid(event); double speed = geolocation_event_get_speed(event); bool speed_valid = geolocation_event_is_speed_valid(event); double num_satellites = geolocation_event_get_num_satellites_used(event); bool num_satellites_valid = geolocation_event_is_num_satellites_valid(event); emit geolocationUpdated(latitude,longitude); } if (bps_event_get_domain(event) == netstatus_get_domain()) { if (NETSTATUS_INFO == bps_event_get_code(event)) { netstatus_info_t *info = netstatus_event_get_info(event); if (info) { status = netstatus_info_get_availability(info); interface = netstatus_info_get_default_interface(info); netstatus_interface_details_t *details; int success = netstatus_get_interface_details(interface, &details); if (success == BPS_SUCCESS) { switch (netstatus_interface_get_type(details)) { case NETSTATUS_INTERFACE_TYPE_UNKNOWN: type = "Unknown"; break; case NETSTATUS_INTERFACE_TYPE_WIRED: type = "Wired"; break; case NETSTATUS_INTERFACE_TYPE_WIFI: type = "Wi-Fi"; break; case NETSTATUS_INTERFACE_TYPE_BLUETOOTH_DUN: type = "Bluetooth"; break; case NETSTATUS_INTERFACE_TYPE_USB: type = "USB"; break; case NETSTATUS_INTERFACE_TYPE_VPN: type = "VPN"; break; case NETSTATUS_INTERFACE_TYPE_BB: type = "BB"; break; case NETSTATUS_INTERFACE_TYPE_CELLULAR: type = "Cellular"; break; case NETSTATUS_INTERFACE_TYPE_P2P: type = "P2P"; break; } } netstatus_free_interface_details(&details); emit networkStatusUpdated(status, type); } } } else if (bps_event_get_domain(event) == locale_get_domain()) { if (LOCALE_INFO == bps_event_get_code(event)) { language = locale_event_get_language(event); country = locale_event_get_country(event); locale = locale_event_get_locale(event); emit localeUpdated(language, country, locale); } } }