mirror of
https://github.com/transmission/transmission
synced 2024-12-26 17:47:37 +00:00
replace a loop with math
This commit is contained in:
parent
456adc3558
commit
fab1ffb8a2
2 changed files with 22 additions and 46 deletions
|
@ -3864,46 +3864,25 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
searchFrame.origin.x += searchFrame.size.width - SEARCH_FILTER_MIN_WIDTH;
|
||||
searchFrame.size.width = SEARCH_FILTER_MIN_WIDTH;
|
||||
|
||||
//resize each button until they don't overlap search
|
||||
int download = 0;
|
||||
BOOL seeding = NO, paused = NO;
|
||||
do
|
||||
{
|
||||
if (download < 8)
|
||||
{
|
||||
download++;
|
||||
downloadRect.size.width--;
|
||||
//resize the buttons so they don't overlay
|
||||
int difference = (NSMaxX(pauseRect) + 5.0) - searchFrame.origin.x;
|
||||
|
||||
seedRect.origin.x--;
|
||||
pauseRect.origin.x--;
|
||||
}
|
||||
else if (!seeding)
|
||||
{
|
||||
seeding = YES;
|
||||
seedRect.size.width--;
|
||||
//decrease downloading by 8, seeding by 1, paused by 1, active by 1, repeat
|
||||
int download = (difference / 11 * 8) + MIN(difference % 11 + 1, 8); //8 for every 11
|
||||
int seed = (difference / 11) + (difference % 11 >= 8 ? 1 : 0);
|
||||
int paused = (difference / 11) + (difference % 11 >= 9 ? 1 : 0);
|
||||
int active = (difference / 11) + (difference % 11 >= 10 ? 1 : 0);
|
||||
|
||||
pauseRect.origin.x--;
|
||||
}
|
||||
else if (!paused)
|
||||
{
|
||||
paused = YES;
|
||||
pauseRect.size.width--;
|
||||
}
|
||||
else
|
||||
{
|
||||
activeRect.size.width--;
|
||||
activeRect.size.width -= active;
|
||||
|
||||
downloadRect.origin.x--;
|
||||
seedRect.origin.x--;
|
||||
pauseRect.origin.x--;
|
||||
downloadRect.size.width -= download;
|
||||
downloadRect.origin.x -= active;
|
||||
|
||||
//reset
|
||||
download = 0;
|
||||
seeding = NO;
|
||||
paused = NO;
|
||||
}
|
||||
}
|
||||
while (NSMaxX(pauseRect) + 5.0 > searchFrame.origin.x);
|
||||
seedRect.size.width -= seed;
|
||||
seedRect.origin.x -= active + download;
|
||||
|
||||
pauseRect.size.width -= paused;
|
||||
pauseRect.origin.x -= active + download + seed;
|
||||
}
|
||||
else;
|
||||
|
||||
|
|
|
@ -1651,17 +1651,14 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
|||
- (void) createFileList
|
||||
{
|
||||
int count = [self fileCount], i;
|
||||
tr_file * file;
|
||||
NSMutableArray * pathComponents;
|
||||
NSString * path;
|
||||
|
||||
NSMutableArray * fileList = [[NSMutableArray alloc] initWithCapacity: count];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
file = &fInfo->files[i];
|
||||
tr_file * file = &fInfo->files[i];
|
||||
|
||||
pathComponents = [[[NSString stringWithUTF8String: file->name] pathComponents] mutableCopy];
|
||||
NSMutableArray * pathComponents = [[[NSString stringWithUTF8String: file->name] pathComponents] mutableCopy];
|
||||
NSString * path;
|
||||
if ([self folder])
|
||||
{
|
||||
path = [pathComponents objectAtIndex: 0];
|
||||
|
|
Loading…
Reference in a new issue