~sense/ubuntu/lucid/transmission/fix-497882

« back to all changes in this revision

Viewing changes to macosx/TorrentCell.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: TorrentCell.m 6252 2008-06-25 05:01:04Z livings124 $
 
2
 * $Id: TorrentCell.m 7032 2008-11-04 01:31:24Z livings124 $
3
3
 *
4
4
 * Copyright (c) 2006-2008 Transmission authors and contributors
5
5
 *
28
28
#import "NSApplicationAdditions.h"
29
29
#import "NSStringAdditions.h"
30
30
#import "NSBezierPathAdditions.h"
31
 
#import "CTGradientAdditions.h"
32
 
 
33
 
#define BAR_HEIGHT 12.0
34
 
 
35
 
#define IMAGE_SIZE_REG 32.0
36
 
#define IMAGE_SIZE_MIN 16.0
37
 
 
38
 
#define NORMAL_BUTTON_WIDTH 14.0
39
 
#define ACTION_BUTTON_WIDTH 16.0
 
31
#import "ProgressGradients.h"
 
32
#import "CTGradient.h"
 
33
 
 
34
#define BAR_HEIGHT 12.0f
 
35
 
 
36
#define IMAGE_SIZE_REG 32.0f
 
37
#define IMAGE_SIZE_MIN 16.0f
 
38
 
 
39
#define NORMAL_BUTTON_WIDTH 14.0f
 
40
#define ACTION_BUTTON_WIDTH 16.0f
40
41
 
41
42
//ends up being larger than font height
42
 
#define HEIGHT_TITLE 16.0
43
 
#define HEIGHT_STATUS 12.0
44
 
 
45
 
#define PADDING_HORIZONTAL 3.0
46
 
#define PADDING_BETWEEN_IMAGE_AND_TITLE 5.0
47
 
#define PADDING_BETWEEN_IMAGE_AND_BAR 7.0
48
 
#define PADDING_ABOVE_TITLE 4.0
49
 
#define PADDING_ABOVE_MIN_STATUS 4.0
50
 
#define PADDING_BETWEEN_TITLE_AND_MIN_STATUS 2.0
51
 
#define PADDING_BETWEEN_TITLE_AND_PROGRESS 1.0
52
 
#define PADDING_BETWEEN_PROGRESS_AND_BAR 2.0
53
 
#define PADDING_BETWEEN_TITLE_AND_BAR_MIN 3.0
54
 
#define PADDING_BETWEEN_BAR_AND_STATUS 2.0
55
 
 
56
 
#define PIECES_TOTAL_PERCENT 0.6
 
43
#define HEIGHT_TITLE 16.0f
 
44
#define HEIGHT_STATUS 12.0f
 
45
 
 
46
#define PADDING_HORIZONTAL 3.0f
 
47
#define PADDING_BETWEEN_IMAGE_AND_TITLE 5.0f
 
48
#define PADDING_BETWEEN_IMAGE_AND_BAR 7.0f
 
49
#define PADDING_ABOVE_TITLE 4.0f
 
50
#define PADDING_ABOVE_MIN_STATUS 4.0f
 
51
#define PADDING_BETWEEN_TITLE_AND_MIN_STATUS 2.0f
 
52
#define PADDING_BETWEEN_TITLE_AND_PROGRESS 1.0f
 
53
#define PADDING_BETWEEN_PROGRESS_AND_BAR 2.0f
 
54
#define PADDING_BETWEEN_TITLE_AND_BAR_MIN 3.0f
 
55
#define PADDING_BETWEEN_BAR_AND_STATUS 2.0f
 
56
 
 
57
#define PIECES_TOTAL_PERCENT 0.6f
57
58
 
58
59
#define MAX_PIECES (18*18)
59
60
 
91
92
        [paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
92
93
    
93
94
        fTitleAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
94
 
                                [NSFont messageFontOfSize: 12.0], NSFontAttributeName,
 
95
                                [NSFont messageFontOfSize: 12.0f], NSFontAttributeName,
95
96
                                paragraphStyle, NSParagraphStyleAttributeName, nil];
