]> git.sesse.net Git - vlc/blob - modules/gui/macosx/playlistinfo.m
Group selection combo box in stream proprieties dialog. Also allows to create new...
[vlc] / modules / gui / macosx / playlistinfo.m
1 /*****************************************************************************
2  r 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     [o_info_window setExcludedFromWindowsMenu: TRUE];
41
42     [o_info_window setTitle: _NS("Properties")];
43     [o_uri_lbl setStringValue: _NS("URI")];
44     [o_title_lbl setStringValue: _NS("Title")];
45     [o_author_lbl setStringValue: _NS("Author")];
46     [o_btn_info_ok setTitle: _NS("OK")];
47     [o_btn_info_cancel setTitle: _NS("Cancel")];
48     [o_group_lbl setStringValue: _NS("Group")];
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;
69             int i_item = [o_vlc_playlist selectedPlaylistItem];
70             [o_uri_txt setStringValue:
71                 ([NSString stringWithUTF8String:p_playlist->
72                     pp_items[i_item]->input.psz_uri] == nil ) ?
73                 [NSString stringWithCString:p_playlist->
74                     pp_items[i_item]->input.psz_uri] :
75                 [NSString stringWithUTF8String:p_playlist->
76                     pp_items[i_item]->input.psz_uri]];
77
78             [o_title_txt setStringValue:
79                 ([NSString stringWithUTF8String:p_playlist->
80                     pp_items[i_item]->input.psz_name] == nil ) ?
81                 [NSString stringWithCString:p_playlist->
82                     pp_items[i_item]->input.psz_name] :
83                 [NSString stringWithUTF8String:p_playlist->
84                     pp_items[i_item]->input.psz_name]];
85
86             [o_author_txt setStringValue:
87                 [NSString stringWithUTF8String:playlist_GetInfo
88                 (p_playlist, i_item ,_("General"),_("Author") )]];
89
90             [[VLCInfoTreeItem rootItem] refresh];
91             [o_outline_view reloadData];
92
93             [o_group_cbx removeAllItems];
94
95             for (i = 0; i < p_playlist->i_groups ; i++)
96             {
97                 [o_group_cbx addItemWithObjectValue: 
98                     [NSString stringWithUTF8String:
99                     p_playlist->pp_groups[i]->psz_name]];
100                 if (p_playlist->pp_items[i_item]->i_group == p_playlist
101                     ->pp_groups[i]->i_id)
102                 {
103                     [o_group_cbx selectItemAtIndex:i];
104                 }
105             }
106
107             [self handleGroup:self];
108
109             vlc_object_release( p_playlist );
110         }
111         [o_info_window makeKeyAndOrderFront: sender];
112     }
113 }
114
115 - (IBAction)infoCancel:(id)sender
116 {
117     [self togglePlaylistInfoPanel:self];
118 }
119
120
121 - (IBAction)infoOk:(id)sender
122 {
123     int i_item = [o_vlc_playlist selectedPlaylistItem];
124     intf_thread_t * p_intf = [NSApp getIntf];
125     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
126                                           FIND_ANYWHERE );
127     vlc_value_t val;
128
129     if (p_playlist)                       
130     {
131         vlc_mutex_lock(&p_playlist->pp_items[i_item]->input.lock);
132         
133         p_playlist->pp_items[i_item]->input.psz_uri =
134             strdup([[o_uri_txt stringValue] cString]);
135         p_playlist->pp_items[i_item]->input.psz_name =
136             strdup([[o_title_txt stringValue] cString]);
137         playlist_ItemAddInfo(p_playlist->pp_items[i_item],_("General"),_("Author"), [[o_author_txt stringValue] cString]);
138
139         if ([[o_group_cbx stringValue] isEqual:
140                     [o_group_cbx objectValueOfSelectedItem]])
141         {
142             p_playlist->pp_items[i_item]->i_group = p_playlist->
143                     pp_groups[[o_group_cbx indexOfSelectedItem]]->i_id; 
144         }
145         else
146         {
147             playlist_group_t * p_group = playlist_CreateGroup( p_playlist, 
148                 strdup([[o_group_cbx stringValue] cString]));
149             p_playlist->pp_items[i_item]->i_group = p_group->i_id;
150         }
151
152
153         vlc_mutex_unlock(&p_playlist->pp_items[i_item]->input.lock);
154         val.b_bool = VLC_TRUE;
155         var_Set( p_playlist,"intf-change",val );
156         vlc_object_release ( p_playlist );
157     } 
158     [self togglePlaylistInfoPanel:self];
159 }
160
161 - (IBAction)handleGroup:(id)sender
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)
168     {
169         if ([[o_group_cbx stringValue] isEqual: 
170                     [o_group_cbx objectValueOfSelectedItem]])
171         {
172             [o_group_color setBackgroundColor:[o_vlc_playlist 
173                 getColor: p_playlist->pp_groups[
174                 [o_group_cbx indexOfSelectedItem]]->i_id]];
175         }
176         else
177         {
178             [o_group_color setBackgroundColor:[o_vlc_playlist 
179                 getColor:p_playlist->pp_groups[
180                 [o_group_cbx numberOfItems] - 1]->i_id + 1]];
181         }
182     vlc_object_release(p_playlist);
183     }
184 }
185
186 @end
187
188 @implementation VLCPlaylistInfo (NSTableDataSource)
189
190 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item  
191 {
192     return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
193 }
194
195 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
196     return ([item numberOfChildren] > 0);
197 }
198
199 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item  
200 {
201     return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
202 }
203
204 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
205 {
206     if ([[tableColumn identifier] isEqualToString:@"0"])
207     {
208         return (item == nil) ? @"" : (id)[item getName];
209     }
210     else
211     {
212         return (item == nil) ? @"" : (id)[item getValue];
213     }
214 }
215
216 @end
217
218 @implementation VLCInfoTreeItem
219
220 static VLCInfoTreeItem *o_root_item = nil;
221
222 #define IsALeafNode ((id)-1)
223
224 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
225 {
226     self = [super init];
227  
228     if( self != nil )
229     {
230
231         i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];
232         o_name = [o_item_name copy];
233         o_value = [o_item_value copy];
234         i_object_id = i_id;
235         o_parent = o_parent_item;
236     }
237     return( self );
238 }
239
240 + (VLCInfoTreeItem *)rootItem {
241     if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
242     return o_root_item;
243 }
244
245 - (void)dealloc
246 {
247     if (o_children != IsALeafNode) [o_children release];
248     [o_name release];
249     [super dealloc];
250 }
251
252 /* Creates and returns the array of children
253  * Loads children incrementally */
254 - (NSArray *)children
255 {
256     if (o_children == NULL)
257     {
258         intf_thread_t * p_intf = [NSApp getIntf];
259         playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
260                                           FIND_ANYWHERE );
261         int i;
262
263         if (p_playlist)
264         {
265             if (i_item > -1)
266             {
267                 if (self == o_root_item)
268                 {
269                     o_children = [[NSMutableArray alloc] initWithCapacity:p_playlist->pp_items[i_item]->input.i_categories];
270                     for (i = 0 ; i<p_playlist->pp_items[i_item]->input.i_categories ; i++)
271                     {
272                         [o_children addObject:[[VLCInfoTreeItem alloc] 
273                             initWithName: [NSString stringWithUTF8String:
274                                 p_playlist->pp_items[i_item]->input.
275                                 pp_categories[i]->psz_name]
276                             value: @""
277                             ID: i 
278                             parent: self]];
279                     }
280                 }
281                 else if (o_parent == o_root_item)
282                 {
283                     o_children = [[NSMutableArray alloc] initWithCapacity:
284                         p_playlist->pp_items[i_item]->input.
285                         pp_categories[i_object_id]->i_infos];
286                     for (i = 0 ; i<p_playlist->pp_items[i_item]->input.
287                            pp_categories[i_object_id]->i_infos ; i++)
288                     {
289                         [o_children addObject:[[VLCInfoTreeItem alloc]
290                         initWithName: [NSString stringWithUTF8String:
291                                 p_playlist->pp_items[i_item]->input.
292                                 pp_categories[i_object_id]->
293                                 pp_infos[i]->psz_name]
294                             value: [NSString stringWithUTF8String:
295                                 p_playlist->pp_items[i_item]->input.
296                                 pp_categories[i_object_id]->
297                                 pp_infos[i]->psz_value]
298                             ID: i
299                             parent: self]];
300                     }
301                 }
302                 else
303                 {
304                     o_children = IsALeafNode;
305                 }
306             }
307             vlc_object_release(p_playlist);
308         }
309     }
310     return o_children;
311 }
312
313 - (NSString *)getName
314 {
315     return o_name;
316 }
317
318 - (NSString *)getValue
319 {
320     return o_value;
321 }
322
323 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
324     return [[self children] objectAtIndex:i_index];
325 }
326
327 - (int)numberOfChildren {
328     id i_tmp = [self children];
329     return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
330 }
331
332 - (int)selectedPlaylistItem
333 {
334     return i_item; 
335 }
336
337 - (void)refresh
338 {
339     if (o_children != NULL)
340     {
341         [o_children release];
342         o_children = NULL;
343     }
344     i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];
345 }
346
347 @end
348