]> git.sesse.net Git - vlc/blob - modules/gui/macosx/playlistinfo.m
Works around an issue with some playlist items added by the sap interface : since...
[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]->psz_uri] == nil ) ?
72                 @"" :
73                 [NSString stringWithUTF8String:p_playlist->
74                     pp_items[i_item]->psz_uri]];
75
76             [o_title_txt setStringValue:
77                 ([NSString stringWithUTF8String:p_playlist->
78                     pp_items[i_item]->psz_name] == nil ) ?
79                 @"" :
80                 [NSString stringWithUTF8String:p_playlist->
81                     pp_items[i_item]->psz_name]];
82
83             [o_author_txt setStringValue:[NSString stringWithUTF8String: playlist_GetInfo(p_playlist, i_item ,_("General"),_("Author") )]];
84
85             [[VLCInfoTreeItem rootItem] refresh];
86             [o_outline_view reloadData];
87             vlc_object_release( p_playlist );
88         }
89         [o_info_window makeKeyAndOrderFront: sender];
90     }
91 }
92
93 - (IBAction)infoCancel:(id)sender
94 {
95     [self togglePlaylistInfoPanel:self];
96 }
97
98
99 - (IBAction)infoOk:(id)sender
100 {
101     int i_item = [o_vlc_playlist selectedPlaylistItem];
102     intf_thread_t * p_intf = [NSApp getIntf];
103     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
104                                           FIND_ANYWHERE );
105     vlc_value_t val;
106
107     if (p_playlist)                       
108     {
109         vlc_mutex_lock(&p_playlist->pp_items[i_item]->lock);
110         
111         p_playlist->pp_items[i_item]->psz_uri = strdup([[o_uri_txt stringValue] cString]);
112         p_playlist->pp_items[i_item]->psz_name = strdup([[o_title_txt stringValue] cString]);
113         playlist_ItemAddInfo(p_playlist->pp_items[i_item],_("General"),_("Author"), [[o_author_txt stringValue] cString]);
114  
115         vlc_mutex_unlock(&p_playlist->pp_items[i_item]->lock);
116         val.b_bool = VLC_TRUE;
117         var_Set( p_playlist,"intf-change",val );
118         vlc_object_release ( p_playlist );
119     } 
120     [self togglePlaylistInfoPanel:self];
121 }
122
123
124 @end
125
126 @implementation VLCPlaylistInfo (NSTableDataSource)
127
128 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item  
129 {
130     return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
131 }
132
133 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
134     return ([item numberOfChildren] > 0);
135 }
136
137 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item  
138 {
139     return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
140 }
141
142 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
143 {
144     if ([[tableColumn identifier] isEqualToString:@"0"])
145     {
146         return (item == nil) ? @"" : (id)[item getName];
147     }
148     else
149     {
150         return (item == nil) ? @"" : (id)[item getValue];
151     }
152 }
153
154 @end
155
156 @implementation VLCInfoTreeItem
157
158 static VLCInfoTreeItem *o_root_item = nil;
159
160 #define IsALeafNode ((id)-1)
161
162 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
163 {
164     self = [super init];
165  
166     if( self != nil )
167     {
168
169         i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];
170         o_name = [o_item_name copy];
171         o_value = [o_item_value copy];
172         i_object_id = i_id;
173         o_parent = o_parent_item;
174     }
175     return( self );
176 }
177
178 + (VLCInfoTreeItem *)rootItem {
179     if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
180     return o_root_item;
181 }
182
183 - (void)dealloc
184 {
185     if (o_children != IsALeafNode) [o_children release];
186     [o_name release];
187     [super dealloc];
188 }
189
190 /* Creates and returns the array of children
191  * Loads children incrementally */
192 - (NSArray *)children
193 {
194     if (o_children == NULL)
195     {
196         intf_thread_t * p_intf = [NSApp getIntf];
197         playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
198                                           FIND_ANYWHERE );
199         int i;
200
201         if (p_playlist)
202         {
203             if (i_item > -1)
204             {
205                 if (self == o_root_item)
206                 {
207                     o_children = [[NSMutableArray alloc] initWithCapacity:p_playlist->pp_items[i_item]->i_categories];
208                     for (i = 0 ; i<p_playlist->pp_items[i_item]->i_categories ; i++)
209                     {
210                         [o_children addObject:[[VLCInfoTreeItem alloc] 
211                             initWithName: [NSString stringWithUTF8String:
212                                 p_playlist->pp_items[i_item]->pp_categories[i]
213                                 ->psz_name]
214                             value: @""
215                             ID: i 
216                             parent: self]];
217                     }
218                 }
219                 else if (o_parent == o_root_item)
220                 {
221                     o_children = [[NSMutableArray alloc] initWithCapacity:
222                         p_playlist->pp_items[i_item]->
223                         pp_categories[i_object_id]->i_infos];
224                     for (i = 0 ; i<p_playlist->pp_items[i_item]->
225                            pp_categories[i_object_id]->i_infos ; i++)
226                     {
227                         [o_children addObject:[[VLCInfoTreeItem alloc]
228                         initWithName: [NSString stringWithUTF8String:
229                                 p_playlist->pp_items[i_item]->
230                                 pp_categories[i_object_id]->
231                                 pp_infos[i]->psz_name]
232                             value: [NSString stringWithUTF8String:
233                                 p_playlist->pp_items[i_item]->
234                                 pp_categories[i_object_id]->
235                                 pp_infos[i]->psz_value]
236                             ID: i
237                             parent: self]];
238                     }
239                 }
240                 else
241                 {
242                     o_children = IsALeafNode;
243                 }
244             }
245             vlc_object_release(p_playlist);
246         }
247     }
248     return o_children;
249 }
250
251 - (NSString *)getName
252 {
253     return o_name;
254 }
255
256 - (NSString *)getValue
257 {
258     return o_value;
259 }
260
261 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
262     return [[self children] objectAtIndex:i_index];
263 }
264
265 - (int)numberOfChildren {
266     id i_tmp = [self children];
267     return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
268 }
269
270 - (int)selectedPlaylistItem
271 {
272     return i_item; 
273 }
274
275 - (void)refresh
276 {
277     if (o_children != NULL)
278     {
279         [o_children release];
280         o_children = NULL;
281     }
282     i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];
283 }
284
285 @end
286