96
97
        fStatusAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
97
 
                                [NSFont messageFontOfSize: 9.0], NSFontAttributeName,
 
98
                                [NSFont messageFontOfSize: 9.0f], NSFontAttributeName,
98
99
                                paragraphStyle, NSParagraphStyleAttributeName, nil];
99
100
        [paragraphStyle release];
100
101
        
101
 
        fBluePieceColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.4 blue: 0.8 alpha: 1.0] retain];
102
 
        fBarBorderColor = [[NSColor colorWithDeviceWhite: 0.0 alpha: 0.2] retain];
 
102
        fBluePieceColor = [[NSColor colorWithCalibratedRed: 0.0f green: 0.4f blue: 0.8f alpha: 1.0f] retain];
 
103
        fBarBorderColor = [[NSColor colorWithDeviceWhite: 0.0f alpha: 0.2f] retain];
103
104
    }
104
105
        return self;
105
106
}
106
107
 
107
108
- (NSRect) iconRectForBounds: (NSRect) bounds
108
109
{
109
 
    float imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
 
110
    CGFloat imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
110
111
    
111
112
    NSRect result = bounds;
112
113
    result.origin.x += PADDING_HORIZONTAL;
113
 
    result.origin.y += floorf((result.size.height - imageSize) * 0.5);
 
114
    result.origin.y += floorf((result.size.height - imageSize) * 0.5f);
114
115
    result.size = NSMakeSize(imageSize, imageSize);
115
116
    
116
117
    return result;
154
155
    else
155
156
        result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
156
157
    
157
 
    result.size.width = round(NSMaxX(bounds) - result.origin.x - PADDING_HORIZONTAL - 2.0 * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH));
 
158
    result.size.width = round(NSMaxX(bounds) - result.origin.x - PADDING_HORIZONTAL - 2.0f * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH));
158
159
    
159
160
    return result;
160
161
}
172
173
    NSRect result = bounds;
173
174
    result.size.height = NORMAL_BUTTON_WIDTH;
174
175
    result.size.width = NORMAL_BUTTON_WIDTH;
175
 
    result.origin.x = NSMaxX(bounds) - 2.0 * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
 
176
    result.origin.x = NSMaxX(bounds) - 2.0f * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
176
177
    
177
 
    result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5;
 
178
    result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f;
178
179
    if ([fDefaults boolForKey: @"SmallView"])
179
180
        result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN;
180
181
    else
190
191
    result.size.width = NORMAL_BUTTON_WIDTH;
