extra/MacOSX/VLC_app: Initial import of a wanna-be VLC.app application that use the...
[vlc.git] / extras / MacOSX / VLC_app / VLCController.m
1 /*****************************************************************************
2  * VLCController.h: VLC.app main controller
3  *****************************************************************************
4  * Copyright (C) 2007 Pierre d'Herbemont
5  * Copyright (C) 2007 the VideoLAN team
6  * $Id$
7  *
8  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /* this code needs rework, but it does nice thing */
26
27 #import <VLC/VLC.h>
28 #import "VLCController.h"
29 #import "VLCCategoryCell.h"
30 NSArrayController * treeController;
31 VLCPlaylist * currentPlaylist;
32 @implementation VLCController
33 - (void)awakeFromNib
34 {
35     [NSApp setDelegate:self];
36     [detailList setTarget:self];
37     [detailList setDoubleAction:@selector(detailListItemDoubleClicked:)];
38
39     [detailList setDataSource: [[VLCPlaylistDataSource alloc] initWithPlaylist:nil videoView:videoView]];
40     [detailList registerForDraggedTypes: [NSArray arrayWithObjects:NSFilenamesPboardType, NSURLPboardType, nil]];
41
42     [categoryList setTarget:self];
43     [categoryList setAction:@selector(categoryListItemClicked:)];
44     [[[categoryList tableColumns] objectAtIndex:0] setDataCell:[[[VLCCategoryCell alloc] init] autorelease]];
45 }
46
47 - (void)detailListItemDoubleClicked:(id)sender
48 {
49     if( [sender isKindOfClass:[NSTableView class]] && [sender selectedRow] >= 0)
50     {
51         [videoView setPlaylist: currentPlaylist];
52         [videoView playMedia: [[treeController selectedObjects] objectAtIndex: 0]];
53     }
54
55 }
56
57 - (void)categoryListItemClicked:(id)sender
58 {
59     VLCPlaylist * aPlaylist;
60     id selectedItem = [sender itemAtRow:[sender selectedRow]];
61
62     if([selectedItem isKindOfClass:[VLCMediaLibrary class]])
63         aPlaylist = [selectedItem allMedia];
64     else if([selectedItem isKindOfClass:[VLCMediaDiscoverer class]])
65         aPlaylist = [selectedItem playlist];
66     else if([selectedItem isKindOfClass:[VLCPlaylist class]])
67         aPlaylist = [selectedItem flatPlaylist];
68     else
69     {
70         return;
71     }
72     currentPlaylist= aPlaylist;
73     treeController = [[NSArrayController alloc] init]; /* XXX: We leak */
74     
75     //[treeController setAutomaticallyPreparesContent: YES];
76     [[detailList dataSource] release];
77     NSLog(@"currentPlaylist %@", currentPlaylist);
78     [detailList setDataSource: [[VLCPlaylistDataSource alloc] initWithPlaylist:aPlaylist videoView:videoView]];
79     //[treeController setContent: [[VLCMediaLibrary sharedMediaLibrary] allMedia]];
80     [treeController bind:@"contentArray" toObject: aPlaylist
81                     withKeyPath:@"items" options:nil];
82         NSTableColumn *tableColumn;
83     NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
84
85     [bindingOptions setObject:@"metaInformation.title contains[c] $value" forKey:NSPredicateFormatBindingOption];
86     [bindingOptions setObject:@"No Title" forKey:NSDisplayNameBindingOption];
87
88     [detailSearchField bind:@"predicate" toObject: treeController
89                     withKeyPath:@"filterPredicate" options:bindingOptions];
90
91     //[treeController setChildrenKeyPath:@"subitems.items"];
92         
93     [bindingOptions removeAllObjects];
94         [bindingOptions setObject:@"Search" forKey:@"NSNullPlaceholder"];
95                 
96         /* binding for "title" column */
97     tableColumn = [detailList tableColumnWithIdentifier:@"title"];
98         
99         [tableColumn bind:@"value" toObject: treeController
100                   withKeyPath:@"arrangedObjects.metaInformation.title" options:bindingOptions];
101
102 }
103 @end
104
105 @implementation VLCController (NSAppDelegating)
106 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
107 {
108     [self categoryListItemClicked: categoryList];
109 }
110 @end