bool QQnxBpsEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
    Q_UNUSED(eventType);
    Q_UNUSED(result);
    bps_event_t *event = static_cast<bps_event_t *>(message);
    const int eventDomain = bps_event_get_domain(event);
    qBpsEventFilterDebug() << Q_FUNC_INFO << "event=" << event << "domain=" << eventDomain;

    if (eventDomain == screen_get_domain()) {
        if (!m_screenEventHandler) {
            qWarning("QQNX: registered for screen events, but no handler provided.");
            return false;
        }

        screen_event_t screenEvent = screen_event_get_event(event);
        return m_screenEventHandler->handleEvent(screenEvent);
    }

    if (eventDomain == dialog_get_domain()) {
        dialog_instance_t nativeDialog = dialog_event_get_dialog_instance(event);
        QQnxFileDialogHelper *dialog = m_dialogMapper.value(nativeDialog, 0);
        if (dialog)
            return dialog->handleEvent(event);
    }

    if (eventDomain == navigator_get_domain())
        return handleNavigatorEvent(event);

    if (m_virtualKeyboard->handleEvent(event))
        return true;

    return false;
}
Beispiel #2
0
void handleEvent() {
	//Request and process BPS next available event
	int rc, domain;

	for (;;) {
		bps_event_t *event = NULL;
		rc = bps_get_event(&event, 0);
		assert(rc == BPS_SUCCESS);

		if (event) {

			int domain = bps_event_get_domain(event);

			if (domain == screen_get_domain()) {
				handleScreenEvent(event);

			} else if(domain == navigator_get_domain()) {
                handleNavigatorEvent(event);

			} else if (domain == dialog_get_domain()) {
                handle_dialog_response(event);
            }
		} else {
			break;
		}
	}

}
Beispiel #3
0
/**
 * A sample application that demonstrates the BlackBerry(R) 10 Native SDK APIs
 * for geolocation.
 */
