* 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
#include "errors.hpp"
#include <vlc_dialog.h>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QLabel>
+#include <QLineEdit>
#include <QMessageBox>
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,
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;
+}