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 "ESFileTransferPreferences.h"
18 #import "ESFileTransferController.h"
19 #import "AILocalizationButton.h"
20 #import "AILocalizationTextField.h"
21 #import <AIUtilities/AIImageAdditions.h>
22 #import <AIUtilities/AIMenuAdditions.h>
23 #import <AIUtilities/AIStringAdditions.h>
25 @interface ESFileTransferPreferences (PRIVATE)
26 - (NSMenu *)downloadLocationMenu;
27 - (void)buildDownloadLocationMenu;
30 @implementation ESFileTransferPreferences
31 //Preference pane properties
32 - (NSString *)paneIdentifier
34 return @"File Transfer";
36 - (NSString *)paneName{
37 return AILocalizedString(@"File Transfer", nil);
39 - (NSString *)nibName{
40 return @"FileTransferPrefs";
44 return [NSImage imageNamed:@"pref-ft" forClass:[self class]];
47 //Called in response to all preference controls, applies new settings
48 - (IBAction)changePreference:(id)sender
50 if ((sender == checkBox_autoAcceptFiles) ||
51 (sender == checkBox_autoAcceptOnlyFromCLList)) {
52 AIFileTransferAutoAcceptType autoAcceptType;
54 if ([checkBox_autoAcceptFiles state] == NSOffState) {
55 autoAcceptType = AutoAccept_None;
57 if ([checkBox_autoAcceptOnlyFromCLList state] == NSOnState) {
58 autoAcceptType = AutoAccept_FromContactList;
60 autoAcceptType = AutoAccept_All;
64 [[adium preferenceController] setPreference:[NSNumber numberWithInt:autoAcceptType]
65 forKey:KEY_FT_AUTO_ACCEPT
66 group:PREF_GROUP_FILE_TRANSFER];
70 //Configure the preference view
73 AIFileTransferAutoAcceptType autoAcceptType = [[[adium preferenceController] preferenceForKey:KEY_FT_AUTO_ACCEPT
74 group:PREF_GROUP_FILE_TRANSFER] intValue];
76 [self buildDownloadLocationMenu];
78 switch (autoAcceptType) {
80 [checkBox_autoAcceptFiles setState:NSOffState];
81 [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];
84 case AutoAccept_FromContactList:
85 [checkBox_autoAcceptFiles setState:NSOnState];
86 [checkBox_autoAcceptOnlyFromCLList setState:NSOnState];
90 [checkBox_autoAcceptFiles setState:NSOnState];
91 [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];
98 [label_whenReceivingFiles setLocalizedString:AILocalizedString(@"Receiving files:","File Transfer preferences label")];
99 [label_defaultReceivingFolder setLocalizedString:AILocalizedString(@"Save files to:","File Transfer preferences label")];
100 [label_safeFilesDescription setLocalizedString:AILocalizedString(@"\"Safe\" files include movies, pictures,\nsounds, text documents, and archives.","Description of safe files (files which Adium can open automatically without danger to the user). This description should be on two lines; the lines are separated by \n.")];
101 [label_transferProgress setLocalizedString:AILocalizedString(@"Progress:","File Transfer preferences label")];
103 [checkBox_autoAcceptFiles setLocalizedString:AILocalizedString(@"Automatically accept files...","File Transfer preferences")];
104 [checkBox_autoAcceptOnlyFromCLList setLocalizedString:AILocalizedString(@"only from contacts on my Contact List","File Transfer preferences")];
105 [checkBox_autoOpenFiles setLocalizedString:AILocalizedString(@"Open \"Safe\" files after receiving","File Transfer preferences")];
106 [checkBox_showProgress setLocalizedString:AILocalizedString(@"Show the File Transfers window automatically","File Transfer preferences")];
107 [checkBox_autoClearCompleted setLocalizedString:AILocalizedString(@"Clear completed transfers automatically","File Transfer preferences")];
110 - (void)buildDownloadLocationMenu
112 [popUp_downloadLocation setMenu:[self downloadLocationMenu]];
113 [popUp_downloadLocation selectItem:[popUp_downloadLocation itemAtIndex:0]];
116 - (NSMenu *)downloadLocationMenu
119 NSMenuItem *menuItem;
120 NSString *userPreferredDownloadFolder;
122 menu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
123 [menu setAutoenablesItems:NO];
125 //Create the menu item for the current download folder
126 userPreferredDownloadFolder = [[adium preferenceController] userPreferredDownloadFolder];
127 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[userPreferredDownloadFolder lastPathComponent]
130 keyEquivalent:@""] autorelease];
131 [menuItem setRepresentedObject:userPreferredDownloadFolder];
132 [menuItem setImage:[[[NSWorkspace sharedWorkspace] iconForFile:userPreferredDownloadFolder] imageByScalingForMenuItem]];
133 [menu addItem:menuItem];
135 [menu addItem:[NSMenuItem separatorItem]];
137 //Create the menu item for changing the current download folder
138 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[AILocalizedString(@"Other",nil) stringByAppendingEllipsis]
140 action:@selector(selectOtherDownloadFolder:)
141 keyEquivalent:@""] autorelease];
142 [menuItem setRepresentedObject:userPreferredDownloadFolder];
143 [menu addItem:menuItem];
148 - (void)selectOtherDownloadFolder:(id)sender
150 NSOpenPanel *openPanel = [NSOpenPanel openPanel];
151 NSString *userPreferredDownloadFolder = [sender representedObject];
153 [openPanel setCanChooseFiles:NO];
154 [openPanel setCanChooseDirectories:YES];
156 [openPanel beginSheetForDirectory:userPreferredDownloadFolder
159 modalForWindow:[[self view] window]
161 didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
165 - (void)openPanelDidEnd:(NSOpenPanel *)openPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo
167 if (returnCode == NSOKButton) {
168 [[adium preferenceController] setUserPreferredDownloadFolder:[openPanel filename]];
171 [self buildDownloadLocationMenu];