1 /*****************************************************************************
2 * variables.cpp : VLC variable class
3 ****************************************************************************
4 * Copyright (C) 2009 RĂ©mi Denis-Courmont
5 * Copyright (C) 2006 the VideoLAN team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
27 #include "variables.hpp"
29 QVLCVariable::QVLCVariable (vlc_object_t *obj, const char *varname, int type,
31 : object (obj), name (qfu(varname))
33 vlc_object_hold (object);
36 type |= VLC_VAR_DOINHERIT;
37 var_Create (object, qtu(name), type);
38 var_AddCallback (object, qtu(name), callback, this);
41 QVLCVariable::~QVLCVariable (void)
43 var_DelCallback (object, qtu(name), callback, this);
44 var_Destroy (object, qtu(name));
45 vlc_object_release (object);
48 int QVLCVariable::callback (vlc_object_t *object, const char *,
49 vlc_value_t old, vlc_value_t cur, void *data)
53 QVLCVariable *self = static_cast<QVLCVariable *>(data);
55 self->trigger (old, cur);
60 QVLCPointer::QVLCPointer (vlc_object_t *obj, const char *varname, bool inherit)
61 : QVLCVariable (obj, varname, VLC_VAR_ADDRESS, inherit)
65 void QVLCPointer::trigger (vlc_value_t, vlc_value_t cur)
67 emit pointerChanged (cur.p_address);
70 bool QVLCPointer::addCallback (QObject *tgt, const char *method,
71 Qt::ConnectionType type)
73 return tgt->connect (this, SIGNAL(pointerChanged(void *)), method, type);
76 QVLCInteger::QVLCInteger (vlc_object_t *obj, const char *varname, bool inherit)
77 : QVLCVariable (obj, varname, VLC_VAR_INTEGER, inherit)
81 void QVLCInteger::trigger (vlc_value_t, vlc_value_t cur)
83 emit integerChanged (cur.i_int);
86 bool QVLCInteger::addCallback (QObject *tgt, const char *method,
87 Qt::ConnectionType type)
89 return tgt->connect (this, SIGNAL(integerChanged(qlonglong)), method,
93 QVLCBool::QVLCBool (vlc_object_t *obj, const char *varname, bool inherit)
94 : QVLCVariable (obj, varname, VLC_VAR_BOOL, inherit)
98 void QVLCBool::trigger (vlc_value_t, vlc_value_t cur)
100 emit boolChanged (cur.b_bool);
103 bool QVLCBool::addCallback (QObject *tgt, const char *method,
104 Qt::ConnectionType type)
106 return tgt->connect (this, SIGNAL(boolChanged(bool)), method, type);
109 QVLCFloat::QVLCFloat (vlc_object_t *obj, const char *varname, bool inherit)
110 : QVLCVariable (obj, varname, VLC_VAR_FLOAT, inherit)
114 void QVLCFloat::trigger (vlc_value_t, vlc_value_t cur)
116 emit floatChanged (cur.f_float);
119 bool QVLCFloat::addCallback (QObject *tgt, const char *method,
120 Qt::ConnectionType type)
122 return tgt->connect (this, SIGNAL(floatChanged(float)), method, type);
125 QVLCString::QVLCString (vlc_object_t *obj, const char *varname, bool inherit)
126 : QVLCVariable (obj, varname, VLC_VAR_STRING, inherit)
130 void QVLCString::trigger (vlc_value_t, vlc_value_t cur)
132 QString str = qfu(cur.psz_string);
133 emit stringChanged (str);
136 bool QVLCString::addCallback (QObject *tgt, const char *method,
137 Qt::ConnectionType type)
139 return tgt->connect (this, SIGNAL(stringChanged(QString)), method, type);