fileinfo.cpp 4.82 KB
Newer Older
1 2 3
/*****************************************************************************
 * fileinfo.cpp : wxWindows plugin for vlc
 *****************************************************************************
4
 * Copyright (C) 2000-2004 the VideoLAN team
5
 * $Id$
6
 *
7
 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * 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
Antoine Cellerier's avatar
Antoine Cellerier committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23
 *****************************************************************************/

24
#include "dialogs/fileinfo.hpp"
25
#include "dialogs/infopanels.hpp"
26 27 28 29 30

/*****************************************************************************
 * Event Table.
 *****************************************************************************/

31 32 33 34
static int ItemChanged( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );


35 36 37 38 39 40 41 42
/* IDs for the controls and the menu commands */
enum
{
    Close_Event
};

BEGIN_EVENT_TABLE(FileInfo, wxFrame)
    /* Button events */
43
    EVT_BUTTON(wxID_OK, FileInfo::OnButtonClose)
44

45
    /* Hide the window when the user closes the window */
46
    EVT_CLOSE(FileInfo::OnClose)
Gildas Bazin's avatar
 
Gildas Bazin committed
47

48 49 50 51 52
END_EVENT_TABLE()

/*****************************************************************************
 * Constructor.
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
53
FileInfo::FileInfo( intf_thread_t *_p_intf, wxWindow *p_parent ):
Sam Hocevar's avatar
Sam Hocevar committed
54
    wxFrame( p_parent, -1, wxU(_("Stream and media info")), wxDefaultPosition,
55 56
             wxDefaultSize, wxDEFAULT_FRAME_STYLE )
{
57 58 59 60
    p_intf = _p_intf;
    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
                                                 VLC_OBJECT_PLAYLIST,
                                                 FIND_ANYWHERE );
61

62
    /* Initializations */
Gildas Bazin's avatar
 
Gildas Bazin committed
63
    SetIcon( *p_intf->p_sys->p_icon );
64
    SetAutoLayout( TRUE );
Gildas Bazin's avatar
 
Gildas Bazin committed
65

Clément Stenac's avatar
Clément Stenac committed
66
    panel_sizer = new wxBoxSizer( wxVERTICAL );
67 68 69 70 71 72 73

    wxNotebook *notebook = new wxNotebook( this, -1 );
#if (!wxCHECK_VERSION(2,5,2))
        wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
#endif
    item_info = new ItemInfoPanel( p_intf, notebook, false );
    stats_info = new InputStatsInfoPanel( p_intf, notebook );
Gildas Bazin's avatar
 
Gildas Bazin committed
74

75 76
    notebook->AddPage( item_info, wxU(_("General") ), true );
    notebook->AddPage( stats_info, wxU(_("Statistics") ), false );
77

78 79 80 81 82
#if (!wxCHECK_VERSION(2,5,2))
    panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
#else
    panel_sizer->Add( notebook, 1, wxEXPAND | wxALL, 5 );
#endif
Anil Daoud's avatar
 
Anil Daoud committed
83

Gildas Bazin's avatar
 
Gildas Bazin committed
84
    panel_sizer->Layout();
85
    SetSizerAndFit( panel_sizer );
Gildas Bazin's avatar
 
Gildas Bazin committed
86

87 88 89 90 91 92 93

    if( p_playlist )
    {
        var_AddCallback( p_playlist, "item-change", ItemChanged, this );
        vlc_object_release( p_playlist );
    }

94
    last_update = 0L;
95
    b_need_update = VLC_TRUE;
96
    Update();
97 98
}

99
void FileInfo::Update()
100
{
101 102 103 104 105 106 107 108 109

    if( mdate() - last_update < 400000L ) return;
    last_update = mdate();

    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
                                                 VLC_OBJECT_PLAYLIST,
                                                 FIND_ANYWHERE );
    if( !p_playlist ) return;

110
    input_thread_t *p_input = p_playlist->p_input ;
111

112
    if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
113
    {
114 115 116
        item_info->Clear();
        stats_info->Clear();
        if ( p_input )
117 118 119
        {
            vlc_object_release(p_input);
        }
120
        vlc_object_release( p_playlist );
121 122 123
        return;
    }

Laurent Aimar's avatar
Laurent Aimar committed
124
    vlc_mutex_lock( &p_input->input.p_item->lock );
125
    if( b_need_update == VLC_TRUE )
126
    {
127
        item_info->Update( p_input->input.p_item );
128
    }
129
    stats_info->Update( p_input->input.p_item );
Laurent Aimar's avatar
Laurent Aimar committed
130
    vlc_mutex_unlock( &p_input->input.p_item->lock );
Gildas Bazin's avatar
 
Gildas Bazin committed
131

132
    vlc_object_release(p_input);
133 134
    vlc_object_release( p_playlist );
    b_need_update = VLC_FALSE;
Clément Stenac's avatar
Clément Stenac committed
135 136
    panel_sizer->Layout();

137
    return;
138 139 140 141 142 143
}

FileInfo::~FileInfo()
{
}

144 145 146 147 148 149 150
void FileInfo::OnButtonClose( wxCommandEvent& event )
{
    wxCloseEvent cevent;
    OnClose(cevent);
}

void FileInfo::OnClose( wxCloseEvent& WXUNUSED(event) )
151
{
152
    Hide();
153
}
154

155
static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
156 157 158 159 160 161
                        vlc_value_t oldval, vlc_value_t newval, void *param )
{
    FileInfo *p_fileinfo = (FileInfo *)param;
    p_fileinfo->b_need_update = VLC_TRUE;
    return VLC_SUCCESS;
}