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