]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
Merge branch 'master' into lpcm_encoder
[vlc] / modules / gui / qt4 / dialogs / mediainfo.cpp
1 /*****************************************************************************
2  * mediainfo.cpp : Information about an item
3  ****************************************************************************
4  * Copyright (C) 2006-2008 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 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include "dialogs/mediainfo.hpp"
30 #include "input_manager.hpp"
31
32 #include <vlc_url.h>
33
34 #include <QTabWidget>
35 #include <QGridLayout>
36 #include <QLineEdit>
37 #include <QLabel>
38 #include <QPushButton>
39
40 /* This Dialog has two main modes:
41     - General Mode that shows the current Played item, and the stats
42     - Single mode that shows the info on ONE SINGLE Item on the playlist
43    Please be Careful of not breaking one the modes behaviour... */
44
45 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
46                                   input_item_t *p_item ) :
47                                   QVLCFrame( _p_intf )
48 {
49     isMainInputInfo = ( p_item == NULL );
50
51     setWindowTitle( qtr( "Media Information" ) );
52     setWindowRole( "vlc-media-info" );
53
54     /* TabWidgets and Tabs creation */
55     infoTabW = new QTabWidget;
56
57     MP = new MetaPanel( infoTabW, p_intf );
58     infoTabW->addTab( MP, qtr( "&General" ) );
59     EMP = new ExtraMetaPanel( infoTabW, p_intf );
60     infoTabW->addTab( EMP, qtr( "&Extra Metadata" ) );
61     IP = new InfoPanel( infoTabW, p_intf );
62     infoTabW->addTab( IP, qtr( "&Codec Details" ) );
63     if( isMainInputInfo )
64     {
65         ISP = new InputStatsPanel( infoTabW, p_intf );
66         infoTabW->addTab( ISP, qtr( "&Statistics" ) );
67     }
68
69     QGridLayout *layout = new QGridLayout( this );
70
71     /* No need to use a QDialogButtonBox here */
72     saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
73     saveMetaButton->hide();
74     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
75     closeButton->setDefault( true );
76
77     QLabel *uriLabel = new QLabel( qtr( "Location:" ) );
78     uriLine = new QLineEdit;
79
80     layout->addWidget( infoTabW, 0, 0, 1, 8 );
81     layout->addWidget( uriLabel, 1, 0, 1, 1 );
82     layout->addWidget( uriLine, 1, 1, 1, 7 );
83     layout->addWidget( saveMetaButton, 2, 6 );
84     layout->addWidget( closeButton, 2, 7 );
85
86     BUTTONACT( closeButton, close() );
87
88     /* The tabs buttons are shown in the main dialog for space and cosmetics */
89     BUTTONACT( saveMetaButton, saveMeta() );
90
91     /* Let the MetaData Panel update the URI */
92     CONNECT( MP, uriSet( const QString& ), this, updateURI( const QString& ) );
93     CONNECT( MP, editing(), saveMetaButton, show() );
94
95     /* Display the buttonBar according to the Tab selected */
96     CONNECT( infoTabW, currentChanged( int ), this, updateButtons( int ) );
97
98     /* If using the General Mode */
99     if( isMainInputInfo )
100     {
101         msg_Dbg( p_intf, "Using a general info windows" );
102         /**
103          * Connects on the various signals of input_Manager
104          * For the currently playing element
105          **/
106         DCONNECT( THEMIM->getIM(), infoChanged( input_item_t* ),
107                   IP, update( input_item_t* ) );
108         DCONNECT( THEMIM->getIM(), currentMetaChanged( input_item_t* ),
109                   MP, update( input_item_t* ) );
110         DCONNECT( THEMIM->getIM(), currentMetaChanged( input_item_t* ),
111                   EMP, update( input_item_t* ) );
112         DCONNECT( THEMIM->getIM(), statisticsUpdated( input_item_t* ),
113                   ISP, update( input_item_t* ) );
114
115         if( THEMIM->getInput() )
116             p_item = input_GetItem( THEMIM->getInput() );
117     }
118     else
119         msg_Dbg( p_intf, "Using an item specific info windows" );
120
121     /* Call update at start, so info is filled up at begginning */
122     if( p_item )
123         updateAllTabs( p_item );
124
125     readSettings( "Mediainfo", QSize( 600 , 480 ) );
126 }
127
128 MediaInfoDialog::~MediaInfoDialog()
129 {
130     writeSettings( "Mediainfo" );
131 }
132
133 void MediaInfoDialog::showTab( int i_tab = 0 )
134 {
135     infoTabW->setCurrentIndex( i_tab );
136     show();
137 }
138
139 void MediaInfoDialog::saveMeta()
140 {
141     MP->saveMeta();
142     saveMetaButton->hide();
143 }
144
145 void MediaInfoDialog::updateAllTabs( input_item_t *p_item )
146 {
147     IP->update( p_item );
148     MP->update( p_item );
149     EMP->update( p_item );
150
151     if( isMainInputInfo ) ISP->update( p_item );
152 }
153
154 void MediaInfoDialog::clearAllTabs()
155 {
156     IP->clear();
157     MP->clear();
158     EMP->clear();
159
160     if( isMainInputInfo ) ISP->clear();
161 }
162
163 void MediaInfoDialog::close()
164 {
165     hide();
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
174     if( !isMainInputInfo )
175         deleteLater();
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 }
185
186 void MediaInfoDialog::updateURI( const QString& uri )
187 {
188     QString location;
189
190     /* If URI points to a local file, show the path instead of the URI */
191     char *path = make_path( qtu( uri ) );
192     if( path != NULL )
193     {
194         location = qfu( path );
195         free( path );
196     }
197     else
198         location = uri;
199
200     uriLine->setText( location );
201 }