Controller.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #import "Controller.h"
  2. /**********************************************************
  3. * First off, some value transformer to easily play with
  4. * bindings
  5. */
  6. @interface VLCFloat10000FoldTransformer : NSObject
  7. @end
  8. @implementation VLCFloat10000FoldTransformer
  9. + (Class)transformedValueClass
  10. {
  11. return [NSNumber class];
  12. }
  13. + (BOOL)allowsReverseTransformation
  14. {
  15. return YES;
  16. }
  17. - (id)transformedValue:(id)value
  18. {
  19. if( !value ) return nil;
  20. if(![value respondsToSelector: @selector(floatValue)])
  21. {
  22. [NSException raise: NSInternalInconsistencyException
  23. format: @"Value (%@) does not respond to -floatValue.",
  24. [value class]];
  25. return nil;
  26. }
  27. return [NSNumber numberWithFloat: [value floatValue]*10000.];
  28. }
  29. - (id)reverseTransformedValue:(id)value
  30. {
  31. if( !value ) return nil;
  32. if(![value respondsToSelector: @selector(floatValue)])
  33. {
  34. [NSException raise: NSInternalInconsistencyException
  35. format: @"Value (%@) does not respond to -floatValue.",
  36. [value class]];
  37. return nil;
  38. }
  39. return [NSNumber numberWithFloat: [value floatValue]/10000.];
  40. }
  41. @end
  42. /**********************************************************
  43. * @implementation Controller
  44. */
  45. @implementation Controller
  46. - (id)init
  47. {
  48. if(self = [super init])
  49. {
  50. VLCFloat10000FoldTransformer *float100fold;
  51. float100fold = [[[VLCFloat10000FoldTransformer alloc] init] autorelease];
  52. [NSValueTransformer setValueTransformer:(id)float100fold forName:@"Float10000FoldTransformer"];
  53. self.media = nil;
  54. self.streamSession = nil;
  55. selectedStreamOutput = [[NSNumber alloc] initWithInt:0];
  56. }
  57. return self;
  58. }
  59. @synthesize streamSession;
  60. @synthesize selectedStreamOutput;
  61. - (void)awakeFromNib
  62. {
  63. [window setShowsResizeIndicator:NO];
  64. [NSApp setDelegate: self];
  65. }
  66. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  67. {
  68. [VLCLibrary sharedLibrary];
  69. }
  70. - (VLCMedia *)media
  71. {
  72. return media;
  73. }
  74. - (void)setMedia:(VLCMedia *)newMedia
  75. {
  76. [media release];
  77. media = [newMedia retain];
  78. NSRect newFrame = [window frameRectForContentRect:[conversionView frame]];
  79. [[window animator] setFrame:NSMakeRect([window frame].origin.x, [window frame].origin.y+NSHeight([window frame])-NSHeight(newFrame), NSWidth(newFrame), NSHeight(newFrame)) display:YES];
  80. [[window animator] setContentView:conversionView];
  81. [window setMinSize:newFrame.size];
  82. [window setMaxSize:NSMakeSize(10000., NSHeight(newFrame))];
  83. [window setShowsResizeIndicator:YES];
  84. }
  85. + (NSSet *)keyPathsForValuesAffectingOutputFilePath
  86. {
  87. return [NSSet setWithObjects:@"media.metaDictionary.title", nil];
  88. }
  89. - (NSString *)outputFilePath
  90. {
  91. return [NSString stringWithFormat:[@"~/Movies/iPod Converted/%@.mp4" stringByExpandingTildeInPath],
  92. [[self.media metaDictionary] objectForKey:@"title"]];
  93. }
  94. - (IBAction)convert:(id)sender
  95. {
  96. self.streamSession = [VLCStreamSession streamSession];
  97. if([selectedStreamOutput intValue] == 0)
  98. {
  99. [self.streamSession setStreamOutput:
  100. [VLCStreamOutput ipodStreamOutputWithFilePath:
  101. [self outputFilePath]
  102. ]];
  103. }
  104. else
  105. {
  106. /* This doesn't really is useful for the iPod/iPhone...
  107. * But one day we'll figure that out */
  108. 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);
  109. [self.streamSession setStreamOutput:
  110. [VLCStreamOutput rtpBroadcastStreamOutput]];
  111. }
  112. NSLog(@"Using %@", self.streamSession.streamOutput );
  113. [self.streamSession setMedia:self.media];
  114. [self.streamSession startStreaming];
  115. [openConvertedFileButton setImage:[[NSWorkspace sharedWorkspace] iconForFile:[self outputFilePath]]];
  116. }
  117. - (IBAction)openConvertedFile:(id)sender
  118. {
  119. [[NSWorkspace sharedWorkspace] openFile:[self outputFilePath]];
  120. }
  121. - (IBAction)openConvertedEnclosingFolder:(id)sender
  122. {
  123. [[NSWorkspace sharedWorkspace] openFile:[[self outputFilePath] stringByDeletingLastPathComponent]];
  124. }
  125. @end