settings: recordings folder

-fix path for recordings
-add option to change recordings folder

Change-Id: I2a4cbc9f6a74d977d00071c37f9faadc63043a8f
diff --git a/src/GeneralPrefsVC.mm b/src/GeneralPrefsVC.mm
index da78544..c6ea2d9 100644
--- a/src/GeneralPrefsVC.mm
+++ b/src/GeneralPrefsVC.mm
@@ -20,6 +20,7 @@
 
 //lrc
 #import <api/datatransfermodel.h>
+#import <api/avmodel.h>
 
 #if ENABLE_SPARKLE
 #import <Sparkle/Sparkle.h>
@@ -35,19 +36,22 @@
     __unsafe_unretained IBOutlet NSView* sparkleContainer;
     __unsafe_unretained IBOutlet NSButton *downloadFolder;
     __unsafe_unretained IBOutlet NSTextField *downloadFolderLabel;
+    __unsafe_unretained IBOutlet NSButton *recordingFolder;
+    __unsafe_unretained IBOutlet NSTextField *recordingFolderLabel;
 }
 @end
 
 @implementation GeneralPrefsVC
 
 @synthesize dataTransferModel;
+@synthesize avModel;
 
 
--(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dataTransferModel:(lrc::api::DataTransferModel*) dataTransferModel
-{
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dataTransferModel:(lrc::api::DataTransferModel*) dataTransferModel avModel:(lrc::api::AVModel*) avModel {
     if (self =  [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
     {
         self.dataTransferModel = dataTransferModel;
+        self.avModel = avModel;
     }
     return self;
 }
@@ -70,11 +74,19 @@
         [downloadFolder setHidden:YES];
         [downloadFolder setEnabled:NO];
         [downloadFolderLabel setHidden: YES];
+        [recordingFolder setHidden:YES];
+        [recordingFolder setEnabled:NO];
+        [recordingFolderLabel setHidden:YES];
         return;
     }
     if (dataTransferModel) {
         downloadFolder.title = [@(dataTransferModel->downloadDirectory.c_str()) lastPathComponent];
     }
+    if (avModel) {
+        auto name1 = avModel->getRecordPath();
+        auto name = @(avModel->getRecordPath().c_str());
+        recordingFolder.title = [@(avModel->getRecordPath().c_str()) lastPathComponent];
+    }
 }
 
 - (IBAction)changeDownloadFolder:(id)sender {
@@ -92,6 +104,20 @@
     [[NSUserDefaults standardUserDefaults] setObject:path forKey:Preferences::DownloadFolder];
 }
 
+- (IBAction)changeRecordingFolder:(id)sender {
+    NSOpenPanel *panel = [NSOpenPanel openPanel];
+    [panel setAllowsMultipleSelection:NO];
+    [panel setCanChooseDirectories:YES];
+    [panel setCanChooseFiles:NO];
+    panel.delegate = self;
+    if ([panel runModal] != NSFileHandlingPanelOKButton) return;
+    if ([[panel URLs] lastObject] == nil) return;
+    NSString * path = [[[[panel URLs] lastObject] path] stringByAppendingString:@"/"];
+    avModel->setRecordPath([path UTF8String]);
+    recordingFolder.title = [@(avModel->getRecordPath().c_str()) lastPathComponent];
+    [[NSUserDefaults standardUserDefaults] setObject:path forKey:Preferences::DownloadFolder];
+}
+
 #pragma mark - Startup API
 
 // MIT license by Brian Dunagan
diff --git a/src/LrcModelsProtocol.h b/src/LrcModelsProtocol.h
index 4bb3f2c..bad7cf7 100644
--- a/src/LrcModelsProtocol.h
+++ b/src/LrcModelsProtocol.h
@@ -29,6 +29,7 @@
 @protocol LrcModelsProtocol
 
 -(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dataTransferModel:(const lrc::api::DataTransferModel*) dataTransferModel;
+-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil dataTransferModel:(const lrc::api::DataTransferModel*) dataTransferModel avModel:(const lrc::api::AVModel*) avModel;
 -(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil avModel:(const lrc::api::AVModel*) avModel;
 -(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountmodel:(const lrc::api::NewAccountModel*) accountModel;
 -(id) initWithWindowNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil accountModel:(const lrc::api::NewAccountModel*)accountModel dataTransferModel:(const lrc::api::DataTransferModel*)dataTransferModel behaviourController:(const lrc::api::BehaviorController*) behaviorController;
diff --git a/src/PreferencesWC.mm b/src/PreferencesWC.mm
index ea96cec..88320d3 100644
--- a/src/PreferencesWC.mm
+++ b/src/PreferencesWC.mm
@@ -71,7 +71,7 @@
 {
     [[prefsContainer subviews]
      makeObjectsPerformSelector:@selector(removeFromSuperview)];
-     currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel];
+    currentVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil dataTransferModel: self.dataTransferModel avModel: self.avModel];
 
     [self resizeWindowWithFrame:currentVC.view.frame];
     [prefsContainer addSubview:currentVC.view];
diff --git a/src/RingWindowController.mm b/src/RingWindowController.mm
index 2c82ff1..a7e4dc8 100644
--- a/src/RingWindowController.mm
+++ b/src/RingWindowController.mm
@@ -200,6 +200,8 @@
     if(appSandboxed()) {
         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
         avModel->setRecordPath([[paths objectAtIndex:0] UTF8String]);
+    } else if (avModel->getRecordPath().empty()) {
+        avModel->setRecordPath([NSHomeDirectory() UTF8String]);
     }
     NSToolbar *tb = [[self window] toolbar];
     [tb setAllowsUserCustomization:NO];