| 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 |
footashida |
1.5 |
- (NSMenu *)createAddressMenu:(id)sender action:(SEL)anAction title:(NSString *)title |
| 7 |
|
|
{ |
| 8 |
|
|
ABAddressBook *ab = [ABAddressBook sharedAddressBook]; |
| 9 |
|
|
|
| 10 |
|
|
NSMenu *newMenu = [[[NSMenu alloc] initWithTitle:@"newItemTitle"] autorelease]; |
| 11 |
|
|
NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:title action:NULL keyEquivalent:@""]; |
| 12 |
|
|
/* |
| 13 |
|
|
NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""]; |
| 14 |
|
|
本来はこっち。後で入れ替え |
| 15 |
|
|
*/ |
| 16 |
|
|
[newMenu addItem:newItem]; |
| 17 |
|
|
[newItem release]; |
| 18 |
|
|
|
| 19 |
|
|
NSEnumerator *enumerator = [group objectEnumerator]; |
| 20 |
|
|
id object; |
| 21 |
|
|
int indexOfGroup = 0; |
| 22 |
|
|
while (object = [enumerator nextObject]) { |
| 23 |
|
|
NSMenuItem *groupItem = [[NSMenuItem alloc] initWithTitle:[object description] action:NULL keyEquivalent:@""]; |
| 24 |
|
|
[newMenu addItem:groupItem]; |
| 25 |
|
|
|
| 26 |
|
|
//とりあえずサブメニュー化 |
| 27 |
|
|
NSMenu *memberMenu = [[NSMenu alloc] initWithTitle:@""]; |
| 28 |
|
|
[groupItem setSubmenu:memberMenu]; |
| 29 |
|
|
|
| 30 |
|
|
//NSLog(@"%d",indexOfGroup); |
| 31 |
|
|
if (!indexOfGroup) { |
| 32 |
|
|
NSArray *member = [[[NSArray alloc] init] autorelease]; |
| 33 |
|
|
member = [ab people]; |
| 34 |
|
|
//NSLog(@"%@",members); |
| 35 |
|
|
NSEnumerator *person = [member objectEnumerator]; |
| 36 |
|
|
id obj; |
| 37 |
|
|
while ((obj = [person nextObject]) != nil) { |
| 38 |
|
|
|
| 39 |
|
|
//NSLog([obj valueForProperty:kABLastNameProperty]); |
| 40 |
|
|
if ([obj valueForProperty:kABLastNameProperty]){ |
| 41 |
|
|
NSMenuItem *personItem = [[NSMenuItem alloc] initWithTitle:[obj valueForProperty:kABLastNameProperty] action:anAction keyEquivalent:@""]; |
| 42 |
|
|
[personItem setTarget:sender]; |
| 43 |
|
|
[memberMenu addItem:personItem]; |
| 44 |
|
|
[personItem release]; |
| 45 |
|
|
} |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
} else { |
| 49 |
|
|
//NSLog(@"%d",indexOfGroup); |
| 50 |
|
|
NSArray *everyGroup = [[[NSArray alloc] init] autorelease]; |
| 51 |
|
|
everyGroup = [ab groups]; |
| 52 |
|
|
ABGroup *mGroup = [everyGroup objectAtIndex:indexOfGroup -1]; |
| 53 |
|
|
//NSLog(@"%@",[mGroup members]); |
| 54 |
|
|
NSArray *member = [[[NSArray alloc] init] autorelease]; |
| 55 |
|
|
member = [mGroup members]; |
| 56 |
|
|
NSEnumerator *person = [member objectEnumerator]; |
| 57 |
|
|
id obj; |
| 58 |
|
|
while ((obj = [person nextObject]) != nil) { |
| 59 |
|
|
|
| 60 |
|
|
if ([obj valueForProperty:kABLastNameProperty]){ |
| 61 |
|
|
NSMenuItem *personItem = [[NSMenuItem alloc] initWithTitle:[obj valueForProperty:kABLastNameProperty] action:anAction keyEquivalent:@""]; |
| 62 |
|
|
[personItem setTarget:sender]; |
| 63 |
|
|
[memberMenu addItem:personItem]; |
| 64 |
|
|
[personItem release]; |
| 65 |
|
|
} |
| 66 |
|
|
} |
| 67 |
|
|
}//if |
| 68 |
|
|
|
| 69 |
|
|
indexOfGroup ++; |
| 70 |
|
|
[groupItem release]; |
| 71 |
|
|
}//while |
| 72 |
|
|
|
| 73 |
|
|
return newMenu; |
| 74 |
|
|
} |
| 75 |
footashida |
1.1 |
- (id)init{ |
| 76 |
|
|
self = [super initWithWindowNibName:@"AddressBook"]; |
| 77 |
|
|
return self; |
| 78 |
|
|
} |
| 79 |
footashida |
1.2 |
-(void)dealloc{ |
| 80 |
|
|
[nameTable release]; |
| 81 |
|
|
[group release]; |
| 82 |
|
|
[currentGroup release]; |
| 83 |
|
|
[super dealloc]; |
| 84 |
|
|
} |
| 85 |
footashida |
1.3 |
-(NSView *)addressBookView{ |
| 86 |
|
|
return addressBookView; |
| 87 |
|
|
} |
| 88 |
footashida |
1.1 |
- (void)windowDidLoad |
| 89 |
|
|
{ |
| 90 |
footashida |
1.3 |
[[self window] setContentView:addressBookView]; |
| 91 |
footashida |
1.4 |
[drawer setContentView:addressBookView]; |
| 92 |
footashida |
1.1 |
[self updateGroup]; |
| 93 |
|
|
}/* windowDidLoad */ |
| 94 |
|
|
|
| 95 |
|
|
- (NSMutableArray *)listGroup |
| 96 |
|
|
{ |
| 97 |
|
|
NSArray *everygroup = [[[NSArray alloc] init] autorelease]; |
| 98 |
|
|
NSMutableArray *aGroup = [[[NSMutableArray alloc] init] autorelease]; |
| 99 |
|
|
|
| 100 |
|
|
[aGroup addObject:@"All"]; |
| 101 |
|
|
|
| 102 |
|
|
ABAddressBook *ab = [ABAddressBook sharedAddressBook]; |
| 103 |
|
|
|
| 104 |
|
|
everygroup = [ab groups]; |
| 105 |
|
|
|
| 106 |
|
|
id obj; |
| 107 |
|
|
NSEnumerator *enumerator = [everygroup objectEnumerator]; |
| 108 |
|
|
while ((obj = [enumerator nextObject]) != nil){ |
| 109 |
|
|
ABGroup *someGroup = obj; |
| 110 |
|
|
[aGroup addObject:[someGroup valueForProperty:kABGroupNameProperty]]; |
| 111 |
|
|
} |
| 112 |
|
|
|
| 113 |
|
|
return aGroup; |
| 114 |
|
|
}/* listGroup*/ |
| 115 |
|
|
|
| 116 |
|
|
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification |
| 117 |
|
|
{ |
| 118 |
|
|
ABAddressBook *ab = [ABAddressBook sharedAddressBook]; |
| 119 |
|
|
//NSLog(@"aNotification"); |
| 120 |
|
|
//NSLog(@"%d",[[aNotification object] selectedRow]); |
| 121 |
|
|
//NSLog(@"%@",[[[aNotification object] dataSource] group]); |
| 122 |
|
|
if ([[aNotification object] selectedRow] == -1){ |
| 123 |
|
|
[self setCurrentGroup:nil]; |
| 124 |
|
|
[self updateUI]; |
| 125 |
|
|
} else if (![[aNotification object] selectedRow]){ |
| 126 |
|
|
|
| 127 |
|
|
ABGroup *all =[[[ABGroup alloc] init] autorelease]; |
| 128 |
|
|
NSEnumerator *enumerator = [[ab people] objectEnumerator]; |
| 129 |
|
|
id obj; |
| 130 |
|
|
|
| 131 |
|
|
while ((obj = [enumerator nextObject]) != nil){ |
| 132 |
|
|
[all addMember:obj]; |
| 133 |
|
|
} |
| 134 |
|
|
|
| 135 |
|
|
[self setCurrentGroup:all]; |
| 136 |
|
|
[self updateUI]; |
| 137 |
|
|
} else { |
| 138 |
|
|
NSArray *everygroup = [[[NSArray alloc] init] autorelease]; |
| 139 |
|
|
everygroup = [ab groups]; |
| 140 |
|
|
ABGroup *someGroup = [everygroup objectAtIndex:[[aNotification object] selectedRow]-1]; |
| 141 |
|
|
[self setCurrentGroup:someGroup]; |
| 142 |
|
|
[self updateUI]; |
| 143 |
|
|
} |
| 144 |
|
|
}/* tableViewSelectionDidChange */ |
| 145 |
|
|
|
| 146 |
|
|
-(void) updateUI |
| 147 |
|
|
{ |
| 148 |
|
|
[nameTable reloadData]; |
| 149 |
|
|
}/* updateUI */ |
| 150 |
|
|
|
| 151 |
|
|
- (void) updateGroup |
| 152 |
|
|
{ |
| 153 |
|
|
group = [[NSMutableArray alloc] init]; |
| 154 |
|
|
[self setGroup:[self listGroup]]; |
| 155 |
|
|
}/* updateGroup */ |
| 156 |
|
|
|
| 157 |
|
|
// ---------------------------------------------------------------------------------------- |
| 158 |
|
|
// NSTableDataSource |
| 159 |
|
|
// ---------------------------------------------------------------------------------------- |
| 160 |
|
|
|
| 161 |
|
|
- (int)numberOfRowsInTableView:(NSTableView *)aTableView |
| 162 |
|
|
{ |
| 163 |
|
|
return [[currentGroup members] count]; |
| 164 |
|
|
}/* numberOfRowsInTableView */ |
| 165 |
|
|
|
| 166 |
|
|
- (id)tableView:(NSTableView *)aTableView |
| 167 |
|
|
objectValueForTableColumn:(NSTableColumn *)aTableColumn |
| 168 |
|
|
row:(int)rowIndex |
| 169 |
|
|
{ |
| 170 |
|
|
//NSDictionary *dictionary = [array objectAtIndex:rowIndex]; |
| 171 |
|
|
//return [dictionary objectForKey:[aTableColumn identifier]]; |
| 172 |
|
|
|
| 173 |
|
|
ABPerson *theRecord; |
| 174 |
|
|
id theValue; |
| 175 |
|
|
ABPropertyType type = [ABPerson typeOfProperty:[aTableColumn identifier]]; |
| 176 |
|
|
theRecord = [[currentGroup members] objectAtIndex:rowIndex]; |
| 177 |
|
|
|
| 178 |
|
|
//First,Last,Email,Phone |
| 179 |
|
|
|
| 180 |
|
|
if ( type & kABMultiValueMask ) { |
| 181 |
|
|
ABMultiValue *mValue = [theRecord valueForProperty:[aTableColumn identifier]]; |
| 182 |
|
|
int index = [mValue indexForIdentifier:[mValue primaryIdentifier]]; |
| 183 |
|
|
theValue = [mValue valueAtIndex:index]; |
| 184 |
|
|
} else { |
| 185 |
|
|
theValue = [theRecord valueForProperty:[aTableColumn identifier]]; |
| 186 |
|
|
} |
| 187 |
|
|
|
| 188 |
|
|
return theValue; |
| 189 |
|
|
}/* tableView */ |
| 190 |
|
|
|
| 191 |
|
|
|
| 192 |
|
|
|
| 193 |
|
|
// ---------------------------------------------------------------------------------------- |
| 194 |
|
|
// アクセッサメソッド |
| 195 |
|
|
// ---------------------------------------------------------------------------------------- |
| 196 |
|
|
|
| 197 |
|
|
|
| 198 |
|
|
- (void) setGroup:(NSMutableArray *)aGroup |
| 199 |
|
|
{ |
| 200 |
|
|
[aGroup retain]; |
| 201 |
|
|
[group release]; |
| 202 |
|
|
group = aGroup; |
| 203 |
|
|
}/* setGroup */ |
| 204 |
|
|
|
| 205 |
|
|
- (NSMutableArray *)group |
| 206 |
|
|
{ |
| 207 |
|
|
return group; |
| 208 |
|
|
}/* group */ |
| 209 |
|
|
|
| 210 |
|
|
- (void) setCurrentGroup:(ABGroup *)cGroup |
| 211 |
|
|
{ |
| 212 |
|
|
[cGroup retain]; |
| 213 |
|
|
[currentGroup release]; |
| 214 |
|
|
currentGroup = cGroup; |
| 215 |
|
|
}/* setCurrentGroup */ |
| 216 |
|
|
- (ABGroup *)currentGroup |
| 217 |
|
|
{ |
| 218 |
|
|
return currentGroup; |
| 219 |
|
|
}/* currentGroup */ |
| 220 |
footashida |
1.6 |
- (void) setWindowController:(id)controller{ |
| 221 |
|
|
if(!windowController){ |
| 222 |
|
|
[windowController release]; |
| 223 |
|
|
} |
| 224 |
|
|
windowController = controller; |
| 225 |
|
|
[windowController retain]; |
| 226 |
|
|
[drawer setParentWindow:[windowController window]]; |
| 227 |
footashida |
1.4 |
[drawer setContentSize:[addressBookView frame].size]; |
| 228 |
|
|
} |
| 229 |
|
|
- (void)showAddressBookWindow{ |
| 230 |
|
|
[drawer setContentSize:[drawer minContentSize]]; |
| 231 |
|
|
[drawer toggle:self]; |
| 232 |
footashida |
1.5 |
} |
| 233 |
|
|
- (NSMenu *)addressMenu{ |
| 234 |
|
|
// このメソッドは使いません |
| 235 |
|
|
// return [self makeAddressMenu]; |
| 236 |
|
|
return nil; |
| 237 |
footashida |
1.4 |
} |
| 238 |
footashida |
1.1 |
@end |