]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/streaminfo.cpp
A bit of cleanup in the info stuff
[vlc] / modules / gui / qt4 / dialogs / streaminfo.cpp
1 /*****************************************************************************
2  * streaminfo.cpp : Information about an item
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
22
23 #include <QTabWidget>
24 #include <QGridLayout>
25
26 #include "dialogs/streaminfo.hpp"
27 #include "input_manager.hpp"
28 #include "dialogs_provider.hpp"
29 #include "util/qvlcframe.hpp"
30 #include "components/infopanels.hpp"
31 #include "qt4.hpp"
32
33 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
34                         vlc_value_t oldval, vlc_value_t newval, void *param );
35 StreamInfoDialog *StreamInfoDialog::instance = NULL;
36
37 StreamInfoDialog::StreamInfoDialog( intf_thread_t *_p_intf ) :QVLCFrame( _p_intf )
38 {
39     i_runs = 0;
40     setWindowTitle( _("Stream information" ) );
41     QGridLayout *layout = new QGridLayout(this);
42     setGeometry(0,0,470,550);
43
44     IT = new InfoTab( this, p_intf, true ) ;
45     QPushButton *closeButton = new QPushButton(qtr("&Close"));
46     layout->addWidget(IT,0,0,1,3);
47     layout->addWidget(closeButton,1,2);
48
49     BUTTONACT( closeButton, close() );
50     ON_TIMEOUT( update() );
51     p_input = NULL;
52
53     var_AddCallback( THEPL, "item-change", ItemChanged, this );
54 }
55
56 StreamInfoDialog::~StreamInfoDialog()
57 {
58     var_DelCallback( THEPL, "item-change", ItemChanged, this );
59 }
60
61 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
62                         vlc_value_t oldval, vlc_value_t newval, void *param )
63 {
64     StreamInfoDialog *p_d = (StreamInfoDialog *)param;
65     p_d->need_update = VLC_TRUE;
66     return VLC_SUCCESS;
67 }
68
69 void StreamInfoDialog::update()
70 {
71     // Timer runs at 150 ms, dont' update more than 2 times per second
72     i_runs++;
73     if( i_runs % 3 != 0 ) return;
74
75     input_thread_t *p_input = MainInputManager::getInstance( p_intf )->getInput();
76     if( !p_input || p_input->b_dead )
77     {
78         IT->clear();
79         return;
80     }
81
82     vlc_object_yield( p_input );
83     vlc_mutex_lock( &p_input->input.p_item->lock );
84
85     IT->update( p_input->input.p_item, need_update, need_update );
86     need_update = false;
87
88     vlc_mutex_unlock( &p_input->input.p_item->lock );
89     vlc_object_release( p_input );
90 }
91
92 void StreamInfoDialog::close()
93 {
94     this->toggleVisible();
95 }