2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "ESFileTransferRequestPromptController.h"
18 #import "ESFileTransferController.h"
19 #import "ESFileTransfer.h"
20 #import "ESTextAndButtonsWindowController.h"
21 #import <Adium/AIPreferenceControllerProtocol.h>
22 #import <Adium/AIListContact.h>
23 #import <Adium/AIContentControllerProtocol.h>
24 #import <AIUtilities/AIApplicationAdditions.h>
25 #import <AIUtilities/AIAttributedStringAdditions.h>
26 #import <AIUtilities/AIStringAdditions.h>
28 @interface ESFileTransferRequestPromptController (PRIVATE)
29 - (id)initForFileTransfer:(ESFileTransfer *)inFileTransfer
30 notifyingTarget:(id)inTarget
31 selector:(SEL)inSelector;
32 - (ESTextAndButtonsWindowController *)windowController;
35 @implementation ESFileTransferRequestPromptController
38 * @brief Display a prompt for a file transfer to save, save as, or cancel
40 * @param inFileTransfer The file transfer
41 * @param inSelector A selector, which must accept two arguments. The first will be inFileTransfer. The second will be the filename to save to, or nil to cancel.
43 + (void)displayPromptForFileTransfer:(ESFileTransfer *)inFileTransfer
44 notifyingTarget:(id)inTarget
45 selector:(SEL)inSelector
47 [[[self alloc] initForFileTransfer:inFileTransfer
48 notifyingTarget:inTarget
49 selector:inSelector] autorelease];
52 - (id)initForFileTransfer:(ESFileTransfer *)inFileTransfer
53 notifyingTarget:(id)inTarget
54 selector:(SEL)inSelector
56 if ((self = [super init])) {
57 fileTransfer = [inFileTransfer retain];
58 target = [inTarget retain];
59 selector = inSelector;
61 [fileTransfer setFileTransferRequestPromptController:self];
62 AILog(@"%@: Requeseting file transfer %@", self, fileTransfer);
63 [[adium contentController] receiveContentObject:fileTransfer];
71 [fileTransfer release];
78 * @brief The user did something with the file transfer request
80 - (void)handleFileTransferAction:(AIFileTransferAction)action
84 NSString *localFilename = nil;
87 [fileTransfer retain];
90 case AISaveFile: /* Save */
92 localFilename = [[[adium preferenceController] userPreferredDownloadFolder] stringByAppendingPathComponent:[fileTransfer remoteFilename]];
94 /* If the file doesn't exist, we're done. If it does, fall through to AISaveFileAs
95 * triggering a Save As... panel.
97 if (![[NSFileManager defaultManager] fileExistsAtPath:localFilename]) {
102 case AISaveFileAs: /* Save As... */
104 //Prompt for a location to save
105 NSSavePanel *savePanel = [NSSavePanel savePanel];
106 int returnCode = [savePanel runModalForDirectory:[[adium preferenceController] userPreferredDownloadFolder]
107 file:[fileTransfer remoteFilename]];
108 //Only need to take action if the user pressed OK; if she pressed cancel, just return to our window.
109 if (returnCode == NSOKButton) {
110 localFilename = [savePanel filename];
116 case AICancel: /* Closed = Cancel */
118 /* File name remains nil and the transfer will therefore be cancelled */
124 BOOL remotelyCanceled = [fileTransfer isStopped];
125 [fileTransfer release];
126 if(remotelyCanceled) {
132 [target performSelector:selector
133 withObject:fileTransfer
134 withObject:localFilename];
136 [fileTransfer setFileTransferRequestPromptController:nil];
141 - (ESFileTransfer *)fileTransfer