2007-05-19 01:16:52 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $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 "DragOverlayWindow.h"
|
2007-05-19 14:11:25 +00:00
|
|
|
#import "DragOverlayView.h"
|
|
|
|
#import "StringAdditions.h"
|
2007-05-19 01:16:52 +00:00
|
|
|
|
|
|
|
@implementation DragOverlayWindow
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
- (id) initWithLib: (tr_handle_t *) lib forWindow: (NSWindow *) window
|
2007-05-19 01:16:52 +00:00
|
|
|
{
|
2007-05-19 14:11:25 +00:00
|
|
|
if (self = ([super initWithContentRect: NSMakeRect(0, 0, 1.0, 1.0) styleMask: NSBorderlessWindowMask
|
2007-05-19 01:16:52 +00:00
|
|
|
backing: NSBackingStoreBuffered defer: NO]))
|
|
|
|
{
|
2007-05-19 14:11:25 +00:00
|
|
|
fLib = lib;
|
|
|
|
|
|
|
|
[self setBackgroundColor: [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.5]];
|
2007-05-21 15:36:52 +00:00
|
|
|
[self setAlphaValue: 0.0];
|
2007-05-19 01:16:52 +00:00
|
|
|
[self setOpaque: NO];
|
|
|
|
[self setHasShadow: NO];
|
2007-05-19 14:11:25 +00:00
|
|
|
|
2007-05-19 14:39:06 +00:00
|
|
|
DragOverlayView * view = [[DragOverlayView alloc] initWithFrame: [self frame]];
|
|
|
|
[self setContentView: view];
|
|
|
|
[view release];
|
2007-05-19 01:16:52 +00:00
|
|
|
|
|
|
|
[self setReleasedWhenClosed: NO];
|
|
|
|
[self setIgnoresMouseEvents: YES];
|
2007-05-21 21:07:47 +00:00
|
|
|
|
|
|
|
fFadeInAnimation = [[NSViewAnimation alloc] initWithViewAnimations: [NSArray arrayWithObject:
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys: self, NSViewAnimationTargetKey,
|
|
|
|
NSViewAnimationFadeInEffect, NSViewAnimationEffectKey, nil]]];
|
2007-05-21 22:39:51 +00:00
|
|
|
[fFadeInAnimation setDuration: 0.15];
|
2007-05-21 21:07:47 +00:00
|
|
|
|
|
|
|
fFadeOutAnimation = [[NSViewAnimation alloc] initWithViewAnimations: [NSArray arrayWithObject:
|
|
|
|
[NSDictionary dictionaryWithObjectsAndKeys: self, NSViewAnimationTargetKey,
|
|
|
|
NSViewAnimationFadeOutEffect, NSViewAnimationEffectKey, nil]]];
|
|
|
|
[fFadeOutAnimation setDuration: 0.5];
|
2007-05-21 21:57:51 +00:00
|
|
|
[fFadeOutAnimation setAnimationBlockingMode: NSAnimationNonblockingThreaded];
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
[window addChildWindow: self ordered: NSWindowAbove];
|
2007-05-19 01:16:52 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-05-19 16:07:36 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-05-21 21:07:47 +00:00
|
|
|
[fFadeInAnimation release];
|
|
|
|
[fFadeOutAnimation release];
|
2007-05-19 18:37:32 +00:00
|
|
|
|
2007-05-19 16:07:36 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
- (void) setTorrents: (NSArray *) files
|
2007-05-19 14:11:25 +00:00
|
|
|
{
|
|
|
|
uint64_t size = 0;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
NSString * name;
|
|
|
|
BOOL folder;
|
2007-06-01 00:33:31 +00:00
|
|
|
int fileCount = 0;
|
2007-05-19 14:11:25 +00:00
|
|
|
|
|
|
|
NSString * file;
|
|
|
|
NSEnumerator * enumerator = [files objectEnumerator];
|
2007-06-27 23:57:02 +00:00
|
|
|
tr_info_t info;
|
2007-05-19 14:11:25 +00:00
|
|
|
while ((file = [enumerator nextObject]))
|
2007-06-28 01:36:30 +00:00
|
|
|
{
|
2007-06-27 23:57:02 +00:00
|
|
|
if (tr_torrentParse(fLib, [file UTF8String], NULL, &info) == TR_OK)
|
2007-07-04 17:12:09 +00:00
|
|
|
{NSLog(@"asdgas");
|
2007-05-19 14:11:25 +00:00
|
|
|
count++;
|
2007-06-27 23:57:02 +00:00
|
|
|
size += info.totalSize;
|
|
|
|
fileCount += info.fileCount;
|
2007-05-19 14:11:25 +00:00
|
|
|
|
|
|
|
//only useful when one torrent
|
|
|
|
if (count == 1)
|
|
|
|
{
|
2007-06-27 23:57:02 +00:00
|
|
|
name = [NSString stringWithUTF8String: info.name];
|
|
|
|
folder = info.multifile;
|
2007-05-19 14:11:25 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-28 01:36:30 +00:00
|
|
|
tr_metainfoFree(&info);
|
|
|
|
}
|
2007-05-19 14:11:25 +00:00
|
|
|
|
2007-06-01 00:33:31 +00:00
|
|
|
if (count <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//set strings and icon
|
2007-05-19 14:11:25 +00:00
|
|
|
NSImage * icon = nil;
|
2007-06-01 00:33:31 +00:00
|
|
|
NSString * secondString = [NSString stringForFileSize: size];
|
|
|
|
if (count > 1 || folder)
|
|
|
|
{
|
|
|
|
NSString * fileString;
|
|
|
|
if (fileCount == 1)
|
2007-06-18 03:40:41 +00:00
|
|
|
fileString = NSLocalizedString(@"1 File, ", "Drag overlay -> torrents");
|
2007-06-01 00:33:31 +00:00
|
|
|
else
|
2007-06-18 03:40:41 +00:00
|
|
|
fileString= [NSString stringWithFormat: NSLocalizedString(@"%d Files, ", "Drag overlay -> torrents"), fileCount];
|
2007-06-01 00:33:31 +00:00
|
|
|
secondString = [fileString stringByAppendingString: secondString];
|
|
|
|
}
|
|
|
|
|
2007-05-19 14:11:25 +00:00
|
|
|
if (count == 1)
|
|
|
|
icon = [[NSWorkspace sharedWorkspace] iconForFileType: folder ? NSFileTypeForHFSTypeCode('fldr') : [name pathExtension]];
|
|
|
|
else
|
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
name = [NSString stringWithFormat: NSLocalizedString(@"%d Torrent Files", "Drag overlay -> torrents"), count];
|
2007-06-01 00:33:31 +00:00
|
|
|
secondString = [secondString stringByAppendingString: @" Total"];
|
2007-05-19 14:11:25 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 17:12:09 +00:00
|
|
|
[[self contentView] setOverlay: icon mainLine: name subLine: secondString];
|
2007-07-01 13:27:26 +00:00
|
|
|
[self fadeIn];
|
2007-05-19 14:11:25 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
- (void) setFile: (NSString *) file
|
|
|
|
{
|
2007-06-18 22:43:49 +00:00
|
|
|
[[self contentView] setOverlay: [NSImage imageNamed: @"CreateLarge.png"]
|
2007-06-18 03:40:41 +00:00
|
|
|
mainLine: NSLocalizedString(@"Create a Torrent File", "Drag overlay -> file") subLine: file];
|
2007-07-01 13:27:26 +00:00
|
|
|
[self fadeIn];
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-19 14:22:01 +00:00
|
|
|
- (void) setURL: (NSString *) url
|
|
|
|
{
|
2007-06-30 13:20:46 +00:00
|
|
|
[[self contentView] setOverlay: [NSImage imageNamed: @"Globe.png"]
|
2007-05-19 18:42:12 +00:00
|
|
|
mainLine: NSLocalizedString(@"Web Address", "Drag overlay -> url") subLine: url];
|
2007-07-01 13:27:26 +00:00
|
|
|
[self fadeIn];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) fadeIn
|
|
|
|
{
|
2007-05-21 22:56:42 +00:00
|
|
|
//stop other animation and set to same progress
|
|
|
|
if ([fFadeOutAnimation isAnimating])
|
|
|
|
{
|
|
|
|
[fFadeOutAnimation stopAnimation];
|
|
|
|
[fFadeInAnimation setCurrentProgress: 1.0 - [fFadeOutAnimation currentProgress]];
|
|
|
|
}
|
2007-05-21 22:38:06 +00:00
|
|
|
[self setFrame: [[self parentWindow] frame] display: YES];
|
2007-05-21 21:07:47 +00:00
|
|
|
[fFadeInAnimation startAnimation];
|
2007-05-19 18:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) fadeOut
|
2007-05-19 16:07:36 +00:00
|
|
|
{
|
2007-05-21 21:57:51 +00:00
|
|
|
if ([self alphaValue] > 0.0)
|
|
|
|
{
|
2007-05-21 22:56:42 +00:00
|
|
|
//stop other animation and set to same progress
|
|
|
|
if ([fFadeInAnimation isAnimating])
|
|
|
|
{
|
|
|
|
[fFadeInAnimation stopAnimation];
|
|
|
|
[fFadeOutAnimation setCurrentProgress: 1.0 - [fFadeInAnimation currentProgress]];
|
|
|
|
}
|
2007-05-21 21:57:51 +00:00
|
|
|
[fFadeOutAnimation startAnimation];
|
|
|
|
}
|
2007-05-19 16:07:36 +00:00
|
|
|
}
|
|
|
|
|
2007-05-19 01:16:52 +00:00
|
|
|
@end
|