Inverse request: Report progress in dock

Feature requests for the Mac OS X version of Transmission
Post Reply
gonsolo
Posts: 1
Joined: Fri Mar 04, 2016 3:18 am

Inverse request: Report progress in dock

Post by gonsolo »

Hi

Here is a patch for reporting the progress of downloads in the dock. I am mostly interested how far my downloads are not what's the current download or upload speed. This has been added before and I know the developers are not interested but here is the patch anyway in case some of the users are interested in this. You have to manually copy UploadBadge.png to PercentageBadge.png.

Index: BadgeView.h
===================================================================
--- BadgeView.h (revision 14706)
+++ BadgeView.h (working copy)
@@ -31,13 +31,12 @@

NSMutableDictionary * fAttributes;

- CGFloat fDownloadRate, fUploadRate;
+ CGFloat fDownloadRate, fUploadRate, fPercentageRate;
BOOL fQuitting;
}

- (id) initWithLib: (tr_session *) lib;
-
-- (BOOL) setRatesWithDownload: (CGFloat) downloadRate upload: (CGFloat) uploadRate;
+- (BOOL) setRatesWithPercentage: (CGFloat) percentageRate;
- (void) setQuitting;

@end
Index: BadgeView.m
===================================================================
--- BadgeView.m (revision 14706)
+++ BadgeView.m (working copy)
@@ -43,6 +43,7 @@

fDownloadRate = 0.0;
fUploadRate = 0.0;
+ fPercentageRate = 0.0;
fQuitting = NO;
}
return self;
@@ -54,14 +55,13 @@
[super dealloc];
}

-- (BOOL) setRatesWithDownload: (CGFloat) downloadRate upload: (CGFloat) uploadRate
+- (BOOL) setRatesWithPercentage: (CGFloat) percentageRate
{
//only needs update if the badges were displayed or are displayed now
- if (fDownloadRate == downloadRate && fUploadRate == uploadRate)
+ if (fPercentageRate == percentageRate)
return NO;

- fDownloadRate = downloadRate;
- fUploadRate = uploadRate;
+ fPercentageRate = percentageRate;
return YES;
}

@@ -82,19 +82,9 @@
return;
}

- const BOOL upload = fUploadRate >= 0.1,
- download = fDownloadRate >= 0.1;
CGFloat bottom = 0.0;
- if (upload)
- {
- NSImage * uploadBadge = [NSImage imageNamed: @"UploadBadge"];
- [self badge: uploadBadge string: [NSString stringForSpeedAbbrev: fUploadRate] atHeight: bottom adjustForQuit: NO];
- if (download)
- bottom += [uploadBadge size].height + BETWEEN_PADDING; //download rate above upload rate
- }
- if (download)
- [self badge: [NSImage imageNamed: @"DownloadBadge"] string: [NSString stringForSpeedAbbrev: fDownloadRate]
- atHeight: bottom adjustForQuit: NO];
+ NSImage * percentageBadge = [NSImage imageNamed: @"PercentageBadge"];
+ [self badge: percentageBadge string: [NSString percentString: fPercentageRate longDecimals:NO] atHeight: bottom adjustForQuit: NO];
}

@end
Index: Badger.h
===================================================================
--- Badger.h (revision 14706)
+++ Badger.h (working copy)
@@ -32,11 +32,12 @@
tr_session * fLib;

NSMutableSet * fHashes;
+ NSMutableArray * fTorrents;
}

-- (id) initWithLib: (tr_session *) lib;
+- (id) initWithLib: (tr_session *) lib torrents: (NSMutableArray *) torrents;

-- (void) updateBadgeWithDownload: (CGFloat) downloadRate upload: (CGFloat) uploadRate;
+- (void) updateBadgeWithPercentage: (CGFloat) percentage;
- (void) addCompletedTorrent: (Torrent *) torrent;
- (void) removeTorrent: (Torrent *) torrent;
- (void) clearCompleted;
Index: Badger.m
===================================================================
--- Badger.m (revision 14706)
+++ Badger.m (working copy)
@@ -29,11 +29,12 @@

@implementation Badger

-- (id) initWithLib: (tr_session *) lib
+- (id) initWithLib: (tr_session *) lib torrents: (NSMutableArray *) torrents
{
if ((self = [super init]))
{
fLib = lib;
+ fTorrents = torrents;

BadgeView * view = [[BadgeView alloc] initWithLib: lib];
[[NSApp dockTile] setContentView: view];
@@ -51,15 +52,12 @@
[super dealloc];
}

-- (void) updateBadgeWithDownload: (CGFloat) downloadRate upload: (CGFloat) uploadRate
+- (void) updateBadgeWithPercentage: (CGFloat) percentageRate
{
- const CGFloat displayDlRate = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeDownloadRate"]
- ? downloadRate : 0.0;
- const CGFloat displayUlRate = [[NSUserDefaults standardUserDefaults] boolForKey: @"BadgeUploadRate"]
- ? uploadRate : 0.0;
+ const CGFloat displayPercentage = percentageRate;

//only update if the badged values change
- if ([(BadgeView *)[[NSApp dockTile] contentView] setRatesWithDownload: displayDlRate upload: displayUlRate])
+ if ([(BadgeView *)[[NSApp dockTile] contentView] setRatesWithPercentage: displayPercentage])
[[NSApp dockTile] display];
}

Index: Controller.m
===================================================================
--- Controller.m (revision 14706)
+++ Controller.m (working copy)
@@ -520,7 +520,7 @@
[torrent startTransfer];
}

- fBadger = [[Badger alloc] initWithLib: fLib];
+ fBadger = [[Badger alloc] initWithLib: fLib torrents: fDisplayedTorrents];

if ([NSApp isOnMountainLionOrBetter])
[[NSUserNotificationCenterMtLion defaultUserNotificationCenter] setDelegate: self];
@@ -1851,7 +1851,7 @@

- (void) updateUI
{
- CGFloat dlRate = 0.0, ulRate = 0.0;
+ CGFloat dlRate = 0.0, ulRate = 0.0, size = 0.0, sizeLeft = 0.0, percRate = 0.0;
BOOL anyCompleted = NO;
for (Torrent * torrent in fTorrents)
{
@@ -1860,10 +1860,13 @@
//pull the upload and download speeds - most consistent by using current stats
dlRate += [torrent downloadRate];
ulRate += [torrent uploadRate];
-
+ size += [torrent size];
+ sizeLeft += [torrent sizeLeft];
anyCompleted |= [torrent isFinishedSeeding];
}

+ percRate = (size - sizeLeft) / size;
+
if (![NSApp isHidden])
{
if ([fWindow isVisible])
@@ -1881,7 +1884,7 @@
}

//badge dock
- [fBadger updateBadgeWithDownload: dlRate upload: ulRate];
+ [fBadger updateBadgeWithPercentage: percRate];
}

#warning can this be removed or refined?
Index: Images/PercentageBadge.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: Images/PercentageBadge.png
===================================================================
--- Images/PercentageBadge.png (revision 14706)
+++ Images/PercentageBadge.png (working copy)

Property changes on: Images/PercentageBadge.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
Post Reply