Request info to get user icons when a Jabber contact signs on. Fixes #4205
[adiumx.git] / Source / ESFileTransferPreferences.m
blob91459390e6ae8543cf5c9005a9923b1b6d632aab
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 - (AIPreferenceCategory)category{
33     return AIPref_FileTransfer;
35 - (NSString *)label{
36     return @"a";
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;
48                 
49                 if ([checkBox_autoAcceptFiles state] == NSOffState) {
50                         autoAcceptType = AutoAccept_None;
51                 } else {
52                         if ([checkBox_autoAcceptOnlyFromCLList state] == NSOnState) {
53                                 autoAcceptType = AutoAccept_FromContactList;
54                         } else {
55                                 autoAcceptType = AutoAccept_All;
56                         }
57                 }
58                 
59                 [[adium preferenceController] setPreference:[NSNumber numberWithInt:autoAcceptType]
60                                              forKey:KEY_FT_AUTO_ACCEPT
61                                               group:PREF_GROUP_FILE_TRANSFER];
62         }
65 //Configure the preference view
66 - (void)viewDidLoad
68         AIFileTransferAutoAcceptType    autoAcceptType = [[[adium preferenceController] preferenceForKey:KEY_FT_AUTO_ACCEPT
69                                                                                                                                                                    group:PREF_GROUP_FILE_TRANSFER] intValue];
70         
71         [self buildDownloadLocationMenu];
72         
73         switch (autoAcceptType) {
74                 case AutoAccept_None:
75                         [checkBox_autoAcceptFiles setState:NSOffState];
76                         [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];                        
77                         break;
78                         
79                 case AutoAccept_FromContactList:
80                         [checkBox_autoAcceptFiles setState:NSOnState];
81                         [checkBox_autoAcceptOnlyFromCLList setState:NSOnState];
82                         break;
84                 case AutoAccept_All:
85                         [checkBox_autoAcceptFiles setState:NSOnState];
86                         [checkBox_autoAcceptOnlyFromCLList setState:NSOffState];
87                         break;
88         }
89         
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")];
94         
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
110         NSMenu          *menu;
111         NSMenuItem      *menuItem;
112         NSString        *userPreferredDownloadFolder;
114         menu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
115         [menu setAutoenablesItems:NO];
116         
117         //Create the menu item for the current download folder
118         userPreferredDownloadFolder = [[adium preferenceController] userPreferredDownloadFolder];
119         menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[userPreferredDownloadFolder lastPathComponent]
120                                                                                                                                          target:nil
121                                                                                                                                          action:nil
122                                                                                                                           keyEquivalent:@""] autorelease];
123         [menuItem setRepresentedObject:userPreferredDownloadFolder];
124         [menuItem setImage:[[[NSWorkspace sharedWorkspace] iconForFile:userPreferredDownloadFolder] imageByScalingForMenuItem]];
125         [menu addItem:menuItem];
126         
127         [menu addItem:[NSMenuItem separatorItem]];
128         
129         //Create the menu item for changing the current download folder
130         menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[AILocalizedString(@"Other",nil) stringByAppendingEllipsis]
131                                                                                                                                          target:self
132                                                                                                                                          action:@selector(selectOtherDownloadFolder:)
133                                                                                                                           keyEquivalent:@""] autorelease];
134         [menuItem setRepresentedObject:userPreferredDownloadFolder];
135         [menu addItem:menuItem];
136         
137         return menu;
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
149                                                                  file:nil
150                                                                 types:nil
151                                            modalForWindow:[[self view] window]
152                                                 modalDelegate:self
153                                            didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
154                                                   contextInfo:nil];
157 - (void)openPanelDidEnd:(NSOpenPanel *)openPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo
159         if (returnCode == NSOKButton) {
160                 [[adium preferenceController] setUserPreferredDownloadFolder:[openPanel filename]];
161         }
163         [self buildDownloadLocationMenu];
166 @end