[vlc-devel] commit: Qt4: back-end for dialog_Question ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Mar 8 11:38:10 CET 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar  8 12:05:11 2009 +0200| [97ce64ff295e77ebd271a350c773cba4682cc17e] | committer: Rémi Denis-Courmont 

Qt4: back-end for dialog_Question

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

 modules/gui/qt4/dialogs/external.cpp |   44 ++++++++++++++++++++++++++++++++++
 modules/gui/qt4/dialogs/external.hpp |    8 ++++-
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/modules/gui/qt4/dialogs/external.cpp b/modules/gui/qt4/dialogs/external.cpp
index afec0cb..8b7b031 100644
--- a/modules/gui/qt4/dialogs/external.cpp
+++ b/modules/gui/qt4/dialogs/external.cpp
@@ -50,12 +50,19 @@ DialogHandler::DialogHandler (intf_thread_t *intf)
      var_Create (intf, "dialog-login", VLC_VAR_ADDRESS);
      var_AddCallback (intf, "dialog-login", LoginCallback, this);
 
+    connect (this, SIGNAL(question(struct dialog_question_t *)),
+             this, SLOT(requestAnswer(struct dialog_question_t *)),
+             Qt::BlockingQueuedConnection);
+     var_Create (intf, "dialog-question", VLC_VAR_ADDRESS);
+     var_AddCallback (intf, "dialog-question", QuestionCallback, this);
+
      dialog_Register (intf);
 }
 
 DialogHandler::~DialogHandler (void)
 {
     dialog_Unregister (intf);
+    var_DelCallback (intf, "dialog-question", QuestionCallback, this);
     var_DelCallback (intf, "dialog-login", LoginCallback, this);
     var_DelCallback (intf, "dialog-fatal", MessageCallback, this);
 }
@@ -138,3 +145,40 @@ void DialogHandler::requestLogin (struct dialog_login_t *data)
 
     delete dialog;
 }
+
+int DialogHandler::QuestionCallback (vlc_object_t *obj, const char *var,
+                                     vlc_value_t, vlc_value_t value, void *data)
+{
+     DialogHandler *self = (DialogHandler *)data;
+     dialog_question_t *dialog = (dialog_question_t *)value.p_address;
+
+     emit self->question (dialog);
+     return VLC_SUCCESS;
+}
+
+void DialogHandler::requestAnswer (struct dialog_question_t *data)
+{
+    QMessageBox *box = new QMessageBox (QMessageBox::Question,
+                                        qfu(data->title), qfu(data->message));
+    QAbstractButton *yes = (data->yes != NULL)
+        ? box->addButton ("&" + qfu(data->yes), QMessageBox::YesRole) : NULL;
+    QAbstractButton *no = (data->no != NULL)
+        ? box->addButton ("&" + qfu(data->no), QMessageBox::NoRole) : NULL;
+    QAbstractButton *cancel = (data->cancel != NULL)
+        ? box->addButton ("&" + qfu(data->cancel), QMessageBox::RejectRole)
+        : NULL;
+
+    box->exec ();
+
+    int answer;
+    if (box->clickedButton () == yes)
+        answer = 1;
+    else
+    if (box->clickedButton () == no)
+        answer = 2;
+    else
+        answer = 3;
+
+    delete box;
+    data->answer = answer;
+}
diff --git a/modules/gui/qt4/dialogs/external.hpp b/modules/gui/qt4/dialogs/external.hpp
index 2daa1d5..0ff46e1 100644
--- a/modules/gui/qt4/dialogs/external.hpp
+++ b/modules/gui/qt4/dialogs/external.hpp
@@ -38,15 +38,19 @@ private:
     static int MessageCallback (vlc_object_t *, const char *,
                                 vlc_value_t, vlc_value_t, void *);
     static int LoginCallback (vlc_object_t *obj, const char *,
-                              vlc_value_t, vlc_value_t, void *data);
+                              vlc_value_t, vlc_value_t, void *);
+    static int QuestionCallback (vlc_object_t *obj, const char *,
+                                 vlc_value_t, vlc_value_t, void *);
 
 private slots:
     void displayMessage (const struct dialog_fatal_t *);
-    void requestLogin (struct dialog_login_t *data);
+    void requestLogin (struct dialog_login_t *);
+    void requestAnswer (struct dialog_question_t *);
 
 signals:
     void message (const struct dialog_fatal_t *);
     void authentication (struct dialog_login_t *);
+    void question (struct dialog_question_t *);
 };
 
 #endif




More information about the vlc-devel mailing list