William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | /*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "AIContactInfoWindowController.h"
#import "AIContactInfoImageViewWithImagePicker.h"
#import <Adium/AIInterfaceControllerProtocol.h>
#import <Adium/AIAccountControllerProtocol.h>
#import <Adium/AIContactAlertsControllerProtocol.h>
#import <Adium/AIListGroup.h>
#import <Adium/AIMetaContact.h>
#import <Adium/AIModularPaneCategoryView.h>
#import <Adium/AIListObject.h>
#import <Adium/AIListOutlineView.h>
#import <Adium/AIService.h>
#import <AIUtilities/AIApplicationAdditions.h>
#import <AIUtilities/AIDictionaryAdditions.h>
#import <AIUtilities/AIImageAdditions.h>
#import <AIUtilities/AIImageViewWithImagePicker.h>
#import <AIUtilities/AIOutlineViewAdditions.h>
#import <AIUtilities/AIStringAdditions.h>
#import <AIUtilities/AITabViewAdditions.h>
#import <QuartzCore/QuartzCore.h>
#define CONTACT_INFO_NIB @"ContactInfoInspector" //Filename of the contact info nib
#define KEY_INFO_WINDOW_FRAME @"Contact Info Inspector Frame" //
#define KEY_INFO_SELECTED_CATEGORY @"Selected Info Category" //
#define CONTACT_INFO_THEME @"Contact Info List Theme"
#define CONTACT_INFO_LAYOUT @"Contact Info List Layout"
//Defines for the image files used by the toolbar segments
#define INFO_SEGMENT_IMAGE (@"info_segment.png")
#define ADDRESS_BOOK_SEGMENT_IMAGE (@"addressbook_segment.png")
#define EVENTS_SEGMENT_IMAGE (@"events_segment.png")
#define ADVANCED_SEGMENT_IMAGE (@"advanced_segment.png")
enum segments {
CONTACT_INFO_SEGMENT = 0,
CONTACT_ADDRESSBOOK_SEGMENT = 1,
CONTACT_EVENTS_SEGMENT = 2,
CONTACT_ADVANCED_SEGMENT = 3,
CONTACT_PLUGINS_SEGMENT = 4
};
@interface AIContactInfoWindowController (PRIVATE)
- (void)configureForDisplayedObject;
-(void)segmentSelected:(id)sender animate:(BOOL)shouldAnimate;
- (void)selectionChanged:(NSNotification *)notification;
- (void)setupToolbarSegments;
- (void)configureToolbarForListObject:(AIListObject *)inObject;
- (void)contactInfoListControllerSelectionDidChangeToListObject:(AIListObject *)listObject;
//View Animation
-(void)addInspectorPanel:(int)newSegment animate:(BOOL)doAnimate;
-(void)animateViewIn:(NSView *)aView;
-(void)animateViewOut:(NSView *)aView;
@end
@interface NSWindow (FakeLeopardAdditions)
- (void)setAutorecalculatesContentBorderThickness:(BOOL)autorecalculateContentBorderThickness forEdge:(NSRectEdge)edge;
- (float)contentBorderThicknessForEdge:(NSRectEdge)edge;
- (void)setContentBorderThickness:(float)borderThickness forEdge:(NSRectEdge)edge;
@end
@implementation AIContactInfoWindowController
static AIContactInfoWindowController *sharedContactInfoInstance = nil;
- (IBAction)segmentSelected:(id)sender
{
[self segmentSelected:sender animate:YES];
}
- (void)segmentSelected:(id)sender animate:(BOOL)shouldAnimate
{
//Action method for the Segmented Control, which is actually the toolbar.
int currentSegment = [sender selectedColumn];
//Take focus away from any textual controls to ensure that they register changes and save
if ([[[self window] firstResponder] isKindOfClass:[NSText class]]) {
[[self window] makeFirstResponder:nil];
}
if(currentSegment != lastSegment) {
[inspectorToolbar deselectAllCells];
}
[inspectorToolbar selectCellAtRow:0 column:currentSegment];
[self addInspectorPanel:currentSegment animate:shouldAnimate];
}
//Return the shared contact info window
+ (AIContactInfoWindowController *)showInfoWindowForListObject:(AIListObject *)listObject
{
//Create the window
if (!sharedContactInfoInstance) {
sharedContactInfoInstance = [[self alloc] initWithWindowNibName:CONTACT_INFO_NIB];
}
[sharedContactInfoInstance setDisplayedListObject:listObject];
[[sharedContactInfoInstance window] makeKeyAndOrderFront:nil];
return sharedContactInfoInstance;
}
//Close the info window
+ (void)closeInfoWindow
{
if (sharedContactInfoInstance) {
[sharedContactInfoInstance closeWindow:nil];
[sharedContactInfoInstance release]; sharedContactInfoInstance = nil;
}
}
- (void)dealloc
{
AILogWithSignature(@"");
deallocating = YES;
[self setDisplayedListObject:nil];
[displayedObject release]; displayedObject = nil;
[loadedContent release]; loadedContent = nil;
[contentController release]; contentController = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (NSString *)adiumFrameAutosaveName
{
return KEY_INFO_WINDOW_FRAME;
}
-(void)windowWillLoad
{
[super windowWillLoad];
//If we are on Leopard, we want our panel to have a finder-esque look.
contentController = [[AIContactInfoContentController defaultInfoContentController] retain];
if(!loadedContent) {
//Load the content array from the content controller.
loadedContent = [[contentController loadedPanes] retain];
}
//Monitor the selected contact
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(selectionChanged:)
name:Interface_ContactSelectionChanged
object:nil];
}
//Setup the window before it is displayed
- (void)windowDidLoad
{
[super windowDidLoad];
//Localization
[self setupToolbarSegments];
currentPane = nil;
lastSegment = 0;
int selectedSegment;
//Select the previously selected category
selectedSegment = [[[adium preferenceController] preferenceForKey:KEY_INFO_SELECTED_CATEGORY
group:PREF_GROUP_WINDOW_POSITIONS] intValue];
if (selectedSegment < 0 || selectedSegment > [inspectorToolbar numberOfColumns])
selectedSegment = 0;
[inspectorToolbar selectCellAtRow:0 column:selectedSegment];
[self segmentSelected:inspectorToolbar];
}
- (void)windowWillClose:(NSNotification *)inNotification
{
AILogWithSignature(@"");
[[adium preferenceController] setPreference:[NSNumber numberWithInt:[inspectorToolbar selectedColumn]]
forKey:KEY_INFO_SELECTED_CATEGORY
group:PREF_GROUP_WINDOW_POSITIONS];
[sharedContactInfoInstance autorelease]; sharedContactInfoInstance = nil;
[super windowWillClose:inNotification];
}
/*
@method setupToolbarSegments
@abstract setupToolbarSegments loads the localized tooltips and images for each toolbar segment
@discussion Since we don't want to enumerate over all of the segments twice, we've combined the
localization and image loading steps into this method.
*/
- (void)setupToolbarSegments
{
int i;
for(i = 0; i < [inspectorToolbar numberOfColumns]; i++) {
NSString *segmentLabel = nil;
NSImage *segmentImage = nil;
switch (i) {
case CONTACT_INFO_SEGMENT:
segmentLabel = AILocalizedString(@"Status and Profile","This segment displays the status and profile information for the selected contact.");
segmentImage = [NSImage imageNamed:INFO_SEGMENT_IMAGE];
break;
case CONTACT_ADDRESSBOOK_SEGMENT:
segmentLabel = AILocalizedString(@"Contact Information", "This segment displays contact and alias information for the selected contact.");
segmentImage = [NSImage imageNamed:ADDRESS_BOOK_SEGMENT_IMAGE];
break;
case CONTACT_EVENTS_SEGMENT:
segmentLabel = AILocalizedString(@"Events", "This segment displays controls for a user to set up events for this contact.");
segmentImage = [NSImage imageNamed:EVENTS_SEGMENT_IMAGE];
break;
case CONTACT_ADVANCED_SEGMENT:
segmentLabel = AILocalizedString(@"Advanced Settings","This segment displays the advanced settings for a contact, including encryption details and account information.");
segmentImage = [NSImage imageNamed:ADVANCED_SEGMENT_IMAGE];
break;
}
[inspectorToolbar setToolTip:segmentLabel forCell:[inspectorToolbar cellAtRow:0 column:i]];
[segmentImage setDataRetained:YES];
[[inspectorToolbar cellAtRow:0 column:i] setImage:segmentImage];
}
}
//When the contact list selection changes, then configure the window for the new contact
- (void)selectionChanged:(NSNotification *)notification
{
AIListObject *object = [[adium interfaceController] selectedListObject];
if (object) {
[self setDisplayedListObject:object];
}
}
- (void)setDisplayedListObject:(AIListObject *)inObject
{
if ([inObject isKindOfClass:[AIListContact class]]) {
inObject = [(AIListContact *)inObject parentContact];
}
if (inObject != displayedObject) {
NSMutableDictionary *notificationUserInfo = [NSMutableDictionary dictionary];;
if (displayedObject)
[notificationUserInfo setObject:displayedObject
forKey:KEY_PREVIOUS_INSPECTED_OBJECT];
if (inObject)
[notificationUserInfo setObject:inObject
forKey:KEY_NEW_INSPECTED_OBJECT];
[displayedObject release];
displayedObject = [inObject retain];
if (!deallocating) {
//Ensure our window is loaded
[self window];
//Configure for the new object
[self configureForDisplayedObject];
}
[[NSNotificationCenter defaultCenter] postNotificationName:AIContactInfoInspectorDidChangeInspectedObject
object:nil
userInfo:notificationUserInfo];
}
}
//Change the list object
- (void)configureForDisplayedObject
{
//Set the title of the window.
if (displayedObject) {
[[self window] setTitle:[NSString stringWithFormat:AILocalizedString(@"%@'s Info",nil), displayedObject.displayName]];
} else {
[[self window] setTitle:AILocalizedString(@"Contact Info",nil)];
}
//Configure each pane for this contact.
for (id<AIContentInspectorPane> pane in loadedContent) {
[pane updateForListObject:displayedObject];
}
}
#pragma mark View Management and Animation
-(void)addInspectorPanel:(int)newSegment animate:(BOOL)doAnimate
{
NSView *newPane = [[loadedContent objectAtIndex:newSegment] inspectorContentView];
if (currentPane == newPane) {
return;
}
if (currentPane) {
// Remove the old pane
[self animateViewOut:currentPane];
[currentPane removeFromSuperview];
}
lastSegment = newSegment;
NSRect paneFrame = [newPane frame], contentBounds = [inspectorContent bounds];
paneFrame.size.width = contentBounds.size.width;
paneFrame.size.height = contentBounds.size.height;
[newPane setFrame:paneFrame];
[inspectorContent addSubview:newPane];
currentPane = newPane;
[self animateViewIn:currentPane];
}
-(void)animateViewIn:(NSView *)aView;
{
NSMutableDictionary *animationDict = [NSMutableDictionary dictionaryWithCapacity:4];
//Set View for animation
[animationDict setObject:aView forKey:NSViewAnimationTargetKey];
//Set View to fade in.
[animationDict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
//Create the animation
NSViewAnimation *viewAnim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:animationDict, nil]];
//Setup the animation
[viewAnim setDuration:0.1];
[viewAnim setAnimationCurve:NSAnimationEaseInOut];
[viewAnim setAnimationBlockingMode:NSAnimationBlocking];
//Start it
[viewAnim startAnimation];
[viewAnim release];
}
-(void)animateViewOut:(NSView *)aView;
{
NSMutableDictionary *animationDict = [NSMutableDictionary dictionaryWithCapacity:3];
//Set View for animation
[animationDict setObject:aView forKey:NSViewAnimationTargetKey];
//Set View to fade out.
[animationDict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
//Create the animation
NSViewAnimation *viewAnim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:animationDict, nil]];
//Setup the animation
[viewAnim setDuration:0.1];
[viewAnim setAnimationCurve:NSAnimationEaseInOut];
[viewAnim setAnimationBlockingMode:NSAnimationBlocking];
//Start it
[viewAnim startAnimation];
[viewAnim release];
}
@end
|