Skip to content

Commit

Permalink
It works! But without the Settings :(
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Ulrich committed Jul 1, 2009
1 parent cec6956 commit 791e5fe
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 51 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LD=$(CC)

LDFLAGS += -framework CoreFoundation
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework CoreGraphics
LDFLAGS += -framework AddressBookUI
LDFLAGS += -framework AddressBook
//LDFLAGS += -framework UIKit
//LDFLAGS += -framework CoreGraphics
//LDFLAGS += -framework AddressBookUI
//LDFLAGS += -framework AddressBook
//LDFLAGS += -framework QuartzCore
//LDFLAGS += -framework GraphicsServices
//LDFLAGS += -framework CoreSurface
Expand All @@ -26,11 +26,14 @@ LDFLAGS += -framework AddressBook
//LDFLAGS += -framework OpenGLES
//LDFLAGS += -framework OpenAL

LDFLAGS += -lsqlite3

LDFLAGS += -L"$(SDK)/usr/lib"
LDFLAGS += -F"$(SDK)/System/Library/Frameworks"
LDFLAGS += -F"$(SDK)/System/Library/PrivateFrameworks"

# Make a bundle
# Comment this out to make a runnable executable
LDFLAGS += -bundle


Expand Down Expand Up @@ -64,6 +67,7 @@ install: ThingsPlugin ThingsPlugin.bundle
cp Info.plist $(BUNDLE)/
cp plugin.css $(BUNDLE)/
cp things.png $(BUNDLE)/
cp Preferences.plist $(BUNDLE)/
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate; ./ldid_intel -S ThingsPlugin
cp ThingsPlugin $(BUNDLE)/

Expand Down
84 changes: 50 additions & 34 deletions Preferences.plist
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
<plist>
<dict>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>com.ashman.lockinfo.MailPlugin</string>
<key>key</key>
<string>Enabled</string>
<key>label</key>
<string>Enabled</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
</dict>
<dict>
<key>cell</key>
<string>PSLinkCell</string>
<key>label</key>
<string>Accounts</string>
<key>detail</key>
<string>MailPluginController</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
</dict>
</array>
<array>
<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>cx.ath.the-kenny.ThingsPlugin</string>
<key>key</key>
<string>Enabled</string>
<key>label</key>
<string>Enabled</string>
</dict>
<dict>
<key>cell</key>
<string>PSLinkListCell</string>
<key>default</key>
<integer>3</integer>
<key>defaults</key>
<string>cx.ath.the-kenny.ThingsPlugin</string>
<key>detail</key>
<string>PSListItemsController</string>
<key>key</key>
<string>Limit</string>
<key>label</key>
<string>Limit</string>
<key>validTitles</key>
<array>
<string>1</string>
<string>2</string>
<string>3</string>
<string>5</string>
<string>10</string>
</array>
<key>validValues</key>
<array>
<integer>1</integer>
<integer>2</integer>
<integer>3</integer>
<integer>5</integer>
<integer>10</integer>
</array>
</dict>
</array>
<key>title</key>
<string>Mail</string>
</dict>
<string>Calendar</string>
</dict>
</plist>
103 changes: 90 additions & 13 deletions ThingsPlugin.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#import <Foundation/Foundation.h>
#import <sqlite3.h>

NSString *databasePath = @"/User/Applications/FE652A8B-7E48-4C66-BDFC-8D5D969640AD/Documents/db.sqlite3";

NSString *todaySql = @"select title,dueDate from Task where status = 1 and type = 2 and flagged = 1 limit 3;";

NSString *nextSql = @"select title,dueDate from Task where status = 1 and type = 2 and focus = 2 limit 3;";

NSString *somedaySql = @"select title,dueDate from Task where status = 1 and type = 2 and focus = 16 limit 3;";

NSString *inboxSql = @"select title,dueDate from Task where status = 1 and type = 2 and focus = 1 limit 3;";

@protocol PluginDelegate <NSObject>

// This data dictionary will be converted into JSON by the extension. This method will get called
// any time an application is closed or the badge changes on the bundles in the LIManagedBundles
// setting and when the phone is woken up. It's the responsibility of the plugin to only load the data
// if it needs to.
// any time an application is closed or the badge changes on the bundles in the LIManagedBundles setting and when the phone is woken up. It'
- (NSDictionary*) data;

@optional
Expand All @@ -14,31 +23,99 @@ - (void) setPreferences:(NSDictionary*) prefs;

@end


@interface ThingsPlugin : NSObject <PluginDelegate> {

}

- (NSDictionary*) data;
@end

@implementation ThingsPlugin

+ (void)initialize {
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionary]];

NSLog(@"Initialized!");
}


- (NSDictionary*) readFromDatabase {
sqlite3 *database = NULL;

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

//NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//NSLog(@"%@", [defaults dictionaryRepresentation]);

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
NSMutableArray *todos = [NSMutableArray arrayWithCapacity:4];

//if(sqlite3_open([[defaults stringForKey:@"databasePath"] UTF8String], &database) == SQLITE_OK) {
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

// Setup the SQL Statement and compile it for faster access
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [todaySql UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {

// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
const char *cText = sqlite3_column_text(compiledStatement, 0);
if(cText == NULL)
cText = "";

const char *cDue = sqlite3_column_text(compiledStatement, 1);
if(cDue == NULL)
cDue = "";

NSString *aText = [NSString stringWithUTF8String:cText];
NSString *aDue = [NSString stringWithUTF8String:cDue];

NSDictionary *todoDict = [NSDictionary dictionaryWithObjectsAndKeys:
aText, @"text",
aDue, @"due",
nil];

[todos addObject:todoDict];
}

}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}

sqlite3_close(database);

[dict setObject:todos forKey:@"todos"];
[dict retain];

[pool release];


return [dict autorelease];
}

- (NSDictionary*) data {

NSArray *todos = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
@"Irgendwas kaufen", @"text",
@"01.01.1970", @"due",
nil],
nil];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:todos, @"today", nil];
NSDictionary* dict = [self readFromDatabase];
[dict retain];

return dict;
[pool release];

return [dict autorelease];
}


@end

int main() {
//printf("42");
/*
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ThingsPlugin* p = [[ThingsPlugin alloc] init];
NSLog(@"%@", [p readFromDatabase]);
[pool release];
*/
}

0 comments on commit 791e5fe

Please sign in to comment.