int
main(int argc, char *argv[])
{
    bool exit_application = false;

    /*
     * Before we can listen for events from the BlackBerry(R) 10 OS platform
     * services, we need to initialize the BPS infrastructure
     */
    bps_initialize();

    /*
     * Initialize the screen so that the window group Id is properly set, to allow
     * the dialogs to be displayed.
     */
    if (setup_screen() != EXIT_SUCCESS) {
        fprintf(stderr, "Unable to initialize screen.");
        exit(-1);
    }

    /*
     * Once the BPS infrastructure has been initialized we can register for
     * events from the various BlackBerry(R) 10 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).
     *
     * We request dialog events so we can be notified when the dialog service
     * responds to our requests/queries.
     *
     * We request geolocation events so that we can be notified of our current
     * geolocation.
     */
    if (BPS_SUCCESS != navigator_request_events(0)) {
        fprintf(stderr, "Error requesting navigator events: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != dialog_request_events(0)) {
        fprintf(stderr, "Error requesting dialog events: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != geolocation_request_events(0)) {
        fprintf(stderr, "Error requesting geolocation events: %s", strerror(errno));
        exit(-1);
    }

    /*
     * Get geolocation events once a second, which is the most often that they
     * are capable of being reported.
     */
    geolocation_set_period(1);

    /*
     * Create and display the dialog that will show the geolocation data.
     */
    create_dialog();
    show_dialog_message("Geolocation getting first fix");

    /*
     * Process Geolocation, Dialog and Navigator events until we receive a
     * NAVIGATOR_EXIT event.
     */
    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 it is a geolocation event, determine the response code and
             * handle the event accordingly.
             */
            if (bps_event_get_domain(event) == geolocation_get_domain()) {
                handle_geolocation_response(event);
            }

            /*
             * If it is a dialog event, determine the response code and handle
             * the event accordingly.
             */
            else if (bps_event_get_domain(event) == dialog_get_domain()) {
                /* We have no buttons so we don't need to do anything. */
                ;
            }

            /*
             * If it is a NAVIGATOR_EXIT event then set the exit_application
             * flag so the application will stop processing events, clean up and
             * exit.
             */
            else if (bps_event_get_domain(event) == navigator_get_domain()) {
                exit_application = handle_navigator_event(event);
            }
        }
    }

    /*
     * Stop geolocation events.
     */
    geolocation_stop_events(0);

    /*
     * Destroy the dialog, if it exists.
     */
    destroy_dialog();

    /*
     * Clean up the bps infrastructure and exit
     */
    bps_shutdown();
    cleanup_screen();
    return 0;
}
void ScoreLoopThread::run() {
	qDebug() << "ScoreLoopThread run() started";

	AppData_t app;
	SC_InitData_t initData;
	SC_Error_t rc;
	char versionBuffer[0x100]; /* Thats 256 bytes */

	qDebug() << "Starting Scoreloop Sample...";

	/* Initialize the BPS event system */
	bps_initialize();
	bps_set_verbosity(0); /* Set to 1 or 2 for more output if you like */

	memset(&app, 0, sizeof(AppData_t));

	/* Initialize the Scoreloop platform dependent SC_InitData_t structure to default values. */
	SC_InitData_Init(&initData);

	/* What version of the Scoreloop library do we use? */
	if (SC_GetVersionInfo(&initData, versionBuffer, sizeof(versionBuffer))) {
		qDebug() << "Version-Info: " << versionBuffer;
	}

	/* Now, create the Scoreloop Client with the initialized SC_InitData_t structure
	 * as well as the game-id and game-secret as found on the developer portal.
	 */
	rc = SC_Client_New(&app.client, &initData, SCORELOOP_GAME_ID, SCORELOOP_GAME_SECRET, SCORELOOP_GAME_VERSION, SCORELOOP_GAME_CURRENCY, SCORELOOP_GAME_LANGUAGE);
	if (rc != SC_OK) {
		HandleError(&app, rc);
	} else {
		//InformUser(&app, "Note", "Scoreloop Sample started...");

		/* Request the user here just for demonstration purposes */
		RequestUser(&app);
	}

	while (!m_quit) {
		/* Get next BPS event */
		bps_event_t *event;
		bps_get_event(&event, -1);

		/* Scoreloop event handling  */
		if (bps_event_get_domain(event) == SC_GetBPSEventDomain(&initData)) {
			SC_HandleBPSEvent(&initData, event);
		}

		else if (bps_event_get_domain(event) == dialog_get_domain()) {
			dialog_destroy(dialog_event_get_dialog_instance(event));
			app.dialog = 0;
		}
		/* Add more BPS event handling here... */

	}

	/* Cleanup the Scoreloop client */
	SC_Client_Release(app.client);

	/* Shutdown BPS */
	bps_shutdown();
	qDebug() << "SensorsThread run() finished.";
}
Beispiel #5
0
int main( int argc, char **argv ) {
    const char *mmrname = NULL;
    const char *ctxtname = "testplayer";
    const char *audioout = NULL;
    const char *inputtype = "track";
    char cwd[PATH_MAX];
    char inputurl[PATH_MAX];
    int rc;
    int final_return_code = EXIT_FAILURE;
    int exit_application = 0;
    mmr_connection_t *connection = NULL;
    mmr_context_t *ctxt = NULL;

    /*
     * Before we can listen for events from the BlackBerry(R) 10 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(R) 10 OS platform services. The
     * Navigator service manages and delivers application life cycle and
     * visibility events.
     * For this sample, we request Navigator events so we can track when
     * the system is terminating the application (NAVIGATOR_EXIT event). 
     * This allows us to clean up application resources.
     */
    navigator_request_events(0);
    dialog_request_events(0);

    /*
     * Create and display the dialog.
     */
    create_dialog();

    getcwd(cwd, PATH_MAX);
    rc = snprintf(inputurl, PATH_MAX, "file://%s%s", cwd, WAV_RELATIVE_PATH);
    if (rc > PATH_MAX - 1)
    {
          show_dialog_message("File name and path too long");
          goto fail;
    }

    mode_t mode = S_IRUSR | S_IXUSR;
    int audio_oid; // output ID
    strm_dict_t *aoparams = NULL; // output parameters

    audioout = DEFAULT_AUDIO_OUT;

    if ( ( connection = mmr_connect( mmrname ) ) == NULL ) {
        snprintf(msg, MSG_SIZE, "mmr_connect: %s", strerror(errno));
        show_dialog_message(msg);
    } else if ( ( ctxt = mmr_context_create( connection, ctxtname, 0, mode ) ) == NULL ) {
        snprintf(msg, MSG_SIZE, "%s: %s", ctxtname, strerror(errno));
        show_dialog_message(msg);
    } else if ( audioout && ( audio_oid = mmr_output_attach( ctxt, audioout, "audio" ) ) < 0 ) {
        mmrerror( ctxt, audioout );
    } else if ( aoparams && mmr_output_parameters( ctxt, audio_oid, aoparams ) ) {
        mmrerror( ctxt, "output parameters (audio)" );
    } else if ( mmr_input_attach( ctxt, inputurl, inputtype ) < 0 ) {
        mmrerror( ctxt, inputurl );
    } else if ( mmr_play( ctxt ) < 0 ) {
        mmrerror( ctxt, "mmr_play" );
    } else if (BPS_SUCCESS != bps_add_sigevent_handler( &mmr_sigevent, mmr_sigevent_handler, ctxt ) ) { 
        snprintf( msg, MSG_SIZE, "bps_add_sigevent_handler() failure %s", strerror( errno ) );
        show_dialog_message( msg );
    } else if ( drain_and_arm_mmr_events ( ctxt ) ) {
        snprintf( msg, MSG_SIZE, "drain_and_arm_mmr_events() failure %s", strerror( errno ) );
        show_dialog_message( msg );
    } else {
        show_dialog_message( "Playing Audio\n" );
        final_return_code = EXIT_SUCCESS;
    }

fail:
    /*
     * Process Navigator events until we receive a NAVIGATOR_EXIT event.
     */
    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 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)) {
                    if (final_return_code == EXIT_SUCCESS) {
                        mmr_stop( ctxt );             // Not really necessary -- mmr_input_detach() would take care of this
                        mmr_input_detach( ctxt );     // Not really necessary -- mmr_context_destroy()  would take care of this
                        mmr_context_destroy( ctxt );  // Not really necessary -- mmr_disconnect() would take care of this
                        mmr_disconnect( connection ); // Not really necessary -- exiting would take care of this
                    }
                    exit_application = 1;
                }
            } else if (bps_event_get_domain(event) == dialog_get_domain()) {
                if (DIALOG_RESPONSE == bps_event_get_code(event)) {
                    handle_dialog_response_events(event);
                }
            }
        }
    }

    /*
     * Destroy the dialog, if it exists and cleanup screen resources.
     */
    destroy_dialog();
    cleanup_screen();
    /*
     * Clean up the BPS infrastructure and exit
     */
    bps_shutdown();

    return final_return_code;

}
Beispiel #6
0
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();
}