Use File picker with c++ in your BlackBerry Application

by Developer on ‎02-24-2014 10:07 AM (793 Views)


What is file Picker ?
File Picker allows you to select a file from your device or to save a file to particular location.

 

There are two types of mode available
1. Picker Mode : used to traverse the folder hierarchy to select a particular file
2. Saver Mode : used to specify a file name and location to save your file

 

You can specify what type of display you want ListView or GridView.

 

  • Link the appropriate library to be able to use the classes you want in your app. In your .pro file, add the following line immediately after the CONFIG line:

LIBS += -lbbcascadespickers

 

  • To implement it in your app, attach the FilePicker and specify the type mode title directories and logic for the picker. Where,
      • Type parameter: specifies the FIleType to associate with the FilePicker.
      • Mode parameter: specifies the mode of the FilePicker.
      • Title parameter: specifies the title for the FilePicker

 

Example 1: PICKER MODE

 

import bb.cascades 1.0
import bb.cascades.pickers 1.0

Page {
      content: Container {
                                   Button {
                                            text: "FilePicker from QML"
                                                  onClicked: {
                                                                           filePicker.open()
                                                                       }
                                                }
                                       }
                             
                                  attachedObjects: [
                                             FilePicker {
                                                          id: filePicker
                                                          type : FileType.Picture
                                                          title : "Select Picture"
                                                          directories : ["/accounts/1000/shared/misc"]
                                             onFileSelected : {
                                                         console.log("FileSelected signal received : "+ selectedFiles);
                                                                           }
                                                                    }
                                             ]
         }

 

 

Create FilePicker with c++

 

FilePicker* filePicker = new FilePicker();
filePicker->setType(FileType::Picture);
filePicker->setTitle("Select Picture");
filePicker->setMode(FilePickerMode::Picker);
filePicker->setDirectories(QStringList("/accounts/1000/shared/misc")); 
filePicker->open();

// Connect the fileSelected() signal with the slot.

// If any Q_ASSERT statement(s) indicate that the slot failed to connect to
// the signal, make sure you know exactly why this has happened. This is not
// normal, and will cause your app to stop working!!
bool connectResult;

// Since the variable is not used in the app, this is added to avoid a
// compiler warning.
Q_UNUSED(connectResult);

connectResult = QObject::connect(filePicker,
SIGNAL(fileSelected(const QStringList&)),
this,
SLOT(onFileSelected(const QStringList&)));

// This is only available in Debug builds.
Q_ASSERT(connectResult);

// Connect the canceled() signal with the slot.
connectResult = QObject::connect(filePicker,
SIGNAL(canceled()),
this,
SLOT(onCanceled()));

// This is only available in Debug builds.
Q_ASSERT(connectResult);

 

 

 

Example 2: PICKER MODE

 

attachedObjects: [
                 FilePicker {
                                     id: picker
                                     title: "File Picker"
                                     mode: FilePickerMode.Saver
                                      type: FileType.Picture
                                      viewMode: FilePickerViewMode.ListView
                                       directories : ["/accounts/1000/shared/misc"]
               onFileSelected : {
                                       console.log("FileSelected signal received : " + selectedFiles);
                                             }
                                   }
                           ]
 

 

 

Example : Create FilePicker in c++

FilePicker* filePicker = new FilePicker();
filePicker->setType(FileType::Picture);
filePicker->setTitle("Save Picture");
filePicker->setMode(FilePickerMode::Saver);
filePicker->setDirectories(QStringList("/accounts/1000/shared/misc")); 
filePicker->open();

// Connect the fileSelected() signal with the slot.

// If any Q_ASSERT statement(s) indicate that the slot failed to connect to
// the signal, make sure you know exactly why this has happened. This is not
// normal, and will cause your app to stop working!!
bool connectResult;

// Since the variable is not used in the app, this is added to avoid a
// compiler warning.
Q_UNUSED(connectResult);

connectResult = QObject::connect(filePicker,
SIGNAL(fileSelected(const QStringList&)),
this,
SLOT(onFileSelected(const QStringList&)));

// This is only available in Debug builds.
Q_ASSERT(connectResult);

// Connect the canceled() signal with the slot.
connectResult = QObject::connect(filePicker,
SIGNAL(canceled()),
this,
SLOT(onCanceled()));

// This is only available in Debug builds.
Q_ASSERT(connectResult);