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

git version control git at videolan.org
Sat Mar 7 23:11:01 CET 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar  8 00:10:24 2009 +0200| [77c9756c40adbeae30b1f23b4ca96df719eaad27] | committer: Rémi Denis-Courmont 

Qt4: back-end for dialog_Login

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

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

diff --git a/modules/gui/qt4/dialogs/external.cpp b/modules/gui/qt4/dialogs/external.cpp
index df18490..afec0cb 100644
--- a/modules/gui/qt4/dialogs/external.cpp
+++ b/modules/gui/qt4/dialogs/external.cpp
@@ -2,6 +2,7 @@
  * external.hpp : Dialogs from other LibVLC core and other plugins
  ****************************************************************************
  * Copyright (C) 2009 Rémi Denis-Courmont
+ * Copyright (C) 2006 the VideoLAN team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,6 +28,10 @@
 #include "errors.hpp"
 #include <vlc_dialog.h>
 
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QLabel>
+#include <QLineEdit>
 #include <QMessageBox>
 
 DialogHandler::DialogHandler (intf_thread_t *intf)
@@ -39,12 +44,20 @@ DialogHandler::DialogHandler (intf_thread_t *intf)
      var_Create (intf, "dialog-fatal", VLC_VAR_ADDRESS);
      var_AddCallback (intf, "dialog-fatal", MessageCallback, this);
 
+    connect (this, SIGNAL(authentication(struct dialog_login_t *)),
+             this, SLOT(requestLogin(struct dialog_login_t *)),
+             Qt::BlockingQueuedConnection);
+     var_Create (intf, "dialog-login", VLC_VAR_ADDRESS);
+     var_AddCallback (intf, "dialog-login", LoginCallback, this);
+
      dialog_Register (intf);
 }
 
 DialogHandler::~DialogHandler (void)
 {
     dialog_Unregister (intf);
+    var_DelCallback (intf, "dialog-login", LoginCallback, this);
+    var_DelCallback (intf, "dialog-fatal", MessageCallback, this);
 }
 
 int DialogHandler::MessageCallback (vlc_object_t *obj, const char *var,
@@ -68,3 +81,60 @@ void DialogHandler::displayMessage (const struct dialog_fatal_t *dialog)
         ErrorsDialog::getInstance (intf)->addError(qfu(dialog->title),
                                                    qfu(dialog->message));
 }
+
+int DialogHandler::LoginCallback (vlc_object_t *obj, const char *var,
+                                  vlc_value_t, vlc_value_t value, void *data)
+{
+     DialogHandler *self = (DialogHandler *)data;
+     dialog_login_t *dialog = (dialog_login_t *)value.p_address;
+
+     emit self->authentication (dialog);
+     return VLC_SUCCESS;
+}
+
+void DialogHandler::requestLogin (struct dialog_login_t *data)
+{
+    QDialog *dialog = new QDialog;
+    QLayout *layout = new QVBoxLayout (dialog);
+
+    dialog->setWindowTitle (qfu(data->title));
+    layout->setMargin (2);
+
+    /* User name and password fields */
+    QWidget *panel = new QWidget (dialog);
+    QGridLayout *grid = new QGridLayout;
+    grid->addWidget (new QLabel (qfu(data->message)), 0, 0, 1, 2);
+
+    QLineEdit *userLine = new QLineEdit;
+    grid->addWidget (new QLabel (qtr("User name")), 1, 0);
+    grid->addWidget (userLine, 1, 1);
+
+    QLineEdit *passLine = new QLineEdit;
+    passLine->setEchoMode (QLineEdit::Password);
+    grid->addWidget (new QLabel (qtr("Password")), 2, 0);
+    grid->addWidget (passLine, 2, 1);
+
+    panel->setLayout (grid);
+    layout->addWidget (panel);
+
+    /* OK, Cancel buttons */
+    QDialogButtonBox *buttonBox;
+    buttonBox = new QDialogButtonBox (QDialogButtonBox::Ok
+                                       | QDialogButtonBox::Cancel);
+    connect (buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
+    connect (buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
+    layout->addWidget (buttonBox);
+
+    /* Run the dialog */
+    dialog->setLayout (layout);
+
+    if (dialog->exec ())
+    {
+        *data->username = strdup (qtu(userLine->text ()));
+        *data->password = strdup (qtu(passLine->text ()));
+    }
+    else
+        *data->username = *data->password = NULL;
+
+    delete dialog;
+}
diff --git a/modules/gui/qt4/dialogs/external.hpp b/modules/gui/qt4/dialogs/external.hpp
index 36cc3fd..2daa1d5 100644
--- a/modules/gui/qt4/dialogs/external.hpp
+++ b/modules/gui/qt4/dialogs/external.hpp
@@ -35,14 +35,18 @@ public:
 
 private:
     intf_thread_t *intf;
-    static int MessageCallback( vlc_object_t *, const char *, vlc_value_t,
-                                vlc_value_t, void * );
+    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);
 
 private slots:
     void displayMessage (const struct dialog_fatal_t *);
+    void requestLogin (struct dialog_login_t *data);
 
 signals:
     void message (const struct dialog_fatal_t *);
+    void authentication (struct dialog_login_t *);
 };
 
 #endif




More information about the vlc-devel mailing list