Controller.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*****************************************************************************
  2. * Copyright (C) 2007-2012 Pierre d'Herbemont and VideoLAN
  3. *
  4. * Authors: Pierre d'Herbemont
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  19. *****************************************************************************/
  20. #import "Controller.h"
  21. /**********************************************************
  22. * First off, some value transformer to easily play with
  23. * bindings
  24. */
  25. @interface VLCFloat10000FoldTransformer : NSObject
  26. @end
  27. @implementation VLCFloat10000FoldTransformer
  28. + (Class)transformedValueClass
  29. {
  30. return [NSNumber class];
  31. }
  32. + (BOOL)allowsReverseTransformation
  33. {
  34. return YES;
  35. }
  36. - (id)transformedValue:(id)value
  37. {
  38. if( !value ) return nil;
  39. if(![value respondsToSelector: @selector(floatValue)])
  40. {
  41. [NSException raise: NSInternalInconsistencyException
  42. format: @"Value (%@) does not respond to -floatValue.",
  43. [value class]];
  44. return nil;
  45. }
  46. return [NSNumber numberWithFloat: [value floatValue]*10000.];
  47. }
  48. - (id)reverseTransformedValue:(id)value
  49. {
  50. if( !value ) return nil;
  51. if(![value respondsToSelector: @selector(floatValue)])
  52. {
  53. [NSException raise: NSInternalInconsistencyException
  54. format: @"Value (%@) does not respond to -floatValue.",
  55. [value class]];
  56. return nil;
  57. }
  58. return [NSNumber numberWithFloat: [value floatValue]/10000.];
  59. }
  60. @end
  61. /**********************************************************
  62. * @implementation Controller
  63. */
  64. @implementation Controller
  65. - (id)init
  66. {
  67. if(self = [super init])
  68. {
  69. VLCFloat10000FoldTransformer *float100fold;
  70. float100fold = [[[VLCFloat10000FoldTransformer alloc] init] autorelease];
  71. [NSValueTransformer setValueTransformer:(id)float100fold forName:@"Float10000FoldTransformer"];
  72. self.media = nil;
  73. self.streamSession = nil;
  74. selectedStreamOutput = [[NSNumber alloc] initWithInt:0];
  75. }
  76. return self;
  77. }
  78. @synthesize streamSession;
  79. @synthesize selectedStreamOutput;
  80. - (void)awakeFromNib
  81. {
  82. [window setShowsResizeIndicator:NO];
  83. [NSApp setDelegate: self];
  84. }
  85. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  86. {
  87. [VLCLibrary sharedLibrary];
  88. }
  89. - (VLCMedia *)media
  90. {
  91. return media;
  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. + (NSSet *)keyPathsForValuesAffectingOutputFilePath
  105. {
  106. return [NSSet setWithObjects:@"media.metaDictionary.title", nil];
  107. }
  108. - (NSString *)outputFilePath
  109. {
  110. return [NSString stringWithFormat:[@"~/Movies/%@.mp4" stringByExpandingTildeInPath],
  111. [[[self.media metaDictionary] objectForKey:@"title"] stringByDeletingPathExtension]];
  112. }
  113. - (IBAction)convert:(id)sender
  114. {
  115. self.streamSession = [VLCStreamSession streamSession];
  116. if([selectedStreamOutput intValue] == 0)
  117. {
  118. [self.streamSession setStreamOutput:
  119. [VLCStreamOutput ipodStreamOutputWithFilePath:
  120. [self outputFilePath]
  121. ]];
  122. }
  123. else
  124. {
  125. /* This doesn't really is useful for the iPod/iPhone...
  126. * But one day we'll figure that out */
  127. 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);
  128. [self.streamSession setStreamOutput:
  129. [VLCStreamOutput rtpBroadcastStreamOutput]];
  130. }
  131. NSLog(@"Using %@", self.streamSession.streamOutput );
  132. [self.streamSession setMedia:self.media];
  133. [self.streamSession startStreaming];
  134. [openConvertedFileButton setImage:[[NSWorkspace sharedWorkspace] iconForFile:[self outputFilePath]]];
  135. }
  136. - (IBAction)openConvertedFile:(id)sender
  137. {
  138. [[NSWorkspace sharedWorkspace] openFile:[self outputFilePath]];
  139. }
  140. - (IBAction)openConvertedEnclosingFolder:(id)sender
  141. {
  142. [[NSWorkspace sharedWorkspace] openFile:[[self outputFilePath] stringByDeletingLastPathComponent]];
  143. }
  144. @end