streaminfo.cpp 3.16 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * streaminfo.cpp : Information about an item
 ****************************************************************************
4
5
 * Copyright (C) 2006 the VideoLAN team
 * $Id$
zorglub's avatar
zorglub committed
6
7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
zorglub's avatar
zorglub committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/

24
#include <QTabWidget>
25
#include <QGridLayout>
26

zorglub's avatar
zorglub committed
27
#include "dialogs/streaminfo.hpp"
28
#include "input_manager.hpp"
zorglub's avatar
zorglub committed
29
30
31
32
33
#include "dialogs_provider.hpp"
#include "util/qvlcframe.hpp"
#include "components/infopanels.hpp"
#include "qt4.hpp"

zorglub's avatar
zorglub committed
34
35
static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *param );
36
MediaInfoDialog *MediaInfoDialog::instance = NULL;
zorglub's avatar
zorglub committed
37

38
MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf ) :QVLCFrame( _p_intf )
zorglub's avatar
zorglub committed
39
{
zorglub's avatar
zorglub committed
40
    i_runs = 0;
41
    p_input = NULL;
42

43
44
45
    setWindowTitle( qtr( "Media information" ) );

    QGridLayout *layout = new QGridLayout(this);
zorglub's avatar
zorglub committed
46
    IT = new InfoTab( this, p_intf, true ) ;
47
    QPushButton *closeButton = new QPushButton(qtr("&Close"));
48

49
50
    layout->addWidget(IT,0,0,1,3);
    layout->addWidget(closeButton,1,2);
51
52

    BUTTONACT( closeButton, close() );
zorglub's avatar
zorglub committed
53
    ON_TIMEOUT( update() );
zorglub's avatar
zorglub committed
54

zorglub's avatar
zorglub committed
55
    var_AddCallback( THEPL, "item-change", ItemChanged, this );
56
    readSettings( "StreamInfo" , QSize( 500, 450 ) );
zorglub's avatar
zorglub committed
57
58
}

59
MediaInfoDialog::~MediaInfoDialog()
zorglub's avatar
zorglub committed
60
{
zorglub's avatar
zorglub committed
61
    var_DelCallback( THEPL, "item-change", ItemChanged, this );
62
    writeSettings( "StreamInfo" );
zorglub's avatar
zorglub committed
63
}
64

zorglub's avatar
zorglub committed
65
66
static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *param )
67
{
68
    MediaInfoDialog *p_d = (MediaInfoDialog *)param;
zorglub's avatar
zorglub committed
69
70
    p_d->need_update = VLC_TRUE;
    return VLC_SUCCESS;
71
72
}

73
void MediaInfoDialog::update()
74
{
zorglub's avatar
zorglub committed
75
76
77
78
79
80
81
82
83
84
    // Timer runs at 150 ms, dont' update more than 2 times per second
    i_runs++;
    if( i_runs % 3 != 0 ) return;

    input_thread_t *p_input = MainInputManager::getInstance( p_intf )->getInput();
    if( !p_input || p_input->b_dead )
    {
        IT->clear();
        return;
    }
85

zorglub's avatar
zorglub committed
86
87
    vlc_object_yield( p_input );
    vlc_mutex_lock( &p_input->input.p_item->lock );
88

zorglub's avatar
zorglub committed
89
90
    IT->update( p_input->input.p_item, need_update, need_update );
    need_update = false;
91

zorglub's avatar
zorglub committed
92
93
    vlc_mutex_unlock( &p_input->input.p_item->lock );
    vlc_object_release( p_input );
94
95
}

96
void MediaInfoDialog::close()
97
{
zorglub's avatar
zorglub committed
98
    this->toggleVisible();
99
}