Native of filebrowse using and the cascading Save dialog box

In my application I need to open file and file save dialog box when a specific button is clicked. I looked at the docs of stunts, but I found that the native options. Tried the native alert dialog, change of filebrowse dialog type. It displays well on Simulator, but could not get any output file that will be used in the Qt code.

I pass these parameters

int * num = NULL;

char * folder [1024];
dialog_update (alert_dialog);

to dialog_event_get_filebrowse_filepaths(event,file,num), but it always returns BPS_FAILURE.

In addition, access_shared is present in the bar-descriptor

Here is my code:

//slot function
void App::fileOpen(){
    //===========================
        dialog_instance_t alert_dialog = 0;

        bps_initialize();

        dialog_request_events(0);    //0 indicates that all events are requested

        if (dialog_create_filebrowse(&alert_dialog) != BPS_SUCCESS) {
                    fprintf(stderr, "Failed to create alert dialog.");
                    return ;
            }
            const char* extensions[] = {"*.*","*.jpg","*.jpeg","*.mp3","*.wav","*.mp4","*.txt","*.doc","*.pdf"};
            int items = 9;
            if(dialog_set_filebrowse_filter(alert_dialog, extensions,items) != BPS_SUCCESS){
                fprintf(stderr, "Failed to set alert dialog message text.");
                        dialog_destroy(alert_dialog);
                       alert_dialog = 0;
                       return ;
            }
           if( dialog_set_filebrowse_multiselect(alert_dialog,FALSE)!=BPS_SUCCESS){
               fprintf(stderr, "Failed to set alert dialog message text.");
                            dialog_destroy(alert_dialog);
                           alert_dialog = 0;
                           return ;
           }

        if (dialog_show(alert_dialog) != BPS_SUCCESS) {
            fprintf(stderr, "Failed to show alert dialog.");
            dialog_destroy(alert_dialog);
            alert_dialog = 0;
            return ;
        }

        int shutdown =0;
        while (!shutdown) {
            bps_event_t *event = NULL;
            bps_get_event(&event, -1);    // -1 means that the function waits
                                          // for an event before returning

            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);

                    char **fileArray[]={};
                    int *numFiles = NULL;
                   //
                          if(selectedIndex == 0){
       shutdown = 1;//user press the cancel button on dialog; close the dialog
   }
   else if(selectedIndex == 1){
       if(dialog_event_get_filebrowse_filepaths(event,file,num)!=BPS_SUCCESS){
       fprintf(stderr,"File open fail");
   }
   else{
//debug purposes
       fprintf(stderr,"File array: %d/n",sizeof(file)*1024);
           fprintf(stderr,"Num files: %n",num);
           //fprintf(stderr,"Files int: %d",files);
   }

   }
                }
            }
        }

        if (alert_dialog) {
            dialog_destroy(alert_dialog);
        }
        //===========================
}

Native Subforums have no useful information on this subject. Any help is greatly appreciated

Hello again, here's the example as promised.

To use the native filebrowse dialog box, the native code must run in its own thread to prevent the user interface in the Cascades to block. This is achieved by encapsulating all the dialog box code in a class derived from QThread.  The class I wrote is called FileBrowseDialog

FileBrowseDialog.hpp

#ifndef FILEBROWSEDIALOG_HPP_
#define FILEBROWSEDIALOG_HPP_

#include 
#include 
#include 

/*
 * The file browse dialog displays a dialog to browse and select
 * files from shared folders on the system.
 */
class FileBrowseDialog : public QThread
{
    Q_OBJECT

    /*
     * QML property to allow multiple selection
     */
    Q_PROPERTY(bool multiselect READ getMultiSelect WRITE setMultiSelect)

    /*
     * QML property to read the selected filenames
     */
    Q_PROPERTY(QVariant filepaths READ getFilePaths)

    /*
     * QML property to set or get the file filters. This is an
     * list array variant.
     */
    Q_PROPERTY(QVariant filters READ getFilters WRITE setFilters)
public:
    /*
     * Ctor and Dtor
     */
    FileBrowseDialog(QObject* parent = 0);
    virtual ~FileBrowseDialog();

