2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2011-01-01 20:42:14 +00:00
|
|
|
* Copyright (c) 2007-2011 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 "DragOverlayWindow.h"
|
|
|
|
#import "DragOverlayView.h"
|
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
|
2010-01-28 03:16:55 +00:00
|
|
|
@interface DragOverlayWindow (Private)
|
|
|
|
|
|
|
|
- (void) resizeWindow;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@implementation DragOverlayWindow
|
|
|
|
|
2008-12-22 19:14:43 +00:00
|
|
|
- (id) initWithLib: (tr_session *) lib forWindow: (NSWindow *) window
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-02-05 02:51:42 +00:00
|
|
|
if ((self = ([super initWithContentRect: [window frame] styleMask: NSBorderlessWindowMask
|
2008-10-01 02:40:04 +00:00
|
|
|
backing: NSBackingStoreBuffered defer: NO])))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
fLib = lib;
|
|
|
|
|
2009-11-27 20:47:03 +00:00
|
|
|
[self setBackgroundColor: [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.5]];
|
|
|
|
[self setAlphaValue: 0.0];
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setOpaque: NO];
|
|
|
|
[self setHasShadow: NO];
|
|
|
|
|
|
|
|
DragOverlayView * view = [[DragOverlayView alloc] initWithFrame: [self frame]];
|
|
|
|
[self setContentView: view];
|
|
|
|
[view release];
|
|
|
|
|
|
|
|
[self setReleasedWhenClosed: NO];
|
|
|
|
[self setIgnoresMouseEvents: YES];
|
|
|
|
|
|
|
|
fFadeInAnimation = [[NSViewAnimation alloc] initWithViewAnimations: [NSArray arrayWithObject:
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys: self, NSViewAnimationTargetKey,
|
|
|
|
NSViewAnimationFadeInEffect, NSViewAnimationEffectKey, nil]]];
|
|
|
|
[fFadeInAnimation setDuration: 0.15];
|
2007-12-27 23:31:54 +00:00
|
|
|
[fFadeInAnimation setAnimationBlockingMode: NSAnimationNonblockingThreaded];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
fFadeOutAnimation = [[NSViewAnimation alloc] initWithViewAnimations: [NSArray arrayWithObject:
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys: self, NSViewAnimationTargetKey,
|
|
|
|
NSViewAnimationFadeOutEffect, NSViewAnimationEffectKey, nil]]];
|
|
|
|
[fFadeOutAnimation setDuration: 0.5];
|
|
|
|
[fFadeOutAnimation setAnimationBlockingMode: NSAnimationNonblockingThreaded];
|
|
|
|
|
|
|
|
[window addChildWindow: self ordered: NSWindowAbove];
|
2010-01-28 03:16:55 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(resizeWindow)
|
|
|
|
name: NSWindowDidResizeNotification object: window];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2010-01-28 03:16:55 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fFadeInAnimation release];
|
|
|
|
[fFadeOutAnimation release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTorrents: (NSArray *) files
|
|
|
|
{
|
|
|
|
uint64_t size = 0;
|
2008-11-01 22:08:02 +00:00
|
|
|
NSInteger count = 0;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
NSString * name;
|
|
|
|
BOOL folder;
|
2008-11-01 22:08:02 +00:00
|
|
|
NSInteger fileCount = 0;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-12-26 07:25:17 +00:00
|
|
|
for (NSString * file in files)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-06-10 22:56:24 +00:00
|
|
|
if ([[[NSWorkspace sharedWorkspace] typeOfFile: file error: NULL] isEqualToString: @"org.bittorrent.torrent"]
|
|
|
|
|| [[file pathExtension] caseInsensitiveCompare: @"torrent"] == NSOrderedSame)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-11-01 22:08:02 +00:00
|
|
|
tr_ctor * ctor = tr_ctorNew(fLib);
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
|
2008-11-01 22:08:02 +00:00
|
|
|
tr_info info;
|
2009-08-05 02:13:45 +00:00
|
|
|
if (tr_torrentParse(ctor, &info) == TR_PARSE_OK)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-12-22 03:31:22 +00:00
|
|
|
count++;
|
|
|
|
size += info.totalSize;
|
|
|
|
fileCount += info.fileCount;
|
|
|
|
|
|
|
|
//only useful when one torrent
|
|
|
|
if (count == 1)
|
|
|
|
{
|
|
|
|
name = [NSString stringWithUTF8String: info.name];
|
|
|
|
folder = info.isMultifile;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-22 03:31:22 +00:00
|
|
|
tr_metainfoFree(&info);
|
2007-12-26 16:42:46 +00:00
|
|
|
tr_ctorFree(ctor);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//set strings and icon
|
|
|
|
NSString * secondString = [NSString stringForFileSize: size];
|
|
|
|
if (count > 1 || folder)
|
|
|
|
{
|
|
|
|
NSString * fileString;
|
|
|
|
if (fileCount == 1)
|
2008-04-07 13:25:55 +00:00
|
|
|
fileString = NSLocalizedString(@"1 file", "Drag overlay -> torrents");
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2010-11-14 21:04:25 +00:00
|
|
|
fileString= [NSString stringWithFormat: NSLocalizedString(@"%@ files", "Drag overlay -> torrents"),
|
|
|
|
[NSString formattedUInteger: fileCount]];
|
2008-03-18 22:11:43 +00:00
|
|
|
secondString = [NSString stringWithFormat: @"%@, %@", fileString, secondString];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 06:03:38 +00:00
|
|
|
NSImage * icon;
|
2007-09-16 01:02:06 +00:00
|
|
|
if (count == 1)
|
|
|
|
icon = [[NSWorkspace sharedWorkspace] iconForFileType: folder ? NSFileTypeForHFSTypeCode('fldr') : [name pathExtension]];
|
|
|
|
else
|
|
|
|
{
|
2010-11-14 21:04:25 +00:00
|
|
|
name = [NSString stringWithFormat: NSLocalizedString(@"%@ Torrent Files", "Drag overlay -> torrents"),
|
|
|
|
[NSString formattedUInteger: count]];
|
2008-04-07 13:25:55 +00:00
|
|
|
secondString = [secondString stringByAppendingString: @" total"];
|
2007-12-04 06:03:38 +00:00
|
|
|
icon = [NSImage imageNamed: @"TransmissionDocument.icns"];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[self contentView] setOverlay: icon mainLine: name subLine: secondString];
|
|
|
|
[self fadeIn];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFile: (NSString *) file
|
|
|
|
{
|
|
|
|
[[self contentView] setOverlay: [NSImage imageNamed: @"CreateLarge.png"]
|
|
|
|
mainLine: NSLocalizedString(@"Create a Torrent File", "Drag overlay -> file") subLine: file];
|
|
|
|
[self fadeIn];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setURL: (NSString *) url
|
|
|
|
{
|
|
|
|
[[self contentView] setOverlay: [NSImage imageNamed: @"Globe.png"]
|
|
|
|
mainLine: NSLocalizedString(@"Web Address", "Drag overlay -> url") subLine: url];
|
|
|
|
[self fadeIn];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) fadeIn
|
|
|
|
{
|
|
|
|
//stop other animation and set to same progress
|
|
|
|
if ([fFadeOutAnimation isAnimating])
|
|
|
|
{
|
|
|
|
[fFadeOutAnimation stopAnimation];
|
|
|
|
[fFadeInAnimation setCurrentProgress: 1.0 - [fFadeOutAnimation currentProgress]];
|
|
|
|
}
|
|
|
|
[fFadeInAnimation startAnimation];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) fadeOut
|
|
|
|
{
|
|
|
|
//stop other animation and set to same progress
|
|
|
|
if ([fFadeInAnimation isAnimating])
|
|
|
|
{
|
|
|
|
[fFadeInAnimation stopAnimation];
|
|
|
|
[fFadeOutAnimation setCurrentProgress: 1.0 - [fFadeInAnimation currentProgress]];
|
|
|
|
}
|
2009-11-27 20:47:03 +00:00
|
|
|
if ([self alphaValue] > 0.0)
|
2008-03-24 02:57:59 +00:00
|
|
|
[fFadeOutAnimation startAnimation];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2010-01-28 03:16:55 +00:00
|
|
|
|
|
|
|
@implementation DragOverlayWindow (Private)
|
|
|
|
|
|
|
|
- (void) resizeWindow
|
|
|
|
{
|
|
|
|
[self setFrame: [[self parentWindow] frame] display: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|