]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Examples/iPodConverter/Controller.m
Qt: PLSelector: expand root level
[vlc] / projects / macosx / framework / Examples / iPodConverter / Controller.m
1 #import "Controller.h"
2
3
4 /**********************************************************
5  * First off, some value transformer to easily play with
6  * bindings
7  */
8 @interface VLCFloat10000FoldTransformer : NSObject
9 @end
10
11 @implementation VLCFloat10000FoldTransformer
12
13 + (Class)transformedValueClass
14 {
15     return [NSNumber class];
16 }
17
18 + (BOOL)allowsReverseTransformation
19 {
20     return YES;
21 }
22
23 - (id)transformedValue:(id)value
24 {
25     if( !value ) return nil;
26  
27     if(![value respondsToSelector: @selector(floatValue)])
28     {
29         [NSException raise: NSInternalInconsistencyException
30                     format: @"Value (%@) does not respond to -floatValue.",
31         [value class]];
32         return nil;
33     }
34  
35     return [NSNumber numberWithFloat: [value floatValue]*10000.];
36 }
37
38 - (id)reverseTransformedValue:(id)value
39 {
40     if( !value ) return nil;
41  
42     if(![value respondsToSelector: @selector(floatValue)])
43     {
44         [NSException raise: NSInternalInconsistencyException
45                     format: @"Value (%@) does not respond to -floatValue.",
46         [value class]];
47         return nil;
48     }
49  
50     return [NSNumber numberWithFloat: [value floatValue]/10000.];
51 }
52 @end
53
54
55 /**********************************************************
56  * @implementation Controller
57  */
58
59 @implementation Controller
60 - (id)init
61 {
62     if(self = [super init])
63     {
64         VLCFloat10000FoldTransformer *float100fold;
65         float100fold = [[[VLCFloat10000FoldTransformer alloc] init] autorelease];
66         [NSValueTransformer setValueTransformer:(id)float100fold forName:@"Float10000FoldTransformer"];
67         self.media = nil;
68         self.streamSession = nil;
69         selectedStreamOutput = [[NSNumber alloc] initWithInt:0];
70     }
71     return self;
72 }
73
74 @synthesize streamSession;
75 @synthesize selectedStreamOutput;
76
77 - (void)awakeFromNib
78 {
79     [window setShowsResizeIndicator:NO];
80     [NSApp setDelegate: self];
81 }
82
83 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
84 {
85     [VLCLibrary sharedLibrary];
86 }
87
88 - (VLCMedia *)media
89 {
90     return media;
91 }
92
93 - (void)setMedia:(VLCMedia *)newMedia
94 {
95     [media release];
96     media = [newMedia retain];
97     NSRect newFrame = [window frameRectForContentRect:[conversionView frame]];
98     [[window animator] setFrame:NSMakeRect([window frame].origin.x, [window frame].origin.y+NSHeight([window frame])-NSHeight(newFrame), NSWidth(newFrame), NSHeight(newFrame)) display:YES];
99     [[window animator] setContentView:conversionView];
100     [window setMinSize:newFrame.size];
101     [window setMaxSize:NSMakeSize(10000., NSHeight(newFrame))];
102     [window setShowsResizeIndicator:YES];
103 }
104
105 + (NSSet *)keyPathsForValuesAffectingOutputFilePath
106 {
107     return [NSSet setWithObjects:@"media.metaDictionary.title", nil];
108 }
109 - (NSString *)outputFilePath
110 {
111     return [NSString stringWithFormat:[@"~/Movies/iPod Converted/%@.mp4" stringByExpandingTildeInPath],
112                             [[self.media metaDictionary] objectForKey:@"title"]];
113 }
114
115 - (IBAction)convert:(id)sender
116 {
117     self.streamSession = [VLCStreamSession streamSession];
118     if([selectedStreamOutput intValue] == 0)
119     {
120         [self.streamSession setStreamOutput:
121                                     [VLCStreamOutput ipodStreamOutputWithFilePath:
122                                         [self outputFilePath]
123                                     ]];
124     }
125     else
126     {
127         /* This doesn't really is useful for the iPod/iPhone...
128          * But one day we'll figure that out */
129         NSRunAlertPanelRelativeToWindow(@"Warning", @"We can't really stream to the iPod/iPhone for now...\n\nSo we're just streaming using the RTP protocol, and annoucing it via SAP.\n\n(Launch the SAP VLC service discovery module to see it).", @"OK", nil, nil, window);
130         [self.streamSession setStreamOutput:
131                                     [VLCStreamOutput rtpBroadcastStreamOutput]];
132     }
133
134
135     NSLog(@"Using %@", self.streamSession.streamOutput );
136
137     [self.streamSession setMedia:self.media];
138     [self.streamSession startStreaming];
139
140     [openConvertedFileButton setImage:[[NSWorkspace sharedWorkspace] iconForFile:[self outputFilePath]]];
141 }
142
143 - (IBAction)openConvertedFile:(id)sender
144 {
145     [[NSWorkspace sharedWorkspace] openFile:[self outputFilePath]];
146 }
147 - (IBAction)openConvertedEnclosingFolder:(id)sender
148 {
149     [[NSWorkspace sharedWorkspace] openFile:[[self outputFilePath] stringByDeletingLastPathComponent]];
150
151 }
152 @end