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;
}
Example #2
0
void handle_dialog_response(bps_event_t *event)
{
    /*
     * Double check that the event is valid
     */
    if (event == NULL) {
        return;
    }

    int selectedIndex = dialog_event_get_selected_index(event);
    fprintf(stderr,"SELECTION: %i\n",selectedIndex);
    switch (selectedIndex){
    case 2:
    	navigator_invoke("appworld://content/92507", 0);
        	break;
    case 1:
    	navigator_invoke("http://www.mappau.com", 0);
        	break;
    }

    dialog_destroy(alert_dialog);
    alert_dialog = 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();
}