/* * GNUnet Setup (Cocoa UI) * Copyright (C) 2009 Heikki Lindholm * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #import "GNNetworkConnectionPage.h" static int insert_nic(const char *name, int default_value, void *opaque) { NSObject *o; NSComboBox *control = (NSComboBox *)opaque; o = [[[NSString alloc] initWithCString:name encoding:NSUTF8StringEncoding] autorelease]; [control addItemWithObjectValue:o]; if (default_value) [control selectItemWithObjectValue:o]; return GNUNET_OK; } @implementation GNNetworkConnectionPage - (void)awakeFromNib { char *val; [messageView setDrawsBackground:NO]; [[messageView enclosingScrollView] setDrawsBackground:NO]; [networkInterfaceComboBox removeAllItems]; GNUNET_list_network_interfaces([assistant gnunetGEContext], &insert_nic, networkInterfaceComboBox); if ([networkInterfaceComboBox numberOfItems] != 0) { [networkInterfaceComboBox setNumberOfVisibleItems: [networkInterfaceComboBox numberOfItems] < 6 ? [networkInterfaceComboBox numberOfItems] : 6]; if ([networkInterfaceComboBox indexOfSelectedItem] == -1) [networkInterfaceComboBox selectItemAtIndex:0]; [assistant setConfigurationOption:"INTERFACE" inSection:"NETWORK" toValue:[[networkInterfaceComboBox stringValue] UTF8String] fromControl:networkInterfaceComboBox]; [assistant setConfigurationOption:"INTERFACES" inSection:"LOAD" toValue:[[networkInterfaceComboBox stringValue] UTF8String] fromControl:networkInterfaceComboBox]; } GNUNET_GC_get_configuration_value_string( [assistant gnunetGCConfiguration], "NETWORK", "IP", "", &val); [ipAddressField setStringValue:[[[NSString alloc] initWithCString:val encoding:NSUTF8StringEncoding] autorelease]]; GNUNET_free(val); } - (IBAction)backAction:(id)sender { NSControl *control = (NSControl *)sender; if ([[control window] firstResponder] != nil && [[control window] firstResponder] != control && [[control window] makeFirstResponder:nil] == NO) { return; } [assistant previousPage]; } - (IBAction)continueAction:(id)sender { NSControl *control = (NSControl *)sender; if ([[control window] firstResponder] != nil && [[control window] firstResponder] != control && [[control window] makeFirstResponder:nil] == NO) { return; } [assistant nextPage]; } - (IBAction)comboAction:(id)sender { NSControl *control = (NSControl *)sender; [assistant setConfigurationOption:"INTERFACE" inSection:"NETWORK" toValue:[[control stringValue] UTF8String] fromControl:control]; [assistant setConfigurationOption:"INTERFACES" inSection:"LOAD" toValue:[[control stringValue] UTF8String] fromControl:control]; } - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor { if (control == ipAddressField) return [assistant setConfigurationOption:"IP" inSection:"NETWORK" toValue:[[control stringValue] UTF8String] fromControl:control]; else if (control == networkInterfaceComboBox) return [assistant setConfigurationOption:"INTERFACE" inSection:"NETWORK" toValue:[[control stringValue] UTF8String] fromControl:control] && [assistant setConfigurationOption:"INTERFACES" inSection:"LOAD" toValue:[[control stringValue] UTF8String] fromControl:control]; return YES; } @end