mediainfo.cpp 6.16 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
#include "dialogs/mediainfo.hpp"
26
#include "components/infopanels.hpp"
27
#include "input_manager.hpp"
28 29
#include "dialogs_provider.hpp"

30 31 32 33
#include <QTabWidget>
#include <QGridLayout>
#include <QLineEdit>
#include <QLabel>
34

35 36
static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *param );
37
MediaInfoDialog *MediaInfoDialog::instance = NULL;
38

39 40 41 42
MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput,
                                  bool _stats ) :
                                  QVLCFrame( _p_intf ), mainInput(_mainInput),
                                  stats( _stats )
Clément Stenac's avatar
Clément Stenac committed
43
{
44
    i_runs = 0;
45
    p_input = NULL;
46
    b_need_update = true;
47

48
    setWindowTitle( qtr( "Media information" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
49
    resize( 600 , 480 );
50

51
    /* TabWidgets and Tabs creation */
52 53 54 55 56
    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" ) );
57 58
    IP = new InfoPanel( IT, p_intf );
    IT->addTab( IP, qtr( "&Codec Details" ) );
59 60 61
    if( stats )
    {
        ISP = new InputStatsPanel( IT, p_intf );
62
        IT->addTab( ISP, qtr( "&Statistics" ) );
63 64
    }

65 66 67 68
    QGridLayout *layout = new QGridLayout( this );

    /* FIXME GNOME/KDE ? */
    saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
69
    saveMetaButton->hide();
70
    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
71
    closeButton->setDefault( true );
72

73
    uriLine = new QLineEdit;
74
    QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
75

76
    layout->addWidget( IT, 0, 0, 1, 8 );
77
    layout->addWidget( uriLabel, 1, 0, 1, 1 );
78 79 80
    layout->addWidget( uriLine, 1, 1, 1, 7 );
    layout->addWidget( saveMetaButton, 2, 6 );
    layout->addWidget( closeButton, 2, 7 );
81 82

    BUTTONACT( closeButton, close() );
83 84

    /* The tabs buttons are shown in the main dialog for space and cosmetics */
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
85
    CONNECT( saveMetaButton, clicked(), this, saveMeta() );
86 87

    /* Let the MetaData Panel update the URI */
88
    CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
89
    CONNECT( MP, editing(), this, editMeta() );
90

91
    CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
92 93

    /* Create the main Update function with a time (150ms) */
94
    if( mainInput ) {
95
        ON_TIMEOUT( update() );
96 97
        var_AddCallback( THEPL, "item-change", ItemChanged, this );
    }
98 99
}

100
MediaInfoDialog::~MediaInfoDialog()
101
{
102 103 104
    if( mainInput ) {
        var_DelCallback( THEPL, "item-change", ItemChanged, this );
    }
105
    writeSettings( "mediainfo" );
106
}
107

108
void MediaInfoDialog::showTab( int i_tab = 0 )
109 110
{
    this->show();
111
    IT->setCurrentIndex( i_tab );
112 113
}

Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
114 115 116 117 118 119 120 121 122 123 124
void MediaInfoDialog::editMeta()
{
    saveMetaButton->show();
}

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

125
static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
126
        vlc_value_t oldval, vlc_value_t newval, void *param )
127
{
128
    MediaInfoDialog *p_d = (MediaInfoDialog *)param;
129
    p_d->b_need_update = VLC_TRUE;
130
    return VLC_SUCCESS;
131 132
}

133
void MediaInfoDialog::setInput( input_item_t *p_input )
134
{
135 136
    clear();
    update( p_input, true, true );
137
    /* if info is from current input, don't set default to edit, if user opens
138 139 140 141
     * some other item, se default to edit, so it won't be updated to current item metas
     *
     * This really doesn't seem as clean solution as it could be
     */
142 143
    input_thread_t *p_current =
                     MainInputManager::getInstance( p_intf )->getInput();
144
    MP->setEditMode( ( !p_current || p_current->b_dead || input_GetItem( p_current ) != p_input ) ?
145
                            true: false );
146 147
}

148
void MediaInfoDialog::update()
149
{
150
    /* Timer runs at 150 ms, dont' update more than 2 times per second */
151
    i_runs++;
152
    if( i_runs % 4 != 0 ) return;
153

154
    /* Get Input and clear if non-existant */
155
    input_thread_t *p_input =
156
                     MainInputManager::getInstance( p_intf )->getInput();
157 158
    if( !p_input || p_input->b_dead )
    {
159
        clear();
160 161
        return;
    }
162

163
    vlc_object_yield( p_input );
164

165 166
    update( input_GetItem(p_input), b_need_update, b_need_update );
    b_need_update = false;
167

168
    vlc_object_release( p_input );
169 170
}

171
void MediaInfoDialog::update( input_item_t *p_item,
172 173
                                                 bool update_info,
                                                 bool update_meta )
174
{
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
175
    MP->setInput( p_item );
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    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();
}

195
void MediaInfoDialog::close()
196
{
197
    this->toggleVisible();
198 199 200 201

    if( mainInput == false ) {
        deleteLater();
    }
202
    MP->setEditMode( false );
203
}
204

205
void MediaInfoDialog::updateButtons( int i_tab )
206
{
207
    if( MP->isInEditMode() && i_tab == 0 )
208 209 210
        saveMetaButton->show();
    else
        saveMetaButton->hide();
211
}