191
192
    result.origin.x = NSMaxX(bounds) - (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
192
193
    
193
 
    result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5;
 
194
    result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f;
194
195
    if ([fDefaults boolForKey: @"SmallView"])
195
196
        result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN;
196
197
    else
204
205
    NSRect result = [self iconRectForBounds: bounds];
205
206
    if (![fDefaults boolForKey: @"SmallView"])
206
207
    {
207
 
        result.origin.x += (result.size.width - ACTION_BUTTON_WIDTH) * 0.5;
208
 
        result.origin.y += (result.size.height - ACTION_BUTTON_WIDTH) * 0.5;
 
208
        result.origin.x += (result.size.width - ACTION_BUTTON_WIDTH) * 0.5f;
 
209
        result.origin.y += (result.size.height - ACTION_BUTTON_WIDTH) * 0.5f;
209
210
        result.size.width = ACTION_BUTTON_WIDTH;
210
211
        result.size.height = ACTION_BUTTON_WIDTH;
211
212
    }
383
384
    //group coloring
384
385
    NSRect iconRect = [self iconRectForBounds: cellFrame];
385
386
    
386
 
    int groupValue = [torrent groupValue];
 
387
    NSInteger groupValue = [torrent groupValue];
387
388
    if (groupValue != -1)
388
389
    {
389
 
        NSRect groupRect = NSInsetRect(iconRect, -1.0, -2.0);
 
390
        NSRect groupRect = NSInsetRect(iconRect, -1.0f, -2.0f);
390
391
        if (!minimal)
391
392
        {
392
393
            groupRect.size.height--;
393
394
            groupRect.origin.y--;
394
395
        }
395
 
        float radius = minimal ? 3.0 : 6.0;
 
396
        const CGFloat radius = minimal ? 3.0f : 6.0f;
396
397
        
397
398
        NSColor * groupColor = [[GroupsController groups] colorForIndex: groupValue],
398
 
                * darkGroupColor = [groupColor blendedColorWithFraction: 0.2 ofColor: [NSColor whiteColor]];
 
399
                * darkGroupColor = [groupColor blendedColorWithFraction: 0.2f ofColor: [NSColor whiteColor]];
399
400
        
400
401
        //border
401
402
        NSBezierPath * bp = [NSBezierPath bezierPathWithRoundedRect: groupRect radius: radius];
402
403
        [darkGroupColor set];
403
 
        [bp setLineWidth: 2.0];
 
404
        [bp setLineWidth: 2.0f];
404
405
        [bp stroke];
405
406
        
406
407
        //inside
407
408
        bp = [NSBezierPath bezierPathWithRoundedRect: groupRect radius: radius];
408
 
        CTGradient * gradient = [CTGradient gradientWithBeginningColor: [groupColor blendedColorWithFraction: 0.7
 
409
        CTGradient * gradient = [CTGradient gradientWithBeginningColor: [groupColor blendedColorWithFraction: 0.7f
409
410
                                    ofColor: [NSColor whiteColor]] endingColor: darkGroupColor];
410
 
        [gradient fillBezierPath: bp angle: 90.0];
 
411
        [gradient fillBezierPath: bp angle: 90.0f];
411
412
    }
412
413
    
413
414
    //error image
422
423
    if (!minimal || !(!fTracking && fHoverAction)) //don't show in minimal mode when hovered over
423
424
    {
424
425
        NSImage * icon = (minimal && error) ? fErrorImage : [torrent icon];
425
 
        [icon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
 
426
        [icon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0f];
426
427
    }
427
428
    
428
429
    if (error && !minimal)
429
430
    {
430
431
        NSRect errorRect = NSMakeRect(NSMaxX(iconRect) - IMAGE_SIZE_MIN, NSMaxY(iconRect) - IMAGE_SIZE_MIN,
431
432
                                        IMAGE_SIZE_MIN, IMAGE_SIZE_MIN);
432
 
        [fErrorImage drawInRect: errorRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
 
433
        [fErrorImage drawInRect: errorRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0f];
433
434
    }
434
435
    
435
436
    //text color
497
498
    
498
499
    [controlImage setFlipped: YES];
499
500
    [controlImage drawInRect: [self controlButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
500
 
        fraction: 1.0];
 
501
        fraction: 1.0f];
501
502
    
502
503
    //reveal button
503
504
    NSString * revealImageString;
511
512
    NSImage * revealImage = [NSImage imageNamed: revealImageString];
512
513
    [revealImage setFlipped: YES];
513
514
    [revealImage drawInRect: [self revealButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
514
 
        fraction: 1.0];
 
515
        fraction: 1.0f];
515
516
    
516
517
    //action button
517
518
    NSString * actionImageString;
527
528
        NSImage * actionImage = [NSImage imageNamed: actionImageString];
528
529
        [actionImage setFlipped: YES];
529
530
        [actionImage drawInRect: [self actionButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
530
 
            fraction: 1.0];
 
531
            fraction: 1.0f];
531
532
    }
532
533
    
533
534
    //status
544
545
 
545
546
- (void) drawBar: (NSRect) barRect
546
547
{
547
 
    float piecesBarPercent = [(TorrentTableView *)[self controlView] piecesBarPercent];
548
 
    if (piecesBarPercent > 0.0)
 
548
    CGFloat piecesBarPercent = [(TorrentTableView *)[self controlView] piecesBarPercent];
 
549
    if (piecesBarPercent > 0.0f)
549
550
    {
550
551
        NSRect regularBarRect = barRect, piecesBarRect = barRect;
551
552
        piecesBarRect.size.height *= PIECES_TOTAL_PERCENT * piecesBarPercent;
563
564
    }
564
565
    
565
566
    [fBarBorderColor set];
566
 
    [NSBezierPath strokeRect: NSInsetRect(barRect, 0.5, 0.5)];
 
567
    [NSBezierPath strokeRect: NSInsetRect(barRect, 0.5f, 0.5f)];
567
568
}
568
569
 
569
570
- (void) drawRegularBar: (NSRect) barRect
570
571
{
571
572
    Torrent * torrent = [self representedObject];
572
573
    
573
 
    int leftWidth = barRect.size.width;
574
 
    float progress = [torrent progress];
 
574
    NSInteger leftWidth = barRect.size.width;
 
575
    CGFloat progress = [torrent progress];
575
576
    
576
 
    if (progress < 1.0)
 
577
    if (progress < 1.0f)
577
578
    {
578
 
        float rightProgress = 1.0 - progress, progressLeft = [torrent progressLeft];
579
 
        int rightWidth = leftWidth * rightProgress;
 
579
        CGFloat rightProgress = 1.0f - progress, progressLeft = [torrent progressLeft];
 
580
        NSInteger rightWidth = leftWidth * rightProgress;
580
581
        leftWidth -= rightWidth;
581
582
        
582
583
        if (progressLeft < rightProgress)
583
584
        {
584
 
            int rightNoIncludeWidth = rightWidth * ((rightProgress - progressLeft) / rightProgress);
 
585
            NSInteger rightNoIncludeWidth = rightWidth * ((rightProgress - progressLeft) / rightProgress);
585
586
            rightWidth -= rightNoIncludeWidth;
586
587
            
587
588
            NSRect noIncludeRect = barRect;
588
589
            noIncludeRect.origin.x += barRect.size.width - rightNoIncludeWidth;
589
590
            noIncludeRect.size.width = rightNoIncludeWidth;
590
591
            
591
 
            [[CTGradient progressLightGrayGradient] fillRect: noIncludeRect angle: 90];
 
592
            [[ProgressGradients progressLightGrayGradient] fillRect: noIncludeRect angle: 90];
592
593
        }
593
594
        
594
595
        if (rightWidth > 0)
596
597
            if ([torrent isActive] && ![torrent allDownloaded] && ![torrent isChecking]
597
598
                && [fDefaults boolForKey: @"DisplayProgressBarAvailable"])
598
599
            {
599
 
                int notAvailableWidth = ceil(rightWidth * [torrent notAvailableDesired]);
 
600
                NSInteger notAvailableWidth = ceil(rightWidth * [torrent notAvailableDesired]);
600
601
                if (notAvailableWidth > 0)
601
602
                {
602
603
                    rightWidth -= notAvailableWidth;
605
606
                    notAvailableRect.origin.x += leftWidth + rightWidth;
606
607
                    notAvailableRect.size.width = notAvailableWidth;
607
608
                    
608
 
                    [[CTGradient progressRedGradient] fillRect: notAvailableRect angle: 90];
 
609
                    [[ProgressGradients progressRedGradient] fillRect: notAvailableRect angle: 90];
609
610
                }
610
611
            }
611
612
            
615
616
                includeRect.origin.x += leftWidth;
616
617
                includeRect.size.width = rightWidth;
617
618
                
618
 
                [[CTGradient progressWhiteGradient] fillRect: includeRect angle: 90];
 
619
                [[ProgressGradients progressWhiteGradient] fillRect: includeRect angle: 90];
619
620
            }
620
621
        }
621
622
    }
628
629
        if ([torrent isActive])
629
630
        {
630
631
            if ([torrent isChecking])
631
 
                [[CTGradient progressYellowGradient] fillRect: completeRect angle: 90];
 
632
                [[ProgressGradients progressYellowGradient] fillRect: completeRect angle: 90];
632
633
            else if ([torrent isSeeding])
633
634
            {
634
 
                int ratioLeftWidth = leftWidth * (1.0 - [torrent progressStopRatio]);
 
635
                NSInteger ratioLeftWidth = leftWidth * (1.0f - [torrent progressStopRatio]);
635
636
                leftWidth -= ratioLeftWidth;
636
637
                
637
638
                if (ratioLeftWidth > 0)
640
641
                    ratioLeftRect.origin.x += leftWidth;
641
642
                    ratioLeftRect.size.width = ratioLeftWidth;
642
643
                    
643
 
                    [[CTGradient progressLightGreenGradient] fillRect: ratioLeftRect angle: 90];
 
644
                    [[ProgressGradients progressLightGreenGradient] fillRect: ratioLeftRect angle: 90];
644
645
                }
645
646
                
646
647
                if (leftWidth > 0)
647
648
                {
648
649
                    completeRect.size.width = leftWidth;
649
650
                    
650
 
                    [[CTGradient progressGreenGradient] fillRect: completeRect angle: 90];
 
651
                    [[ProgressGradients progressGreenGradient] fillRect: completeRect angle: 90];
651
652
                }
652
653
            }
653
654
            else
654
 
                [[CTGradient progressBlueGradient] fillRect: completeRect angle: 90];
 
655
                [[ProgressGradients progressBlueGradient] fillRect: completeRect angle: 90];
655
656
        }
656
657
        else
657
658
        {
658
659
            if ([torrent waitingToStart])
659
660
            {
660
 
                if ([torrent progressLeft] <= 0.0)
661
 
                    [[CTGradient progressDarkGreenGradient] fillRect: completeRect angle: 90];
 
661
                if ([torrent progressLeft] <= 0.0f)
 
662
                    [[ProgressGradients progressDarkGreenGradient] fillRect: completeRect angle: 90];
662
663
                else
663
 
                    [[CTGradient progressDarkBlueGradient] fillRect: completeRect angle: 90];
 
664
                    [[ProgressGradients progressDarkBlueGradient] fillRect: completeRect angle: 90];
664
665
            }
665
666
            else
666
 
                [[CTGradient progressGrayGradient] fillRect: completeRect angle: 90];
 
667
                [[ProgressGradients progressGrayGradient] fillRect: completeRect angle: 90];
667
668
        }
668
669
    }
669
670
}
672
673
{
673
674
    Torrent * torrent = [self representedObject];
674
675
    
675
 
    int pieceCount = MIN([torrent pieceCount], MAX_PIECES);
 
676
    NSInteger pieceCount = MIN([torrent pieceCount], MAX_PIECES);
676
677
    float * piecesPercent = malloc(pieceCount * sizeof(float));
677
678
    [torrent getAmountFinished: piecesPercent size: pieceCount];
678
679
    
683
684
    NSIndexSet * previousFinishedIndexes = [torrent previousFinishedPieces];
684
685
    NSMutableIndexSet * finishedIndexes = [NSMutableIndexSet indexSet];
685
686
    
686
 
    int i;
687
 
    for (i = 0; i < pieceCount; i++)
 
687
    for (NSInteger i = 0; i < pieceCount; i++)
688
688
    {
689
689
        NSColor * pieceColor;
690
 
        if (piecesPercent[i] == 1.0)
 
690
        if (piecesPercent[i] == 1.0f)
691
691
        {
692
692
            if (previousFinishedIndexes && ![previousFinishedIndexes containsIndex: i])
693
693
                pieceColor = [NSColor orangeColor];