[Source Code] PowerTool.app

Discussion in 'iOS Development' started by gojohnnyboi, Apr 28, 2008.

  1. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Ok, this application consists of a prefs table and come cells, i wont explain anything really, im just posting the source code for those who wish to have it.



    main.m
    Code:
    #import <UIKit/UIKit.h>
    
    #import "PowerTool.h"
    
    int main(int argc, char **argv)
    {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        return UIApplicationMain(argc, argv, [PowerTool class]);
    }
    
    
    PowerTool.h
    Code:
    #import <CoreFoundation/CoreFoundation.h>
    #import <Foundation/Foundation.h>
    #import <UIKit/UIApplication.h>
    #import <UIKit/UIKit.h>
    #import <LayerKit/LayerKit.h>
    #import <UIKit/UINavigationItem.h>
    #import <UIKit/UIPushButton.h>
    #import <UIKit/UIAlertSheet.h>
    #import <UIKit/UINavigationBar.h>
    #import <UIKit/UIButtonBar.h>
    #import <UIKit/UIPreferencesTable.h>
    #import <UIKit/UIPreferencesTableCell.h>
    #import <UIKit/UIPushButton.h>
    #import <UIKit/UIButtonBar.h>
    #import <UIKit/UIPreferencesTextTableCell.h>
    #import <UIKit/UITransitionView.h>
    #import <UIKit/UIPreferencesControlTableCell.h>
    #import <UIKit/UIControl.h>
    #import <UIKit/UIProgressHUD.h>
    #import <UIKit/UIProgressBar.h>
    #import <UIKit/UIImageView.h>
    #import <UIKit/UIImage.h>
    #import <UIKit/UISliderControl.h>
    #import <UIKit/UISwitchControl.h>
    #import <UIKit/UITextField.h>
    #import <UIKit/UITextView.h>
    #import <UIKit/UIFontChooser.h>
    #import <UIKit/UISectionList.h>
    #import <UIKit/UITable.h>
    #import <UIKit/UIView-Hierarchy.h>
    #import <UIKit/UIView-UIImageViewImplementation.h>
    #import <UIKit/UIAnimator.h>
    #import <Foundation/Foundation.h>
    #import <LayerKit/LayerKit.h>
    #import <notify.h>
    
    @interface PowerTool : UIApplication
    {
    	UIWindow* window;
    	struct CGRect rect;
    	UIView* mainView;
    	UINavigationBar* navBar;
    	UINavigationItem* navBarTitle;
    	UIAlertSheet* otherSheet;
    	UIPreferencesTable* prefsTable;
    	UIPreferencesTableCell* _cell1;
    	UIPreferencesTableCell* _cell2;
    	UIPreferencesTableCell* _cell3;
    	UIPreferencesTableCell* _cell4;
    	UIPreferencesTableCell* _cell5;
    	UIPreferencesTableCell* _cell6;
    	UIPreferencesTableCell* _cell7;
    	UIPreferencesTableCell* _cell8;
    	UIPreferencesTableCell* _cell9;
    	UIPreferencesTableCell* _cell10;
    	UIPreferencesTableCell* _cell11;
    	UIPreferencesTableCell* _cell12;
    	UIPreferencesTableCell* _cell13;
    	UIPreferencesTableCell* _cell14;
    	UIPreferencesTableCell* _cell15;
    	UIPreferencesTableCell* _cell16;
    	UIPreferencesTableCell* _cell17;
    	UIPreferencesTableCell* _cell18;
    	UIPreferencesTableCell* _cell19;
    	UIPreferencesTableCell* _cell20;
    	UIPreferencesTableCell* _cell21;
    	UIPreferencesTableCell* _cell22;
    	UIPreferencesTableCell* _cell23;
    	UIPreferencesTableCell* _cell24;
    	UIPreferencesTableCell* _cell25;
    	UIPreferencesTableCell* _cell26;
    	UIPreferencesTableCell* _cell27;
    	UIPreferencesTableCell* _cell28;
    	UIPreferencesTableCell* _cell29;
    	UIPreferencesTableCell* _cell30;
    	UIPreferencesTableCell* _cell31;
    	UIPreferencesTableCell* _cell32;
    	UIPreferencesTableCell* _cell33;
    	UIPreferencesTableCell* _cell34;
    	UIPreferencesTableCell* _cell35;
    	UIPreferencesTableCell* _cell36;
    	UIPreferencesTableCell* _cell37;
    	UIPreferencesTableCell* _cell38;
    	UIPreferencesTableCell* _cell39;
    	UIPreferencesTableCell* _cell40;
    	UIPreferencesTableCell* _cell41;
    	UIPreferencesTableCell* _cell42;
    	UIPreferencesTableCell* _cell43;
    	UIPreferencesTableCell* _cell44;
    	UIPreferencesTableCell* _cell45;
    }
    
    - (void)setLanguageRespring;
    - (void)rebootDevice;
    - (void)respringDevice;
    
    
    @end
    
    PowerTool.m
    Code:
    #import "PowerTool.h"
    
    @implementation PowerTool
    
    - (void) applicationDidFinishLaunching: (id) unused
    {
    
            rect = [UIHardware fullScreenApplicationContentRect];        
            rect.origin.x = rect.origin.y = 0.0f;
             
    	window = [[UIWindow alloc] initWithFrame: rect];
    	[window makeKey: self];
    	[window orderFront: self];
    	[window _setHidden: false];
             
    	mainView = [[[UIView alloc] initWithFrame:rect] autorelease];
    	[window setContentView: mainView];
    
    	navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 20.0f, 320.0f, 45.0f)];
    	[navBar setBarStyle: 0];
    	navBarTitle = [[UINavigationItem alloc] initWithTitle:@"PowerTool"];
    	[navBar pushNavigationItem: navBarTitle];
    	[mainView addSubview: navBar];
    
    	prefsTable = [[UIPreferencesTable alloc] initWithFrame:CGRectMake(0.0f, 65.0f, 320.0f, 415.0f)];
    	[prefsTable setDataSource:self];
    	[prefsTable setDelegate:self];
    	[mainView addSubview: prefsTable];
    	[prefsTable reloadData];
    }
    
    
    /* ------------FUNCTIONS FOR APPLICATION ( REBOOT - RESPRING - SETLANGUAGE ) These are in the header file---------------- */	
    
    - (void)setLanguageRespring
    {
    	notify_post("com.apple.language.changed");
    }
    
    
    - (void)respringDevice
    {
    	system("launchctl stop com.apple.SpringBoard");
    }
    
    
    - (void)rebootDevice
    {
    	notify_post("com.apple.mobile.nikita_uninstalled");
    }
    	
    
    
    
    
    /* ----------------------DELEGATE METHODS FOR THE PREFSTABLE (THE CELLS, THEIR FUNCTIONS, ETC) ------------------- */
    
    
    - (void)reloadData
    {
    	[prefsTable reloadData];
    }
    
    
    - (int)numberOfGroupsInPreferencesTable:(UIPreferencesTable *)table
    {
    	return 3;
    }
    
    
    - (int)preferencesTable:(UIPreferencesTable *)table numberOfRowsInGroup:(int)group
    {
    	switch(group) {
    	case 0: return 2;
    	case 1: return 1;
    	case 2: return 0;
    	}
    }
    
    
    - (UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)table cellForGroup:(int)group
    {
        switch(group) {
    	case 0: {
    		_cell1 = [[UIPreferencesTableCell alloc] init];
    		[_cell1 setTitle:@"Re-Spring"];
    	       return [_cell1 autorelease];
    	       break;
    	}
    	case 1: {
    		_cell2 = [[UIPreferencesTableCell alloc] init];
    		[_cell2 setTitle:@"Reboot"];
    	       return [_cell2 autorelease];
    	       break;
    	}
    	case 2: {
    		_cell4 = [[UIPreferencesTableCell alloc] init];
    		[_cell4 setTitle:@"Made By: Gojohnnyboi"];
    		[_cell4 _setDrawAsLabel: YES];
    		[_cell4 setDrawsBackground: NO];
    	       return [_cell4 autorelease];
    	       break;
    	}
        }
    }
    
    
    
    - (UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)table cellForRow:(int)row inGroup:(int)group
    {
         if(group == 0) {
              switch  (row) {
                  case 0: {
                     _cell5 = [[UIPreferencesTableCell alloc] init];
                     [_cell5 setTitle:@"Set Language"];
                     return [_cell5 autorelease];
                     break;
                 }  
                 case 1: {
                     _cell6 = [[UIPreferencesTableCell alloc] init];
                     [_cell6 setTitle:@"Restart SpringBoard"];
                     return [_cell6 autorelease];
                     break;
                 }
             }
         }
         else if(group == 1) {
              switch  (row) {
                  case 0: {
                     _cell7 = [[UIPreferencesTableCell alloc] init];
    		[_cell7 setTitle:@"Reboot"];
                     return [_cell7 autorelease];
                     break;
                 }   
             }
         }
         else if(group == 2) {
              switch  (row) {
                  case 0: {
                     _cell10 = [[UIPreferencesTableCell alloc] init];
                     return [_cell10 autorelease];
                     break;
                 }  
             }
         }
    }
    
    
    - (float) preferencesTable: (UIPreferencesTable*)table heightForRow: (int)row inGroup: (int)group withProposedHeight: (float)proposed  {
    	switch(group) {
    	case 0: return 45.0f; break;
    	case 1: return 45.0f; break;
    	case 2: return proposed; break;
    	default: return proposed;
    	}
    }
    
    
    
    - (void)tableRowSelected:(NSNotification *)notification
    {
    	switch ([prefsTable selectedRow]) {
    	case 1: [_cell5 setSelected:NO withFade:YES]; 	
    		[self setLanguageRespring];
    		break;
    	case 2: [_cell6 setSelected:NO withFade:YES];
    		[self respringDevice];
    		break;
    	case 4: [_cell7 setSelected:NO withFade:YES]; 	
    		[self rebootDevice];
    		break;	
             }
    }
    
    
    
    @end
    
    makefile
    Code:
    CC=arm-apple-darwin-gcc
    LD=$(CC)
    LDFLAGS=-lobjc -framework CoreFoundation -framework Foundation -framework UIKit -framework CoreGraphics
    
    all: PowerTool
    
    PowerTool:	main.o PowerTool.o 
    	$(LD) $(LDFLAGS) -o $@ $^
    
    
    %.o:	%.m
    		$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
    
    clean:
    		rm -f *.o PowerTool
    
    	
    	
    

    There u go. Some stuff like the extra cells and headers arent needed thats just all that i include in all my apps so i never have to worry about it.

    Have fun,
    Gojohnnyboi
    1 person likes this.
  2. Aristarchos

    Aristarchos Banned

    Joined:
    Feb 8, 2008
    Messages:
    520
    Likes Received:
    26
    thanks this will help me understand the programming language a little bit more
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55

    yup. np. have fun. nice sig lol
  4. Aristarchos

    Aristarchos Banned

    Joined:
    Feb 8, 2008
    Messages:
    520
    Likes Received:
    26
    haha thanks
  5. Chucky102

    Chucky102 Well-Known Member

    Joined:
    Nov 23, 2007
    Messages:
    3,555
    Likes Received:
    66
    Device:
    iPhone 5 (Black)
    thanks for sharing.
  6. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55

    yup. any questions just post or pm
  7. Chucky102

    Chucky102 Well-Known Member

    Joined:
    Nov 23, 2007
    Messages:
    3,555
    Likes Received:
    66
    Device:
    iPhone 5 (Black)
    sure

    Please Register or Log in to view images

    but I'm OK for now
  8. Ezra

    Ezra Well-Known Member

    Joined:
    Feb 23, 2008
    Messages:
    1,122
    Likes Received:
    41
    Device:
    iPhone
    What program would you use (on windows) to make (compile) an application in Objective C?
  9. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55


    I simply wrote and saved the code with notepad, and compiled with cygwin binary toolchain.

    search google for iphonegameover cygwin binary toolchain and theres a guide on it.


    Then, in cygwin( a terminal emulator for windows), change the directory to the one of your app, and type make. If your code and makefile are correct, the application will compile
  10. hockeypanda32

    hockeypanda32 Well-Known Member

    Joined:
    Dec 18, 2007
    Messages:
    2,183
    Likes Received:
    89
    Device:
    iPhone 4 (Black)
    Is there a version of Cygwin for Mac, the Toolchain is really bugging me with what I got now!

Share This Page