]> git.sesse.net Git - vlc/blob - modules/gui/qt4/variables.cpp
Qt4: remove useless alive check on input
[vlc] / modules / gui / qt4 / variables.cpp
1 /*****************************************************************************
2  * variables.cpp : VLC variable class
3  ****************************************************************************
4  * Copyright (C) 2009 RĂ©mi Denis-Courmont
5  * Copyright (C) 2006 the VideoLAN team
6  *
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.
11  *
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.
16  *
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  *****************************************************************************/
21
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 #include "qt4.hpp"
27 #include "variables.hpp"
28
29 QVLCVariable::QVLCVariable (vlc_object_t *obj, const char *varname, int type,
30                             bool inherit)
31     : object (obj), name (qfu(varname))
32 {
33     vlc_object_hold (object);
34
35     if (inherit)
36         type |= VLC_VAR_DOINHERIT;
37     var_Create (object, qtu(name), type);
38     var_AddCallback (object, qtu(name), callback, this);
39 }
40
41 QVLCVariable::~QVLCVariable (void)
42 {
43     var_DelCallback (object, qtu(name), callback, this);
44     var_Destroy (object, qtu(name));
45     vlc_object_release (object);
46 }
47
48 int QVLCVariable::callback (vlc_object_t *object, const char *,
49                             vlc_value_t old, vlc_value_t cur, void *data)
50 {
51     VLC_UNUSED(object);
52
53     QVLCVariable *self = static_cast<QVLCVariable *>(data);
54
55     self->trigger (old, cur);
56     return VLC_SUCCESS;
57 }
58
59
60 QVLCPointer::QVLCPointer (vlc_object_t *obj, const char *varname, bool inherit)
61     : QVLCVariable (obj, varname, VLC_VAR_ADDRESS, inherit)
62 {
63 }
64
65 void QVLCPointer::trigger (vlc_value_t, vlc_value_t cur)
66 {
67     emit pointerChanged (cur.p_address);
68 }
69
70 bool QVLCPointer::addCallback (QObject *tgt, const char *method,
71                                Qt::ConnectionType type)
72 {
73     return tgt->connect (this, SIGNAL(pointerChanged(void *)), method, type);
74 }
75
76 QVLCInteger::QVLCInteger (vlc_object_t *obj, const char *varname, bool inherit)
77     : QVLCVariable (obj, varname, VLC_VAR_INTEGER, inherit)
78 {
79 }
80
81 void QVLCInteger::trigger (vlc_value_t, vlc_value_t cur)
82 {
83     emit integerChanged (cur.i_int);
84 }
85
86 bool QVLCInteger::addCallback (QObject *tgt, const char *method,
87                                Qt::ConnectionType type)
88 {
89     return tgt->connect (this, SIGNAL(integerChanged(qlonglong)), method,
90                          type);
91 }
92
93 QVLCBool::QVLCBool (vlc_object_t *obj, const char *varname, bool inherit)
94     : QVLCVariable (obj, varname, VLC_VAR_BOOL, inherit)
95 {
96 }
97
98 void QVLCBool::trigger (vlc_value_t, vlc_value_t cur)
99 {
100     emit boolChanged (cur.b_bool);
101 }
102
103 bool QVLCBool::addCallback (QObject *tgt, const char *method,
104                             Qt::ConnectionType type)
105 {
106     return tgt->connect (this, SIGNAL(boolChanged(bool)), method, type);
107 }
108
109 QVLCFloat::QVLCFloat (vlc_object_t *obj, const char *varname, bool inherit)
110     : QVLCVariable (obj, varname, VLC_VAR_FLOAT, inherit)
111 {
112 }
113
114 void QVLCFloat::trigger (vlc_value_t, vlc_value_t cur)
115 {
116     emit floatChanged (cur.f_float);
117 }
118
119 bool QVLCFloat::addCallback (QObject *tgt, const char *method,
120                             Qt::ConnectionType type)
121 {
122     return tgt->connect (this, SIGNAL(floatChanged(float)), method, type);
123 }
124
125 QVLCString::QVLCString (vlc_object_t *obj, const char *varname, bool inherit)
126     : QVLCVariable (obj, varname, VLC_VAR_STRING, inherit)
127 {
128 }
129
130 void QVLCString::trigger (vlc_value_t, vlc_value_t cur)
131 {
132     QString str = qfu(cur.psz_string);
133     emit stringChanged (str);
134 }
135
136 bool QVLCString::addCallback (QObject *tgt, const char *method,
137                               Qt::ConnectionType type)
138 {
139     return tgt->connect (this, SIGNAL(stringChanged(QString)), method, type);
140 }