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