| 1 |
footashida |
1.1 |
#import "AddressBookController.h" |
| 2 |
|
|
#import <AddressBook/AddressBook.h> |
| 3 |
footashida |
1.4 |
#import "ComposeController.h" |
| 4 |
footashida |
1.1 |
|
| 5 |
|
|
@implementation AddressBookController |
| 6 |
|
|
- (id)init{ |
| 7 |
|
|
self = [super initWithWindowNibName:@"AddressBook"]; |
| 8 |
|
|
return self; |
| 9 |
|
|
} |
| 10 |
footashida |
1.2 |
-(void)dealloc{ |
| 11 |
|
|
[nameTable release]; |
| 12 |
|
|
[group release]; |
| 13 |
|
|
[currentGroup release]; |
| 14 |
|
|
[super dealloc]; |
| 15 |
|
|
} |
| 16 |
footashida |
1.3 |
-(NSView *)addressBookView{ |
| 17 |
|
|
return addressBookView; |
| 18 |
|
|
} |
| 19 |
footashida |
1.1 |
- (void)windowDidLoad |
| 20 |
|
|
{ |
| 21 |
footashida |
1.3 |
[[self window] setContentView:addressBookView]; |
| 22 |
footashida |
1.4 |
[drawer setContentView:addressBookView]; |
| 23 |
footashida |
1.1 |
[self updateGroup]; |
| 24 |
|
|
}/* windowDidLoad */ |
| 25 |
|
|
|
| 26 |
|
|
- (NSMutableArray *)listGroup |
| 27 |
|
|
{ |
| 28 |
|
|
NSArray *everygroup = [[[NSArray alloc] init] autorelease]; |
| 29 |
|
|
NSMutableArray *aGroup = [[[NSMutableArray alloc] init] autorelease]; |
| 30 |
|
|
|
| 31 |
|
|
[aGroup addObject:@"All"]; |
| 32 |
|
|
|
| 33 |
|
|
ABAddressBook *ab = [ABAddressBook sharedAddressBook]; |
| 34 |
|
|
|
| 35 |
|
|
everygroup = [ab groups]; |
| 36 |
|
|
|
| 37 |
|
|
id obj; |
| 38 |
|
|
NSEnumerator *enumerator = [everygroup objectEnumerator]; |
| 39 |
|
|
while ((obj = [enumerator nextObject]) != nil){ |
| 40 |
|
|
ABGroup *someGroup = obj; |
| 41 |
|
|
[aGroup addObject:[someGroup valueForProperty:kABGroupNameProperty]]; |
| 42 |
|
|
} |
| 43 |
|
|
|
| 44 |
|
|
return aGroup; |
| 45 |
|
|
}/* listGroup*/ |
| 46 |
|
|
|
| 47 |
|
|
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification |
| 48 |
|
|
{ |
| 49 |
|
|
ABAddressBook *ab = [ABAddressBook sharedAddressBook]; |
| 50 |
|
|
//NSLog(@"aNotification"); |
| 51 |
|
|
//NSLog(@"%d",[[aNotification object] selectedRow]); |
| 52 |
|
|
//NSLog(@"%@",[[[aNotification object] dataSource] group]); |
| 53 |
|
|
if ([[aNotification object] selectedRow] == -1){ |
| 54 |
|
|
[self setCurrentGroup:nil]; |
| 55 |
|
|
[self updateUI]; |
| 56 |
|
|
} else if (![[aNotification object] selectedRow]){ |
| 57 |
|
|
|
| 58 |
|
|
ABGroup *all =[[[ABGroup alloc] init] autorelease]; |
| 59 |
|
|
NSEnumerator *enumerator = [[ab people] objectEnumerator]; |
| 60 |
|
|
id obj; |
| 61 |
|
|
|
| 62 |
|
|
while ((obj = [enumerator nextObject]) != nil){ |
| 63 |
|
|
[all addMember:obj]; |
| 64 |
|
|
} |
| 65 |
|
|
|
| 66 |
|
|
[self setCurrentGroup:all]; |
| 67 |
|
|
[self updateUI]; |
| 68 |
|
|
} else { |
| 69 |
|
|
NSArray *everygroup = [[[NSArray alloc] init] autorelease]; |
| 70 |
|
|
everygroup = [ab groups]; |
| 71 |
|
|
ABGroup *someGroup = [everygroup objectAtIndex:[[aNotification object] selectedRow]-1]; |
| 72 |
|
|
[self setCurrentGroup:someGroup]; |
| 73 |
|
|
[self updateUI]; |
| 74 |
|
|
} |
| 75 |
|
|
}/* tableViewSelectionDidChange */ |
| 76 |
|
|
|
| 77 |
|
|
-(void) updateUI |
| 78 |
|
|
{ |
| 79 |
|
|
[nameTable reloadData]; |
| 80 |
|
|
}/* updateUI */ |
| 81 |
|
|
|
| 82 |
|
|
- (void) updateGroup |
| 83 |
|
|
{ |
| 84 |
|
|
group = [[NSMutableArray alloc] init]; |
| 85 |
|
|
[self setGroup:[self listGroup]]; |
| 86 |
|
|
}/* updateGroup */ |
| 87 |
|
|
|
| 88 |
|
|
// ---------------------------------------------------------------------------------------- |
| 89 |
|
|
// NSTableDataSource |
| 90 |
|
|
// ---------------------------------------------------------------------------------------- |
| 91 |
|
|
|
| 92 |
|
|
- (int)numberOfRowsInTableView:(NSTableView *)aTableView |
| 93 |
|
|
{ |
| 94 |
|
|
return [[currentGroup members] count]; |
| 95 |
|
|
}/* numberOfRowsInTableView */ |
| 96 |
|
|
|
| 97 |
|
|
- (id)tableView:(NSTableView *)aTableView |
| 98 |
|
|
objectValueForTableColumn:(NSTableColumn *)aTableColumn |
| 99 |
|
|
row:(int)rowIndex |
| 100 |
|
|
{ |
| 101 |
|
|
//NSDictionary *dictionary = [array objectAtIndex:rowIndex]; |
| 102 |
|
|
//return [dictionary objectForKey:[aTableColumn identifier]]; |
| 103 |
|
|
|
| 104 |
|
|
ABPerson *theRecord; |
| 105 |
|
|
id theValue; |
| 106 |
|
|
ABPropertyType type = [ABPerson typeOfProperty:[aTableColumn identifier]]; |
| 107 |
|
|
theRecord = [[currentGroup members] objectAtIndex:rowIndex]; |
| 108 |
|
|
|
| 109 |
|
|
//First,Last,Email,Phone |
| 110 |
|
|
|
| 111 |
|
|
if ( type & kABMultiValueMask ) { |
| 112 |
|
|
ABMultiValue *mValue = [theRecord valueForProperty:[aTableColumn identifier]]; |
| 113 |
|
|
int index = [mValue indexForIdentifier:[mValue primaryIdentifier]]; |
| 114 |
|
|
theValue = [mValue valueAtIndex:index]; |
| 115 |
|
|
} else { |
| 116 |
|
|
theValue = [theRecord valueForProperty:[aTableColumn identifier]]; |
| 117 |
|
|
} |
| 118 |
|
|
|
| 119 |
|
|
return theValue; |
| 120 |
|
|
}/* tableView */ |
| 121 |
|
|
|
| 122 |
|
|
|
| 123 |
|
|
|
| 124 |
|
|
// ---------------------------------------------------------------------------------------- |
| 125 |
|
|
// �A�N�Z�b�T���\�b�h |
| 126 |
|
|
// ---------------------------------------------------------------------------------------- |
| 127 |
|
|
|
| 128 |
|
|
|
| 129 |
|
|
- (void) setGroup:(NSMutableArray *)aGroup |
| 130 |
|
|
{ |
| 131 |
|
|
[aGroup retain]; |
| 132 |
|
|
[group release]; |
| 133 |
|
|
group = aGroup; |
| 134 |
|
|
}/* setGroup */ |
| 135 |
|
|
|
| 136 |
|
|
- (NSMutableArray *)group |
| 137 |
|
|
{ |
| 138 |
|
|
return group; |
| 139 |
|
|
}/* group */ |
| 140 |
|
|
|
| 141 |
|
|
- (void) setCurrentGroup:(ABGroup *)cGroup |
| 142 |
|
|
{ |
| 143 |
|
|
[cGroup retain]; |
| 144 |
|
|
[currentGroup release]; |
| 145 |
|
|
currentGroup = cGroup; |
| 146 |
|
|
}/* setCurrentGroup */ |
| 147 |
|
|
- (ABGroup *)currentGroup |
| 148 |
|
|
{ |
| 149 |
|
|
return currentGroup; |
| 150 |
|
|
}/* currentGroup */ |
| 151 |
footashida |
1.4 |
- (void) setComposeController:(ComposeController *)controller{ |
| 152 |
|
|
composeController = controller; |
| 153 |
|
|
[drawer setParentWindow:[composeController window]]; |
| 154 |
|
|
[drawer setContentSize:[addressBookView frame].size]; |
| 155 |
|
|
} |
| 156 |
|
|
- (void)showAddressBookWindow{ |
| 157 |
|
|
NSLog(@"%@", NSStringFromSize([drawer contentSize])); |
| 158 |
|
|
[drawer setContentSize:[drawer minContentSize]]; |
| 159 |
|
|
NSLog(@"%@", NSStringFromSize([drawer contentSize])); |
| 160 |
|
|
|
| 161 |
|
|
[drawer toggle:self]; |
| 162 |
|
|
} |
| 163 |
footashida |
1.1 |
@end |