Source/AIDockController.m
author Frank Dowsett <wixardy@adium.im>
Fri, 18 Feb 2011 15:44:06 -0500
changeset 3670 add0c83648a5
parent 3092 ffb42621b742
child 3673 c3cc8fe8f018
permissions -rw-r--r--
Massive changes to dock icon drawing:
- Use NSDockTile for badging fixes #13439
- Remove flashing of the contact name* fixes #14452
- Use a constant size instead of the current screen's size fixes #13088

Fixes #616

*It's superfluous and may have been broken in 1.3 based on the reports from after 1.4 was released.
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     1
/* 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     2
 * Adium is the legal property of its developers, whose names are listed in the copyright file included
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     3
 * with this source distribution.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     4
 * 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     6
 * General Public License as published by the Free Software Foundation; either version 2 of the License,
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     7
 * or (at your option) any later version.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     8
 * 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    10
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    11
 * Public License for more details.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    12
 * 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    13
 * You should have received a copy of the GNU General Public License along with this program; if not,
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    14
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    15
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    16
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    17
// $Id$
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    18
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    19
#import "AIDockController.h"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    20
#import <Adium/AIInterfaceControllerProtocol.h>
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    21
#import <AIUtilities/AIDictionaryAdditions.h>
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    22
#import <AIUtilities/AIFileManagerAdditions.h>
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    23
#import <AIUtilities/AIApplicationAdditions.h>
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    24
#import <Adium/AIChatControllerProtocol.h>
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    25
#import <Adium/AIIconState.h>
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    26
#import <Adium/AIChat.h>
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    27
#import <Adium/AIStatusControllerProtocol.h>
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    28
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    29
#define DOCK_DEFAULT_PREFS			@"DockPrefs"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    30
#define ICON_DISPLAY_DELAY			0.1
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    31
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    32
#define LAST_ICON_UPDATE_VERSION	@"Adium:Last Icon Update Version"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    33
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    34
#define CONTINUOUS_BOUNCE_INTERVAL  0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    35
#define SINGLE_BOUNCE_INTERVAL		999
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    36
#define NO_BOUNCE_INTERVAL			1000
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    37
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    38
#define DOCK_ICON_INTERNAL_PATH		@"../Shared Images/"
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    39
#define DOCK_ICON_SHARED_IMAGES		@"Shared Dock Icon Images"
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    40
84
3b5f51e77592 Switch all of our private method categories over to the new objc way of doing it (documented at http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_4_section_5.html#//apple_ref/doc/uid/TP30001163-CH20-SW2). This enforces having implementations for them, and in the process turned up a vast number of methods we had deleted the impl for but not the declaration. loc -= 198;
David Smith
parents: 75
diff changeset
    41
@interface AIDockController ()
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    42
- (void)_setNeedsDisplay;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    43
- (void)_buildIcon;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    44
- (void)animateIcon:(NSTimer *)timer;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    45
- (void)_singleBounce;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    46
- (BOOL)_continuousBounce;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    47
- (void)_stopBouncing;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    48
- (BOOL)_bounceWithInterval:(double)delay;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    49
- (AIIconState *)iconStateFromStateDict:(NSDictionary *)stateDict folderPath:(NSString *)folderPath;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    50
- (void)updateAppBundleIcon;
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    51
- (void)updateDockView;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    52
- (void)updateDockBadge;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    53
- (void)animateDockIcon;
3092
ffb42621b742 Resolving most* undeclared selectors in Adium.app.
Stephen Holt <sholt@adium.im>
parents: 3088
diff changeset
    54
ffb42621b742 Resolving most* undeclared selectors in Adium.app.
Stephen Holt <sholt@adium.im>
parents: 3088
diff changeset
    55
- (void)appWillChangeActive:(NSNotification *)notification;
ffb42621b742 Resolving most* undeclared selectors in Adium.app.
Stephen Holt <sholt@adium.im>
parents: 3088
diff changeset
    56
- (void)bounceWithTimer:(NSTimer *)timer;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    57
@end
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    58
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    59
@implementation AIDockController
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    60
 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    61
//init and close
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    62
- (id)init
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    63
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    64
	if ((self = [super init])) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    65
		activeIconStateArray = [[NSMutableArray alloc] initWithObjects:@"Base",nil];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    66
		availableDynamicIconStateDict = [[NSMutableDictionary alloc] init];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    67
		currentIconState = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    68
		currentAttentionRequest = -1;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    69
		currentBounceInterval = NO_BOUNCE_INTERVAL;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    70
		animationTimer = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    71
		bounceTimer = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    72
		needsDisplay = NO;
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    73
		unviewedState = NO;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    74
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    75
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    76
	return self;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    77
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    78
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    79
- (void)controllerDidLoad
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    80
{
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    81
	dockTile = [NSApp dockTile];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    82
	view = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 128, 128)];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    83
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    84
	[dockTile setContentView:view];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    85
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    86
	//Register our default preferences
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    87
	[adium.preferenceController registerDefaults:[NSDictionary dictionaryNamed:DOCK_DEFAULT_PREFS
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    88
																	  forClass:[self class]] 
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    89
										forGroup:PREF_GROUP_APPEARANCE];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    90
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    91
	//Observe pref changes
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    92
	[adium.preferenceController registerPreferenceObserver:self forGroup:PREF_GROUP_APPEARANCE];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    93
	// Register as an observer of the status preferences for unread conversation count
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    94
	[adium.preferenceController registerPreferenceObserver:self
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    95
												  forGroup:PREF_GROUP_STATUS_PREFERENCES];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    96
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    97
	[adium.chatController registerChatObserver:self];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
    98
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    99
	NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   100
	
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   101
	//We always want to stop bouncing when Adium is made active
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   102
	[notificationCenter addObserver:self
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   103
	                       selector:@selector(appWillChangeActive:) 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   104
	                           name:NSApplicationWillBecomeActiveNotification 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   105
	                         object:nil];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   106
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   107
    //We also stop bouncing when Adium is no longer active
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   108
    [notificationCenter addObserver:self
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   109
	                       selector:@selector(appWillChangeActive:) 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   110
	                           name:NSApplicationWillResignActiveNotification 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   111
	                         object:nil];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   112
	
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   113
	//If Adium has been upgraded since the last time we ran re-apply the user's custom icon
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   114
	NSString	*lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:LAST_ICON_UPDATE_VERSION];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   115
	if (![[NSApp applicationVersion] isEqualToString:lastVersion]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   116
		[self updateAppBundleIcon];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   117
		[[NSUserDefaults standardUserDefaults] setObject:[NSApp applicationVersion] forKey:LAST_ICON_UPDATE_VERSION];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   118
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   119
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   120
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   121
- (void)controllerWillClose
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   122
{
95
47acbc0cc17a Propertyize AIListObject and convert some more controller accesses to dot syntax
David Smith
parents: 84
diff changeset
   123
	[adium.preferenceController unregisterPreferenceObserver:self];
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   124
	[adium.chatController unregisterChatObserver:self];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   125
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   126
	//Reset our icon by removing all icon states (except for the base state)
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   127
	NSArray *stateArrayCopy = [[activeIconStateArray copy] autorelease]; //Work with a copy, since this array will change as we remove states
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   128
	NSEnumerator *enumerator = [stateArrayCopy objectEnumerator];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   129
	[enumerator nextObject]; //Skip the first icon
2115
699ae94cb727 Peter points out I can fast enumerate on an enumerator to still cleanly get the skip-first-object behavior here
David Smith <catfish.man@gmail.com>
parents: 2102
diff changeset
   130
	for (NSString *iconState in enumerator) {
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   131
		[self removeIconStateNamed:iconState];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   132
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   133
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   134
	//Force the icon to update
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   135
	[self _buildIcon];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   136
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   137
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   138
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   139
#pragma mark Dock Icon Packs
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   140
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   141
 * @brief Returns an array of available dock icon pack paths
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   142
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   143
- (NSArray *)availableDockIconPacks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   144
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   145
	NSMutableArray * iconPackPaths = [NSMutableArray array]; //this will be the folder path for old packs, and the bundle resource path for new
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   146
	for (NSString *path in [adium allResourcesForName:FOLDER_DOCK_ICONS withExtensions:@"AdiumIcon"]) {
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   147
		NSBundle *xtraBundle = [NSBundle bundleWithPath:path];
3
f0cc4d307eb8 Merge 64 bit branch to trunk. Fingers crossed, and I have been testing it some, but expect fallout from this. 11,000 line diffs are rarely without consequence ;)
David Smith
parents: 0
diff changeset
   148
		if (xtraBundle && ([[xtraBundle objectForInfoDictionaryKey:@"XtraBundleVersion"] integerValue] == 1))//This checks for a new-style xtra
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   149
			path = [xtraBundle resourcePath];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   150
		[iconPackPaths addObject:path];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   151
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   152
	return iconPackPaths;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   153
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   154
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   155
//Load an icon pack
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   156
- (NSMutableDictionary *)iconPackAtPath:(NSString *)folderPath
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   157
{
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   158
	//Load the icon pack
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   159
	NSDictionary *iconPackDict = [NSDictionary dictionaryWithContentsOfFile:[folderPath stringByAppendingPathComponent:@"IconPack.plist"]];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   160
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   161
	NSMutableDictionary *iconStateDict = [NSMutableDictionary dictionary];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   162
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   163
	//Process each state in the icon pack, adding it to the iconStateDict
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   164
	for (NSString *stateNameKey in [iconPackDict objectForKey:@"State"]) {
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   165
		NSDictionary *stateDict = [[iconPackDict objectForKey:@"State"] objectForKey:stateNameKey];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   166
		AIIconState *iconState = [self iconStateFromStateDict:stateDict folderPath:folderPath];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   167
		if (iconState)
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   168
			[iconStateDict setObject:iconState forKey:stateNameKey];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   169
	}
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   170
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   171
	return [NSMutableDictionary dictionaryWithObjectsAndKeys:[iconPackDict objectForKey:@"Description"], @"Description", iconStateDict, @"State", nil];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   172
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   173
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   174
- (AIIconState *)previewStateForIconPackAtPath:(NSString *)folderPath
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   175
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   176
	AIIconState	*previewState = nil;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   177
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   178
	[self getName:NULL previewState:&previewState forIconPackAtPath:folderPath];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   179
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   180
	return previewState;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   181
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   182
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   183
/*!
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   184
 * @brief Get the name and preview state for a dock icon pack
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   185
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   186
 * @param outName Reference to an NSString, or NULL if this information is not needed
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   187
 * @param outIconState Reference to an AIIconState, or NULL if this information is not needed
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   188
 * @param folderPath The path to the dock icon pack
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   189
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   190
- (void)getName:(NSString **)outName previewState:(AIIconState **)outIconState forIconPackAtPath:(NSString *)folderPath
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   191
{
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   192
	//Load the icon pack
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   193
	NSDictionary *iconPackDict = [NSDictionary dictionaryWithContentsOfFile:[folderPath stringByAppendingPathComponent:@"IconPack.plist"]];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   194
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   195
	//Load the preview state
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   196
	NSDictionary *stateDict = [[iconPackDict objectForKey:@"State"] objectForKey:@"Preview"];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   197
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   198
	if (outIconState) *outIconState = [self iconStateFromStateDict:stateDict folderPath:folderPath];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   199
	if (outName) *outName = [[iconPackDict objectForKey:@"Description"] objectForKey:@"Title"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   200
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   201
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   202
- (AIIconState *)iconStateFromStateDict:(NSDictionary *)stateDict folderPath:(NSString *)folderPath
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   203
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   204
	AIIconState		*iconState = nil;
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   205
	//Get the state information
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   206
	BOOL _overlay = [[stateDict objectForKey:@"Overlay"] boolValue];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   207
	BOOL looping = [[stateDict objectForKey:@"Looping"] boolValue];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   208
	
3
f0cc4d307eb8 Merge 64 bit branch to trunk. Fingers crossed, and I have been testing it some, but expect fallout from this. 11,000 line diffs are rarely without consequence ;)
David Smith
parents: 0
diff changeset
   209
	if ([[stateDict objectForKey:@"Animated"] integerValue]) { //Animated State
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   210
		NSMutableDictionary	*tempIconCache = [NSMutableDictionary dictionary];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   211
		
3087
30703336e5b6 Resolve implicit 64->32 bit castings in Adium.app
Stephen Holt <sholt@adium.im>
parents: 3034
diff changeset
   212
		CGFloat delay   = (CGFloat)[[stateDict objectForKey:@"Delay"] doubleValue];
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   213
		NSArray *imageNameArray = [stateDict objectForKey:@"Images"];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   214
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   215
		//Load the images
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   216
		NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:[imageNameArray count]];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   217
		for (NSString *imageName in imageNameArray) {
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   218
			NSString	*imagePath;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   219
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   220
			if ([imageName hasPrefix:DOCK_ICON_INTERNAL_PATH]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   221
				//Special hack for all the incorrectly made icon packs we have floating around out there :P
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   222
				imageName = [imageName substringFromIndex:[DOCK_ICON_INTERNAL_PATH length]];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   223
				imagePath = [[NSBundle mainBundle] pathForResource:[[[imageName stringByDeletingPathExtension] stringByAppendingString:@"-localized"] stringByAppendingPathExtension:[imageName pathExtension]]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   224
				                                            ofType:@""
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   225
				                                       inDirectory:DOCK_ICON_SHARED_IMAGES];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   226
				
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   227
				if (!imagePath) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   228
					imagePath = [[NSBundle mainBundle] pathForResource:imageName
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   229
																ofType:@""
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   230
														   inDirectory:DOCK_ICON_SHARED_IMAGES];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   231
				}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   232
			} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   233
				imagePath = [folderPath stringByAppendingPathComponent:imageName];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   234
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   235
			
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   236
			NSImage *image = [tempIconCache objectForKey:imagePath]; //We re-use the same images for each state if possible to lower memory usage.
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   237
			if (!image && imagePath) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   238
				image = [[[NSImage alloc] initByReferencingFile:imagePath] autorelease];
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   239
				if (image)
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   240
					[tempIconCache setObject:image forKey:imagePath];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   241
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   242
			
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   243
			if (image)
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   244
				[imageArray addObject:image];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   245
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   246
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   247
		//Create the state
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   248
		if (delay != 0 && [imageArray count] != 0) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   249
			iconState = [[AIIconState alloc] initWithImages:imageArray
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   250
													  delay:delay
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   251
													looping:looping
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   252
													overlay:_overlay];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   253
		} else {
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   254
			NSLog(@"Invalid animated icon state");
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   255
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   256
	} else { //Static State
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   257
		NSString	*imageName;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   258
		NSString	*imagePath;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   259
		NSImage		*image;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   260
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   261
		imageName = [stateDict objectForKey:@"Image"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   262
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   263
		if ([imageName hasPrefix:DOCK_ICON_INTERNAL_PATH]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   264
			//Special hack for all the incorrectly made icon packs we have floating around out there :P
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   265
			imageName = [imageName substringFromIndex:[DOCK_ICON_INTERNAL_PATH length]];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   266
			imagePath = [[NSBundle mainBundle] pathForResource:[[[imageName stringByDeletingPathExtension] stringByAppendingString:@"-localized"] stringByAppendingPathExtension:[imageName pathExtension]]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   267
														ofType:@""
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   268
												   inDirectory:DOCK_ICON_SHARED_IMAGES];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   269
			if (!imagePath) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   270
				imagePath = [[NSBundle mainBundle] pathForResource:imageName
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   271
															ofType:@""
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   272
													   inDirectory:DOCK_ICON_SHARED_IMAGES];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   273
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   274
		} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   275
			imagePath = [folderPath stringByAppendingPathComponent:imageName];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   276
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   277
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   278
		//Get the state information
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   279
		image = [[NSImage alloc] initByReferencingFile:imagePath];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   280
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   281
		//Create the state
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   282
		iconState = [[AIIconState alloc] initWithImage:image overlay:_overlay];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   283
		[image release];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   284
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   285
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   286
	return [iconState autorelease];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   287
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   288
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   289
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   290
 * @brief Does the current icon know how to display a given state?
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   291
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   292
- (BOOL)currentIconSupportsIconStateNamed:(NSString *)inName
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   293
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   294
	return ([[availableIconStateDict objectForKey:@"State"] objectForKey:inName] != nil);
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   295
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   296
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   297
//Set an icon state from our currently loaded icon pack
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   298
- (void)setIconStateNamed:(NSString *)inName
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   299
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   300
	if (![activeIconStateArray containsObject:inName]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   301
		[activeIconStateArray addObject:inName];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   302
		[self _setNeedsDisplay];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   303
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   304
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   305
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   306
//Remove an active icon state
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   307
- (void)removeIconStateNamed:(NSString *)inName
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   308
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   309
	if ([activeIconStateArray containsObject:inName]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   310
		[activeIconStateArray removeObject:inName];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   311
		[self _setNeedsDisplay];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   312
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   313
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   314
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   315
//Set a custom icon state
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   316
- (void)setIconState:(AIIconState *)iconState named:(NSString *)inName
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   317
{
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   318
	[availableDynamicIconStateDict setObject:iconState forKey:inName]; //Add the new state to our available dict
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   319
	[self setIconStateNamed:inName]; //Set it
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   320
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   321
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   322
#pragma mark Controller
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   323
- (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   324
							object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   325
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   326
	if ([group isEqualToString:PREF_GROUP_APPEARANCE]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   327
		if (!key || [key isEqualToString:KEY_ACTIVE_DOCK_ICON]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   328
			//Load the new icon pack
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   329
			NSString *iconPath = [adium pathOfPackWithName:[prefDict objectForKey:KEY_ACTIVE_DOCK_ICON]
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   330
												 extension:@"AdiumIcon"
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   331
										resourceFolderName:FOLDER_DOCK_ICONS];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   332
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   333
			if (iconPath) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   334
				NSMutableDictionary	*newAvailableIconStateDict = [self iconPackAtPath:iconPath];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   335
				if (newAvailableIconStateDict) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   336
					[availableIconStateDict autorelease];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   337
					availableIconStateDict = [newAvailableIconStateDict retain];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   338
				}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   339
			}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   340
			
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   341
			//Write the icon to the Adium application bundle so that Finder will see it.
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   342
			//On launch we only need to update the icon file if this is a new version of Adium.
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   343
			//When preferences change we always want to update it
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   344
			if (!firstTime) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   345
				[self updateAppBundleIcon];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   346
			}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   347
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   348
			//Recomposite the icon
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   349
			[self _setNeedsDisplay];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   350
		}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   351
		else if (!key || [key isEqualToString:KEY_BADGE_DOCK_ICON]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   352
			BOOL newShouldBadge = [[prefDict objectForKey:KEY_BADGE_DOCK_ICON] boolValue];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   353
			if (newShouldBadge != shouldBadge) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   354
				shouldBadge = newShouldBadge;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   355
				
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   356
				[self updateDockBadge];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   357
			}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   358
		}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   359
		else if (!key || [key isEqualToString:KEY_ANIMATE_DOCK_ICON]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   360
			BOOL newAnimateDockIcon = [[prefDict objectForKey:KEY_ANIMATE_DOCK_ICON] boolValue];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   361
			if (newAnimateDockIcon != animateDockIcon) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   362
				animateDockIcon = newAnimateDockIcon;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   363
				
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   364
				[self animateDockIcon];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   365
			}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   366
		}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   367
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   368
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   369
	if ([group isEqualToString:PREF_GROUP_STATUS_PREFERENCES]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   370
		if (!key || [key isEqualToString:KEY_STATUS_CONVERSATION_COUNT]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   371
			BOOL newShowConversationCount = [[prefDict objectForKey:KEY_STATUS_CONVERSATION_COUNT] boolValue];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   372
			if (newShowConversationCount != showConversationCount) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   373
				showConversationCount = newShowConversationCount;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   374
				
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   375
				[self updateDockBadge];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   376
			}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   377
		}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   378
		else if ([key isEqualToString:KEY_STATUS_MENTION_COUNT]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   379
			//Just update as the counting is handled elsewhere
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   380
			[self updateDockBadge];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   381
		}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   382
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   383
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   384
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   385
//Icons ------------------------------------------------------------------------------------
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   386
- (void)_setNeedsDisplay
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   387
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   388
	if (!needsDisplay) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   389
		needsDisplay = YES;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   390
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   391
		//Invoke a display after a short delay
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   392
		[NSTimer scheduledTimerWithTimeInterval:ICON_DISPLAY_DELAY
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   393
										 target:self
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   394
									   selector:@selector(_buildIcon)
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   395
									   userInfo:nil
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   396
										repeats:NO];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   397
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   398
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   399
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   400
- (void)updateAppBundleIcon
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   401
{	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   402
	NSImage *image = [[[availableIconStateDict objectForKey:@"State"] objectForKey:@"ApplicationIcon"] image];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   403
	if (!image)
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   404
		image = [[[availableIconStateDict objectForKey:@"State"] objectForKey:@"Base"] image];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   405
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   406
	if (image) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   407
		[[NSWorkspace sharedWorkspace] setIcon:image
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   408
									   forFile:[[NSBundle mainBundle] bundlePath]
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   409
									   options:0];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   410
		
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   411
		//Finder won't update Adium's icon to match the new one until it is restarted if we don't
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   412
		//tell NSWorkspace to note the change.
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   413
		[[NSWorkspace sharedWorkspace] noteFileSystemChanged:[[NSBundle mainBundle] bundlePath]];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   414
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   415
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   416
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   417
/*!
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   418
 * @brief Return the dock icon image without any auxiliary states
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   419
 */
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   420
- (NSImage *)baseApplicationIconImage
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   421
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   422
	NSDictionary	*availableIcons = [availableIconStateDict objectForKey:@"State"];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   423
	AIIconState		*baseState = [availableIcons objectForKey:@"Base"];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   424
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   425
	if (baseState) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   426
		AIIconState		*iconState = [[[AIIconState alloc] initByCompositingStates:[NSArray arrayWithObject:baseState]] autorelease];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   427
		return [iconState image];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   428
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   429
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   430
	return nil;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   431
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   432
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   433
- (void)setOverlay:(NSImage *)newImage
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   434
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   435
	[overlay release];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   436
	overlay = [newImage retain];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   437
	[self updateDockView];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   438
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   439
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   440
//Build/Pre-render the icon images, start/stop animation
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   441
- (void)_buildIcon
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   442
{
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   443
	NSMutableArray	*iconStates = [NSMutableArray array];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   444
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   445
	//Stop any existing animation
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   446
	[animationTimer invalidate]; [animationTimer release]; animationTimer = nil;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   447
	if (observingFlash) {
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   448
		[adium.interfaceController unregisterFlashObserver:self];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   449
		observingFlash = NO;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   450
	}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   451
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   452
	//Build an array of the valid active icon states
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   453
	NSDictionary *availableIcons = [availableIconStateDict objectForKey:@"State"];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   454
	for (NSString *name in activeIconStateArray) {
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   455
		AIIconState *state = [availableIcons objectForKey:name];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   456
		if (!state)
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   457
			state = [availableDynamicIconStateDict objectForKey:name];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   458
		if (state)
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   459
			[iconStates addObject:state];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   460
	}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   461
3034
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   462
	@try {
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   463
		//Generate the composited icon state
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   464
		[currentIconState release];
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   465
		currentIconState = [[AIIconState alloc] initByCompositingStates:iconStates];
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   466
		
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   467
		if (![currentIconState animated]) { //Static icon
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   468
			[self updateDockView];
3034
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   469
		} else { //Animated icon
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   470
			//Our dock icon can run its animation at any speed, but we want to try and sync it with the global Adium flashing.  To do this, we delay starting our timer until the next flash occurs.
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   471
			[adium.interfaceController registerFlashObserver:self];
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   472
			observingFlash = YES;
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   473
			
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   474
			//Set the first frame of our animation
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   475
			[self animateIcon:nil]; //Set the icon and move to the next frame
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   476
		}
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   477
	}
3034
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   478
	@catch (NSException *exception) {
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   479
		if ([[exception name] isEqualToString:NSImageCacheException])
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   480
			currentIconState = nil;
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   481
	}
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   482
	@finally {
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   483
		needsDisplay = NO;
179a22b315e7 Patch from Luca Motta ('''lucamot''') which fixes #13537 ("Dock icon not updating after system is put to sleep"). Thanks!
Evan Schoenberg
parents: 2115
diff changeset
   484
	}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   485
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   486
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   487
- (void)flash:(int)value
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   488
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   489
    //Start the flash timer
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   490
    animationTimer = [[NSTimer scheduledTimerWithTimeInterval:[currentIconState animationDelay]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   491
                                                       target:self
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   492
                                                     selector:@selector(animateIcon:)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   493
                                                     userInfo:nil
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   494
                                                      repeats:YES] retain];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   495
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   496
    //Animate the icon
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   497
    [self animateIcon:animationTimer]; //Set the icon and move to the next frame
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   498
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   499
    //Once our animations stops, we no longer need to observe flashing
100
68210ab2807a sed is evil. All [adium *Controller]s are now adium.*Controller.
David Smith
parents: 95
diff changeset
   500
    [adium.interfaceController unregisterFlashObserver:self];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   501
    observingFlash = NO;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   502
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   503
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   504
//Move the dock to the next animation frame (Assumes the current state is animated)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   505
- (void)animateIcon:(NSTimer *)timer
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   506
{
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   507
	//Move to the next image
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   508
	if (timer) {
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   509
		[currentIconState nextFrame];
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   510
		[self updateDockView];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   511
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   512
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   513
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   514
//Bouncing -------------------------------------------------------------------------------------------------------------
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   515
#pragma mark Bouncing
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   516
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   517
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   518
 * @brief Perform a bouncing behavior
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   519
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   520
 * @result YES if the behavior is ongoing; NO if it isn't (because it is immediately complete or some other, faster continuous behavior is in progress)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   521
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   522
- (BOOL)performBehavior:(AIDockBehavior)behavior
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   523
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   524
	BOOL	ongoingBehavior = NO;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   525
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   526
	//Start up the new behavior
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   527
	switch (behavior) {
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   528
		case AIDockBehaviorStopBouncing: {
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   529
			[self _stopBouncing];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   530
			break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   531
		}
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   532
		case AIDockBehaviorBounceOnce: {
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   533
			if (currentBounceInterval >= SINGLE_BOUNCE_INTERVAL) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   534
				currentBounceInterval = SINGLE_BOUNCE_INTERVAL;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   535
				[self _singleBounce];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   536
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   537
			break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   538
		}
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   539
		case AIDockBehaviorBounceRepeatedly: ongoingBehavior = [self _continuousBounce]; break;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   540
		case AIDockBehaviorBounceDelay_FiveSeconds: ongoingBehavior = [self _bounceWithInterval:5.0]; break;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   541
		case AIDockBehaviorBounceDelay_TenSeconds: ongoingBehavior = [self _bounceWithInterval:10.0]; break;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   542
		case AIDockBehaviorBounceDelay_FifteenSeconds: ongoingBehavior = [self _bounceWithInterval:15.0]; break;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   543
		case AIDockBehaviorBounceDelay_ThirtySeconds: ongoingBehavior = [self _bounceWithInterval:30.0]; break;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   544
		case AIDockBehaviorBounceDelay_OneMinute: ongoingBehavior = [self _bounceWithInterval:60.0]; break;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   545
	}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   546
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   547
	return ongoingBehavior;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   548
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   549
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   550
//Return a string description of the bouncing behavior
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   551
- (NSString *)descriptionForBehavior:(AIDockBehavior)behavior
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   552
{
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   553
	switch (behavior) {
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   554
		case AIDockBehaviorStopBouncing: return AILocalizedString(@"None",nil);
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   555
		case AIDockBehaviorBounceOnce: return AILocalizedString(@"Once",nil);
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   556
		case AIDockBehaviorBounceRepeatedly: return AILocalizedString(@"Repeatedly",nil);
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   557
		case AIDockBehaviorBounceDelay_FiveSeconds: return AILocalizedString(@"Every 5 Seconds",nil);
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   558
		case AIDockBehaviorBounceDelay_TenSeconds: return AILocalizedString(@"Every 10 Seconds",nil);
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   559
		case AIDockBehaviorBounceDelay_FifteenSeconds: return AILocalizedString(@"Every 15 Seconds",nil);
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   560
		case AIDockBehaviorBounceDelay_ThirtySeconds: return AILocalizedString(@"Every 30 Seconds",nil);
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   561
		case AIDockBehaviorBounceDelay_OneMinute: return AILocalizedString(@"Every 60 Seconds",nil);
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   562
		default: return @"";
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   563
	}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   564
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   565
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   566
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   567
 * @brief Start a delayed, repeated bounce
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   568
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   569
 * @result YES if we are now bouncing more frequently than before; NO if this call had no effect
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   570
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   571
- (BOOL)_bounceWithInterval:(NSTimeInterval)delay
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   572
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   573
	//Bounce only if the new delay is a faster bounce than the current one
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   574
	if (delay < currentBounceInterval) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   575
		[self _singleBounce]; // do one right away
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   576
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   577
		currentBounceInterval = delay;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   578
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   579
		bounceTimer = [[NSTimer scheduledTimerWithTimeInterval:delay
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   580
														target:self
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   581
													  selector:@selector(bounceWithTimer:)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   582
													  userInfo:nil
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   583
													   repeats:YES] retain];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   584
		
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   585
		return YES;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   586
	}
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   587
	return NO;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   588
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   589
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   590
//Activated by the time after each delay
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   591
- (void)bounceWithTimer:(NSTimer *)timer
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   592
{
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   593
	//Bounce
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   594
	[self _singleBounce];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   595
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   596
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   597
//Bounce once via NSApp's NSInformationalRequest (also used by the timer to perform a single bounce)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   598
- (void)_singleBounce
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   599
{
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   600
	currentAttentionRequest = [NSApp requestUserAttention:NSInformationalRequest];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   601
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   602
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   603
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   604
 * @brief Bounce continuously via NSApp's NSCriticalRequest
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   605
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   606
 * We will bounce until we become the active application or our dock icon is clicked
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   607
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   608
 * @result YES if we are now bouncing more frequently than before; NO if this call had no effect
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   609
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   610
- (BOOL)_continuousBounce
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   611
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   612
	if (CONTINUOUS_BOUNCE_INTERVAL < currentBounceInterval) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   613
		currentBounceInterval = CONTINUOUS_BOUNCE_INTERVAL;
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   614
		currentAttentionRequest = [NSApp requestUserAttention:NSCriticalRequest];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   615
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   616
		return YES;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   617
	}
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   618
	return NO;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   619
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   620
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   621
//Stop bouncing
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   622
- (void)_stopBouncing
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   623
{
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   624
	//Stop any timer
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   625
	if (bounceTimer) {
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   626
		[bounceTimer invalidate];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   627
		[bounceTimer release];
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   628
		bounceTimer = nil;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   629
	}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   630
2102
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   631
	//Stop any continuous bouncing
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   632
	if (currentAttentionRequest != -1) {
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   633
		[NSApp cancelUserAttentionRequest:currentAttentionRequest];
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   634
		currentAttentionRequest = -1;
e391e3c13aa7 Code cleanup; C99 use, fast enumeration, indentation, judicious use of early returns, etc...
David Smith <catfish.man@gmail.com>
parents: 1946
diff changeset
   635
	}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   636
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   637
	currentBounceInterval = NO_BOUNCE_INTERVAL;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   638
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   639
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   640
- (void)appWillChangeActive:(NSNotification *)notification
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   641
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   642
    [self _stopBouncing]; //Stop any bouncing
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   643
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   644
3670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   645
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   646
#pragma mark Dock Drawing
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   647
- (void)updateDockView
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   648
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   649
	NSImage *image = [[[currentIconState image] copy] autorelease];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   650
	if (overlay) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   651
		[image lockFocus];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   652
		[overlay drawInRect:[view frame] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   653
		[image unlockFocus];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   654
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   655
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   656
	[view setImage:image];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   657
	[dockTile setContentView:view];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   658
	[dockTile display];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   659
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   660
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   661
- (void)updateDockBadge
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   662
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   663
	NSInteger contentCount = (showConversationCount ?
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   664
							 [adium.chatController unviewedConversationCount] : [adium.chatController unviewedContentCount]);
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   665
	if (contentCount > 0 && shouldBadge)
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   666
		[dockTile setBadgeLabel:[NSString stringWithFormat:@"%d", contentCount]];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   667
	else
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   668
		[dockTile setBadgeLabel:nil];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   669
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   670
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   671
- (void)animateDockIcon
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   672
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   673
	[self updateDockBadge];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   674
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   675
	if (adium.chatController.unviewedContentCount && animateDockIcon) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   676
		//If this is the first contact with unviewed content, animate the dock
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   677
		if (!unviewedState) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   678
			NSString *iconState;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   679
			if (([adium.statusController.activeStatusState statusType] == AIInvisibleStatusType) &&
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   680
				[self currentIconSupportsIconStateNamed:@"InvisibleAlert"]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   681
				iconState = @"InvisibleAlert";
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   682
			} else {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   683
				iconState = @"Alert";
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   684
			}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   685
			
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   686
			[self setIconStateNamed:iconState];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   687
			unviewedState = YES;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   688
		}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   689
	} else if (unviewedState) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   690
		//If there are no more contacts with unviewed content, stop animating the dock
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   691
		[self removeIconStateNamed:@"Alert"];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   692
		[self removeIconStateNamed:@"InvisibleAlert"];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   693
		unviewedState = NO;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   694
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   695
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   696
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   697
/*!
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   698
 * @brief When a chat has unviewed content update the badge and maybe start/stop the animation
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   699
 */
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   700
- (NSSet *)updateChat:(AIChat *)inChat keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   701
{
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   702
	if (inModifiedKeys == nil || [inModifiedKeys containsObject:KEY_UNVIEWED_CONTENT]) {
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   703
		[self animateDockIcon];
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   704
	}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   705
	
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   706
	return nil;
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   707
}
add0c83648a5 Massive changes to dock icon drawing:
Frank Dowsett <wixardy@adium.im>
parents: 3092
diff changeset
   708
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   709
@end