Media file menu item, directory scanning

This commit is contained in:
Matthias Neeracher 2011-08-10 18:46:30 +02:00
parent abbc405b6f
commit 269388a545
5 changed files with 149 additions and 3406 deletions

View File

@ -22,6 +22,7 @@
950BB69D13F2C6B400D8E669 /* MAAnno.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB69C13F2C6B400D8E669 /* MAAnno.mm */; }; 950BB69D13F2C6B400D8E669 /* MAAnno.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB69C13F2C6B400D8E669 /* MAAnno.mm */; };
950BB6A013F2C6B400D8E669 /* MAMedia.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB69F13F2C6B400D8E669 /* MAMedia.mm */; }; 950BB6A013F2C6B400D8E669 /* MAMedia.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB69F13F2C6B400D8E669 /* MAMedia.mm */; };
950BB6A313F2C6B400D8E669 /* MATagDescription.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB6A213F2C6B400D8E669 /* MATagDescription.mm */; }; 950BB6A313F2C6B400D8E669 /* MATagDescription.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB6A213F2C6B400D8E669 /* MATagDescription.mm */; };
950BB78613F2D95500D8E669 /* MADocWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB78513F2D95500D8E669 /* MADocWindow.mm */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
@ -49,6 +50,8 @@
950BB69F13F2C6B400D8E669 /* MAMedia.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MAMedia.mm; sourceTree = "<group>"; }; 950BB69F13F2C6B400D8E669 /* MAMedia.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MAMedia.mm; sourceTree = "<group>"; };
950BB6A113F2C6B400D8E669 /* MATagDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MATagDescription.h; sourceTree = "<group>"; }; 950BB6A113F2C6B400D8E669 /* MATagDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MATagDescription.h; sourceTree = "<group>"; };
950BB6A213F2C6B400D8E669 /* MATagDescription.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MATagDescription.mm; sourceTree = "<group>"; }; 950BB6A213F2C6B400D8E669 /* MATagDescription.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MATagDescription.mm; sourceTree = "<group>"; };
950BB78413F2D95500D8E669 /* MADocWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MADocWindow.h; sourceTree = "<group>"; };
950BB78513F2D95500D8E669 /* MADocWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MADocWindow.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -108,6 +111,8 @@
950BB69513F2C6B300D8E669 /* MAFolder.h */, 950BB69513F2C6B300D8E669 /* MAFolder.h */,
950BB69613F2C6B300D8E669 /* MAFolder.mm */, 950BB69613F2C6B300D8E669 /* MAFolder.mm */,
950BB67F13F1F26200D8E669 /* MADocument.xib */, 950BB67F13F1F26200D8E669 /* MADocument.xib */,
950BB78413F2D95500D8E669 /* MADocWindow.h */,
950BB78513F2D95500D8E669 /* MADocWindow.mm */,
950BB68213F1F26200D8E669 /* MainMenu.xib */, 950BB68213F1F26200D8E669 /* MainMenu.xib */,
950BB68513F1F26200D8E669 /* MADocument.xcdatamodeld */, 950BB68513F1F26200D8E669 /* MADocument.xcdatamodeld */,
950BB67113F1F26200D8E669 /* Supporting Files */, 950BB67113F1F26200D8E669 /* Supporting Files */,
@ -199,6 +204,7 @@
950BB69D13F2C6B400D8E669 /* MAAnno.mm in Sources */, 950BB69D13F2C6B400D8E669 /* MAAnno.mm in Sources */,
950BB6A013F2C6B400D8E669 /* MAMedia.mm in Sources */, 950BB6A013F2C6B400D8E669 /* MAMedia.mm in Sources */,
950BB6A313F2C6B400D8E669 /* MATagDescription.mm in Sources */, 950BB6A313F2C6B400D8E669 /* MATagDescription.mm in Sources */,
950BB78613F2D95500D8E669 /* MADocWindow.mm in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@ -8,6 +8,10 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@interface MADocWindow : NSWindowController @interface MADocWindow : NSWindowController {
}
- (IBAction)addMediaFiles:(id)sender;
- (void)addMedia:(NSArray *)urls;
@end @end

View File

@ -7,6 +7,7 @@
// //
#import "MADocWindow.h" #import "MADocWindow.h"
#import <QTKit/QTKit.h>
@implementation MADocWindow @implementation MADocWindow
@ -27,4 +28,55 @@
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
} }
#pragma mark Media management
- (IBAction)addMediaFiles:(id)sender
{
NSOpenPanel * openPanel = [NSOpenPanel openPanel];
[openPanel setAllowedFileTypes:[QTMovie movieFileTypes:QTIncludeCommonTypes]];
[openPanel setAllowsMultipleSelection:YES];
[openPanel setCanChooseDirectories:YES];
[openPanel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton)
[self addMedia:[openPanel URLs]];
}];
}
- (void)addMediaTypes:(NSArray *)types inDirectory:(NSURL *)dir toList:(NSMutableArray *)urls
{
NSFileManager * fm = [NSFileManager defaultManager];
NSDirectoryEnumerator * dirEnum = [fm enumeratorAtURL:dir
includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLNameKey, NSURLIsDirectoryKey, nil]
options:NSDirectoryEnumerationSkipsHiddenFiles errorHandler:nil];
for (NSURL * url in dirEnum) {
NSNumber * isDirectory;
[url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:NULL];
if (![isDirectory boolValue]) {
NSString * ext = [url pathExtension];
if ([types indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return ![obj caseInsensitiveCompare:ext];
}] != NSNotFound
)
[urls addObject:url];
}
}
}
- (void)addMedia:(NSArray *)urls
{
NSMutableArray * expandedURLs = [NSMutableArray array];
for (NSURL * url in urls) {
if ([url isFileURL]) {
NSNumber * isDirectory;
[url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil];
if ([isDirectory boolValue]) {
[self addMediaTypes:[QTMovie movieFileTypes:QTIncludeCommonTypes] inDirectory:url toList:expandedURLs];
continue;
}
}
[expandedURLs addObject:url];
}
NSLog(@"Adding %@\n", expandedURLs);
}
@end @end

View File

@ -7,6 +7,7 @@
// //
#import "MADocument.h" #import "MADocument.h"
#import "MADocWindow.h"
#import "MAFolder.h" #import "MAFolder.h"
#pragma mark NSPersistentDocument file URL hook #pragma mark NSPersistentDocument file URL hook
@ -71,6 +72,13 @@ static NSString *StoreFileName = @"MediannoDB.sql";
return @"MADocument"; return @"MADocument";
} }
- (void)makeWindowControllers
{
MADocWindow * windowController = [[MADocWindow alloc] initWithWindowNibName:[self windowNibName]];
[self addWindowController:windowController];
[windowController release];
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController - (void)windowControllerDidLoadNib:(NSWindowController *)aController
{ {
[super windowControllerDidLoadNib:aController]; [super windowControllerDidLoadNib:aController];

File diff suppressed because it is too large Load Diff