[ Source Code ] ~ gLauncher

Discussion in 'iOS Development' started by gojohnnyboi, Jul 27, 2008.

  1. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Here is the source for my recently released launcher for 2.0 "gLauncher". Yes, this code is a little sloppy as a had to make tons and tons of modifications. This was a learning experience for me, mostly using arrays and enumerators, and i hope you benefit from it as well.

    main.m
    Code:
    #import <UIKit/UIKit.h>
    #import "AppLauncher.h"
    
    int main(int argc, char *argv[])
    {
    	NSAutoreleasePool* pool = [ [ NSAutoreleasePool alloc ] init ];
    	int appReturn = UIApplicationMain(argc, argv, @"AppLauncher", @"AppLauncher");
    	return appReturn;
    	[ pool release ];
    }
    AppLauncher.h
    Code:
    #import "ApplicationList.h"
    
    @interface AppLauncher : UIApplication
    {
    	CGRect rect;
    	UIWindow* window;
    	UIView* mainView;
    	UINavigationBar* navBar;
    	ApplicationList* appList;
    }
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
    - (void)dealloc;
    
    @end
    AppLauncher.m
    Code:
    #import "AppLauncher.h"
    
    @implementation AppLauncher
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
    	rect = [ UIHardware fullScreenApplicationContentRect ];
    	rect.origin.x = 0.0f;
    	rect.origin.y = 0.0f;
    	
    	window = [ [ UIWindow alloc ] initWithContentRect: rect ];
    	[ window makeKeyAndVisible ];
    	
    	mainView = [ [ UIView alloc ] initWithFrame: rect ];
    	[ window setContentView: mainView ];
    	
    	navBar = [ [ UINavigationBar alloc ] initWithFrame: CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, 45.0f) ];
    	[ navBar pushNavigationItem: [ [ UINavigationItem alloc ] initWithTitle:@"gLauncher" ] ];
    	[ navBar showLeftButton:nil withStyle:nil rightButton:@"About" withStyle: 0 ];
    	[ navBar setDelegate: self ];
    	[ mainView addSubview: navBar ];
    	
    	appList = [ [ ApplicationList alloc ] initWithFrame: CGRectMake(rect.origin.x, rect.origin.y + [ navBar bounds ].size.height, rect.size.width, rect.size.height - [ navBar bounds ].size.height) ];
    	[ appList reloadData ];
    	[ mainView addSubview: appList ];
    }
    
    
    - (void)dealloc
    {
    	[ window release ];
    	[ mainView release ];
    	[ navBar release ];
    	[ appList release ];
    	[ super dealloc ];
    }
    
    - (void)navigationBar:(UINavigationBar*)bar buttonClicked:(int)button
    {
    	UIAlertSheet *sheet = [ [ UIAlertSheet alloc ] init ];
    	[ sheet setTitle: @"About" ];
    	[ sheet setBodyText:@"gLauncher v1.0\n\nBy Gojohnnnyboi\nUpdates coming soon!" ];
    	[ sheet setDelegate: self ];
    	[ sheet addButtonWithTitle:@"OK" ];
    	[ sheet popupAlertAnimated: YES ];
    }
    
    - (void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(int)button
    {
    	[ sheet dismiss ];
    }
    
    
    @end
    ApplicationList.h
    Code:
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <UIKit/UITable.h>
    #import <UIKit/UIImageAndTextTableCell.h>
    #import <UIKit/UITableColumn.h>
    
    @interface ApplicationList : UITable
    {
    	NSFileManager* appManager;
    	NSArray* appArray;
    	NSMutableArray* infoArray;
    }
    
    - (id)initWithFrame:(CGRect)rect;
    - (void)dealloc;
    
    @end
    ApplicationList.m
    Code:
    #import "ApplicationList.h"
    #import <UIKit2/UIColor.h>
    #import <WebCore/WebFontCache.h>
    #import <GraphicsServices/GraphicsServices.h>
    
    @implementation ApplicationList 
    
    - (id)initWithFrame:(CGRect)rect
    {
    	if(( self == [ super initWithFrame: rect ]) != nil)
    		{
    			appManager = [ NSFileManager defaultManager ];
    			appArray = [ [ NSArray alloc ] initWithArray: [ appManager directoryContentsAtPath:@"/Applications" ] ];
    			infoArray = [ [ NSMutableArray alloc ] initWithCapacity: [ appArray count ] ];
    
    			int i;
    			
    			for(i = 0; i < [ appArray count ]; i++)
    				{
    					NSDictionary* dict = [ [ NSDictionary alloc ] initWithContentsOfFile: [ NSString stringWithFormat:@"/Applications/%@/Info.plist", [ appArray objectAtIndex: i ] ] ];
    					NSString* ID = [ NSString stringWithFormat: @"%@", [ dict objectForKey: @"CFBundleIdentifier" ] ];
    					NSDictionary* currentDict = [ [ NSDictionary alloc ] initWithContentsOfFile:[ [ NSBundle mainBundle ] pathForResource:@"Info" ofType:@"plist" ] ];
    					[ infoArray addObject: [ NSString stringWithFormat: @"%@", [ dict objectForKey: @"CFBundleIdentifier" ] ] ];
    				}
    			
    			UITableColumn* tableColumn = [ [ UITableColumn alloc] initWithTitle:@"Applications" identifier:@"column1" width:rect.size.width ];
    			[ self addTableColumn: tableColumn ];
    			
    			[ self setDelegate: self ];
    			[ self setDataSource: self ];
    			[ self setSeparatorStyle: 1 ];
    			[ self setRowHeight: 70 ];
    		}
    	return self;
    }
    
    - (int)numberOfRowsInTable:(UITable*)table
    {	
    	int i = [ appArray count ];
    	return i;
    }
    
    - (UITableCell *)table:(UITable *)table cellForRow:(int)row column:(int)column
    {	 		 
    	UIImageAndTextTableCell* cell = [ [ UIImageAndTextTableCell alloc ] init ];
    	NSString* title = [ NSString stringWithFormat: @"%@", [ appArray objectAtIndex: row ] ];
    	[ cell setTitle: [ title substringToIndex: [ title length ] - 4 ] ]; //[ appArray objectAtIndex: row ]];
    	bool regularIcon = [ appManager fileExistsAtPath: [ NSString stringWithFormat:@"/Applications/%@/icon.png", [ appArray objectAtIndex: row ] ] ];
    	bool regularIconCaps = [ appManager fileExistsAtPath: [ NSString stringWithFormat:@"/Applications/%@/Icon.png", [ appArray objectAtIndex: row ] ] ];
    	bool photosIcon = [ appManager fileExistsAtPath: [ NSString stringWithFormat:@"/Applications/%@/icon-Photos.png", [ appArray objectAtIndex: row ] ] ];
    	NSString* bundleIcon = [ [ [ NSMutableDictionary alloc ] initWithContentsOfFile:@"/Applications/%@/Info.plist" ] objectForKey:@"CFBundleIcon" ];
    	
    	if(regularIcon)
    		{
    			[ cell setImage: [ UIImage imageAtPath: [ NSString stringWithFormat:@"/Applications/%@/icon.png", [ appArray objectAtIndex: row ] ] ] ];	
    		}
    	else if(regularIconCaps)
    		{
    			[ cell setImage: [ UIImage imageAtPath: [ NSString stringWithFormat:@"/Applications/%@/Icon.png", [ appArray objectAtIndex: row ] ] ] ];	
    		}
    	else if(photosIcon)
    		{
    			[ cell setImage: [ UIImage imageAtPath: [ NSString stringWithFormat:@"/Applications/%@/icon-Photos.png", [ appArray objectAtIndex: row ] ] ] ];	
    		}
    	else if(bundleIcon != nil)
    		{
    			[ cell setImage: [ UIImage imageAtPath: [ NSString stringWithFormat: @"/Applications/%@/%@", [ appArray objectAtIndex: row ], bundleIcon ] ] ];
    		}
    	else if(regularIcon == FALSE && bundleIcon == nil)
    		{
    			[ cell setImage: [ UIImage applicationImageNamed: @"MissingIcon.png" ] ];		
    		}
    	
    	struct __GSFont *font = [NSClassFromString(@"WebFontCache") createFontWithFamily:@"Helvetica" traits:2 size:12]; 
    	UITextLabel* label = [ [ UITextLabel alloc ] initWithFrame: CGRectMake(100.0f, 45.0f, 250.0f, 15.0f) ];
    	[ label setFont: font ];
    	NSDictionary* bundle = [ [ NSDictionary alloc ] initWithContentsOfFile: [ NSString stringWithFormat: @"/Applications/%@/Info.plist", [ appArray objectAtIndex: row ] ] ];
    	[ label setText: [ NSString stringWithFormat:@"%@", [ bundle objectForKey:@"CFBundleIdentifier" ] ] ];
    	[ label setColor: [ UIColor grayColor ] ];
    	[ label setBackgroundColor: [ UIColor clearColor ] ];
    	[ cell addSubview: label ];
    
    	
    	return cell;
    }
    
    - (void)dealloc
    {
    	[ appManager release ];
    	[ appArray release ];
    	[ infoArray release ];
    	[ super dealloc ];
    }
    
    - (void)tableRowSelected:(NSNotification*)notification
    {
    	[[[notification object]cellAtRow:[[notification object]selectedRow]column:0] setSelected:FALSE withFade:TRUE];
    	[ UIApp launchApplicationWithIdentifier: [ infoArray objectAtIndex: [ self selectedRow ] ] suspended: NO ];
    }
    
    @end
    Makefile
    Code:
    CC=arm-apple-darwin9-gcc
    LD=$(CC)
    LDFLAGS =	-framework Foundation \
    				-framework UIKit \
    				-framework CoreFoundation \
    				-framework CoreGraphics \
    				-lobjc \
    				-L"/usr/lib" \
    				-F"/System/Library/Frameworks" \
    				-F"/System/Library/PrivateFrameworks" \
    				-bind_at_load
    CFLAGS=-I/var/include
    
    TARGET=gLauncher
    
    all:	$(TARGET)
    
    $(TARGET): main.o AppLauncher.o ApplicationList.o
    	$(LD) $(LDFLAGS) -o $@ $^
    			ldid -S $(TARGET)
    			chmod 0755 $(TARGET)
    
    %.o:	%.m
    	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
    
    clean:	
    	rm -fr *.o $(TARGET)
    
    
    ]

    Post any questions about it here.
  2. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    Ya I have a question -

    Why didn't you post the files so that you actually compile the app?

    Without them the src is completely useless =(
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    the sdk headers are under NDA or whatever, so yeah, its illegal. get them from a source of your own, patch them for toolchain use, and place them under UIKit2. you also need to replace WebFontCache.h if you're on iphone-gcc
  4. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    Is this objective-c 2.0? Or is this made for the compiler from cydia?
  5. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    objective-c is objective-c. and yes, this will work with the iphone-gcc compiler, if you've made the modifications above.
  6. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    I tried compiling this with the iphone-gcc and it came up with an error.
    Code:
    arm-apple-darwin9-gcc -c -I/var/include main.m -o main.o
    /var/tmp//ccxgHScf.s:unknown:FATAL:can't create output file main.o
    make: *** [main.o] Error 1
    
    I don't know where the problem is.
  7. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    • Flaming and/or trolling
    Gojohnnyboi wrote it.
    Stephen - 1
    Johnny - 0
  8. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    LOL. It took me a while to actually get what you meant. But seriously idk why I'm getting this error.
  9. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    • Flaming and/or trolling
    suck my balls douchebag its not him, its his compiler.
    me - 2
    stephen - 0

    what i said above. your compiler is most likely broken. reinstall it from cydia, and try once more. report any more problems and i'll do my best to help ya

    Please Register or Log in to view images

  10. 48days

    48days Active Member

    Joined:
    Mar 6, 2008
    Messages:
    1,883
    Likes Received:
    4
    Device:
    iPhone 3G (Black)
    Can you explain the difference between gLauncher and Launcher?

Share This Page