Spotlight search now works. It's a pretty buggy hack at the moment.
This commit is contained in:
parent
d654c37fe3
commit
28d85a0f42
8 changed files with 1530 additions and 720 deletions
|
@ -11,8 +11,6 @@
|
|||
@class FileOutlineView;
|
||||
@class AppleRemote;
|
||||
@class PlaylistLoader;
|
||||
@class SpotlightWindowController;
|
||||
|
||||
|
||||
@interface AppController : NSObject
|
||||
{
|
||||
|
@ -48,7 +46,7 @@
|
|||
IBOutlet NSMenuItem *showTrackColumn;
|
||||
IBOutlet NSMenuItem *showYearColumn;
|
||||
|
||||
IBOutlet SpotlightWindowController *spotlightWindowController;
|
||||
IBOutlet NSWindowController *spotlightWindowController;
|
||||
|
||||
NDHotKeyEvent *playHotKey;
|
||||
NDHotKeyEvent *prevHotKey;
|
||||
|
|
|
@ -101,7 +101,9 @@
|
|||
17F3BB890CBC565900864489 /* CueSheet.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17F3BB880CBC565100864489 /* CueSheet.bundle */; };
|
||||
17F561400C3BD4F30019975C /* CogAudio.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17F561330C3BD4DC0019975C /* CogAudio.framework */; };
|
||||
17F562390C3BD91B0019975C /* General.preferencePane in Resources */ = {isa = PBXBuildFile; fileRef = 17F5622E0C3BD8FB0019975C /* General.preferencePane */; };
|
||||
569C52E20D5F347800BDBDC9 /* SpotlightWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 569C52E10D5F347800BDBDC9 /* SpotlightWindowController.m */; };
|
||||
567E73780D5F456D006C6486 /* SpotlightSearchController.m in Sources */ = {isa = PBXBuildFile; fileRef = 567E73770D5F456D006C6486 /* SpotlightSearchController.m */; };
|
||||
567E75070D5F71E7006C6486 /* SpotlightTransformers.m in Sources */ = {isa = PBXBuildFile; fileRef = 567E75060D5F71E7006C6486 /* SpotlightTransformers.m */; };
|
||||
567E75750D5F8E20006C6486 /* SpotlightWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 567E75740D5F8E20006C6486 /* SpotlightWindowController.m */; };
|
||||
569C52E60D5F34F500BDBDC9 /* SpotlightPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 569C52E50D5F34F500BDBDC9 /* SpotlightPanel.xib */; };
|
||||
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
||||
|
@ -585,8 +587,12 @@
|
|||
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
||||
32CA4F630368D1EE00C91783 /* Cog_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cog_Prefix.pch; sourceTree = "<group>"; };
|
||||
566D32160D538550004466A5 /* APL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = APL.xcodeproj; path = Plugins/APL/APL.xcodeproj; sourceTree = "<group>"; };
|
||||
569C52E00D5F347800BDBDC9 /* SpotlightWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpotlightWindowController.h; sourceTree = "<group>"; };
|
||||
569C52E10D5F347800BDBDC9 /* SpotlightWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpotlightWindowController.m; sourceTree = "<group>"; };
|
||||
567E73760D5F456D006C6486 /* SpotlightSearchController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpotlightSearchController.h; sourceTree = "<group>"; };
|
||||
567E73770D5F456D006C6486 /* SpotlightSearchController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpotlightSearchController.m; sourceTree = "<group>"; };
|
||||
567E75050D5F71E7006C6486 /* SpotlightTransformers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpotlightTransformers.h; sourceTree = "<group>"; };
|
||||
567E75060D5F71E7006C6486 /* SpotlightTransformers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpotlightTransformers.m; sourceTree = "<group>"; };
|
||||
567E75730D5F8E20006C6486 /* SpotlightWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpotlightWindowController.h; sourceTree = "<group>"; };
|
||||
567E75740D5F8E20006C6486 /* SpotlightWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpotlightWindowController.m; sourceTree = "<group>"; };
|
||||
569C52E50D5F34F500BDBDC9 /* SpotlightPanel.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SpotlightPanel.xib; sourceTree = "<group>"; };
|
||||
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
|
||||
8E07AAEE0AAC910500A4B32F /* SS_PreferencePaneProtocol.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SS_PreferencePaneProtocol.h; path = Preferences/SS_PreferencePaneProtocol.h; sourceTree = "<group>"; };
|
||||
|
@ -1076,8 +1082,12 @@
|
|||
569C52C50D5F2BD500BDBDC9 /* Spotlight */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
569C52E00D5F347800BDBDC9 /* SpotlightWindowController.h */,
|
||||
569C52E10D5F347800BDBDC9 /* SpotlightWindowController.m */,
|
||||
567E73760D5F456D006C6486 /* SpotlightSearchController.h */,
|
||||
567E73770D5F456D006C6486 /* SpotlightSearchController.m */,
|
||||
567E75050D5F71E7006C6486 /* SpotlightTransformers.h */,
|
||||
567E75060D5F71E7006C6486 /* SpotlightTransformers.m */,
|
||||
567E75730D5F8E20006C6486 /* SpotlightWindowController.h */,
|
||||
567E75740D5F8E20006C6486 /* SpotlightWindowController.m */,
|
||||
);
|
||||
name = Spotlight;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1609,7 +1619,9 @@
|
|||
178BAB9A0CD4E1B700B33D47 /* GCWindowMenu.m in Sources */,
|
||||
178BAB9B0CD4E1B700B33D47 /* PopupButton.m in Sources */,
|
||||
17BBE5BC0CD95CFA00258F7A /* InvertedToolbarWindow.m in Sources */,
|
||||
569C52E20D5F347800BDBDC9 /* SpotlightWindowController.m in Sources */,
|
||||
567E73780D5F456D006C6486 /* SpotlightSearchController.m in Sources */,
|
||||
567E75070D5F71E7006C6486 /* SpotlightTransformers.m in Sources */,
|
||||
567E75750D5F8E20006C6486 /* SpotlightWindowController.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
2060
SpotlightPanel.xib
2060
SpotlightPanel.xib
File diff suppressed because it is too large
Load diff
27
SpotlightSearchController.h
Normal file
27
SpotlightSearchController.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// SpotlightSearchController.h
|
||||
// Cog
|
||||
//
|
||||
// Created by Matthew Grinshpun on 10/02/08.
|
||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class SpotlightWindowController;
|
||||
|
||||
@interface SpotlightSearchController : NSObject {
|
||||
IBOutlet NSArrayController *playlistController;
|
||||
IBOutlet SpotlightWindowController *spotlightWindowController;
|
||||
NSMetadataQuery *query;
|
||||
NSString *searchString;
|
||||
}
|
||||
|
||||
- (IBAction)addToPlaylist:(id)sender;
|
||||
|
||||
- (void)performSearch;
|
||||
|
||||
@property(retain) NSMetadataQuery *query;
|
||||
@property(copy) NSString *searchString;
|
||||
|
||||
@end
|
90
SpotlightSearchController.m
Normal file
90
SpotlightSearchController.m
Normal file
|
@ -0,0 +1,90 @@
|
|||
//
|
||||
// SpotlightSearchController.m
|
||||
// Cog
|
||||
//
|
||||
// Created by Matthew Grinshpun on 10/02/08.
|
||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SpotlightSearchController.h"
|
||||
#import "SpotlightWindowController.h"
|
||||
#import "PlaylistLoader.h"
|
||||
|
||||
// Store a class predicate for searching for music
|
||||
static NSPredicate * musicOnlyPredicate = nil;
|
||||
|
||||
@implementation SpotlightSearchController
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
musicOnlyPredicate = [[NSPredicate predicateWithFormat:
|
||||
@"kMDItemContentTypeTree==\'public.audio\'"] retain];
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
self.query = [[NSMetadataQuery alloc] init];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)performSearch
|
||||
{
|
||||
unsigned options = (NSCaseInsensitivePredicateOption|
|
||||
NSDiacriticInsensitivePredicateOption);
|
||||
NSString *processedKey = [NSString stringWithFormat: @"*%@*", self.searchString];
|
||||
|
||||
NSPredicate *searchPredicate = [NSComparisonPredicate
|
||||
predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"*"]
|
||||
rightExpression:[NSExpression expressionForConstantValue:processedKey]
|
||||
modifier:NSDirectPredicateModifier
|
||||
type:NSLikePredicateOperatorType
|
||||
options:options];
|
||||
|
||||
// spotlightPredicate, which is what will finally be used for the spotlight search
|
||||
// is the union of the bound NSSearchField and the static musicOnlyPredicate
|
||||
|
||||
NSPredicate *spotlightPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:
|
||||
[NSArray arrayWithObjects: musicOnlyPredicate,
|
||||
searchPredicate,
|
||||
nil]];
|
||||
if([self.query isStarted])
|
||||
[self.query stopQuery];
|
||||
self.query.predicate = spotlightPredicate;
|
||||
[self.query startQuery];
|
||||
NSLog(@"Started query: %@", [self.query.predicate description], [[self.query class]description]);
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self.query stopQuery];
|
||||
[self.query release];
|
||||
[self.searchString release];
|
||||
[musicOnlyPredicate release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (IBAction)addToPlaylist:(id)sender;
|
||||
{
|
||||
NSArray *songPaths = [[playlistController selectedObjects]valueForKey:@"kMDItemPath"];
|
||||
NSMutableArray *songURLs = [NSMutableArray arrayWithCapacity:[songPaths count]];
|
||||
for (NSString *songPath in songPaths) {
|
||||
[songURLs addObject:[NSURL fileURLWithPath:songPath]];
|
||||
}
|
||||
[spotlightWindowController.playlistLoader addURLs:songURLs sort:NO];
|
||||
}
|
||||
|
||||
@synthesize query;
|
||||
|
||||
@synthesize searchString;
|
||||
- (void)setSearchString:(NSString *)aString
|
||||
{
|
||||
if (searchString != aString) {
|
||||
searchString = [aString copy];
|
||||
[self performSearch];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// SpotlightWindowController.h
|
||||
// SpotlightTransformers.h
|
||||
// Cog
|
||||
//
|
||||
// Created by Matthew Grinshpun on 10/02/08.
|
||||
|
@ -9,7 +9,7 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
@interface SpotlightWindowController : NSWindowController {
|
||||
@interface SpotlightArtistTransformer : NSValueTransformer{
|
||||
|
||||
}
|
||||
|
27
SpotlightTransformers.m
Normal file
27
SpotlightTransformers.m
Normal file
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// SpotlightTransformers.m
|
||||
// Cog
|
||||
//
|
||||
// Created by Matthew Grinshpun on 10/02/08.
|
||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SpotlightTransformers.h"
|
||||
|
||||
// kMDItemAuthor is an array of values.
|
||||
// For music, the first value is the artist
|
||||
@implementation SpotlightArtistTransformer
|
||||
|
||||
+ (Class)transformedValueClass {
|
||||
return [NSString class];
|
||||
}
|
||||
|
||||
- (id)transformedValue:(id)value {
|
||||
NSString * artistString = @"";
|
||||
if (value != nil) {
|
||||
artistString = [NSString stringWithString:
|
||||
(NSString *)[value objectAtIndex:0]];
|
||||
}
|
||||
return artistString;
|
||||
}
|
||||
@end
|
|
@ -1,14 +0,0 @@
|
|||
//
|
||||
// SpotlightWindowController.m
|
||||
// Cog
|
||||
//
|
||||
// Created by Matthew Grinshpun on 10/02/08.
|
||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SpotlightWindowController.h"
|
||||
|
||||
|
||||
@implementation SpotlightWindowController
|
||||
|
||||
@end
|
Loading…
Reference in a new issue