]> git.sesse.net Git - vlc/blob - modules/gui/qt4/variables.cpp
qt4: attempt to work around a design flaw in the toolbar editor
[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     QVLCVariable *self = static_cast<QVLCVariable *>(data);
52
53     self->trigger (self->object, old, cur);
54     return VLC_SUCCESS;
55 }
56
57
58 QVLCPointer::QVLCPointer (vlc_object_t *obj, const char *varname, bool inherit)
59     : QVLCVariable (obj, varname, VLC_VAR_ADDRESS, inherit)
60 {
61 }
62
63 void QVLCPointer::trigger (vlc_object_t *obj, vlc_value_t old, vlc_value_t cur)
64 {
65     emit pointerChanged (obj, old.p_address, cur.p_address);
66     emit pointerChanged (obj, cur.p_address);
67 }
68
69
70 QVLCInteger::QVLCInteger (vlc_object_t *obj, const char *varname, bool inherit)
71     : QVLCVariable (obj, varname, VLC_VAR_INTEGER, inherit)
72 {
73 }
74
75 void QVLCInteger::trigger (vlc_object_t *obj, vlc_value_t old, vlc_value_t cur)
76 {
77     emit integerChanged (obj, old.i_int, cur.i_int);
78     emit integerChanged (obj, cur.i_int);
79 }