]> git.sesse.net Git - vlc/blob - modules/gui/macosx/info.m
* extras/MacOSX/Resources/English.lproj/MainMenu.nib
[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.9 2004/01/09 22:11:04 hartman Exp $
6  *
7  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
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     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
88                                                        FIND_ANYWHERE );
89
90     if ( p_input == NULL )
91     {
92         return;
93     }
94
95     [o_strings removeAllObjects];
96     [o_selector removeAllItems];
97
98     vlc_mutex_lock( &p_input->stream.stream_lock );
99     input_info_category_t * p_category = p_input->stream.p_info;
100
101     while( p_category )
102     {
103         [self createInfoView: p_category];
104         p_category = p_category->p_next;
105     }
106
107     vlc_mutex_unlock( &p_input->stream.stream_lock );
108     if( p_input ) vlc_object_release( p_input );
109
110     int i_select = [o_selector indexOfItemWithTitle:o_selectedPane];
111     if ( i_select < 0 )
112     {
113         i_select = 0;
114     }
115     [o_selector selectItemAtIndex: i_select ];
116     [self showCategory: o_selector];
117 }
118
119 - (void)createInfoView:(input_info_category_t *)p_category
120 {
121     NSString * o_title;
122     NSMutableString * o_content;
123     input_info_t * p_info;
124
125     /* Add a category */
126     o_title = [NSString stringWithUTF8String: p_category->psz_name];
127     [o_selector addItemWithTitle: o_title];
128
129     /* Create empty content string */
130     o_content = [NSMutableString string];
131
132     /* Add the fields */
133     p_info = p_category->p_info;
134
135     while( p_info )
136     {
137         [o_content appendFormat: @"%@: %@\n\n", [NSApp localizedString: p_info->psz_name],
138                                                 [NSApp localizedString: p_info->psz_value]]; 
139         p_info = p_info->p_next;
140     }
141
142     [o_strings setObject: o_content forKey: o_title];
143 }
144
145 @end
146
147 @implementation VLCInfo (NSMenuValidation)
148  
149 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
150 {
151     BOOL bEnabled = TRUE;
152
153     intf_thread_t * p_intf = [NSApp getIntf];
154     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
155                                                        FIND_ANYWHERE );
156
157     if( [[o_mi title] isEqualToString: _NS("Info")] )
158     {
159         if( p_input == NULL )
160         {
161             bEnabled = FALSE;
162         }
163     }
164     if( p_input ) vlc_object_release( p_input );
165
166     return( bEnabled );
167 }
168
169 @end