This repository has been archived on 2018-06-04. You can view files and clone it, but cannot push or open issues/pull-requests.
iMoodUpdater/OSX/iMoodUpdater.m

127 lines
4.2 KiB
Objective-C

#import "iMoodUpdater.h"
#import "XMLTree.h"
#include <unistd.h>
#define preferences [NSUserDefaults standardUserDefaults]
@implementation iMoodUpdater
- (IBAction)iMoodUpdater:(id)sender
{
// Put data from app into usable variables
int iFace = [face selectedTag];
NSString *lMood = @"happy";
char *crypt();
char passwd[256];
char salt[3];
char rndChar[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./";
// Setup the salt for crypt()
srandom(time(0));
salt[0] = rndChar[random() %64];
salt[1] = rndChar[random() &64];
salt[3] = 0;
if ([[preferences stringForKey:@"Advanced"] compare:@"1"])
{
lMood = [moodList titleOfSelectedItem];
}
else
{
lMood = [moodTextList stringValue];
}
// Setup the URL to goto to update the mood for given user.
NSString *tempURL = @"http://xml.imood.org/update.cgi?email=";
tempURL = [tempURL stringByAppendingString:[preferences stringForKey:@"UserID"]];
tempURL = [tempURL stringByAppendingString:@"&crypt=1"];
tempURL = [tempURL stringByAppendingString:@"&password="];
// Crypt the password
[[preferences stringForKey:@"Password"] getCString:passwd];
tempURL = [tempURL stringByAppendingString:[NSString stringWithFormat:@"%s",crypt(passwd, salt)]];
tempURL = [tempURL stringByAppendingString:@"&base="];
tempURL = [tempURL stringByAppendingString:lMood];
tempURL = [tempURL stringByAppendingString:@"&face="];
tempURL = [tempURL stringByAppendingFormat:@"%d",iFace];
tempURL = [tempURL stringByAppendingString:@"&personal="];
tempURL = [tempURL stringByAppendingString:[pMood stringValue]];
tempURL = (NSString *) CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)tempURL,NULL, NULL,kCFStringEncodingUTF8);
[tempURL retain];
//NSLog(tempURL);
XMLTree *errorXML = [[[XMLTree alloc] initWithURL:[NSURL URLWithString:tempURL]] retain];
NSString *errorMsg = [NSString stringWithFormat: @"%@", [errorXML descendentNamed:@"error"]];
NSRunAlertPanel(@"iMood Updater",errorMsg,@"OK",NULL,NULL);
}
- (void)awakeFromNib
{
if ([preferences stringForKey:@"UserID"] == nil)
{
[preferences setObject:@"" forKey:@"UserID"];
[preferences setObject:@"" forKey:@"Password"];
NSRunAlertPanel(@"No Account Info Found",@"Please go into preferences and set your account info.",@"OK", NULL, NULL);
}
else
{
[userID setStringValue:[preferences stringForKey:@"UserID"]];
[pass setStringValue:[preferences stringForKey:@"Password"]];
if ([preferences stringForKey:@"Advanced"] == nil)
{
[preferences setObject:[adv stringValue] forKey:@"Advanced"];
}
else
{
[adv setStringValue:[preferences stringForKey:@"Advanced"]];
}
}
if ([[preferences stringForKey:@"Advanced"] compare:@"1"])
{
NSDictionary *moodsDict = [NSDictionary dictionaryWithContentsOfURL:
[NSURL URLWithString:@"http://dev.sdf1.net/moods.xml"]];
NSArray *moods = [moodsDict valueForKey:@"Moods"];
NSLog(@"Number of moods found in XML: %d",[moods count]);
[moodTextList removeFromSuperview];
[moodList addItemsWithTitles:moods];
[moodList removeItemAtIndex:0];
[moodList selectItemAtIndex:0];
}
else
{
[moodList removeFromSuperview];
}
[[mood window] makeKeyAndOrderFront:self];
[moodTextList selectText:self];
[userID selectText:self];
}
- (void)setMoodPrefs:(id)sender;
{
[preferences setObject:[userID stringValue] forKey:@"UserID"];
[preferences setObject:[pass stringValue] forKey:@"Password"];
[preferences setObject:[adv stringValue] forKey:@"Advanced"];
[[userID window] performClose:self];
}
- (void)goiMoodURL:(id)sender;
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://my.imood.com"]];
}
- (void)goDEVSDF1:(id)sender;
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://dev.sdf1.net"]];
}
- (void)goDonate:(id)sender;
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://dev.sdf1.net/donate.html"]];
}
@end