AIHyperlinks universal building
[adiumx.git] / Source / ESFileTransferPreferences.m
blobf380fabecee7e633b0a836b93849f7d497831638
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 <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;
27 @end
29 @implementation ESFileTransferPreferences
30 //Preference pane properties
31 - (PREFERENCE_CATEGORY)category{
32     return(AIPref_FileTransfer);
34 - (NSString *)label{
35     return(@"a");
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;
57                 
58                 if([checkBox_autoAcceptFiles state] == NSOffState){
59                         autoAcceptType = AutoAccept_None;
60                 }else{
61                         if([checkBox_autoAcceptOnlyFromCLList state] == NSOnState){
62                                 autoAcceptType = AutoAccept_FromContactList;
63                         }else{
64                                 autoAcceptType = AutoAccept_All;
65                         }
66                 }
67                 
68                 [[adium preferenceController] setPreference:[NSNumber numberWithInt:autoAcceptType]
69                                              forKey:KEY_FT_AUTO_ACCEPT
70                                               group:PREF_GROUP_FILE_TRANSFER];
71                 [self configureControlDimming];
72                 
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];
77         }
80 //Dim controls as needed
81 - (void)configureControlDimming
83         [checkBox_autoAcceptOnlyFromCLList setEnabled:([checkBox_autoAcceptFiles state] == NSOnState)];
86 //Configure the preference view
87 - (void)viewDidLoad
89     NSDictionary                *prefDict = [[adium preferenceController] preferencesForGroup:PREF_GROUP_FILE_TRANSFER];
90         FTAutoAcceptType        autoAcceptType = [[prefDict objectForKey:KEY_FT_AUTO_ACCEPT] intValue];
91         
92         [self buildDownloadLocationMenu];
93         
94         switch(autoAcceptType){
95                 case AutoAccept_None:
96                         [checkBox_autoAcceptFiles setState:NSOffState];
97                         [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];                        
98                         break;
99                         
100                 case AutoAccept_FromContactList:
101                         [checkBox_autoAcceptFiles setState:NSOnState];
102                         [checkBox_autoAcceptOnlyFromCLList setState:NSOnState];
103                         break;
105                 case AutoAccept_All:
106                         [checkBox_autoAcceptFiles setState:NSOnState];
107                         [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];
108                         break;
109         }
110         
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];
116         
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")];
121         
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
137         NSMenu          *menu;
138         NSMenuItem      *menuItem;
139         NSString        *userPreferredDownloadFolder;
141         menu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
142         [menu setAutoenablesItems:NO];
143         
144         //Create the menu item for the current download folder
145         userPreferredDownloadFolder = [[adium preferenceController] userPreferredDownloadFolder];
146         menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[userPreferredDownloadFolder lastPathComponent]
147                                                                                                                                          target:nil
148                                                                                                                                          action:nil
149                                                                                                                           keyEquivalent:@""] autorelease];
150         [menuItem setRepresentedObject:userPreferredDownloadFolder];
151         [menuItem setImage:[[[NSWorkspace sharedWorkspace] iconForFile:userPreferredDownloadFolder] imageByScalingToSize:NSMakeSize(16,16)]];
152         [menu addItem:menuItem];
153         
154         [menu addItem:[NSMenuItem separatorItem]];
155         
156         //Create the menu item for changing the current download folder
157         menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:AILocalizedString(@"Other...",nil)
158                                                                                                                                          target:self
159                                                                                                                                          action:@selector(selectOtherDownloadFolder:)
160                                                                                                                           keyEquivalent:@""] autorelease];
161         [menuItem setRepresentedObject:userPreferredDownloadFolder];
162         [menu addItem:menuItem];
163         
164         return(menu);
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
176                                                                  file:nil
177                                                                 types:nil
178                                            modalForWindow:[[self view] window]
179                                                 modalDelegate:self
180                                            didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
181                                                   contextInfo:nil];
184 - (void)openPanelDidEnd:(NSOpenPanel *)openPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo
186         if(returnCode == NSOKButton){
187                 [[adium preferenceController] setUserPreferredDownloadFolder:[openPanel filename]];
188         }
190         [self buildDownloadLocationMenu];
193 @end