Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Selectable Downloads Path #314

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Classes/Dialogs/Preferences/PreferencesController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,6 +44,9 @@
- (void)onInputSelectFont:(id)sender;
- (void)onOverrideFontChanged:(id)sender;
- (void)onChangedTransparency:(id)sender;
- (IBAction)onOpenDownloadsPath:(id)sender;

- (void)displaySetPath;

@end

Expand Down
40 changes: 40 additions & 0 deletions Classes/Dialogs/Preferences/PreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define PONG_INTERVAL_MIN 20



@implementation PreferencesController
{
NSMutableArray* _sounds;
Expand All @@ -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
Expand All @@ -42,16 +47,19 @@ - (void)dealloc
_soundsTable.dataSource = nil;
}


#pragma mark - Utilities

- (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];
Expand Down Expand Up @@ -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"]) {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions Classes/IRC/IRCClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this bit if you switch the if to become negative, and then you'll only need the part which you currently have in else

}
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];
Expand Down
2 changes: 1 addition & 1 deletion Classes/Library/YAML/SyckInput.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import <syck.h>
#import "syck.h"
#import "YAML.h"
#import "GTMBase64.h"

Expand Down
4 changes: 4 additions & 0 deletions Classes/Preferences/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
33 changes: 32 additions & 1 deletion Classes/Preferences/Preferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
static NSMutableArray* keywords;
static NSMutableArray* excludeWords;


@implementation Preferences

+ (DCCActionType)dccAction
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down
Loading