-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathCOBookmark.m
More file actions
98 lines (76 loc) · 2.54 KB
/
Copy pathCOBookmark.m
File metadata and controls
98 lines (76 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
Copyright (C) 2013 Quentin Mathe
Date: March 2013
License: MIT (see COPYING)
*/
#import "COBookmark.h"
@implementation COBookmark
@synthesize URL = _URL, lastVisitedDate = _lastVisitedDate, favIconData = _favIconData;
+ (ETEntityDescription *)newEntityDescription
{
ETEntityDescription *bookmark = [self newBasicEntityDescription];
// For subclasses that don't override -newEntityDescription, we must not add the
// property descriptions that we will inherit through the parent
if (![bookmark.name isEqual: [COBookmark className]])
return bookmark;
ETPropertyDescription *URL =
[ETPropertyDescription descriptionWithName: @"URL" typeName: @"NSURL"];
ETPropertyDescription *lastVisitedDate =
[ETPropertyDescription descriptionWithName: @"lastVisitedDate" typeName: @"NSDate"];
ETPropertyDescription *favIconData =
[ETPropertyDescription descriptionWithName: @"favIconData" typeName: @"NSData"];
NSArray *persistentProperties = @[URL, lastVisitedDate, favIconData];
[[persistentProperties mappedCollection] setPersistent: YES];
bookmark.propertyDescriptions = persistentProperties;
return bookmark;
}
- (instancetype)initWithURL: (NSURL *)aURL
{
NILARG_EXCEPTION_TEST(aURL);
SUPERINIT;
_URL = aURL;
_favIconData = aURL.favIconData;
return self;
}
- (instancetype)initWithURLFile: (NSString *)aFilePath
{
// TODO: Finish to implement
NSURL *URL = nil;
return [self initWithURL: URL];
}
- (void)setURL: (NSURL *)aURL
{
[self willChangeValueForProperty: @"URL"];
_URL = [aURL copy];
[self didChangeValueForProperty: @"URL"];
}
/** The URL is serialized as a NSString (rather than NSData through NSCoding) to
support bookmark search based on URL text. */
- (NSString *)serializedURL
{
return _URL.relativeString;
}
- (void)setSerializedURL: (NSString *)aURLString
{
_URL = (aURLString != nil ? [NSURL URLWithString: aURLString] : nil);
}
- (void)setLastVisitedDate: (NSDate *)aDate
{
[self willChangeValueForProperty: @"lastVisitedDate"];
_lastVisitedDate = [aDate copy];
[self didChangeValueForProperty: @"lastVisitedDate"];
}
- (void)setFavIconData: (NSData *)favIconData
{
[self willChangeValueForProperty: @"favIconData"];
_favIconData = [favIconData copy];
[self didChangeValueForProperty: @"favIconData"];
}
@end
@implementation NSURL (COBookmark)
- (NSData *)favIconData
{
NSURL *URL = [NSURL URLWithString: @"/favicon.ico" relativeToURL: self];
return [NSData dataWithContentsOfURL: URL];
}
@end