[PATCH] Implement filedialog upload support for Snowshoe desktop.

3 views
Skip to first unread message

Alexis Menard

unread,
Jun 21, 2012, 9:08:26 AM6/21/12
to snowsh...@googlegroups.com
For now it uses QWidget but when Qt Components will provide an alternative
we can change it.

Reviewed-by: NOBODY
---
src/desktop/BrowserWindow.cpp | 2 ++
src/desktop/DialogRunner.cpp | 36 ++++++++++++++++++++++++++++++++++++
src/desktop/DialogRunner.h | 32 ++++++++++++++++++++++++++++++++
src/desktop/qml/PageWidget.qml | 10 ++++++++++
src/main.pro | 2 ++
5 files changed, 82 insertions(+)
create mode 100644 src/desktop/DialogRunner.cpp
create mode 100644 src/desktop/DialogRunner.h

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..7d0c3bb
--- /dev/null
+++ b/src/desktop/DialogRunner.cpp
@@ -0,0 +1,36 @@
+/****************************************************************************
+ * 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 <QFileDialog>
+
+DialogRunner::DialogRunner(QObject *parent) :
+ QObject(parent)
+{
+}
+
+QStringList DialogRunner::openFileDialog(bool allowMultipleFiles, const QStringList& selectedFiles)
+{
+ QFileDialog dialog;
+ dialog.setAcceptMode(QFileDialog::AcceptOpen);
+ dialog.setFileMode(allowMultipleFiles ? QFileDialog::ExistingFiles : QFileDialog::ExistingFiles);
+ dialog.setWindowTitle(QLatin1String("Open File - Snowshoe"));
+ foreach (const QString &filePath, selectedFiles)
+ dialog.selectFile(filePath);
+ dialog.exec();
+ return dialog.selectedFiles();
+}
diff --git a/src/desktop/DialogRunner.h b/src/desktop/DialogRunner.h
new file mode 100644
index 0000000..535edc6
--- /dev/null
+++ b/src/desktop/DialogRunner.h
@@ -0,0 +1,32 @@
+/****************************************************************************
+ * 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 <QObject>
+#include <QStringList>
+
+class DialogRunner : public QObject
+{
+ Q_OBJECT
+public:
+ explicit DialogRunner(QObject *parent = 0);
+
+ Q_INVOKABLE QStringList openFileDialog(bool allowMultipleFiles, const QStringList& selectedFiles);
+};
+
+#endif // DialogRunner_h
diff --git a/src/desktop/qml/PageWidget.qml b/src/desktop/qml/PageWidget.qml
index 5b84734..374396c 100644
--- a/src/desktop/qml/PageWidget.qml
+++ b/src/desktop/qml/PageWidget.qml
@@ -89,6 +89,16 @@ Item {
maxHeight: 600
}

+ experimental.filePicker: Item {
+ Component.onCompleted : {
+ var files = DialogRunner.openFileDialog(model.allowMutipleFiles, model.fileList)
+ if (files.length)
+ model.accept(files);
+ else
+ model.reject();
+ }
+ }
+
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 \

--
1.7.10.4

Caio Marcelo de Oliveira Filho

unread,
Jun 21, 2012, 9:59:49 AM6/21/12
to snowsh...@googlegroups.com
Could we use dialog.open() instead of exec() and avoid the nested
mainloop here? Connect (maybe indirectly) the signals from the dialog
with the slots exposed in the model object.

Cheers,

--
Caio Marcelo de Oliveira Filho
openBossa @ INdT - Instituto Nokia de Tecnologia

Alexis Menard

unread,
Jun 21, 2012, 11:49:52 AM6/21/12
to snowsh...@googlegroups.com
For now it uses QWidget but when Qt Components will provide an alternative
we can change it.

Reviewed-by: NOBODY
---
src/desktop/BrowserWindow.cpp | 2 ++
src/desktop/DialogRunner.cpp | 52 ++++++++++++++++++++++++++++++++++++++++
src/desktop/DialogRunner.h | 43 +++++++++++++++++++++++++++++++++
src/desktop/qml/PageWidget.qml | 14 +++++++++++
src/main.pro | 2 ++
5 files changed, 113 insertions(+)
create mode 100644 src/desktop/DialogRunner.cpp
create mode 100644 src/desktop/DialogRunner.h

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..ebaa339
--- /dev/null
+++ b/src/desktop/DialogRunner.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+ * 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 <QFileDialog>
+#include <QVariant>
+#include <QDebug>
+DialogRunner::DialogRunner(QObject *parent)
+ : QObject(parent)
+ , m_fileDialog(0)
+ , m_filePickerModel(0)
+{
+}
+
+DialogRunner::~DialogRunner()
+{
+ delete m_fileDialog;
+}
+
+void DialogRunner::openFileDialog(QObject* filePickerModel)
+{
+ if (!filePickerModel)
+ return;
+
+ if (!m_fileDialog)
+ m_fileDialog = new QFileDialog;
+
+ 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_filePickerModel = filePickerModel;
+ connect(m_fileDialog, SIGNAL(rejected()), this, SIGNAL(fileDialogRejected()));
+ m_fileDialog->open(this, SIGNAL(fileDialogAccepted(QStringList)));
+}
+
diff --git a/src/desktop/DialogRunner.h b/src/desktop/DialogRunner.h
new file mode 100644
index 0000000..482c729
--- /dev/null
+++ b/src/desktop/DialogRunner.h
@@ -0,0 +1,43 @@
+/****************************************************************************
+ * 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 <QObject>
+#include <QStringList>
+
+class QFileDialog;
+
+class DialogRunner : public QObject
+{
+ Q_OBJECT
+public:
+ explicit DialogRunner(QObject *parent = 0);
+ ~DialogRunner();
+
+ Q_INVOKABLE void openFileDialog(QObject* filePickerModel);
+
+Q_SIGNALS:
+ void fileDialogAccepted(const QStringList& selectedFiles);
+ void fileDialogRejected();
+
+private:
+ QFileDialog* m_fileDialog;
+ QObject* m_filePickerModel;
+};
+
+#endif // DialogRunner_h
diff --git a/src/desktop/qml/PageWidget.qml b/src/desktop/qml/PageWidget.qml
index 5b84734..2f41fb5 100644
--- a/src/desktop/qml/PageWidget.qml
+++ b/src/desktop/qml/PageWidget.qml
@@ -89,6 +89,20 @@ Item {
maxHeight: 600
}

+ experimental.filePicker: Item {
+ id: picker
+ property QtObject filePickerModel: model
+ Connections {
+ target: DialogRunner
+ onFileDialogAccepted: picker.filePickerModel.accept(selectedFiles)
+ onFileDialogRejected: picker.filePickerModel.reject()
+ }
+
+ Component.onCompleted: {
+ DialogRunner.openFileDialog(filePickerModel)

Caio Marcelo de Oliveira Filho

unread,
Jun 21, 2012, 12:40:33 PM6/21/12
to snowsh...@googlegroups.com
r=me with comments

> +#include <QFileDialog>
> +#include <QVariant>
> +#include <QDebug>
> +DialogRunner::DialogRunner(QObject *parent)

Need a blank line after includes. Do we still need QDebug?

> +void DialogRunner::openFileDialog(QObject* filePickerModel)
> +{
> + if (!filePickerModel)
> + return;
> +
> + if (!m_fileDialog)
> + m_fileDialog = new QFileDialog;

I think we can create the connections here, and later use an open() with no arguments.

> +
> + 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_filePickerModel = filePickerModel;

Do we still need to keep this reference? If we don't maybe openFileDialog could
take allowMultipleFiles and fileList arguments instead of this model
object.

> + connect(m_fileDialog, SIGNAL(rejected()), this, SIGNAL(fileDialogRejected()));
> + m_fileDialog->open(this, SIGNAL(fileDialogAccepted(QStringList)));

See comment above.


> +private:
> + QFileDialog* m_fileDialog;

QScopedPointer?


> + experimental.filePicker: Item {
> + id: picker
> + property QtObject filePickerModel: model
> + Connections {
> + target: DialogRunner
> + onFileDialogAccepted: picker.filePickerModel.accept(selectedFiles)
> + onFileDialogRejected: picker.filePickerModel.reject()

Is this property because we can't use model directly inside
Connections? If so I would add a comment.
Reply all
Reply to author
Forward
0 new messages