]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
Qt4 - MediaInfo, move the tabWidget to the Dialog class and remove it from components.
[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                                   bool _stats ) :
42                                   QVLCFrame( _p_intf ), mainInput(_mainInput),
43                                   stats( _stats )
44 {
45     i_runs = 0;
46     p_input = NULL;
47
48     setWindowTitle( qtr( "Media information" ) );
49     resize( 600 , 450 );
50
51     QGridLayout *layout = new QGridLayout(this);
52
53     IT = new QTabWidget;
54     MP = new MetaPanel( IT, p_intf );
55     IT->addTab( MP, qtr( "&General" ) );
56     EMP = new ExtraMetaPanel( IT, p_intf );
57     IT->addTab( EMP, qtr( "&Extra Metadata" ) );
58     IP = new InfoPanel( IT, p_intf);
59     IT->addTab( IP, qtr("&Codec Details"));
60     if( stats )
61     {
62         ISP = new InputStatsPanel( IT, p_intf );
63         IT->addTab(ISP, qtr("&Stats"));
64     }
65
66     QPushButton *closeButton = new QPushButton(qtr("&Close"));
67     closeButton->setDefault( true );
68
69     layout->addWidget( IT, 0, 0, 1, 3);
70     layout->addWidget(closeButton,1,2);
71
72     BUTTONACT( closeButton, close() );
73     ON_TIMEOUT( update() );
74
75     if( mainInput ) {
76         var_AddCallback( THEPL, "item-change", ItemChanged, this );
77     }
78 }
79
80 MediaInfoDialog::~MediaInfoDialog()
81 {
82     if( mainInput ) {
83         var_DelCallback( THEPL, "item-change", ItemChanged, this );
84     }
85     writeSettings( "mediainfo" );
86 }
87
88 void MediaInfoDialog::showTab(int i_tab=0)
89 {
90     this->show();
91     IT->setCurrentIndex(i_tab);
92 }
93
94 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
95                         vlc_value_t oldval, vlc_value_t newval, void *param )
96 {
97     MediaInfoDialog *p_d = (MediaInfoDialog *)param;
98     p_d->need_update = VLC_TRUE;
99     return VLC_SUCCESS;
100 }
101
102 void MediaInfoDialog::setInput(input_item_t *p_input)
103 {
104     clear();
105     vlc_mutex_lock( &p_input->lock );
106     update( p_input, true, true );
107     vlc_mutex_unlock( &p_input->lock );
108 }
109
110 void MediaInfoDialog::update()
111 {
112     msg_Dbg( p_intf, "updating" );
113     /* Timer runs at 150 ms, dont' update more than 2 times per second */
114     if( i_runs % 3 != 0 ) return;
115     i_runs++;
116
117     /* Get Input and clear if non-existant */
118     input_thread_t *p_input =
119              MainInputManager::getInstance( p_intf )->getInput();
120     if( !p_input || p_input->b_dead )
121     {
122         clear();
123         return;
124     }
125
126     vlc_object_yield( p_input );
127     vlc_mutex_lock( &input_GetItem(p_input)->lock );
128
129     update( input_GetItem(p_input), need_update, need_update );
130     need_update = false;
131
132     vlc_mutex_unlock( &input_GetItem(p_input)->lock );
133     vlc_object_release( p_input );
134 }
135
136 void MediaInfoDialog::update( input_item_t *p_item, bool update_info,
137         bool update_meta )
138 {
139     if( update_info )
140         IP->update( p_item );
141     if( update_meta )
142     {
143         MP->update( p_item );
144         EMP->update( p_item );
145     }
146     if( stats )
147         ISP->update( p_item );
148 }
149
150 void MediaInfoDialog::clear()
151 {
152     IP->clear();
153     MP->clear();
154     EMP->clear();
155     if( stats ) ISP->clear();
156 }
157
158
159 void MediaInfoDialog::close()
160 {
161     this->toggleVisible();
162
163     if( mainInput == false ) {
164         deleteLater();
165     }
166 }