[vlc-devel] [PATCH 07/29] qt: add getTextDialog function to DialogsProvider

Fatih Uzunoglu fuzun54 at outlook.com
Thu Apr 1 22:22:19 UTC 2021


This static function provides a simple way
to prompt the user and ask for text input.
---
 modules/gui/qt/dialogs/dialogs_provider.cpp | 31 +++++++++++++++++++++
 modules/gui/qt/dialogs/dialogs_provider.hpp |  5 ++++
 2 files changed, 36 insertions(+)

diff --git a/modules/gui/qt/dialogs/dialogs_provider.cpp b/modules/gui/qt/dialogs/dialogs_provider.cpp
index 3b33280315..414bdb60a3 100644
--- a/modules/gui/qt/dialogs/dialogs_provider.cpp
+++ b/modules/gui/qt/dialogs/dialogs_provider.cpp
@@ -60,6 +60,7 @@
 #include <QSignalMapper>
 #include <QFileDialog>
 #include <QUrl>
+#include <QInputDialog>
 
 #define I_OP_DIR_WINTITLE I_DIR_OR_FOLDER( N_("Open Directory"), \
                                            N_("Open Folder") )
@@ -111,6 +112,36 @@ QString DialogsProvider::getSaveFileName( QWidget *parent,
     return QFileDialog::getSaveFileUrl( parent, caption, dir, filter, selectedFilter, QFileDialog::Options(), schemes).toLocalFile();
 }
 
+QVariant DialogsProvider::getTextDialog(QWidget *parent,
+                                        const QString &title,
+                                        const QString &label,
+                                        const QString &placeholder,
+                                        bool *ok)
+{
+    bool _ok = false;
+    QString ret = QInputDialog::getText(parent,
+                                        title,
+                                        label,
+                                        QLineEdit::Normal,
+                                        placeholder,
+                                        ok ? ok : &_ok);
+
+    if (!ok)
+    {
+        // When this function is called from the QML side, instead of setting `ok` parameter
+        // a QVariantMap with key `ok` and `text` is returned instead
+
+        QVariantMap map;
+        map["text"] = ret;
+        map["ok"] = _ok;
+        return map;
+    }
+    else
+    {
+        return ret;
+    }
+}
+
 void DialogsProvider::quit()
 {
     b_isDying = true;
diff --git a/modules/gui/qt/dialogs/dialogs_provider.hpp b/modules/gui/qt/dialogs/dialogs_provider.hpp
index a83f7d04e5..eab38d82cd 100644
--- a/modules/gui/qt/dialogs/dialogs_provider.hpp
+++ b/modules/gui/qt/dialogs/dialogs_provider.hpp
@@ -100,6 +100,11 @@ public:
                                     const QString &filter = QString(),
                                     QString *selectedFilter = NULL );
 
+    Q_INVOKABLE static QVariant getTextDialog(QWidget *parent, const QString& title,
+                                              const QString& label,
+                                              const QString& placeholder,
+                                              bool* ok = nullptr);
+
 protected:
     void customEvent( QEvent *);
 
-- 
2.27.0



More information about the vlc-devel mailing list