forked from quicksilver/com.apple.AddressBook-qsplugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ABPerson_Display.m
81 lines (62 loc) · 2.01 KB
/
ABPerson_Display.m
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
//
// ABPerson-DisplayProperties.m
// QSAddressBookPlugIn
//
// Created by Brian Donovan on 23/03/05.
// Copyright 2005 __MyCompanyName__. All rights reserved.
//
#import "ABPerson_Display.h"
@implementation ABRecord (Display)
- (BOOL)firstNameFirst {
if (![self isKindOfClass:[ABPerson class]]) return NO;
int nameOrderingFlags = [[self valueForProperty:kABPersonFlags] intValue] & kABNameOrderingMask;
if (nameOrderingFlags == kABDefaultNameOrdering) {
nameOrderingFlags = [[ABAddressBook sharedAddressBook] defaultNameOrdering];
}
return (nameOrderingFlags == kABFirstNameFirst);
}
- (NSString *)displayName {
NSString *first = nil, *last = nil;
if ([self isKindOfClass:[ABPerson class]]) { // ABMailRecent doesn't understand these properties
int flags = [[self valueForProperty:kABPersonFlags] intValue];
// it's a company, just return the company name
if (flags & kABShowAsMask & kABShowAsCompany)
return [self valueForProperty:kABOrganizationProperty];
first = [self valueForProperty:kABNicknameProperty];
}
if (!first)
first = [self valueForProperty:kABFirstNameProperty];
last = [self valueForProperty:kABLastNameProperty];
if (first) {
if (last)
return [self firstNameFirst] ? [NSString stringWithFormat:@"%@ %@", first, last]
: [NSString stringWithFormat:@"%@, %@", last, first];
else
return first;
} else {
if (last)
return last;
else
return @"No Name";
}
}
- (NSString *)jobTitle {
if (![self isKindOfClass:[ABPerson class]]) return nil;
// companies do not have job titles
if ([[self valueForProperty:kABPersonFlags] intValue] & kABShowAsMask & kABShowAsCompany)
return nil;
NSString *title = [self valueForProperty:kABTitleProperty],
*company = [self valueForProperty:kABOrganizationProperty];
if (title) {
if (company)
return [NSString stringWithFormat:@"%@, %@", title, company];
else
return title;
} else {
if (company)
return company;
else
return nil;
}
}
@end