Permalink
Browse files

Add to Gambit REPL some functions to send SMS and take pictures (this…

… functionnality still needs a bit of work).
  • Loading branch information...
1 parent 6e4a04a commit 2d04867bb33076b6e7d344263182ad611323439a @feeley feeley committed Feb 25, 2012
Binary file not shown.
@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
+#import <MessageUI/MessageUI.h>
// ViewController methods callable from Scheme.
@@ -26,6 +27,8 @@ void set_webView_content(int view, NSString *str, NSString *base_url_path, BOOL
void set_webView_content_from_file(int view, NSString *path, NSString *base_url_path, BOOL enable_scaling, NSString *mime_type);
NSString *eval_js_in_webView(int view, NSString *script);
void open_URL(NSString *url);
+BOOL send_SMS(NSString *recipient, NSString *messsage);
+BOOL pick_image();
void set_idle_timer(BOOL enable);
void set_toolbar_alpha(double alpha);
void segm_ctrl_set_title(int segment, NSString *title);
@@ -44,7 +47,7 @@ void setup_location_updates(double desired_accuracy, double distance_filter);
#define NB_TEXTVIEWS 2
#define NB_IMAGEVIEWS 2
-@interface ViewController : UIViewController <UITextViewDelegate,UIWebViewDelegate,UIAlertViewDelegate,CLLocationManagerDelegate> {
+@interface ViewController : UIViewController <UITextViewDelegate,UIWebViewDelegate,UIAlertViewDelegate,CLLocationManagerDelegate,MFMessageComposeViewControllerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate> {
UISegmentedControl *segmCtrl;
UIWebView *webViews[NB_WEBVIEWS];
@@ -621,6 +621,88 @@ void open_URL(NSString *url) {
}
+BOOL send_SMS(NSString *recipient, NSString *message) {
+
+ ViewController *vc = theViewController;
+ if (vc != nil)
+ {
+ if ([MFMessageComposeViewController canSendText])
+ {
+ MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
+
+ controller.body = message;
+ controller.recipients = [NSArray arrayWithObjects:recipient,nil];
+ controller.messageComposeDelegate = vc;
+ [vc presentModalViewController:controller animated:YES];
+
+ return YES;
+ }
+ }
+
+ return NO;
+}
+
+
+- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
+{
+ NSString *event;
+
+ [self dismissModalViewControllerAnimated:YES];
+
+ switch (result) {
+
+ default:
+ case MessageComposeResultFailed:
+ event = @"SMS-failed";
+ break;
+
+ case MessageComposeResultCancelled:
+ event = @"SMS-cancelled";
+ break;
+
+ case MessageComposeResultSent:
+ event = @"SMS-sent";
+ break;
+ }
+
+ [self send_event:event];
+}
+
+
+BOOL pick_image() {
+
+ ViewController *vc = theViewController;
+ if (vc != nil)
+ {
+ if ([UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceRear] ||
+ [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront])
+ {
+ UIImagePickerController *controller = [[[UIImagePickerController alloc] init] autorelease];
+
+ controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
+
+ controller.sourceType = UIImagePickerControllerSourceTypeCamera;
+
+ controller.delegate = vc;
+
+ [vc presentModalViewController:controller animated:YES];
+
+ return YES;
+ }
+ }
+
+ return NO;
+}
+
+
+- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
+{
+ [picker dismissModalViewControllerAnimated:YES];
+
+ [self send_event:@"pick-image:"];
+}
+
+
void set_idle_timer(BOOL enable) {
[UIApplication sharedApplication].idleTimerDisabled = !enable;
View
@@ -199,7 +199,6 @@ EOF
(let* ((port (open-tcp-client
(list server-address: '#u8(73 125 226 48) ;; google.com
port-number: 443)))
- (_ (thread-sleep! 2))
(ip (socket-info-address
(tcp-client-self-socket-info port))))
(close-port port)
@@ -217,7 +216,7 @@ EOF
(and port
(try-catch
(begin
- (input-port-timeout-set! port 2.0)
+ (input-port-timeout-set! port 1.0)
(let ((header (read port)))
(input-port-timeout-set! port +inf.0)
(if (equal? header 'Gambit)
@@ -288,7 +287,7 @@ EOF
(let ((conn (REPL-server-connect addr)))
(if conn
(found conn))
- (sleep 0.5)))
+ (sleep 1.0)))
(define (scan-local-REPL-servers)
(discover-local-REPL-servers
View
@@ -73,6 +73,8 @@ set-webView-content-from-file
eval-js-in-webView
open-URL
+send-SMS
+pick-image
set-idle-timer
set-toolbar-alpha
segm-ctrl-set-title
View
@@ -422,6 +422,12 @@ c-declare-end
(define open-URL
(c-lambda (NSString*) void "open_URL"))
+(define send-SMS
+ (c-lambda (NSString* NSString*) bool "send_SMS"))
+
+(define pick-image
+ (c-lambda () bool "pick_image"))
+
(define set-idle-timer
(c-lambda (bool) void "set_idle_timer"))
View
@@ -2,5 +2,5 @@
* Time stamp of last source code repository commit.
*/
-#define ___STAMP_YMD 20120222
-#define ___STAMP_HMS 164157
+#define ___STAMP_YMD 20120225
+#define ___STAMP_HMS 135406

0 comments on commit 2d04867

Please sign in to comment.