remove broken bookmark detection code. b=276657 sr=pinkerton

This commit is contained in:
joshmoz%gmail.com 2005-01-04 04:24:27 +00:00
parent 17c2a55125
commit 276f49ac6e
12 changed files with 34 additions and 490 deletions

View File

@ -23,7 +23,6 @@
mFolderView = NSBox;
mLastVisitField = NSTextField;
mNumberVisitsField = NSTextField;
mStatusField = NSTextField;
mTabView = NSTabView;
mTabgroupCheckbox = NSButton;
};

View File

@ -8,34 +8,18 @@
<string>364.0</string>
<key>IBGroupedObjects</key>
<dict>
<key>29</key>
<array>
<string>436</string>
<string>445</string>
</array>
<key>30</key>
<array>
<string>437</string>
<string>435</string>
<string>453</string>
</array>
<key>31</key>
<array>
<string>441</string>
<string>448</string>
<string>447</string>
</array>
<key>32</key>
<array>
<string>459</string>
<string>439</string>
<string>452</string>
</array>
<key>33</key>
<array>
<string>438</string>
<string>450</string>
</array>
</dict>
<key>IBLastGroupID</key>
<string>34</string>
@ -45,10 +29,10 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>130</integer>
<integer>304</integer>
<integer>130</integer>
</array>
<key>IBSystem Version</key>
<string>7M34</string>
<string>7S215</string>
</dict>
</plist>

View File

@ -21,6 +21,7 @@
*
* Contributor(s):
* David Haas <haasd@cae.wisc.edu>
* Josh Aas <joshmoz@gmail.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -41,28 +42,21 @@
//Status Flags
#define kBookmarkOKStatus 0
#define kBookmarkBrokenLinkStatus 1
#define kBookmarkMovedLinkStatus 2
#define kBookmarkServerErrorStatus 3
#define kBookmarkNeverCheckStatus 5
#define kBookmarkSpacerStatus 9
@interface Bookmark : BookmarkItem //DBME
@interface Bookmark : BookmarkItem
{
NSString* mURL; //DBMu
NSDate* mLastVisit; //DBMv
NSString* mURL;
NSDate* mLastVisit;
NSNumber* mStatus;
NSNumber* mNumberOfVisits;
}
-(NSString *) url;
-(NSDate *) lastVisit;
-(NSString *) url;
-(NSDate *) lastVisit;
-(unsigned) numberOfVisits;
-(unsigned) status;
-(BOOL) isMoved;
-(BOOL) isCheckable;
-(BOOL) isSeparator;
-(BOOL) isSick; //DHIs
-(void) setUrl:(NSString *)aURL;
-(void) setLastVisit:(NSDate *)aLastVisit;
@ -70,10 +64,4 @@
-(void) setIsSeparator:(BOOL)aSeparatorFlag;
-(void) setNumberOfVisits:(unsigned)aNumber;
// functions aiding in checking for updates
-(NSURL *)urlAsURL;
-(void) checkForUpdate;
@end

View File

