libs-gui/Source/NSMovie.m

258 lines
5.8 KiB
Mathematica
Raw Normal View History

/** <title>NSMovie</title>
<abstract>Encapsulate a Quicktime movie</abstract>
Copyright <copy>(C) 2003 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <FredKiefer@gmx.de>
Date: March 2003
2022-03-19 07:10:31 +00:00
Author: Gregory John Casamento <greg.casamento@gmail.com>
Date: March 2022
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSCoder.h>
#import <Foundation/NSData.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSURL.h>
#import "AppKit/NSMovie.h"
#import "AppKit/NSPasteboard.h"
#import "GNUstepGUI/GSVideoSource.h"
#import "GNUstepGUI/GSVideoSink.h"
#import "GSFastEnumeration.h"
/* Class variables and functions for class methods */
2022-03-22 13:23:27 +00:00
static NSArray *__videoSourcePlugIns = nil;
static NSArray *__videoSinkPlugIns = nil;
static inline void _loadNSMoviePlugIns (void)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSAllDomainsMask, YES);
NSMutableArray *all = [NSMutableArray array];
NSMutableArray *sourcePlugins = [NSMutableArray array];
NSMutableArray *sinkPlugins = [NSMutableArray array];
// Collect paths...
FOR_IN(NSString*, path, paths)
{
NSBundle *bundle = [NSBundle bundleWithPath: path];
paths = [bundle pathsForResourcesOfType: @"nsmovie"
inDirectory: @"Bundles"];
[all addObjectsFromArray: paths];
}
END_FOR_IN(paths);
// Check all paths for bundles conforming to the protocol...
FOR_IN(NSString*, path, all)
{
NSBundle *bundle = [NSBundle bundleWithPath: path];
Class plugInClass = [bundle principalClass];
if ([plugInClass conformsToProtocol: @protocol(GSVideoSource)])
{
[sourcePlugins addObject:plugInClass];
}
else if ([plugInClass conformsToProtocol: @protocol(GSVideoSink)])
{
[sinkPlugins addObject:plugInClass];
}
else
{
NSLog (@"Bundle %@ does not conform to GSVideoSource or GSVideoSink",
path);
}
}
END_FOR_IN(all);
2022-03-22 13:23:27 +00:00
__videoSourcePlugIns = [[NSArray alloc] initWithArray: sourcePlugins];
__videoSinkPlugIns = [[NSArray alloc] initWithArray: sinkPlugins];
}
@implementation NSMovie
+ (void) initialize
{
if (self == [NSMovie class])
{
[self setVersion: 2];
_loadNSMoviePlugIns();
}
}
+ (NSArray *) movieUnfilteredFileTypes
{
Class sourceClass;
NSMutableArray *array;
NSEnumerator *enumerator;
array = [NSMutableArray arrayWithCapacity: 10];
2022-03-22 13:23:27 +00:00
FOR_IN(Class, sourceClass, __videoSourcePlugIns)
{
[array addObjectsFromArray: [sourceClass movieUnfilteredFileTypes]];
}
2022-03-22 13:23:27 +00:00
END_FOR_IN(__videoSourcePlugIns);
return array;
}
+ (NSArray *) movieUnfilteredPasteboardTypes
{
return [NSArray arrayWithObjects: @"NSGeneralPboardType", nil];
}
+ (BOOL) canInitWithPasteboard: (NSPasteboard*)pasteboard
{
NSArray *pbTypes = [pasteboard types];
NSArray *myTypes = [self movieUnfilteredPasteboardTypes];
return ([pbTypes firstObjectCommonWithArray: myTypes] != nil);
}
2022-03-19 07:10:31 +00:00
- (id) initWithData: (NSData *)movieData
{
2022-03-19 07:10:31 +00:00
if (movieData == nil)
{
RELEASE(self);
return nil;
}
[super init];
2022-03-19 07:10:31 +00:00
ASSIGN(_movieData, movieData);
return self;
}
- (id) initWithMovie: (void*)movie
{
2022-03-19 07:10:31 +00:00
self = [super init];
if (self != nil)
{
_movie = movie;
}
return self;
}
- (id) initWithURL: (NSURL*)url byReference: (BOOL)byRef
{
NSData* data = [url resourceDataUsingCache: YES];
self = [self initWithData: data];
if (byRef)
{
ASSIGN(_url, url);
}
return self;
}
- (id) initWithPasteboard: (NSPasteboard*)pasteboard
{
NSString *type;
NSData* data;
type = [pasteboard availableTypeFromArray:
[object_getClass(self) movieUnfilteredPasteboardTypes]];
if (type == nil)
{
// NSArray *array = [pasteboard propertyListForType: NSFilenamesPboardType];
// FIXME
data = nil;
}
else
{
data = [pasteboard dataForType: type];
}
if (data == nil)
{
RELEASE(self);
return nil;
}
self = [self initWithData: data];
return self;
}
- (void) dealloc
{
TEST_RELEASE(_url);
2022-03-22 13:23:27 +00:00
TEST_RELEASE(_movieData);
[super dealloc];
}
- (void*) QTMovie
{
2022-03-19 07:10:31 +00:00
return (void*)[_movieData bytes];
}
- (NSURL*) URL
{
return _url;
}
// NSCopying protocoll
- (id) copyWithZone: (NSZone *)zone
{
NSMovie *new = (NSMovie*)NSCopyObject (self, 0, zone);
2022-03-19 07:10:31 +00:00
new->_movie = _movie;
new->_movieData = [_movieData copyWithZone: zone];
new->_url = [_url copyWithZone: zone];
return new;
}
// NSCoding protocoll
- (void) encodeWithCoder: (NSCoder*)aCoder
{
if ([aCoder allowsKeyedCoding])
{
// FIXME
}
else
{
2022-03-19 07:10:31 +00:00
[aCoder encodeObject: _movieData];
[aCoder encodeObject: _url];
}
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
if ([aDecoder allowsKeyedCoding])
{
// FIXME
}
else
{
2022-03-19 07:10:31 +00:00
ASSIGN (_movieData, [aDecoder decodeObject]);
ASSIGN (_url, [aDecoder decodeObject]);
}
return self;
}
@end