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