]> git.sesse.net Git - vlc/blob - modules/gui/macosx/playlistinfo.m
* modules/gui/*: compilation fixes for the new input_item_t change.
[vlc] / modules / gui / macosx / playlistinfo.m
1 /*****************************************************************************
2  * playlistinfo.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2002-2004 VideoLAN
5  * $Id: playlistinfo.m 7015 2004-03-08 15:22:58Z bigben $
6  *
7  * Authors: Benjmaib Pracht <bigben 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 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #include "intf.h"
29 #include "playlistinfo.h"
30 #include "playlist.h"
31
32 /*****************************************************************************
33  * VLCPlaylistInfo Implementation
34  *****************************************************************************/
35
36 @implementation VLCPlaylistInfo
37
38 - (void)awakeFromNib
39 {
40
41     [o_info_window setExcludedFromWindowsMenu: TRUE];
42
43     [o_info_window setTitle: _NS("Properties")];
44     [o_uri_lbl setStringValue: _NS("URI")];
45     [o_title_lbl setStringValue: _NS("Title")];
46     [o_author_lbl setStringValue: _NS("Author")];
47     [o_btn_info_ok setTitle: _NS("OK")];
48     [o_btn_info_cancel setTitle: _NS("Cancel")];
49 }
50
51 - (IBAction)togglePlaylistInfoPanel:(id)sender
52 {
53     intf_thread_t * p_intf = [NSApp getIntf];
54     playlist_t * p_playlist;
55
56     if( [o_info_window isVisible] )
57     {
58         [o_info_window orderOut: sender];
59     }
60     else
61     {
62         p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
63                                           FIND_ANYWHERE );
64
65         if (p_playlist)
66         {
67             /*fill uri / title / author info */
68             int i_item = [o_vlc_playlist selectedPlaylistItem];
69             [o_uri_txt setStringValue:
70                 ([NSString stringWithUTF8String:p_playlist->
71                     pp_items[i_item]->input.psz_uri] == nil ) ?
72                 [NSString stringWithCString:p_playlist->
73                     pp_items[i_item]->input.psz_uri] :
74                 [NSString stringWithUTF8String:p_playlist->
75                     pp_items[i_item]->input.psz_uri]];
76
77             [o_title_txt setStringValue:
78                 ([NSString stringWithUTF8String:p_playlist->
79                     pp_items[i_item]->input.psz_name] == nil ) ?
80                 [NSString stringWithCString:p_playlist->
81                     pp_items[i_item]->input.psz_name] :
82                 [NSString stringWithUTF8String:p_playlist->
83                     pp_items[i_item]->input.psz_name]];
84
85             [o_author_txt setStringValue:[NSString stringWithUTF8String: playlist_GetInfo(p_playlist, i_item ,_("General"),_("Author") )]];
86
87             [[VLCInfoTreeItem rootItem] refresh];
88             [o_outline_view reloadData];
89             vlc_object_release( p_playlist );
90         }
91         [o_info_window makeKeyAndOrderFront: sender];
92     }
93 }
94
95 - (IBAction)infoCancel:(id)sender
96 {
97     [self togglePlaylistInfoPanel:self];
98 }
99
100
101 - (IBAction)infoOk:(id)sender
102 {
103     int i_item = [o_vlc_playlist selectedPlaylistItem];
104     intf_thread_t * p_intf = [NSApp getIntf];
105     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
106                                           FIND_ANYWHERE );
107     vlc_value_t val;
108
109     if (p_playlist)                       
110     {
111         vlc_mutex_lock(&p_playlist->pp_items[i_item]->input.lock);
112         
113         p_playlist->pp_items[i_item]->input.psz_uri =
114             strdup([[o_uri_txt stringValue] cString]);
115         p_playlist->pp_items[i_item]->input.psz_name =
116             strdup([[o_title_txt stringValue] cString]);
117         playlist_ItemAddInfo(p_playlist->pp_items[i_item],_("General"),_("Author"), [[o_author_txt stringValue] cString]);
118  
119         vlc_mutex_unlock(&p_playlist->pp_items[i_item]->input.lock);
120         val.b_bool = VLC_TRUE;
121         var_Set( p_playlist,"intf-change",val );
122         vlc_object_release ( p_playlist );
123     } 
124     [self togglePlaylistInfoPanel:self];
125 }
126
127
128 @end
129
130 @implementation VLCPlaylistInfo (NSTableDataSource)
131
132 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item  
133 {
134     return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
135 }
136
137 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
138     return ([item numberOfChildren] > 0);
139 }
140
141 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item  
142 {
143     return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
144 }
145
146 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
147 {
148     if ([[tableColumn identifier] isEqualToString:@"0"])
149     {
150         return (item == nil) ? @"" : (id)[item getName];
151     }
152     else
153     {
154         return (item == nil) ? @"" : (id)[item getValue];
155     }
156 }
157
158 @end
159
160 @implementation VLCInfoTreeItem
161
162 static VLCInfoTreeItem *o_root_item = nil;
163
164 #define IsALeafNode ((id)-1)
165
166 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
167 {
168     self = [super init];
169  
170     if( self != nil )
171     {
172
173         i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];
174         o_name = [o_item_name copy];
175         o_value = [o_item_value copy];
176         i_object_id = i_id;
177         o_parent = o_parent_item;
178     }
179     return( self );
180 }
181
182 + (VLCInfoTreeItem *)rootItem {
183     if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
184     return o_root_item;
185 }
186
187 - (void)dealloc
188 {
189     if (o_children != IsALeafNode) [o_children release];
190     [o_name release];
191     [super dealloc];
192 }
193
194 /* Creates and returns the array of children
195  * Loads children incrementally */
196 - (NSArray *)children
197 {
198     if (o_children == NULL)
199     {
200         intf_thread_t * p_intf = [NSApp getIntf];
201         playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
202                                           FIND_ANYWHERE );
203         int i;
204
205         if (p_playlist)
206         {
207             if (i_item > -1)
208             {
209                 if (self == o_root_item)
210                 {
211                     o_children = [[NSMutableArray alloc] initWithCapacity:p_playlist->pp_items[i_item]->input.i_categories];
212                     for (i = 0 ; i<p_playlist->pp_items[i_item]->input.i_categories ; i++)
213                     {
214                         [o_children addObject:[[VLCInfoTreeItem alloc] 
215                             initWithName: [NSString stringWithUTF8String:
216                                 p_playlist->pp_items[i_item]->input.
217                                 pp_categories[i]->psz_name]
218                             value: @""
219                             ID: i 
220                             parent: self]];
221                     }
222                 }
223                 else if (o_parent == o_root_item)
224                 {
225                     o_children = [[NSMutableArray alloc] initWithCapacity:
226                         p_playlist->pp_items[i_item]->input.
227                         pp_categories[i_object_id]->i_infos];
228                     for (i = 0 ; i<p_playlist->pp_items[i_item]->input.
229                            pp_categories[i_object_id]->i_infos ; i++)
230                     {
231                         [o_children addObject:[[VLCInfoTreeItem alloc]
232                         initWithName: [NSString stringWithUTF8String:
233                                 p_playlist->pp_items[i_item]->input.
234                                 pp_categories[i_object_id]->
235                                 pp_infos[i]->psz_name]
236                             value: [NSString stringWithUTF8String:
237                                 p_playlist->pp_items[i_item]->input.
238                                 pp_categories[i_object_id]->
239                                 pp_infos[i]->psz_value]
240                             ID: i
241                             parent: self]];
242                     }
243                 }
244                 else
245                 {
246                     o_children = IsALeafNode;
247                 }
248             }
249             vlc_object_release(p_playlist);
250         }
251     }
252     return o_children;
253 }
254
255 - (NSString *)getName
256 {
257     return o_name;
258 }
259
260 - (NSString *)getValue
261 {
262     return o_value;
263 }
264
265 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
266     return [[self children] objectAtIndex:i_index];
267 }
268
269 - (int)numberOfChildren {
270     id i_tmp = [self children];
271     return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
272 }
273
274 - (int)selectedPlaylistItem
275 {
276     return i_item; 
277 }
278
279 - (void)refresh
280 {
281     if (o_children != NULL)
282     {
283         [o_children release];
284         o_children = NULL;
285     }
286     i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];
287 }
288
289 @end
290