~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-updates

« back to all changes in this revision

Viewing changes to macosx/TorrentTableView.m

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2008-11-28 15:33:48 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20081128153348-it70trfnxiroblmc
Tags: 1.40-0ubuntu1
* New upstream release (LP: #302672)
  - Tracker communication uses fewer resources
  - More accurate bandwidth limits
  - Reduce disk fragmentation by preallocating files (LP: #287726)
  - Stability, security and performance improvements to the RPC /
    Web UI server (closes LP: #290423)
  - Support compression when serving Web UI and RPC responses
  - Simplify the RPC whitelist
  - Fix bug that prevented handshakes with encrypted BitComet peers
  - Fix 1.3x bug that could re-download some data unnecessarily
    (LP: #295040)
  - Option to automatically update the blocklist weekly
  - Added off-hour bandwidth scheduling
  - Simplify file/priority selection in the details dialog
  - Fix a couple of crashes
  - New / updated translations
  - Don't inhibit hibernation by default (LP: #292929)
  - Use "close" animation when sending to notification area (LP: #130811)
  - Fix resize problems (LP: #269872)
  - Support "--version" option when launching from command line
    (LP: #292011)
  - Correctly parse announce URLs that have leading or trailing
    spaces (LP: #262411)
  - Display an error when "Open Torrent" fails (LP: #281463)
* Dropped 10_fix_crasher_from_upstream.dpatch: Fix is in this
  upstream release.
* debian/control: Don't just build-depend on libcurl-dev, which is
  a virtual package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: TorrentTableView.m 6289 2008-07-07 02:09:27Z livings124 $
 
2
 * $Id: TorrentTableView.m 7080 2008-11-09 12:12:29Z livings124 $
3
3
 *
4
4
 * Copyright (c) 2005-2008 Transmission authors and contributors
5
5
 *
30
30
#import "QuickLookController.h"
31
31
#import "NSApplicationAdditions.h"
32
32
 
33
 
#define MAX_GROUP (INT_MAX-10)
 
33
#define MAX_GROUP 999999
34
34
 
35
35
#define ACTION_MENU_GLOBAL_TAG 101
36
36
#define ACTION_MENU_UNLIMITED_TAG 102
37
37
#define ACTION_MENU_LIMIT_TAG 103
38
38
 
39
 
#define GROUP_SPEED_IMAGE_COLUMN_WIDTH 8.0
40
 
#define GROUP_RATIO_IMAGE_COLUMN_WIDTH 10.0
 
39
#define GROUP_SPEED_IMAGE_COLUMN_WIDTH 8.0f
 
40
#define GROUP_RATIO_IMAGE_COLUMN_WIDTH 10.0f
41
41
 
42
42
#define TOGGLE_PROGRESS_SECONDS 0.175
43
43
 
71
71
            [self setOutlineTableColumn: groupColumn];
72
72
            
73
73
            //remove all unnecessary columns
74
 
            int i;
75
 
            for (i = [[self tableColumns] count]-1; i >= 0; i--)
 
74
            for (NSInteger i = [[self tableColumns] count]-1; i >= 0; i--)
76
75
            {
77
76
                NSTableColumn * column = [[self tableColumns] objectAtIndex: i];
78
77
                if (column != groupColumn)
97
96
        
98
97
        [self setDelegate: self];
99
98
        
100
 
        fPiecesBarPercent = [fDefaults boolForKey: @"PiecesBar"] ? 1.0 : 0.0;
 
99
        fPiecesBarPercent = [fDefaults boolForKey: @"PiecesBar"] ? 1.0f : 0.0f;
101
100
    }
102
101
    
103
102
    return self;
123
122
    [self setGroupStatusColumns];
124
123
}
125
124
 
126
 
- (BOOL) isGroupCollapsed: (int) value
 
125
- (BOOL) isGroupCollapsed: (NSInteger) value
127
126
{
128
127
    if (value == -1)
129
128
        value = MAX_GROUP;
131
130
    return [fCollapsedGroups containsIndex: value];
132
131
}
133
132
 
134
 
- (void) removeCollapsedGroup: (int) value
 
133
- (void) removeCollapsedGroup: (NSInteger) value
135
134
{
136
135
    if (value == -1)
137
136
        value = MAX_GROUP;
175
174
    {
176
175
        [cell setRepresentedObject: item];
177
176
        
178
 
        int row = [self rowForItem: item];
 
177
        NSInteger row = [self rowForItem: item];
179
178
        if ([NSApp isOnLeopardOrBetter])
180
179
        {
181
180
            [cell setControlHover: row == fMouseControlRow];
212
211
        
213
212
        //adjust placement for proper vertical alignment
214
213
        if (column == [self columnWithIdentifier: @"Group"])
215
 
            rect.size.height -= 1.0;
 
214
            rect.size.height -= 1.0f;
216
215
        
217
216
        return rect;
218
217
    }
235
234
                : NSLocalizedString(@"Upload speed", "Torrent table -> group row -> tooltip");
236
235
    else if (ident)
237
236
    {
238
 
        int count = [[item torrents] count];
 
237
        NSInteger count = [[item torrents] count];
239
238
        if (count == 1)
240
239
            return NSLocalizedString(@"1 transfer", "Torrent table -> group row -> tooltip");
241
240
        else
255
254
        return;
256
255
    
257
256
    NSPoint mouseLocation = [self convertPoint: [[self window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil];
258
 
    
259
 
    NSUInteger row;
260
 
    for (row = rows.location; row < NSMaxRange(rows); row++)
 
257
    for (NSUInteger row = rows.location; row < NSMaxRange(rows); row++)
261
258
    {
262
259
        if (![[self itemAtRow: row] isKindOfClass: [Torrent class]])
263
260
            continue;
286
283
    }
287
284
}
288
285
 
289
 
- (void) setControlButtonHover: (int) row
 
286
- (void) setControlButtonHover: (NSInteger) row
290
287
{
291
288
    fMouseControlRow = row;
292
289
    if (row >= 0)
293
290
        [self setNeedsDisplayInRect: [self rectOfRow: row]];
294
291
}
295
292
 
296
 
- (void) setRevealButtonHover: (int) row
 
293
- (void) setRevealButtonHover: (NSInteger) row
297
294
{
298
295
    fMouseRevealRow = row;
299
296
    if (row >= 0)
300
297
        [self setNeedsDisplayInRect: [self rectOfRow: row]];
301
298
}
302
299
 
303
 
- (void) setActionButtonHover: (int) row
 
300
- (void) setActionButtonHover: (NSInteger) row
304
301
{
305
302
    fMouseActionRow = row;
306
303
    if (row >= 0)
315
312
    NSNumber * row;
316
313
    if ((row = [dict objectForKey: @"Row"]))
317
314
    {
318
 
        int rowVal = [row intValue];
 
315
        NSInteger rowVal = [row intValue];
319
316
        NSString * type = [dict objectForKey: @"Type"];
320
317
        if ([type isEqualToString: @"Action"])
321
318
            fMouseActionRow = rowVal;
355
352
 
356
353
- (void) outlineViewItemDidExpand: (NSNotification *) notification
357
354
{
358
 
    int value = [[[notification userInfo] objectForKey: @"NSObject"] groupIndex];
 
355
    NSInteger value = [[[notification userInfo] objectForKey: @"NSObject"] groupIndex];
359
356
    if (value < 0)
360
357
        value = MAX_GROUP;
361
358
    
368
365
 
369
366
- (void) outlineViewItemDidCollapse: (NSNotification *) notification
370
367
{
371
 
    int value = [[[notification userInfo] objectForKey: @"NSObject"] groupIndex];
 
368
    NSInteger value = [[[notification userInfo] objectForKey: @"NSObject"] groupIndex];
372
369
    if (value < 0)
373
370
        value = MAX_GROUP;
374
371
    
403
400
    //avoid weird behavior when showing menu by doing this after mouse down
404
401
    if ([self pointInActionRect: point])
405
402
    {
406
 
        int row = [self rowAtPoint: point];
 
403
        NSInteger row = [self rowAtPoint: point];
407
404
        
408
405
        fActionPushedRow = row;
409
406
        [self setNeedsDisplayInRect: [self rectOfRow: row]]; //ensure button is pushed down
416
413
    else if (!pushed && [event clickCount] == 2) //double click
417
414
    {
418
415
        id item = nil;
419
 
        int row = [self rowAtPoint: point];
 
416
        NSInteger row = [self rowAtPoint: point];
420
417
        if (row != -1)
421
418
            item = [self itemAtRow: row];
422
419
        
449
446
        }
450
447
        else
451
448
        {
452
 
            int i, group = [item groupIndex];
453
 
            for (i = 0; i < [self numberOfRows]; i++)
 
449
            NSInteger group = [item groupIndex];
 
450
            for (NSInteger i = 0; i < [self numberOfRows]; i++)
454
451
            {
455
452
                if ([indexSet containsIndex: i])
456
453
                    continue;
473
470
    NSIndexSet * selectedIndexes = [self selectedRowIndexes];
474
471
    NSMutableArray * values = [NSMutableArray arrayWithCapacity: [selectedIndexes count]];
475
472
    
476
 
    NSUInteger i;
477
 
    for (i = [selectedIndexes firstIndex]; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex: i])
 
473
    for (NSUInteger i = [selectedIndexes firstIndex]; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex: i])
478
474
        [values addObject: [self itemAtRow: i]];
479
475
    
480
476
    return values;
485
481
    NSIndexSet * selectedIndexes = [self selectedRowIndexes];
486
482
    NSMutableArray * torrents = [NSMutableArray arrayWithCapacity: [selectedIndexes count]]; //take a shot at guessing capacity
487
483
    
488
 
    NSUInteger i;
489
 
    for (i = [selectedIndexes firstIndex]; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex: i])
 
484
    for (NSUInteger i = [selectedIndexes firstIndex]; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex: i])
490
485
    {
491
486
        id item = [self itemAtRow: i];
492
487
        if ([item isKindOfClass: [Torrent class]])
504
499
 
505
500
- (NSMenu *) menuForEvent: (NSEvent *) event
506
501
{
507
 
    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
 
502
    NSInteger row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
508
503
    if (row >= 0)
509
504
    {
510
505
        if (![self isRowSelected: row])
528
523
//option-command-f will focus the filter bar's search field
529
524
- (void) keyDown: (NSEvent *) event
530
525
{
531
 
    unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0];
 
526
    const unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0];
532
527
    
533
528
    if (firstChar == 'f' && [event modifierFlags] & NSAlternateKeyMask && [event modifierFlags] & NSCommandKeyMask)
534
529
        [fController focusFilterField];
547
542
    }
548
543
}
549
544
 
550
 
- (NSRect) iconRectForRow: (int) row
 
545
- (NSRect) iconRectForRow: (NSInteger) row
551
546
{
552
547
    return [fTorrentCell iconRectForBounds: [self rectOfRow: row]];
553
548
}
586
581
 
587
582
- (void) displayTorrentMenuForEvent: (NSEvent *) event
588
583
{
589
 
    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
 
584
    NSInteger row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
590
585
    if (row < 0)
591
586
        return;
592
587
    
599
594
    //place menu below button
600
595
    NSRect rect = [fTorrentCell iconRectForBounds: [self rectOfRow: row]];
601
596
    NSPoint location = rect.origin;
602
 
    location.y += rect.size.height + 5.0;
 
597
    location.y += rect.size.height + 5.0f;
603
598
    location = [self convertPoint: location toView: nil];
604
599
    
605
600
    NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
608
603
    
609
604
    [NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
610
605
    
611
 
    NSInteger i;
612
 
    for (i = [fActionMenu numberOfItems]-1; i >= numberOfNonFileItems; i--)
 
606
    for (NSInteger i = [fActionMenu numberOfItems]-1; i >= numberOfNonFileItems; i--)
613
607
        [fActionMenu removeItemAtIndex: i];
614
608
    
615
609
    [fMenuTorrent release];
627
621
        NSMenuItem * item;
628
622
        if ([menu numberOfItems] == 4)
629
623
        {
630
 
            const int speedLimitActionValue[] = { 0, 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750, -1 };
 
624
            const NSInteger speedLimitActionValue[] = { 0, 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750, -1 };
631
625
            
632
 
            int i;
633
 
            for (i = 0; speedLimitActionValue[i] != -1; i++)
 
626
            for (NSInteger i = 0; speedLimitActionValue[i] != -1; i++)
634
627
            {
635
628
                item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%d KB/s",
636
629
                        "Action menu -> upload/download limit"), speedLimitActionValue[i]] action: @selector(setQuickLimit:)
643
636
        }
644
637
        
645
638
        BOOL upload = menu == fUploadMenu;
646
 
        int mode = [fMenuTorrent speedMode: upload];
 
639
        NSInteger mode = [fMenuTorrent speedMode: upload];
647
640
        
648
641
        item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
649
642
        [item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
661
654
        NSMenuItem * item;
662
655
        if ([menu numberOfItems] == 4)
663
656
        {
664
 
            const float ratioLimitActionValue[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, -1.0 };
 
657
            const CGFloat ratioLimitActionValue[] = { 0.25f, 0.5f, 0.75f, 1.0f, 1.5f, 2.0f, 3.0f, -1.0f };
665
658
            
666
 
            int i;
667
 
            for (i = 0; ratioLimitActionValue[i] != -1.0; i++)
 
659
            for (NSInteger i = 0; ratioLimitActionValue[i] != -1.0f; i++)
668
660
            {
669
661
                item = [[NSMenuItem alloc] initWithTitle: [NSString localizedStringWithFormat: @"%.2f", ratioLimitActionValue[i]]
670
662
                        action: @selector(setQuickRatio:) keyEquivalent: @""];
675
667
            }
676
668
        }
677
669
        
678
 
        int mode = [fMenuTorrent ratioSetting];
 
670
        NSInteger mode = [fMenuTorrent ratioSetting];
679
671
        
680
672
        item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
681
673
        [item setState: mode == NSOnState ? NSOnState : NSOffState];
708
700
    NSRect visibleRect = clipRect;
709
701
    NSRange rows = [self rowsInRect: visibleRect];
710
702
    BOOL start = YES;
711
 
    int i;
712
703
    
713
704
    if (rows.length > 0)
714
705
    {
715
706
        //determine what the first row color should be
716
707
        if ([[self itemAtRow: rows.location] isKindOfClass: [Torrent class]])
717
708
        {
718
 
            for (i = rows.location-1; i>=0; i--)
 
709
            for (NSInteger i = rows.location-1; i>=0; i--)
719
710
            {
720
711
                if (![[self itemAtRow: i] isKindOfClass: [Torrent class]])
721
712
                    break;
728
719
            rows.length--;
729
720
        }
730
721
        
 
722
        NSInteger i;
731
723
        for (i = rows.location; i < NSMaxRange(rows); i++)
732
724
        {
733
725
            if (![[self itemAtRow: i] isKindOfClass: [Torrent class]])
742
734
            start = !start;
743
735
        }
744
736
        
745
 
        float newY = NSMaxY([self rectOfRow: i-1]);
 
737
        CGFloat newY = NSMaxY([self rectOfRow: i-1]);
746
738
        visibleRect.size.height -= newY - visibleRect.origin.y;
747
739
        visibleRect.origin.y = newY;
748
740
    }
749
 
    
 
741
        
750
742
    //remaining visible rows continue alternating
751
 
    float height = [self rowHeight] + [self intercellSpacing].height;
752
 
    int numberOfRects = ceil(visibleRect.size.height / height);
 
743
    const CGFloat height = [self rowHeight] + [self intercellSpacing].height;
 
744
    const NSInteger numberOfRects = ceil(visibleRect.size.height / height);
 
745
    
753
746
    visibleRect.size.height = height;
754
 
    
755
 
    for (i=0; i<numberOfRects; i++)
756
 
    {
757
 
        if (!start)
758
 
            NSRectFill(visibleRect);
759
 
        
760
 
        start = !start;
 
747
    if (start)
761
748
        visibleRect.origin.y += height;
 
749
    
 
750
    for (NSInteger i = start ? 1 : 0; i < numberOfRects; i += 2)
 
751
    {
 
752
        NSRectFill(visibleRect);
 
753
        visibleRect.origin.y += 2.0 * height;
762
754
    }
763
755
    
764
756
    [super highlightSelectionInClipRect: clipRect];
766
758
 
767
759
- (void) setQuickLimitMode: (id) sender
768
760
{
769
 
    int mode;
 
761
    NSInteger mode;
770
762
    switch ([sender tag])
771
763
    {
772
764
        case ACTION_MENU_UNLIMITED_TAG:
798
790
 
799
791
- (void) setQuickRatioMode: (id) sender
800
792
{
801
 
    int mode;
 
793
    NSInteger mode;
802
794
    switch ([sender tag])
803
795
    {
804
796
        case ACTION_MENU_UNLIMITED_TAG:
847
839
        [fPiecesBarAnimation release];
848
840
    
849
841
    NSMutableArray * progressMarks = [NSMutableArray arrayWithCapacity: 16];
850
 
    NSAnimationProgress i;
851
 
    for (i = 0.0625; i <= 1.0; i += 0.0625)
 
842
    for (NSAnimationProgress i = 0.0625f; i <= 1.0f; i += 0.0625f)
852
843
        [progressMarks addObject: [NSNumber numberWithFloat: i]];
853
844
    
854
845
    fPiecesBarAnimation = [[NSAnimation alloc] initWithDuration: TOGGLE_PROGRESS_SECONDS animationCurve: NSAnimationEaseIn];
875
866
        if ([fDefaults boolForKey: @"PiecesBar"])
876
867
            fPiecesBarPercent = progress;
877
868
        else
878
 
            fPiecesBarPercent = 1.0 - progress;
 
869
            fPiecesBarPercent = 1.0f - progress;
879
870
        
880
871
        [self reloadData];
881
872
    }
882
873
}
883
874
 
884
 
- (float) piecesBarPercent
 
875
- (CGFloat) piecesBarPercent
885
876
{
886
877
    return fPiecesBarPercent;
887
878
}
892
883
 
893
884
- (BOOL) pointInControlRect: (NSPoint) point
894
885
{
895
 
    int row = [self rowAtPoint: point];
 
886
    NSInteger row = [self rowAtPoint: point];
896
887
    if (row < 0 || ![[self itemAtRow: row] isKindOfClass: [Torrent class]])
897
888
        return NO;
898
889
    
901
892
 
902
893
- (BOOL) pointInRevealRect: (NSPoint) point
903
894
{
904
 
    int row = [self rowAtPoint: point];
 
895
    NSInteger row = [self rowAtPoint: point];
905
896
    if (row < 0 || ![[self itemAtRow: row] isKindOfClass: [Torrent class]])
906
897
        return NO;
907
898
    
910
901
 
911
902
- (BOOL) pointInActionRect: (NSPoint) point
912
903
{
913
 
    int row = [self rowAtPoint: point];
 
904
    NSInteger row = [self rowAtPoint: point];
914
905
    if (row < 0 || ![[self itemAtRow: row] isKindOfClass: [Torrent class]])
915
906
        return NO;
916
907
    
919
910
 
920
911
- (BOOL) pointInGroupStatusRect: (NSPoint) point
921
912
{
922
 
    int row = [self rowAtPoint: point];
 
913
    NSInteger row = [self rowAtPoint: point];
923
914
    if (row < 0 || [[self itemAtRow: row] isKindOfClass: [Torrent class]])
924
915
        return NO;
925
916
    
937
928
    
938
929
    //change size of image column
939
930
    NSTableColumn * ulImageTableColumn = [self tableColumnWithIdentifier: @"UL Image"];
940
 
    float oldWidth = [ulImageTableColumn width], newWidth = ratio ? GROUP_RATIO_IMAGE_COLUMN_WIDTH : GROUP_SPEED_IMAGE_COLUMN_WIDTH;
 
931
    CGFloat oldWidth = [ulImageTableColumn width], newWidth = ratio ? GROUP_RATIO_IMAGE_COLUMN_WIDTH : GROUP_SPEED_IMAGE_COLUMN_WIDTH;
941
932
    if (oldWidth != newWidth)
942
933
    {
943
934
        [ulImageTableColumn setWidth: newWidth];