]> git.sesse.net Git - vlc/commitdiff
Qt4: move QVLCVariable out of external dialogs
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 16 May 2009 09:23:51 +0000 (12:23 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 16 May 2009 10:01:35 +0000 (13:01 +0300)
modules/gui/qt4/Modules.am
modules/gui/qt4/dialogs/external.cpp
modules/gui/qt4/dialogs/external.hpp
modules/gui/qt4/variables.cpp [new file with mode: 0644]
modules/gui/qt4/variables.hpp [new file with mode: 0644]

index ce0f73e62cd9b8a9c9c5d8ab8bba1e96e3c4d703..a863447dd126ff98bcc9b7d3a539d489eaa5027d 100644 (file)
@@ -21,6 +21,7 @@ nodist_SOURCES_qt4 = \
                input_manager.moc.cpp \
                actions_manager.moc.cpp \
                recents.moc.cpp \
+               variables.moc.cpp \
                dialogs/playlist.moc.cpp \
                dialogs/bookmarks.moc.cpp \
                dialogs/mediainfo.moc.cpp \
@@ -195,6 +196,7 @@ SOURCES_qt4 =       qt4.cpp \
                input_manager.cpp \
                actions_manager.cpp \
                recents.cpp \
+               variables.cpp \
                dialogs/playlist.cpp \
                dialogs/bookmarks.cpp \
                dialogs/preferences.cpp \
@@ -241,6 +243,7 @@ noinst_HEADERS = \
        input_manager.hpp \
        actions_manager.hpp \
        recents.hpp \
+       variables.hpp \
        dialogs/playlist.hpp \
        dialogs/bookmarks.hpp \
        dialogs/mediainfo.hpp \
index 4153470f7ddf41cf17a638b9b54e566ea86a27d2..af2818f4a5d7085be2ace30fad28b6e34fc585dc 100644 (file)
 #include <QProgressDialog>
 #include <QMutex>
 
-QVLCVariable::QVLCVariable (vlc_object_t *obj, const char *varname, int type)
-    : object (obj), name (qfu(varname))
-{
-    var_Create (object, qtu(name), type);
-    var_AddCallback (object, qtu(name), callback, 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);
-    return VLC_SUCCESS;
-}
-
-
 DialogHandler::DialogHandler (intf_thread_t *intf)
     : intf (intf),
       message (VLC_OBJECT(intf), "dialog-fatal", VLC_VAR_ADDRESS),
index d2894ef883f0981a89f1596763fd570da6b65fe1..dda635bc0a2413234f32ae6f28d8f93e51a46ee1 100644 (file)
 
 #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 *);
-};
+#include "variables.hpp"
 
 struct intf_thread_t;
 class QProgressDialog;
@@ -56,10 +40,10 @@ public:
 
 private:
     intf_thread_t *intf;
-    QVLCVariable message;
-    QVLCVariable login;
-    QVLCVariable question;
-    QVLCVariable progressBar;
+    QVLCPointer message;
+    QVLCPointer login;
+    QVLCPointer question;
+    QVLCPointer progressBar;
 signals:
     void progressBarDestroyed (QWidget *);
 
diff --git a/modules/gui/qt4/variables.cpp b/modules/gui/qt4/variables.cpp
new file mode 100644 (file)
index 0000000..6dc2895
--- /dev/null
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * variables.cpp : VLC variable class
+ ****************************************************************************
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "qt4.hpp"
+#include "variables.hpp"
+
+QVLCVariable::QVLCVariable (vlc_object_t *obj, const char *varname, int type,
+                            bool inherit)
+    : object (obj), name (qfu(varname))
+{
+    vlc_object_hold (object);
+
+    if (inherit)
+        type |= VLC_VAR_DOINHERIT;
+    var_Create (object, qtu(name), type);
+    var_AddCallback (object, qtu(name), callback, this);
+}
+
+QVLCVariable::~QVLCVariable (void)
+{
+    var_DelCallback (object, qtu(name), callback, this);
+    var_Destroy (object, qtu(name));
+    vlc_object_release (object);
+}
+
+int QVLCVariable::callback (vlc_object_t *object, const char *,
+                            vlc_value_t old, vlc_value_t cur, void *data)
+{
+    QVLCVariable *self = static_cast<QVLCVariable *>(data);
+
+    self->trigger (self->object, old, cur);
+    return VLC_SUCCESS;
+}
+
+
+QVLCPointer::QVLCPointer (vlc_object_t *obj, const char *varname, bool inherit)
+    : QVLCVariable (obj, varname, VLC_VAR_ADDRESS, inherit)
+{
+}
+
+void QVLCPointer::trigger (vlc_object_t *obj, vlc_value_t old, vlc_value_t cur)
+{
+    emit pointerChanged (obj, old.p_address, cur.p_address);
+    emit pointerChanged (obj, cur.p_address);
+}
diff --git a/modules/gui/qt4/variables.hpp b/modules/gui/qt4/variables.hpp
new file mode 100644 (file)
index 0000000..af6e65b
--- /dev/null
@@ -0,0 +1,56 @@
+/*****************************************************************************
+ * external.hpp : Dialogs from other LibVLC core and other plugins
+ ****************************************************************************
+ * Copyright (C) 2009 Rémi Denis-Courmont
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef QVLC_VARIABLES_H_
+#define QVLC_VARIABLES_H_ 1
+
+#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;
+    virtual void trigger (vlc_object_t *, vlc_value_t, vlc_value_t) = 0;
+
+public:
+    QVLCVariable (vlc_object_t *, const char *, int, bool);
+    virtual ~QVLCVariable (void);
+};
+
+class QVLCPointer : public QVLCVariable
+{
+    Q_OBJECT
+private:
+    virtual void trigger (vlc_object_t *, vlc_value_t, vlc_value_t);
+
+public:
+    QVLCPointer (vlc_object_t *, const char *, bool inherit = false);
+
+signals:
+    void pointerChanged (vlc_object_t *, void *, void *);
+    void pointerChanged (vlc_object_t *, void *);
+};
+
+#endif