Commit 8693ccb6 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

VLC pointer variable callback -> Qt4 signal class

This could easily be extended to support varaibles of other types, and
set/get operations. But I don't need that :D
parent e598037c
...@@ -34,27 +34,42 @@ ...@@ -34,27 +34,42 @@
#include <QLineEdit> #include <QLineEdit>
#include <QMessageBox> #include <QMessageBox>
DialogHandler::DialogHandler (intf_thread_t *intf) QVLCVariable::QVLCVariable (vlc_object_t *obj, const char *varname, int type)
: object (obj), name (qfu(varname))
{ {
this->intf = intf; var_Create (object, qtu(name), type);
var_AddCallback (object, qtu(name), callback, this);
}
connect (this, SIGNAL(message(const struct dialog_fatal_t *)), QVLCVariable::~QVLCVariable (void)
this, SLOT(displayMessage(const struct dialog_fatal_t *)), {
Qt::BlockingQueuedConnection); var_DelCallback (object, qtu(name), callback, this);
var_Create (intf, "dialog-fatal", VLC_VAR_ADDRESS); var_Destroy (object, qtu(name));
var_AddCallback (intf, "dialog-fatal", MessageCallback, this); }
int QVLCVariable::callback (vlc_object_t *object, const char *,
vlc_value_t, vlc_value_t cur, void *data)
{
QVLCVariable *self = (QVLCVariable *)data;
emit self->pointerChanged (object, cur.p_address);
}
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);
connect (this, SIGNAL(question(struct dialog_question_t *)), DialogHandler::DialogHandler (intf_thread_t *intf)
this, SLOT(requestAnswer(struct dialog_question_t *)), : intf (intf),
message (VLC_OBJECT(intf), "dialog-fatal", VLC_VAR_ADDRESS),
login (VLC_OBJECT(intf), "dialog-login", VLC_VAR_ADDRESS),
question (VLC_OBJECT(intf), "dialog-question", VLC_VAR_ADDRESS)
{
connect (&message, SIGNAL(pointerChanged(vlc_object_t *, void *)),
this, SLOT(displayMessage(vlc_object_t *, void *)),
Qt::BlockingQueuedConnection);
connect (&login, SIGNAL(pointerChanged(vlc_object_t *, void *)),
this, SLOT(requestLogin(vlc_object_t *, void *)),
Qt::BlockingQueuedConnection);
connect (&question, SIGNAL(pointerChanged(vlc_object_t *, void *)),
this, SLOT(requestAnswer(vlc_object_t *, void *)),
Qt::BlockingQueuedConnection); Qt::BlockingQueuedConnection);
var_Create (intf, "dialog-question", VLC_VAR_ADDRESS);
var_AddCallback (intf, "dialog-question", QuestionCallback, this);
dialog_Register (intf); dialog_Register (intf);
} }
...@@ -62,24 +77,12 @@ DialogHandler::DialogHandler (intf_thread_t *intf) ...@@ -62,24 +77,12 @@ DialogHandler::DialogHandler (intf_thread_t *intf)
DialogHandler::~DialogHandler (void) DialogHandler::~DialogHandler (void)
{ {
dialog_Unregister (intf); dialog_Unregister (intf);
var_DelCallback (intf, "dialog-question", QuestionCallback, this);
var_DelCallback (intf, "dialog-login", LoginCallback, this);
var_DelCallback (intf, "dialog-fatal", MessageCallback, this);
} }
int DialogHandler::MessageCallback (vlc_object_t *obj, const char *var, void DialogHandler::displayMessage (vlc_object_t *, void *value)
vlc_value_t, vlc_value_t value,
void *data)
{ {
DialogHandler *self = (DialogHandler *)data; const dialog_fatal_t *dialog = (const dialog_fatal_t *)value;
const dialog_fatal_t *dialog = (const dialog_fatal_t *)value.p_address;
emit self->message (dialog);
return VLC_SUCCESS;
}
void DialogHandler::displayMessage (const struct dialog_fatal_t *dialog)
{
if (dialog->modal) if (dialog->modal)
QMessageBox::critical (NULL, qfu(dialog->title), qfu(dialog->message), QMessageBox::critical (NULL, qfu(dialog->title), qfu(dialog->message),
QMessageBox::Ok); QMessageBox::Ok);
...@@ -89,18 +92,9 @@ void DialogHandler::displayMessage (const struct dialog_fatal_t *dialog) ...@@ -89,18 +92,9 @@ void DialogHandler::displayMessage (const struct dialog_fatal_t *dialog)
qfu(dialog->message)); qfu(dialog->message));
} }
int DialogHandler::LoginCallback (vlc_object_t *obj, const char *var, void DialogHandler::requestLogin (vlc_object_t *, void *value)
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)
{ {
dialog_login_t *data = (dialog_login_t *)value;
QDialog *dialog = new QDialog; QDialog *dialog = new QDialog;
QLayout *layout = new QVBoxLayout (dialog); QLayout *layout = new QVBoxLayout (dialog);
...@@ -146,18 +140,10 @@ void DialogHandler::requestLogin (struct dialog_login_t *data) ...@@ -146,18 +140,10 @@ void DialogHandler::requestLogin (struct dialog_login_t *data)
delete dialog; delete dialog;
} }
int DialogHandler::QuestionCallback (vlc_object_t *obj, const char *var, void DialogHandler::requestAnswer (vlc_object_t *, void *value)
vlc_value_t, vlc_value_t value, void *data)
{ {
DialogHandler *self = (DialogHandler *)data; dialog_question_t *data = (dialog_question_t *)value;
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, QMessageBox *box = new QMessageBox (QMessageBox::Question,
qfu(data->title), qfu(data->message)); qfu(data->title), qfu(data->message));
QAbstractButton *yes = (data->yes != NULL) QAbstractButton *yes = (data->yes != NULL)
......
...@@ -24,6 +24,23 @@ ...@@ -24,6 +24,23 @@
#include <QObject> #include <QObject>
#include <vlc_common.h> #include <vlc_common.h>
class QVLCVariable : public QObject
{
Q_OBJECT
private:
static int callback (vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void *);
vlc_object_t *object;
QString name;
public:
QVLCVariable (vlc_object_t *, const char *, int);
virtual ~QVLCVariable (void);
signals:
void pointerChanged (vlc_object_t *, void *);
};
struct intf_thread_t; struct intf_thread_t;
class DialogHandler : public QObject class DialogHandler : public QObject
...@@ -35,22 +52,14 @@ public: ...@@ -35,22 +52,14 @@ public:
private: private:
intf_thread_t *intf; intf_thread_t *intf;
static int MessageCallback (vlc_object_t *, const char *, QVLCVariable message;
vlc_value_t, vlc_value_t, void *); QVLCVariable login;
static int LoginCallback (vlc_object_t *obj, const char *, QVLCVariable question;
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: private slots:
void displayMessage (const struct dialog_fatal_t *); void displayMessage (vlc_object_t *, void *);
void requestLogin (struct dialog_login_t *); void requestLogin (vlc_object_t *, void *);
void requestAnswer (struct dialog_question_t *); void requestAnswer (vlc_object_t *, void *);
signals:
void message (const struct dialog_fatal_t *);
void authentication (struct dialog_login_t *);
void question (struct dialog_question_t *);
}; };
#endif #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