Commit b77f3984 authored by Karlheinz Wohlmuth's avatar Karlheinz Wohlmuth Committed by Felix Paul Kühne

macosx: Growl notification plugin: use the Cocoa-based API

Support for the NSDistributedNotificationCenter based methods
was removed in Growl 1.3.
Signed-off-by: default avatarFelix Paul Kühne <fkuehne@videolan.org>
(cherry picked from commit 999170bd706b7d56d50a40a032522be7a379746b)

Conflicts:

	modules/notify/growl.m
parent 69117545
...@@ -4048,7 +4048,7 @@ AC_ARG_ENABLE(growl, ...@@ -4048,7 +4048,7 @@ AC_ARG_ENABLE(growl,
AS_IF([test "${enable_growl}" != "no"], [ AS_IF([test "${enable_growl}" != "no"], [
AC_CHECK_HEADERS(${CONTRIB_DIR}/Growl.framework/Versions/A/Headers/GrowlDefines.h, [ AC_CHECK_HEADERS(${CONTRIB_DIR}/Growl.framework/Versions/A/Headers/GrowlDefines.h, [
VLC_ADD_PLUGIN([growl]) VLC_ADD_PLUGIN([growl])
VLC_ADD_LIBS([growl], [-F${CONTRIB_DIR} -Wl,-framework,Growl,-framework,CoreFoundation]) VLC_ADD_LIBS([growl], [-F${CONTRIB_DIR} -Wl,-framework,Growl,-framework,Foundation])
VLC_ADD_OBJCFLAGS([growl], [-F${CONTRIB_DIR}]) VLC_ADD_OBJCFLAGS([growl], [-F${CONTRIB_DIR}])
VLC_ADD_OBJCFLAGS([growl], [-fobjc-exceptions] ) VLC_ADD_OBJCFLAGS([growl], [-fobjc-exceptions] )
]) ])
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
***************************************************************************** *****************************************************************************
* VLC specific code: * VLC specific code:
* *
* Copyright © 2008,2011 the VideoLAN team * Copyright © 2008,2011,2012 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Rafaël Carré <funman@videolanorg> * Authors: Rafaël Carré <funman@videolanorg>
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
# include "config.h" # include "config.h"
#endif #endif
#import <CoreFoundation/CoreFoundation.h> #import <Foundation/Foundation.h>
#import <Growl/GrowlDefines.h> #import <Growl/Growl.h>
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
...@@ -63,13 +63,23 @@ ...@@ -63,13 +63,23 @@
/***************************************************************************** /*****************************************************************************
* intf_sys_t * intf_sys_t, VLCGrowlDelegate
*****************************************************************************/ *****************************************************************************/
@interface VLCGrowlDelegate : NSObject <GrowlApplicationBridgeDelegate>
{
NSString *o_applicationName;
NSString *o_notificationType;
NSMutableDictionary *o_registrationDictionary;
}
- (void)registerToGrowl;
- (void)notifyWithDescription: (const char *)psz_desc
artUrl: (const char *)psz_arturl;
@end
struct intf_sys_t struct intf_sys_t
{ {
CFDataRef default_icon; VLCGrowlDelegate *o_growl_delegate;
CFStringRef app_name;
CFStringRef notification_type;
int i_id; int i_id;
int i_item_changes; int i_item_changes;
}; };
...@@ -83,11 +93,6 @@ static void Close ( vlc_object_t * ); ...@@ -83,11 +93,6 @@ static void Close ( vlc_object_t * );
static int ItemChange( vlc_object_t *, const char *, static int ItemChange( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
static void RegisterToGrowl( vlc_object_t * );
static void NotifyToGrowl( intf_thread_t *, const char *, CFDataRef );
static CFDataRef readFile(const char *);
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
****************************************************************************/ ****************************************************************************/
...@@ -114,21 +119,15 @@ static int Open( vlc_object_t *p_this ) ...@@ -114,21 +119,15 @@ static int Open( vlc_object_t *p_this )
if( !p_sys ) if( !p_sys )
return VLC_ENOMEM; return VLC_ENOMEM;
p_sys->app_name = CFSTR( "VLC media player" ); p_sys->o_growl_delegate = [[VLCGrowlDelegate alloc] init];
p_sys->notification_type = CFSTR( "New input playing" ); if( !p_sys->o_growl_delegate )
return VLC_ENOMEM;
char *data_path = config_GetDataDir ( p_this );
char buf[strlen (data_path) + sizeof ("/vlc512x512.png")];
snprintf (buf, sizeof (buf), "%s/vlc512x512.png", data_path);
msg_Dbg( p_this, "looking for icon at %s", buf );
free( data_path );
p_sys->default_icon = (CFDataRef) readFile( buf );
p_playlist = pl_Get( p_intf ); p_playlist = pl_Get( p_intf );
var_AddCallback( p_playlist, "item-change", ItemChange, p_intf ); var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
var_AddCallback( p_playlist, "item-current", ItemChange, p_intf ); var_AddCallback( p_playlist, "item-current", ItemChange, p_intf );
RegisterToGrowl( p_this ); [p_sys->o_growl_delegate registerToGrowl];
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -144,9 +143,7 @@ static void Close( vlc_object_t *p_this ) ...@@ -144,9 +143,7 @@ static void Close( vlc_object_t *p_this )
var_DelCallback( p_playlist, "item-change", ItemChange, p_intf ); var_DelCallback( p_playlist, "item-change", ItemChange, p_intf );
var_DelCallback( p_playlist, "item-current", ItemChange, p_intf ); var_DelCallback( p_playlist, "item-current", ItemChange, p_intf );
CFRelease( p_sys->default_icon ); [p_sys->o_growl_delegate release];
CFRelease( p_sys->app_name );
CFRelease( p_sys->notification_type );
free( p_sys ); free( p_sys );
} }
...@@ -192,7 +189,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, ...@@ -192,7 +189,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
p_intf->p_sys->i_item_changes++; p_intf->p_sys->i_item_changes++;
} }
input_thread_t *p_input = playlist_CurrentInput( (playlist_t*)p_this ); input_thread_t *p_input = playlist_CurrentInput( (playlist_t*)p_this );
if( !p_input ) return VLC_SUCCESS; if( !p_input ) return VLC_SUCCESS;
...@@ -246,18 +242,13 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, ...@@ -246,18 +242,13 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
free( psz_arturl ); free( psz_arturl );
psz_arturl = psz; psz_arturl = psz;
} }
CFDataRef art = NULL;
if( psz_arturl ) [p_intf->p_sys->o_growl_delegate notifyWithDescription: psz_tmp artUrl: psz_arturl];
art = (CFDataRef) readFile( psz_arturl );
free( psz_title ); free( psz_title );
free( psz_artist ); free( psz_artist );
free( psz_album ); free( psz_album );
free( psz_arturl ); free( psz_arturl );
NotifyToGrowl( p_intf, psz_tmp, art );
if( art ) CFRelease( art );
free( psz_tmp ); free( psz_tmp );
vlc_object_release( p_input ); vlc_object_release( p_input );
...@@ -265,91 +256,76 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, ...@@ -265,91 +256,76 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
} }
/***************************************************************************** /*****************************************************************************
* RegisterToGrowl * VLCGrowlDelegate
*****************************************************************************/ *****************************************************************************/
static void RegisterToGrowl( vlc_object_t *p_this ) @implementation VLCGrowlDelegate
- (id)init
{ {
intf_sys_t *p_sys = ((intf_thread_t *)p_this)->p_sys; if( !( self = [super init] ) )
return nil;
CFArrayRef defaultAndAllNotifications = CFArrayCreate(
kCFAllocatorDefault, (const void **)&(p_sys->notification_type), 1, o_applicationName = nil;
&kCFTypeArrayCallBacks ); o_notificationType = nil;
o_registrationDictionary = nil;
CFTypeRef registerKeys[4] = {
GROWL_APP_NAME, return self;
GROWL_NOTIFICATIONS_ALL,
GROWL_NOTIFICATIONS_DEFAULT,
GROWL_APP_ICON
};
CFTypeRef registerValues[4] = {
p_sys->app_name,
defaultAndAllNotifications,
defaultAndAllNotifications,
p_sys->default_icon
};
CFDictionaryRef registerInfo = CFDictionaryCreate(
kCFAllocatorDefault, registerKeys, registerValues, 4,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
CFRelease( defaultAndAllNotifications );
CFNotificationCenterPostNotificationWithOptions(
CFNotificationCenterGetDistributedCenter(),
(CFStringRef)GROWL_APP_REGISTRATION, NULL, registerInfo,
kCFNotificationPostToAllSessions );
CFRelease( registerInfo );
} }
static void NotifyToGrowl( intf_thread_t *p_intf, const char *psz_desc, CFDataRef art ) - (void)dealloc
{ {
intf_sys_t *p_sys = p_intf->p_sys; [o_applicationName release];
[o_notificationType release];
CFStringRef title = CFStringCreateWithCString( kCFAllocatorDefault, _("Now playing"), kCFStringEncodingUTF8 ); [o_registrationDictionary release];
CFStringRef desc = CFStringCreateWithCString( kCFAllocatorDefault, psz_desc, kCFStringEncodingUTF8 ); [super dealloc];
}
CFMutableDictionaryRef notificationInfo = CFDictionaryCreateMutable( - (void)registerToGrowl
kCFAllocatorDefault, 5, &kCFTypeDictionaryKeyCallBacks, {
&kCFTypeDictionaryValueCallBacks); o_applicationName = [[NSString alloc] initWithUTF8String: _( "VLC media player" )];
o_notificationType = [[NSString alloc] initWithUTF8String: _( "New input playing" )];
CFDictionarySetValue( notificationInfo, GROWL_NOTIFICATION_NAME, p_sys->notification_type ); NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
CFDictionarySetValue( notificationInfo, GROWL_APP_NAME, p_sys->app_name ); NSArray *o_defaultAndAllNotifications = [NSArray arrayWithObject: o_notificationType];
CFDictionarySetValue( notificationInfo, GROWL_NOTIFICATION_TITLE, title );
CFDictionarySetValue( notificationInfo, GROWL_NOTIFICATION_DESCRIPTION, desc );
CFDictionarySetValue( notificationInfo, GROWL_NOTIFICATION_ICON, o_registrationDictionary = [[NSMutableDictionary alloc] init];
art ? art : p_sys->default_icon ); [o_registrationDictionary setObject: o_defaultAndAllNotifications
forKey: GROWL_NOTIFICATIONS_ALL];
[o_registrationDictionary setObject: o_defaultAndAllNotifications
forKey: GROWL_NOTIFICATIONS_DEFAULT];
CFRelease( title ); [GrowlApplicationBridge setGrowlDelegate: self];
CFRelease( desc ); [o_pool drain];
}
CFNotificationCenterPostNotificationWithOptions( - (void)notifyWithDescription: (const char *)psz_desc artUrl: (const char *)psz_arturl
CFNotificationCenterGetDistributedCenter(), {
(CFStringRef)GROWL_NOTIFICATION, NULL, notificationInfo, NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
kCFNotificationPostToAllSessions ); NSData *o_art = nil;
CFRelease( notificationInfo ); if( psz_arturl )
o_art = [NSData dataWithContentsOfFile: [NSString stringWithUTF8String: psz_arturl]];
[GrowlApplicationBridge notifyWithTitle: [NSString stringWithUTF8String: _( "Now playing" )]
description: [NSString stringWithUTF8String: psz_desc]
notificationName: o_notificationType
iconData: o_art
priority: 0
isSticky: NO
clickContext: nil];
[o_pool drain];
} }
/* Ripped from CFGrowlAdditions.c /*****************************************************************************
* Strangely, this function does exist in Growl shared library, but is not * Delegate methods
* defined in public header files */ *****************************************************************************/
static CFDataRef readFile(const char *filename) - (NSDictionary *)registrationDictionaryForGrowl
{ {
CFDataRef data; return o_registrationDictionary;
// read the file into a CFDataRef
FILE *fp = fopen(filename, "r");
if( !fp )
return NULL;
fseek(fp, 0, SEEK_END);
long dataLength = ftell(fp);
fseek(fp, 0, SEEK_SET);
unsigned char *fileData = malloc(dataLength);
fread(fileData, 1, dataLength, fp);
fclose(fp);
return CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, fileData,
dataLength, kCFAllocatorMalloc);
} }
- (NSString *)applicationNameForGrowl
{
return o_applicationName;
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment