mediainfo.cpp 5.69 KB
Newer Older
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 11 12 13 14 15 16 17 18 19 20 21
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
22 23
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 ******************************************************************************/
24 25 26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
27

28
#include "dialogs/mediainfo.hpp"
29
#include "input_manager.hpp"
30 31
#include "dialogs_provider.hpp"

32 33 34 35
#include <QTabWidget>
#include <QGridLayout>
#include <QLineEdit>
#include <QLabel>
36

37
MediaInfoDialog *MediaInfoDialog::instance = NULL;
38

39 40 41 42 43
/* This Dialog has two main modes:
    - General Mode that shows the current Played item, and the stats
    - Single mode that shows the info on ONE SINGLE Item on the playlist
   Please be Careful of not breaking one the modes behaviour... */

44 45 46
MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
                                  input_item_t *_p_item,
                                  bool _mainInput,
47 48 49
                                  bool _stats ) :
                                  QVLCFrame( _p_intf ), mainInput(_mainInput),
                                  stats( _stats )
Clément Stenac's avatar
Clément Stenac committed
50
{
51
    p_item = _p_item;
52
    b_cleaned = true;
53
    i_runs = 0;
54

55
    setWindowTitle( qtr( "Media Information" ) );
56

57
    /* TabWidgets and Tabs creation */
58 59 60 61 62
    IT = new QTabWidget;
    MP = new MetaPanel( IT, p_intf );
    IT->addTab( MP, qtr( "&General" ) );
    EMP = new ExtraMetaPanel( IT, p_intf );
    IT->addTab( EMP, qtr( "&Extra Metadata" ) );
63 64
    IP = new InfoPanel( IT, p_intf );
    IT->addTab( IP, qtr( "&Codec Details" ) );
65 66 67
    if( stats )
    {
        ISP = new InputStatsPanel( IT, p_intf );
68
        IT->addTab( ISP, qtr( "&Statistics" ) );
69 70
    }

71 72
    QGridLayout *layout = new QGridLayout( this );

73
    /* No need to use a QDialogButtonBox here */
74
    saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
75
    saveMetaButton->hide();
76
    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
77
    closeButton->setDefault( true );
78

79
    uriLine = new QLineEdit;
80
    QLabel *uriLabel = new QLabel( qtr( "Location:" ) );
81

82
    layout->addWidget( IT, 0, 0, 1, 8 );
83
    layout->addWidget( uriLabel, 1, 0, 1, 1 );
84 85 86
    layout->addWidget( uriLine, 1, 1, 1, 7 );
    layout->addWidget( saveMetaButton, 2, 6 );
    layout->addWidget( closeButton, 2, 7 );
87 88

    BUTTONACT( closeButton, close() );
89 90

    /* The tabs buttons are shown in the main dialog for space and cosmetics */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
91
    BUTTONACT( saveMetaButton, saveMeta() );
92 93

    /* Let the MetaData Panel update the URI */
94
    CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
95
    CONNECT( MP, editing(), this, showMetaSaveButton() );
96

97
    CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
98

99 100 101 102 103 104 105
    /* If using the General Mode */
    if( !p_item )
    {
        msg_Dbg( p_intf, "Using a general windows" );
        CONNECT( THEMIM, inputChanged( input_thread_t * ),
                 this, update( input_thread_t * ) );

106 107
        if( THEMIM->getInput() )
            p_item = input_GetItem( THEMIM->getInput() );
108
    }
109

110
    /* Call update by hand, so info is shown from current item too */
111 112 113
    if( p_item )
        update( p_item, true, true );

114
    readSettings( "Mediainfo", QSize( 600 , 480 ) );
115 116
}

117
MediaInfoDialog::~MediaInfoDialog()
118
{
119
    writeSettings( "Mediainfo" );
120
}
121

122
void MediaInfoDialog::showTab( int i_tab = 0 )
123
{
124
    IT->setCurrentIndex( i_tab );
125
    show();
126 127
}

128
void MediaInfoDialog::showMetaSaveButton()
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
129 130 131 132 133 134 135 136 137 138
{
    saveMetaButton->show();
}

void MediaInfoDialog::saveMeta()
{
    MP->saveMeta();
    saveMetaButton->hide();
}

139 140
/* Function called on inputChanged-update*/
void MediaInfoDialog::update( input_thread_t *p_input )
141
{
142 143
    if( !p_input || p_input->b_dead )
    {
144 145 146 147 148
        if( !b_cleaned )
        {
            clear();
            b_cleaned = true;
        }
149 150
        return;
    }
151

152
    /* Launch the update in all the panels */
153
    vlc_object_hold( p_input );
154

155
    update( input_GetItem(p_input), true, true);
156

157
    vlc_object_release( p_input );
158 159
}

160
void MediaInfoDialog::update( input_item_t *p_item,
161 162
                              bool update_info,
                              bool update_meta )
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
{
    if( update_info )
        IP->update( p_item );
    if( update_meta )
    {
        MP->update( p_item );
        EMP->update( p_item );
    }
    if( stats )
        ISP->update( p_item );
}

void MediaInfoDialog::clear()
{
    IP->clear();
    MP->clear();
    EMP->clear();
    if( stats ) ISP->clear();
181
    b_cleaned = true;
182 183
}

184
void MediaInfoDialog::close()
185
{
186
    toggleVisible();
187

188 189 190 191 192 193
    /* if dialog is closed, revert editing if not saved */
    if( MP->isInEditMode() )
    {
        MP->setEditMode( false );
        updateButtons( 0 );
    }
194 195 196
    if( mainInput == false ) {
        deleteLater();
    }
197
}
198

199
void MediaInfoDialog::updateButtons( int i_tab )
200
{
201
    if( MP->isInEditMode() && i_tab == 0 )
202 203 204
        saveMetaButton->show();
    else
        saveMetaButton->hide();
205
}