]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
Qt: toolbar editor: make it easier for small narrow screens
[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     if ( isMainInputInfo )
52         setWindowTitle( qtr( "Current Media Information" ) );
53     else
54         setWindowTitle( qtr( "Media Information" ) );
55     setWindowRole( "vlc-media-info" );
56
57     setWindowFlags( Qt::Window | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint );
58
59     /* TabWidgets and Tabs creation */
60     infoTabW = new QTabWidget;
61
62     MP = new MetaPanel( infoTabW, p_intf );
63     infoTabW->insertTab( META_PANEL, MP, qtr( "&General" ) );
64     EMP = new ExtraMetaPanel( infoTabW );
65     infoTabW->insertTab( EXTRAMETA_PANEL, EMP, qtr( "&Metadata" ) );
66     IP = new InfoPanel( infoTabW );
67     infoTabW->insertTab( INFO_PANEL, IP, qtr( "Co&dec" ) );
68     if( isMainInputInfo )
69     {
70         ISP = new InputStatsPanel( infoTabW );
71         infoTabW->insertTab( INPUTSTATS_PANEL, ISP, qtr( "S&tatistics" ) );
72     }
73
74     QGridLayout *layout = new QGridLayout( this );
75
76     /* No need to use a QDialogButtonBox here */
77     saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
78     saveMetaButton->hide();
79     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
80     closeButton->setDefault( true );
81
82     QLabel *uriLabel = new QLabel( qtr( "Location:" ) );
83     uriLine = new QLineEdit;
84     uriLine->setReadOnly( true );
85
86     layout->addWidget( infoTabW, 0, 0, 1, 8 );
87     layout->addWidget( uriLabel, 1, 0, 1, 1 );
88     layout->addWidget( uriLine, 1, 1, 1, 7 );
89     layout->addWidget( saveMetaButton, 2, 6 );
90     layout->addWidget( closeButton, 2, 7 );
91
92     BUTTONACT( closeButton, close() );
93
94     /* The tabs buttons are shown in the main dialog for space and cosmetics */
95     BUTTONACT( saveMetaButton, saveMeta() );
96
97     /* Let the MetaData Panel update the URI */
98     CONNECT( MP, uriSet( const QString& ), this, updateURI( const QString& ) );
99     CONNECT( MP, editing(), saveMetaButton, show() );
100
101     /* Display the buttonBar according to the Tab selected */
102     CONNECT( infoTabW, currentChanged( int ), this, updateButtons( int ) );
103
104     /* If using the General Mode */
105     if( isMainInputInfo )
106     {
107         msg_Dbg( p_intf, "Using a general info windows" );
108         /**
109          * Connects on the various signals of input_Manager
110          * For the currently playing element
111          **/
112         DCONNECT( THEMIM->getIM(), infoChanged( input_item_t* ),
113                   IP, update( input_item_t* ) );
114         DCONNECT( THEMIM->getIM(), currentMetaChanged( input_item_t* ),
115                   MP, update( input_item_t* ) );
116         DCONNECT( THEMIM->getIM(), currentMetaChanged( input_item_t* ),
117                   EMP, update( input_item_t* ) );
118         DCONNECT( THEMIM->getIM(), statisticsUpdated( input_item_t* ),
119                   ISP, update( input_item_t* ) );
120
121         if( THEMIM->getInput() )
122             p_item = input_GetItem( THEMIM->getInput() );
123     }
124     else
125         msg_Dbg( p_intf, "Using an item specific info windows" );
126
127     /* Call update at start, so info is filled up at begginning */
128     if( p_item )
129         updateAllTabs( p_item );
130
131     restoreWidgetPosition( "Mediainfo", QSize( 600 , 480 ) );
132 }
133
134 MediaInfoDialog::~MediaInfoDialog()
135 {
136     saveWidgetPosition( "Mediainfo" );
137 }
138
139 void MediaInfoDialog::showTab( panel i_tab = META_PANEL )
140 {
141     infoTabW->setCurrentIndex( i_tab );
142     show();
143 }
144
145 void MediaInfoDialog::saveMeta()
146 {
147     MP->saveMeta();
148     saveMetaButton->hide();
149 }
150
151 void MediaInfoDialog::updateAllTabs( input_item_t *p_item )
152 {
153     IP->update( p_item );
154     MP->update( p_item );
155     EMP->update( p_item );
156
157     if( isMainInputInfo ) ISP->update( p_item );
158 }
159
160 void MediaInfoDialog::clearAllTabs()
161 {
162     IP->clear();
163     MP->clear();
164     EMP->clear();
165
166     if( isMainInputInfo ) ISP->clear();
167 }
168
169 void MediaInfoDialog::close()
170 {
171     hide();
172
173     /* if dialog is closed, revert editing if not saved */
174     if( MP->isInEditMode() )
175     {
176         MP->setEditMode( false );
177         updateButtons( 0 );
178     }
179
180     if( !isMainInputInfo )
181         deleteLater();
182 }
183
184 void MediaInfoDialog::updateButtons( int i_tab )
185 {
186     if( MP->isInEditMode() && i_tab == 0 )
187         saveMetaButton->show();
188     else
189         saveMetaButton->hide();
190 }
191
192 void MediaInfoDialog::updateURI( const QString& uri )
193 {
194     QString location;
195
196     /* If URI points to a local file, show the path instead of the URI */
197     char *path = make_path( qtu( uri ) );
198     if( path != NULL )
199     {
200         location = qfu( path );
201         free( path );
202     }
203     else
204         location = uri;
205
206     uriLine->setText( location );
207 }