write out bookmark items into a metadata folder so they can be parsed by

spotlight on 10.4
This commit is contained in:
pinkerton%aol.net 2005-05-06 02:54:10 +00:00
Родитель b05070119d
Коммит 64195f5882
7 изменённых файлов: 110 добавлений и 5 удалений

Просмотреть файл

@ -204,4 +204,8 @@ typedef enum EBookmarkOpenBehavior
+(NSString*)urlStringFromWebloc:(NSString*)inFile;
+(NSString*)urlStringFromIEURLFile:(NSString*)inFile;
// OS feature checks
+ (BOOL)supportsSpotlight;
+ (BOOL)supportsBonjour;
@end

Просмотреть файл

@ -121,6 +121,48 @@ const int kReuseWindowOnAE = 2;
@implementation MainController
//
// +isRunningOnTiger
//
// returns YES if we're on 10.4 or better
//
+ (BOOL)isTigerOrHigher
{
BOOL runningOnTiger = NO;
long version = 0;
::Gestalt(gestaltSystemVersion, &version);
if (version >= 0x00001040)
runningOnTiger = YES;
return runningOnTiger;
}
//
// +supportsSpotlight
//
// returns YES if we're running on a machine that supports spotlight (tiger or higher)
//
+ (BOOL)supportsSpotlight
{
return [self isTigerOrHigher];
}
//
// +supportsBonjour
//
// returns YES if we're running on a machine that supports bonjour (formerly rendezvous, 10.2
// or higher)
//
+ (BOOL)supportsBonjour
{
// are we on 10.2.3 or higher? The DNS resolution stuff is broken before 10.2.3
BOOL supportsBonjour = NO;
long version = 0;
::Gestalt(gestaltSystemVersion, &version);
if (version >= 0x00001023)
supportsBonjour = YES;
return supportsBonjour;
}
-(id)init
{
if ( (self = [super init]) ) {
@ -252,10 +294,7 @@ const int kReuseWindowOnAE = 2;
BOOL doingRendezvous = NO;
if ([pm getBooleanPref:"chimera.enable_rendezvous" withSuccess:&success]) {
// are we on 10.2.3 or higher? The DNS resolution stuff is broken before 10.2.3
long systemVersion;
OSErr err = ::Gestalt(gestaltSystemVersion, &systemVersion);
if ((err == noErr) && (systemVersion >= 0x00001023)) {
if ([MainController supportsBonjour]) {
[notificationCenter addObserver:self selector:@selector(availableServicesChanged:) name:NetworkServicesAvailableServicesChanged object:nil];
[notificationCenter addObserver:self selector:@selector(serviceResolved:) name:NetworkServicesResolutionSuccess object:nil];
[notificationCenter addObserver:self selector:@selector(serviceResolutionFailed:) name:NetworkServicesResolutionFailure object:nil];

Просмотреть файл

@ -303,6 +303,24 @@ NSString* const URLLoadSuccessKey = @"url_bool";
return YES;
}
//
// -writeBookmarksMetaDatatoPath:
//
// Writes out the meta data for this bookmark to a file with the name of this item's UUID
// in the given path. Using the suffix "webbookmark" allows us to pick up on the Spotlight
// importer already on Tiger for Safari.
//
-(void)writeBookmarksMetadataToPath:(NSString*)inPath
{
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
mTitle, @"Name",
mURL, @"URL",
nil];
NSString* file = [self UUID];
NSString* path = [NSString stringWithFormat:@"%@/%@.webbookmark", inPath, file];
[dict writeToFile:path atomically:YES];
}
// for plist in native format
-(NSDictionary *)writeNativeDictionary
{

Просмотреть файл

@ -924,6 +924,22 @@ NSString* const BookmarkFolderDockMenuChangeNotificaton = @"bf_dmc";
return noErr;
}
//
// -writeBookmarksMetadataToPath:
//
// Recursively tells each of its children to write out its spotlight metadata at the
// given path. Folders themselves aren't written to the metadata store.
//
-(void)writeBookmarksMetadataToPath:(NSString*)inPath
{
if (![self isSmartFolder]) {
id item;
NSEnumerator* enumerator = [mChildArray objectEnumerator];
// do it for each child
while ((item = [enumerator nextObject]))
[item writeBookmarksMetadataToPath:inPath];
}
}
-(NSDictionary *)writeNativeDictionary
{

Просмотреть файл

@ -98,6 +98,7 @@ enum
-(BOOL) readSafariDictionary:(NSDictionary *)aDict;
-(BOOL) readCaminoXML:(CFXMLTreeRef)aTreeRef;
-(void)writeBookmarksMetadataToPath:(NSString*)inPath;
-(NSDictionary *)writeNativeDictionary;
-(NSDictionary *)writeSafariDictionary;
-(NSString *)writeHTML:(unsigned)aPad;

Просмотреть файл

@ -315,6 +315,11 @@ static BOOL gSuppressAllUpdates = NO;
return NO;
}
-(void)writeBookmarksMetadataToPath:(NSString*)inPath
{
// do nothing, subclasses must override
}
-(NSDictionary *)writeNativeDictionary
{
return [NSDictionary dictionary];

Просмотреть файл

@ -61,6 +61,7 @@
- (void)delayedStartupItems;
- (void)writeBookmarks:(NSNotification *)note;
- (BookmarkFolder *)findDockMenuFolderInFolder:(BookmarkFolder *)aFolder;
- (void)writeBookmarksMetadataForSpotlight;
@end
@implementation BookmarkManager
@ -572,6 +573,28 @@ static unsigned gFirstUserCollection = 0;
- (void)writeBookmarks:(NSNotification *)note
{
[self writePropertyListFile:mPathToBookmarkFile];
[self writeBookmarksMetadataForSpotlight];
}
//
// -writeBookmarksMetadataForSpotlight
//
// If we're running on Tiger, write out a flat list of all bookmarks in the caches folder
// so that Spotlight can parse them. We don't need to write our own metadata plugin, we piggyback
// the one that Safari uses. It launches the default browser when selected. This is a fairly
// naive implementation, writing out everything in one go.
//
- (void)writeBookmarksMetadataForSpotlight
{
if ([MainController supportsSpotlight]) {
NSString* metaDataPath = [@"~/Library/Caches/Metadata/Camino" stringByExpandingTildeInPath];
[[NSFileManager defaultManager] removeFileAtPath:metaDataPath handler:nil];
[[NSFileManager defaultManager] createDirectoryAtPath:metaDataPath attributes:nil];
// write the bookmark menu and toolbar only.
[[self bookmarkMenuFolder] writeBookmarksMetadataToPath:metaDataPath];
[[self toolbarFolder] writeBookmarksMetadataToPath:metaDataPath];
}
}
#pragma mark -
@ -1076,5 +1099,4 @@ static unsigned gFirstUserCollection = 0;
NSLog(@"writePropertyList: Failed to write file %@",pathToFile);
}
@end