source: trunk/macosx/DragOverlayWindow.m @ 4275

Last change on this file since 4275 was 4275, checked in by livings124, 15 years ago

get rid of all the deprecated functions for the ctor versions

  • Property Id set to /Users/mitchell/Desktop/Transmission/macosx/ActionMenuRatioToDisplayRatioTransformer.h
  • Property svn:keywords set to Date Rev Author Id
File size: 6.3 KB
Line 
1/******************************************************************************
2 * $Id: DragOverlayWindow.m 4275 2007-12-22 03:31:22Z livings124 $
3 *
4 * Copyright (c) 2007 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "DragOverlayWindow.h"
26#import "DragOverlayView.h"
27#import "NSStringAdditions.h"
28
29@implementation DragOverlayWindow
30
31- (id) initWithLib: (tr_handle *) lib forWindow: (NSWindow *) window
32{
33    if (self = ([super initWithContentRect: NSMakeRect(0, 0, 1.0, 1.0) styleMask: NSBorderlessWindowMask
34                    backing: NSBackingStoreBuffered defer: NO]))
35    {
36        fLib = lib;
37       
38        [self setBackgroundColor: [NSColor colorWithCalibratedWhite: 0.0 alpha: 0.5]];
39        [self setAlphaValue: 0.0];
40        [self setOpaque: NO];
41        [self setHasShadow: NO];
42       
43        DragOverlayView * view = [[DragOverlayView alloc] initWithFrame: [self frame]];
44        [self setContentView: view];
45        [view release];
46       
47        [self setReleasedWhenClosed: NO];
48        [self setIgnoresMouseEvents: YES];
49       
50        fFadeInAnimation = [[NSViewAnimation alloc] initWithViewAnimations: [NSArray arrayWithObject:
51                                [NSDictionary dictionaryWithObjectsAndKeys: self, NSViewAnimationTargetKey,
52                                NSViewAnimationFadeInEffect, NSViewAnimationEffectKey, nil]]];
53        [fFadeInAnimation setDuration: 0.15];
54       
55        fFadeOutAnimation = [[NSViewAnimation alloc] initWithViewAnimations: [NSArray arrayWithObject:
56                                [NSDictionary dictionaryWithObjectsAndKeys: self, NSViewAnimationTargetKey,
57                                NSViewAnimationFadeOutEffect, NSViewAnimationEffectKey, nil]]];
58        [fFadeOutAnimation setDuration: 0.5];
59        [fFadeOutAnimation setAnimationBlockingMode: NSAnimationNonblockingThreaded];
60       
61        [window addChildWindow: self ordered: NSWindowAbove];
62    }
63    return self;
64}
65
66- (void) dealloc
67{
68    [fFadeInAnimation release];
69    [fFadeOutAnimation release];
70   
71    [super dealloc];
72}
73
74- (void) setTorrents: (NSArray *) files
75{
76    uint64_t size = 0;
77    int count = 0;
78   
79    NSString * name;
80    BOOL folder;
81    int fileCount = 0;
82   
83    NSString * file;
84    NSEnumerator * enumerator = [files objectEnumerator];
85    tr_ctor * ctor;
86    tr_info info;
87    while ((file = [enumerator nextObject]))
88    {
89        if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] == NSOrderedSame)
90        {
91            ctor = tr_ctorNew(fLib);
92            tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
93            if (tr_torrentParseFromCtor(fLib, ctor, &info) == TR_OK)
94            {
95                count++;
96                size += info.totalSize;
97                fileCount += info.fileCount;
98               
99                //only useful when one torrent
100                if (count == 1)
101                {
102                    name = [NSString stringWithUTF8String: info.name];
103                    folder = info.isMultifile;
104                }
105            }
106            tr_metainfoFree(&info);
107        }
108    }
109   
110    if (count <= 0)
111        return;
112   
113    //set strings and icon
114    NSString * secondString = [NSString stringForFileSize: size];
115    if (count > 1 || folder)
116    {
117        NSString * fileString;
118        if (fileCount == 1)
119            fileString = NSLocalizedString(@"1 File, ", "Drag overlay -> torrents");
120        else
121            fileString= [NSString stringWithFormat: NSLocalizedString(@"%d Files, ", "Drag overlay -> torrents"), fileCount];
122        secondString = [fileString stringByAppendingString: secondString];
123    }
124   
125    NSImage * icon;
126    if (count == 1)
127        icon = [[NSWorkspace sharedWorkspace] iconForFileType: folder ? NSFileTypeForHFSTypeCode('fldr') : [name pathExtension]];
128    else
129    {
130        name = [NSString stringWithFormat: NSLocalizedString(@"%d Torrent Files", "Drag overlay -> torrents"), count];
131        secondString = [secondString stringByAppendingString: @" Total"];
132        icon = [NSImage imageNamed: @"TransmissionDocument.icns"];
133    }
134   
135    [[self contentView] setOverlay: icon mainLine: name subLine: secondString];
136    [self fadeIn];
137}
138
139- (void) setFile: (NSString *) file
140{
141    [[self contentView] setOverlay: [NSImage imageNamed: @"CreateLarge.png"]
142        mainLine: NSLocalizedString(@"Create a Torrent File", "Drag overlay -> file") subLine: file];
143    [self fadeIn];
144}
145
146- (void) setURL: (NSString *) url
147{
148    [[self contentView] setOverlay: [NSImage imageNamed: @"Globe.png"]
149        mainLine: NSLocalizedString(@"Web Address", "Drag overlay -> url") subLine: url];
150    [self fadeIn];
151}
152
153- (void) fadeIn
154{
155    //stop other animation and set to same progress
156    if ([fFadeOutAnimation isAnimating])
157    {
158        [fFadeOutAnimation stopAnimation];
159        [fFadeInAnimation setCurrentProgress: 1.0 - [fFadeOutAnimation currentProgress]];
160    }
161    [self setFrame: [[self parentWindow] frame] display: YES];
162    [fFadeInAnimation startAnimation];
163}
164
165- (void) fadeOut
166{
167    if ([self alphaValue] <= 0.0)
168        return;
169   
170    //stop other animation and set to same progress
171    if ([fFadeInAnimation isAnimating])
172    {
173        [fFadeInAnimation stopAnimation];
174        [fFadeOutAnimation setCurrentProgress: 1.0 - [fFadeInAnimation currentProgress]];
175    }
176    [fFadeOutAnimation startAnimation];
177}
178
179@end
Note: See TracBrowser for help on using the repository browser.