1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-25 15:32:33 +00:00

keep track of which rows are groups with a separate object

This commit is contained in:
Mitchell Livingston 2008-01-23 17:03:42 +00:00
parent c38bfdc481
commit 5852c78682
6 changed files with 2325 additions and 2300 deletions

View file

@ -52,6 +52,7 @@ typedef enum
tr_handle * fLib;
NSMutableArray * fTorrents, * fDisplayedTorrents;
NSMutableIndexSet * fDisplayedGroupIndexes;
PrefsController * fPrefsController;
InfoWindowController * fInfoController;

View file

@ -211,6 +211,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
fTorrents = [[NSMutableArray alloc] init];
fDisplayedTorrents = [[NSMutableArray alloc] init];
fDisplayedGroupIndexes = [[NSMutableIndexSet alloc] init];
fMessageController = [[MessageWindowController alloc] init];
fInfoController = [[InfoWindowController alloc] init];
@ -323,6 +324,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[fPrefsController setUpdater: fUpdater];
[fTableView setTorrents: fDisplayedTorrents];
[fTableView setGroupIndexes: fDisplayedGroupIndexes];
[fTableView registerForDraggedTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE]];
[fWindow registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, NSURLPboardType, nil]];
@ -586,6 +588,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[fTorrents release];
[fDisplayedTorrents release];
[fDisplayedGroupIndexes release];
[fOverlayWindow release];
[fIPCController release];
@ -1684,8 +1687,13 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
//add group divider if necessary
int total = [fDisplayedTorrents count];
[fDisplayedGroupIndexes removeAllIndexes];
if (group && total > 0 && [NSApp isOnLeopardOrBetter])
{
#warning make more efficient
NSMutableIndexSet * tempGroupIndexes = [[NSMutableIndexSet alloc] init];
int i, groupValue = [[fDisplayedTorrents objectAtIndex: total-1] groupValue], newGroupValue, count = 1;
for (i = total-1; i >= 0; i--)
{
@ -1693,9 +1701,11 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
newGroupValue = [[fDisplayedTorrents objectAtIndex: i-1] groupValue];
if (groupValue != newGroupValue || i == 0)
{
#warning count can be derived...elliminate
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: groupValue], @"Group",
[NSNumber numberWithInt: count], @"Count", nil];
[fDisplayedTorrents insertObject: dict atIndex: i];
[tempGroupIndexes addIndex: i];
groupValue = newGroupValue;
count = 1;
@ -1703,6 +1713,11 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
else
count++;
}
for (i = [tempGroupIndexes firstIndex], count = 0; i != NSNotFound; i = [tempGroupIndexes indexGreaterThanIndex: i], count++)
[fDisplayedGroupIndexes addIndex: i+count];
[tempGroupIndexes release];
}
[fTableView reloadData];
@ -1759,6 +1774,9 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
- (void) applyFilter: (id) sender
{
NSMutableArray * previousTorrents = [fDisplayedTorrents mutableCopy];
int i;
for (i = [fDisplayedGroupIndexes lastIndex]; i != NSNotFound; i = [fDisplayedGroupIndexes indexLessThanIndex: i])
[previousTorrents removeObjectAtIndex: i];
NSArray * selectedValues = [fTableView selectedValues];
@ -1788,7 +1806,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
//get count of each type
NSEnumerator * enumerator = [fTorrents objectEnumerator];
Torrent * torrent;
int i = -1;
i = -1;
BOOL isActive;
while ((torrent = [enumerator nextObject]))
{
@ -1865,20 +1883,6 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[fDisplayedTorrents setArray: [fTorrents objectsAtIndexes: indexes]];
//clear display cache for not-shown torrents
[previousTorrents removeObjectsInArray: fDisplayedTorrents];
if ([previousTorrents count] > 0)
{
NSEnumerator * enumerator = [previousTorrents objectEnumerator];
id torrent;
while ((torrent = [enumerator nextObject]))
{
if ([torrent isKindOfClass: [Torrent class]])
[torrent setPreviousAmountFinished: NULL];
}
}
[previousTorrents release];
//set button tooltips
[fNoFilterButton setCount: [fTorrents count]];
[fActiveFilterButton setCount: active];
@ -1886,9 +1890,17 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[fSeedFilterButton setCount: seeding];
[fPauseFilterButton setCount: paused];
[self sortTorrentsIgnoreSelected];
//clear display cache for not-shown torrents
[previousTorrents removeObjectsInArray: fDisplayedTorrents]; //neither array should currently have group items
//set selected rows
enumerator = [previousTorrents objectEnumerator];
while ((torrent = [enumerator nextObject]))
[torrent setPreviousAmountFinished: NULL];
[previousTorrents release];
//sort, add groups, and reset selected
[self sortTorrentsIgnoreSelected];
[fTableView selectValues: selectedValues];
//set status bar torrent count text
@ -3610,15 +3622,10 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
- (NSRect) sizedWindowFrame
{
float heightChange = 0;
float heightChange = (GROUP_SEPARATOR_HEIGHT + [fTableView intercellSpacing].height) * [fDisplayedGroupIndexes count]
+ ([fTableView rowHeight] + [fTableView intercellSpacing].height) * ([fDisplayedTorrents count]
- [fDisplayedGroupIndexes count]) - [fScrollView frame].size.height;
NSEnumerator * enumerator = [fDisplayedTorrents objectEnumerator];
id object;
while ((object = [enumerator nextObject]))
heightChange += ([object isKindOfClass: [Torrent class]] ? [fTableView rowHeight] : GROUP_SEPARATOR_HEIGHT)
+ [fTableView intercellSpacing].height;
heightChange -= [fScrollView frame].size.height;
return [self windowFrameByAddingHeight: heightChange checkLimits: YES];
}

File diff suppressed because it is too large Load diff

View file

@ -794,7 +794,7 @@
* previousPiecePercent = [torrent getPreviousAmountFinished];
[torrent getAmountFinished: piecePercent size: pieceCount];
int i, h, index;
int i, index;
float increment = (float)pieceCount / MAX_PIECES;
NSColor * pieceColor;
for (i = 0; i < MAX_PIECES; i++)

View file

@ -34,6 +34,7 @@
{
IBOutlet Controller * fController;
NSArray * fTorrents;
NSIndexSet * fGroupIndexes;
NSUserDefaults * fDefaults;
@ -52,6 +53,7 @@
}
- (void) setTorrents: (NSArray *) torrents;
- (void) setGroupIndexes: (NSIndexSet *) indexes;
- (void) removeButtonTrackingAreas;
- (void) setControlButtonHover: (int) row;

View file

@ -94,20 +94,24 @@
fTorrents = torrents;
}
- (void) setGroupIndexes: (NSIndexSet *) indexes
{
fGroupIndexes = indexes;
}
- (id) dataCellForRow: (NSInteger) row
{
return (row == -1 || [[fTorrents objectAtIndex: row] isKindOfClass: [Torrent class]]) ? [[[TorrentCell alloc] init] autorelease]
: nil;
return (row == -1 || ![fGroupIndexes containsIndex: row]) ? [[[TorrentCell alloc] init] autorelease] : nil;
}
- (BOOL) tableView: (NSTableView *) tableView isGroupRow: (NSInteger) row
{
return ![[fTorrents objectAtIndex: row] isKindOfClass: [Torrent class]];
return [fGroupIndexes containsIndex: row];
}
- (CGFloat) tableView: (NSTableView *) tableView heightOfRow: (NSInteger) row
{
return [[fTorrents objectAtIndex: row] isKindOfClass: [Torrent class]] ? [self rowHeight] : GROUP_SEPARATOR_HEIGHT;
return ![fGroupIndexes containsIndex: row] ? [self rowHeight] : GROUP_SEPARATOR_HEIGHT;
}
- (NSCell *) tableView: (NSTableView *) tableView dataCellForTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
@ -117,7 +121,7 @@
- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn row: (int) row
{
if (![cell isKindOfClass: [TorrentCell class]])
if ([fGroupIndexes containsIndex: row])
return;
[cell setRepresentedObject: [fTorrents objectAtIndex: row]];
@ -130,8 +134,8 @@
- (NSString *) tableView: (NSTableView *) tableView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn row: (int) row
{
id object = [fTorrents objectAtIndex: row];
return [object isKindOfClass: [Torrent class]] ? [object name] : [[self preparedCellAtColumn: 0 row: row] stringValue];
return ![fGroupIndexes containsIndex: row] ? [[fTorrents objectAtIndex: row] name]
: [[self preparedCellAtColumn: 0 row: row] stringValue];
}
- (void) updateTrackingAreas
@ -150,11 +154,11 @@
int row;
for (row = visibleRows.location; row < NSMaxRange(visibleRows); row++)
{
TorrentCell * cell = (TorrentCell *)[self preparedCellAtColumn: col row: row];
if (![cell isKindOfClass: [TorrentCell class]])
if ([fGroupIndexes containsIndex: row])
continue;
NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: row] forKey: @"Row"];
TorrentCell * cell = (TorrentCell *)[self preparedCellAtColumn: col row: row];
[cell addTrackingAreasForView: self inRect: [self frameOfCellAtColumn: col row: row] withUserInfo: userInfo
mouseLocation: mouseLocation];
}
@ -278,7 +282,7 @@
else;
}
#warning better way?
#warning better way? - use group indexes
- (void) selectValues: (NSArray *) values
{
id object;
@ -295,8 +299,7 @@
unsigned i;
for (i = 0; i < [fTorrents count]; i++)
{
id currentObject = [fTorrents objectAtIndex: i];
if (![currentObject isKindOfClass: [Torrent class]] && value == [[currentObject objectForKey: @"Group"] intValue])
if ([fGroupIndexes containsIndex: i] && value == [[[fTorrents objectAtIndex: i] objectForKey: @"Group"] intValue])
{
index = i;
break;
@ -325,17 +328,16 @@
NSUInteger i;
for (i = [selectedIndexes firstIndex]; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex: i])
{
id object = [fTorrents objectAtIndex: i];
if ([object isKindOfClass: [Torrent class]])
if (![fGroupIndexes containsIndex: i])
[indexSet addIndex: i];
else
{
int count = [[object objectForKey: @"Count"] intValue];
#warning elliminate count so equals comparison can be done?
int count = [[[fTorrents objectAtIndex: i] objectForKey: @"Count"] intValue];
[indexSet addIndexesInRange: NSMakeRange(i+1, count)];
i += count;
}
}
[fTorrents objectsAtIndexes: indexSet];
}
@ -649,43 +651,40 @@
- (BOOL) pointInControlRect: (NSPoint) point
{
int row = [self rowAtPoint: point];
if (row < 0)
if (row < 0 || [fGroupIndexes containsIndex: row])
return NO;
NSCell * cell = [self dataCellForRow: row];
return [cell isKindOfClass: [TorrentCell class]]
&& NSPointInRect(point, [(TorrentCell*)cell controlButtonRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
TorrentCell * cell = [self dataCellForRow: row];
return NSPointInRect(point, [cell controlButtonRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
}
- (BOOL) pointInRevealRect: (NSPoint) point
{
int row = [self rowAtPoint: point];
if (row < 0)
if (row < 0 || [fGroupIndexes containsIndex: row])
return NO;
NSCell * cell = [self dataCellForRow: row];
return [cell isKindOfClass: [TorrentCell class]]
&& NSPointInRect(point, [(TorrentCell*)cell revealButtonRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
TorrentCell * cell = [self dataCellForRow: row];
return NSPointInRect(point, [cell revealButtonRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
}
- (BOOL) pointInActionRect: (NSPoint) point
{
int row = [self rowAtPoint: point];
if (row < 0)
if (row < 0 || [fGroupIndexes containsIndex: row])
return NO;
NSCell * cell = [self dataCellForRow: row];
return [cell isKindOfClass: [TorrentCell class]]
&& NSPointInRect(point, [(TorrentCell*)cell iconRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
TorrentCell * cell = [self dataCellForRow: row];
return NSPointInRect(point, [cell iconRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
}
- (BOOL) pointInProgressRect: (NSPoint) point
{
int row = [self rowAtPoint: point];
if (row < 0 || [fDefaults boolForKey: @"SmallView"])
if (row < 0 || [fGroupIndexes containsIndex: row] || [fDefaults boolForKey: @"SmallView"])
return NO;
NSCell * cell;
TorrentCell * cell;
if ([NSApp isOnLeopardOrBetter])
cell = (TorrentCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row];
else
@ -693,17 +692,16 @@
cell = [self dataCellForRow: row];
[cell setRepresentedObject: [fTorrents objectAtIndex: row]];
}
return [cell isKindOfClass: [TorrentCell class]]
&& NSPointInRect(point, [(TorrentCell*)cell progressRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
return NSPointInRect(point, [cell progressRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
}
- (BOOL) pointInMinimalStatusRect: (NSPoint) point
{
int row = [self rowAtPoint: point];
if (row < 0 || ![fDefaults boolForKey: @"SmallView"])
if (row < 0 || [fGroupIndexes containsIndex: row] || ![fDefaults boolForKey: @"SmallView"])
return NO;
NSCell * cell;
TorrentCell * cell;
if ([NSApp isOnLeopardOrBetter])
cell = (TorrentCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row];
else
@ -711,8 +709,7 @@
cell = [self dataCellForRow: row];
[cell setRepresentedObject: [fTorrents objectAtIndex: row]];
}
return [cell isKindOfClass: [TorrentCell class]]
&& NSPointInRect(point, [(TorrentCell*)cell minimalStatusRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
return NSPointInRect(point, [cell minimalStatusRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
}
- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files