rendered paste body#import <UIKit/UIKit.h>
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <UIKit/CDStructures.h>
#import <UIKit/UINavigationBar.h>
#import <UIKit/UIPreferencesTable.h>
#import <UIKit/UIPreferencesControlTableCell.h>
#import <UIKit/UIPreferencesTextTableCell.h>
#import <UIKit/UIPreferencesTableCell.h>
#import <UIKit/UIPreferencesDeleteTableCell.h>
#import <UIKit/UIWindow.h>
#import <UIKit/UIHardware.h>
#import <UIKit/UIControl.h>
#import <UIKit/UIImageView.h>
#import <UIKit/UITable.h>
#import <UIKit/UITableCell.h>
#import <UIKit/UISwitchControl.h>
#import <UIKit/UISwitchControlButton.h>
#import <UIKit/UINavigationItem.h>
#import <UIKit/UITextField.h>
#import "PSSpecifiers.h"
#import "ServiceTableCell2.h"
#import "SSHServiceTableCell2.h"
#import "WifiServiceTableCell2.h"
#import "FireflyServiceTableCell2.h"
#import "ApacheServiceTableCell2.h"
#import "EDGEServiceTableCell2.h"
#import "AFPServiceTableCell2.h"
#import "PhoneServiceTableCell2.h"
#import "BluetoothServiceTableCell2.h"
#import "SocksServiceTableCell2.h"
#import "TinyproxyServiceTableCell2.h"
#import "SambaServiceTableCell2.h"
#import "LighttpdServiceTableCell2.h"
#import "IPTableCell2.h"
#import "AutolockServiceTableCell2.h"
#import "TwoView.h"
#import "UITransitionApplication.h"
#import "OneView.h"
static TwoView *sharedInstance = nil;
@implementation TwoView
+ (TwoView *) sharedInstance {
return ( sharedInstance ? sharedInstance : ( sharedInstance = [[self alloc] init] ) );
}
// get screen coords and use them as the default coords
// initWithFrame: is designated initializer
-(id)init{
struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
rect.origin.x = rect.origin.y = 0.0f;
return [self initWithFrame:rect];
}
// designated initializer
-(id)initWithFrame:(CGRect) rect{
self = [super initWithFrame: rect];
sharedInstance = self;
NSLog(@"Starting");
/* Create the Preferences Table, it holds all the controls on the preferences page */
pref = [[UIPreferencesTable alloc] initWithFrame: CGRectMake(0.0f, 48.0f, 320.0f, 480.0f-48.0f)];
/* Tell the preferences table to get its data from this class */
[pref setDataSource: self];
/* Tell the preferences table to send events to this class */
[pref setDelegate: self];
/* Necessary variables for setting up preferences table */
CGRect controlPos = CGRectMake(0.0f, 0.0f, 320.0f, 45.0f);
NSFileManager *fileManager = [NSFileManager defaultManager];
/* Create header cell*/
netServicesHeader = [[UIPreferencesTableCell alloc] init];
[netServicesHeader _setDrawAsLabel: YES];
[netServicesHeader setDrawsBackground: YES];
[netServicesHeader setTitle:@"Tap Label to Change Set Visibility"];
[netServicesHeader setShowSelection: NO];
/* Holds the services that are listed under the Network Services group */
netServices2 = [[[NSMutableArray alloc] init] retain];
ServiceTableCell2 *cell;
/* Initialize the Edge Service Control */
cell = [[EDGEServiceTableCell2 alloc] initWithFrame: controlPos];
/* Add this to the array of services */
[netServices2 addObject:cell];
/* Initialize the Bluetooth Control */
cell = [[BluetoothServiceTableCell2 alloc] initWithFrame: controlPos];
/* Add this to the array of services */
[netServices2 addObject:cell];
/* Initialize the Wifi Control */
cell = [[WifiServiceTableCell2 alloc] initWithFrame: controlPos];
/* Add this to the array of services */
[netServices2 addObject:cell];
/* Initialize the Airport Control */
cell = [[PhoneServiceTableCell2 alloc] initWithFrame: controlPos];
/* Add this to the array of services */
[netServices2 addObject:cell];
/* Initialize the OpenSSH Control */
/* Add this to the array of services, only if the opensshd daemon exists */
if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/com.openssh.sshd.plist"]) {
cell = [[SSHServiceTableCell2 alloc] initWithFrame: controlPos];
[netServices2 addObject:cell];
}
/* Initialize the Dropbear SSH Control */
cell = nil;
NSString *dropbear = @"/System/Library/LaunchDaemons/au.asn.ucc.matt.dropbear.plist";
if ([fileManager fileExistsAtPath:dropbear]) {
cell = [[SSHServiceTableCell2 alloc] initWithFrame: controlPos];
} else if ([fileManager fileExistsAtPath:(dropbear = @"/Library/LaunchDaemons/au.asn.ucc.matt.dropbear.plist")]) {
cell = [[SSHServiceTableCell2 alloc] initWithFrame: controlPos];
}
/* Add this to the array of services, only if the sshd daemon exists */
if (cell != nil) {
[netServices2 addObject:cell];
}
/* Initialize the AFP Control */
/* Add this to the array of services, only if the AFP daemon exists */
if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/com.core.afp.plist"]) {
cell = [[AFPServiceTableCell2 alloc] initWithFrame: controlPos];
[netServices2 addObject:cell];
}
/* Initialize the Samba Control */
/* Add this to the array of services, only if the Samba daemon exists */
if ([fileManager fileExistsAtPath:@"/usr/local/samba/smbd"]) {
cell = [[SambaServiceTableCell2 alloc] initWithFrame: controlPos];
[netServices2 addObject:cell];
}
/* Initialize the FireFly Control */
/* Add this to the array of services, only if the Firefly daemon exists */
if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/org.fireflymediaserver.mt-daapd.plist"]) {
cell = [[FireflyServiceTableCell2 alloc] initWithFrame: controlPos];
[netServices2 addObject:cell];
}
/* Initialize the Apache Control */
/* Add this to the array of services, only if the Apache daemon exists */
if ([fileManager fileExistsAtPath:@"/System/Library/LaunchDaemons/org.apache.httpd.plist"]) {
cell = [[ApacheServiceTableCell2 alloc] initWithFrame: controlPos];
[netServices2 addObject:cell];
}
/* Initialize the Lighttpd Control */
/* Add this to the array of services, only if the Lighttpd daemon exists */
if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/com.amcgregor.lighttpd.plist"]) {
cell = [[LighttpdServiceTableCell2 alloc] initWithFrame: controlPos];
[netServices2 addObject:cell];
}
/* Initialize the Socks Server Control */
/* Add this to the array of services, only if the Socks Server daemon exists */
if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/net.sourceforge.socks-relay.srelay.plist"]) {
cell = [[SocksServiceTableCell2 alloc] initWithFrame: controlPos];
[netServices2 addObject:cell];
}
/* Initialize the Tinyproxy Control */
/* Add this to the array of services, only if the Tinyproxy daemon exists */
cell = nil;
NSString *tinyproxy = @"/System/Library/LaunchDaemons/com.wickedpsyched.iphone.tinyproxy.plist";
if ([fileManager fileExistsAtPath:tinyproxy]) {
cell = [[TinyproxyServiceTableCell2 alloc] initWithFrame: controlPos];
} else if ([fileManager fileExistsAtPath:@"/System/Library/LaunchDaemonscom.wickedpsyched.iphone.tinyproxy.plist"]) {
cell = [[TinyproxyServiceTableCell2 alloc] initWithFrame: controlPos];
}
if (cell != nil) {
[netServices2 addObject:cell];
}
/* Initialize the IP Control Add this to the array of services */
cell = [[IPTableCell2 alloc] initWithFrame: controlPos];
[netServices2 addObject:cell];
/* Initialize the Autolock Control Add this to the array of services */
cell = [[AutolockServiceTableCell2 alloc] initWithFrame: controlPos];
[netServices2 addObject:cell];
topBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
[topBar pushNavigationItem: [[UINavigationItem alloc] initWithTitle: @"NetServices"]];
[topBar showButtonsWithLeftTitle:@"Main" rightTitle:nil leftBack:YES];
[topBar enableAnimation];
[topBar setDelegate:self];
/* Create the cells for the about information */
aboutVersion = [[UIPreferencesTableCell alloc] init];
[aboutVersion setTitle:[[NSString alloc] initWithFormat:@"Version %@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]]];
[aboutVersion _setDrawAsLabel: YES];
[aboutVersion setDrawsBackground: NO];
aboutCopyright = [[UIPreferencesTableCell alloc] init];
[aboutCopyright setTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleCopyright"]];
[aboutCopyright _setDrawAsLabel: YES];
[aboutCopyright setDrawsBackground: NO];
/* Populate the Preference table */
[pref reloadData];
[self addSubview:topBar];
[self addSubview:pref];
return self;
}
- (void)reloadData
{
[pref reloadData];
}
- (void)changeLabel:(NSString *)newLabel {
NSDictionary *labelDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/NetServices.app/ProgramFiles/plists/settings.plist"];
NSLog(@"got dict");
NSString *fullLabel = [NSString stringWithFormat:@"Label-%@", newLabel];
NSString *changeButtonLabel = [labelDictionary objectForKey:fullLabel];
NSLog(@"buttonLabel in plist %@", changeButtonLabel);
system([[NSString stringWithFormat:@"/Applications/NetServices.app/ProgramFiles/bin/alert -t 'Switch Label Change' -b \"Change the Label for %@\" -o -F \"%@\" > /Applications/NetServices.app/file", newLabel, changeButtonLabel] UTF8String]);
NSData *labelData = [NSData dataWithContentsOfFile: @"/Applications/NetServices.app/file"];
NSString *changedLabel = [[NSString alloc] initWithData: labelData encoding: NSUTF8StringEncoding];
NSLog (@"got\n%@", changedLabel);
changedLabel = [changedLabel stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n"]];
system([[NSString stringWithFormat:@"/Applications/NetServices.app/ProgramFiles/bin/plutil -s \"%@\" -v \"%@\" /Applications/NetServices.app/ProgramFiles/plists/settings.plist", fullLabel, changedLabel] UTF8String]);
[self reloadData];
}
- (void)tableRowSelected:(NSNotification *)notification {
int rowIndex = [pref selectedRow];
NSLog(@"table=%@", pref);
NSLog(@"selected row %d", rowIndex);
NSString *rowValue = [NSString stringWithFormat:@"%@", [pref cellAtRow:rowIndex column:0]];
NSLog(@"rowValue %@", rowValue);
NSString *rowValue2 = [NSString stringWithFormat:@"%@", [pref cellForRow:rowIndex inGroup:0]];
NSLog(@"rowValue2 %@", rowValue2);
NSString *serviceStringShort = [rowValue substringWithRange:NSMakeRange(1, 4)];
NSLog(@"substring %@", serviceStringShort);
if ([serviceStringShort isEqual:@"AFPS"]){
[self changeLabel:@"AFP"];
}
if ([serviceStringShort isEqual:@"Apac"]){
[self changeLabel:@"Apache"];
}
if ([serviceStringShort isEqual:@"Auto"]){
[self changeLabel:@"Autolock"];
}
if ([serviceStringShort isEqual:@"Blue"]){
[self changeLabel:@"Bluetooth"];
}
if ([serviceStringShort isEqual:@"Drop"]){
[self changeLabel:@"Dropbear"];
}
if ([serviceStringShort isEqual:@"EDGE"]){
[self changeLabel:@"EDGE"];
}
if ([serviceStringShort isEqual:@"File"]){
[self changeLabel:@"Fileshare"];
}
if ([serviceStringShort isEqual:@"Fire"]){
[self changeLabel:@"Firefly"];
}
if ([serviceStringShort isEqual:@"IPTa"]){
[self changeLabel:@"IP"];
}
if ([serviceStringShort isEqual:@"Ligh"]){
[self changeLabel:@"Lighttpd"];
}
if ([serviceStringShort isEqual:@"Phon"]){
[self changeLabel:@"Airplane"];
}
if ([serviceStringShort isEqual:@"SSHS"]){
[self changeLabel:@"SSH"];
}
if ([serviceStringShort isEqual:@"Samb"]){
[self changeLabel:@"Samba"];
}
if ([serviceStringShort isEqual:@"Sock"]){
[self changeLabel:@"Socks"];
}
if ([serviceStringShort isEqual:@"Tiny"]){
[self changeLabel:@"Tiny"];
}
if ([serviceStringShort isEqual:@"Wifi"]){
[self changeLabel:@"Wifi"];
}
}
/**
* Called by the preference table to determine how many separate groups there are
**/
- (int)numberOfGroupsInPreferencesTable:(UIPreferencesTable *)aTable {
return GROUPS;
}
/**
* Called by the preference table to setup how many unique rows are in each group
**/
- (int)preferencesTable:(UIPreferencesTable *)aTable numberOfRowsInGroup:(int)group {
switch (group) {
case 0:
return 1;
case 1:
return [netServices2 count];
case 2:
return 2;
}
}
- (UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)aTable cellForGroup:(int)group {
if (groupcell2[group] == NULL) {
groupcell2[group] = [[UIPreferencesTableCell alloc] init];
}
return groupcell2[group];
}
- (float)preferencesTable:(UIPreferencesTable *)aTable heightForRow:(int)row inGroup:(int)group withProposedHeight:(float)proposed {
switch (group) {
case 0:
return 0.7*proposed;
case 1:
return proposed;
case 2:
return 0.5*proposed;
default:
return 2*proposed;
}
}
- (BOOL)preferencesTable:(UIPreferencesTable *)aTable isLabelGroup:(int)group {
return NO;
}
- (UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)aTable cellForRow:(int)row inGroup:(int)group {
switch(group) {
case 0:
return netServicesHeader;
case 1:
return [netServices2 objectAtIndex:row];
case 2:
switch(row) {
case 0:
return aboutVersion;
case 1:
return aboutCopyright;
}
}
}
-(void)navigationBar:(UINavigationBar*)bar buttonClicked:(int)button{
NSLog(@"navbar clicked bar:%@ button:%i", bar, button);
if (button == 0){
[[UITransitionApplication sharedInstance] showView:[OneView sharedInstance]];
}
if (button == 1){
[[UITransitionApplication sharedInstance] showView:[OneView sharedInstance]];
}
}
- (void)applicationWillTerminate {
[netServicesHeader release];
[aboutVersion release];
[aboutCopyright release];
for (int i = 0; i < GROUPS; i++)
[groupcell2[i] release];
for(int i = 0; i < [netServices2 count]; i++) {
[[netServices2 objectAtIndex:i] release];
[[netServices2 objectAtIndex:i] release];
//if ([[netServices objectAtIndex:i] class] == [EDGEServiceTableCell2 class]) {
// NSLog(@"Retain count (%d) of %@ %d", [[netServices objectAtIndex:i] retainCount], [netServices objectAtIndex: i], [netServices retainCount]);
//}
}
[netServices2 release];
}
@end