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 <Adium/AILocalizationButton.h>
20 #import <Adium/AILocalizationTextField.h>
21 #import <AIUtilities/ESImageAdditions.h>
22 #import <AIUtilities/AIMenuAdditions.h>
24 @interface ESFileTransferPreferences (PRIVATE)
25 - (NSMenu *)downloadLocationMenu;
26 - (void)buildDownloadLocationMenu;
29 @implementation ESFileTransferPreferences
30 //Preference pane properties
31 - (PREFERENCE_CATEGORY)category{
32 return(AIPref_FileTransfer);
37 - (NSString *)nibName{
38 return(@"FileTransferPrefs");
41 //Called in response to all preference controls, applies new settings
42 - (IBAction)changePreference:(id)sender
44 if(sender == checkBox_autoOpenFiles){
45 [[adium preferenceController] setPreference:[NSNumber numberWithBool:[sender state]]
46 forKey:KEY_FT_AUTO_OPEN_SAFE
47 group:PREF_GROUP_FILE_TRANSFER];
49 }else if(sender == checkBox_showProgress){
50 [[adium preferenceController] setPreference:[NSNumber numberWithBool:[sender state]]
51 forKey:KEY_FT_SHOW_PROGRESS_WINDOW
52 group:PREF_GROUP_FILE_TRANSFER];
54 }else if((sender == checkBox_autoAcceptFiles) ||
55 (sender == checkBox_autoAcceptOnlyFromCLList)){
56 FTAutoAcceptType autoAcceptType;
58 if([checkBox_autoAcceptFiles state] == NSOffState){
59 autoAcceptType = AutoAccept_None;
61 if([checkBox_autoAcceptOnlyFromCLList state] == NSOnState){
62 autoAcceptType = AutoAccept_FromContactList;
64 autoAcceptType = AutoAccept_All;
68 [[adium preferenceController] setPreference:[NSNumber numberWithInt:autoAcceptType]
69 forKey:KEY_FT_AUTO_ACCEPT
70 group:PREF_GROUP_FILE_TRANSFER];
71 [self configureControlDimming];
73 }else if(sender == checkBox_autoClearCompleted){
74 [[adium preferenceController] setPreference:[NSNumber numberWithBool:[sender state]]
75 forKey:KEY_FT_AUTO_CLEAR_COMPLETED
76 group:PREF_GROUP_FILE_TRANSFER];
80 //Dim controls as needed
81 - (void)configureControlDimming
83 [checkBox_autoAcceptOnlyFromCLList setEnabled:([checkBox_autoAcceptFiles state] == NSOnState)];
86 //Configure the preference view
89 NSDictionary *prefDict = [[adium preferenceController] preferencesForGroup:PREF_GROUP_FILE_TRANSFER];
90 FTAutoAcceptType autoAcceptType = [[prefDict objectForKey:KEY_FT_AUTO_ACCEPT] intValue];
92 [self buildDownloadLocationMenu];
94 switch(autoAcceptType){
96 [checkBox_autoAcceptFiles setState:NSOffState];
97 [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];
100 case AutoAccept_FromContactList:
101 [checkBox_autoAcceptFiles setState:NSOnState];
102 [checkBox_autoAcceptOnlyFromCLList setState:NSOnState];
106 [checkBox_autoAcceptFiles setState:NSOnState];
107 [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];
111 [checkBox_autoOpenFiles setState:[[prefDict objectForKey:KEY_FT_AUTO_OPEN_SAFE] boolValue]];
112 [checkBox_showProgress setState:[[prefDict objectForKey:KEY_FT_SHOW_PROGRESS_WINDOW] boolValue]];
113 [checkBox_autoClearCompleted setState:[[prefDict objectForKey:KEY_FT_AUTO_CLEAR_COMPLETED] boolValue]];
115 [self configureControlDimming];
117 [label_whenReceivingFiles setLocalizedString:AILocalizedString(@"Receiving files:","FT Preferences")];
118 [label_defaultReceivingFolder setLocalizedString:AILocalizedString(@"Save files to:","FT Preferences")];
119 [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.")];
120 [label_transferProgress setLocalizedString:AILocalizedString(@"Progress:","FT Preferences")];
122 [checkBox_autoAcceptFiles setLocalizedString:AILocalizedString(@"Automatically accept files...","FT Preferences")];
123 [checkBox_autoAcceptOnlyFromCLList setLocalizedString:AILocalizedString(@"only from contacts on my Contact List","FT Preferences")];
124 [checkBox_autoOpenFiles setLocalizedString:AILocalizedString(@"Open \"Safe\" files after receiving","FT Preferences")];
125 [checkBox_showProgress setLocalizedString:AILocalizedString(@"Show the File Transfers window automatically","FT Preferences")];
126 [checkBox_autoClearCompleted setLocalizedString:AILocalizedString(@"Clear completed transfers automatically","FT Preferences")];
129 - (void)buildDownloadLocationMenu
131 [popUp_downloadLocation setMenu:[self downloadLocationMenu]];
132 [popUp_downloadLocation selectItem:[popUp_downloadLocation itemAtIndex:0]];
135 - (NSMenu *)downloadLocationMenu
138 NSMenuItem *menuItem;
139 NSString *userPreferredDownloadFolder;
141 menu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
142 [menu setAutoenablesItems:NO];
144 //Create the menu item for the current download folder
145 userPreferredDownloadFolder = [[adium preferenceController] userPreferredDownloadFolder];
146 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[userPreferredDownloadFolder lastPathComponent]
149 keyEquivalent:@""] autorelease];
150 [menuItem setRepresentedObject:userPreferredDownloadFolder];
151 [menuItem setImage:[[[NSWorkspace sharedWorkspace] iconForFile:userPreferredDownloadFolder] imageByScalingToSize:NSMakeSize(16,16)]];
152 [menu addItem:menuItem];
154 [menu addItem:[NSMenuItem separatorItem]];
156 //Create the menu item for changing the current download folder
157 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:AILocalizedString(@"Other...",nil)
159 action:@selector(selectOtherDownloadFolder:)
160 keyEquivalent:@""] autorelease];
161 [menuItem setRepresentedObject:userPreferredDownloadFolder];
162 [menu addItem:menuItem];
167 - (void)selectOtherDownloadFolder:(id)sender
169 NSOpenPanel *openPanel = [NSOpenPanel openPanel];
170 NSString *userPreferredDownloadFolder = [sender representedObject];
172 [openPanel setCanChooseFiles:NO];
173 [openPanel setCanChooseDirectories:YES];
175 [openPanel beginSheetForDirectory:userPreferredDownloadFolder
178 modalForWindow:[[self view] window]
180 didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
184 - (void)openPanelDidEnd:(NSOpenPanel *)openPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo
186 if(returnCode == NSOKButton){
187 [[adium preferenceController] setUserPreferredDownloadFolder:[openPanel filename]];
190 [self buildDownloadLocationMenu];