use a view to draw the badge on Leopard
This commit is contained in:
parent
93caebd82f
commit
731b6379a4
2
NEWS
2
NEWS
|
@ -2,7 +2,7 @@ NEWS file for Transmission <http://transmission.m0k.org/>
|
|||
|
||||
0.92 (2007/xx/yy)
|
||||
- OS X:
|
||||
+ Leopard: Time Machine will ignore incomplete files
|
||||
+ Leopard: Time Machine will ignore incomplete downloads
|
||||
+ Leopard: Fix bug with typing values in Inspector->Options
|
||||
+ Leopard: Fix bug with toggling Minimal View
|
||||
|
||||
|
|
|
@ -126,6 +126,7 @@
|
|||
A2A3065E0AAD24A80049E2AC /* UKFNSubscribeFileWatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A306560AAD24A80049E2AC /* UKFNSubscribeFileWatcher.m */; };
|
||||
A2A306600AAD24A80049E2AC /* UKKQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A306580AAD24A80049E2AC /* UKKQueue.m */; };
|
||||
A2A306620AAD24A80049E2AC /* UKMainThreadProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A3065A0AAD24A80049E2AC /* UKMainThreadProxy.m */; };
|
||||
A2A6321B0CD9751700E3DA60 /* BadgeView.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A6321A0CD9751700E3DA60 /* BadgeView.m */; };
|
||||
A2A6E3A00CA7E4C900F10FEF /* AboutWindow.nib in Resources */ = {isa = PBXBuildFile; fileRef = A2A6E39F0CA7E4C900F10FEF /* AboutWindow.nib */; };
|
||||
A2AA579D0ADFCAB400CA59F6 /* PiecesView.m in Sources */ = {isa = PBXBuildFile; fileRef = A2AA579B0ADFCAB400CA59F6 /* PiecesView.m */; };
|
||||
A2AE68330C628A35008753C9 /* Creator.nib in Resources */ = {isa = PBXBuildFile; fileRef = A2AE68310C628A35008753C9 /* Creator.nib */; };
|
||||
|
@ -469,6 +470,8 @@
|
|||
A2A306580AAD24A80049E2AC /* UKKQueue.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = UKKQueue.m; path = macosx/UKKQueue/UKKQueue.m; sourceTree = "<group>"; };
|
||||
A2A306590AAD24A80049E2AC /* UKMainThreadProxy.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = UKMainThreadProxy.h; path = macosx/UKKQueue/UKMainThreadProxy.h; sourceTree = "<group>"; };
|
||||
A2A3065A0AAD24A80049E2AC /* UKMainThreadProxy.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = UKMainThreadProxy.m; path = macosx/UKKQueue/UKMainThreadProxy.m; sourceTree = "<group>"; };
|
||||
A2A632190CD9751700E3DA60 /* BadgeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BadgeView.h; path = macosx/BadgeView.h; sourceTree = "<group>"; };
|
||||
A2A6321A0CD9751700E3DA60 /* BadgeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BadgeView.m; path = macosx/BadgeView.m; sourceTree = "<group>"; };
|
||||
A2A6E39F0CA7E4C900F10FEF /* AboutWindow.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = AboutWindow.nib; path = macosx/AboutWindow.nib; sourceTree = "<group>"; };
|
||||
A2AA579A0ADFCAB400CA59F6 /* PiecesView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = PiecesView.h; path = macosx/PiecesView.h; sourceTree = "<group>"; };
|
||||
A2AA579B0ADFCAB400CA59F6 /* PiecesView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = PiecesView.m; path = macosx/PiecesView.m; sourceTree = "<group>"; };
|
||||
|
@ -715,6 +718,8 @@
|
|||
A25E74460AF5089E006F11AE /* ExpandedPathToIconTransformer.m */,
|
||||
4DE5CCA50980735700BE280E /* Badger.h */,
|
||||
4DE5CCA60980735700BE280E /* Badger.m */,
|
||||
A2A632190CD9751700E3DA60 /* BadgeView.h */,
|
||||
A2A6321A0CD9751700E3DA60 /* BadgeView.m */,
|
||||
A256588A0A9A695400E8A03B /* MessageWindowController.h */,
|
||||
A256588B0A9A695400E8A03B /* MessageWindowController.m */,
|
||||
A2DF37040C220D03006523C1 /* CreatorWindowController.h */,
|
||||
|
@ -1529,6 +1534,7 @@
|
|||
A257C1820CAD3003004E121C /* PeerTableView.m in Sources */,
|
||||
A2E23AC60CB5E1930002BB25 /* InfoTabButtonCell.m in Sources */,
|
||||
A2399CCD0CD3852300225B2B /* NSApplicationAdditions.m in Sources */,
|
||||
A2A6321B0CD9751700E3DA60 /* BadgeView.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/******************************************************************************
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2007 Transmission authors and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <transmission.h>
|
||||
|
||||
@interface BadgeView : NSView
|
||||
{
|
||||
tr_handle * fLib;
|
||||
|
||||
NSDictionary * fAttributes;
|
||||
}
|
||||
|
||||
- (id) initWithFrame: (NSRect) frame lib: (tr_handle *) lib;
|
||||
|
||||
@end
|
|
@ -0,0 +1,135 @@
|
|||
/******************************************************************************
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2007 Transmission authors and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#import "BadgeView.h"
|
||||
#import "NSStringAdditions.h"
|
||||
|
||||
#define SPEED_BOTTOM_PADDING 2.0
|
||||
#define SPEED_BETWEEN_PADDING 2.0
|
||||
|
||||
@interface BadgeView (Private)
|
||||
|
||||
- (void) badgeString: (NSString *) string forRect: (NSRect) rect;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BadgeView
|
||||
|
||||
- (id) initWithFrame: (NSRect) frame lib: (tr_handle *) lib
|
||||
{
|
||||
if ((self = [super initWithFrame: frame]))
|
||||
{
|
||||
fLib = lib;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) drawRect: (NSRect) rect
|
||||
{
|
||||
[[NSImage imageNamed: @"NSApplicationIcon"] drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
|
||||
|
||||
BOOL checkDownload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeDownloadRate"],
|
||||
checkUpload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeUploadRate"];
|
||||
if (checkDownload || checkUpload)
|
||||
{
|
||||
//set upload and download rate badges
|
||||
NSString * downloadRateString = nil, * uploadRateString = nil;
|
||||
|
||||
float downloadRate, uploadRate;
|
||||
tr_torrentRates(fLib, &downloadRate, &uploadRate);
|
||||
|
||||
if (checkDownload && downloadRate >= 0.1)
|
||||
downloadRateString = [NSString stringForSpeedAbbrev: downloadRate];
|
||||
if (checkUpload && uploadRate >= 0.1)
|
||||
uploadRateString = [NSString stringForSpeedAbbrev: uploadRate];
|
||||
|
||||
if (uploadRateString || downloadRateString)
|
||||
{
|
||||
NSRect badgeRect;
|
||||
badgeRect.size = [[NSImage imageNamed: @"UploadBadge"] size];
|
||||
badgeRect.origin = NSZeroPoint;
|
||||
|
||||
//ignore shadow of badge when placing string
|
||||
NSRect stringRect = badgeRect;
|
||||
stringRect.size.height -= SPEED_BOTTOM_PADDING;
|
||||
stringRect.origin.y += SPEED_BOTTOM_PADDING;
|
||||
|
||||
if (uploadRateString)
|
||||
{
|
||||
//place badge and text
|
||||
[[NSImage imageNamed: @"UploadBadge"] drawInRect: badgeRect fromRect: NSZeroRect
|
||||
operation: NSCompositeSourceOver fraction: 1.0];
|
||||
[self badgeString: uploadRateString forRect: stringRect];
|
||||
}
|
||||
|
||||
if (downloadRateString)
|
||||
{
|
||||
//download rate above upload rate
|
||||
if (uploadRateString)
|
||||
{
|
||||
float spaceBetween = badgeRect.size.height + SPEED_BETWEEN_PADDING;
|
||||
badgeRect.origin.y += spaceBetween;
|
||||
stringRect.origin.y += spaceBetween;
|
||||
}
|
||||
|
||||
//place badge and text
|
||||
[[NSImage imageNamed: @"DownloadBadge"] drawInRect: badgeRect fromRect: NSZeroRect
|
||||
operation: NSCompositeSourceOver fraction: 1.0];
|
||||
[self badgeString: downloadRateString forRect: stringRect];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BadgeView (Private)
|
||||
|
||||
//dock icon must have locked focus
|
||||
- (void) badgeString: (NSString *) string forRect: (NSRect) rect
|
||||
{
|
||||
if (!fAttributes)
|
||||
{
|
||||
NSShadow * stringShadow = [[NSShadow alloc] init];
|
||||
[stringShadow setShadowOffset: NSMakeSize(2.0, -2.0)];
|
||||
[stringShadow setShadowBlurRadius: 4.0];
|
||||
|
||||
#warning center here?
|
||||
fAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSColor whiteColor], NSForegroundColorAttributeName,
|
||||
[NSFont boldSystemFontOfSize: 26.0], NSFontAttributeName, stringShadow, NSShadowAttributeName, nil];
|
||||
|
||||
[stringShadow release];
|
||||
}
|
||||
|
||||
NSSize stringSize = [string sizeWithAttributes: fAttributes];
|
||||
|
||||
//string is in center of image
|
||||
rect.origin.x += (rect.size.width - stringSize.width) * 0.5;
|
||||
rect.origin.y += (rect.size.height - stringSize.height) * 0.5;
|
||||
|
||||
[string drawAtPoint: rect.origin withAttributes: fAttributes];
|
||||
}
|
||||
|
||||
@end
|
|
@ -23,6 +23,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#import "Badger.h"
|
||||
#import "BadgeView.h"
|
||||
#import "NSApplicationAdditions.h"
|
||||
#import "NSStringAdditions.h"
|
||||
|
||||
|
@ -47,6 +48,13 @@
|
|||
fCompleted = 0;
|
||||
fCompletedBadged = 0;
|
||||
fSpeedBadge = NO;
|
||||
|
||||
if ([NSApp isOnLeopardOrBetter])
|
||||
{
|
||||
BadgeView * view = [[BadgeView alloc] initWithFrame: [[[NSApp dockTile] contentView] frame] lib: fLib];
|
||||
[[NSApp dockTile] setContentView: view];
|
||||
[view release];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -62,8 +70,14 @@
|
|||
|
||||
- (void) updateBadge
|
||||
{
|
||||
if ([NSApp isOnLeopardOrBetter])
|
||||
{
|
||||
[[NSApp dockTile] display];
|
||||
return;
|
||||
}
|
||||
|
||||
//set completed badge to top right
|
||||
BOOL completedChange = ![NSApp isOnLeopardOrBetter] && fCompleted != fCompletedBadged;
|
||||
BOOL completedChange = fCompleted != fCompletedBadged;
|
||||
if (completedChange)
|
||||
{
|
||||
fCompletedBadged = fCompleted;
|
||||
|
@ -203,14 +217,16 @@
|
|||
}
|
||||
}
|
||||
|
||||
//for quitting
|
||||
- (void) clearBadge
|
||||
{
|
||||
fCompleted = 0;
|
||||
fCompletedBadged = 0;
|
||||
fSpeedBadge = NO;
|
||||
[NSApp setApplicationIconImage: [NSImage imageNamed: @"NSApplicationIcon"]];
|
||||
if ([NSApp isOnLeopardOrBetter])
|
||||
[[NSApp dockTile] setBadgeLabel: @""];
|
||||
if (![NSApp isOnLeopardOrBetter])
|
||||
{
|
||||
fSpeedBadge = NO;
|
||||
fCompleted = 0;
|
||||
fCompletedBadged = 0;
|
||||
[NSApp setApplicationIconImage: nil];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue