Skip to content

Commit

Permalink
update notifications on osx
Browse files Browse the repository at this point in the history
  • Loading branch information
fairwinds committed Oct 28, 2012
1 parent 6b97e28 commit 519c892
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 283 deletions.
9 changes: 0 additions & 9 deletions apidoc/Titanium/Notification/Notification/setCallback.yml

This file was deleted.

8 changes: 0 additions & 8 deletions modules/ti.UI/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Notification::Notification() : KAccessorObject("Notification"),
SetMethod("setIcon", &Notification::_SetIcon);
SetMethod("setTimeout", &Notification::_SetTimeout);
SetMethod("setDelay", &Notification::_SetTimeout);
SetMethod("setCallback", &Notification::_SetCallback);
SetMethod("show", &Notification::_Show);
SetMethod("hide", &Notification::_Hide);

Expand Down Expand Up @@ -54,12 +53,6 @@ void Notification::_SetTimeout(const ValueList& args, KValueRef result)
this->timeout = args.GetInt(0);
}

void Notification::_SetCallback(const ValueList& args, KValueRef result)
{
args.VerifyException("setCallback", "m");
this->clickedCallback = args.GetMethod(0);
}

void Notification::_Show(const ValueList& args, KValueRef result)
{
result->SetBool(this->ShowImpl());
Expand All @@ -76,7 +69,6 @@ void Notification::Configure(KObjectRef properties)
this->message = properties->GetString("message");
this->iconURL = properties->GetString("icon");
this->timeout = properties->GetInt("timeout", -1);
this->clickedCallback = properties->GetMethod("callback");
}

}
4 changes: 1 addition & 3 deletions modules/ti.UI/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ class Notification : public KAccessorObject
std::string message;
std::string iconURL;
int timeout;
KMethodRef clickedCallback;
PlatformNotification notification;

void _SetTitle(const ValueList& args, KValueRef result);
void _SetMessage(const ValueList& args, KValueRef result);
void _SetIcon(const ValueList& args, KValueRef result);
void _SetTimeout(const ValueList& args, KValueRef result);
void _SetCallback(const ValueList& args, KValueRef result);
void _Show(const ValueList& args, KValueRef result);
void _Hide(const ValueList& args, KValueRef result);
};
Expand All @@ -57,4 +55,4 @@ typedef AutoPtr<Notification> AutoNotification;

}

#endif
#endif
27 changes: 27 additions & 0 deletions modules/ti.UI/osx/growl_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2012 Software in the Public Interest Inc (SPI)
* Copyright (c) 2012 Steven Verbeek
* Copyright (c) 2012 David Pratt
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#import <Foundation/Foundation.h>
#import <Growl/Growl.h>
#include <string>

@interface growlWrapper : NSObject <GrowlApplicationBridgeDelegate>

void showGrowlMessage(NSInteger priority, NSString *title, NSString *desc, CFDataRef icon);

@end
51 changes: 51 additions & 0 deletions modules/ti.UI/osx/growl_wrapper.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) 2012 Software in the Public Interest Inc (SPI)
* Copyright (c) 2012 Steven Verbeek
* Copyright (c) 2012 David Pratt
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#import "growl_wrapper.h"

@implementation growlWrapper

// Register for Growl using tiGrowl as the application name
// TODO: Make it so the application name is the name of the application, rather then tiGrowl
-(NSDictionary *)registrationDictionaryForGrowl {
NSArray *notifications = [NSArray arrayWithObject:@"tiGrowl"];
return [NSDictionary dictionaryWithObjectsAndKeys: @"tiGrowl", GROWL_APP_ID, @"tiGrowl", GROWL_APP_NAME, notifications, GROWL_NOTIFICATIONS_ALL, notifications, GROWL_NOTIFICATIONS_DEFAULT, nil];
}

// Function to show growl notification
void showGrowlMessage(NSInteger priority, NSString *title, NSString *desc, CFDataRef iconData)
{
growlWrapper *growlDelegate;
growlDelegate = [[growlWrapper alloc] init];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSData *icon = (NSData *)iconData;

[GrowlApplicationBridge setGrowlDelegate:growlDelegate];
[GrowlApplicationBridge notifyWithTitle: title
description: desc
notificationName: @"tiGrowl"
iconData:icon
priority:priority
isSticky:NO
clickContext:nil];
// TODO: Memory check, make sure this is being released properly and there isn't any memory leaks
[pool drain];
}

@end
Loading

0 comments on commit 519c892

Please sign in to comment.