]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
Qt4 : Some work on OpenDialog. Does not work with files with spaces... More work...
[vlc] / modules / gui / qt4 / dialogs / mediainfo.cpp
1 /*****************************************************************************
2  * mediainfo.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  *          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 #include <QTabWidget>
25 #include <QGridLayout>
26
27 #include "dialogs/mediainfo.hpp"
28 #include "input_manager.hpp"
29 #include "dialogs_provider.hpp"
30 #include "util/qvlcframe.hpp"
31 #include "components/infopanels.hpp"
32 #include "qt4.hpp"
33
34
35 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
36                         vlc_value_t oldval, vlc_value_t newval, void *param );
37 MediaInfoDialog *MediaInfoDialog::instance = NULL;
38
39 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf ) :QVLCFrame( _p_intf )
40 {
41     i_runs = 0;
42     p_input = NULL;
43
44     setWindowTitle( qtr( "Media information" ) );
45
46     QGridLayout *layout = new QGridLayout(this);
47     IT = new InfoTab( this, p_intf, true ) ;
48     QPushButton *closeButton = new QPushButton(qtr("&Close"));
49
50     layout->addWidget(IT,0,0,1,3);
51     layout->addWidget(closeButton,1,2);
52
53     BUTTONACT( closeButton, close() );
54     ON_TIMEOUT( update() );
55
56     var_AddCallback( THEPL, "item-change", ItemChanged, this );
57     readSettings( "mediainfo" , QSize( 500, 450 ) );
58 }
59
60 MediaInfoDialog::~MediaInfoDialog()
61 {
62     var_DelCallback( THEPL, "item-change", ItemChanged, this );
63     writeSettings( "mediainfo" );
64 }
65
66 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
67                         vlc_value_t oldval, vlc_value_t newval, void *param )
68 {
69     MediaInfoDialog *p_d = (MediaInfoDialog *)param;
70     p_d->need_update = VLC_TRUE;
71     return VLC_SUCCESS;
72 }
73
74 void MediaInfoDialog::update()
75 {
76     // Timer runs at 150 ms, dont' update more than 2 times per second
77     i_runs++;
78     if( i_runs % 3 != 0 ) return;
79
80     input_thread_t *p_input = MainInputManager::getInstance( p_intf )->getInput();
81     if( !p_input || p_input->b_dead )
82     {
83         IT->clear();
84         return;
85     }
86
87     vlc_object_yield( p_input );
88     vlc_mutex_lock( &input_GetItem(p_input)->lock );
89
90     IT->update( input_GetItem(p_input), need_update, need_update );
91     need_update = false;
92
93     vlc_mutex_unlock( &input_GetItem(p_input)->lock );
94     vlc_object_release( p_input );
95 }
96
97 void MediaInfoDialog::close()
98 {
99     this->toggleVisible();
100 }