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