summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-13 12:01:29 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-13 12:01:29 (GMT)
commit17229ead05caae32a0c7c6c7a553442abcb6aede (patch)
tree702931ea04f9131a9ec132afc4a346137c2846e7 /src
parent58ea2b2acf2a959f286ed5ae996b6e6a74206e0d (diff)
downloadpowder-17229ead05caae32a0c7c6c7a553442abcb6aede.zip
powder-17229ead05caae32a0c7c6c7a553442abcb6aede.tar.gz
URI handling for MacOS
Diffstat (limited to 'src')
-rw-r--r--src/SDLMain.m16
-rw-r--r--src/interface.c12
-rw-r--r--src/main.c29
3 files changed, 55 insertions, 2 deletions
diff --git a/src/SDLMain.m b/src/SDLMain.m
index b6216af..3298fc2 100644
--- a/src/SDLMain.m
+++ b/src/SDLMain.m
@@ -9,6 +9,7 @@
#include "SDLMain.h"
#include <sys/param.h> /* for MAXPATHLEN */
#include <unistd.h>
+#include "defines.h"
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
but the method still is there and works. To avoid warnings, we declare
@@ -282,6 +283,21 @@ static void CustomApplicationMain (int argc, char **argv)
return TRUE;
}
+- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
+{
+ NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
+ int tempSaveOpen = [[url host] intValue];
+ if(tempSaveOpen > 0)
+ saveURIOpen = tempSaveOpen;
+}
+
+-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
+{
+ NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
+ [appleEventManager setEventHandler:self
+ andSelector:@selector(handleGetURLEvent:withReplyEvent:)
+ forEventClass:kInternetEventClass andEventID:kAEGetURL];
+}
/* Called when the internal event loop has just started running */
- (void) applicationDidFinishLaunching: (NSNotification *) note
diff --git a/src/interface.c b/src/interface.c
index 53fd481..0e31ffb 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -1298,7 +1298,7 @@ void info_box(pixel *vid_buf, char *msg)
{
int w = textwidth(msg)+16;
int x0=(XRES-w)/2,y0=(YRES-24)/2;
-
+
clearrect(vid_buf, x0-2, y0-2, w+4, 28);
drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255);
drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255);
@@ -1310,6 +1310,16 @@ void info_box(pixel *vid_buf, char *msg)
#endif
}
+void info_box_overlay(pixel *vid_buf, char *msg)
+{
+ int w = textwidth(msg)+16;
+ int x0=(XRES-w)/2,y0=(YRES-24)/2;
+
+ clearrect(vid_buf, x0-2, y0-2, w+4, 28);
+ drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255);
+ drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255);
+}
+
void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt)
{
int state = 0;
diff --git a/src/main.c b/src/main.c
index 87baa4a..bd9962c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -202,6 +202,8 @@ static const char *old_ver_msg = "A new version is available - click here!";
char new_message_msg[255];
float mheat = 0.0f;
+int saveURIOpen = 0;
+
int do_open = 0;
int sys_pause = 0;
int sys_shortcuts = 1;
@@ -777,6 +779,7 @@ int main(int argc, char *argv[])
part_vbuf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); //Extra video buffer
part_vbuf_store = part_vbuf;
pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
+ int saveOpenError = 0;
gravity_init();
GSPEED = 1;
@@ -831,6 +834,7 @@ int main(int argc, char *argv[])
svf_filename[0] = 0;
svf_fileopen = 1;
} else {
+ saveOpenError = 1;
svf_last = NULL;
svf_lsize = 0;
free(file_data);
@@ -839,7 +843,6 @@ int main(int argc, char *argv[])
}
i++;
}
-
}
load_presets();
@@ -916,6 +919,11 @@ int main(int argc, char *argv[])
error_ui(vid_buf, 0, "Unsupported CPU. Try another version.");
return 1;
}
+
+ if(saveOpenError)
+ {
+ error_ui(vid_buf, 0, "Unable to open save file.");
+ }
http_ver_check = http_async_req_start(NULL, "http://" SERVER "/Update.api?Action=CheckVersion", NULL, 0, 0);
if (svf_login) {
@@ -1128,6 +1136,7 @@ int main(int argc, char *argv[])
{
if (!do_s_check && http_async_req_status(http_session_check))
{
+ char saveURIOpenString[512];
check_data = http_async_req_stop(http_session_check, &http_s_ret, NULL);
if (http_ret==200 && check_data)
{
@@ -1212,7 +1221,15 @@ int main(int argc, char *argv[])
svf_messages = 0;
}
http_session_check = NULL;
+ if(saveURIOpen)
+ {
+ sprintf(saveURIOpenString, "%d", saveURIOpen);
+ open_ui(vid_buf, saveURIOpenString, NULL);
+ saveURIOpen = 0;
+ }
} else {
+ if(saveURIOpen)
+ info_box_overlay(vid_buf, "Waiting for login...");
clearrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14);
drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255);
drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255);
@@ -1231,6 +1248,16 @@ int main(int argc, char *argv[])
}
do_s_check = (do_s_check+1) & 15;
}
+ else
+ {
+ char saveURIOpenString[512];
+ if(saveURIOpen)
+ {
+ sprintf(saveURIOpenString, "%d", saveURIOpen);
+ open_ui(vid_buf, saveURIOpenString, NULL);
+ saveURIOpen = 0;
+ }
+ }
#ifdef LUACONSOLE
if(sdl_key){
if(!luacon_keyevent(sdl_key, sdl_mod, LUACON_KDOWN))