]> git.sesse.net Git - vlc/blob - modules/gui/macosx/info.m
* had accidentally deleted the first line of vout.m
[vlc] / modules / gui / macosx / info.m
1 /*****************************************************************************
2  * info.m: MacOS X info panel
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: info.m,v 1.6 2003/05/25 17:27:13 massiot Exp $
6  *
7  * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include "intf.h"
25 #include "info.h"
26
27 /*****************************************************************************
28  * VLCInfo implementation 
29  *****************************************************************************/
30 @implementation VLCInfo
31
32 - (void)awakeFromNib
33 {
34     [o_window setExcludedFromWindowsMenu: YES];
35 }
36
37 - (id)init
38 {
39     self = [super init];
40
41     if( self != nil )
42     {
43         o_strings = [[NSMutableDictionary alloc] init];
44     }
45
46     return( self );
47 }
48
49 - (void)dealloc
50 {
51     [o_strings release];
52     [super dealloc];
53 }
54
55 - (IBAction)toggleInfoPanel:(id)sender
56 {
57     if( [o_window isVisible] )
58     {
59         [o_window orderOut: sender];
60     }
61     else
62     {
63         [o_window orderFront: sender];
64         [self updateInfo];
65     }
66 }
67
68 - (IBAction)showCategory:(id)sender
69 {
70     NSString * o_title = [o_selector titleOfSelectedItem];
71     [o_view setString: [o_strings objectForKey: o_title]];
72     [o_view setNeedsDisplay: YES];
73 }
74
75 - (void)updateInfo
76 {
77     NSString *o_selectedPane;
78     
79     if( ![o_window isVisible] )
80     {
81         return;
82     }
83     
84     o_selectedPane = [[o_selector selectedItem] title];
85
86     intf_thread_t * p_intf = [NSApp getIntf]; 
87     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
88                                                        FIND_ANYWHERE );
89
90     if( p_playlist == NULL )
91     {
92         return;
93     }
94
95     vlc_mutex_lock( &p_playlist->object_lock );
96
97     if ( p_playlist->p_input == NULL )
98     {
99         vlc_mutex_unlock( &p_playlist->object_lock );
100         vlc_object_release( p_playlist );
101         return;
102     }
103
104     [o_strings removeAllObjects];
105     [o_selector removeAllItems];
106
107     vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
108     input_info_category_t * p_category = p_playlist->p_input->stream.p_info;
109
110     while( p_category )
111     {
112         [self createInfoView: p_category];
113         p_category = p_category->p_next;
114     }
115
116     vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
117     vlc_mutex_unlock( &p_playlist->object_lock );
118     vlc_object_release( p_playlist );
119
120     int i_select = [o_selector indexOfItemWithTitle:o_selectedPane];
121     if ( i_select < 0 )
122     {
123         i_select = 0;
124     }
125     [o_selector selectItemAtIndex: i_select ];
126     [self showCategory: o_selector];
127 }
128
129 - (void)createInfoView:(input_info_category_t *)p_category
130 {
131     NSString * o_title;
132     NSMutableString * o_content;
133     input_info_t * p_info;
134
135     /* Add a category */
136     o_title = [NSString stringWithUTF8String: p_category->psz_name];
137     [o_selector addItemWithTitle: o_title];
138
139     /* Create empty content string */
140     o_content = [NSMutableString string];
141
142     /* Add the fields */
143     p_info = p_category->p_info;
144
145     while( p_info )
146     {
147         [o_content appendFormat: @"%@: %@\n\n", [NSApp localizedString: p_info->psz_name],
148                                                 [NSApp localizedString: p_info->psz_value]]; 
149         p_info = p_info->p_next;
150     }
151
152     [o_strings setObject: o_content forKey: o_title];
153 }
154
155 @end
156
157 @implementation VLCInfo (NSMenuValidation)
158  
159 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
160 {
161     BOOL bEnabled = TRUE;
162
163     intf_thread_t * p_intf = [NSApp getIntf];
164     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
165                                                        FIND_ANYWHERE );
166
167     if( p_playlist != NULL )
168     {
169         vlc_mutex_lock( &p_playlist->object_lock );
170     }
171
172     if( [[o_mi title] isEqualToString: _NS("Info")] )
173     {
174         if( p_playlist == NULL || p_playlist->p_input == NULL )
175         {
176             bEnabled = FALSE;
177         }
178     }
179     
180     if( p_playlist != NULL )
181     {
182         vlc_mutex_unlock( &p_playlist->object_lock );
183         vlc_object_release( p_playlist );
184     }
185
186     return( bEnabled );
187 }
188
189 @end