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 - (AIPreferenceCategory)category{
33 return AIPref_FileTransfer;
38 - (NSString *)nibName{
39 return @"FileTransferPrefs";
42 //Called in response to all preference controls, applies new settings
43 - (IBAction)changePreference:(id)sender
45 if ((sender == checkBox_autoAcceptFiles) ||
46 (sender == checkBox_autoAcceptOnlyFromCLList)) {
47 AIFileTransferAutoAcceptType autoAcceptType;
49 if ([checkBox_autoAcceptFiles state] == NSOffState) {
50 autoAcceptType = AutoAccept_None;
52 if ([checkBox_autoAcceptOnlyFromCLList state] == NSOnState) {
53 autoAcceptType = AutoAccept_FromContactList;
55 autoAcceptType = AutoAccept_All;
59 [[adium preferenceController] setPreference:[NSNumber numberWithInt:autoAcceptType]
60 forKey:KEY_FT_AUTO_ACCEPT
61 group:PREF_GROUP_FILE_TRANSFER];
65 //Configure the preference view
68 AIFileTransferAutoAcceptType autoAcceptType = [[[adium preferenceController] preferenceForKey:KEY_FT_AUTO_ACCEPT
69 group:PREF_GROUP_FILE_TRANSFER] intValue];
71 [self buildDownloadLocationMenu];
73 switch (autoAcceptType) {
75 [checkBox_autoAcceptFiles setState:NSOffState];
76 [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];
79 case AutoAccept_FromContactList:
80 [checkBox_autoAcceptFiles setState:NSOnState];
81 [checkBox_autoAcceptOnlyFromCLList setState:NSOnState];
85 [checkBox_autoAcceptFiles setState:NSOnState];
86 [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];
90 [label_whenReceivingFiles setLocalizedString:AILocalizedString(@"Receiving files:","FT Preferences")];
91 [label_defaultReceivingFolder setLocalizedString:AILocalizedString(@"Save files to:","FT Preferences")];
92 [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.")];
93 [label_transferProgress setLocalizedString:AILocalizedString(@"Progress:","FT Preferences")];
95 [checkBox_autoAcceptFiles setLocalizedString:AILocalizedString(@"Automatically accept files...","FT Preferences")];
96 [checkBox_autoAcceptOnlyFromCLList setLocalizedString:AILocalizedString(@"only from contacts on my Contact List","FT Preferences")];
97 [checkBox_autoOpenFiles setLocalizedString:AILocalizedString(@"Open \"Safe\" files after receiving","FT Preferences")];
98 [checkBox_showProgress setLocalizedString:AILocalizedString(@"Show the File Transfers window automatically","FT Preferences")];
99 [checkBox_autoClearCompleted setLocalizedString:AILocalizedString(@"Clear completed transfers automatically","FT Preferences")];
102 - (void)buildDownloadLocationMenu
104 [popUp_downloadLocation setMenu:[self downloadLocationMenu]];
105 [popUp_downloadLocation selectItem:[popUp_downloadLocation itemAtIndex:0]];
108 - (NSMenu *)downloadLocationMenu
111 NSMenuItem *menuItem;
112 NSString *userPreferredDownloadFolder;
114 menu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
115 [menu setAutoenablesItems:NO];
117 //Create the menu item for the current download folder
118 userPreferredDownloadFolder = [[adium preferenceController] userPreferredDownloadFolder];
119 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[userPreferredDownloadFolder lastPathComponent]
122 keyEquivalent:@""] autorelease];
123 [menuItem setRepresentedObject:userPreferredDownloadFolder];
124 [menuItem setImage:[[[NSWorkspace sharedWorkspace] iconForFile:userPreferredDownloadFolder] imageByScalingForMenuItem]];
125 [menu addItem:menuItem];
127 [menu addItem:[NSMenuItem separatorItem]];
129 //Create the menu item for changing the current download folder
130 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[AILocalizedString(@"Other",nil) stringByAppendingEllipsis]
132 action:@selector(selectOtherDownloadFolder:)
133 keyEquivalent:@""] autorelease];
134 [menuItem setRepresentedObject:userPreferredDownloadFolder];
135 [menu addItem:menuItem];
140 - (void)selectOtherDownloadFolder:(id)sender
142 NSOpenPanel *openPanel = [NSOpenPanel openPanel];
143 NSString *userPreferredDownloadFolder = [sender representedObject];
145 [openPanel setCanChooseFiles:NO];
146 [openPanel setCanChooseDirectories:YES];
148 [openPanel beginSheetForDirectory:userPreferredDownloadFolder
151 modalForWindow:[[self view] window]
153 didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
157 - (void)openPanelDidEnd:(NSOpenPanel *)openPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo
159 if (returnCode == NSOKButton) {
160 [[adium preferenceController] setUserPreferredDownloadFolder:[openPanel filename]];
163 [self buildDownloadLocationMenu];