1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-15 16:29:34 +00:00

use built-in buttons for filter buttons

This commit is contained in:
Mitchell Livingston 2007-11-06 20:52:11 +00:00
parent 9df263326d
commit 5cc14442cb
10 changed files with 19 additions and 409 deletions

View file

@ -69,8 +69,7 @@
* fTrackerSortActionItem, * fDateSortActionItem, * fOrderSortActionItem;
IBOutlet FilterBarView * fFilterBar;
IBOutlet FilterBarButton * fNoFilterButton, * fDownloadFilterButton,
* fSeedFilterButton, * fPauseFilterButton;
IBOutlet NSButton * fNoFilterButton, * fDownloadFilterButton, * fSeedFilterButton, * fPauseFilterButton;
IBOutlet NSSearchField * fSearchFilterField;
IBOutlet NSMenuItem * fNextFilterItem, * fPrevFilterItem;

View file

@ -339,7 +339,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
#warning clean up
NSString * filterType = [fDefaults stringForKey: @"Filter"];
FilterBarButton * currentFilterButton;
NSButton * currentFilterButton;
if ([filterType isEqualToString: FILTER_PAUSE])
currentFilterButton = fPauseFilterButton;
else if ([filterType isEqualToString: FILTER_SEED])
@ -1154,8 +1154,8 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
" and trash both data and torrent files.", "Removal confirm panel -> title"), torrentName];
message = NSLocalizedString(@"This transfer is active."
" Once removed, continuing the transfer will require the torrent file."
" Do you really want to remove it?", "Removal confirm panel -> message");
" Once removed, continuing the transfer will require the torrent file.",
"Removal confirm panel -> message");
}
else
{
@ -1180,8 +1180,8 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
message = [NSString stringWithFormat: NSLocalizedString(@"There are %d transfers (%d active).",
"Removal confirm panel -> message part 1"), selected, active];
message = [message stringByAppendingString:
NSLocalizedString(@" Once removed, continuing the transfers will require the torrent files."
" Do you really want to remove them?", "Removal confirm panel -> message part 2")];
NSLocalizedString(@" Once removed, continuing the transfers will require the torrent files.",
"Removal confirm panel -> message part 2")];
}
NSBeginAlertSheet(title, NSLocalizedString(@"Remove", "Removal confirm panel -> button"),
@ -1856,10 +1856,11 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[tempTorrents setArray: fTorrents];
//set buttons with counts
[fNoFilterButton setCount: [fTorrents count]];
#warning reimplement
/*[fNoFilterButton setCount: [fTorrents count]];
[fDownloadFilterButton setCount: downloading];
[fSeedFilterButton setCount: seeding];
[fPauseFilterButton setCount: paused];
[fPauseFilterButton setCount: paused];*/
NSString * searchString = [fSearchFilterField stringValue];
if ([searchString length] > 0)
@ -1942,7 +1943,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
{
NSString * oldFilterType = [fDefaults stringForKey: @"Filter"];
FilterBarButton * prevFilterButton;
NSButton * prevFilterButton;
if ([oldFilterType isEqualToString: FILTER_PAUSE])
prevFilterButton = fPauseFilterButton;
else if ([oldFilterType isEqualToString: FILTER_SEED])
@ -1999,11 +2000,12 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[self applyFilter: nil];
}
#warning improve
- (void) switchFilter: (id) sender
{
NSString * filterType = [fDefaults stringForKey: @"Filter"];
FilterBarButton * button;
NSButton * button;
if ([filterType isEqualToString: FILTER_NONE])
button = sender == fNextFilterItem ? fDownloadFilterButton : fPauseFilterButton;
else if ([filterType isEqualToString: FILTER_DOWNLOAD])

View file

@ -9,17 +9,6 @@
<string>FilterBarView</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>OUTLETS</key>
<dict>
<key>fDownloadFilterButton</key>
<string>FilterBarButton</string>
<key>fNoFilterButton</key>
<string>FilterBarButton</string>
<key>fPauseFilterButton</key>
<string>FilterBarButton</string>
<key>fSeedFilterButton</key>
<string>FilterBarButton</string>
</dict>
<key>SUPERCLASS</key>
<string>ImageBackgroundView</string>
</dict>
@ -173,7 +162,7 @@
<key>fDockMenu</key>
<string>NSMenu</string>
<key>fDownloadFilterButton</key>
<string>FilterBarButton</string>
<string>NSButton</string>
<key>fDownloadLimitItem</key>
<string>NSMenuItem</string>
<key>fDownloadMenu</key>
@ -191,7 +180,7 @@
<key>fNextInfoTabItem</key>
<string>NSMenuItem</string>
<key>fNoFilterButton</key>
<string>FilterBarButton</string>
<string>NSButton</string>
<key>fOpenIgnoreDownloadFolder</key>
<string>NSMenuItem</string>
<key>fOrderSortActionItem</key>
@ -199,7 +188,7 @@
<key>fOrderSortItem</key>
<string>NSMenuItem</string>
<key>fPauseFilterButton</key>
<string>FilterBarButton</string>
<string>NSButton</string>
<key>fPrevFilterItem</key>
<string>NSMenuItem</string>
<key>fPrevInfoTabItem</key>
@ -213,7 +202,7 @@
<key>fSearchFilterField</key>
<string>NSSearchField</string>
<key>fSeedFilterButton</key>
<string>FilterBarButton</string>
<string>NSButton</string>
<key>fSpeedLimitButton</key>
<string>NSButton</string>
<key>fStateSortActionItem</key>
@ -252,14 +241,6 @@
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
<dict>
<key>CLASS</key>
<string>FilterBarButton</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>SUPERCLASS</key>
<string>NSButton</string>
</dict>
<dict>
<key>ACTIONS</key>
<dict>

View file

@ -10,7 +10,7 @@
<integer>5</integer>
<key>IBOpenObjects</key>
<array>
<integer>2185</integer>
<integer>1603</integer>
</array>
<key>IBSystem Version</key>
<string>9A581</string>

Binary file not shown.

View file

@ -1,51 +0,0 @@
/******************************************************************************
* $Id$
*
* Copyright (c) 2006-2007 Transmission authors and contributors
*
* 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 <Cocoa/Cocoa.h>
@class CTGradient;
@interface FilterBarButton : NSButton
{
int fCount;
int fState;
BOOL fEnabled;
NSTrackingRectTag fTrackingTag;
NSBezierPath * fPath, * fEdgePath, * fStepPath;
NSDictionary * fNormalAttributes, * fNormalDimAttributes,
* fHighlightedAttributes, * fHighlightedDimAttributes;
CTGradient * fHighlightedBackground, * fHighlightedOutline,
* fActiveBackground, * fActiveOutline,
* fHoveringBackground;
NSColor * fHoveringOutline;
}
- (void) setCount: (int) count;
- (void) setEnabled: (BOOL) enable;
- (void) resetBounds: (NSNotification *) notification;
- (void) setForActive: (NSNotification *) notification;
- (void) setForInactive: (NSNotification *) notification;
@end

View file

@ -1,300 +0,0 @@
/******************************************************************************
* $Id$
*
* Copyright (c) 2006-2007 Transmission authors and contributors
*
* 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 "FilterBarButton.h"
#import "CTGradient.h"
#import "CTGradientAdditions.h"
#import "NSBezierPathAdditions.h"
@interface FilterBarButton (Private)
- (void) createPaths;
- (void) createGradients;
- (void) createFontAttributes;
@end
@implementation FilterBarButton
- (id) initWithCoder: (NSCoder *) coder
{
if ((self = [super initWithCoder: coder]))
{
fEnabled = NO;
fTrackingTag = 0;
fCount = -1;
[self setCount: 0];
[self createPaths];
[self createGradients];
[self createFontAttributes];
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self selector: @selector(setForActive:) name: NSWindowDidBecomeKeyNotification object: [self window]];
[nc addObserver: self selector: @selector(setForInactive:) name: NSWindowDidResignKeyNotification object: [self window]];
[nc addObserver: self selector: @selector(resetBounds:) name: NSViewFrameDidChangeNotification object: nil];
}
return self;
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[fPath release];
[fEdgePath release];
[fStepPath release];
[fNormalAttributes release];
[fNormalDimAttributes release];
[fHighlightedAttributes release];
[fHighlightedDimAttributes release];
[fHighlightedBackground release];
[fHighlightedOutline release];
[fActiveBackground release];
[fActiveOutline release];
[fHoveringBackground release];
[fHoveringOutline release];
[super dealloc];
}
- (void) sizeToFit
{
NSSize size = [[self title] sizeWithAttributes: fNormalAttributes];
size.width = floorf(size.width + 14.5);
size.height += 1;
[self setFrameSize: size];
[self setBoundsSize: size];
[self createPaths];
}
- (BOOL) isFlipped
{
return NO;
}
- (void) drawRect: (NSRect) rect
{
// draw background
if ([[self cell] isHighlighted])
{
[fHighlightedBackground fillBezierPath: fPath angle: -90.0];
[fHighlightedOutline fillBezierPath: fStepPath angle: -90.0];
}
else
switch (fState)
{
case 1: // active
[fActiveBackground fillBezierPath: fPath angle: -90.0];
[fActiveOutline fillBezierPath: fStepPath angle: -90.0];
break;
case 2: // hovering
case 3: // clicked but cell is not highlighted
[fHoveringBackground fillBezierPath: fPath angle: -90.0];
[fHoveringOutline setStroke];
[fEdgePath stroke];
break;
}
// draw title
NSSize titleSize = [[self title] sizeWithAttributes: fNormalAttributes];
NSPoint titlePos = NSMakePoint(([self bounds].size.width - titleSize.width) * 0.5,
([self bounds].size.height - titleSize.height) * 0.5 + 1.5);
NSDictionary * attributes;
if (fState)
attributes = fEnabled ? fHighlightedAttributes : fHighlightedDimAttributes;
else
attributes = fEnabled ? fNormalAttributes : fNormalDimAttributes;
[[self title] drawAtPoint: titlePos withAttributes: attributes];
}
- (void) setCount: (int) count
{
if (count == fCount)
return;
fCount = count;
[self setToolTip: fCount == 1 ? NSLocalizedString(@"1 Transfer", "Filter Bar Button -> tool tip")
: [NSString stringWithFormat: NSLocalizedString(@"%d Transfers", "Filter Bar Button -> tool tip"), fCount]];
}
- (void) mouseDown: (NSEvent *) event
{
if ([self state] != 1)
[self setState: 3];
[super mouseDown: event];
}
- (void) mouseUp: (NSEvent *) event
{
[super mouseUp: event];
if ([self state] != 1)
[self setState: 1];
}
- (void) mouseEntered: (NSEvent *) event
{
[super mouseEntered: event];
if ([self state] == 0)
[self setState: 2];
}
- (void) mouseExited: (NSEvent *) event
{
[super mouseExited: event];
if ([self state] >= 2)
[self setState: 0];
}
- (void) setEnabled: (BOOL) enable
{
fEnabled = enable;
[self setNeedsDisplay: YES];
}
- (int) state
{
return fState;
}
- (void) setState: (int) state
{
fState = state;
[self setNeedsDisplay: YES];
}
- (void) resetBounds: (NSNotification *) notification
{
if (fTrackingTag)
[self removeTrackingRect: fTrackingTag];
fTrackingTag = [self addTrackingRect: [self bounds] owner: self userData: nil assumeInside: NO];
}
- (void) setForActive: (NSNotification *) notification
{
[self setEnabled: YES];
[self resetBounds: nil];
[self setNeedsDisplay: YES];
}
- (void) setForInactive: (NSNotification *) notification
{
if (fTrackingTag)
{
[self removeTrackingRect: fTrackingTag];
fTrackingTag = 0;
}
[self setEnabled: NO];
[self setNeedsDisplay: YES];
}
@end
@implementation FilterBarButton (Private)
- (void) createPaths
{
NSSize buttonSize = [self frame].size;
// the main button path
[fPath release];
fPath = [[NSBezierPath bezierPathWithRoundedRect: NSMakeRect(0.0, 1.0, buttonSize.width, buttonSize.height - 1.0)
radius: (buttonSize.height - 1.0) / 2.0] retain];
// the path used to draw the hover edging
[fEdgePath release];
fEdgePath = [[NSBezierPath bezierPathWithRoundedRect: NSMakeRect(0.5, 1.5, buttonSize.width - 1.0, buttonSize.height - 2.0)
radius: (buttonSize.height - 2.0) / 2.0] retain];
// the path used to draw the depressed shading/highlights of the active button
[fStepPath release];
fStepPath = [[NSBezierPath bezierPathWithRoundedRect: NSMakeRect(0.0, 0.0, buttonSize.width, buttonSize.height - 1.0)
radius: (buttonSize.height - 1.0) / 2.0] retain];
[fStepPath appendBezierPath: fPath];
[fStepPath setWindingRule: NSEvenOddWindingRule];
}
- (void) createGradients
{
NSColor *quarterAlphaBlack = [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.25];
NSColor *thirdAlphaWhite = [NSColor colorWithCalibratedWhite: 1.0 alpha: 0.3333];
fHighlightedBackground = [[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedRed: 134.0/255 green: 151.0/255 blue: 176.0/255 alpha: 1.0]
endingColor: [NSColor colorWithCalibratedRed: 104.0/255 green: 125.0/255 blue: 157.0/255 alpha: 1.0]] retain];
fHighlightedOutline = [[CTGradient gradientWithBeginningColor: quarterAlphaBlack
middleColor1: quarterAlphaBlack
middleColor2: thirdAlphaWhite
endingColor: thirdAlphaWhite] retain];
fActiveBackground = [[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedRed: 151.0/255 green: 166.0/255 blue: 188.0/255 alpha: 1.0]
endingColor: [NSColor colorWithCalibratedRed: 126.0/255 green: 144.0/255 blue: 171.0/255 alpha: 1.0]] retain];
fActiveOutline = [fHighlightedOutline retain];
fHoveringBackground = [[CTGradient gradientWithBeginningColor: [NSColor colorWithCalibratedRed: 164.0/255 green: 177.0/255 blue: 196.0/255 alpha: 1.0]
endingColor: [NSColor colorWithCalibratedRed: 141.0/255 green: 158.0/255 blue: 182.0/255 alpha: 1.0]] retain];
fHoveringOutline = [[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.075] retain];
}
- (void) createFontAttributes
{
NSFont * boldSystemFont = [NSFont boldSystemFontOfSize: 12.0];
NSSize shadowOffset = NSMakeSize(0.0, -1.0);
NSShadow * shadowNormal = [[[NSShadow alloc] init] autorelease];
[shadowNormal setShadowOffset: shadowOffset];
[shadowNormal setShadowBlurRadius: 1.0];
[shadowNormal setShadowColor: [NSColor colorWithCalibratedWhite: 1.0 alpha: 0.4]];
NSShadow * shadowNormalDim = [[[NSShadow alloc] init] autorelease];
[shadowNormalDim setShadowOffset: shadowOffset];
[shadowNormalDim setShadowBlurRadius: 1.0];
[shadowNormalDim setShadowColor: [NSColor colorWithCalibratedWhite: 1.0 alpha: 0.2]];
NSShadow * shadowHighlighted = [[[NSShadow alloc] init] autorelease];
[shadowHighlighted setShadowOffset: shadowOffset];
[shadowHighlighted setShadowBlurRadius: 1.0];
[shadowHighlighted setShadowColor: [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.4]];
fNormalAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSColor colorWithCalibratedWhite: 0.259 alpha: 1.0], NSForegroundColorAttributeName,
boldSystemFont, NSFontAttributeName,
shadowNormal, NSShadowAttributeName, nil];
fNormalDimAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSColor disabledControlTextColor], NSForegroundColorAttributeName,
boldSystemFont, NSFontAttributeName,
shadowNormalDim, NSShadowAttributeName, nil];
fHighlightedAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSColor whiteColor], NSForegroundColorAttributeName,
boldSystemFont, NSFontAttributeName,
shadowHighlighted, NSShadowAttributeName, nil];
fHighlightedDimAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSColor colorWithCalibratedWhite: 0.9 alpha: 1.0], NSForegroundColorAttributeName,
boldSystemFont, NSFontAttributeName,
shadowHighlighted, NSShadowAttributeName, nil];
}
@end

View file

@ -24,12 +24,9 @@
#import <Cocoa/Cocoa.h>
#import "ImageBackgroundView.h"
#import "FilterBarButton.h"
@interface FilterBarView : ImageBackgroundView
{
IBOutlet FilterBarButton * fNoFilterButton, * fDownloadFilterButton,
* fSeedFilterButton, * fPauseFilterButton;
}
@end

View file

@ -22,32 +22,15 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#import "FilterBarView.h"
#warning needed?
#define ORIGIN_VERTICAL 3.0
#define ORIGIN_HORIZONTAL 4.0
#define PADDING_HORIZONTAL 2.0
#import "FilterBarView.h"
@implementation FilterBarView
- (void) awakeFromNib
{
[self setBackgroundImage: [NSImage imageNamed: @"FilterBarBackground.png"]];
[fNoFilterButton setTitle: NSLocalizedString(@"All", @"Filter Bar Button -> title")];
[fDownloadFilterButton setTitle: NSLocalizedString(@"Downloading", @"Filter Bar Button -> title")];
[fSeedFilterButton setTitle: NSLocalizedString(@"Seeding", @"Filter Bar Button -> title")];
[fPauseFilterButton setTitle: NSLocalizedString(@"Paused", @"Filter Bar Button -> title")];
[fNoFilterButton sizeToFit];
[fDownloadFilterButton sizeToFit];
[fSeedFilterButton sizeToFit];
[fPauseFilterButton sizeToFit];
[fNoFilterButton setFrameOrigin: NSMakePoint(ORIGIN_HORIZONTAL, ORIGIN_VERTICAL)];
[fDownloadFilterButton setFrameOrigin: NSMakePoint(NSMaxX([fNoFilterButton frame]) + PADDING_HORIZONTAL, ORIGIN_VERTICAL)];
[fSeedFilterButton setFrameOrigin: NSMakePoint(NSMaxX([fDownloadFilterButton frame]) + PADDING_HORIZONTAL, ORIGIN_VERTICAL)];
[fPauseFilterButton setFrameOrigin: NSMakePoint(NSMaxX([fSeedFilterButton frame]) + PADDING_HORIZONTAL, ORIGIN_VERTICAL)];
}
@end

View file

@ -461,7 +461,6 @@
float * piecePercent = malloc(pieceCount * sizeof(float));
[torrent getAmountFinished: piecePercent size: pieceCount];
//lines 2 to 14: blue, green, or gray depending on piece availability
int i, h, index;
float increment = (float)pieceCount / MAX_PIECES;
NSColor * pieceColor;