diff --git a/Classes/Dialogs/Preferences/PreferencesController.h b/Classes/Dialogs/Preferences/PreferencesController.h index ca0fdc7f..11017073 100644 --- a/Classes/Dialogs/Preferences/PreferencesController.h +++ b/Classes/Dialogs/Preferences/PreferencesController.h @@ -26,8 +26,12 @@ @property (nonatomic) IBOutlet NSPopUpButton* transcriptFolderButton; @property (nonatomic) IBOutlet NSPopUpButton* themeButton; @property (nonatomic) IBOutlet NSTableView* soundsTable; +@property (nonatomic, weak) IBOutlet NSTextField *labelDisplay; + + - (void)show; +- (void)receivedNotification:(NSNotification*)notification; - (void)onAddKeyword:(id)sender; - (void)onAddExcludeWord:(id)sender; @@ -40,6 +44,9 @@ - (void)onInputSelectFont:(id)sender; - (void)onOverrideFontChanged:(id)sender; - (void)onChangedTransparency:(id)sender; +- (IBAction)onOpenDownloadsPath:(id)sender; + +- (void)displaySetPath; @end diff --git a/Classes/Dialogs/Preferences/PreferencesController.m b/Classes/Dialogs/Preferences/PreferencesController.m index ee274563..2faee5bc 100644 --- a/Classes/Dialogs/Preferences/PreferencesController.m +++ b/Classes/Dialogs/Preferences/PreferencesController.m @@ -14,6 +14,7 @@ #define PONG_INTERVAL_MIN 20 + @implementation PreferencesController { NSMutableArray* _sounds; @@ -29,7 +30,11 @@ - (id)init if (self) { [[NSBundle mainBundle] loadNibNamed:@"Preferences" owner:self topLevelObjects:nil]; } + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedNotification:) name:@"Downloads Path Set" object:nil]; + return self; + } - (void)dealloc @@ -42,6 +47,7 @@ - (void)dealloc _soundsTable.dataSource = nil; } + #pragma mark - Utilities - (void)show @@ -49,9 +55,11 @@ - (void)show [self loadHotKey]; [self updateTranscriptFolder]; [self updateTheme]; + [Preferences checkOldPath]; _logFont = [NSFont fontWithName:[Preferences themeLogFontName] size:[Preferences themeLogFontSize]]; _inputFont = [NSFont fontWithName:[Preferences themeInputFontName] size:[Preferences themeInputFontSize]]; + if (![self.window isVisible]) { [self.window center]; @@ -142,6 +150,7 @@ - (void)setPongInterval:(int)value [Preferences setPongInterval:value]; } + - (BOOL)validateValue:(id *)value forKey:(NSString *)key error:(NSError **)error { if ([key isEqualToString:@"maxLogLines"]) { @@ -492,6 +501,37 @@ - (void)onLayoutChanged:(id)sender [nc postNotificationName:ThemeDidChangeNotification object:nil userInfo:nil]; } +- (IBAction)onOpenDownloadsPath:(id)sender { + + NSOpenPanel* panel = [NSOpenPanel openPanel]; + [panel setCanChooseFiles:NO]; + [panel setCanChooseDirectories:YES]; + [panel setAllowsMultipleSelection:NO]; + + + [panel beginWithCompletionHandler:^(NSInteger result){ + if (result == NSFileHandlingPanelOKButton) { + NSURL* theDir = [[panel URLs] objectAtIndex:0]; + NSString* thePath = theDir.path; + [Preferences setDownloadsPath:thePath]; + + } + }];} + +- (void)displaySetPath { + + _labelDisplay.stringValue = [Preferences getDownloadsPath]; +} + +#pragma mark - Notification + +- (void)receivedNotification:(NSNotification*)notification { + + if ([[notification name] isEqualToString:@"Downloads Path Set"]) { + [self displaySetPath]; + } +} + #pragma mark - NSWindow Delegate - (void)windowWillClose:(NSNotification *)note diff --git a/Classes/IRC/IRCClient.m b/Classes/IRC/IRCClient.m index ded1322a..401fce4f 100644 --- a/Classes/IRC/IRCClient.m +++ b/Classes/IRC/IRCClient.m @@ -2593,14 +2593,15 @@ - (void)receiveDCCSend:(IRCMessage*)m fileName:(NSString*)fileName address:(NSSt if ([Preferences dccAction] != DCC_IGNORE) { if (port > 0 && size > 0) { - NSString* path = [@"~/Downloads" stringByExpandingTildeInPath]; + NSString* path = [Preferences getDownloadsPath]; NSFileManager* fm = [NSFileManager defaultManager]; BOOL isDir = NO; if ([fm fileExistsAtPath:path isDirectory:&isDir]) { - path = @"~/Downloads"; + ; } else { - path = @"~/Desktop"; + [Preferences setDownloadsPath:[@"~Desktop" stringByExpandingTildeInPath]]; + path = [Preferences getDownloadsPath]; } [_world.dcc addReceiverWithUID:self.uid nick:nick host:host port:port path:path fileName:fileName size:size]; diff --git a/Classes/Library/YAML/SyckInput.m b/Classes/Library/YAML/SyckInput.m index dc2258fd..a09df553 100644 --- a/Classes/Library/YAML/SyckInput.m +++ b/Classes/Library/YAML/SyckInput.m @@ -1,4 +1,4 @@ -#import +#import "syck.h" #import "YAML.h" #import "GTMBase64.h" diff --git a/Classes/Preferences/Preferences.h b/Classes/Preferences/Preferences.h index 1d5c5294..7fd56c6a 100644 --- a/Classes/Preferences/Preferences.h +++ b/Classes/Preferences/Preferences.h @@ -96,6 +96,10 @@ typedef enum { + (int)pongInterval; + (void)setPongInterval:(int)value; ++ (void)setDownloadsPath:(NSString*)value; ++ (NSString*)getDownloadsPath; ++ (void)checkOldPath; + + (int)maxLogLines; + (void)setMaxLogLines:(int)value; diff --git a/Classes/Preferences/Preferences.m b/Classes/Preferences/Preferences.m index 4a58713c..381a865b 100644 --- a/Classes/Preferences/Preferences.m +++ b/Classes/Preferences/Preferences.m @@ -9,7 +9,6 @@ static NSMutableArray* keywords; static NSMutableArray* excludeWords; - @implementation Preferences + (DCCActionType)dccAction @@ -339,6 +338,37 @@ + (void)setPongInterval:(int)value [ud setInteger:value forKey:@"Preferences.Advanced.pongInterval"]; } +#pragma mark - Downloads Path + ++ (void)setDownloadsPath:(NSString *)value { + + NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; + [ud setValue:value forKey:@"Preferences.downloadsPath"]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"Downloads Path Set" object:self]; +} + ++ (NSString*)getDownloadsPath { + + NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; + return [ud stringForKey:@"Preferences.downloadsPath"]; +} + ++ (void)checkOldPath { + + NSString* oldPath = [Preferences getDownloadsPath]; + NSFileManager *fileManager = [[NSFileManager alloc] init]; + + if (![fileManager fileExistsAtPath:oldPath]) { + NSString* defaultPath = [@"~/Downloads" stringByExpandingTildeInPath]; + if (![fileManager fileExistsAtPath:defaultPath]) { + [Preferences setDownloadsPath:[@"~/Desktop" stringByExpandingTildeInPath]]; //default to Desktop + } + else if ([fileManager fileExistsAtPath:defaultPath]) { + [Preferences setDownloadsPath:defaultPath]; //default to Downloads + } + } +} + #pragma mark - Max Log Lines + (int)maxLogLines @@ -832,6 +862,7 @@ + (void)initPreferences [d setObject:@"~/Documents/LimeChat Transcripts" forKey:@"Preferences.General.transcript_folder"]; [d setInt:0 forKey:@"Preferences.General.hotkey_key_code"]; [d setInt:0 forKey:@"Preferences.General.hotkey_modifier_flags"]; + [d setObject:[@"~Downloads" stringByExpandingTildeInPath] forKey:@"Preferences.downloadsPath"]; NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; [ud registerDefaults:d]; diff --git a/English.lproj/Preferences.xib b/English.lproj/Preferences.xib index 5fb83db6..411a61f0 100644 --- a/English.lproj/Preferences.xib +++ b/English.lproj/Preferences.xib @@ -1,8 +1,8 @@ - + - + @@ -13,6 +13,7 @@ + @@ -25,13 +26,13 @@ - + - + @@ -41,7 +42,7 @@ - + @@ -50,7 +51,7 @@ - + @@ -66,7 +67,7 @@ - - - + @@ -105,10 +106,10 @@ - + - + @@ -119,7 +120,7 @@ - + @@ -139,16 +140,16 @@ - - - - + - + @@ -185,7 +186,7 @@ - + @@ -212,16 +213,16 @@ - - - - - - - - + @@ -333,7 +334,7 @@ - + @@ -351,7 +352,7 @@ - + @@ -369,7 +370,7 @@ - + @@ -378,14 +379,14 @@ - + - + @@ -394,7 +395,7 @@ - - + @@ -422,7 +423,7 @@ - + @@ -439,7 +440,7 @@ - + @@ -460,7 +461,7 @@ - - + @@ -480,12 +481,12 @@ - + - + NSAllRomanInputSourcesLocaleIdentifier @@ -499,7 +500,7 @@ - - - - + @@ -585,7 +586,7 @@ - + @@ -606,7 +607,7 @@ - - - + - + @@ -656,7 +657,7 @@ - - + @@ -684,7 +685,7 @@ - - + @@ -704,7 +705,7 @@ - + @@ -715,7 +716,7 @@ - + @@ -736,7 +737,7 @@ - - - - - @@ -1123,6 +1160,7 @@ +