add support for importing Omniweb 5 bookmarks (bug 258902) sr=pinkerton

git-svn-id: svn://10.0.0.236/trunk@165241 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
joshmoz%gmail.com
2004-11-11 00:32:33 +00:00
parent e54792eafa
commit a2ebbb8fec
2 changed files with 97 additions and 14 deletions

View File

@@ -47,8 +47,12 @@
@interface BookmarkImportDlgController (Private)
-(void) tryAddImportFromBrowser: (NSString *) aBrowserName withBookmarkPath: (NSString *) aPath;
-(void) tryOmniWeb5Import;
-(void) buildButtonForBrowser:(NSString *) aBrowserName withObject:(id)anObject;
-(NSString *) getSaltedBookmarkPathForProfile: (NSString *) aPath;
-(void) beginImportFrom:(NSString *) aPath intoFolder:(BookmarkFolder *) aFolder;
-(void) beginOmniWeb5ImportFrom:(NSArray *)anArray intoFolder:(BookmarkFolder *)aFolder;
-(void) finishImport:(BOOL)success fromFile:(NSString *)aFile;
@end
@@ -72,7 +76,9 @@
[self tryAddImportFromBrowser:@"iCab" withBookmarkPath:@"~/Library/Preferences/iCab Preferences/Hotlist.html"];
[self tryAddImportFromBrowser:@"Opera" withBookmarkPath:@"~/Library/Preferences/Opera Preferences/Bookmarks"];
[self tryAddImportFromBrowser:@"Omniweb" withBookmarkPath:@"~/Library/Application Support/Omniweb/Bookmarks.html"];
[self tryAddImportFromBrowser:@"OmniWeb 4" withBookmarkPath:@"~/Library/Application Support/Omniweb/Bookmarks.html"];
// Stupid OmniWeb 5 has between 0 and 3 bookmark files. Dumb.
[self tryOmniWeb5Import];
[self tryAddImportFromBrowser:@"Internet Explorer" withBookmarkPath:@"~/Library/Preferences/Explorer/Favorites.html"];
[self tryAddImportFromBrowser:@"Safari" withBookmarkPath:@"~/Library/Safari/Bookmarks.plist"];
@@ -100,15 +106,35 @@
NSFileManager *fm = [NSFileManager defaultManager];
NSString *fullPathString = [aPath stringByStandardizingPath];
if ([fm fileExistsAtPath:fullPathString]) {
[mBrowserListButton insertItemWithTitle:aBrowserName atIndex:0];
NSMenuItem *browserItem = [mBrowserListButton itemAtIndex:0];
[browserItem setTarget:self];
[browserItem setAction:@selector(nullAction:)];
[browserItem setRepresentedObject:fullPathString];
[self buildButtonForBrowser:aBrowserName withObject:aPath];
}
}
// Given a Mozilla-like profile, returns the bookmarss.html file in the salt directory,
// Stupid OmniWeb 5
-(void) tryOmniWeb5Import
{
NSArray *owFiles = [NSArray arrayWithObjects:
@"~/Library/Application Support/OmniWeb 5/Bookmarks.html",
@"~/Library/Application Support/OmniWeb 5/Favorites.html",
@"~/Library/Application Support/OmniWeb 5/Published.html",
nil];
NSMutableArray *haveFiles = [NSMutableArray array];
NSEnumerator *enumerator = [owFiles objectEnumerator];
NSFileManager *fm = [NSFileManager defaultManager];
NSString *aPath, *fullPathString;
while ( (aPath = [enumerator nextObject]) ) {
fullPathString = [aPath stringByStandardizingPath];
if ([fm fileExistsAtPath:fullPathString]) {
[haveFiles addObject:fullPathString];
}
}
if ([haveFiles count] > 0)
{
[self buildButtonForBrowser:@"OmniWeb 5" withObject:haveFiles];
}
}
// Given a Mozilla-like profile, returns the bookmarks.html file in the salt directory,
// or nil if no salt directory is found
-(NSString *) getSaltedBookmarkPathForProfile: (NSString *) aPath
{
@@ -126,6 +152,15 @@
return nil;
}
-(void) buildButtonForBrowser:(NSString *) aBrowserName withObject:(id)aThingy
{
[mBrowserListButton insertItemWithTitle:aBrowserName atIndex:0];
NSMenuItem *browserItem = [mBrowserListButton itemAtIndex:0];
[browserItem setTarget:self];
[browserItem setAction:@selector(nullAction:)];
[browserItem setRepresentedObject:aThingy];
}
// keeps browsers turned on
-(IBAction) nullAction:(id)aSender
{
@@ -148,7 +183,13 @@
titleString = [[NSString alloc] initWithFormat:NSLocalizedString(@"Imported %@ Bookmarks",@"Imported %@ Bookmarks"),[selectedItem title]];
[importFolder setTitle:titleString];
[titleString release];
[self beginImportFrom:[selectedItem representedObject] intoFolder:importFolder];
// Stupid OmniWeb 5 gets its own import function
if ( [[selectedItem title] isEqualToString:@"OmniWeb 5"] ) {
[self beginOmniWeb5ImportFrom:[selectedItem representedObject] intoFolder:importFolder];
}
else {
[self beginImportFrom:[selectedItem representedObject] intoFolder:importFolder];
}
}
-(IBAction) loadOpenPanel:(id)aSender
@@ -170,6 +211,39 @@
}
}
-(void) beginOmniWeb5ImportFrom:(NSArray *)anArray intoFolder:(BookmarkFolder *) aFolder
{
[mCancelButton setEnabled:NO];
[mImportButton setEnabled:NO];
NSEnumerator *enumerator = [anArray objectEnumerator];
NSString *aPath;
NSString *aFile;
BOOL success = TRUE;
while ( success && (aPath = [enumerator nextObject] ) ) {
aFile = [aPath lastPathComponent];
// What folder we import into depends on what OmniWeb file we're importing.
if ([aFile isEqualToString:@"Bookmarks.html"] ) {
success = [[BookmarkManager sharedBookmarkManager] importBookmarks:aPath intoFolder:aFolder];
}
else if ([aFile isEqualToString:@"Favorites.html"] ) {
BookmarkFolder *favoriteFolder = [aFolder addBookmarkFolder];
[favoriteFolder setTitle:NSLocalizedString(@"OmniWeb Favorites",@"OmniWeb Favorites")];
success = [[BookmarkManager sharedBookmarkManager] importBookmarks:aPath intoFolder:favoriteFolder];
} else if ([aFile isEqualToString:@"Published.html"]) {
BookmarkFolder *publishedFolder = [aFolder addBookmarkFolder];
[publishedFolder setTitle:NSLocalizedString(@"OmniWeb Published",@"OmniWeb Published")];
success = [[BookmarkManager sharedBookmarkManager] importBookmarks:aPath intoFolder:publishedFolder];
}
}
[mCancelButton setEnabled:YES];
[mImportButton setEnabled:YES];
// Non-rigorous reporting of errors
[self finishImport:success fromFile:aFile];
}
-(void) beginImportFrom:(NSString *) aPath intoFolder:(BookmarkFolder *) aFolder
{
[mCancelButton setEnabled:NO];
@@ -180,6 +254,13 @@
[mCancelButton setEnabled:YES];
[mImportButton setEnabled:YES];
[self finishImport:success fromFile:[aPath lastPathComponent]];
}
-(void) finishImport:(BOOL)success fromFile:(NSString *)aFile
{
if (success) { //show them the imported bookmarks if import succeeded
[[self window] orderOut:self];
BrowserWindowController *windowController = [(MainController *)[NSApp delegate] openBrowserWindowWithURL:@"" andReferrer:nil behind:nil];
@@ -196,7 +277,7 @@
@selector(alertSheetDidEnd:returnCode:contextInfo:),
nil, // no dismiss sel
(void *)NULL, // no context
[NSString stringWithFormat:NSLocalizedString(@"ImportFailureMessage", @"The file '%@' is not a supported bookmark file type."), [aPath lastPathComponent]]
[NSString stringWithFormat:NSLocalizedString(@"ImportFailureMessage", @"The file '%@' is not a supported bookmark file type."), aFile]
);
}
}

View File

@@ -739,10 +739,10 @@ static unsigned gFirstUserCollection = 0;
[fileScanner setScanLocation:([fileScanner scanLocation] + 7)];
} else {
isNetscape = NO;
aRange = [fileAsString rangeOfString:@"<bookmarkInfo>" options:NSCaseInsensitiveSearch];
aRange = [fileAsString rangeOfString:@"<bookmarkInfo" options:NSCaseInsensitiveSearch];
if (aRange.location != NSNotFound)
// omniweb setup - start at <bookmarkInfo>
[fileScanner scanUpToString:@"<bookmarkInfo>" intoString:NULL];
// omniweb setup - start at <bookmarkInfo
[fileScanner scanUpToString:@"<bookmarkInfo" intoString:NULL];
else {
NSLog(@"Unrecognized style of Bookmark File. Read fails.");
[fileScanner release];
@@ -827,8 +827,10 @@ static unsigned gFirstUserCollection = 0;
if (tempRange.location != NSNotFound)
[(BookmarkFolder *)currentItem setIsGroup:YES];
} else {
[tokenScanner scanUpToString:@"<a>" intoString:NULL];
[tokenScanner setScanLocation:([tokenScanner scanLocation]+3)];
// have to do this in chunks to handle omniweb 5
[tokenScanner scanUpToString:@"<a" intoString:NULL];
[tokenScanner scanUpToString:@">" intoString:NULL];
[tokenScanner setScanLocation:([tokenScanner scanLocation]+1)];
[tokenScanner scanUpToString:@"</a>" intoString:&tempItem];
[currentItem setTitle:[tempItem stringByRemovingAmpEscapes]];
}