//
//  ipbcAppDelegate.m
//  ipbc-Client
//
//  Created by Gerrit Linnemann on 25.10.13.
//  Copyright (c) 2013 Adawim UG (haftungsbeschränkt). All rights reserved.
//

#import "ipbcAppDelegate.h"
#import "ImageHelper.h"
#import "WebServiceConstants.h"

@implementation ipbcAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    
    NSString *settingTempName = [[NSUserDefaults standardUserDefaults] stringForKey:@"setting.name"];
    NSString *settingTempToken = [[NSUserDefaults standardUserDefaults] stringForKey:@"setting.token"];
    
    [settingName setStringValue:(settingTempName != nil ? settingTempName : @"")];
    [settingToken setStringValue:(settingTempToken != nil ? settingTempToken : @"")];
}

-(void)awakeFromNib {
    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
    [statusItem setMenu:statusMenu];
    [statusItem setHighlightMode:YES];
        
    // statusbar icon
    NSSize statusbarIconSize;
    statusbarIconSize.width = 18;
    statusbarIconSize.height = 18;
    [statusItem setImage:[ImageHelper resizeImage:[NSImage imageNamed: @"statusbar-icon.png"] size:statusbarIconSize]];
}

-(IBAction)fromMenuSettings:(id)sender {
    [settings makeKeyAndOrderFront:nil];
}

-(IBAction)fromMenuQuit:(id)sender {
    [NSApp terminate:self];
}

-(IBAction)fromSettingsSave:(id)sender {
    NSUserDefaults *defauls = [NSUserDefaults standardUserDefaults];
    [defauls setObject:[settingName stringValue] forKey:@"setting.name"];
    [defauls setObject:[settingToken stringValue] forKey:@"setting.token"];
    
    // ip reset
    [defauls setObject:@"0.0.0.0" forKey:@"value.ip.ipv4"];
    
    [settings orderOut:self];
}

-(IBAction)fromSettingsCancel:(id)sender {
    [settings orderOut:self];
}

-(IBAction)gotoHomepage:(id)sender {
    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:HOMEPAGE_REGISTER]];
}

@end