@ -21,6 +21,7 @@
*
* Contributor(s):
* David Haas <haasd@cae.wisc.edu>
* Josh Aas <joshmoz@gmail.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -48,18 +49,8 @@
@interface Bookmark (Private)
-(void) siteIconCheck:(NSNotification *)aNote;
-(void) urlLoadCheck:(NSNotification *)aNote;
-(void) invalidSchemeForUpdating;
-(BOOL) hostIsReachable:(NSURL *)aURL;
-(void) doHTTPUpdateRequest:(NSURL *)aURL;
-(void) doFileUpdateRequest:(NSURL *)aURL;
-(void) interpretHTTPUpdateCode:(UInt32) aCode;
-(void) cleanupHTTPCheck:(NSTimer *)aTimer;
-(NSString *)userAgentString;
@end
// Constants - for update status checking
static const CFOptionFlags kNetworkEvents = kCFStreamEventEndEncountered | kCFStreamEventErrorOccurred;
// Notification of URL load
NSString *URLLoadNotification = @"url_load";
NSString *URLLoadSuccessKey = @"url_bool";
@ -70,8 +61,8 @@ NSString *URLLoadSuccessKey = @"url_bool";
{
if ((self = [super init])) {
mURL = [[NSString alloc] init];
mStatus = [[NSNumber alloc] initWithUnsignedInt:0];//retain count +1
mNumberOfVisits = [mStatus retain]; //retain count +2
mStatus = [[NSNumber alloc] initWithUnsignedInt:0]; // retain count +1
mNumberOfVisits = [mStatus retain]; // retain count +2
mLastVisit = [[NSDate date] retain];
mIcon = [[NSImage imageNamed:@"smallbookmark"] retain];
// register for notifications
@ -82,7 +73,6 @@ NSString *URLLoadSuccessKey = @"url_bool";
return self;
}
-(id) copyWithZone:(NSZone *)zone
{
id doppleganger = [super copyWithZone:zone];
@ -128,51 +118,26 @@ NSString *URLLoadSuccessKey = @"url_bool";
-(BOOL) isSeparator
{
if ([self status]==kBookmarkSpacerStatus)
return YES;
return NO;
}
-(BOOL) isMoved
{
if ([self status]==kBookmarkMovedLinkStatus)
return YES;
return NO;
}
-(BOOL) isCheckable
{
unsigned myStatus = [self status];
if (myStatus!=kBookmarkNeverCheckStatus &&
myStatus!=kBookmarkBrokenLinkStatus &&
myStatus!=kBookmarkSpacerStatus)
return YES;
return NO;
}
-(BOOL) isSick
{
if (([self status]==kBookmarkBrokenLinkStatus) || ([self status]==kBookmarkServerErrorStatus))
if ([self status] == kBookmarkSpacerStatus)
return YES;
return NO;
}
-(void) setStatus:(unsigned)aStatus
{
if ((aStatus != [mStatus unsignedIntValue]) &&
((aStatus == kBookmarkBrokenLinkStatus) ||
(aStatus == kBookmarkMovedLinkStatus) ||
(aStatus == kBookmarkOKStatus) ||
(aStatus == kBookmarkSpacerStatus) ||
(aStatus == kBookmarkServerErrorStatus) ||
(aStatus == kBookmarkNeverCheckStatus)))
{
if (aStatus != [mStatus unsignedIntValue]) {
// There used to be more than two possible status states.
// Now we regard everything except kBookmarkSpacerStatus
// as kBookmarkOKStatus.
if (aStatus != kBookmarkSpacerStatus)
aStatus = kBookmarkOKStatus;
[mStatus release];
mStatus = [[NSNumber alloc] initWithUnsignedInt:aStatus];
[self itemUpdatedNote];
if (aStatus == kBookmarkSpacerStatus)
[self setTitle:NSLocalizedString(@"<Menu Spacer>",@"<Menu Spacer>")];
}
}
}
- (void) setUrl:(NSString *)aURL
@ -234,10 +199,7 @@ NSString *URLLoadSuccessKey = @"url_bool";
}
}
}
//
// from loads, we only get success or failure - not why things failed.
// so we'll call everything "server error"
//
-(void) urlLoadCheck:(NSNotification *)note
{
NSString *loadedURL = [note object];
@ -247,263 +209,18 @@ NSString *URLLoadSuccessKey = @"url_bool";
if ([myURL hasSuffix:@"/"])
myURL = [myURL substringToIndex:([myURL length]-1)];
if ([loadedURL isEqualToString:myURL]) {
unsigned loadStatus = [[[note userInfo] objectForKey:URLLoadSuccessKey] unsignedIntValue];
[self setLastVisit:[NSDate date]];
[self setStatus:loadStatus];
if (loadStatus == kBookmarkOKStatus)
if ([[[note userInfo] objectForKey:URLLoadSuccessKey] unsignedIntValue] == kBookmarkOKStatus)
[self setNumberOfVisits:([self numberOfVisits]+1)];
}
}
#pragma mark -
//
// handles checking for updates & whatnot of itself
//
-(NSURL *)urlAsURL
{
// We'll just assume if there's a # it's a fragment marker. Yes,
// this is almost certainly a bug, but just for checking status so who cares.
NSString *escapedURL = (NSString *)CFURLCreateStringByAddingPercentEscapes
(NULL,(CFStringRef)[self url],CFSTR("#"),NULL,kCFStringEncodingUTF8);
NSURL *myURL = [NSURL URLWithString:escapedURL];
[escapedURL release];
return myURL;
}
// for now, we'll only check updates on file or http scheme.
// don't know if https will work.
- (void) checkForUpdate;
{
NSURL* myURL = [self urlAsURL];
if (myURL) {
if ([[myURL scheme] isEqualToString:@"http"] && [self hostIsReachable:myURL])
[self doHTTPUpdateRequest:myURL];
else if ([[myURL scheme] isEqualToString:@"file"])
[self doFileUpdateRequest:myURL];
else
[self setStatus:kBookmarkNeverCheckStatus];
}
}
- (BOOL) hostIsReachable:(NSURL *)aURL
{
const char *hostname = [[aURL host] cString];
if (!hostname)
return NO;
SCNetworkConnectionFlags flags;
// just like TN 1145 instructs, not that we're using CodeWarrior
assert(sizeof(SCNetworkConnectionFlags) == sizeof(int));
BOOL isReachable = NO;
if ( SCNetworkCheckReachabilityByName(hostname, &flags) ) {
isReachable = !(flags & kSCNetworkFlagsConnectionRequired) && (flags & kSCNetworkFlagsReachable);
}
return isReachable;
}
//
// CF Callback functions for handling bookmark updating
//
static void doHTTPUpdateCallBack(CFReadStreamRef stream, CFStreamEventType type, void *bookmark)
{
CFHTTPMessageRef aResponse = NULL;
CFStreamError anError;
NSString *newURL = NULL;
UInt32 errCode;
switch (type){
case kCFStreamEventEndEncountered:
aResponse = (CFHTTPMessageRef) CFReadStreamCopyProperty(stream,kCFStreamPropertyHTTPResponseHeader);
if (aResponse) {
errCode = CFHTTPMessageGetResponseStatusCode(aResponse);
switch (errCode) {
case 301: //permanent move - update URL
newURL = (NSString*)CFHTTPMessageCopyHeaderFieldValue(aResponse,CFSTR("Location"));
[(Bookmark *)bookmark setUrl:newURL];
[newURL release];
break;
default:
[(Bookmark *)bookmark interpretHTTPUpdateCode:errCode];
break;
}
} else //beats me. blame the server.
[(Bookmark *)bookmark interpretHTTPUpdateCode:500];
break;
case kCFStreamEventErrorOccurred:
anError = CFReadStreamGetError(stream);
if (anError.domain == kCFStreamErrorDomainHTTP) {
errCode = anError.error; //signed being assigned to unsinged. oh well
[(Bookmark *)bookmark interpretHTTPUpdateCode:errCode];
} else // call it server error
[(Bookmark *)bookmark interpretHTTPUpdateCode:500];
break;
default:
NSLog(@"If you can read this you're too close to the screen.");
break;
}
//
// update our last visit date & cleanup
//
[(Bookmark *)bookmark setLastVisit:[NSDate date]];
if (aResponse)
CFRelease(aResponse);
}
// borrowed heavily from Apple's CFNetworkHTTPDownload example
-(void) doHTTPUpdateRequest:(NSURL *)aURL
{
CFHTTPMessageRef messageRef = NULL;
CFReadStreamRef readStreamRef = NULL;
CFStreamClientContext ctxt= { 0, (void*)self, NULL, NULL, NULL }; //pointer to self lets us update
// get message
messageRef = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("HEAD"), (CFURLRef)aURL, kCFHTTPVersion1_1);
if (!messageRef) {
NSLog(@"CheckForUpdate: Can't create CFHTTPMessage for %@",aURL);
return;
}
// set if-modified-since header field, and maybe others if we're bored.
// really, since we just want to see if it's there, don't even need to
// do this.
NSString *httpDate = [[self lastVisit] descriptionWithCalendarFormat:@"%a, %d %b %Y %H:%M:%S GMT" timeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"] locale:nil];
NSString *userAgent = [self userAgentString];
CFHTTPMessageSetHeaderFieldValue(messageRef,CFSTR("If-Modified-Since"),(CFStringRef)httpDate);
CFHTTPMessageSetHeaderFieldValue(messageRef,CFSTR("User-Agent"),(CFStringRef)userAgent);
//setup read stream
readStreamRef = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, messageRef);
CFRelease(messageRef);
if (!readStreamRef) {
NSLog(@"CheckForUpdate: Can't create CFReadStream for %@",aURL);
return;
}
// handle http proxy, if necessary
NSDictionary* proxyConfigDict = (NSDictionary *)SCDynamicStoreCopyProxies(NULL);
if (proxyConfigDict) {
if ([[proxyConfigDict objectForKey:(NSString*)kSCPropNetProxiesHTTPEnable] intValue] != 0) {
NSString *proxyURL = [proxyConfigDict objectForKey:(NSString*)kSCPropNetProxiesHTTPProxy];
NSNumber *proxyPort = [proxyConfigDict objectForKey:(NSString*)kSCPropNetProxiesHTTPPort];
if (proxyURL && proxyPort) {
CFHTTPReadStreamSetProxy(readStreamRef,(CFStringRef)proxyURL,(CFIndex)[proxyPort unsignedIntValue]);
}
}
[proxyConfigDict release];
}
//setup callback function
if (CFReadStreamSetClient(readStreamRef, kNetworkEvents, doHTTPUpdateCallBack, &ctxt ) == false ) {
NSLog(@"CheckForUpdate: Can't set CFReadStream callback for %@",aURL);
CFRelease(readStreamRef);
return;
}
//schedule the stream & open the connection
CFReadStreamScheduleWithRunLoop(readStreamRef, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
if (CFReadStreamOpen(readStreamRef) == false ){
NSLog(@"CheckForUpdate: Can't open CFReadStream for %@",aURL);
CFReadStreamSetClient(readStreamRef, NULL, NULL, NULL);
CFRelease(readStreamRef);
return;
}
//schedule a timeout. we'll give it, oh, 60 seconds before killing the check
//this timer is responsible for cleaning up the read stream memory!!!!!!!!!
[NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(cleanupHTTPCheck:) userInfo:(id)readStreamRef repeats:NO];
}
// My interpretation of what should & shouldn't happen is
// quite possibly incorrect. Feel free to adjust.
-(void) interpretHTTPUpdateCode:(UInt32) errCode
{
switch (errCode){
case 200: //OK - bookmark updated
case 203: //Non-authoritative info - call it same as OK
case 302: //Found - new link, but don't update
case 303: //See other - new link, but don't update
case 304: //Not modified - do nothing
case 307: //Temporary redirect - new link, but don't update
[self setStatus:kBookmarkOKStatus];
break;
case 300: //multiple choices - not sure what to do so we'll bail here
case 301: //Moved permananently - should be handled in callback
case 305: //Use proxy (specified) - should retry request
[self setStatus:kBookmarkMovedLinkStatus];
break;
case 400: //Bad request - we f'd up
case 403: //Forbidden - not good
case 404: //Not found - clearly not good
case 410: //Gone - nah nah nahnah, nah nah nahnah, hey hey hey, etc.
[self setStatus:kBookmarkBrokenLinkStatus];
break;
case 401: //Unauthorized - need to be clever about checking this
case 402: //Payment required - funk that.
case 405: //Method not allowed - funk that, too.
case 406: //Not Acceptable - shouldn't happen, but oh well.
case 407: //Proxy Authentication Required - need to be cleverer here
case 411: //Length required - need to be cleverer
case 413: //Request entity too large - shouldn't happen
case 414: //Request URI too large - shouldn't happen
case 415: //Request URI too large - shouldn't happen
case 500: //Internal server error
case 501: //Not Implemented
case 502: //Bad Gateway
case 503: //Service Unavailable
case 504: //Gateway Timeout
case 505: //HTTP Version not supported
[self setStatus:kBookmarkServerErrorStatus];
break;
case 100: //Continue - just ignore
case 101: //Switching protocols - not that smart yet
case 201: //Created - shouldn't happen
case 202: //Accepted - shouldn't happen
case 204: //No content - shouldn't happen
case 205: //Reset content - shouldn't happen
case 206: //Partial content - shouldn't happen for HEAD request
case 408: //Request timeout - shouldn't happen
case 409: //Conflict - shouldn't happen
case 412: //Precondintion failed - shouldn't happen
case 416: //requested range not satisfiable - shouldn't happen
case 417: //Expectation failed - shouldn't happen
default:
break;
}
}
-(void) doFileUpdateRequest:(NSURL *)aURL
{
// if it's here, it's got a scheme of file, so we can call path directly
NSFileManager *fM = [NSFileManager defaultManager];
if (![fM fileExistsAtPath:[aURL path]])
[self setStatus:kBookmarkBrokenLinkStatus];
}
// this function cleans up after our stream request.
// if you get rid of it, we leak memory
-(void) cleanupHTTPCheck:(NSTimer *)aTimer;
{
CFReadStreamRef stream = (CFReadStreamRef)[aTimer userInfo];
CFReadStreamSetClient(stream,NULL,NULL,NULL);
CFRelease(stream);
}
// this is done poorly. if someone feels like doing this more correctly, more power to you.
-(NSString *)userAgentString
{
return [NSString stringWithString:@"Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O) Gecko Camino"];
}
#pragma mark -
//
// for reading/writing from/to disk
//
-(BOOL) readNativeDictionary:(NSDictionary *)aDict
{
//gather the redundant update notifications
@ -521,7 +238,7 @@ static void doHTTPUpdateCallBack(CFReadStreamRef stream, CFStreamEventType type,
[self setAccumulateUpdateNotifications:NO];
return YES;
}
-(BOOL) readSafariDictionary:(NSDictionary *)aDict
{
//gather the redundant update notifications
@ -614,7 +331,6 @@ static void doHTTPUpdateCallBack(CFReadStreamRef stream, CFStreamEventType type,
return dict;
}
-(NSString *)writeHTML:(unsigned int)aPad
{
NSString* formatString;
@ -653,4 +369,3 @@ static void doHTTPUpdateCallBack(CFReadStreamRef stream, CFStreamEventType type,
}
@end

View File

@ -59,7 +59,6 @@
IBOutlet NSTextField* mFolderKeywordField;
IBOutlet NSTextField* mFolderDescField;
IBOutlet NSTextField* mLastVisitField;
IBOutlet NSTextField* mStatusField;
IBOutlet NSTextField* mNumberVisitsField;
IBOutlet NSButton* mTabgroupCheckbox;

View File

@ -212,9 +212,7 @@ static BookmarkInfoController *sharedBookmarkInfoController = nil;
-(void)updateUI:(BookmarkItem *)aBookmark
{
if (aBookmark) {
//
// setup for bookmarks
//
NSBox *newView;
if ([aBookmark isKindOfClass:[Bookmark class]]) {
newView = mBookmarkView;
@ -224,29 +222,6 @@ static BookmarkInfoController *sharedBookmarkInfoController = nil;
[mBookmarkLocationField setStringValue: [(Bookmark *)aBookmark url]];
[mNumberVisitsField setIntValue:[(Bookmark *)aBookmark numberOfVisits]];
[mLastVisitField setStringValue: [[(Bookmark *)aBookmark lastVisit] descriptionWithCalendarFormat:[[mLastVisitField formatter] dateFormat] timeZone:[NSTimeZone localTimeZone] locale:nil]];
NSString *statusString = nil;
unsigned status = [(Bookmark *)aBookmark status];
switch (status) {
case (kBookmarkOKStatus):
case (kBookmarkSpacerStatus):
statusString = NSLocalizedString(@"OK",@"OK");
break;
case (kBookmarkBrokenLinkStatus):
statusString = NSLocalizedString(@"Link Broken",@"Link Broken");
break;
case (kBookmarkMovedLinkStatus):
statusString = NSLocalizedString(@"Link has Moved",@"Link has Moved");
break;
case (kBookmarkServerErrorStatus):
statusString = NSLocalizedString(@"Server Unreachable",@"Server Unreachable");
break;
case (kBookmarkNeverCheckStatus):
statusString = NSLocalizedString(@"Uncheckable",@"Uncheckable");
break;
default:
statusString = [NSString string];
}
[mStatusField setStringValue:statusString];
// if its parent is a smart folder or it's a menu separator,
// we turn off all the fields. if it isn't, then we turn them all on
id parent = [aBookmark parent];
@ -266,9 +241,7 @@ static BookmarkInfoController *sharedBookmarkInfoController = nil;
[mBookmarkLocationField setEditable:NO];
}
}
//
// Folders
//
else if ([aBookmark isKindOfClass:[BookmarkFolder class]]) {
newView = mFolderView;
if ([(BookmarkFolder *)aBookmark isGroup]) {
@ -280,9 +253,7 @@ static BookmarkInfoController *sharedBookmarkInfoController = nil;
[mFolderNameField setStringValue: [aBookmark title]];
[mFolderKeywordField setStringValue: [aBookmark keyword]];
[mFolderDescField setStringValue: [aBookmark description]];
//
// we can't just unselect dock menu - we have to pick a new one
//
if ([(BookmarkFolder *)aBookmark isDockMenu]) {
[mDockMenuCheckbox setState:NSOnState];
[mDockMenuCheckbox setEnabled:NO];

View File

@ -53,21 +53,15 @@ enum {
kHistoryContainerIndex = 2,
};
// check 1 bookmark every 2 minutes, but only if we haven't been there in a day
#define kTimeBeforeRecheckingBookmark 86400.0
#define kTimeBetweenBookmarkChecks 120
@interface BookmarkManager : NSObject <BookmarksClient> {
BookmarkFolder *mRootBookmarks; // root bookmark object
KindaSmartFolderManager *mSmartFolderManager; //brains behind 4 smart folders
NSUndoManager *mUndoManager;// handles deletes, adds of bookmarks
NSUndoManager *mUndoManager; // handles deletes, adds of bookmarks
BookmarkImportDlgController *mImportDlgController;
NSString *mPathToBookmarkFile; //exactly what it looks like
NSTimer *mUpdateTimer; //we don't actually retain this
// smart folders
BookmarkFolder *mTop10Container;
BookmarkFolder *mBrokenBookmarkContainer;
BookmarkFolder *mRendezvousContainer;
BookmarkFolder *mAddressBookContainer;
}
@ -84,7 +78,6 @@ enum {
-(BookmarkFolder *) bookmarkMenuFolder;
-(BookmarkFolder *) dockMenuFolder;
-(BookmarkFolder *) top10Folder;
-(BookmarkFolder *) brokenLinkFolder;
-(BookmarkFolder *) rendezvousFolder;
-(BookmarkFolder *) addressBookFolder;
-(BookmarkFolder *) historyFolder;

View File

@ -61,9 +61,7 @@
- (void)setupSmartCollections;
- (void)delayedStartupItems;
- (void)writeBookmarks:(NSNotification *)note;
- (void)checkForUpdates:(NSTimer *)aTimer;
- (BookmarkFolder *)findDockMenuFolderInFolder:(BookmarkFolder *)aFolder;
- (Bookmark *)findABookmarkToCheckInFolder:(BookmarkFolder *)aFolder;
@end
@implementation BookmarkManager
@ -179,12 +177,9 @@ static unsigned gFirstUserCollection = 0;
-(void) dealloc
{
[mTop10Container release];
[mBrokenBookmarkContainer release];
[mRendezvousContainer release];
[mAddressBookContainer release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
if (mUpdateTimer)
[mUpdateTimer invalidate]; //we don't retain this, so don't release it.
[mUndoManager release];
[mRootBookmarks release];
[mPathToBookmarkFile release];
@ -196,18 +191,11 @@ static unsigned gFirstUserCollection = 0;
[super dealloc];
}
//
// -delayedStartupItems
//
// Perform additional setup items on the main thread.
//
- (void)delayedStartupItems
{
[[NSApp delegate] setupBookmarkMenus:gBookmarksManager];
// check update status of 1 bookmark every 2 minutes if autoupdate is enabled.
if ([[PreferenceManager sharedInstance] getBooleanPref:"camino.bookmarks.autoupdate" withSuccess:NULL])
mUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:kTimeBetweenBookmarkChecks target:self selector:@selector(checkForUpdates:) userInfo:nil repeats:YES];
[mSmartFolderManager postStartupInitialization:self];
[[self toolbarFolder] refreshIcon];
@ -234,7 +222,7 @@ static unsigned gFirstUserCollection = 0;
}
//
// smart collections, as of now, are Rendezvous, Address Book, Top 10 List, Broken Bookmarks,
// smart collections, as of now, are Rendezvous, Address Book, Top 10 List.
// We also have history, but that just points to the real history stuff.
- (void)setupSmartCollections
{
@ -255,26 +243,15 @@ static unsigned gFirstUserCollection = 0;
[mTop10Container setIsSmartFolder:YES];
[mRootBookmarks insertChild:mTop10Container atIndex:(collectionIndex++) isMove:NO];
// add broken bookmarks if auto-checking is enabled
if ([[PreferenceManager sharedInstance] getBooleanPref:"camino.bookmarks.autoupdate" withSuccess:NULL]) {
mBrokenBookmarkContainer = [[BookmarkFolder alloc] init];
[mBrokenBookmarkContainer setTitle:NSLocalizedString(@"Broken Bookmarks",@"Broken Bookmarks")];
[mBrokenBookmarkContainer setIsSmartFolder:YES];
[mRootBookmarks insertChild:mBrokenBookmarkContainer atIndex:(collectionIndex++) isMove:NO];
}
// add rendezvous and address book in 10.2+
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_1) {
mRendezvousContainer = [[BookmarkFolder alloc] init];
[mRendezvousContainer setTitle:NSLocalizedString(@"Rendezvous",@"Rendezvous")];
[mRendezvousContainer setIsSmartFolder:YES];
[mRootBookmarks insertChild:mRendezvousContainer atIndex:(collectionIndex++) isMove:NO];
mRendezvousContainer = [[BookmarkFolder alloc] init];
[mRendezvousContainer setTitle:NSLocalizedString(@"Rendezvous",@"Rendezvous")];
[mRendezvousContainer setIsSmartFolder:YES];
[mRootBookmarks insertChild:mRendezvousContainer atIndex:(collectionIndex++) isMove:NO];
mAddressBookContainer = [[BookmarkFolder alloc] init];
[mAddressBookContainer setTitle:NSLocalizedString(@"Address Book",@"Address Book")];
[mAddressBookContainer setIsSmartFolder:YES];
[mRootBookmarks insertChild:mAddressBookContainer atIndex:(collectionIndex++) isMove:NO];
}
mAddressBookContainer = [[BookmarkFolder alloc] init];
[mAddressBookContainer setTitle:NSLocalizedString(@"Address Book",@"Address Book")];
[mAddressBookContainer setIsSmartFolder:YES];
[mRootBookmarks insertChild:mAddressBookContainer atIndex:(collectionIndex++) isMove:NO];
gFirstUserCollection = collectionIndex;
@ -286,7 +263,6 @@ static unsigned gFirstUserCollection = 0;
[[self toolbarFolder] setIcon:[NSImage imageNamed:@"bookmarktoolbar_icon"]];
[[self rendezvousFolder] setIcon:[NSImage imageNamed:@"rendezvous_icon"]];
[[self addressBookFolder] setIcon:[NSImage imageNamed:@"addressbook_icon"]];
[[self brokenLinkFolder] setIcon:[NSImage imageNamed:@"brokenbookmark_icon"]];
}
//
@ -328,11 +304,6 @@ static unsigned gFirstUserCollection = 0;
return mTop10Container;
}
-(BookmarkFolder *) brokenLinkFolder
{
return mBrokenBookmarkContainer;
}
-(BookmarkFolder *) toolbarFolder
{
return [[self rootBookmarks] objectAtIndex:kToolbarContainerIndex];
@ -408,34 +379,6 @@ static unsigned gFirstUserCollection = 0;
return matchingArray;
}
//
// every couple of minutes, this gets called
// it finds the first bookmark we haven't been to in 24 hours
// and makes sure it's still there
//
- (void)checkForUpdates:(NSTimer *)aTimer
{
Bookmark *bm = [self findABookmarkToCheckInFolder:[self rootBookmarks]];
if (bm)
[bm checkForUpdate];
}
-(Bookmark *)findABookmarkToCheckInFolder:(BookmarkFolder *)aFolder
{
NSEnumerator *enumerator = [[aFolder childArray] objectEnumerator];
id aKid;
Bookmark *foundBookmark = nil;
while ((!foundBookmark) && (aKid = [enumerator nextObject])) {
if ([aKid isKindOfClass:[Bookmark class]]) {
if (([(Bookmark *)aKid isCheckable]) &&
(-[[(Bookmark *)aKid lastVisit] timeIntervalSinceNow] > kTimeBeforeRecheckingBookmark))
foundBookmark = aKid;
} else if ([aKid isKindOfClass:[BookmarkFolder class]])
foundBookmark = [self findABookmarkToCheckInFolder:aKid];
}
return foundBookmark;
}
//
// Drag & drop
//

View File

@ -46,7 +46,6 @@
@class BookmarkManager;
@interface KindaSmartFolderManager : NSObject {
BookmarkFolder* mBrokenBookmarkFolder;
BookmarkFolder* mUpdatedBookmarkFolder;
BookmarkFolder* mTop10Folder;
BookmarkFolder* mAddressBookFolder;

View File

@ -49,7 +49,6 @@
@interface KindaSmartFolderManager (Private) <NetworkServicesClient, BookmarksClient>
-(void)addBookmark:(Bookmark *)aBookmark toSmartFolder:(BookmarkFolder *)aFolder;
-(void)removeBookmark:(Bookmark *)aBookmark fromSmartFolder:(BookmarkFolder *)aFolder;
-(void)setupBrokenBookmarks;
-(void)checkForNewTop10:(Bookmark *)aBookmark;
-(void)setupAddressBook;
-(void)rebuildTop10List;
@ -61,7 +60,6 @@
{
if ((self = [super init])) {
// retain all our smart folders, just to be safe
mBrokenBookmarkFolder = [[manager brokenLinkFolder] retain];
mTop10Folder = [[manager top10Folder] retain];
mAddressBookFolder = [[manager addressBookFolder] retain];
mRendezvousFolder = [[manager rendezvousFolder] retain];
@ -78,7 +76,6 @@
-(void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[mBrokenBookmarkFolder release];
[mTop10Folder release];
[mAddressBookFolder release];
[mRendezvousFolder release];
@ -96,8 +93,6 @@
}
if (mAddressBookFolder)
[self setupAddressBook];
if (mBrokenBookmarkFolder)
[self setupBrokenBookmarks];
// get top 10 list started
NSArray *bookmarkArray = [[manager rootBookmarks] allChildBookmarks];
unsigned i, j = [bookmarkArray count];
@ -107,18 +102,6 @@
}
}
-(void) setupBrokenBookmarks
{
BookmarkManager *manager = [BookmarkManager sharedBookmarkManager];
NSArray *bookmarkArray = [[manager rootBookmarks] allChildBookmarks];
unsigned i, j = [bookmarkArray count];
for (i=0; i < j; i++) {
Bookmark *aBookmark = [bookmarkArray objectAtIndex:i];
if ([aBookmark isSick])
[self addBookmark:aBookmark toSmartFolder:mBrokenBookmarkFolder];
}
}
// when 10.1 support is dropped, most of "init" method of AddressBookManager goes here.
// we'd also need to add that class' fillAddressBook method to this class
-(void) setupAddressBook
@ -289,13 +272,12 @@ static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void
}
//
// need to tell top 10 list, broken items
// need to tell top 10 list
//
- (void)bookmarkRemoved:(NSNotification *)note
{
BookmarkItem *anItem = [[note userInfo] objectForKey:BookmarkFolderChildKey];
if (![anItem parent] && [anItem isKindOfClass:[Bookmark class]]) {
[self removeBookmark:anItem fromSmartFolder:mBrokenBookmarkFolder];
[self removeBookmark:anItem fromSmartFolder:mTop10Folder];
}
}
@ -305,12 +287,6 @@ static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void
BookmarkItem *anItem = [note object];
if ([anItem isKindOfClass:[Bookmark class]]) {
[self checkForNewTop10:anItem];
// see what the status is
if ([(Bookmark *)anItem isSick])
[self addBookmark:anItem toSmartFolder:mBrokenBookmarkFolder];
else {
[self removeBookmark:anItem fromSmartFolder:mBrokenBookmarkFolder];
}
}
}

View File

@ -53,8 +53,6 @@
#include "nsIDOMPopupBlockedEvent.h"
#include "nsNetError.h"
#import "CHBrowserView.h"
#import "BookmarksClient.h"
#import "Bookmark.h"
#include "CHBrowserListener.h"
@ -535,27 +533,6 @@ CHBrowserListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequ
[obj onLoadingStarted];
}
else if (aStateFlags & nsIWebProgressListener::STATE_STOP) {
// we need to pass along errors like this so our bookmarks know
// if they're still OK
NSNumber *errNum = nil;
if ((aStatus == NS_ERROR_UNKNOWN_HOST ||
aStatus == NS_ERROR_CONNECTION_REFUSED ||
aStatus == NS_ERROR_UNKNOWN_PROXY_HOST ||
aStatus == NS_ERROR_PROXY_CONNECTION_REFUSED))
errNum = [NSNumber numberWithUnsignedInt:kBookmarkServerErrorStatus];
else if (( aStatus == NS_ERROR_MALFORMED_URI ||
aStatus == NS_ERROR_UNKNOWN_PROTOCOL))
errNum = [NSNumber numberWithUnsignedInt:kBookmarkBrokenLinkStatus];
else if ((aStatus == NS_BINDING_REDIRECTED))
errNum = [NSNumber numberWithUnsignedInt:kBookmarkMovedLinkStatus];
if (errNum) {
nsCAutoString uriString;
aRequest->GetName(uriString);
NSString *fixedURL = [NSString stringWithUTF8String:uriString.get()];
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:errNum forKey:URLLoadSuccessKey];
NSNotification *note = [NSNotification notificationWithName:URLLoadNotification object:fixedURL userInfo:userInfo];
[[NSNotificationQueue defaultQueue] enqueueNotification:note postingStyle:NSPostWhenIdle];
}
while ((obj = [enumerator nextObject])) {
[obj onLoadingCompleted:(NS_SUCCEEDED(aStatus))];
}