    /*
     * Exposed to QML to start the run loop which creates and displays the dialog.
     * The dialog is shown until a button is clicked.
     */
    Q_INVOKABLE void show();

public:
    /*
     * Getter for the selected filenames QML property
     */
    QVariant getFilePaths() const;

    /*
     * Setter and Getter for the filters QML property
     */
    QVariant getFilters() const;
    void setFilters(QVariant const& value);

    /*
     * Getter and Setter for the multiselect QML property
     */
    bool getMultiSelect() const;
    void setMultiSelect(bool value);

signals:
    /*
     * Signal emitted when the OK button has been clicked on the browse dialog
     * The OK button is not enabled unless a file is selected
     */
    void selectionCompleted();

    /*
     * Signal emitted when the cancel button has been clicked on the browse dialog
     */
    void selectionCancelled();

protected:
    /*
     * Implements the run loop. Dialog stays open until a button is clicked.
     */
    virtual void run();

protected:
    dialog_instance_t m_dialog;
    bool m_multiSelect;
    QVariantList m_filePaths;
    QVariantList m_filters;
};

#endif /* FILEBROWSEDIALOG_HPP_ */

FileBrowseDialog.cpp

#include "FileBrowseDialog.hpp"
#include 
#include 

FileBrowseDialog::FileBrowseDialog(QObject* parent)
    : QThread(parent)
    , m_multiSelect(false)
{
    m_filters.push_back(QString("*.*"));
}

FileBrowseDialog::~FileBrowseDialog()
{
}

void FileBrowseDialog::show()
{
    if (!isRunning())
    {
        m_filePaths.clear();
        start();
    }
}

QVariant FileBrowseDialog::getFilePaths() const
{
    return m_filePaths;
}

bool FileBrowseDialog::getMultiSelect() const
{
    return m_multiSelect;
}

void FileBrowseDialog::setMultiSelect(bool value)
{
    m_multiSelect = value;
}

QVariant FileBrowseDialog::getFilters() const
{
    return m_filters;
}

void FileBrowseDialog::setFilters(QVariant const& value)
{
    m_filters = value.toList();
    qDebug() << "filter count: " << m_filters.count();
}

void FileBrowseDialog::run()
{
    bps_initialize();

    //request all dialog events
    dialog_request_events(0);
    if (dialog_create_filebrowse(&m_dialog) != BPS_SUCCESS)
    {
        qDebug() << "Failed to create file browse dialog.";
        emit selectionCancelled();
        return;
    }

    //set the selection filters
    if (m_filters.count() > 0)
    {
        char** ext = (char**)new char[m_filters.count()*sizeof(char*)];
        int i = 0;
        for (QVariantList::iterator it = m_filters.begin(); it != m_filters.end(); ++it, ++i)
        {
            QString filter = it->toString();
            if (!filter.trimmed().isEmpty())
            {
                int length = (filter.length() + 1) * sizeof(char);
                ext[i] = new char[length];
                strncpy(ext[i], filter.toAscii(), length);
            }
        }
        if (dialog_set_filebrowse_filter(m_dialog, (const char**)ext, m_filters.count()) != BPS_SUCCESS)
        {
            qDebug() << "unable to set file browse dialog extensions";
        }
        for (i = 0; i < m_filters.count(); i++)
        {
            delete ext[i];
        }
        delete ext;
    }

    if (dialog_show(m_dialog) != BPS_SUCCESS)
    {
        qDebug() << "Failed to show file browse dialog.";
        dialog_destroy(m_dialog);
        m_dialog = 0;
        emit selectionCancelled();
        return;
    }

    bool shutdown = false;
    while (!shutdown)
    {
        bps_event_t* event = NULL;
        bps_get_event(&event, -1);    // -1 means that the function waits
        // for an event before returning

        if (event)
        {
            if (bps_event_get_domain(event) == dialog_get_domain())
            {
                //0=ok, 1=cancel
                int selectedIndex = dialog_event_get_selected_index(event);

                if (selectedIndex == 1)
                {
                    int count;
                    char** filepaths;
                    if (BPS_SUCCESS == dialog_event_get_filebrowse_filepaths(event, &filepaths, &count))
                    {
                        for (int i = 0; i < count; i++)
                        {
                            qDebug() << "selected file: " << filepaths[i];
                            m_filePaths.push_back(QString(filepaths[i]));
                        }
                        bps_free(filepaths);
                    }
                    emit selectionCompleted();
                }
                else
                {
                    emit selectionCancelled();
                }

                qDebug() << "Got file browse dialog click";
                shutdown = true;
            }
        }
    }

    if (m_dialog)
    {
        dialog_destroy(m_dialog);
    }
}

