]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
Change backgroundwidget and mediainfo-dialog to use THEMIM
[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
29 #include <QTabWidget>
30 #include <QGridLayout>
31 #include <QLineEdit>
32 #include <QLabel>
33
34 MediaInfoDialog *MediaInfoDialog::instance = NULL;
35
36 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
37                                   input_item_t *_p_item,
38                                   bool _mainInput,
39                                   bool _stats ) :
40                                   QVLCFrame( _p_intf ), mainInput(_mainInput),
41                                   stats( _stats )
42 {
43     i_runs = 0;
44     p_item = _p_item;
45     b_need_update = true;
46     b_cleaned = true;
47
48     setWindowTitle( qtr( "Media information" ) );
49     resize( 600 , 480 );
50
51     /* TabWidgets and Tabs creation */
52     IT = new QTabWidget;
53     MP = new MetaPanel( IT, p_intf );
54     IT->addTab( MP, qtr( "&General" ) );
55     EMP = new ExtraMetaPanel( IT, p_intf );
56     IT->addTab( EMP, qtr( "&Extra Metadata" ) );
57     IP = new InfoPanel( IT, p_intf );
58     IT->addTab( IP, qtr( "&Codec Details" ) );
59     if( stats )
60     {
61         ISP = new InputStatsPanel( IT, p_intf );
62         IT->addTab( ISP, qtr( "&Statistics" ) );
63     }
64
65     QGridLayout *layout = new QGridLayout( this );
66
67     /* No need to use a QDialogButtonBox here */
68     saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
69     saveMetaButton->hide();
70     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
71     closeButton->setDefault( true );
72
73     uriLine = new QLineEdit;
74     QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
75
76     layout->addWidget( IT, 0, 0, 1, 8 );
77     layout->addWidget( uriLabel, 1, 0, 1, 1 );
78     layout->addWidget( uriLine, 1, 1, 1, 7 );
79     layout->addWidget( saveMetaButton, 2, 6 );
80     layout->addWidget( closeButton, 2, 7 );
81
82     BUTTONACT( closeButton, close() );
83
84     /* The tabs buttons are shown in the main dialog for space and cosmetics */
85     CONNECT( saveMetaButton, clicked(), this, saveMeta() );
86
87     /* Let the MetaData Panel update the URI */
88     CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
89     CONNECT( MP, editing(), this, showMetaSaveButton() );
90
91     CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
92
93     CONNECT( THEMIM, inputChanged( input_thread_t * ), this, update( input_thread_t * ) );
94     /* Call update by hand, so info is shown from current item too */
95     update( input_GetItem(THEMIM->getInput()), true, true );
96 }
97
98 MediaInfoDialog::~MediaInfoDialog()
99 {
100     writeSettings( "mediainfo" );
101 }
102
103 void MediaInfoDialog::showTab( int i_tab = 0 )
104 {
105     IT->setCurrentIndex( i_tab );
106     show();
107 }
108
109 void MediaInfoDialog::showMetaSaveButton()
110 {
111     saveMetaButton->show();
112 }
113
114 void MediaInfoDialog::saveMeta()
115 {
116     MP->saveMeta();
117     saveMetaButton->hide();
118 }
119
120 /* Function called on inputChanged-update*/
121 void MediaInfoDialog::update( input_thread_t *p_input )
122 {
123     if( !p_input || p_input->b_dead )
124     {
125         if( !b_cleaned )
126         {
127             clear();
128             b_cleaned = true;
129         }
130         return;
131     }
132
133     /* Launch the update in all the panels */
134     vlc_object_yield( p_input );
135
136     update( input_GetItem(p_input), b_need_update, b_need_update );
137     b_need_update = false;
138     b_cleaned = false;
139
140     vlc_object_release( p_input );
141 }
142
143 void MediaInfoDialog::update( input_item_t *p_item,
144                               bool update_info,
145                               bool update_meta )
146 {
147     if( update_info )
148         IP->update( p_item );
149     if( update_meta )
150     {
151         MP->update( p_item );
152         EMP->update( p_item );
153     }
154     if( stats )
155         ISP->update( p_item );
156 }
157
158 void MediaInfoDialog::clear()
159 {
160     IP->clear();
161     MP->clear();
162     EMP->clear();
163     if( stats ) ISP->clear();
164     b_cleaned = true;
165 }
166
167 void MediaInfoDialog::close()
168 {
169     this->toggleVisible();
170
171     if( mainInput == false ) {
172         deleteLater();
173     }
174 }
175
176 void MediaInfoDialog::updateButtons( int i_tab )
177 {
178     if( MP->isInEditMode() && i_tab == 0 )
179         saveMetaButton->show();
180     else
181         saveMetaButton->hide();
182 }