the beginnings of an overlay badge when dragging on files
This commit is contained in:
parent
c95ceafb9d
commit
55c54b0961
|
@ -118,7 +118,6 @@
|
|||
A24999230B49F1B5001EADA3 /* ActionPopUpButton.m in Sources */ = {isa = PBXBuildFile; fileRef = A24999210B49F1B5001EADA3 /* ActionPopUpButton.m */; };
|
||||
A24F19080A3A790800C9C145 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A24F19070A3A790800C9C145 /* Sparkle.framework */; };
|
||||
A24F19210A3A796800C9C145 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = A24F19070A3A790800C9C145 /* Sparkle.framework */; };
|
||||
A251EAB80BE1A2370023D908 /* Controller.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4DF0C5AA0899190500DD8943 /* Controller.h */; };
|
||||
A253F6F30A698970008EE24F /* FilterBarBackground.png in Resources */ = {isa = PBXBuildFile; fileRef = A253F6F20A698970008EE24F /* FilterBarBackground.png */; };
|
||||
A253F70B0A6990EB008EE24F /* FilterButtonOverMain.png in Resources */ = {isa = PBXBuildFile; fileRef = A253F7080A6990EB008EE24F /* FilterButtonOverMain.png */; };
|
||||
A253F70C0A6990EB008EE24F /* FilterButtonOverLeft.png in Resources */ = {isa = PBXBuildFile; fileRef = A253F7090A6990EB008EE24F /* FilterButtonOverLeft.png */; };
|
||||
|
@ -150,7 +149,6 @@
|
|||
A29B0C270BD15FEF0006F230 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = A2F8951E0A2D4BA500ED2127 /* Credits.rtf */; };
|
||||
A29C8B330ACC6E93000ED9F9 /* YellowDot.tiff in Resources */ = {isa = PBXBuildFile; fileRef = A29C8B320ACC6E93000ED9F9 /* YellowDot.tiff */; };
|
||||
A29C8B370ACC6EB3000ED9F9 /* PortChecker.m in Sources */ = {isa = PBXBuildFile; fileRef = A29C8B350ACC6EB3000ED9F9 /* PortChecker.m */; };
|
||||
A2A1CB790BF29D5500AE959F /* PeerProgressIndicatorCell.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = A2A1CB770BF29D5500AE959F /* PeerProgressIndicatorCell.h */; };
|
||||
A2A1CB7A0BF29D5500AE959F /* PeerProgressIndicatorCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A1CB780BF29D5500AE959F /* PeerProgressIndicatorCell.m */; };
|
||||
A2A3065C0AAD24A80049E2AC /* UKFileWatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A306540AAD24A80049E2AC /* UKFileWatcher.m */; };
|
||||
A2A3065E0AAD24A80049E2AC /* UKFNSubscribeFileWatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = A2A306560AAD24A80049E2AC /* UKFNSubscribeFileWatcher.m */; };
|
||||
|
@ -166,6 +164,7 @@
|
|||
A2D4F0850A915F7200890C32 /* GreenDot.tiff in Resources */ = {isa = PBXBuildFile; fileRef = A2D4F0840A915F7200890C32 /* GreenDot.tiff */; };
|
||||
A2F40AE40A361C00006B8288 /* Transmission.icns in Resources */ = {isa = PBXBuildFile; fileRef = 4D2784360905709500687951 /* Transmission.icns */; };
|
||||
A2F6DB090A55F31C0058D1E5 /* SpeedLimitButton.png in Resources */ = {isa = PBXBuildFile; fileRef = A2F6DB070A55F31C0058D1E5 /* SpeedLimitButton.png */; };
|
||||
A2FB057F0BFEB6800095564D /* DragOverlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = A2FB057D0BFEB6800095564D /* DragOverlayView.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
@ -194,8 +193,6 @@
|
|||
files = (
|
||||
A261F1E40A69A1B10002815A /* Growl.framework in CopyFiles */,
|
||||
A24F19210A3A796800C9C145 /* Sparkle.framework in CopyFiles */,
|
||||
A251EAB80BE1A2370023D908 /* Controller.h in CopyFiles */,
|
||||
A2A1CB790BF29D5500AE959F /* PeerProgressIndicatorCell.h in CopyFiles */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -417,6 +414,8 @@
|
|||
A2D4F0840A915F7200890C32 /* GreenDot.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = GreenDot.tiff; path = macosx/Images/GreenDot.tiff; sourceTree = "<group>"; };
|
||||
A2F6DB070A55F31C0058D1E5 /* SpeedLimitButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = SpeedLimitButton.png; path = macosx/Images/SpeedLimitButton.png; sourceTree = "<group>"; };
|
||||
A2F8951E0A2D4BA500ED2127 /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = Credits.rtf; path = macosx/Credits.rtf; sourceTree = "<group>"; };
|
||||
A2FB057C0BFEB6800095564D /* DragOverlayView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DragOverlayView.h; path = macosx/DragOverlayView.h; sourceTree = "<group>"; };
|
||||
A2FB057D0BFEB6800095564D /* DragOverlayView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = DragOverlayView.m; path = macosx/DragOverlayView.m; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -455,6 +454,8 @@
|
|||
080E96DDFE201D6D7F000001 /* Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A2FB057C0BFEB6800095564D /* DragOverlayView.h */,
|
||||
A2FB057D0BFEB6800095564D /* DragOverlayView.m */,
|
||||
A2385DD20BFE06C800B24EF6 /* DragOverlayWindow.m */,
|
||||
A2385DD30BFE06C800B24EF6 /* DragOverlayWindow.h */,
|
||||
A2265F3F0B5EF5F40093DDA5 /* FileBrowserCell.h */,
|
||||
|
@ -999,6 +1000,7 @@
|
|||
A2265F420B5EF5F40093DDA5 /* FileBrowserCell.m in Sources */,
|
||||
A2A1CB7A0BF29D5500AE959F /* PeerProgressIndicatorCell.m in Sources */,
|
||||
A2385DD40BFE06C800B24EF6 /* DragOverlayWindow.m in Sources */,
|
||||
A2FB057F0BFEB6800095564D /* DragOverlayView.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -167,6 +167,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
fPrefsController = [[PrefsController alloc] initWithWindowNibName: @"PrefsWindow" handle: fLib];
|
||||
|
||||
fBadger = [[Badger alloc] initWithLib: fLib];
|
||||
fOverlayWindow = [[DragOverlayWindow alloc] initWithLib: fLib];
|
||||
|
||||
[GrowlApplicationBridge setGrowlDelegate: self];
|
||||
|
||||
|
@ -202,7 +203,6 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
[fFilterBar setBackgroundImage: [NSImage imageNamed: @"FilterBarBackground.png"]];
|
||||
|
||||
[fWindow setAcceptsMouseMovedEvents: YES]; //ensure filter buttons display correctly
|
||||
fOverlayWindow = [[DragOverlayWindow alloc] init];
|
||||
|
||||
fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Transmission Toolbar"];
|
||||
[fToolbar setDelegate: self];
|
||||
|
@ -2090,16 +2090,18 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
if ([[pasteboard types] containsObject: NSFilenamesPboardType])
|
||||
{
|
||||
//check if any files can be added
|
||||
NSEnumerator * enumerator = [[pasteboard propertyListForType: NSFilenamesPboardType] objectEnumerator];
|
||||
NSArray * files = [pasteboard propertyListForType: NSFilenamesPboardType];
|
||||
NSEnumerator * enumerator = [files objectEnumerator];
|
||||
NSString * file;
|
||||
tr_torrent_t * tempTor;
|
||||
while ((file = [enumerator nextObject]))
|
||||
{
|
||||
tr_torrent_t * tempTor;
|
||||
int error;
|
||||
if ((tempTor = tr_torrentInit(fLib, [file UTF8String], NULL, 0, &error)))
|
||||
{
|
||||
tr_torrentClose(fLib, tempTor);
|
||||
|
||||
[fOverlayWindow setFiles: files];
|
||||
[fOverlayWindow setFrame: [fWindow frame] display: YES];
|
||||
[fWindow addChildWindow: fOverlayWindow ordered: NSWindowAbove];
|
||||
|
||||
|
@ -2137,9 +2139,9 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
NSMutableArray * filesToOpen = [[NSMutableArray alloc] init];
|
||||
NSEnumerator * enumerator = [[pasteboard propertyListForType: NSFilenamesPboardType] objectEnumerator];
|
||||
NSString * file;
|
||||
tr_torrent_t * tempTor;
|
||||
while ((file = [enumerator nextObject]))
|
||||
{
|
||||
tr_torrent_t * tempTor;
|
||||
int error;
|
||||
if ((tempTor = tr_torrentInit(fLib, [file UTF8String], NULL, 0, &error)))
|
||||
{
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/******************************************************************************
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 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>
|
||||
|
||||
@interface DragOverlayView : NSView
|
||||
{
|
||||
NSImage * fImage, * fAppIcon;
|
||||
|
||||
NSDictionary * fMainLineAttributes, * fSubLineAttributes;
|
||||
}
|
||||
|
||||
- (void) setOverlay: (NSImage *) icon mainLine: (NSString *) mainLine subLine: (NSString *) subLine;
|
||||
|
||||
@end
|
|
@ -0,0 +1,146 @@
|
|||
/******************************************************************************
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 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 "DragOverlayView.h"
|
||||
|
||||
@implementation DragOverlayView
|
||||
|
||||
- (id) initWithFrame: (NSRect) frame
|
||||
{
|
||||
if ((self = [super initWithFrame: frame]))
|
||||
{
|
||||
NSShadow * stringShadow = [[NSShadow alloc] init];
|
||||
[stringShadow setShadowOffset: NSMakeSize(2.0, -2.0)];
|
||||
[stringShadow setShadowBlurRadius: 4.0];
|
||||
|
||||
NSFont * bigFont = [[NSFontManager sharedFontManager] convertFont:
|
||||
[NSFont fontWithName: @"Lucida Grande" size: 18.0] toHaveTrait: NSBoldFontMask],
|
||||
* smallFont = [NSFont fontWithName: @"Lucida Grande" size: 14.0];
|
||||
|
||||
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
||||
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
|
||||
|
||||
fMainLineAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSColor whiteColor], NSForegroundColorAttributeName,
|
||||
bigFont, NSFontAttributeName, stringShadow, NSShadowAttributeName,
|
||||
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
||||
|
||||
fSubLineAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSColor whiteColor], NSForegroundColorAttributeName,
|
||||
smallFont, NSFontAttributeName, stringShadow, NSShadowAttributeName,
|
||||
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
||||
|
||||
[stringShadow release];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (fImage)
|
||||
[fImage release];
|
||||
if (fAppIcon)
|
||||
[fAppIcon release];
|
||||
|
||||
[fMainLineAttributes release];
|
||||
[fSubLineAttributes release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) setOverlay: (NSImage *) icon mainLine: (NSString *) mainLine subLine: (NSString *) subLine
|
||||
{
|
||||
NSSize iconSize = NSMakeSize(64.0, 64.0);
|
||||
if (!icon)
|
||||
{
|
||||
if (!fAppIcon)
|
||||
{
|
||||
fAppIcon = [[NSImage imageNamed: @"TransmissionDocument.icns"] copy];
|
||||
[fAppIcon setScalesWhenResized: YES];
|
||||
[fAppIcon setSize: iconSize];
|
||||
}
|
||||
icon = [fAppIcon retain];
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = [icon copy];
|
||||
[icon setScalesWhenResized: YES];
|
||||
[icon setSize: iconSize];
|
||||
}
|
||||
|
||||
if (fImage)
|
||||
[fImage release];
|
||||
fImage = [[NSImage alloc] initWithSize: NSMakeSize(300.0, 84.0)];
|
||||
|
||||
[fImage lockFocus];
|
||||
|
||||
//create oval
|
||||
#warning don't do each time
|
||||
NSRect badgeRect = NSMakeRect(0, 0, 300.0, 80.0);
|
||||
[[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.75] set];
|
||||
[NSBezierPath fillRect: badgeRect];
|
||||
|
||||
[[NSColor whiteColor] set];
|
||||
[NSBezierPath setDefaultLineWidth: 3.0];
|
||||
[NSBezierPath strokeRect: badgeRect];
|
||||
|
||||
float padding = 10.0;
|
||||
|
||||
//place icon
|
||||
[icon compositeToPoint: NSMakePoint(padding, (badgeRect.size.height - iconSize.height) * 0.5)
|
||||
operation: NSCompositeSourceOver];
|
||||
|
||||
//place main text
|
||||
NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes];
|
||||
NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes];
|
||||
|
||||
NSRect lineRect = NSMakeRect(padding + iconSize.width + 5.0,
|
||||
(badgeRect.size.height + (subLineSize.height + 2.0 - mainLineSize.height)) * 0.5,
|
||||
badgeRect.size.width - (padding + iconSize.width + 2.0) - padding, mainLineSize.height);
|
||||
[mainLine drawInRect: lineRect withAttributes: fMainLineAttributes];
|
||||
|
||||
//place sub text
|
||||
lineRect.origin.y -= subLineSize.height + 2.0;
|
||||
lineRect.size.height = subLineSize.height;
|
||||
[subLine drawInRect: lineRect withAttributes: fSubLineAttributes];
|
||||
|
||||
[fImage unlockFocus];
|
||||
|
||||
[icon release];
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void) drawRect: (NSRect) rect
|
||||
{
|
||||
if (fImage)
|
||||
{
|
||||
NSRect frame = [self frame];
|
||||
NSSize imageSize = [fImage size];
|
||||
[fImage compositeToPoint: NSMakePoint((frame.size.width - imageSize.width) * 0.5,
|
||||
(frame.size.height - imageSize.height) * 0.5) operation: NSCompositeSourceOver];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -23,9 +23,13 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <transmission.h>
|
||||
|
||||
@interface DragOverlayWindow : NSWindow
|
||||
{
|
||||
tr_handle_t * fLib;
|
||||
}
|
||||
|
||||
- (void) setFiles: (NSArray *) files;
|
||||
|
||||
@end
|
||||
|
|
|
@ -23,19 +23,27 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#import "DragOverlayWindow.h"
|
||||
#import "DragOverlayView.h"
|
||||
#import "StringAdditions.h"
|
||||
|
||||
@implementation DragOverlayWindow
|
||||
|
||||
- (id) init
|
||||
- (id) initWithLib: (tr_handle_t *) lib
|
||||
{
|
||||
if (self = ([super initWithContentRect: NSMakeRect(0, 0, 0, 0) styleMask: NSBorderlessWindowMask
|
||||
if (self = ([super initWithContentRect: NSMakeRect(0, 0, 1.0, 1.0) styleMask: NSBorderlessWindowMask
|
||||
backing: NSBackingStoreBuffered defer: NO]))
|
||||
{
|
||||
[self setBackgroundColor: [NSColor blackColor]];
|
||||
[self setLevel: NSStatusWindowLevel];
|
||||
[self setAlphaValue: 0.5];
|
||||
fLib = lib;
|
||||
|
||||
[self setBackgroundColor: [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.5]];
|
||||
[self setAlphaValue: 1.0];
|
||||
[self setOpaque: NO];
|
||||
[self setHasShadow: NO];
|
||||
[self setLevel: NSStatusWindowLevel];
|
||||
|
||||
DragOverlayView * backgroundView = [[DragOverlayView alloc] initWithFrame: [self frame]];
|
||||
[self setContentView: backgroundView];
|
||||
[backgroundView release];
|
||||
|
||||
[self setReleasedWhenClosed: NO];
|
||||
[self setIgnoresMouseEvents: YES];
|
||||
|
@ -43,4 +51,55 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) setFiles: (NSArray *) files
|
||||
{
|
||||
uint64_t size = 0;
|
||||
int count = 0;
|
||||
|
||||
NSString * name;
|
||||
BOOL folder;
|
||||
|
||||
NSString * file;
|
||||
NSEnumerator * enumerator = [files objectEnumerator];
|
||||
tr_torrent_t * tempTor;
|
||||
tr_info_t * info;
|
||||
while ((file = [enumerator nextObject]))
|
||||
{
|
||||
int error;
|
||||
if ((tempTor = tr_torrentInit(fLib, [file UTF8String], NULL, 0, &error)))
|
||||
{
|
||||
info = tr_torrentInfo(tempTor);
|
||||
|
||||
count++;
|
||||
size += info->totalSize;
|
||||
|
||||
//only useful when one torrent
|
||||
if (count == 1)
|
||||
{
|
||||
name = [NSString stringWithUTF8String: info->name];
|
||||
folder = info->multifile;
|
||||
}
|
||||
|
||||
tr_torrentClose(fLib, tempTor);
|
||||
}
|
||||
}
|
||||
|
||||
NSImage * icon = nil;
|
||||
NSString * sizeString = [NSString stringForFileSize: size];
|
||||
if (count == 1)
|
||||
icon = [[NSWorkspace sharedWorkspace] iconForFileType: folder ? NSFileTypeForHFSTypeCode('fldr') : [name pathExtension]];
|
||||
else
|
||||
{
|
||||
name = [NSString stringWithFormat: NSLocalizedString(@"%d Torrent Files", "Drag overlay -> multiple drag files"), count];
|
||||
sizeString = [sizeString stringByAppendingString: @" Total"];
|
||||
}
|
||||
|
||||
[[self contentView] setOverlay: icon mainLine: name subLine: sizeString];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue