add webbrowser support for ios

This commit is contained in:
Mathieu Virbel 2012-05-10 03:43:52 +02:00
parent 4d07ae4112
commit 0147538dfd
4 changed files with 50 additions and 2 deletions

View file

@ -13,6 +13,7 @@ cdef extern from "ios_wrapper.h":
ctypedef void (*ios_send_email_cb)(char *, void *)
int ios_send_email(char *subject, char *text, char *mimetype, char
*filename, char *filename_alias, ios_send_email_cb cb, void *userdata)
void ios_open_url(char *url)
cdef void _send_email_done(char *status, void *data):
cdef object callback = <object>data
@ -20,11 +21,43 @@ cdef void _send_email_done(char *status, void *data):
Py_DECREF(callback)
#
# Support for webbrowser module
#
class IosBrowser(object):
def open(self, url, new=0, autoraise=True):
open_url(url)
def open_new(self, url):
open_url(url)
def open_new_tab(self, url):
open_url(url)
import webbrowser
webbrowser.register('ios', IosBrowser, None, -1)
#
# API
#
__version__ = (1, 0, 0)
__version__ = (1, 1, 0)
def open_url(url):
'''Open an URL in Safari
:Parameters:
`url`: str
The url string
'''
cdef char *j_url = NULL
if url is not None:
if type(url) is unicode:
url = url.encode('UTF-8')
j_url = <bytes>url
ios_open_url(j_url)
def send_email(subject, text, mimetype=None, filename=None, filename_alias=None, callback=None):
'''Send an email using the IOS api.

13
src/ios/ios_browser.m Normal file
View file

@ -0,0 +1,13 @@
/*
* Browser support
*/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#include "ios_wrapper.h"
void ios_open_url(char *url)
{
NSString *nsurl = [NSString stringWithCString:(char *)url encoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: nsurl]];
}

View file

@ -1,6 +1,8 @@
#ifndef __IOS_WRAPPER
#define __IOS_WRAPPER
void ios_open_url(char *url);
typedef void (*ios_send_email_cb)(char *, void *);
int ios_send_email(char *subject, char *text, char *mimetype, char *filename,

View file

@ -5,7 +5,7 @@ setup(name='ios',
version='1.0',
ext_modules=[
Extension(
'ios', ['ios.c', 'ios_mail.m'],
'ios', ['ios.c', 'ios_mail.m', 'ios_browser.m'],
libraries=[ ],
library_dirs=[],
)