From eaf4ecc37a6bd8fc20aea0f5e2189198dd6a1e97 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Thu, 24 Apr 2008 21:24:42 +0000 Subject: [PATCH] don't redraw the dock tile if there is no change --- Transmission.xcodeproj/project.pbxproj | 9 +++++ macosx/BadgeView.h | 2 + macosx/BadgeView.m | 55 +++++++++++++++----------- macosx/Badger.m | 19 +++++++-- macosx/Torrent.m | 1 - 5 files changed, 59 insertions(+), 27 deletions(-) diff --git a/Transmission.xcodeproj/project.pbxproj b/Transmission.xcodeproj/project.pbxproj index ae50fde0b..c1196f099 100644 --- a/Transmission.xcodeproj/project.pbxproj +++ b/Transmission.xcodeproj/project.pbxproj @@ -91,6 +91,10 @@ A22A8D560AEEAFA5007E9CB9 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A22A8D540AEEAFA5007E9CB9 /* Localizable.strings */; }; A22D3AA60D00D1790079CFED /* Turtle.png in Resources */ = {isa = PBXBuildFile; fileRef = A22D3AA30D00D1790079CFED /* Turtle.png */; }; A22D3AA70D00D1790079CFED /* TurtleBlue.png in Resources */ = {isa = PBXBuildFile; fileRef = A22D3AA40D00D1790079CFED /* TurtleBlue.png */; }; + A22E59A70DC11A1D00F4BE15 /* libcurl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A29EBE700DC06068006CEE80 /* libcurl.dylib */; }; + A22E59A80DC11A1F00F4BE15 /* libcurl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A29EBE700DC06068006CEE80 /* libcurl.dylib */; }; + A22E59A90DC11A2000F4BE15 /* libcurl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A29EBE700DC06068006CEE80 /* libcurl.dylib */; }; + A22E59AA0DC11A2000F4BE15 /* libcurl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A29EBE700DC06068006CEE80 /* libcurl.dylib */; }; A231274C0D11D0B7003F9AFF /* AboutWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A231274B0D11D0B7003F9AFF /* AboutWindow.xib */; }; A232D29E0A70903E00973B12 /* Filter.png in Resources */ = {isa = PBXBuildFile; fileRef = A232D29D0A70903E00973B12 /* Filter.png */; }; A233BD330D8C6585007EE7B4 /* MessageWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A233BD320D8C6585007EE7B4 /* MessageWindow.xib */; }; @@ -766,6 +770,7 @@ files = ( 4D9A2BF009E16D21002D0FF9 /* libtransmission.a in Frameworks */, 4D9A2BF909E16D4F002D0FF9 /* libcrypto.0.9.7.dylib in Frameworks */, + A22E59A70DC11A1D00F4BE15 /* libcurl.dylib in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -813,6 +818,7 @@ files = ( BEFC1C040C07753100B0BB3C /* libcrypto.0.9.7.dylib in Frameworks */, BEFC1C050C07753500B0BB3C /* libtransmission.a in Frameworks */, + A22E59A80DC11A1F00F4BE15 /* libcurl.dylib in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -822,6 +828,7 @@ files = ( BEFC1CF40C07822400B0BB3C /* libcrypto.0.9.7.dylib in Frameworks */, BEFC1D2D0C0783D900B0BB3C /* libtransmission.a in Frameworks */, + A22E59A90DC11A2000F4BE15 /* libcurl.dylib in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -831,6 +838,7 @@ files = ( BEFC1D3E0C0783EE00B0BB3C /* libcrypto.0.9.7.dylib in Frameworks */, BEFC1D3F0C0783EE00B0BB3C /* libtransmission.a in Frameworks */, + A22E59AA0DC11A2000F4BE15 /* libcurl.dylib in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2209,6 +2217,7 @@ OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = ""; PREBINDING = NO; + PRELINK_LIBS = ""; SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; }; name = Development; diff --git a/macosx/BadgeView.h b/macosx/BadgeView.h index 4dc8c6efc..ac428c53d 100644 --- a/macosx/BadgeView.h +++ b/macosx/BadgeView.h @@ -31,11 +31,13 @@ NSDictionary * fAttributes; + float fDownloadRate, fUploadRate; BOOL fQuitting; } - (id) initWithFrame: (NSRect) frame lib: (tr_handle *) lib; +- (BOOL) setRatesWithDownload: (float) downloadRate upload: (float) uploadRate; - (void) setQuitting; @end diff --git a/macosx/BadgeView.m b/macosx/BadgeView.m index 407624731..5d07301f3 100644 --- a/macosx/BadgeView.m +++ b/macosx/BadgeView.m @@ -40,22 +40,39 @@ if ((self = [super initWithFrame: frame])) { fLib = lib; + + fDownloadRate = 0.0; + fUploadRate = 0.0; fQuitting = NO; } return self; } -- (void) setQuitting -{ - fQuitting = YES; -} - - (void) dealloc { [fAttributes release]; [super dealloc]; } +- (BOOL) setRatesWithDownload: (float) downloadRate upload: (float) uploadRate +{ + //only needs update if the badges were displayed or are displayed now + BOOL needsUpdate = fDownloadRate != downloadRate || fUploadRate != uploadRate; + if (needsUpdate) + { + fDownloadRate = downloadRate; + fUploadRate = uploadRate; + } + + return needsUpdate; +} + +- (void) setQuitting +{ + fQuitting = YES; + [self display]; +} + - (void) drawRect: (NSRect) rect { [[NSImage imageNamed: @"NSApplicationIcon"] drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0]; @@ -68,27 +85,19 @@ return; } - BOOL checkDownload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeDownloadRate"], - checkUpload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeUploadRate"]; - if (checkDownload || checkUpload) + BOOL upload = fUploadRate >= 0.1, + download = fDownloadRate >= 0.1; + float bottom = 0.0; + if (upload) { - float downloadRate, uploadRate; - tr_torrentRates(fLib, &downloadRate, &uploadRate); - - BOOL upload = checkUpload && uploadRate >= 0.1, - download = checkDownload && downloadRate >= 0.1; - float bottom = 0.0; - if (upload) - { - NSImage * uploadBadge = [NSImage imageNamed: @"UploadBadge.png"]; - [self badge: uploadBadge string: [NSString stringForSpeedAbbrev: uploadRate] atHeight: bottom adjustForQuit: NO]; - if (download) - bottom += [uploadBadge size].height + BETWEEN_PADDING; //download rate above upload rate - } + NSImage * uploadBadge = [NSImage imageNamed: @"UploadBadge.png"]; + [self badge: uploadBadge string: [NSString stringForSpeedAbbrev: fUploadRate] atHeight: bottom adjustForQuit: NO]; if (download) - [self badge: [NSImage imageNamed: @"DownloadBadge.png"] string: [NSString stringForSpeedAbbrev: downloadRate] - atHeight: bottom adjustForQuit: NO]; + bottom += [uploadBadge size].height + BETWEEN_PADDING; //download rate above upload rate } + if (download) + [self badge: [NSImage imageNamed: @"DownloadBadge.png"] string: [NSString stringForSpeedAbbrev: fDownloadRate] + atHeight: bottom adjustForQuit: NO]; } @end diff --git a/macosx/Badger.m b/macosx/Badger.m index c9178f5c5..898cac37c 100644 --- a/macosx/Badger.m +++ b/macosx/Badger.m @@ -85,8 +85,21 @@ { if ([NSApp isOnLeopardOrBetter]) { - #warning only update if change to values - [[NSApp dockTile] display]; + float downloadRate = 0.0, uploadRate = 0.0; + BOOL checkDownload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeDownloadRate"], + checkUpload = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeUploadRate"]; + if (checkDownload || checkUpload) + { + tr_torrentRates(fLib, &downloadRate, &uploadRate); + + downloadRate = checkDownload ? downloadRate : 0.0; + uploadRate = checkUpload ? uploadRate : 0.0; + } + + //only update if the badged values change + if ([(BadgeView *)[[NSApp dockTile] contentView] setRatesWithDownload: downloadRate upload: uploadRate]) + [[NSApp dockTile] display]; + return; } else if (fQuittingTiger) @@ -235,7 +248,7 @@ { [self clearCompleted]; [(BadgeView *)[[NSApp dockTile] contentView] setQuitting]; - [self updateBadge]; + [[NSApp dockTile] display]; } else { diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 0ac308a5b..16df32cf1 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -770,7 +770,6 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * return [NSString stringWithUTF8String: fStat->tracker_stat.scrapeResponse]; } -#warning removes separators? - (NSArray *) allTrackers: (BOOL) separators { int count = fInfo->trackerCount, capacity = count; -- 2.40.0