home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Examples / NEXTIME / SimplePlayer / Controller.m < prev    next >
Encoding:
Text File  |  1996-01-16  |  5.3 KB  |  191 lines

  1.  
  2.  
  3. #import "Controller.h"
  4. #import "Document.h"
  5. #import "SimplePlayer_Globals.h"
  6.  
  7. static NSString *curDirectory = nil;    /* Directory for open panel */
  8.  
  9. @implementation Controller
  10.  
  11. // Register our defaults
  12. + (void)initialize {
  13.     if (self == [Controller class]) {
  14.         NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
  15.             @"EvenMultiples", @"NTVideoCellSizing",
  16.             nil];
  17.         NSArray *types = [NSArray arrayWithObject: NSFilenamesPboardType];
  18.  
  19.         [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
  20.     [NSApp registerServicesMenuSendTypes:types returnTypes:NULL];
  21.     }
  22.     return;
  23. }
  24.  
  25. + (NTMovieScreenCellSizing)sizingPolicy
  26. {
  27.         NSString * policyString;
  28.  
  29.         policyString = [[NSUserDefaults standardUserDefaults]
  30.                     stringForKey: @"NTVideoCellSizing"];
  31.         if (  policyString == nil
  32.            || [policyString isEqualToString:@"EvenMultiples"] )
  33.         {
  34.             return NTMovieScreenCellPowerOfTwoSizing;
  35.         }
  36.         if ( [policyString isEqualToString:@"Normal"] )
  37.         {
  38.             return NTMovieScreenCellNormalSizing;
  39.         }
  40.         if ( [policyString isEqualToString:@"Continuous"] )
  41.         {
  42.             return NTMovieScreenCellContinuousSizing;
  43.         }
  44.         if ( [policyString isEqualToString:@"MaintainAspectRatio"] )
  45.         {
  46.             return NTMovieScreenCellMaintainAspectRatioSizing;
  47.         }
  48.         return NTMovieScreenCellPowerOfTwoSizing;
  49. }
  50.  
  51. + (void)setSizingPolicy:(NTMovieScreenCellSizing)policy
  52. {
  53.         NSString * policyString;
  54.     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  55.     NSMutableDictionary *domainDict;
  56.     NSString *domain = [[NSProcessInfo processInfo] processName];
  57.         
  58.         switch ( policy )
  59.         {
  60.         case NTMovieScreenCellNormalSizing:
  61.                 policyString = @"Normal";
  62.                 break;
  63.                 default:
  64.             case NTMovieScreenCellPowerOfTwoSizing:
  65.                         policyString = @"EvenMultiples";
  66.                         break;
  67.             case NTMovieScreenCellContinuousSizing:
  68.                         policyString = @"Continuous";
  69.                         break;
  70.             case NTMovieScreenCellMaintainAspectRatioSizing:
  71.                         policyString = @"MaintainAspectRatio";
  72.                         break;
  73.         }
  74.         domainDict = [[[defaults persistentDomainForName:domain] mutableCopy]
  75.                                     autorelease];
  76.         [domainDict setObject:policyString forKey:@"NTVideoCellSizing"];
  77.     [defaults setPersistentDomain:domainDict forName:domain];
  78.         [[NSNotificationCenter defaultCenter]
  79.         postNotificationName: NTResizePolicyChangeNotification
  80.                 object:self];
  81. }
  82.  
  83. - init
  84. {
  85.     self = [super init];
  86.     if ( self == nil )
  87.         return nil;
  88.         return self;
  89. }
  90.  
  91. - (void)dealloc
  92. {
  93.     [[NSUserDefaults standardUserDefaults] synchronize];
  94.     if ( infoPanel )
  95.         [infoPanel release];
  96.     if ( inspectorPanel )
  97.         [inspectorPanel release];
  98.     if ( preferencesPanel )
  99.         [preferencesPanel release];
  100.     [super dealloc];
  101. }
  102.  
  103. - (void)showInfoPanel:sender
  104. {
  105.     if (!infoPanel)
  106.         [NSBundle loadNibNamed:@"InfoPanel.nib" owner:self];
  107.     [infoPanel makeKeyAndOrderFront:self];
  108. }
  109.  
  110. - (void)showInspectorPanel:sender
  111. {
  112.     if (!inspectorPanel)
  113.         [NSBundle loadNibNamed:@"InspectorPanel.nib" owner:self];
  114.     [inspectorPanel makeKeyAndOrderFront:self];
  115. }
  116.  
  117. - (void)showPreferencesPanel:sender
  118. {
  119.     if (!preferencesPanel)
  120.         [NSBundle loadNibNamed:@"PreferencesPanel.nib" owner:self];
  121.     [preferencesPanel makeKeyAndOrderFront:self];
  122.     [videoResizeMatrix selectCellWithTag:[Controller sizingPolicy]];
  123. }
  124.  
  125. - (void)openDocument:sender
  126. {
  127.     Document *newDocument;
  128.     NSOpenPanel *openPanel;
  129.     NSArray *filenames;
  130.     int i, count;
  131.     
  132.     openPanel = [NSOpenPanel openPanel];
  133.     [openPanel setCanChooseFiles:YES];
  134.     [openPanel setAllowsMultipleSelection:YES];
  135.         if ( curDirectory != nil )
  136.             [openPanel setDirectory:curDirectory];
  137.         else
  138.                [openPanel setDirectory:NSHomeDirectory()];
  139.     i = [openPanel runModalForTypes:[NTMovieDocument readableMovieFileTypes]];
  140.     if ( i != NSOKButton )
  141.         return;
  142.     filenames = [openPanel filenames];
  143.     count = [filenames count];
  144.     for ( i = 0; i < count; ++i )
  145.     {
  146.         newDocument = [[Document alloc]
  147.                 initByReferencingFile:[filenames objectAtIndex:i]];
  148.             if ( newDocument == nil )
  149.             {
  150.             continue;
  151.             }
  152.         [newDocument show];
  153.         // We let tke kit keep track of windows and the delegate
  154.         // documents, using
  155.             // [[[NSApplication sharedApplication] mainWindow]
  156.         // to fish out the current document when needed.
  157.  
  158.     }
  159.         // Keep track of the 'current directory'
  160.         [curDirectory autorelease];
  161.         curDirectory = [[[filenames objectAtIndex:(count - 1)]
  162.                        stringByDeletingLastPathComponent] copy];
  163. }
  164.  
  165. - ( void)setDocumentSizingPolicy:sender
  166. {
  167.     [Controller setSizingPolicy:[[videoResizeMatrix selectedCell] tag]];
  168. }
  169.  
  170. /* NSApplication delegate methods */
  171. - (BOOL)application:(NSApplication *)application
  172.            openFile:(NSString *)filename
  173. {
  174.     Document *newDocument;
  175.  
  176.     newDocument = [[Document alloc] initByReferencingFile:filename];
  177.         if ( newDocument == nil )
  178.         {
  179.             return NO;
  180.         }
  181.     [newDocument show];
  182.     // We let tke kit keep track of windows and the delegate
  183.     // documents, using
  184.         // [[[NSApplication sharedApplication] mainWindow]
  185.     // to fish out the current document when needed.
  186.  
  187.         return YES;
  188. }
  189.  
  190. @end
  191.