[vlc-devel] commit: VLC pointer variable callback -> Qt4 signal class ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sun Mar 8 18:07:35 CET 2009
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar 8 18:57:45 2009 +0200| [8693ccb6ee8ad45ab3b9f14e689d1a4a75e414d5] | committer: 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
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8693ccb6ee8ad45ab3b9f14e689d1a4a75e414d5
---
modules/gui/qt4/dialogs/external.cpp | 90 ++++++++++++++-------------------
modules/gui/qt4/dialogs/external.hpp | 37 +++++++++-----
2 files changed, 61 insertions(+), 66 deletions(-)
diff --git a/modules/gui/qt4/dialogs/external.cpp b/modules/gui/qt4/dialogs/external.cpp
index 8b7b031..bc91b27 100644
--- a/modules/gui/qt4/dialogs/external.cpp
+++ b/modules/gui/qt4/dialogs/external.cpp
@@ -34,52 +34,55 @@
#include <QLineEdit>
#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 *)),
- this, SLOT(displayMessage(const struct dialog_fatal_t *)),
- Qt::BlockingQueuedConnection);
- var_Create (intf, "dialog-fatal", VLC_VAR_ADDRESS);
- var_AddCallback (intf, "dialog-fatal", MessageCallback, this);
+QVLCVariable::~QVLCVariable (void)
+{
+ var_DelCallback (object, qtu(name), callback, this);
+ var_Destroy (object, qtu(name));
+}
+
+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 *)),
- this, SLOT(requestAnswer(struct dialog_question_t *)),
+DialogHandler::DialogHandler (intf_thread_t *intf)
+ : 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);
- var_Create (intf, "dialog-question", VLC_VAR_ADDRESS);
- var_AddCallback (intf, "dialog-question", QuestionCallback, this);
- dialog_Register (intf);
+ 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);
}
-int DialogHandler::MessageCallback (vlc_object_t *obj, const char *var,
- vlc_value_t, vlc_value_t value,
- void *data)
+void DialogHandler::displayMessage (vlc_object_t *, void *value)
{
- DialogHandler *self = (DialogHandler *)data;
- const dialog_fatal_t *dialog = (const dialog_fatal_t *)value.p_address;
-
- emit self->message (dialog);
- return VLC_SUCCESS;
-}
+ const dialog_fatal_t *dialog = (const dialog_fatal_t *)value;
-void DialogHandler::displayMessage (const struct dialog_fatal_t *dialog)
-{
if (dialog->modal)
QMessageBox::critical (NULL, qfu(dialog->title), qfu(dialog->message),
QMessageBox::Ok);
@@ -89,18 +92,9 @@ void DialogHandler::displayMessage (const struct dialog_fatal_t *dialog)
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)
+void DialogHandler::requestLogin (vlc_object_t *, void *value)
{
+ dialog_login_t *data = (dialog_login_t *)value;
QDialog *dialog = new QDialog;
QLayout *layout = new QVBoxLayout (dialog);
@@ -146,18 +140,10 @@ 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)
+void DialogHandler::requestAnswer (vlc_object_t *, void *value)
{
- DialogHandler *self = (DialogHandler *)data;
- dialog_question_t *dialog = (dialog_question_t *)value.p_address;
+ dialog_question_t *data = (dialog_question_t *)value;
- 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)
diff --git a/modules/gui/qt4/dialogs/external.hpp b/modules/gui/qt4/dialogs/external.hpp
index 0ff46e1..23aa263 100644
--- a/modules/gui/qt4/dialogs/external.hpp
+++ b/modules/gui/qt4/dialogs/external.hpp
@@ -24,6 +24,23 @@
#include <QObject>
#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;
class DialogHandler : public QObject
@@ -35,22 +52,14 @@ public:
private:
intf_thread_t *intf;
- 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 *);
- static int QuestionCallback (vlc_object_t *obj, const char *,
- vlc_value_t, vlc_value_t, void *);
+ QVLCVariable message;
+ QVLCVariable login;
+ QVLCVariable question;
private slots:
- void displayMessage (const struct dialog_fatal_t *);
- 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 *);
+ void displayMessage (vlc_object_t *, void *);
+ void requestLogin (vlc_object_t *, void *);
+ void requestAnswer (vlc_object_t *, void *);
};
#endif
More information about the vlc-devel
mailing list