This class derives from QObject (by QThread) which means that it can be used by QML when it exposes properties and signals. The FileBrowseDialog class has 3 properties

-multiple selection: a Boolean flag indicating if single or multiple selection is allowed

-filepaths: a read only value that returns the list of files selected

-Filters: a read/write value is where you can specify one or more filters to file (for example, ".doc", "*.jpg") etc.

The next part is how you call the FileBrowseDialog through the QML. To do this, we must inform the QML of the FileBrowseDialog page. This is done in the App class via the qmlregistertype code.

App.cpp

#include 
#include 
#include 

#include "app.hpp"
#include "FileBrowseDialog.hpp"

using namespace bb::cascades;

App::App()
{
    qmlRegisterType("Dialog.FileBrowse", 1, 0, "FileBrowseDialog");
    QmlDocument *qml = QmlDocument::create("main.qml");
    qml->setContextProperty("cs", this);

    AbstractPane *root = qml->createRootNode();
    Application::setScene(root);
}

The QML is now ready to be able to use the FileBrowseDialog. The example below is a page complete qml which has a button and a label. When we click on the FileBrowseDialog button is open, and all selected files will appear in the label.

Main.QML

import bb.cascades 1.0
import Dialog.FileBrowse 1.0

Page {
    content: Container {
        Label { id: filebrowseDialogLabel }
        Button {
            text : "File Browse Dialog"
            onClicked: {
                filebrowseDialog.show();
            }
        }
        attachedObjects: [
            FileBrowseDialog {
                id: filebrowseDialog
                multiselect : true
                filters : ["*.doc","*.jpg","*.txt"]
                onSelectionCompleted: {
                    if(filebrowseDialog.filepaths.length>0)
                        filebrowseDialogLabel.text = filebrowseDialog.filepaths[0];
                    else
                        filebrowseDialogLabel.text = "no file selected";
                }
                onSelectionCancelled: {
                    filebrowseDialogLabel.text = "file browse dialog was cancelled";
                }
            }
        ]
    }
}

And it's pretty much just invoke the native dialog file navigation in stunts. Please note save the file would follow a similar model, but I found that this dialog box was not particularly useful because it displays only a simple dialogbox with a text file name entry.

See you soon

Swann

Tags: BlackBerry Developers

