[vlc-commits] qt: add getTextDialog function to DialogsProvider

Fatih Uzunoglu git at videolan.org
Tue Apr 6 09:54:47 UTC 2021


vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Fri Apr  2 01:22:19 2021 +0300| [771de11ffef7b0e096b9b5b26f58a285005f7351] | committer: Pierre Lamot

qt: add getTextDialog function to DialogsProvider

This static function provides a simple way
to prompt the user and ask for text input.

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=771de11ffef7b0e096b9b5b26f58a285005f7351
---

 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 *);
 



More information about the vlc-commits mailing list