Commit 77c9756c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Qt4: back-end for dialog_Login

parent 2a2773ed
......@@ -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;
}
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment