Changeset 2a5e50e0a9 in tspsg


Ignore:
Timestamp:
Aug 31, 2013, 11:52:40 PM (11 years ago)
Author:
Oleksii Serdiuk
Branches:
appveyor, imgbot, master, readme
Children:
6c3fbe1191
Parents:
7ed8b57eea
Message:

[BB10] Use native file pickers.

Also, use "/accounts/1000/shared" folder as default in open/save dialogs.

Cherry-picks from:
c039ebbe827ae1ba92ae89b2e9caef549a96547c
2512bd5a48d086ea03092bc4bdb368c58fc82854

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/mainwindow.cpp

    r7ed8b57eea r2a5e50e0a9  
    8080#ifdef Q_OS_WIN32
    8181#   include "shobjidl.h"
     82#endif
     83
     84#ifdef Q_OS_BLACKBERRY
     85#   include <bb/ApplicationSupport>
     86#   include <bb/cascades/pickers/FilePicker>
     87using namespace bb::cascades::pickers;
    8288#endif
    8389
     
    264270}
    265271
     272#ifdef Q_OS_BLACKBERRY
     273void MainWindow::setWindowModified(bool modified)
     274{
     275    QMainWindow::setWindowModified(modified);
     276    bb::ApplicationSupport app;
     277    if (modified)
     278        app.setClosePrompt(tr("Unsaved Changes"), tr("The task has unsaved changes. Would you really like to close the application?"));
     279    else
     280        app.clearClosePrompt();
     281}
     282#endif
     283
    266284/* Privates **********************************************************/
    267285
     
    286304        return;
    287305
    288 QStringList filters(tr("All Supported Formats") + " (*.tspt *.zkt)");
     306    QStringList filters;
     307#ifdef Q_OS_BLACKBERRY
     308    filters << "*.tspt" << "*.zkt";
     309#else
     310    filters.append(tr("All Supported Formats") + " (*.tspt *.zkt)");
    289311    filters.append(tr("%1 Task Files").arg("TSPSG") + " (*.tspt)");
    290312    filters.append(tr("%1 Task Files").arg("ZKomModRd") + " (*.zkt)");
    291313    filters.append(tr("All Files") + " (*)");
     314#endif
    292315
    293316QString file;
    294317    if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool())
     318#ifdef Q_OS_BLACKBERRY
     319        file = settings->value(OS"/LastUsed/TaskLoadPath", "/accounts/1000/shared/documents").toString();
     320#else
    295321        file = settings->value(OS"/LastUsed/TaskLoadPath").toString();
     322#endif
    296323    else
    297324        file = QFileInfo(fileName).path();
    298 QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
     325#ifdef Q_OS_BLACKBERRY
     326    FilePicker fd;
     327    fd.setType(FileType::Document | FileType::Other);
     328    fd.setDefaultType(FileType::Document);
     329    fd.setTitle(tr("Task Load"));
     330    fd.setFilter(filters);
     331    fd.setDirectories(QStringList(file));
     332    fd.open();
     333
     334    QEventLoop loop;
     335    connect(&fd, SIGNAL(pickerClosed()), &loop, SLOT(quit()));
     336    loop.exec();
     337
     338    if (fd.selectedFiles().count() < 1)
     339        return;
     340    file = fd.selectedFiles().at(0);
     341    if (!QFileInfo(file).isFile())
     342        return;
     343#else
     344    QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
    299345    file = QFileDialog::getOpenFileName(this, tr("Task Load"), file, filters.join(";;"), NULL, opts);
    300346    if (file.isEmpty() || !QFileInfo(file).isFile())
    301347        return;
     348#endif
    302349    if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool())
    303350        settings->setValue(OS"/LastUsed/TaskLoadPath", QFileInfo(file).path());
     
    334381    if (selectedFile.isEmpty()) {
    335382        if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) {
     383#ifdef Q_OS_BLACKBERRY
     384            selectedFile = settings->value(OS"/LastUsed/SolutionSavePath", "/accounts/1000/shared/documents").toString();
     385#else
    336386            selectedFile = settings->value(OS"/LastUsed/SolutionSavePath").toString();
     387#endif
    337388        }
    338389    } else
     
    355406
    356407QStringList filters;
     408#ifdef Q_OS_BLACKBERRY
     409    filters << "*.pdf" << "*.html" << "*.htm" << "*.odf";
     410#else
    357411#ifndef QT_NO_PRINTER
    358412    filters.append(tr("PDF Files") + " (*.pdf)");
     
    362416    filters.append(tr("OpenDocument Files") + " (*.odt)");
    363417    filters.append(tr("All Files") + " (*)");
    364 
    365 QFileDialog::Options opts(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog);
    366 QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, opts);
     418#endif
     419
     420#ifdef Q_OS_BLACKBERRY
     421    FilePicker fd;
     422    fd.setMode(FilePickerMode::Saver);
     423    fd.setType(FileType::Document | FileType::Other);
     424    fd.setDefaultType(FileType::Document);
     425    fd.setAllowOverwrite(true);
     426    fd.setTitle(tr("Solution Save"));
     427//    fd.setDirectories(QStringList(QFileInfo(selectedFile).path()));
     428    fd.setDefaultSaveFileNames(QStringList(selectedFile));
     429    fd.setFilter(filters);
     430    fd.open();
     431
     432    QEventLoop loop;
     433    connect(&fd, SIGNAL(pickerClosed()), &loop, SLOT(quit()));
     434    loop.exec();
     435
     436    if (fd.selectedFiles().count() < 1)
     437        return;
     438    selectedFile = fd.selectedFiles().at(0);
     439#else
     440    QFileDialog::Options opts(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog);
     441    QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, opts);
    367442    if (file.isEmpty())
    368443        return;
    369444    selectedFile = file;
     445#endif
    370446    if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool())
    371447        settings->setValue(OS"/LastUsed/SolutionSavePath", QFileInfo(selectedFile).path());
     
    18161892}
    18171893
    1818 bool MainWindow::saveTask() {
    1819 QStringList filters(tr("%1 Task File").arg("TSPSG") + " (*.tspt)");
     1894bool MainWindow::saveTask()
     1895{
     1896    QStringList filters;
     1897#ifdef Q_OS_BLACKBERRY
     1898    filters << "*.tspt";
     1899#else
     1900    filters.append(tr("%1 Task File").arg("TSPSG") + " (*.tspt)");
    18201901    filters.append(tr("All Files") + " (*)");
     1902#endif
    18211903QString file;
    18221904    if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) {
     1905#ifdef Q_OS_BLACKBERRY
     1906        file = settings->value(OS"/LastUsed/TaskSavePath", "/accounts/1000/shared/documents").toString();
     1907#else
    18231908        file = settings->value(OS"/LastUsed/TaskSavePath").toString();
     1909#endif
    18241910        if (!file.isEmpty())
    18251911            file.append("/");
     
    18301916        file = QFileInfo(fileName).path() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt";
    18311917
    1832 QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
     1918#ifdef Q_OS_BLACKBERRY
     1919    FilePicker fd;
     1920    fd.setMode(FilePickerMode::Saver);
     1921    fd.setType(FileType::Document | FileType::Other);
     1922    fd.setDefaultType(FileType::Document);
     1923    fd.setAllowOverwrite(true);
     1924    fd.setTitle(tr("Task Save"));
     1925//    fd.setDirectories(QStringList(QFileInfo(file).path()));
     1926    fd.setDefaultSaveFileNames(QStringList(file));
     1927    fd.setFilter(filters);
     1928    fd.open();
     1929
     1930    QEventLoop loop;
     1931    connect(&fd, SIGNAL(pickerClosed()), &loop, SLOT(quit()));
     1932    loop.exec();
     1933
     1934    if (fd.selectedFiles().count() < 1)
     1935        return false;
     1936    file = fd.selectedFiles().at(0);
     1937#else
     1938    QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
    18331939    file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts);
    18341940    if (file.isEmpty())
    18351941        return false;
    1836     else if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool())
     1942#endif
     1943    if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool())
    18371944        settings->setValue(OS"/LastUsed/TaskSavePath", QFileInfo(file).path());
    18381945    if (QFileInfo(file).suffix().isEmpty()) {
  • src/mainwindow.h

    r7ed8b57eea r2a5e50e0a9  
    6363    MainWindow(QWidget *parent = 0);
    6464    ~MainWindow();
     65
     66#ifdef Q_OS_BLACKBERRY
     67public slots:
     68    void setWindowModified(bool modified);
     69#endif
    6570
    6671private slots:
  • tspsg.pro

    r7ed8b57eea r2a5e50e0a9  
    2828    DEFINES += QT_NO_PRINTDIALOG
    2929    DEFINES += QT_NO_PRINTPREVIEWDIALOG
     30
     31    QT += xml declarative
     32    LIBS += -lbb -lbbcascadespickers
    3033}
    3134
Note: See TracChangeset for help on using the changeset viewer.