diff options
author | Alexis Menard <alexis.menard@openbossa.org> | 2012-06-21 10:05:53 -0300 |
---|---|---|
committer | Alexis Menard <alexis.menard@openbossa.org> | 2012-06-21 14:04:35 -0300 |
commit | dbeb77f0632bf3a43ab59c0c1970a981f856d05a (patch) | |
tree | 03838c9084e6a3f5f8515d1c7807173c5287db78 | |
parent | c199980cd1bd242f8ce6d4f61aed024fb07899b7 (diff) | |
download | snowshoe-dbeb77f0632bf3a43ab59c0c1970a981f856d05a.tar.gz |
Implement filedialog upload support for Snowshoe desktop.
For now it uses QWidget but when Qt Components will provide an alternative
we can change it.
Reviewed-by: Caio Oliveira
-rw-r--r-- | src/desktop/BrowserWindow.cpp | 2 | ||||
-rw-r--r-- | src/desktop/DialogRunner.cpp | 46 | ||||
-rw-r--r-- | src/desktop/DialogRunner.h | 40 | ||||
-rw-r--r-- | src/desktop/qml/PageWidget.qml | 15 | ||||
-rw-r--r-- | src/main.pro | 2 |
5 files changed, 105 insertions, 0 deletions
diff --git a/src/desktop/BrowserWindow.cpp b/src/desktop/BrowserWindow.cpp index a29c528..b5a22a7 100644 --- a/src/desktop/BrowserWindow.cpp +++ b/src/desktop/BrowserWindow.cpp @@ -19,6 +19,7 @@ #include "BookmarkModel.h" #include "DatabaseManager.h" +#include "DialogRunner.h" #include "Shortcut.h" #include "UrlTools.h" #include <QtCore/QCoreApplication> @@ -138,6 +139,7 @@ void BrowserWindow::setupDeclarativeEnvironment() QQmlContext* context = rootContext(); context->setContextProperty("BookmarkModel", DatabaseManager::instance()->bookmarkDataBaseModel()); context->setContextProperty("BrowserWindow", this); + context->setContextProperty("DialogRunner", new DialogRunner(this)); context->setContextProperty("UrlTools", new UrlTools(this)); context->setContextProperty("StateTracker", &m_stateTracker); diff --git a/src/desktop/DialogRunner.cpp b/src/desktop/DialogRunner.cpp new file mode 100644 index 0000000..17442fc --- /dev/null +++ b/src/desktop/DialogRunner.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** + * Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) * + * * + * This file may be used under the terms of the GNU Lesser * + * General Public License version 2.1 as published by the Free Software * + * Foundation and appearing in the file LICENSE.LGPL included in the * + * packaging of this file. Please review the following information to * + * ensure the GNU Lesser General Public License version 2.1 requirements * + * will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + ****************************************************************************/ + +#include "DialogRunner.h" + +#include <QVariant> + +DialogRunner::DialogRunner(QObject *parent) + : QObject(parent) + , m_fileDialog(0) +{ +} + +void DialogRunner::openFileDialog(QObject* filePickerModel) +{ + if (!filePickerModel) + return; + + if (!m_fileDialog) { + m_fileDialog.reset(new QFileDialog); + connect(m_fileDialog.data(), SIGNAL(rejected()), this, SIGNAL(fileDialogRejected())); + connect(m_fileDialog.data(), SIGNAL(filesSelected(QStringList)), this, SIGNAL(fileDialogAccepted(QStringList))); + } + + m_fileDialog->setAcceptMode(QFileDialog::AcceptOpen); + m_fileDialog->setFileMode(filePickerModel->property("allowMultipleFiles").toBool() ? QFileDialog::ExistingFiles : QFileDialog::ExistingFiles); + m_fileDialog->setWindowTitle(QLatin1String("Open File - Snowshoe")); + + foreach (const QString &filePath, filePickerModel->property("fileList").toStringList()) + m_fileDialog->selectFile(filePath); + m_fileDialog->open(); +} + diff --git a/src/desktop/DialogRunner.h b/src/desktop/DialogRunner.h new file mode 100644 index 0000000..923fd26 --- /dev/null +++ b/src/desktop/DialogRunner.h @@ -0,0 +1,40 @@ +/**************************************************************************** + * Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) * + * * + * This file may be used under the terms of the GNU Lesser * + * General Public License version 2.1 as published by the Free Software * + * Foundation and appearing in the file LICENSE.LGPL included in the * + * packaging of this file. Please review the following information to * + * ensure the GNU Lesser General Public License version 2.1 requirements * + * will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + ****************************************************************************/ + +#ifndef DialogRunner_h +#define DialogRunner_h + +#include <QFileDialog> +#include <QObject> +#include <QStringList> + +class DialogRunner : public QObject +{ + Q_OBJECT +public: + explicit DialogRunner(QObject *parent = 0); + + Q_INVOKABLE void openFileDialog(QObject* filePickerModel); + +Q_SIGNALS: + void fileDialogAccepted(const QStringList& selectedFiles); + void fileDialogRejected(); + +private: + QScopedPointer<QFileDialog> m_fileDialog; +}; + +#endif // DialogRunner_h diff --git a/src/desktop/qml/PageWidget.qml b/src/desktop/qml/PageWidget.qml index 5b84734..e652fe0 100644 --- a/src/desktop/qml/PageWidget.qml +++ b/src/desktop/qml/PageWidget.qml @@ -89,6 +89,21 @@ Item { maxHeight: 600 } + experimental.filePicker: Item { + id: picker + // We can't use the model directly in the Connection below. + property QtObject filePickerModel: model + Connections { + target: DialogRunner + onFileDialogAccepted: picker.filePickerModel.accept(selectedFiles) + onFileDialogRejected: picker.filePickerModel.reject() + } + + Component.onCompleted: { + DialogRunner.openFileDialog(filePickerModel) + } + } + experimental.onDownloadRequested: { downloadItem.destinationPath = BrowserWindow.decideDownloadPath(downloadItem.suggestedFilename) downloadItem.start() diff --git a/src/main.pro b/src/main.pro index 24a6703..7380072 100644 --- a/src/main.pro +++ b/src/main.pro @@ -15,12 +15,14 @@ linux-g++-maemo { SOURCES += \ desktop/BrowserWindow.cpp \ + desktop/DialogRunner.cpp \ desktop/Shortcut.cpp \ mobile/BrowserWindowMobile.cpp \ main.cpp HEADERS += \ desktop/BrowserWindow.h \ + desktop/DialogRunner.h \ mobile/BrowserWindowMobile.h \ desktop/Shortcut.h \ |