Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Source / ESFileTransferPreferences.m
blob3be3db9c7b37b4804595bb24ad04fbdf45622b8d
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
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;
28 @end
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";
42 - (NSImage *)paneIcon
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;
53                 
54                 if ([checkBox_autoAcceptFiles state] == NSOffState) {
55                         autoAcceptType = AutoAccept_None;
56                 } else {
57                         if ([checkBox_autoAcceptOnlyFromCLList state] == NSOnState) {
58                                 autoAcceptType = AutoAccept_FromContactList;
59                         } else {
60                                 autoAcceptType = AutoAccept_All;
61                         }
62                 }
63                 
64                 [[adium preferenceController] setPreference:[NSNumber numberWithInt:autoAcceptType]
65                                              forKey:KEY_FT_AUTO_ACCEPT
66                                               group:PREF_GROUP_FILE_TRANSFER];
67         }
70 //Configure the preference view
71 - (void)viewDidLoad
73         AIFileTransferAutoAcceptType    autoAcceptType = [[[adium preferenceController] preferenceForKey:KEY_FT_AUTO_ACCEPT
74                                                                                                                                                                    group:PREF_GROUP_FILE_TRANSFER] intValue];
75         
76         [self buildDownloadLocationMenu];
77         
78         switch (autoAcceptType) {
79                 case AutoAccept_None:
80                         [checkBox_autoAcceptFiles setState:NSOffState];
81                         [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];                        
82                         break;
83                         
84                 case AutoAccept_FromContactList:
85                         [checkBox_autoAcceptFiles setState:NSOnState];
86                         [checkBox_autoAcceptOnlyFromCLList setState:NSOnState];
87                         break;
89                 case AutoAccept_All:
90                         [checkBox_autoAcceptFiles setState:NSOnState];
91                         [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];
92                         break;
93         }       
96 - (void)localizePane
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")];
102         
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
118         NSMenu          *menu;
119         NSMenuItem      *menuItem;
120         NSString        *userPreferredDownloadFolder;
122         menu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
123         [menu setAutoenablesItems:NO];
124         
125         //Create the menu item for the current download folder
126         userPreferredDownloadFolder = [[adium preferenceController] userPreferredDownloadFolder];
127         menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[userPreferredDownloadFolder lastPathComponent]
128                                                                                                                                          target:nil
129                                                                                                                                          action:nil
130                                                                                                                           keyEquivalent:@""] autorelease];
131         [menuItem setRepresentedObject:userPreferredDownloadFolder];
132         [menuItem setImage:[[[NSWorkspace sharedWorkspace] iconForFile:userPreferredDownloadFolder] imageByScalingForMenuItem]];
133         [menu addItem:menuItem];
134         
135         [menu addItem:[NSMenuItem separatorItem]];
136         
137         //Create the menu item for changing the current download folder
138         menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[AILocalizedString(@"Other",nil) stringByAppendingEllipsis]
139                                                                                                                                          target:self
140                                                                                                                                          action:@selector(selectOtherDownloadFolder:)
141                                                                                                                           keyEquivalent:@""] autorelease];
142         [menuItem setRepresentedObject:userPreferredDownloadFolder];
143         [menu addItem:menuItem];
144         
145         return menu;
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
157                                                                  file:nil
158                                                                 types:nil
159                                            modalForWindow:[[self view] window]
160                                                 modalDelegate:self
161                                            didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
162                                                   contextInfo:nil];
165 - (void)openPanelDidEnd:(NSOpenPanel *)openPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo
167         if (returnCode == NSOKButton) {
168                 [[adium preferenceController] setUserPreferredDownloadFolder:[openPanel filename]];
169         }
171         [self buildDownloadLocationMenu];
174 @end