growl: Renamed Growl plugin to OS X Notifications
authorMarvin Scholz <epirat07@gmail.com>
Thu, 22 Oct 2015 16:18:50 +0000 (18:18 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 23 Oct 2015 09:28:02 +0000 (11:28 +0200)
This renames the Growl plugin to OS X Notifications to highlight
the new capabilities and to not advertise Growl so much, as
requested.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
configure.ac
extras/package/macosx/Resources/English.lproj/SimplePreferences.xib
extras/package/macosx/configure.sh
modules/gui/macosx/simple_prefs.h
modules/gui/macosx/simple_prefs.m
modules/notify/Makefile.am
modules/notify/growl.m [deleted file]
modules/notify/osx_notifications.m [new file with mode: 0644]
po/POTFILES.in

index aaaae68..3971c8e 100644 (file)
@@ -4060,17 +4060,17 @@ then
 fi
 
 dnl
-dnl Growl notification plugin
+dnl OS X notification plugin
 dnl
-AC_ARG_ENABLE(growl,
-  [  --enable-growl          growl notification plugin (default disabled)],,
-  [enable_growl=no])
-AS_IF([test "${enable_growl}" != "no"], [
+AC_ARG_ENABLE(osx_notifications,
+  [  --enable-osx-notifications          osx notification plugin (default disabled)],,
+  [enable_osx_notifications=no])
+AS_IF([test "${enable_osx_notifications}" != "no"], [
     AC_CHECK_HEADERS(${CONTRIB_DIR}/Growl.framework/Versions/A/Headers/Growl.h, [
-      VLC_ADD_PLUGIN([growl])
-      VLC_ADD_LIBS([growl], [-F${CONTRIB_DIR} -Wl,-framework,Growl,-framework,Foundation])
-      VLC_ADD_OBJCFLAGS([growl], [-F${CONTRIB_DIR}])
-      VLC_ADD_OBJCFLAGS([growl], [-fobjc-exceptions] )
+      VLC_ADD_PLUGIN([osx_notifications])
+      VLC_ADD_LIBS([osx_notifications], [-F${CONTRIB_DIR} -Wl,-framework,Growl,-framework,Foundation])
+      VLC_ADD_OBJCFLAGS([osx_notifications], [-F${CONTRIB_DIR}])
+      VLC_ADD_OBJCFLAGS([osx_notifications], [-fobjc-exceptions] )
     ])
   ]
 )
index fda675e..9ae4239 100644 (file)
@@ -72,7 +72,7 @@
                 <outlet property="intf_continueplaybackLabel" destination="3919" id="ZJO-qY-UCq"/>
                 <outlet property="intf_continueplaybackPopup" destination="3920" id="dZ3-SI-SCp"/>
                 <outlet property="intf_embeddedCheckbox" destination="2445" id="eGx-n3-YeT"/>
-                <outlet property="intf_enableGrowlCheckbox" destination="3564" id="ntp-Ut-7XL"/>
+                <outlet property="intf_enableNotificationsCheckbox" destination="3564" id="IIA-ce-g61"/>
                 <outlet property="intf_fspanelCheckbox" destination="2327" id="cnD-cL-uNI"/>
                 <outlet property="intf_languageLabel" destination="3892" id="klM-r2-XKf"/>
                 <outlet property="intf_languagePopup" destination="3900" id="USp-A1-Aut"/>
@@ -262,7 +262,7 @@ Gw
                     <rect key="frame" x="18" y="281" width="534" height="18"/>
                     <autoresizingMask key="autoresizingMask"/>
                     <animations/>
-                    <buttonCell key="cell" type="check" title="Enable Growl notifications (on playlist item change)" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="3565">
+                    <buttonCell key="cell" type="check" title="Enable notifications on playlist item change" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="3565">
                         <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
                         <font key="font" metaFont="system"/>
                     </buttonCell>
@@ -1774,7 +1774,7 @@ Gw
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" alternatingRowBackgroundColors="YES" columnReordering="NO" multipleSelection="NO" emptySelection="NO" autosaveName="sprefs_hotkeys_view" headerView="3541" id="2670">
-                                <rect key="frame" x="0.0" y="0.0" width="528" height="286"/>
+                                <rect key="frame" x="0.0" y="0.0" width="528" height="19"/>
                                 <autoresizingMask key="autoresizingMask"/>
                                 <animations/>
                                 <size key="intercellSpacing" width="3" height="2"/>
index 1db7cc6..c968d66 100755 (executable)
@@ -18,7 +18,7 @@ OPTIONS="
         --prefix=`pwd`/vlc_install_dir
         --enable-macosx
         --enable-merge-ffmpeg
-        --enable-growl
+        --enable-osx-notifications
         --enable-faad
         --enable-flac
         --enable-theora
index 3244f8f..5db8d26 100644 (file)
@@ -99,7 +99,7 @@
 @property (readwrite, weak) IBOutlet NSView *intfView;
 @property (readwrite, weak) IBOutlet NSButton *intf_updateCheckbox;
 @property (readwrite, weak) IBOutlet NSTextField *intf_last_updateLabel;
-@property (readwrite, weak) IBOutlet NSButton *intf_enableGrowlCheckbox;
+@property (readwrite, weak) IBOutlet NSButton *intf_enableNotificationsCheckbox;
 @property (readwrite, weak) IBOutlet NSButton *intf_nativefullscreenCheckbox;
 @property (readwrite, weak) IBOutlet NSButton *intf_autoresizeCheckbox;
 @property (readwrite, weak) IBOutlet NSButton *intf_pauseminimizedCheckbox;
index 41a42e2..af0a982 100644 (file)
@@ -377,7 +377,7 @@ create_toolbar_item(NSString *itemIdent, NSString *name, NSString *desc, NSStrin
     [_intf_artCheckbox setTitle: _NS("Allow metadata network access")];
     [_intf_updateCheckbox setTitle: _NS("Automatically check for updates")];
     [_intf_last_updateLabel setStringValue: @""];
-    [_intf_enableGrowlCheckbox setTitle: _NS("Enable Growl notifications (on playlist item change)")];
+    [_intf_enableNotificationsCheckbox setTitle: _NS("Enable notifications on playlist item change")];
     [_intf_autoresizeCheckbox setTitle: _NS("Resize interface to the native video size")];
     [_intf_pauseminimizedCheckbox setTitle: _NS("Pause the video playback when minimized")];
     [_intf_luahttpBox setTitle:_NS("Lua HTTP")];
@@ -590,10 +590,10 @@ static inline char * __config_GetLabel(vlc_object_t *p_this, const char *psz_nam
 
     psz_tmp = config_GetPsz(p_intf, "control");
     if (psz_tmp) {
-        [_intf_enableGrowlCheckbox setState: (NSInteger)strstr(psz_tmp, "growl")];
+        [_intf_enableNotificationsCheckbox setState: (NSInteger)strstr(psz_tmp, "growl")];
         free(psz_tmp);
     } else
-        [_intf_enableGrowlCheckbox setState: NSOffState];
+        [_intf_enableNotificationsCheckbox setState: NSOffState];
     if (config_GetInt(p_intf, "macosx-interfacestyle")) {
         [_intf_style_darkButtonCell setState: YES];
         [_intf_style_brightButtonCell setState: NO];
@@ -929,7 +929,7 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
         config_PutInt(p_intf, "macosx-nativefullscreenmode", [_intf_nativefullscreenCheckbox state]);
         config_PutInt(p_intf, "macosx-pause-minimized", [_intf_pauseminimizedCheckbox state]);
         config_PutInt(p_intf, "macosx-video-autoresize", [_intf_autoresizeCheckbox state]);
-        if ([_intf_enableGrowlCheckbox state] == NSOnState) {
+        if ([_intf_enableNotificationsCheckbox state] == NSOnState) {
             tmpString = getString("control");
             tmpRange = [tmpString rangeOfString:@"growl"];
             if ([tmpString length] > 0 && tmpRange.location == NSNotFound)
index c38c453..714a3c5 100644 (file)
@@ -1,15 +1,15 @@
 notifydir = $(pluginsdir)/notify
 
-libgrowl_plugin_la_SOURCES = notify/growl.m
-libgrowl_plugin_la_OBJCFLAGS = $(AM_OBJCFLAGS) $(OBJCFLAGS_growl)
-libgrowl_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(notifydir)' -Wl,-framework,AppKit
-libgrowl_plugin_la_LIBADD = $(LIBS_growl)
-libgrowl_plugin_la_LIBTOOLFLAGS = --tag=CC
+libosx_notifications_plugin_la_SOURCES = notify/osx_notifications.m
+libosx_notifications_plugin_la_OBJCFLAGS = $(AM_OBJCFLAGS) $(OBJCFLAGS_osx_notifications)
+libosx_notifications_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(notifydir)' -Wl,-framework,AppKit
+libosx_notifications_plugin_la_LIBADD = $(LIBS_osx_notifications)
+libosx_notifications_plugin_la_LIBTOOLFLAGS = --tag=CC
 
 libnotify_plugin_la_SOURCES = notify/notify.c
 libnotify_plugin_la_CFLAGS = $(AM_CFLAGS) $(NOTIFY_CFLAGS)
 libnotify_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(notifydir)'
 libnotify_plugin_la_LIBADD = $(NOTIFY_LIBS)
 
-notify_LTLIBRARIES = $(LTLIBgrowl) $(LTLIBnotify)
-EXTRA_LTLIBRARIES += libgrowl_plugin.la libnotify_plugin.la
+notify_LTLIBRARIES = $(LTLIBosx_notifications) $(LTLIBnotify)
+EXTRA_LTLIBRARIES += libosx_notifications_plugin.la libnotify_plugin.la
diff --git a/modules/notify/growl.m b/modules/notify/growl.m
deleted file mode 100644 (file)
index 30d9fd3..0000000
+++ /dev/null
@@ -1,473 +0,0 @@
-/*****************************************************************************
- * growl.m : growl notification plugin
- *****************************************************************************
- * VLC specific code:
- *
- * Copyright © 2008,2011,2012,2015 the VideoLAN team
- * $Id$
- *
- * Authors: Rafaël Carré <funman@videolanorg>
- *          Felix Paul Kühne <fkuehne@videolan.org
- *          Marvin Scholz <epirat07@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *
- * Growl specific code, ripped from growlnotify:
- *
- * Copyright (c) The Growl Project, 2004-2005
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Growl nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#import <Foundation/Foundation.h>
-#import <Cocoa/Cocoa.h>
-#import <Growl/Growl.h>
-
-#define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_playlist.h>
-#include <vlc_input.h>
-#include <vlc_meta.h>
-#include <vlc_interface.h>
-#include <vlc_url.h>
-
-/*****************************************************************************
- * intf_sys_t, VLCGrowlDelegate
- *****************************************************************************/
-@interface VLCGrowlDelegate : NSObject <GrowlApplicationBridgeDelegate>
-{
-    NSString *applicationName;
-    NSString *notificationType;
-    NSMutableDictionary *registrationDictionary;
-    id lastNotification;
-    BOOL isInForeground;
-    intf_thread_t *interfaceThread;
-}
-
-- (id)initWithInterfaceThread:(intf_thread_t *)thread;
-- (void)registerToGrowl;
-- (void)notifyWithTitle:(const char *)title
-                 artist:(const char *)artist
-                  album:(const char *)album
-              andArtUrl:(const char *)url;
-@end
-
-struct intf_sys_t
-{
-    VLCGrowlDelegate *o_growl_delegate;
-    int             i_id;
-    int             i_item_changes;
-};
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int  Open    ( vlc_object_t * );
-static void Close   ( vlc_object_t * );
-
-static int ItemChange( vlc_object_t *, const char *,
-                      vlc_value_t, vlc_value_t, void * );
-
-/*****************************************************************************
- * Module descriptor
- ****************************************************************************/
-
-vlc_module_begin ()
-set_category( CAT_INTERFACE )
-set_subcategory( SUBCAT_INTERFACE_CONTROL )
-set_shortname( "Growl" )
-set_description( N_("Growl Notification Plugin") )
-set_capability( "interface", 0 )
-set_callbacks( Open, Close )
-vlc_module_end ()
-
-/*****************************************************************************
- * Open: initialize and create stuff
- *****************************************************************************/
-static int Open( vlc_object_t *p_this )
-{
-    intf_thread_t *p_intf = (intf_thread_t *)p_this;
-    playlist_t *p_playlist;
-    intf_sys_t    *p_sys;
-
-    p_sys = p_intf->p_sys = calloc( 1, sizeof(intf_sys_t) );
-    if( !p_sys )
-        return VLC_ENOMEM;
-
-    p_sys->o_growl_delegate = [[VLCGrowlDelegate alloc] initWithInterfaceThread:p_intf];
-    if( !p_sys->o_growl_delegate )
-      return VLC_ENOMEM;
-
-    p_playlist = pl_Get( p_intf );
-    var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
-    var_AddCallback( p_playlist, "input-current", ItemChange, p_intf );
-
-    [p_sys->o_growl_delegate registerToGrowl];
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * Close: destroy interface stuff
- *****************************************************************************/
-static void Close( vlc_object_t *p_this )
-{
-    intf_thread_t *p_intf = (intf_thread_t *)p_this;
-    playlist_t *p_playlist = pl_Get( p_intf );
-    intf_sys_t *p_sys = p_intf->p_sys;
-
-    var_DelCallback( p_playlist, "item-change", ItemChange, p_intf );
-    var_DelCallback( p_playlist, "input-current", ItemChange, p_intf );
-
-    [GrowlApplicationBridge setGrowlDelegate:nil];
-    [p_sys->o_growl_delegate release];
-    free( p_sys );
-}
-
-/*****************************************************************************
- * ItemChange: Playlist item change callback
- *****************************************************************************/
-static int ItemChange( vlc_object_t *p_this, const char *psz_var,
-                      vlc_value_t oldval, vlc_value_t newval, void *param )
-{
-    VLC_UNUSED(oldval);
-
-    intf_thread_t *p_intf = (intf_thread_t *)param;
-    char *psz_tmp           = NULL;
-    char *psz_title         = NULL;
-    char *psz_artist        = NULL;
-    char *psz_album         = NULL;
-    input_item_t *p_item = newval.p_address;
-
-    bool b_is_item_current = !strcmp( "input-current", psz_var );
-
-    /* Don't update each time an item has been preparsed */
-    if( b_is_item_current )
-    { /* stores the current input item id */
-        input_thread_t *p_input = newval.p_address;
-        if( !p_input )
-            return VLC_SUCCESS;
-
-        p_item = input_GetItem( p_input );
-        if( p_intf->p_sys->i_id != p_item->i_id )
-        {
-            p_intf->p_sys->i_id = p_item->i_id;
-            p_intf->p_sys->i_item_changes = 0;
-        }
-
-        return VLC_SUCCESS;
-    }
-    /* ignore items which weren't pre-parsed yet */
-    else if( !input_item_IsPreparsed(p_item) )
-        return VLC_SUCCESS;
-    else
-    {   /* "item-change" */
-        
-        if( p_item->i_id != p_intf->p_sys->i_id )
-            return VLC_SUCCESS;
-
-        /* Some variable bitrate inputs call "item-change" callbacks each time
-         * their length is updated, that is several times per second.
-         * We'll limit the number of changes to 1 per input. */
-        if( p_intf->p_sys->i_item_changes > 0 )
-            return VLC_SUCCESS;
-
-        p_intf->p_sys->i_item_changes++;
-    }
-
-    /* Playing something ... */
-    if( input_item_GetNowPlayingFb( p_item ) )
-        psz_title = input_item_GetNowPlayingFb( p_item );
-    else
-        psz_title = input_item_GetTitleFbName( p_item );
-    if( EMPTY_STR( psz_title ) )
-    {
-        free( psz_title );
-        return VLC_SUCCESS;
-    }
-
-    psz_artist = input_item_GetArtist( p_item );
-    if( EMPTY_STR( psz_artist ) ) FREENULL( psz_artist );
-    psz_album = input_item_GetAlbum( p_item ) ;
-    if( EMPTY_STR( psz_album ) ) FREENULL( psz_album );
-
-    int i_ret;
-    if( psz_artist && psz_album )
-        i_ret = asprintf( &psz_tmp, "%s\n%s [%s]",
-                         psz_title, psz_artist, psz_album );
-    else if( psz_artist )
-        i_ret = asprintf( &psz_tmp, "%s\n%s", psz_title, psz_artist );
-    else
-        i_ret = asprintf(&psz_tmp, "%s", psz_title );
-
-    if( i_ret == -1 )
-    {
-        free( psz_title );
-        free( psz_artist );
-        free( psz_album );
-        return VLC_ENOMEM;
-    }
-
-    char *psz_arturl = input_item_GetArtURL( p_item );
-    if( psz_arturl )
-    {
-        char *psz = make_path( psz_arturl );
-        free( psz_arturl );
-        psz_arturl = psz;
-    }
-
-    [p_intf->p_sys->o_growl_delegate notifyWithTitle:psz_title
-                                              artist:psz_artist
-                                               album:psz_album
-                                           andArtUrl:psz_arturl];
-
-    free( psz_title );
-    free( psz_artist );
-    free( psz_album );
-    free( psz_arturl );
-    free( psz_tmp );
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * VLCGrowlDelegate
- *****************************************************************************/
-@implementation VLCGrowlDelegate
-
-- (id)initWithInterfaceThread:(intf_thread_t *)thread {
-    if( !( self = [super init] ) )
-        return nil;
-
-    applicationName = nil;
-    notificationType = nil;
-    registrationDictionary = nil;
-    interfaceThread = thread;
-
-    // Assume we start in foreground
-    isInForeground = YES;
-
-    // Subscribe to notifications to determine if VLC is in foreground or not
-    @autoreleasepool {
-        [[NSNotificationCenter defaultCenter] addObserver:self
-                                                 selector:@selector(applicationActiveChange:)
-                                                     name:NSApplicationDidBecomeActiveNotification
-                                                   object:nil];
-
-        [[NSNotificationCenter defaultCenter] addObserver:self
-                                                 selector:@selector(applicationActiveChange:)
-                                                     name:NSApplicationDidResignActiveNotification
-                                                   object:nil];
-    }
-    return self;
-}
-
-- (void)dealloc
-{
-#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
-    // Clear the remaining lastNotification in Notification Center, if any
-    @autoreleasepool {
-        if (lastNotification) {
-            [NSUserNotificationCenter.defaultUserNotificationCenter
-             removeDeliveredNotification:(NSUserNotification *)lastNotification];
-            [lastNotification release];
-        }
-        [[NSNotificationCenter defaultCenter] removeObserver:self];
-    }
-#endif
-
-    // Release everything
-    [applicationName release];
-    [notificationType release];
-    [registrationDictionary release];
-    [super dealloc];
-}
-
-- (void)registerToGrowl
-{
-    @autoreleasepool {
-        applicationName = [[NSString alloc] initWithUTF8String:_( "VLC media player" )];
-        notificationType = [[NSString alloc] initWithUTF8String:_( "New input playing" )];
-
-        NSArray *defaultAndAllNotifications = [NSArray arrayWithObject: notificationType];
-        registrationDictionary = [[NSMutableDictionary alloc] init];
-        [registrationDictionary setObject:defaultAndAllNotifications
-                                   forKey:GROWL_NOTIFICATIONS_ALL];
-        [registrationDictionary setObject:defaultAndAllNotifications
-                                   forKey: GROWL_NOTIFICATIONS_DEFAULT];
-
-        [GrowlApplicationBridge setGrowlDelegate:self];
-
-#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
-        [[NSUserNotificationCenter defaultUserNotificationCenter]
-         setDelegate:(id<NSUserNotificationCenterDelegate>)self];
-#endif
-    }
-}
-
-- (void)notifyWithTitle:(const char *)title
-                 artist:(const char *)artist
-                  album:(const char *)album
-              andArtUrl:(const char *)url
-{
-    @autoreleasepool {
-        // Init Cover
-        NSData *coverImageData = nil;
-        NSImage *coverImage = nil;
-
-        if (url) {
-            coverImageData = [NSData dataWithContentsOfFile:[NSString stringWithUTF8String:url]];
-            coverImage = [[NSImage alloc] initWithData:coverImageData];
-        }
-
-        // Init Track info
-        NSString *titleStr = nil;
-        NSString *artistStr = nil;
-        NSString *albumStr = nil;
-
-        if (title) {
-            titleStr = [NSString stringWithUTF8String:title];
-        } else {
-            // Without title, notification makes no sense, so return here
-            // title should never be empty, but better check than crash.
-            return;
-        }
-        if (artist)
-            artistStr = [NSString stringWithUTF8String:artist];
-        if (album)
-            albumStr = [NSString stringWithUTF8String:album];
-
-        // Notification stuff
-        if ([GrowlApplicationBridge isGrowlRunning]) {
-            // Make the Growl notification string
-            NSString *desc = nil;
-
-            if (artistStr && albumStr) {
-                desc = [NSString stringWithFormat:@"%@\n%@ [%@]", titleStr, artistStr, albumStr];
-            } else if (artistStr) {
-                desc = [NSString stringWithFormat:@"%@\n%@", titleStr, artistStr];
-            } else {
-                desc = titleStr;
-            }
-
-            // Send notification
-            [GrowlApplicationBridge notifyWithTitle:[NSString stringWithUTF8String:_("Now playing")]
-                                        description:desc
-                                   notificationName:notificationType
-                                           iconData:coverImageData
-                                           priority:0
-                                           isSticky:NO
-                                       clickContext:nil];
-        } else {
-#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
-            // Make the OS X notification and string
-            NSUserNotification *notification = [NSUserNotification new];
-            NSString *desc = nil;
-
-            if (artistStr && albumStr) {
-                desc = [NSString stringWithFormat:@"%@ – %@", artistStr, albumStr];
-            } else if (artistStr) {
-                desc = artistStr;
-            }
-
-            notification.title              = titleStr;
-            notification.subtitle           = desc;
-            notification.hasActionButton    = YES;
-            notification.actionButtonTitle  = [NSString stringWithUTF8String:_("Skip")];
-
-            // Private APIs to set cover image, see rdar://23148801
-            // and show action button, see rdar://23148733
-            [notification setValue:coverImage forKey:@"_identityImage"];
-            [notification setValue:@(YES) forKey:@"_showsButtons"];
-            [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
-            [notification release];
-#endif
-        }
-
-        // Release stuff
-        [coverImage release];
-    }
-}
-
-/*****************************************************************************
- * Delegate methods
- *****************************************************************************/
-- (NSDictionary *)registrationDictionaryForGrowl
-{
-    return registrationDictionary;
-}
-
-- (NSString *)applicationNameForGrowl
-{
-    return applicationName;
-}
-
-- (void)applicationActiveChange:(NSNotification *)n {
-    if (n.name == NSApplicationDidBecomeActiveNotification)
-        isInForeground = YES;
-    else if (n.name == NSApplicationDidResignActiveNotification)
-        isInForeground = NO;
-}
-
-#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
-- (void)userNotificationCenter:(NSUserNotificationCenter *)center
-       didActivateNotification:(NSUserNotification *)notification
-{
-    if (notification.activationType == NSUserNotificationActivationTypeActionButtonClicked) {
-        playlist_Next(pl_Get(interfaceThread));
-    }
-}
-
-- (void)userNotificationCenter:(NSUserNotificationCenter *)center
-        didDeliverNotification:(NSUserNotification *)notification
-{
-    // Only keep the most recent notification in the Notification Center
-    if (lastNotification) {
-        [center removeDeliveredNotification: (NSUserNotification *)lastNotification];
-        [lastNotification release];
-    }
-    [notification retain];
-    lastNotification = notification;
-}
-
-- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
-     shouldPresentNotification:(NSUserNotification *)notification
-{
-    // Show notifications regardless if App in foreground or background
-    return YES;
-}
-#endif
-@end
diff --git a/modules/notify/osx_notifications.m b/modules/notify/osx_notifications.m
new file mode 100644 (file)
index 0000000..73bcd9e
--- /dev/null
@@ -0,0 +1,485 @@
+/*****************************************************************************
+ * osx_notifications.m : OS X notification plugin
+ *****************************************************************************
+ * VLC specific code:
+ *
+ * Copyright © 2008,2011,2012,2015 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Rafaël Carré <funman@videolanorg>
+ *          Felix Paul Kühne <fkuehne@videolan.org
+ *          Marvin Scholz <epirat07@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *
+ * ---
+ *
+ * Growl specific code, ripped from growlnotify:
+ *
+ * Copyright (c) The Growl Project, 2004-2005
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Growl nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#import <Foundation/Foundation.h>
+#import <Cocoa/Cocoa.h>
+#import <Growl/Growl.h>
+
+#define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_playlist.h>
+#include <vlc_input.h>
+#include <vlc_meta.h>
+#include <vlc_interface.h>
+#include <vlc_url.h>
+
+/*****************************************************************************
+ * intf_sys_t, VLCGrowlDelegate
+ *****************************************************************************/
+@interface VLCGrowlDelegate : NSObject <GrowlApplicationBridgeDelegate>
+{
+    NSString *applicationName;
+    NSString *notificationType;
+    NSMutableDictionary *registrationDictionary;
+    id lastNotification;
+    BOOL isInForeground;
+    intf_thread_t *interfaceThread;
+}
+
+- (id)initWithInterfaceThread:(intf_thread_t *)thread;
+- (void)registerToGrowl;
+- (void)notifyWithTitle:(const char *)title
+                 artist:(const char *)artist
+                  album:(const char *)album
+              andArtUrl:(const char *)url;
+@end
+
+struct intf_sys_t
+{
+    VLCGrowlDelegate *o_growl_delegate;
+    int             i_id;
+    int             i_item_changes;
+};
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Open    ( vlc_object_t * );
+static void Close   ( vlc_object_t * );
+
+static int ItemChange( vlc_object_t *, const char *,
+                      vlc_value_t, vlc_value_t, void * );
+
+/*****************************************************************************
+ * Module descriptor
+ ****************************************************************************/
+
+vlc_module_begin ()
+set_category( CAT_INTERFACE )
+set_subcategory( SUBCAT_INTERFACE_CONTROL )
+set_shortname( "OSX-Notifications" )
+add_shortcut( "growl" )
+set_description( N_("OS X Notification Plugin") )
+set_capability( "interface", 0 )
+set_callbacks( Open, Close )
+vlc_module_end ()
+
+/*****************************************************************************
+ * Open: initialize and create stuff
+ *****************************************************************************/
+static int Open( vlc_object_t *p_this )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)p_this;
+    playlist_t *p_playlist;
+    intf_sys_t    *p_sys;
+
+    p_sys = p_intf->p_sys = calloc( 1, sizeof(intf_sys_t) );
+    if( !p_sys )
+        return VLC_ENOMEM;
+
+    p_sys->o_growl_delegate = [[VLCGrowlDelegate alloc] initWithInterfaceThread:p_intf];
+    if( !p_sys->o_growl_delegate )
+      return VLC_ENOMEM;
+
+    p_playlist = pl_Get( p_intf );
+    var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
+    var_AddCallback( p_playlist, "input-current", ItemChange, p_intf );
+
+    [p_sys->o_growl_delegate registerToGrowl];
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Close: destroy interface stuff
+ *****************************************************************************/
+static void Close( vlc_object_t *p_this )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)p_this;
+    playlist_t *p_playlist = pl_Get( p_intf );
+    intf_sys_t *p_sys = p_intf->p_sys;
+
+    var_DelCallback( p_playlist, "item-change", ItemChange, p_intf );
+    var_DelCallback( p_playlist, "input-current", ItemChange, p_intf );
+
+    [GrowlApplicationBridge setGrowlDelegate:nil];
+    [p_sys->o_growl_delegate release];
+    free( p_sys );
+}
+
+/*****************************************************************************
+ * ItemChange: Playlist item change callback
+ *****************************************************************************/
+static int ItemChange( vlc_object_t *p_this, const char *psz_var,
+                      vlc_value_t oldval, vlc_value_t newval, void *param )
+{
+    VLC_UNUSED(oldval);
+
+    intf_thread_t *p_intf = (intf_thread_t *)param;
+    char *psz_tmp           = NULL;
+    char *psz_title         = NULL;
+    char *psz_artist        = NULL;
+    char *psz_album         = NULL;
+    input_item_t *p_item = newval.p_address;
+
+    bool b_is_item_current = !strcmp( "input-current", psz_var );
+
+    /* Don't update each time an item has been preparsed */
+    if( b_is_item_current )
+    { /* stores the current input item id */
+        input_thread_t *p_input = newval.p_address;
+        if( !p_input )
+            return VLC_SUCCESS;
+
+        p_item = input_GetItem( p_input );
+        if( p_intf->p_sys->i_id != p_item->i_id )
+        {
+            p_intf->p_sys->i_id = p_item->i_id;
+            p_intf->p_sys->i_item_changes = 0;
+        }
+
+        return VLC_SUCCESS;
+    }
+    /* ignore items which weren't pre-parsed yet */
+    else if( !input_item_IsPreparsed(p_item) )
+        return VLC_SUCCESS;
+    else
+    {   /* "item-change" */
+        if( p_item->i_id != p_intf->p_sys->i_id )
+            return VLC_SUCCESS;
+
+        /* Some variable bitrate inputs call "item-change" callbacks each time
+         * their length is updated, that is several times per second.
+         * We'll limit the number of changes to 1 per input. */
+        if( p_intf->p_sys->i_item_changes > 0 )
+            return VLC_SUCCESS;
+
+        p_intf->p_sys->i_item_changes++;
+    }
+
+    /* Playing something ... */
+    if( input_item_GetNowPlayingFb( p_item ) )
+        psz_title = input_item_GetNowPlayingFb( p_item );
+    else
+        psz_title = input_item_GetTitleFbName( p_item );
+    if( EMPTY_STR( psz_title ) )
+    {
+        free( psz_title );
+        return VLC_SUCCESS;
+    }
+
+    psz_artist = input_item_GetArtist( p_item );
+    if( EMPTY_STR( psz_artist ) ) FREENULL( psz_artist );
+    psz_album = input_item_GetAlbum( p_item ) ;
+    if( EMPTY_STR( psz_album ) ) FREENULL( psz_album );
+
+    int i_ret;
+    if( psz_artist && psz_album )
+        i_ret = asprintf( &psz_tmp, "%s\n%s [%s]",
+                         psz_title, psz_artist, psz_album );
+    else if( psz_artist )
+        i_ret = asprintf( &psz_tmp, "%s\n%s", psz_title, psz_artist );
+    else
+        i_ret = asprintf(&psz_tmp, "%s", psz_title );
+
+    if( i_ret == -1 )
+    {
+        free( psz_title );
+        free( psz_artist );
+        free( psz_album );
+        return VLC_ENOMEM;
+    }
+
+    char *psz_arturl = input_item_GetArtURL( p_item );
+    if( psz_arturl )
+    {
+        char *psz = make_path( psz_arturl );
+        free( psz_arturl );
+        psz_arturl = psz;
+    }
+
+    [p_intf->p_sys->o_growl_delegate notifyWithTitle:psz_title
+                                              artist:psz_artist
+                                               album:psz_album
+                                           andArtUrl:psz_arturl];
+
+    free( psz_title );
+    free( psz_artist );
+    free( psz_album );
+    free( psz_arturl );
+    free( psz_tmp );
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * VLCGrowlDelegate
+ *****************************************************************************/
+@implementation VLCGrowlDelegate
+
+- (id)initWithInterfaceThread:(intf_thread_t *)thread {
+    if( !( self = [super init] ) )
+        return nil;
+
+    applicationName = nil;
+    notificationType = nil;
+    registrationDictionary = nil;
+    interfaceThread = thread;
+
+    // Assume we start in foreground
+    isInForeground = YES;
+
+    // Subscribe to notifications to determine if VLC is in foreground or not
+    @autoreleasepool {
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(applicationActiveChange:)
+                                                     name:NSApplicationDidBecomeActiveNotification
+                                                   object:nil];
+
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(applicationActiveChange:)
+                                                     name:NSApplicationDidResignActiveNotification
+                                                   object:nil];
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+    // Clear the remaining lastNotification in Notification Center, if any
+    @autoreleasepool {
+        if (lastNotification) {
+            [NSUserNotificationCenter.defaultUserNotificationCenter
+             removeDeliveredNotification:(NSUserNotification *)lastNotification];
+            [lastNotification release];
+        }
+        [[NSNotificationCenter defaultCenter] removeObserver:self];
+    }
+#endif
+
+    // Release everything
+    [applicationName release];
+    [notificationType release];
+    [registrationDictionary release];
+    [super dealloc];
+}
+
+- (void)registerToGrowl
+{
+    @autoreleasepool {
+        applicationName = [[NSString alloc] initWithUTF8String:_( "VLC media player" )];
+        notificationType = [[NSString alloc] initWithUTF8String:_( "New input playing" )];
+
+        NSArray *defaultAndAllNotifications = [NSArray arrayWithObject: notificationType];
+        registrationDictionary = [[NSMutableDictionary alloc] init];
+        [registrationDictionary setObject:defaultAndAllNotifications
+                                   forKey:GROWL_NOTIFICATIONS_ALL];
+        [registrationDictionary setObject:defaultAndAllNotifications
+                                   forKey: GROWL_NOTIFICATIONS_DEFAULT];
+
+        [GrowlApplicationBridge setGrowlDelegate:self];
+
+#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+        [[NSUserNotificationCenter defaultUserNotificationCenter]
+         setDelegate:(id<NSUserNotificationCenterDelegate>)self];
+#endif
+    }
+}
+
+- (void)notifyWithTitle:(const char *)title
+                 artist:(const char *)artist
+                  album:(const char *)album
+              andArtUrl:(const char *)url
+{
+    @autoreleasepool {
+        // Init Cover
+        NSData *coverImageData = nil;
+        NSImage *coverImage = nil;
+
+        if (url) {
+            coverImageData = [NSData dataWithContentsOfFile:[NSString stringWithUTF8String:url]];
+            coverImage = [[NSImage alloc] initWithData:coverImageData];
+        }
+
+        // Init Track info
+        NSString *titleStr = nil;
+        NSString *artistStr = nil;
+        NSString *albumStr = nil;
+
+        if (title) {
+            titleStr = [NSString stringWithUTF8String:title];
+        } else {
+            // Without title, notification makes no sense, so return here
+            // title should never be empty, but better check than crash.
+            return;
+        }
+        if (artist)
+            artistStr = [NSString stringWithUTF8String:artist];
+        if (album)
+            albumStr = [NSString stringWithUTF8String:album];
+
+        // Notification stuff
+        if ([GrowlApplicationBridge isGrowlRunning]) {
+            // Make the Growl notification string
+            NSString *desc = nil;
+
+            if (artistStr && albumStr) {
+                desc = [NSString stringWithFormat:@"%@\n%@ [%@]", titleStr, artistStr, albumStr];
+            } else if (artistStr) {
+                desc = [NSString stringWithFormat:@"%@\n%@", titleStr, artistStr];
+            } else {
+                desc = titleStr;
+            }
+
+            // Send notification
+            [GrowlApplicationBridge notifyWithTitle:[NSString stringWithUTF8String:_("Now playing")]
+                                        description:desc
+                                   notificationName:notificationType
+                                           iconData:coverImageData
+                                           priority:0
+                                           isSticky:NO
+                                       clickContext:nil];
+        } else {
+#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+            // Make the OS X notification and string
+            NSUserNotification *notification = [NSUserNotification new];
+            NSString *desc = nil;
+
+            if (artistStr && albumStr) {
+                desc = [NSString stringWithFormat:@"%@ – %@", artistStr, albumStr];
+            } else if (artistStr) {
+                desc = artistStr;
+            }
+
+            notification.title              = titleStr;
+            notification.subtitle           = desc;
+            notification.hasActionButton    = YES;
+            notification.actionButtonTitle  = [NSString stringWithUTF8String:_("Skip")];
+
+            // Private APIs to set cover image, see rdar://23148801
+            // and show action button, see rdar://23148733
+            [notification setValue:coverImage forKey:@"_identityImage"];
+            [notification setValue:@(YES) forKey:@"_showsButtons"];
+            [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
+            [notification release];
+#endif
+        }
+
+        // Release stuff
+        [coverImage release];
+    }
+}
+
+/*****************************************************************************
+ * Delegate methods
+ *****************************************************************************/
+- (NSDictionary *)registrationDictionaryForGrowl
+{
+    return registrationDictionary;
+}
+
+- (NSString *)applicationNameForGrowl
+{
+    return applicationName;
+}
+
+- (void)applicationActiveChange:(NSNotification *)n {
+    if (n.name == NSApplicationDidBecomeActiveNotification)
+        isInForeground = YES;
+    else if (n.name == NSApplicationDidResignActiveNotification)
+        isInForeground = NO;
+}
+
+#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+- (void)userNotificationCenter:(NSUserNotificationCenter *)center
+       didActivateNotification:(NSUserNotification *)notification
+{
+    if (notification.activationType == NSUserNotificationActivationTypeActionButtonClicked) {
+        playlist_Next(pl_Get(interfaceThread));
+    }
+}
+
+- (void)userNotificationCenter:(NSUserNotificationCenter *)center
+        didDeliverNotification:(NSUserNotification *)notification
+{
+    // Only keep the most recent notification in the Notification Center
+    if (lastNotification) {
+        [center removeDeliveredNotification: (NSUserNotification *)lastNotification];
+        [lastNotification release];
+    }
+    [notification retain];
+    lastNotification = notification;
+}
+
+- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
+     shouldPresentNotification:(NSUserNotification *)notification
+{
+    // Show notifications regardless if App in foreground or background
+    return YES;
+}
+#endif
+@end
index a5b21c8..c8bebfd 100644 (file)
@@ -1005,7 +1005,7 @@ modules/mux/mpeg/ts.c
 modules/mux/mpjpeg.c
 modules/mux/ogg.c
 modules/mux/wav.c
-modules/notify/growl.m
+modules/notify/osx_notifications.m
 modules/notify/notify.c
 modules/packetizer/avparser.h
 modules/packetizer/copy.c