2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-02 16:55:05 +00:00
|
|
|
* Copyright (c) 2005-2008 Transmission authors and contributors
|
2007-09-16 01:02:06 +00:00
|
|
|
*
|
|
|
|
* 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 "TorrentTableView.h"
|
|
|
|
#import "TorrentCell.h"
|
|
|
|
#import "Controller.h"
|
|
|
|
#import "Torrent.h"
|
2007-10-27 14:57:46 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSMenuAdditions.h"
|
|
|
|
|
|
|
|
#define ACTION_MENU_GLOBAL_TAG 101
|
|
|
|
#define ACTION_MENU_UNLIMITED_TAG 102
|
|
|
|
#define ACTION_MENU_LIMIT_TAG 103
|
|
|
|
|
2008-01-16 15:56:40 +00:00
|
|
|
#define PIECE_INCREASE 0.1
|
|
|
|
#define PIECE_TIME 0.01
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@interface TorrentTableView (Private)
|
|
|
|
|
2008-01-15 03:50:00 +00:00
|
|
|
- (BOOL) pointInControlRect: (NSPoint) point;
|
|
|
|
- (BOOL) pointInRevealRect: (NSPoint) point;
|
2008-01-14 19:12:26 +00:00
|
|
|
- (BOOL) pointInActionRect: (NSPoint) point;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-09-23 05:39:41 +00:00
|
|
|
- (BOOL) pointInProgressRect: (NSPoint) point;
|
2007-09-16 01:02:06 +00:00
|
|
|
- (BOOL) pointInMinimalStatusRect: (NSPoint) point;
|
|
|
|
- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
|
|
|
|
|
2008-01-16 15:56:40 +00:00
|
|
|
- (void) resizePiecesBarIncrement;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentTableView
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder *) decoder
|
|
|
|
{
|
|
|
|
if ((self = [super initWithCoder: decoder]))
|
|
|
|
{
|
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
2008-01-24 01:05:00 +00:00
|
|
|
fTorrentCell = [[TorrentCell alloc] init];
|
2008-01-27 19:10:14 +00:00
|
|
|
if (![NSApp isOnLeopardOrBetter])
|
|
|
|
[[self tableColumnWithIdentifier: @"Torrent"] setDataCell: fTorrentCell];
|
2008-01-24 01:05:00 +00:00
|
|
|
|
2008-01-15 04:45:57 +00:00
|
|
|
fMouseControlRow = -1;
|
|
|
|
fMouseRevealRow = -1;
|
2008-01-15 23:48:03 +00:00
|
|
|
fMouseActionRow = -1;
|
2008-01-16 19:49:10 +00:00
|
|
|
fActionPushedRow = -1;
|
2008-01-15 03:33:44 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setDelegate: self];
|
2008-01-16 15:56:40 +00:00
|
|
|
|
|
|
|
fPiecesBarPercent = [fDefaults boolForKey: @"PiecesBar"] ? 1.0 : 0.0;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2008-01-24 01:05:00 +00:00
|
|
|
[self setGridStyleMask: NSTableViewSolidVerticalGridLineMask]; //weird redrawing issues if set to none
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2008-01-16 15:56:40 +00:00
|
|
|
[fPiecesBarTimer invalidate];
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
[fSelectedValues release];
|
2008-01-15 03:33:44 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fKeyStrokes release];
|
|
|
|
[fMenuTorrent release];
|
|
|
|
|
2008-01-24 01:05:00 +00:00
|
|
|
[fTorrentCell release];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTorrents: (NSArray *) torrents
|
|
|
|
{
|
|
|
|
fTorrents = torrents;
|
|
|
|
}
|
|
|
|
|
2008-01-23 17:03:42 +00:00
|
|
|
- (void) setGroupIndexes: (NSIndexSet *) indexes
|
|
|
|
{
|
|
|
|
fGroupIndexes = indexes;
|
|
|
|
}
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
- (BOOL) tableView: (NSTableView *) tableView isGroupRow: (NSInteger) row
|
|
|
|
{
|
2008-01-23 17:03:42 +00:00
|
|
|
return [fGroupIndexes containsIndex: row];
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat) tableView: (NSTableView *) tableView heightOfRow: (NSInteger) row
|
|
|
|
{
|
2008-01-23 17:03:42 +00:00
|
|
|
return ![fGroupIndexes containsIndex: row] ? [self rowHeight] : GROUP_SEPARATOR_HEIGHT;
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCell *) tableView: (NSTableView *) tableView dataCellForTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
|
|
|
|
{
|
2008-01-24 21:14:02 +00:00
|
|
|
return ![fGroupIndexes containsIndex: row] ? fTorrentCell : nil;
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn row: (int) row
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-23 17:03:42 +00:00
|
|
|
if ([fGroupIndexes containsIndex: row])
|
2008-01-23 02:51:58 +00:00
|
|
|
return;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[cell setRepresentedObject: [fTorrents objectAtIndex: row]];
|
2008-01-16 15:56:40 +00:00
|
|
|
|
2008-01-15 04:45:57 +00:00
|
|
|
[cell setControlHover: row == fMouseControlRow];
|
|
|
|
[cell setRevealHover: row == fMouseRevealRow];
|
2008-01-15 23:48:03 +00:00
|
|
|
[cell setActionHover: row == fMouseActionRow];
|
2008-01-16 19:49:10 +00:00
|
|
|
[cell setActionPushed: row == fActionPushedRow];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-10-27 14:57:46 +00:00
|
|
|
- (NSString *) tableView: (NSTableView *) tableView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn row: (int) row
|
|
|
|
{
|
2008-01-23 17:03:42 +00:00
|
|
|
return ![fGroupIndexes containsIndex: row] ? [[fTorrents objectAtIndex: row] name]
|
|
|
|
: [[self preparedCellAtColumn: 0 row: row] stringValue];
|
2007-10-27 14:57:46 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 21:33:54 +00:00
|
|
|
- (BOOL) tableView: (NSTableView *) tableView shouldEditTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
- (void) updateTrackingAreas
|
|
|
|
{
|
|
|
|
[super updateTrackingAreas];
|
|
|
|
|
2008-01-15 16:19:16 +00:00
|
|
|
[self removeButtonTrackingAreas];
|
2008-01-15 03:33:44 +00:00
|
|
|
|
2008-01-24 15:09:28 +00:00
|
|
|
NSMutableIndexSet * indexes = [NSMutableIndexSet indexSetWithIndexesInRange: [self rowsInRect: [self visibleRect]]];
|
|
|
|
[indexes removeIndexes: fGroupIndexes];
|
|
|
|
if ([indexes count] == 0)
|
2008-01-15 03:33:44 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
NSPoint mouseLocation = [self convertPoint: [[self window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil];
|
|
|
|
|
2008-01-24 15:09:28 +00:00
|
|
|
NSUInteger row;
|
|
|
|
for (row = [indexes firstIndex]; row != NSNotFound; row = [indexes indexGreaterThanIndex: row])
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
|
|
|
NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: row] forKey: @"Row"];
|
2008-01-24 15:09:28 +00:00
|
|
|
TorrentCell * cell = (TorrentCell *)[self preparedCellAtColumn: 0 row: row];
|
|
|
|
[cell addTrackingAreasForView: self inRect: [self frameOfCellAtColumn: 0 row: row] withUserInfo: userInfo
|
2008-01-15 03:33:44 +00:00
|
|
|
mouseLocation: mouseLocation];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-15 16:19:16 +00:00
|
|
|
- (void) removeButtonTrackingAreas
|
|
|
|
{
|
|
|
|
fMouseControlRow = -1;
|
|
|
|
fMouseRevealRow = -1;
|
2008-01-15 23:48:03 +00:00
|
|
|
fMouseActionRow = -1;
|
2008-01-15 16:19:16 +00:00
|
|
|
|
2008-01-17 01:57:14 +00:00
|
|
|
if (![NSApp isOnLeopardOrBetter])
|
|
|
|
return;
|
|
|
|
|
2008-01-15 16:19:16 +00:00
|
|
|
NSEnumerator * enumerator = [[self trackingAreas] objectEnumerator];
|
|
|
|
NSTrackingArea * area;
|
|
|
|
while ((area = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if ([area owner] == self && [[area userInfo] objectForKey: @"Row"])
|
|
|
|
[self removeTrackingArea: area];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-15 19:48:19 +00:00
|
|
|
- (void) setControlButtonHover: (int) row
|
|
|
|
{
|
|
|
|
fMouseControlRow = row;
|
|
|
|
if (row >= 0)
|
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: row]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRevealButtonHover: (int) row
|
|
|
|
{
|
|
|
|
fMouseRevealRow = row;
|
|
|
|
if (row >= 0)
|
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: row]];
|
|
|
|
}
|
|
|
|
|
2008-01-15 23:48:03 +00:00
|
|
|
- (void) setActionButtonHover: (int) row
|
|
|
|
{
|
|
|
|
fMouseActionRow = row;
|
|
|
|
if (row >= 0)
|
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: row]];
|
|
|
|
}
|
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
- (void) mouseEntered: (NSEvent *) event
|
|
|
|
{
|
2008-01-15 04:45:57 +00:00
|
|
|
NSDictionary * dict = (NSDictionary *)[event userData];
|
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
NSNumber * row;
|
2008-01-15 04:45:57 +00:00
|
|
|
if ((row = [dict objectForKey: @"Row"]))
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
|
|
|
int rowVal = [row intValue];
|
2008-01-20 18:51:53 +00:00
|
|
|
NSString * type = [dict objectForKey: @"Type"];
|
|
|
|
if ([type isEqualToString: @"Action"])
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseActionRow = rowVal;
|
2008-01-20 18:51:53 +00:00
|
|
|
else if ([type isEqualToString: @"Control"])
|
2008-01-15 04:45:57 +00:00
|
|
|
fMouseControlRow = rowVal;
|
2008-01-15 23:48:03 +00:00
|
|
|
else
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseRevealRow = rowVal;
|
2008-01-15 04:45:57 +00:00
|
|
|
|
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: rowVal]];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseExited: (NSEvent *) event
|
|
|
|
{
|
2008-01-16 06:48:12 +00:00
|
|
|
NSDictionary * dict = (NSDictionary *)[event userData];
|
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
NSNumber * row;
|
2008-01-16 06:48:12 +00:00
|
|
|
if ((row = [dict objectForKey: @"Row"]))
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2008-01-20 18:51:53 +00:00
|
|
|
NSString * type = [dict objectForKey: @"Type"];
|
|
|
|
if ([type isEqualToString: @"Action"])
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseActionRow = -1;
|
2008-01-20 18:51:53 +00:00
|
|
|
else if ([type isEqualToString: @"Control"])
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseControlRow = -1;
|
|
|
|
else
|
|
|
|
fMouseRevealRow = -1;
|
2008-01-15 04:45:57 +00:00
|
|
|
|
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: [row intValue]]];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-15 04:45:57 +00:00
|
|
|
- (void) tableViewSelectionIsChanging: (NSNotification *) notification
|
2008-01-15 03:50:00 +00:00
|
|
|
{
|
2008-01-23 02:51:58 +00:00
|
|
|
if (fSelectedValues)
|
|
|
|
[self selectValues: fSelectedValues];
|
2008-01-15 03:50:00 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) mouseDown: (NSEvent *) event
|
|
|
|
{
|
2008-01-15 03:50:00 +00:00
|
|
|
NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
|
|
|
|
|
2008-01-22 05:33:02 +00:00
|
|
|
BOOL pushed = [self pointInControlRect: point] || [self pointInRevealRect: point] || [self pointInActionRect: point]
|
|
|
|
|| [self pointInProgressRect: point] || [self pointInMinimalStatusRect: point];
|
|
|
|
|
2008-01-17 04:20:52 +00:00
|
|
|
//if pushing a button, don't change the selected rows
|
2008-01-22 05:33:02 +00:00
|
|
|
if (pushed)
|
2008-01-23 02:51:58 +00:00
|
|
|
fSelectedValues = [[self selectedValues] retain];
|
2008-01-17 04:20:52 +00:00
|
|
|
|
|
|
|
[super mouseDown: event];
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
[fSelectedValues release];
|
|
|
|
fSelectedValues = nil;
|
2008-01-17 04:20:52 +00:00
|
|
|
|
|
|
|
//avoid weird behavior when showing menu by doing this after mouse down
|
2008-01-14 18:02:08 +00:00
|
|
|
if ([self pointInActionRect: point])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-14 18:02:08 +00:00
|
|
|
int row = [self rowAtPoint: point];
|
2008-01-16 19:49:10 +00:00
|
|
|
|
|
|
|
fActionPushedRow = row;
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: row]]; //ensure button is pushed down
|
|
|
|
|
|
|
|
[self displayTorrentMenuForEvent: event];
|
|
|
|
|
2008-01-16 19:49:10 +00:00
|
|
|
fActionPushedRow = -1;
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: row]];
|
|
|
|
}
|
2008-01-22 05:33:02 +00:00
|
|
|
else if (!pushed && [event clickCount] == 2) //double click
|
2008-01-22 05:19:18 +00:00
|
|
|
[fController showInfo: nil];
|
2008-01-21 06:23:10 +00:00
|
|
|
else;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
- (void) selectValues: (NSArray *) values
|
2008-01-20 18:28:28 +00:00
|
|
|
{
|
2008-01-23 18:41:33 +00:00
|
|
|
NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet];
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
NSEnumerator * enumerator = [values objectEnumerator];
|
2008-01-23 18:41:33 +00:00
|
|
|
id object;
|
2008-01-23 02:51:58 +00:00
|
|
|
while ((object = [enumerator nextObject]))
|
2008-01-20 20:38:51 +00:00
|
|
|
{
|
2008-01-23 18:25:05 +00:00
|
|
|
unsigned index = [fTorrents indexOfObject: object]; //works with torrents and groups
|
2008-01-20 20:38:51 +00:00
|
|
|
if (index != NSNotFound)
|
|
|
|
[indexSet addIndex: index];
|
|
|
|
}
|
2008-01-20 18:28:28 +00:00
|
|
|
|
|
|
|
[self selectRowIndexes: indexSet byExtendingSelection: NO];
|
|
|
|
}
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
- (NSArray *) selectedValues
|
|
|
|
{
|
|
|
|
return [fTorrents objectsAtIndexes: [self selectedRowIndexes]];
|
|
|
|
}
|
|
|
|
|
2008-01-22 23:48:14 +00:00
|
|
|
- (NSArray *) selectedTorrents
|
|
|
|
{
|
2008-01-23 02:51:58 +00:00
|
|
|
NSIndexSet * selectedIndexes = [self selectedRowIndexes];
|
|
|
|
NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet];
|
|
|
|
|
2008-01-23 21:33:54 +00:00
|
|
|
NSUInteger i;
|
2008-01-23 18:47:34 +00:00
|
|
|
for (i = [selectedIndexes firstIndex]; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex: i])
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2008-01-23 18:22:54 +00:00
|
|
|
|
2008-01-23 17:03:42 +00:00
|
|
|
if (![fGroupIndexes containsIndex: i])
|
2008-01-23 02:51:58 +00:00
|
|
|
[indexSet addIndex: i];
|
2008-01-23 03:12:06 +00:00
|
|
|
else
|
|
|
|
{
|
2008-01-23 20:31:04 +00:00
|
|
|
NSUInteger nextGroup = [fGroupIndexes indexGreaterThanIndex: i],
|
|
|
|
count = (nextGroup != NSNotFound ? nextGroup : [fTorrents count]) - i - 1;
|
2008-01-23 03:12:06 +00:00
|
|
|
[indexSet addIndexesInRange: NSMakeRange(i+1, count)];
|
2008-01-23 18:47:34 +00:00
|
|
|
i = nextGroup-1;
|
2008-01-23 03:12:06 +00:00
|
|
|
}
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
[fTorrents objectsAtIndexes: indexSet];
|
2008-01-22 23:48:14 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSMenu *) menuForEvent: (NSEvent *) event
|
|
|
|
{
|
|
|
|
int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
|
|
|
|
|
|
|
|
if (row >= 0)
|
|
|
|
{
|
|
|
|
if (![self isRowSelected: row])
|
|
|
|
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
|
|
|
return fContextRow;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self deselectAll: self];
|
|
|
|
return fContextNoRow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-16 21:09:59 +00:00
|
|
|
//make sure that the pause buttons become orange when holding down the option key
|
2007-10-27 14:57:46 +00:00
|
|
|
- (void) flagsChanged: (NSEvent *) event
|
|
|
|
{
|
|
|
|
[self display];
|
|
|
|
[super flagsChanged: event];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) keyDown: (NSEvent *) event
|
|
|
|
{
|
2007-10-27 14:57:46 +00:00
|
|
|
//this is handled by the delegate in Leopard
|
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
|
|
|
{
|
|
|
|
[super keyDown: event];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-23 05:39:41 +00:00
|
|
|
if (!fKeyStrokes)
|
|
|
|
fKeyStrokes = [[NSMutableArray alloc] init];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
unichar newChar = [[event characters] characterAtIndex: 0];
|
|
|
|
if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar]
|
|
|
|
|| [[NSCharacterSet symbolCharacterSet] characterIsMember: newChar]
|
|
|
|
|| [[NSCharacterSet punctuationCharacterSet] characterIsMember: newChar])
|
|
|
|
{
|
|
|
|
if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0)
|
|
|
|
[fKeyStrokes removeAllObjects];
|
|
|
|
[fKeyStrokes addObject: event];
|
|
|
|
|
|
|
|
[self interpretKeyEvents: fKeyStrokes];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-23 05:39:41 +00:00
|
|
|
[fKeyStrokes removeAllObjects];
|
2007-09-16 01:02:06 +00:00
|
|
|
[super keyDown: event];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) insertText: (NSString *) text
|
|
|
|
{
|
2007-10-27 14:57:46 +00:00
|
|
|
//this is handled by the delegate in Leopard
|
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
|
|
|
{
|
|
|
|
[super insertText: text];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//sort torrents by name before finding closest match
|
|
|
|
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES
|
|
|
|
selector: @selector(caseInsensitiveCompare:)] autorelease];
|
|
|
|
|
2008-01-16 19:30:12 +00:00
|
|
|
NSArray * tempTorrents = [fTorrents sortedArrayUsingDescriptors: [NSArray arrayWithObject: nameDescriptor]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-27 14:57:46 +00:00
|
|
|
text = [text lowercaseString];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//select torrent closest to text that isn't before text alphabetically
|
|
|
|
NSEnumerator * enumerator = [tempTorrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
2007-10-27 14:57:46 +00:00
|
|
|
if ([[[torrent name] lowercaseString] hasPrefix: text])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-10-27 18:40:43 +00:00
|
|
|
int row = [fTorrents indexOfObject: torrent];
|
|
|
|
[self selectRow: row byExtendingSelection: NO];
|
|
|
|
[self scrollRowToVisible: row];
|
|
|
|
return;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
- (void) toggleControlForTorrent: (Torrent *) torrent
|
|
|
|
{
|
|
|
|
if ([torrent isActive])
|
|
|
|
[fController stopTorrents: [NSArray arrayWithObject: torrent]];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
|
|
|
|
[fController resumeTorrentsNoWait: [NSArray arrayWithObject: torrent]];
|
|
|
|
else if ([torrent waitingToStart])
|
|
|
|
[fController stopTorrents: [NSArray arrayWithObject: torrent]];
|
|
|
|
else
|
|
|
|
[fController resumeTorrents: [NSArray arrayWithObject: torrent]];
|
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) displayTorrentMenuForEvent: (NSEvent *) event
|
|
|
|
{
|
|
|
|
int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
|
|
|
|
if (row < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//get and update file menu
|
|
|
|
fMenuTorrent = [[fTorrents objectAtIndex: row] retain];
|
|
|
|
NSMenu * fileMenu = [fMenuTorrent fileMenu];
|
|
|
|
[self updateFileMenu: fileMenu forFiles: [fMenuTorrent fileList]];
|
|
|
|
|
|
|
|
//add file menu items to action menu
|
2007-10-12 23:18:21 +00:00
|
|
|
NSRange range = NSMakeRange(0, [fileMenu numberOfItems]);
|
2007-12-17 16:06:20 +00:00
|
|
|
[fActionMenu appendItemsFromMenu: fileMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range] atBottom: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//place menu below button
|
2008-01-24 21:14:02 +00:00
|
|
|
NSRect rect = [fTorrentCell iconRectForBounds: [self frameOfCellAtColumn: 0 row: row]];
|
2007-09-16 01:02:06 +00:00
|
|
|
NSPoint location = rect.origin;
|
|
|
|
location.y += rect.size.height + 5.0;
|
|
|
|
location = [self convertPoint: location toView: nil];
|
|
|
|
|
|
|
|
NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
|
|
|
|
modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
|
|
|
|
context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
|
|
|
|
|
|
|
|
[NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
|
|
|
|
|
|
|
|
//move file menu items back to the torrent's file menu
|
|
|
|
range.location = [fActionMenu numberOfItems] - range.length;
|
2007-12-17 16:06:20 +00:00
|
|
|
[fileMenu appendItemsFromMenu: fActionMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range] atBottom: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[fMenuTorrent release];
|
|
|
|
fMenuTorrent = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) menuNeedsUpdate: (NSMenu *) menu
|
|
|
|
{
|
|
|
|
//this method seems to be called when it shouldn't be
|
|
|
|
if (!fMenuTorrent || ![menu supermenu])
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (menu == fUploadMenu || menu == fDownloadMenu)
|
|
|
|
{
|
2008-01-10 06:52:13 +00:00
|
|
|
NSMenuItem * item;
|
|
|
|
if ([menu numberOfItems] == 4)
|
|
|
|
{
|
2008-01-10 07:00:56 +00:00
|
|
|
const int speedLimitActionValue[] = { 0, 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750, -1 };
|
|
|
|
|
2008-01-10 06:52:13 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; speedLimitActionValue[i] != -1; i++)
|
|
|
|
{
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%d KB/s",
|
|
|
|
"Action menu -> upload/download limit"), speedLimitActionValue[i]] action: @selector(setQuickLimit:)
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setRepresentedObject: [NSNumber numberWithInt: speedLimitActionValue[i]]];
|
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
BOOL upload = menu == fUploadMenu;
|
2007-09-20 20:24:33 +00:00
|
|
|
int mode = [fMenuTorrent speedMode: upload];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-10 06:52:13 +00:00
|
|
|
item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
|
|
|
|
[item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
|
2008-01-10 06:52:13 +00:00
|
|
|
"torrent action menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
|
|
|
|
[item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState];
|
|
|
|
|
|
|
|
item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
|
|
|
|
[item setState: mode == TR_SPEEDLIMIT_GLOBAL ? NSOnState : NSOffState];
|
|
|
|
}
|
|
|
|
else if (menu == fRatioMenu)
|
|
|
|
{
|
2008-01-10 06:52:13 +00:00
|
|
|
NSMenuItem * item;
|
|
|
|
if ([menu numberOfItems] == 4)
|
|
|
|
{
|
2008-01-10 07:00:56 +00:00
|
|
|
const float ratioLimitActionValue[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, -1.0 };
|
|
|
|
|
2008-01-10 06:52:13 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; ratioLimitActionValue[i] != -1.0; i++)
|
|
|
|
{
|
2008-01-10 15:53:02 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%.2f", ratioLimitActionValue[i]]
|
|
|
|
action: @selector(setQuickRatio:) keyEquivalent: @""];
|
2008-01-10 06:52:13 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setRepresentedObject: [NSNumber numberWithFloat: ratioLimitActionValue[i]]];
|
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
int mode = [fMenuTorrent ratioSetting];
|
|
|
|
|
2008-01-10 06:52:13 +00:00
|
|
|
item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setState: mode == NSOnState ? NSOnState : NSOffState];
|
2008-01-10 06:52:13 +00:00
|
|
|
[item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)", "torrent action menu -> ratio stop"),
|
|
|
|
[fMenuTorrent ratioLimit]]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
|
|
|
|
[item setState: mode == NSOffState ? NSOnState : NSOffState];
|
|
|
|
|
|
|
|
item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
|
|
|
|
[item setState: mode == NSMixedState ? NSOnState : NSOffState];
|
|
|
|
}
|
2008-01-22 05:19:18 +00:00
|
|
|
else //assume the menu is part of the file list
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSMenu * supermenu = [menu supermenu];
|
|
|
|
[self updateFileMenu: menu forFiles: [[[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]]
|
|
|
|
representedObject] objectForKey: @"Children"]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setQuickLimitMode: (id) sender
|
|
|
|
{
|
2007-09-20 20:24:33 +00:00
|
|
|
int mode;
|
2007-10-11 12:06:46 +00:00
|
|
|
switch ([sender tag])
|
|
|
|
{
|
|
|
|
case ACTION_MENU_UNLIMITED_TAG:
|
|
|
|
mode = TR_SPEEDLIMIT_UNLIMITED;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_LIMIT_TAG:
|
|
|
|
mode = TR_SPEEDLIMIT_SINGLE;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_GLOBAL_TAG:
|
|
|
|
mode = TR_SPEEDLIMIT_GLOBAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[fMenuTorrent setSpeedMode: mode upload: [sender menu] == fUploadMenu];
|
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setQuickLimit: (id) sender
|
|
|
|
{
|
|
|
|
BOOL upload = [sender menu] == fUploadMenu;
|
|
|
|
[fMenuTorrent setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: upload];
|
2008-01-10 06:52:13 +00:00
|
|
|
[fMenuTorrent setSpeedLimit: [[sender representedObject] intValue] upload: upload];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setQuickRatioMode: (id) sender
|
|
|
|
{
|
|
|
|
int mode;
|
2007-10-11 12:06:46 +00:00
|
|
|
switch ([sender tag])
|
|
|
|
{
|
|
|
|
case ACTION_MENU_UNLIMITED_TAG:
|
|
|
|
mode = NSOffState;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_LIMIT_TAG:
|
|
|
|
mode = NSOnState;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_GLOBAL_TAG:
|
|
|
|
mode = NSMixedState;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[fMenuTorrent setRatioSetting: mode];
|
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setQuickRatio: (id) sender
|
|
|
|
{
|
|
|
|
[fMenuTorrent setRatioSetting: NSOnState];
|
2008-01-10 06:52:13 +00:00
|
|
|
[fMenuTorrent setRatioLimit: [[sender representedObject] floatValue]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) checkFile: (id) sender
|
|
|
|
{
|
|
|
|
NSIndexSet * indexSet = [[sender representedObject] objectForKey: @"Indexes"];
|
|
|
|
[fMenuTorrent setFileCheckState: [sender state] != NSOnState ? NSOnState : NSOffState forIndexes: indexSet];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
|
|
|
|
}
|
|
|
|
|
2008-01-16 19:30:12 +00:00
|
|
|
- (void) togglePiecesBar
|
2008-01-16 15:56:40 +00:00
|
|
|
{
|
|
|
|
[self resizePiecesBarIncrement];
|
|
|
|
|
2008-01-16 16:39:18 +00:00
|
|
|
if (!fPiecesBarTimer)
|
|
|
|
{
|
|
|
|
fPiecesBarTimer = [NSTimer scheduledTimerWithTimeInterval: PIECE_TIME target: self
|
|
|
|
selector: @selector(resizePiecesBarIncrement) userInfo: nil repeats: YES];
|
|
|
|
[[NSRunLoop currentRunLoop] addTimer: fPiecesBarTimer forMode: NSModalPanelRunLoopMode];
|
|
|
|
[[NSRunLoop currentRunLoop] addTimer: fPiecesBarTimer forMode: NSEventTrackingRunLoopMode];
|
|
|
|
}
|
2008-01-16 15:56:40 +00:00
|
|
|
}
|
|
|
|
|
2008-01-16 19:30:12 +00:00
|
|
|
- (float) piecesBarPercent
|
|
|
|
{
|
|
|
|
return fPiecesBarPercent;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentTableView (Private)
|
|
|
|
|
2008-01-15 03:50:00 +00:00
|
|
|
- (BOOL) pointInControlRect: (NSPoint) point
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
|
|
|
int row = [self rowAtPoint: point];
|
2008-01-23 17:03:42 +00:00
|
|
|
if (row < 0 || [fGroupIndexes containsIndex: row])
|
2008-01-15 03:33:44 +00:00
|
|
|
return NO;
|
|
|
|
|
2008-01-24 21:14:02 +00:00
|
|
|
return NSPointInRect(point, [fTorrentCell controlButtonRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) pointInRevealRect: (NSPoint) point
|
|
|
|
{
|
|
|
|
int row = [self rowAtPoint: point];
|
2008-01-23 17:03:42 +00:00
|
|
|
if (row < 0 || [fGroupIndexes containsIndex: row])
|
2008-01-15 03:33:44 +00:00
|
|
|
return NO;
|
|
|
|
|
2008-01-24 21:14:02 +00:00
|
|
|
return NSPointInRect(point, [fTorrentCell revealButtonRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
|
2008-01-15 03:50:00 +00:00
|
|
|
}
|
2008-01-15 03:33:44 +00:00
|
|
|
|
2008-01-14 19:12:26 +00:00
|
|
|
- (BOOL) pointInActionRect: (NSPoint) point
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
int row = [self rowAtPoint: point];
|
2008-01-23 17:03:42 +00:00
|
|
|
if (row < 0 || [fGroupIndexes containsIndex: row])
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
|
2008-01-24 21:14:02 +00:00
|
|
|
return NSPointInRect(point, [fTorrentCell iconRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-23 05:39:41 +00:00
|
|
|
- (BOOL) pointInProgressRect: (NSPoint) point
|
|
|
|
{
|
|
|
|
int row = [self rowAtPoint: point];
|
2008-01-23 17:03:42 +00:00
|
|
|
if (row < 0 || [fGroupIndexes containsIndex: row] || [fDefaults boolForKey: @"SmallView"])
|
2007-09-23 05:39:41 +00:00
|
|
|
return NO;
|
|
|
|
|
2008-01-23 17:03:42 +00:00
|
|
|
TorrentCell * cell;
|
2008-01-12 05:09:03 +00:00
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
2008-01-24 15:09:28 +00:00
|
|
|
cell = (TorrentCell *)[self preparedCellAtColumn: 0 row: row];
|
2008-01-12 05:09:03 +00:00
|
|
|
else
|
|
|
|
{
|
2008-01-24 21:14:02 +00:00
|
|
|
cell = fTorrentCell;
|
2008-01-12 05:09:03 +00:00
|
|
|
[cell setRepresentedObject: [fTorrents objectAtIndex: row]];
|
|
|
|
}
|
2008-01-23 17:03:42 +00:00
|
|
|
return NSPointInRect(point, [cell progressRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
|
2007-09-23 05:39:41 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (BOOL) pointInMinimalStatusRect: (NSPoint) point
|
|
|
|
{
|
|
|
|
int row = [self rowAtPoint: point];
|
2008-01-23 17:03:42 +00:00
|
|
|
if (row < 0 || [fGroupIndexes containsIndex: row] || ![fDefaults boolForKey: @"SmallView"])
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
|
2008-01-23 17:03:42 +00:00
|
|
|
TorrentCell * cell;
|
2008-01-12 05:09:03 +00:00
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
2008-01-24 15:09:28 +00:00
|
|
|
cell = (TorrentCell *)[self preparedCellAtColumn: 0 row: row];
|
2008-01-12 05:09:03 +00:00
|
|
|
else
|
|
|
|
{
|
2008-01-24 21:14:02 +00:00
|
|
|
cell = fTorrentCell;
|
2008-01-12 05:09:03 +00:00
|
|
|
[cell setRepresentedObject: [fTorrents objectAtIndex: row]];
|
|
|
|
}
|
2008-01-23 17:03:42 +00:00
|
|
|
return NSPointInRect(point, [cell minimalStatusRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files
|
|
|
|
{
|
|
|
|
BOOL create = [menu numberOfItems] <= 0;
|
|
|
|
|
|
|
|
NSEnumerator * enumerator = [files objectEnumerator];
|
|
|
|
NSDictionary * dict;
|
|
|
|
NSMenuItem * item;
|
|
|
|
while ((dict = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
NSString * name = [dict objectForKey: @"Name"];
|
|
|
|
|
|
|
|
if (create)
|
|
|
|
{
|
2007-12-17 16:06:20 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle: name action: @selector(checkFile:) keyEquivalent: @""];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
NSImage * icon;
|
|
|
|
if (![[dict objectForKey: @"IsFolder"] boolValue])
|
2007-11-26 17:33:31 +00:00
|
|
|
icon = [[NSWorkspace sharedWorkspace] iconForFileType: [name pathExtension]];
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name];
|
|
|
|
[itemMenu setAutoenablesItems: NO];
|
|
|
|
[item setSubmenu: itemMenu];
|
|
|
|
[itemMenu setDelegate: self];
|
|
|
|
[itemMenu release];
|
|
|
|
|
2007-11-26 17:33:31 +00:00
|
|
|
icon = [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[item setRepresentedObject: dict];
|
|
|
|
|
|
|
|
[icon setScalesWhenResized: YES];
|
|
|
|
[icon setSize: NSMakeSize(16.0, 16.0)];
|
|
|
|
[item setImage: icon];
|
|
|
|
|
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
item = [menu itemWithTitle: name];
|
|
|
|
|
|
|
|
NSIndexSet * indexSet = [dict objectForKey: @"Indexes"];
|
|
|
|
[item setState: [fMenuTorrent checkForFiles: indexSet]];
|
|
|
|
[item setEnabled: [fMenuTorrent canChangeDownloadCheckForFiles: indexSet]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-16 15:56:40 +00:00
|
|
|
- (void) resizePiecesBarIncrement
|
|
|
|
{
|
2008-01-27 19:10:14 +00:00
|
|
|
BOOL done;
|
|
|
|
if ([fDefaults boolForKey: @"PiecesBar"])
|
|
|
|
{
|
|
|
|
fPiecesBarPercent = MIN(fPiecesBarPercent + PIECE_INCREASE, 1.0);
|
|
|
|
done = fPiecesBarPercent == 1.0;
|
|
|
|
}
|
2008-01-16 15:56:40 +00:00
|
|
|
else
|
2008-01-27 19:10:14 +00:00
|
|
|
{
|
|
|
|
fPiecesBarPercent = MAX(fPiecesBarPercent - PIECE_INCREASE, 0.0);
|
|
|
|
done = fPiecesBarPercent == 0.0;
|
|
|
|
}
|
2008-01-16 15:56:40 +00:00
|
|
|
|
2008-01-27 19:10:14 +00:00
|
|
|
if (done)
|
2008-01-16 15:56:40 +00:00
|
|
|
{
|
|
|
|
[fPiecesBarTimer invalidate];
|
|
|
|
fPiecesBarTimer = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self reloadData];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|