Similar Questions

  • disable the download of the display of the option 'Save' dialog box

    In my website, I have a file I have let users

    to work with, I can't download the file to open it used to for

    I add this meta to the head, but it does not work

    < meta name = "DownloadOptions" content = "nosave" / >


    Best regards

    Hello

    It seems (IMHO) the case is a bit complicated. You know / have you consider that this detailed publication?

    http://geekswithblogs.NET/theunstablemind/archive/2009/09/02/disabling-the-Open-button-in-Internet-Explorer.aspx

    If my index is not enough for you, please watch plea of Murray:

    http://forums.Adobe.com/message/3017246#3017246

    Hans G.

  • I try to install vista on a computer running xp. XP does not even recognize the vista disc is in the drive. XP recognizes any other drive that I use and the vista drive is recognized on other computers, that I put it in it's not a prob with the disk or cd

    I try to install vista on a computer running xp. XP does not even recognize the vista disc is in the drive. XP recognizes any other drive that I use and the vista drive is recognized on other computers, that I put it in it's not a prob with the disk or cd rom

    The Vista installation disc is a DVD. Apparently, you don't have a DVD player. You would need to purchase/install a DVD-ROM or DVD - RW to install Vista. Are you sure that your hardware supports Vista before doing this?

    http://www.Microsoft.com/Windows/Windows-Vista/get/system-requirements.aspx
    Even if a minimum of 1 GB, the requirements in the real world Vista requires a minimum of 2 GB of RAM to run without problem. You will also need Vista drivers for all your hardware.

    http://www.Microsoft.com/Windows/Windows-Vista/get/Upgrade-Advisor.aspx MS - MVP - Elephant Boy computers - don't panic!

  • Can I use * and the list of the column names in a select query

    PLSQL again.  Can I use * and the list of the column names in a select query, i.e. Select *, col1, col2 from Mytable.  When I do that my questions tend to the bomb.  Can do in other databases.

    Thank you

    Mike

    Hi, Mike,.

    If there is something else in the more SELECT clause *, then * must be qualified with a table name or alias.

    For example:

    SELECT Mytable. *, col1, col2

    FROM MyTable;

  • I bought adobe cc of my student account and installed. Then my computer broke down and I bought a new one. Do not know how to install cc on the new computer. The redemption code can be used and the web campus will not make another p

    I bought adobe cc of my student account and installed. Then my computer broke down and I bought a new one. Do not know how to install cc on the new computer. The redemption code cannot be used and the campus web allow me to make another payment within 1 year in term aid.

    I'll appreciate any help!

    The Adobe ID here in the forums have no CC registered to it, you can activate the CC to your Adobe ID twice. in case you have activated it twice, you have to disable among the previous machine or the third machine will give you the ability to disable from all the previous machine.

    Concerning

    Baudier

  • Save dialog and save dialog boxes under appear empty in several programs. I can't save my work

    Title explains it all.   I click on 'Save' or ' Save as ' DBDesigner4, SrcEdit, and other programs of the dialog box is EMPTY.  The "Favorites", "FTP", and "File Format" options appear and the buttons save and cancel at the bottom, but nothing else.

    I can't choose a destination directory, the name of the file to save, choose the type of file, and when I click on save, nothing happens.

    Hello

    How old are these programs and have you checked the updates or for compatibility with Windows 7 for these programs?

    It seems that these programs can use the older common dialog box has been updated.

    Go to the following site: Windows 7 Compatibility Center

    You will see a tab hardware and software that you can use to locate the product that you want to check for compatibility.

    Select the Compatibility FAQ which will explain how to use the compatibility Web site.

    If you find a piece of software/hardware installed that is not on the compatibility list, go to the website of the manufacturer of this product and check for updates.

    If you find that the program is not compatible with Windows 7 and the manufacturer of software will not support the product on Windows 7, try the following.
    HOW to: Install software using Compatibility Mode

    I hope this helps.

    Thank you for using Windows 7

    Ronnie Vernon MVP
  • How to make or force the Save dialog box for the link pop-up in Dreamweaver

    How do or force the Save dialog box for the pop-up link in Dreamweaver, legally?

    I looked on google how to and what is the code for this but all the answers are to use php or javascript code and paste it into "Web page editor" and edit with your file name. I wonder what the 'legal' way to do that using Dreamweaver options for getting to this: when I click on my link to the image on my Web page, I created, pop-up "save under" dialog box, then the visitor of my site for can save file that my site wish to offer for download.

    It is very easy to just a link certain file (in my case is png image) and open in a new page in the browser, but I want to save as dialog window appears and then visitor on my site to save my png file or not.

    Help!

    You will need to use a script.  If your server supports PHP, this will do what you want. Change filename & path to point to your download folder.  SaveAs download.php.

    Place a link on your page parent download.php file.

    
    

    Nancy O.
    ALT-Web Design & Publishing
    Web | Graphics | Print | Media specialists
    http://ALT-Web.com/
    http://Twitter.com/ALTWEB

  • Use the own user dialog box

    Hello

    I want to use my own user dialog box at startup of the user interface. This dialog gets the user to a database of information and I'm not logging in twice.

    Is it possible, where can I disable the standard dialog box, where I should put my dialog box and what data should I send to TS.

    Using TS3.0 and LV8.2.1.

    schwede greetings

    Schwede-

    If you want to change the user login dialog box when you start TestStand, what you want to do is to change the sequence of LoginLogout in the sequence FrontEndCallbacks.seq file. Before editing, I recommend that you copy the folder \Components\NI\Callbacks\FrontEnd \Components\User\Callbacks in the Directory. Then, modify the files there. You want to replace the steps of connection and disconnection of the sequence of LoginLogout with your own steps that display your own personal dialog box.

    I hope this helps.

  • To display the taskbar and Start Menu Properties dialog box

    To display the taskbar and Start Menu Properties dialog box, click on? in the context menu of the taskbar.

    Hello

    1 are. which option you referring?

    2. what you trying to accomplish?

    I suggest to check the following links and check if it helps.

    Taskbar of Windows: http://windows.microsoft.com/en-us/windows7/products/features/windows-taskbar

    The new taskbar of Windows 7: http://windows.microsoft.com/en-US/windows7/help/better-stronger-faster-the-windows-7-taskbar

    Hope this information is useful.

  • How to remove the Save dialog box before you close the form?

    Hi all

    I've created a form that will open a data connection to a button click.

    I get the error on failure and the code to close my form of app.execMenuItem ("Close");

    but a save dialog box appears before I can close.

    (maybe because I did something on the opening form),

    It is able to remove it? Or simply impossible?

    Best rgds.

    Hmmm,

    What happens if you add?

    Event.Target.Dirty = false;

    app.execMenuItem ("Close");

  • Pipette in the curve adjustment dialog box average pixels, so the color balance is watered.

    Hi all.

    When you use the pipette to set the points black and white pixels of an image in the dialog box curve setting, I found that it seems not middle of the neighbouring pixels or provide a way to select a value "monochrome".  Thus, the color balance is still impaired and is thrown way if you happen to choose a noisy pixel (for example).

    I expect that there is an option to set the size of the sampling for the pipette area, but I don't see one.  I have considered making the monochrome image, defining curves, save them as a preset, and then reload the image color and apply the preset (if she does not leave me); but this seems heavy and hokey.  What is the usual procedure to adjust the tone curve of the image without changing its color balance?

    Thanks for any idea.

    When you select an eyedropper in the curves adjustment dialog box, you went to the eyedropper tool.

    You then set the sample in the Options bar.

    In the curves adjustment layer, any pipette also has sample settings in the Options bar.

  • Completely disable the "Untrusted connection" dialog box

    I am a professional developer stuck behind a proxy at work. The behavior of this power of Attorney causes the SSL connection attempts get a certificate signed by my company, not the web site I try to connect to. I have no control over the proxy, so change this behaviour is out of the question.

    I need to use Firefox for a number of things and am generally fine adding exceptions for sites that I want to connect. However, some sites like github.com loading resources many other areas via SSL (CDN, Google Analytics, Gravatar, etc.). For these sites, I try to add exceptions in order to allow the company a signed, cert but I can only add to github.com, not any other sites, so even after adding an exception I'm brought back in the right to the page "this connection is untrusted". No matter how many times I try to grant a waiver, I never really get to github.com.

    Other browsers on my system are administered remotely and seem to be configured to automatically trust signed certs society. I need to know how to manually configure Firefox to always trust these certificates OR never shows me the unreliable connection dialog box and just maybe show red in the address bar when he does not trust the site cert.

    Apparently in OS X, there are at the level of the authorities of certification system. I don't know why it does not use Firefox, but I was able to export the CA company and import it in Firefox. Finally solved my problem.

  • Can not enter wildcard (*) in the file selection dialog box when opening a file

    It's something I've not seen before. I posted this question in the forum Autodesk AutoCad LT five days ago, but I got no answer at all. Because I'm not sure whether it is a Windows or a problem with Autocad, I thought I'll try to post here, too.

    On one of our AutoCad workstations, when you open a drawing, we cannot enter a wildcard character (*) in the file selection dialog box to help unravel the drawings.

    In other words, say there are 10 versions of a drawing with the number 5008. I should be able to enter the 5008 * and just see these ten designs. On this computer, when I try to type an asterisk (*), I get this error message: invalid character. The following characters are not allowed in file names: \ /: *? "<>

    Now, I know that they are not allowed... but I don't mean to create a file name. I'm just trying to classify them. On our other RTE Autocad workstations, the wildcard character works fine.  What's up with this one? Y at - it a setting or a variable that controls this?

    Thanks - Kevin

    Hello

    ·         The problem occurs with any other application?

    It may be some setting in Auto CAD, which raises the question, and its best you seek help from experts in DAO automatic.

    Diana
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

    If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • Open/Save dialog box as in Windows 7 appear not

    Hello

    I have an intermittent problem with Windows 7.  I tend to keep the programs up and running for weeks, because every day instead of shutting down the computer, I put on standby.  The problem is, after a few weeks to go in and out of sleep, the open/save as box stops in programs which were broadcast during weeks of dialogue.  Here is an example:

    I open word, excel, firefox, January 1.  I opened random documents by clicking through Explorer or just browse the web.  But I never completely close all programs.  I could open up doc1, doc2, doc3, doc1 close, open doc4, narrow doc2, etc..  All programs stay in memory.  After a few weeks, said Jan 28, if I select file-> open, the dialog box is not pop up.  I can open via the documents Explorer, but no file-> open.  Also, I can't make a file-> save as.  I can do-> file save (saves the document), but nothing that causes the dialog box.  It is reproducible in word, excel, firefox, or any other program, I leave the door open for several weeks.

    Here's the weird second problem.  Say I got word, excel, and firefox open for weeks.  If I exit excel completely, and then restart, the dialog box continues to work in excel.  But it remains broken in word and firefox.

    Everyone race in this issue?  Somehow I can fix this without having to restart the program?  The main reason, it's a problem for me is because I do not often know that this problem occurred.  Hopefully, I'll open a spreadsheet from a web page and start editing.  I try to do a save as, only to find the pop dialog box - up will not appear and I can't save the work I do.  Or I have a word document open for weeks.  I usually just hit the Save button, but this time I want to save it under a different name.  I can't do it while this problem is here and I have to close microsoft word completely to get the box to start working again.

    Thanks for your help!

    Hello

    The key is that every so often, you have to restart things, windows programs, the computer itself, in order clearly to all the memory, unload all managers, the .dll files - indeed clear the cobwebs from the computer. If you do not, you can continue to run into the problem you describe.

    For my part, even if I do not turn off my computer, I restart from time to time to get a fresh start, for me, that means being able to have all the features with drag-and-drop processes; for you, this is the Save as dialogue box.

    Nothing else to do.

    Kind regards

    BearPup

  • The open file dialog box does not show up on Windows 7

    My first installation of Win 7 32 bit on my systemeverything was end of work, but after some time all of a sudden all the program that I opened in Windows 7 which has an and save as dialog box or try to download an attachment in mail. the open file dialog box will appear, so I can't be able to open, save, and download any file, it seems that the open a file dialog box is disabled somehow, but I can't be able to find the exact cause of this problem so I need help very badly as soon as possible. So please help and answer...

    Hello Bharat Bhushan Wadhwa,

    Below, I've added a link where other users have had this problem.  There are a few steps to try troubleshooting.  Please let us know status.

    Microsoft Answers:

    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-windows_programs/the-open-file-or-browse-for-file-dialog-box-doesn ' t/50f452f7-f73b-4ad5-8887-b8bb361f07b9

    Thank you

Maybe you are looking for