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 #include +#include +#include #include #include @@ -29,6 +31,9 @@ class DialogRunner : public QObject { 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 @@ class DialogRunner : public QObject { 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 m_fileDialog; QScopedPointer m_colorDialog; + QScopedPointer m_messageBox; + QScopedPointer 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()