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