diff --git a/syncthing.xcodeproj/project.pbxproj b/syncthing.xcodeproj/project.pbxproj index bbabcc8..b87d6ae 100644 --- a/syncthing.xcodeproj/project.pbxproj +++ b/syncthing.xcodeproj/project.pbxproj @@ -16,6 +16,8 @@ C4576BE61D11E79F0031BCFD /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C4576BE51D11E79F0031BCFD /* Foundation.framework */; }; C4576BEA1D11E7E10031BCFD /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C4576BE91D11E7E10031BCFD /* CoreFoundation.framework */; }; C4576BEB1D11E9280031BCFD /* XGSyncthing.m in Sources */ = {isa = PBXBuildFile; fileRef = C4FFB0641D0D7E4C0015D14A /* XGSyncthing.m */; }; + C46500121DA1177F00C250BC /* GeneralViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C46500111DA1177F00C250BC /* GeneralViewController.xib */; }; + C46500151DA1180800C250BC /* STPreferencesWindowGeneralViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C46500141DA1180800C250BC /* STPreferencesWindowGeneralViewController.m */; }; C47F6C3A1D0DE68D00F36CF6 /* syncthing.icns in Resources */ = {isa = PBXBuildFile; fileRef = C47F6C391D0DE68D00F36CF6 /* syncthing.icns */; }; C4946B011D5877F2008447A2 /* STAboutWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = C4946B001D5877F2008447A2 /* STAboutWindow.xib */; }; C4946B031D587878008447A2 /* STAboutWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = C4946B021D587878008447A2 /* STAboutWindowController.m */; }; @@ -65,6 +67,9 @@ C4576BE51D11E79F0031BCFD /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; C4576BE71D11E7C00031BCFD /* libobjc.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libobjc.tbd; path = usr/lib/libobjc.tbd; sourceTree = SDKROOT; }; C4576BE91D11E7E10031BCFD /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; + C46500111DA1177F00C250BC /* GeneralViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = GeneralViewController.xib; path = UI/STPreferencesWindow/GeneralViewController.xib; sourceTree = ""; }; + C46500131DA1180800C250BC /* STPreferencesWindowGeneralViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = STPreferencesWindowGeneralViewController.h; path = UI/STPreferencesWindow/STPreferencesWindowGeneralViewController.h; sourceTree = ""; }; + C46500141DA1180800C250BC /* STPreferencesWindowGeneralViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = STPreferencesWindowGeneralViewController.m; path = UI/STPreferencesWindow/STPreferencesWindowGeneralViewController.m; sourceTree = ""; }; C47F6C391D0DE68D00F36CF6 /* syncthing.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = syncthing.icns; sourceTree = ""; }; C4946B001D5877F2008447A2 /* STAboutWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = STAboutWindow.xib; path = UI/STAboutWindow.xib; sourceTree = ""; }; C4946B021D587878008447A2 /* STAboutWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = STAboutWindowController.m; path = Controllers/STAboutWindowController.m; sourceTree = ""; }; @@ -140,6 +145,26 @@ name = Frameworks; sourceTree = ""; }; + C465000A1DA114FE00C250BC /* STPreferencesWindow */ = { + isa = PBXGroup; + children = ( + C4460A7C1D0DD2D500200C21 /* STPreferencesWindowController.h */, + C4460A7D1D0DD2D500200C21 /* STPreferencesWindowController.m */, + C46500131DA1180800C250BC /* STPreferencesWindowGeneralViewController.h */, + C46500141DA1180800C250BC /* STPreferencesWindowGeneralViewController.m */, + ); + name = STPreferencesWindow; + sourceTree = ""; + }; + C46500101DA116D400C250BC /* STPreferencesWindow */ = { + isa = PBXGroup; + children = ( + C46500111DA1177F00C250BC /* GeneralViewController.xib */, + C4460A821D0DD38F00200C21 /* STPreferencesWindow.xib */, + ); + name = STPreferencesWindow; + sourceTree = ""; + }; C4A415571D0D579D00DC6018 = { isa = PBXGroup; children = ( @@ -192,8 +217,7 @@ C4D6DD5F1D0DAF530024D20A /* Controllers */ = { isa = PBXGroup; children = ( - C4460A7C1D0DD2D500200C21 /* STPreferencesWindowController.h */, - C4460A7D1D0DD2D500200C21 /* STPreferencesWindowController.m */, + C465000A1DA114FE00C250BC /* STPreferencesWindow */, C4460A7E1D0DD2D500200C21 /* STStatusBarController.h */, C4460A7F1D0DD2D500200C21 /* STStatusBarController.m */, C4946B021D587878008447A2 /* STAboutWindowController.m */, @@ -205,7 +229,7 @@ C4D6DD601D0DB18A0024D20A /* UI */ = { isa = PBXGroup; children = ( - C4460A821D0DD38F00200C21 /* STPreferencesWindow.xib */, + C46500101DA116D400C250BC /* STPreferencesWindow */, C4A4156B1D0D579D00DC6018 /* STApplication.xib */, C4946B001D5877F2008447A2 /* STAboutWindow.xib */, ); @@ -317,6 +341,7 @@ C4A4156D1D0D579D00DC6018 /* STApplication.xib in Resources */, C4460A831D0DD38F00200C21 /* STPreferencesWindow.xib in Resources */, C4946B011D5877F2008447A2 /* STAboutWindow.xib in Resources */, + C46500121DA1177F00C250BC /* GeneralViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -356,6 +381,7 @@ C4D567A21D3A8DFE002AD881 /* STLoginItem.m in Sources */, C4FFB0661D0D7F870015D14A /* XGSyncthing.m in Sources */, C4A415681D0D579D00DC6018 /* main.m in Sources */, + C46500151DA1180800C250BC /* STPreferencesWindowGeneralViewController.m in Sources */, C4946B031D587878008447A2 /* STAboutWindowController.m in Sources */, C4460A811D0DD2D500200C21 /* STStatusBarController.m in Sources */, C4460A801D0DD2D500200C21 /* STPreferencesWindowController.m in Sources */, diff --git a/syncthing/Assets.xcassets/StatusIconDefault.imageset/default.pdf b/syncthing/Assets.xcassets/StatusIconDefault.imageset/default.pdf deleted file mode 100644 index d746521..0000000 Binary files a/syncthing/Assets.xcassets/StatusIconDefault.imageset/default.pdf and /dev/null differ diff --git a/syncthing/Assets.xcassets/StatusIconNotify.imageset/notify.pdf b/syncthing/Assets.xcassets/StatusIconNotify.imageset/notify.pdf deleted file mode 100644 index 6b86130..0000000 --- a/syncthing/Assets.xcassets/StatusIconNotify.imageset/notify.pdf +++ /dev/null @@ -1,92 +0,0 @@ -%PDF-1.5 -%µí®û -3 0 obj -<< /Length 4 0 R - /Filter /FlateDecode ->> -stream -xœ¥”»®1 †{?…_àø8÷qKƒ„D±PP -Ø3B,Òž-x}ì\F›hvvü%öo'ñÌ®à6¼ >"qpèId´»ŽAÖkZ¢£<ÝF̆ ö_ç¸Úö;À‚ö™ëþGΧ¦û4M‹¿ÀóWÆ—>ßö„·N òz}x‹}˜Ä‰�¿�ñ�Þ?àódbüßãÝÐ=4]¢,‚[«F×ÚÑyÊyk£Ôè0*& -ì&z˜1�†^”È—ãÍ”þ¨3A£‘ÒL™ý±Î�xnky}Ácþ¶>¦µvÚJÒ8O)ª:S’ˆ?ñÍ?ʸ¨u$ÌzÄò?2�|ö¦Æe–ÓÃMÇQñAWl-p™˜ÉK±m(e±»[$$©ŒXèpÔ-]œA[RË,9+wJ”´4íÃâ»{ÕAB>ÄÑlÀ{1Ë¶ŠŸÁe -![U’�­o0k9b;“äºg�¨lÚ.3®ãªÚVù�G3GÊ¡X�>÷³4ôÄÚ궉[¡;Ö‰‰JŠ# -:<÷Çç»ö°=e=õöaÑ7Ý‚Cg|=¦èù®ƒôíÓØ¡ÐŽù)´¡×ïæ×§ûȘî�6}‚?Ä©ûX -endstream -endobj -4 0 obj - 465 -endobj -2 0 obj -<< - /ExtGState << - /a0 << /CA 1 /ca 1 >> - >> - /Shading << /sh5 5 0 R >> ->> -endobj -6 0 obj -<< /Type /Page - /Parent 1 0 R - /MediaBox [ 0 0 18 18 ] - /Contents 3 0 R - /Group << - /Type /Group - /S /Transparency - /I true - /CS /DeviceRGB - >> - /Resources 2 0 R ->> -endobj -7 0 obj -<< /FunctionType 2 - /Domain [ 0 1 ] - /C0 [ 0.14902 0.713725 0.858824 ] - /C1 [ 0.0313725 0.509804 0.784314 ] - /N 1 ->> -endobj -5 0 obj - << /ShadingType 2 - /ColorSpace /DeviceRGB - /Coords [ 8 0 8 16 ] - /Domain [ 0 1 ] - /Extend [ false false ] - /Function 7 0 R - >> -endobj -1 0 obj -<< /Type /Pages - /Kids [ 6 0 R ] - /Count 1 ->> -endobj -8 0 obj -<< /Creator (cairo 1.14.6 (http://cairographics.org)) - /Producer (cairo 1.14.6 (http://cairographics.org)) ->> -endobj -9 0 obj -<< /Type /Catalog - /Pages 1 0 R ->> -endobj -xref -0 10 -0000000000 65535 f -0000001225 00000 n -0000000579 00000 n -0000000015 00000 n -0000000557 00000 n -0000001032 00000 n -0000000680 00000 n -0000000892 00000 n -0000001290 00000 n -0000001417 00000 n -trailer -<< /Size 10 - /Root 9 0 R - /Info 8 0 R ->> -startxref -1469 -%%EOF diff --git a/syncthing/Assets.xcassets/StatusIconPause.imageset/pause.pdf b/syncthing/Assets.xcassets/StatusIconPause.imageset/pause.pdf deleted file mode 100644 index bac0e66..0000000 Binary files a/syncthing/Assets.xcassets/StatusIconPause.imageset/pause.pdf and /dev/null differ diff --git a/syncthing/Assets.xcassets/StatusIconSync.imageset/sync.pdf b/syncthing/Assets.xcassets/StatusIconSync.imageset/sync.pdf deleted file mode 100644 index 738a7ef..0000000 --- a/syncthing/Assets.xcassets/StatusIconSync.imageset/sync.pdf +++ /dev/null @@ -1,90 +0,0 @@ -%PDF-1.5 -%µí®û -3 0 obj -<< /Length 4 0 R - /Filter /FlateDecode ->> -stream -xœ¥TË®Ô0 Ýû+üøæ�xË ‰Å… ÄõŽÐ Ò0 ~;�ª)wêtzNjŸ$nîp[�ñ†òd¼E뉣A½ë4rMÄ2jfØÈ)¬ÿuŽ ÖßN4é2k}ÆŸ`ɺØtßL¨ù7xúfðå�O�KÄÇžAäåúøû0Ä–Ù;ü ßËý¾|EC¿CÀxG;twM)1cind®�ZG)•öPÛAÅHÞØI�˜9� ½:X$—GŽSÈýQg�ÆFiˆ2e.gŸŸðL›Ë¯Ü—áµùòA¼SÉQòÅ ê†"¼âÛ”±A|DL²Åü?2ž\rªfò´ÓÓUÇRv^f¬-p›4‘ã¬Ë�ó‚{XŒ‰c)°°=P–t-°�´¤ØÌLÞY¤(Ö¤³[p�ªƒ19FFÀG1­¶Šo`yŸÔ'«ó܈Ö•‰|"=²Nê)i—™×éªÚfyª#•%ŸÕ K}/•:2ÒVØ®¤ÖI#åF,l�¼œkl‡öÐ55²ëí`‘/<]mˆ…ô :˜Ö¶®Á®3N�)º:Èû"&|$ÝÙßX¾¯Ö’äó¤WÝñÃÆU>ÝÃëâ™:ÕZp7ÑpE¯««m$šŸ– -6ö -G 4xՓ–®JS3º¿;ᱚGÜ«wÒÖr±³É1ûîØ.J -endstream -endobj -4 0 obj - 533 -endobj -2 0 obj -<< - /ExtGState << - /a0 << /CA 1 /ca 1 >> - >> - /Shading << /sh5 5 0 R >> ->> -endobj -6 0 obj -<< /Type /Page - /Parent 1 0 R - /MediaBox [ 0 0 18 18 ] - /Contents 3 0 R - /Group << - /Type /Group - /S /Transparency - /I true - /CS /DeviceRGB - >> - /Resources 2 0 R ->> -endobj -7 0 obj -<< /FunctionType 2 - /Domain [ 0 1 ] - /C0 [ 0.14902 0.713725 0.858824 ] - /C1 [ 0.0313725 0.509804 0.784314 ] - /N 1 ->> -endobj -5 0 obj - << /ShadingType 2 - /ColorSpace /DeviceRGB - /Coords [ 8 0 8 16 ] - /Domain [ 0 1 ] - /Extend [ false false ] - /Function 7 0 R - >> -endobj -1 0 obj -<< /Type /Pages - /Kids [ 6 0 R ] - /Count 1 ->> -endobj -8 0 obj -<< /Creator (cairo 1.14.6 (http://cairographics.org)) - /Producer (cairo 1.14.6 (http://cairographics.org)) ->> -endobj -9 0 obj -<< /Type /Catalog - /Pages 1 0 R ->> -endobj -xref -0 10 -0000000000 65535 f -0000001293 00000 n -0000000647 00000 n -0000000015 00000 n -0000000625 00000 n -0000001100 00000 n -0000000748 00000 n -0000000960 00000 n -0000001358 00000 n -0000001485 00000 n -trailer -<< /Size 10 - /Root 9 0 R - /Info 8 0 R ->> -startxref -1537 -%%EOF diff --git a/syncthing/Controllers/STPreferencesWindowController.h b/syncthing/Controllers/STPreferencesWindowController.h index 24cc9f4..c885b7c 100644 --- a/syncthing/Controllers/STPreferencesWindowController.h +++ b/syncthing/Controllers/STPreferencesWindowController.h @@ -10,9 +10,4 @@ @interface STPreferencesWindowController : NSWindowController -@property (weak) IBOutlet NSTextField *Syncthing_URI; -@property (weak) IBOutlet NSTextField *Syncthing_ApiKey; -@property (weak) IBOutlet NSButton *StartAtLogin; -@property (weak) IBOutlet NSButton *Test; - @end diff --git a/syncthing/Controllers/STPreferencesWindowController.m b/syncthing/Controllers/STPreferencesWindowController.m index cb8fda5..7104e41 100644 --- a/syncthing/Controllers/STPreferencesWindowController.m +++ b/syncthing/Controllers/STPreferencesWindowController.m @@ -7,8 +7,6 @@ // #import "STPreferencesWindowController.h" -#import "STLoginItem.h" -#import "XGSyncthing.h" @interface STPreferencesWindowController () @@ -21,53 +19,65 @@ } - (void)windowDidLoad { - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - - [self.Syncthing_URI setStringValue:[defaults objectForKey:@"URI"]]; - [self.Syncthing_ApiKey setStringValue:[defaults objectForKey:@"ApiKey"]]; - [self.StartAtLogin setStringValue:[defaults objectForKey:@"StartAtLogin"]]; - - [self updateTestButton]; } -- (void)updateTestButton { - XGSyncthing *st = [[XGSyncthing alloc] init]; - - [st setURI:[self.Syncthing_URI stringValue]]; - [st setApiKey:[self.Syncthing_ApiKey stringValue]]; - - if ([st ping]) { - [self.Test setImage:[NSImage imageNamed:NSImageNameStatusAvailable]]; - } else { - [self.Test setImage:[NSImage imageNamed:NSImageNameStatusUnavailable]]; +- (IBAction)toolbarButtonClicked:(id)sender { + NSToolbarItem *item = sender; + [self loadViewWithIdentifier:item.itemIdentifier withAnimation:YES]; +} + +-(void)loadViewWithIdentifier:(NSString *)viewTabIdentifier + withAnimation:(BOOL)shouldAnimate{ + /* + if ([_currentView isEqualToString:viewTabIdentifier]){ + return; } -} - -- (void)updateStartAtLogin:(NSUserDefaults *)defaults { - STLoginItem *li = [STLoginItem alloc]; - - if ([defaults integerForKey:@"StartAtLogin"]) { - if (![li wasAppAddedAsLoginItem]) - [li addAppAsLoginItem]; - } else { - [li deleteAppFromLoginItem]; - } -} - -- (IBAction)clickedDone:(id)sender { - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + else + { + _currentView = viewTabIdentifier; + } + */ + //Loop through the view array and find out the class to load - [defaults setObject:[self.Syncthing_URI stringValue] forKey:@"URI"]; - [defaults setObject:[self.Syncthing_ApiKey stringValue] forKey:@"ApiKey"]; - [defaults setObject:[self.StartAtLogin stringValue] forKey:@"StartAtLogin"]; - - [self updateStartAtLogin:defaults]; - - [self close]; -} - -- (IBAction)clickedTest:(id)sender { - [self updateTestButton]; + /* + NSDictionary *viewInfoDict = nil; + for (NSDictionary *dict in _toolbarTabsArray){ + if ([dict[@"identifier"] isEqualToString:viewTabIdentifier]){ + viewInfoDict = dict; + break; + } + } + */ + + //NSString *class = @"STPreferencesWindowGeneralViewController";//viewInfoDict[@"class"]; + //if(NSClassFromString(class)) + //{ + /* + _currentViewController = [[STPreferencesWindowGeneralViewController alloc] init]; + + //Old View + //NSView * oldView = self.window.contentView; + + //self.window.contentView + + //New View + NSView *newView = _currentViewController.view; + + NSRect windowRect = self.window.frame; + NSRect currentViewRect = newView.frame; + + + + windowRect.origin.y = windowRect.origin.y + (windowRect.size.height - currentViewRect.size.height); + windowRect.size.height = currentViewRect.size.height; + windowRect.size.width = currentViewRect.size.width; + + [self.window setContentView:newView]; + [self.window setFrame:windowRect display:YES animate:shouldAnimate]; + */ + //} else{ + // NSAssert(false, @"Couldn't load %@", class); + //} } @end diff --git a/syncthing/STApplication.m b/syncthing/STApplication.m index eee369e..468d09b 100644 --- a/syncthing/STApplication.m +++ b/syncthing/STApplication.m @@ -16,7 +16,7 @@ self.syncthing = [[XGSyncthing alloc] init]; [self applicationLoadConfiguration]; - [self.syncthing runExecutable]; + //[self.syncthing runExecutable]; self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(updateStatusFromTimer) userInfo:nil repeats:YES]; } @@ -41,7 +41,7 @@ { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSString *cfgExecutable = [defaults stringForKey:@"Executable"]; + NSString *cfgExecutable = [defaults stringForKey:@"Executable"]; if (cfgExecutable) { [self.syncthing setExecutable:cfgExecutable]; } else { @@ -50,7 +50,7 @@ @"syncthing/syncthing"]]; } - NSString *cfgURI = [defaults stringForKey:@"URI"]; + NSString *cfgURI = [defaults stringForKey:@"URI"]; if (cfgURI) { [self.syncthing setURI:cfgURI]; } else { @@ -58,7 +58,7 @@ [defaults setObject:[self.syncthing URI] forKey:@"URI"]; } - NSString *cfgApiKey = [defaults stringForKey:@"ApiKey"]; + NSString *cfgApiKey = [defaults stringForKey:@"ApiKey"]; if (cfgApiKey) { [self.syncthing setApiKey:cfgApiKey]; } else { @@ -85,14 +85,10 @@ { if ([self.syncthing ping]) { [self updateStatusIcon:@"StatusIconDefault"]; - [self.statusItem setToolTip:[ - NSString stringWithFormat:@"Syncthing - Connected\n%@\nUptime %@", - [self.syncthing URI], - [self.syncthing getUptime] - ]]; + [self.statusItem setToolTip:@"Connected"]; } else { [self updateStatusIcon:@"StatusIconNotify"]; - [self.statusItem setToolTip:@"Syncthing - Not connected"]; + [self.statusItem setToolTip:@"Not connected"]; } } @@ -139,6 +135,9 @@ - (IBAction)clickedPreferences:(NSMenuItem *)sender { + if (self.preferencesWindow) + return; + self.preferencesWindow = [[STPreferencesWindowController alloc] init]; [self.preferencesWindow.window setLevel:NSFloatingWindowLevel]; [NSApp activateIgnoringOtherApps:YES]; @@ -151,6 +150,9 @@ - (IBAction)clickedAbout:(NSMenuItem *)sender { + if (self.aboutWindow) + return; + self.aboutWindow = [[STAboutWindowController alloc] init]; [self.aboutWindow.window setLevel:NSFloatingWindowLevel]; [NSApp activateIgnoringOtherApps:YES]; diff --git a/syncthing/UI/STPreferencesWindow.xib b/syncthing/UI/STPreferencesWindow.xib index 2872db9..186a494 100644 --- a/syncthing/UI/STPreferencesWindow.xib +++ b/syncthing/UI/STPreferencesWindow.xib @@ -6,123 +6,77 @@ - - - - - + - + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + - diff --git a/syncthing/UI/STPreferencesWindow/GeneralViewController.xib b/syncthing/UI/STPreferencesWindow/GeneralViewController.xib new file mode 100644 index 0000000..f8564ea --- /dev/null +++ b/syncthing/UI/STPreferencesWindow/GeneralViewController.xib @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/syncthing/UI/STPreferencesWindow/STPreferencesWindowGeneralViewController.h b/syncthing/UI/STPreferencesWindow/STPreferencesWindowGeneralViewController.h new file mode 100644 index 0000000..14fc754 --- /dev/null +++ b/syncthing/UI/STPreferencesWindow/STPreferencesWindowGeneralViewController.h @@ -0,0 +1,19 @@ +// +// STPreferencesWindowGeneralViewController.h +// syncthing +// +// Created by Jerry Jacobs on 02/10/2016. +// Copyright © 2016 Jerry Jacobs. All rights reserved. +// + +#import + +@interface STPreferencesWindowGeneralViewController : NSViewController + +/* TODO: move into generalViewController */ +@property (weak) IBOutlet NSTextField *Syncthing_URI; +@property (weak) IBOutlet NSTextField *Syncthing_ApiKey; +@property (weak) IBOutlet NSButton *StartAtLogin; +@property (weak) IBOutlet NSButton *buttonTest; + +@end diff --git a/syncthing/UI/STPreferencesWindow/STPreferencesWindowGeneralViewController.m b/syncthing/UI/STPreferencesWindow/STPreferencesWindowGeneralViewController.m new file mode 100644 index 0000000..490de06 --- /dev/null +++ b/syncthing/UI/STPreferencesWindow/STPreferencesWindowGeneralViewController.m @@ -0,0 +1,68 @@ +// +// STPreferencesWindowGeneralViewController.m +// syncthing +// +// Created by Jerry Jacobs on 02/10/2016. +// Copyright © 2016 Jerry Jacobs. All rights reserved. +// + +#import "STPreferencesWindowGeneralViewController.h" +#import "STLoginItem.h" +#import "XGSyncthing.h" + +@interface STPreferencesWindowGeneralViewController () + +@end + +@implementation STPreferencesWindowGeneralViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + + [self.Syncthing_URI setStringValue:[defaults objectForKey:@"URI"]]; + [self.Syncthing_ApiKey setStringValue:[defaults objectForKey:@"ApiKey"]]; + [self.StartAtLogin setStringValue:[defaults objectForKey:@"StartAtLogin"]]; + + [self updateTestButton]; +} + +- (void)updateTestButton { + XGSyncthing *st = [[XGSyncthing alloc] init]; + + [st setURI:[self.Syncthing_URI stringValue]]; + [st setApiKey:[self.Syncthing_ApiKey stringValue]]; + + if ([st ping]) + [self.buttonTest setImage:[NSImage imageNamed:NSImageNameStatusAvailable]]; + else + [self.buttonTest setImage:[NSImage imageNamed:NSImageNameStatusUnavailable]]; +} + +- (void)updateStartAtLogin:(NSUserDefaults *)defaults { + STLoginItem *li = [STLoginItem alloc]; + + if ([defaults integerForKey:@"StartAtLogin"]) { + if (![li wasAppAddedAsLoginItem]) + [li addAppAsLoginItem]; + } else { + [li deleteAppFromLoginItem]; + } +} + +- (IBAction)clickedDone:(id)sender { + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + + [defaults setObject:[self.Syncthing_URI stringValue] forKey:@"URI"]; + [defaults setObject:[self.Syncthing_ApiKey stringValue] forKey:@"ApiKey"]; + [defaults setObject:[self.StartAtLogin stringValue] forKey:@"StartAtLogin"]; + + [self updateStartAtLogin:defaults]; +} + +- (IBAction)clickedTest:(id)sender { + [self updateTestButton]; +} + +@end