From f49ddc9d1ee231e5fd443e407883afe12204a3e5 Mon Sep 17 00:00:00 2001 From: aaeric Date: Mon, 16 Dec 2019 13:51:31 +0545 Subject: [PATCH 1/5] added basic download path functionality --- .../Preferences/PreferencesController.h | 1 + .../Preferences/PreferencesController.m | 18 ++ Classes/Preferences/Preferences.h | 4 + Classes/Preferences/Preferences.m | 21 ++ English.lproj/Preferences.xib | 223 ++++++++++-------- 5 files changed, 174 insertions(+), 93 deletions(-) diff --git a/Classes/Dialogs/Preferences/PreferencesController.h b/Classes/Dialogs/Preferences/PreferencesController.h index ca0fdc7f..c632a147 100644 --- a/Classes/Dialogs/Preferences/PreferencesController.h +++ b/Classes/Dialogs/Preferences/PreferencesController.h @@ -40,6 +40,7 @@ - (void)onInputSelectFont:(id)sender; - (void)onOverrideFontChanged:(id)sender; - (void)onChangedTransparency:(id)sender; +- (IBAction)onOpenDownloadsPath:(id)sender; @end diff --git a/Classes/Dialogs/Preferences/PreferencesController.m b/Classes/Dialogs/Preferences/PreferencesController.m index ee274563..6563c613 100644 --- a/Classes/Dialogs/Preferences/PreferencesController.m +++ b/Classes/Dialogs/Preferences/PreferencesController.m @@ -492,6 +492,24 @@ - (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; + + + } + + }];} + #pragma mark - NSWindow Delegate - (void)windowWillClose:(NSNotification *)note diff --git a/Classes/Preferences/Preferences.h b/Classes/Preferences/Preferences.h index 1d5c5294..b0b4223d 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; ++ (void)setDownloadsPath; ++ (NSString*)getDownloadsPath; + + (int)maxLogLines; + (void)setMaxLogLines:(int)value; diff --git a/Classes/Preferences/Preferences.m b/Classes/Preferences/Preferences.m index 4a58713c..5b69560d 100644 --- a/Classes/Preferences/Preferences.m +++ b/Classes/Preferences/Preferences.m @@ -339,6 +339,26 @@ + (void)setPongInterval:(int)value [ud setInteger:value forKey:@"Preferences.Advanced.pongInterval"]; } +#pragma mark - Downloads Path + ++ (void)setDownloadsPath:(NSString *)value { + + NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; + [ud setObject:value forKey:@"Preferences.downloadsPath"]; +} + ++ (void)setDownloadsPath { + + NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; + [ud setObject:[@"~/Desktop" stringByExpandingTildeInPath] forKey:@"Preferences.downloadsPath"]; +} + ++ (NSString*)getDownloadsPath { + + NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; + return [ud stringForKey:@"Preferences.downloadsPath"]; +} + #pragma mark - Max Log Lines + (int)maxLogLines @@ -832,6 +852,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..ec3e559b 100644 --- a/English.lproj/Preferences.xib +++ b/English.lproj/Preferences.xib @@ -1,8 +1,8 @@ - + - + @@ -25,13 +25,13 @@ - + - + @@ -41,7 +41,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -66,7 +66,7 @@ - - - + @@ -105,10 +105,10 @@ - + - + @@ -119,7 +119,7 @@ - + @@ -139,16 +139,16 @@ - - - - + - + @@ -185,7 +185,7 @@ - + @@ -212,16 +212,16 @@ - - - - - - - - + @@ -333,7 +333,7 @@ - + @@ -351,7 +351,7 @@ - + @@ -369,7 +369,7 @@ - + @@ -378,14 +378,14 @@ - + - + @@ -394,7 +394,7 @@ - - + @@ -422,7 +422,7 @@ - + @@ -439,7 +439,7 @@ - + @@ -460,7 +460,7 @@ - - + @@ -480,12 +480,12 @@ - + - + NSAllRomanInputSourcesLocaleIdentifier @@ -499,7 +499,7 @@ - - - - + @@ -585,7 +585,7 @@ - + @@ -606,7 +606,7 @@ - - - + - + @@ -656,7 +656,7 @@ - - + @@ -684,7 +684,7 @@ - - + @@ -704,7 +704,7 @@ - + @@ -715,7 +715,7 @@ - + @@ -736,7 +736,7 @@ - - - - - @@ -1123,6 +1159,7 @@ + From ef8df7c2aa991e8363e9afddcb02a32d3cf35b09 Mon Sep 17 00:00:00 2001 From: aaeric Date: Mon, 16 Dec 2019 14:05:39 +0545 Subject: [PATCH 2/5] set new download path --- Classes/Dialogs/Preferences/PreferencesController.m | 3 +-- Classes/Library/YAML/SyckInput.m | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Classes/Dialogs/Preferences/PreferencesController.m b/Classes/Dialogs/Preferences/PreferencesController.m index 6563c613..a84f0031 100644 --- a/Classes/Dialogs/Preferences/PreferencesController.m +++ b/Classes/Dialogs/Preferences/PreferencesController.m @@ -504,8 +504,7 @@ - (IBAction)onOpenDownloadsPath:(id)sender { if (result == NSFileHandlingPanelOKButton) { NSURL* theDir = [[panel URLs] objectAtIndex:0]; NSString* thePath = theDir.path; - - + [Preferences setDownloadsPath:thePath]; } }];} 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" From e6259f9c2e610f75d0370d1c59c7d03fe18bd351 Mon Sep 17 00:00:00 2001 From: aaeric Date: Tue, 17 Dec 2019 20:11:57 +0545 Subject: [PATCH 3/5] displays new downloads path via label stringvalue --- Classes/Dialogs/Preferences/PreferencesController.h | 3 +++ Classes/Dialogs/Preferences/PreferencesController.m | 6 +++++- Classes/Preferences/Preferences.m | 3 ++- English.lproj/Preferences.xib | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Classes/Dialogs/Preferences/PreferencesController.h b/Classes/Dialogs/Preferences/PreferencesController.h index c632a147..feb3df39 100644 --- a/Classes/Dialogs/Preferences/PreferencesController.h +++ b/Classes/Dialogs/Preferences/PreferencesController.h @@ -26,6 +26,8 @@ @property (nonatomic) IBOutlet NSPopUpButton* transcriptFolderButton; @property (nonatomic) IBOutlet NSPopUpButton* themeButton; @property (nonatomic) IBOutlet NSTableView* soundsTable; +@property (nonatomic, weak) IBOutlet NSTextField* labelDisplay; + - (void)show; @@ -45,6 +47,7 @@ @end + @interface NSObject (PreferencesControllerDelegate) - (void)preferencesDialogWillClose:(PreferencesController*)sender; @end diff --git a/Classes/Dialogs/Preferences/PreferencesController.m b/Classes/Dialogs/Preferences/PreferencesController.m index a84f0031..e3843ae1 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; @@ -142,6 +143,7 @@ - (void)setPongInterval:(int)value [Preferences setPongInterval:value]; } + - (BOOL)validateValue:(id *)value forKey:(NSString *)key error:(NSError **)error { if ([key isEqualToString:@"maxLogLines"]) { @@ -504,7 +506,9 @@ - (IBAction)onOpenDownloadsPath:(id)sender { if (result == NSFileHandlingPanelOKButton) { NSURL* theDir = [[panel URLs] objectAtIndex:0]; NSString* thePath = theDir.path; - [Preferences setDownloadsPath:thePath]; + [Preferences setDownloadsPath:thePath]; + self->_labelDisplay.stringValue = [Preferences getDownloadsPath]; + } }];} diff --git a/Classes/Preferences/Preferences.m b/Classes/Preferences/Preferences.m index 5b69560d..ca77459c 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 @@ -345,6 +344,8 @@ + (void)setDownloadsPath:(NSString *)value { NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; [ud setObject:value forKey:@"Preferences.downloadsPath"]; + + } + (void)setDownloadsPath { diff --git a/English.lproj/Preferences.xib b/English.lproj/Preferences.xib index ec3e559b..efaecd8a 100644 --- a/English.lproj/Preferences.xib +++ b/English.lproj/Preferences.xib @@ -13,6 +13,7 @@ + @@ -37,7 +38,7 @@ - + @@ -902,7 +903,7 @@ - + From c737fda8472f5672e0268d95a0e1ec7e09b9d4d3 Mon Sep 17 00:00:00 2001 From: aaeric Date: Sun, 22 Dec 2019 14:50:55 +0545 Subject: [PATCH 4/5] added user default downloads paths --- .../Preferences/PreferencesController.h | 12 +++++++-- .../Preferences/PreferencesController.m | 23 ++++++++++++++-- Classes/IRC/IRCClient.m | 7 ++--- Classes/Preferences/Preferences.h | 2 +- Classes/Preferences/Preferences.m | 27 ++++++++++++------- English.lproj/Preferences.xib | 6 ++--- 6 files changed, 57 insertions(+), 20 deletions(-) diff --git a/Classes/Dialogs/Preferences/PreferencesController.h b/Classes/Dialogs/Preferences/PreferencesController.h index feb3df39..e0676e7c 100644 --- a/Classes/Dialogs/Preferences/PreferencesController.h +++ b/Classes/Dialogs/Preferences/PreferencesController.h @@ -26,10 +26,13 @@ @property (nonatomic) IBOutlet NSPopUpButton* transcriptFolderButton; @property (nonatomic) IBOutlet NSPopUpButton* themeButton; @property (nonatomic) IBOutlet NSTableView* soundsTable; -@property (nonatomic, weak) IBOutlet NSTextField* labelDisplay; +@property (nonatomic, weak) IBOutlet NSTextField *labelDisplay; + - (void)show; +- (void)receivedNotification:(NSNotification*)notification; +- (void)statusNotification:(NSNotification*)notification; - (void)onAddKeyword:(id)sender; - (void)onAddExcludeWord:(id)sender; @@ -44,9 +47,14 @@ - (void)onChangedTransparency:(id)sender; - (IBAction)onOpenDownloadsPath:(id)sender; -@end +- (void)displaySetPath; +- (NSString*)getPath; +- (void)quickUpdate; + +@end + @interface NSObject (PreferencesControllerDelegate) - (void)preferencesDialogWillClose:(PreferencesController*)sender; diff --git a/Classes/Dialogs/Preferences/PreferencesController.m b/Classes/Dialogs/Preferences/PreferencesController.m index e3843ae1..2faee5bc 100644 --- a/Classes/Dialogs/Preferences/PreferencesController.m +++ b/Classes/Dialogs/Preferences/PreferencesController.m @@ -30,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 @@ -43,6 +47,7 @@ - (void)dealloc _soundsTable.dataSource = nil; } + #pragma mark - Utilities - (void)show @@ -50,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]; @@ -507,12 +514,24 @@ - (IBAction)onOpenDownloadsPath:(id)sender { NSURL* theDir = [[panel URLs] objectAtIndex:0]; NSString* thePath = theDir.path; [Preferences setDownloadsPath:thePath]; - self->_labelDisplay.stringValue = [Preferences getDownloadsPath]; } - }];} +- (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/Preferences/Preferences.h b/Classes/Preferences/Preferences.h index b0b4223d..7fd56c6a 100644 --- a/Classes/Preferences/Preferences.h +++ b/Classes/Preferences/Preferences.h @@ -97,8 +97,8 @@ typedef enum { + (void)setPongInterval:(int)value; + (void)setDownloadsPath:(NSString*)value; -+ (void)setDownloadsPath; + (NSString*)getDownloadsPath; ++ (void)checkOldPath; + (int)maxLogLines; + (void)setMaxLogLines:(int)value; diff --git a/Classes/Preferences/Preferences.m b/Classes/Preferences/Preferences.m index ca77459c..381a865b 100644 --- a/Classes/Preferences/Preferences.m +++ b/Classes/Preferences/Preferences.m @@ -343,21 +343,30 @@ + (void)setPongInterval:(int)value + (void)setDownloadsPath:(NSString *)value { NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; - [ud setObject:value forKey:@"Preferences.downloadsPath"]; - - + [ud setValue:value forKey:@"Preferences.downloadsPath"]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"Downloads Path Set" object:self]; } -+ (void)setDownloadsPath { ++ (NSString*)getDownloadsPath { NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; - [ud setObject:[@"~/Desktop" stringByExpandingTildeInPath] forKey:@"Preferences.downloadsPath"]; + return [ud stringForKey:@"Preferences.downloadsPath"]; } -+ (NSString*)getDownloadsPath { ++ (void)checkOldPath { - NSUserDefaults* ud = [NSUserDefaults standardUserDefaults]; - return [ud stringForKey:@"Preferences.downloadsPath"]; + 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 @@ -853,7 +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"]; + [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 efaecd8a..a5a698a4 100644 --- a/English.lproj/Preferences.xib +++ b/English.lproj/Preferences.xib @@ -13,7 +13,7 @@ - + @@ -38,7 +38,7 @@ - + @@ -903,7 +903,7 @@ - + From d9d1d01a1ba57cb967b5fe94cb1e82a9aa94685c Mon Sep 17 00:00:00 2001 From: aaeric Date: Sun, 22 Dec 2019 15:06:53 +0545 Subject: [PATCH 5/5] cleaned up unused function code --- Classes/Dialogs/Preferences/PreferencesController.h | 5 ----- English.lproj/Preferences.xib | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Classes/Dialogs/Preferences/PreferencesController.h b/Classes/Dialogs/Preferences/PreferencesController.h index e0676e7c..11017073 100644 --- a/Classes/Dialogs/Preferences/PreferencesController.h +++ b/Classes/Dialogs/Preferences/PreferencesController.h @@ -32,7 +32,6 @@ - (void)show; - (void)receivedNotification:(NSNotification*)notification; -- (void)statusNotification:(NSNotification*)notification; - (void)onAddKeyword:(id)sender; - (void)onAddExcludeWord:(id)sender; @@ -48,10 +47,6 @@ - (IBAction)onOpenDownloadsPath:(id)sender; - (void)displaySetPath; -- (NSString*)getPath; -- (void)quickUpdate; - - @end diff --git a/English.lproj/Preferences.xib b/English.lproj/Preferences.xib index a5a698a4..411a61f0 100644 --- a/English.lproj/Preferences.xib +++ b/English.lproj/Preferences.xib @@ -774,7 +774,7 @@ - + @@ -1132,8 +1132,8 @@ - - + +