summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@openbossa.org>2012-07-18 17:56:28 -0300
committerAlexis Menard <alexis.menard@openbossa.org>2012-07-18 18:12:01 -0300
commitb9b2d30f988c92c941303b82afcc909852039937 (patch)
treee485fd5b4530c572cafea919f4f99a2f50373b14
parent5edf17a3922fa3185a28cf442c00cd6a448c1dbf (diff)
downloadsnowshoe-b9b2d30f988c92c941303b82afcc909852039937.tar.gz
Implement JS alert, prompt, confirm.
Reviewed-by: Rafael Brandao
-rw-r--r--src/desktop/DialogRunner.cpp60
-rw-r--r--src/desktop/DialogRunner.h18
-rw-r--r--src/desktop/qml/PageWidget.qml45
3 files changed, 123 insertions, 0 deletions
diff --git a/src/desktop/DialogRunner.cpp b/src/desktop/DialogRunner.cpp
index edf1fe2..2734791 100644
--- a/src/desktop/DialogRunner.cpp
+++ b/src/desktop/DialogRunner.cpp
@@ -60,3 +60,63 @@ void DialogRunner::openColorDialog(QObject* colorDialogModel)
m_colorDialog->open();
}
+void DialogRunner::openAlert(QObject* alertModel)
+{
+ if (!alertModel)
+ return;
+ ensureMessageBox();
+ m_messageBox->setText(alertModel->property("message").toString());
+ m_messageBox->setIcon(QMessageBox::Warning);
+ m_messageBox->setStandardButtons(QMessageBox::Ok);
+ openMessageBox();
+}
+
+void DialogRunner::openConfirm(QObject* confirmModel)
+{
+ if (!confirmModel)
+ return;
+ ensureMessageBox();
+ m_messageBox->setText(confirmModel->property("message").toString());
+ m_messageBox->setIcon(QMessageBox::Question);
+ m_messageBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+ openMessageBox();
+}
+
+void DialogRunner::openPrompt(QObject* promptModel)
+{
+ if (!promptModel)
+ return;
+
+ if (!m_inputDialog)
+ m_inputDialog.reset(new QInputDialog);
+
+ m_inputDialog->setInputMode(QInputDialog::TextInput);
+ m_inputDialog->setLabelText(promptModel->property("message").toString());
+ m_inputDialog->setTextValue(promptModel->property("defaultValue").toString());
+ connect(m_inputDialog.data(), SIGNAL(rejected()), this, SIGNAL(inputDialogRejected()));
+ connect(m_inputDialog.data(), SIGNAL(textValueSelected(const QString&)), this, SIGNAL(inputDialogAccepted(const QString&)));
+ m_inputDialog->open();
+}
+
+void DialogRunner::ensureMessageBox()
+{
+ if (!m_messageBox)
+ m_messageBox.reset(new QMessageBox);
+}
+
+void DialogRunner::openMessageBox()
+{
+ connect(m_messageBox.data(), SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(onMessageBoxButtonClicked(QAbstractButton*)));
+
+ m_messageBox->setWindowTitle(QLatin1String("Snowshoe"));
+ m_messageBox->open();
+}
+
+void DialogRunner::onMessageBoxButtonClicked(QAbstractButton* button)
+{
+ QMessageBox::ButtonRole role = m_messageBox->buttonRole(button);
+ if (role == QMessageBox::AcceptRole)
+ emit messageBoxAccepted();
+ if (role == QMessageBox::RejectRole)
+ emit messageBoxRejected();
+}
diff --git a/src/desktop/DialogRunner.h b/src/desktop/DialogRunner.h
index c99f9e5..ecefa6e 100644
--- a/src/desktop/DialogRunner.h
+++ b/src/desktop/DialogRunner.h
@@ -19,6 +19,8 @@
#include <QColorDialog>
#include <QFileDialog>
+#include <QInputDialog>
+#include <QMessageBox>
#include <QObject>
#include <QStringList>
@@ -29,6 +31,9 @@ public:
Q_INVOKABLE void openFileDialog(QObject* filePickerModel);
Q_INVOKABLE void openColorDialog(QObject* colorDialogModel);
+ Q_INVOKABLE void openAlert(QObject* alertModel);
+ Q_INVOKABLE void openConfirm(QObject* confirmModel);
+ Q_INVOKABLE void openPrompt(QObject* promptModel);
Q_SIGNALS:
void fileDialogAccepted(const QStringList& selectedFiles);
@@ -37,9 +42,22 @@ Q_SIGNALS:
void colorDialogAccepted(const QColor& selectedColor);
void colorDialogRejected();
+ void messageBoxAccepted();
+ void messageBoxRejected();
+
+ void inputDialogAccepted(const QString& text);
+ void inputDialogRejected();
+
+private slots:
+ void onMessageBoxButtonClicked(QAbstractButton*);
+
private:
+ void ensureMessageBox();
+ void openMessageBox();
QScopedPointer<QFileDialog> m_fileDialog;
QScopedPointer<QColorDialog> m_colorDialog;
+ QScopedPointer<QMessageBox> m_messageBox;
+ QScopedPointer<QInputDialog> m_inputDialog;
};
#endif // DialogRunner_h
diff --git a/src/desktop/qml/PageWidget.qml b/src/desktop/qml/PageWidget.qml
index 0434bcb..b32b1fb 100644
--- a/src/desktop/qml/PageWidget.qml
+++ b/src/desktop/qml/PageWidget.qml
@@ -119,6 +119,51 @@ Item {
}
}
+ experimental.alertDialog: Item {
+ id: alertBox
+ // We can't use the model directly in the Connection below.
+ property QtObject alertBoxModel: model
+ Connections {
+ target: DialogRunner
+ onMessageBoxRejected: alertBox.alertBoxModel.dismiss()
+ onMessageBoxAccepted: alertBox.alertBoxModel.dismiss()
+ }
+
+ Component.onCompleted: {
+ DialogRunner.openAlert(alertBoxModel)
+ }
+ }
+
+ experimental.confirmDialog: Item {
+ id: confirmBox
+ // We can't use the model directly in the Connection below.
+ property QtObject confirmBoxModel: model
+ Connections {
+ target: DialogRunner
+ onMessageBoxRejected: confirmBox.confirmBoxModel.reject()
+ onMessageBoxAccepted: confirmBox.confirmBoxModel.accept()
+ }
+
+ Component.onCompleted: {
+ DialogRunner.openConfirm(confirmBoxModel)
+ }
+ }
+
+ experimental.promptDialog: Item {
+ id: promptDialog
+ // We can't use the model directly in the Connection below.
+ property QtObject promptDialogModel: model
+ Connections {
+ target: DialogRunner
+ onInputDialogRejected: promptDialog.promptDialogModel.reject()
+ onInputDialogAccepted: promptDialog.promptDialogModel.accept(text)
+ }
+
+ Component.onCompleted: {
+ DialogRunner.openPrompt(promptDialogModel)
+ }
+ }
+
experimental.onDownloadRequested: {
downloadItem.destinationPath = BrowserWindow.decideDownloadPath(downloadItem.suggestedFilename)
downloadItem.start()