Cache notifications until the handlers are ready, stop sounds through reference

cusax-fix
Ingo Bauersachs 14 years ago
parent c543e54197
commit 1f7765cd81

@ -916,7 +916,8 @@
bundle-systemactivitynotifications,
bundle-osdependent,bundle-browserlauncher,
bundle-pluginmanager,bundle-skinmanager,
bundle-notification-service,bundle-notification-handlers,bundle-notification-config,
bundle-notification-service,bundle-notification-handlers,
bundle-notification-wiring,bundle-notification-config,
bundle-contacteventhandler,
bundle-plugin-contactinfo,bundle-plugin-chatalerter, bundle-keybindings,
bundle-plugin-keybindingChooser,bundle-plugin-globalproxyconfig,
@ -2060,6 +2061,7 @@ javax.swing.event, javax.swing.border"/>
</jar>
</target>
<!-- BUNDLE-NOTIFICATION-HANDLERS -->
<target name="bundle-notification-handlers">
<!-- Creates a bundle for the notifications.-->
<jar compress="false" destfile="${bundles.dest}/notification-handlers.jar"
@ -2069,6 +2071,16 @@ javax.swing.event, javax.swing.border"/>
</jar>
</target>
<!-- BUNDLE-NOTIFICATION-WIRING -->
<target name="bundle-notification-wiring">
<!-- Creates a bundle for the notifications.-->
<jar compress="false" destfile="${bundles.dest}/notification-wiring.jar"
manifest="${src}/net/java/sip/communicator/plugin/notificationwiring/notificationwiring.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/plugin/notificationwiring"
prefix="net/java/sip/communicator/plugin/notificationwiring"/>
</jar>
</target>
<!-- BUNDLE-PLUGIN-WHITEBOARD -->
<target name="bundle-plugin-whiteboard">
<!-- Creates a bundle for the Whiteboard plugin.-->

@ -109,7 +109,6 @@ felix.auto.start.60= \
reference:file:sc-bundles/filehistory.jar \
reference:file:sc-bundles/metahistory.jar \
reference:file:sc-bundles/keybindings.jar \
reference:file:sc-bundles/notification-handlers.jar \
reference:file:sc-bundles/contactsource.jar
felix.auto.start.66= \
@ -133,6 +132,8 @@ felix.auto.start.67= \
reference:file:sc-bundles/yahooaccregwizz.jar \
reference:file:sc-bundles/contacteventhandler.jar \
reference:file:sc-bundles/notificationconfig.jar \
reference:file:sc-bundles/notification-handlers.jar \
reference:file:sc-bundles/notification-wiring.jar \
reference:file:sc-bundles/contactinfo.jar \
reference:file:sc-bundles/chatalerter.jar \
reference:file:sc-bundles/keybindingChooser.jar \

@ -101,7 +101,7 @@ felix.auto.start.60= \
reference:file:sc-bundles/callhistory.jar \
reference:file:sc-bundles/filehistory.jar \
reference:file:sc-bundles/metahistory.jar \
reference:file:sc-bundles/notification.jar \
reference:file:sc-bundles/notification-service.jar \
reference:file:sc-bundles/plugin-nimbuzzavatars.jar \
reference:file:sc-bundles/osdependent.jar

@ -7,10 +7,7 @@
package net.java.sip.communicator.impl.notification;
import net.java.sip.communicator.service.audionotifier.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.neomedia.*;
import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.service.systray.*;
import net.java.sip.communicator.util.*;
@ -25,16 +22,14 @@
public class NotificationActivator
implements BundleActivator
{
private final Logger logger = Logger.getLogger(NotificationActivator.class);
private final Logger logger =
Logger.getLogger(NotificationActivator.class);
protected static BundleContext bundleContext;
private static AudioNotifierService audioNotifierService;
private static SystrayService systrayService;
private static NotificationService notificationService;
private static ResourceManagementService resourcesService;
private static UIService uiService = null;
private static MediaService mediaService;
private CommandNotificationHandler commandHandler;
private LogMessageNotificationHandler logMessageHandler;
@ -67,8 +62,6 @@ public void start(BundleContext bc) throws Exception
notificationService.addActionHandler(popupMessageHandler);
notificationService.addActionHandler(soundHandler);
new NotificationManager().init();
logger.info("Notification handler Service ...[REGISTERED]");
}
finally
@ -79,10 +72,14 @@ public void start(BundleContext bc) throws Exception
public void stop(BundleContext bc) throws Exception
{
notificationService.removeActionHandler(commandHandler.getActionType());
notificationService.removeActionHandler(logMessageHandler.getActionType());
notificationService.removeActionHandler(popupMessageHandler.getActionType());
notificationService.removeActionHandler(soundHandler.getActionType());
notificationService.removeActionHandler(
commandHandler.getActionType());
notificationService.removeActionHandler(
logMessageHandler.getActionType());
notificationService.removeActionHandler(
popupMessageHandler.getActionType());
notificationService.removeActionHandler(
soundHandler.getActionType());
logger.info("Notification handler Service ...[STOPPED]");
}
@ -128,63 +125,4 @@ public static SystrayService getSystray()
return systrayService;
}
/**
* Returns the <tt>NotificationService</tt> obtained from the bundle context.
*
* @return the <tt>NotificationService</tt> obtained from the bundle context
*/
public static NotificationService getNotificationService()
{
return notificationService;
}
/**
* Returns the <tt>ResourceManagementService</tt>, through which we will
* access all resources.
*
* @return the <tt>ResourceManagementService</tt>, through which we will
* access all resources.
*/
public static ResourceManagementService getResources()
{
if (resourcesService == null)
{
resourcesService
= ServiceUtils.getService(
bundleContext,
ResourceManagementService.class);
}
return resourcesService;
}
/**
* Returns the current implementation of the <tt>UIService</tt>.
* @return the current implementation of the <tt>UIService</tt>
*/
public static UIService getUIService()
{
if (uiService == null)
{
uiService = ServiceUtils.getService(bundleContext, UIService.class);
}
return uiService;
}
/**
* Returns an instance of the <tt>MediaService</tt> obtained from the
* bundle context.
* @return an instance of the <tt>MediaService</tt> obtained from the
* bundle context
*/
public static MediaService getMediaService()
{
if (mediaService == null)
{
mediaService
= ServiceUtils.getService(bundleContext, MediaService.class);
}
return mediaService;
}
}

@ -6,22 +6,22 @@
*/
package net.java.sip.communicator.impl.notification;
import java.util.*;
import net.java.sip.communicator.service.audionotifier.*;
import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.util.*;
/**
* An implementation of the <tt>SoundNotificationHandlerImpl</tt> interface.
* An implementation of the <tt>SoundNotificationHandler</tt> interface.
*
* @author Yana Stamcheva
*/
public class SoundNotificationHandlerImpl
implements SoundNotificationHandler
{
/**
* The audio clip that manages to play the sound.
*/
private SCAudioClip audio;
WeakHashMap<SCAudioClip, NotificationData> playedClips =
new WeakHashMap<SCAudioClip, NotificationData>();
/**
* {@inheritDoc}
@ -34,9 +34,10 @@ public String getActionType()
/**
* Plays the sound given by the containing <tt>soundFileDescriptor</tt>. The
* sound is played in loop if the loopInterval is defined.
* @param action the action to act upon.
* @param action The action to act upon.
* @param data Additional data for the event.
*/
public void start(SoundNotificationAction action)
public void start(SoundNotificationAction action, NotificationData data)
{
AudioNotifierService audioNotifService
= NotificationActivator.getAudioNotifier();
@ -45,18 +46,13 @@ public void start(SoundNotificationAction action)
|| StringUtils.isNullOrEmpty(action.getDescriptor(), true))
return;
//stop any previous audio notification
if(audio != null)
{
stop();
}
audio = audioNotifService.createAudio(action.getDescriptor());
SCAudioClip audio = audioNotifService.createAudio(action.getDescriptor());
// it is possible that audio cannot be created
if(audio == null)
return;
playedClips.put(audio, data);
if(action.getLoopInterval() > -1)
audio.playInLoop(action.getLoopInterval());
else
@ -65,17 +61,26 @@ public void start(SoundNotificationAction action)
/**
* Stops the sound.
* @param data Additional data for the event.
*/
public void stop()
public void stop(NotificationData data)
{
AudioNotifierService audioNotifService
= NotificationActivator.getAudioNotifier();
if(audioNotifService == null || audio == null)
if(audioNotifService == null)
return;
audio.stop();
audioNotifService.destroyAudio(audio);
audio = null;
for (Map.Entry<SCAudioClip, NotificationData> entry : playedClips
.entrySet())
{
if(entry.getValue() == data)
{
SCAudioClip audio = entry.getKey();
audio.stop();
audioNotifService.destroyAudio(audio);
return;
}
}
}
}

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.notification;
package net.java.sip.communicator.plugin.notificationwiring;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
@ -68,6 +68,13 @@ public class NotificationManager
*/
private Map<Contact,Long> proactiveTimer = new HashMap<Contact, Long>();
/**
* Stores notification references to stop them if a notification has expired
* (e.g. to stop the dialing sound).
*/
private Map<Call, NotificationData> callNotifications =
new WeakHashMap<Call, NotificationData>();
/**
* Default event type for call been saved using a recorder.
*/
@ -138,7 +145,7 @@ void init()
registerDefaultNotifications();
// listens for new protocols
NotificationActivator.bundleContext.addServiceListener(this);
NotificationWiringActivator.bundleContext.addServiceListener(this);
// enumerate currently registered protocols
for(ProtocolProviderService pp : getProtocolProviders())
@ -146,7 +153,7 @@ void init()
handleProviderAdded(pp);
}
NotificationActivator.getMediaService().addRecorderListener(this);
NotificationWiringActivator.getMediaService().addRecorderListener(this);
}
/**
@ -155,27 +162,27 @@ void init()
private void registerDefaultNotifications()
{
NotificationService notificationService
= NotificationActivator.getNotificationService();
= NotificationWiringActivator.getNotificationService();
if(notificationService == null)
return;
// Register incoming message notifications.
notificationService.registerDefaultNotificationForEvent(
NotificationManager.INCOMING_MESSAGE,
INCOMING_MESSAGE,
NotificationAction.ACTION_POPUP_MESSAGE,
null,
null);
notificationService.registerDefaultNotificationForEvent(
NotificationManager.INCOMING_MESSAGE,
INCOMING_MESSAGE,
NotificationAction.ACTION_SOUND,
SoundProperties.INCOMING_MESSAGE,
null);
// Register incoming call notifications.
notificationService.registerDefaultNotificationForEvent(
NotificationManager.INCOMING_CALL,
INCOMING_CALL,
NotificationAction.ACTION_POPUP_MESSAGE,
null,
null);
@ -184,7 +191,7 @@ private void registerDefaultNotifications()
= new SoundNotificationAction(SoundProperties.INCOMING_CALL, 2000);
notificationService.registerDefaultNotificationForEvent(
NotificationManager.INCOMING_CALL,
INCOMING_CALL,
inCallSoundHandler);
// Register outgoing call notifications.
@ -192,7 +199,7 @@ private void registerDefaultNotifications()
= new SoundNotificationAction(SoundProperties.OUTGOING_CALL, 3000);
notificationService.registerDefaultNotificationForEvent(
NotificationManager.OUTGOING_CALL,
OUTGOING_CALL,
outCallSoundHandler);
// Register busy call notifications.
@ -200,7 +207,7 @@ private void registerDefaultNotifications()
= new SoundNotificationAction(SoundProperties.BUSY, 1);
notificationService.registerDefaultNotificationForEvent(
NotificationManager.BUSY_CALL,
BUSY_CALL,
busyCallSoundHandler);
// Register dial notifications.
@ -208,7 +215,7 @@ private void registerDefaultNotifications()
= new SoundNotificationAction(SoundProperties.DIALING, 0);
notificationService.registerDefaultNotificationForEvent(
NotificationManager.DIALING,
DIALING,
dialSoundHandler);
// Register the hangup sound notification.
@ -216,53 +223,53 @@ private void registerDefaultNotifications()
= new SoundNotificationAction(SoundProperties.HANG_UP, -1);
notificationService.registerDefaultNotificationForEvent(
NotificationManager.HANG_UP,
HANG_UP,
hangupSoundHandler);
// Register proactive notifications.
notificationService.registerDefaultNotificationForEvent(
NotificationManager.PROACTIVE_NOTIFICATION,
PROACTIVE_NOTIFICATION,
NotificationAction.ACTION_POPUP_MESSAGE,
null,
null);
// Register warning message notifications.
notificationService.registerDefaultNotificationForEvent(
NotificationManager.SECURITY_MESSAGE,
SECURITY_MESSAGE,
NotificationAction.ACTION_POPUP_MESSAGE,
null,
null);
// Register sound notification for security state on during a call.
notificationService.registerDefaultNotificationForEvent(
NotificationManager.CALL_SECURITY_ON,
CALL_SECURITY_ON,
NotificationAction.ACTION_SOUND,
SoundProperties.CALL_SECURITY_ON,
null);
// Register sound notification for security state off during a call.
notificationService.registerDefaultNotificationForEvent(
NotificationManager.CALL_SECURITY_ERROR,
CALL_SECURITY_ERROR,
NotificationAction.ACTION_SOUND,
SoundProperties.CALL_SECURITY_ERROR,
null);
// Register sound notification for incoming files.
notificationService.registerDefaultNotificationForEvent(
NotificationManager.INCOMING_FILE,
INCOMING_FILE,
NotificationAction.ACTION_POPUP_MESSAGE,
null,
null);
notificationService.registerDefaultNotificationForEvent(
NotificationManager.INCOMING_FILE,
INCOMING_FILE,
NotificationAction.ACTION_SOUND,
SoundProperties.INCOMING_FILE,
null);
// Register notification for saved calls.
notificationService.registerDefaultNotificationForEvent(
NotificationManager.CALL_SAVED,
CALL_SAVED,
NotificationAction.ACTION_POPUP_MESSAGE,
null,
null);
@ -283,7 +290,7 @@ private void registerDefaultNotifications()
{
// get all registered provider factories
serRefs
= NotificationActivator.bundleContext.getServiceReferences(
= NotificationWiringActivator.bundleContext.getServiceReferences(
ProtocolProviderFactory.class.getName(),
null);
}
@ -301,7 +308,7 @@ private void registerDefaultNotifications()
{
ProtocolProviderFactory providerFactory
= (ProtocolProviderFactory)
NotificationActivator.bundleContext.getService(serRef);
NotificationWiringActivator.bundleContext.getService(serRef);
providerFactoriesMap.put(
serRef.getProperty(ProtocolProviderFactory.PROTOCOL),
@ -323,7 +330,7 @@ private void registerDefaultNotifications()
{
// get all registered provider factories
serRefs
= NotificationActivator.bundleContext.getServiceReferences(
= NotificationWiringActivator.bundleContext.getServiceReferences(
ProtocolProviderService.class.getName(),
null);
}
@ -341,7 +348,7 @@ private void registerDefaultNotifications()
{
ProtocolProviderService pp
= (ProtocolProviderService)
NotificationActivator.bundleContext.getService(serRef);
NotificationWiringActivator.bundleContext.getService(serRef);
providersList.add(pp);
}
@ -521,7 +528,7 @@ public void serviceChanged(ServiceEvent event)
}
Object service =
NotificationActivator.bundleContext.getService(serviceRef);
NotificationWiringActivator.bundleContext.getService(serviceRef);
// we don't care if the source service is not a protocol provider
if (!(service instanceof ProtocolProviderService))
@ -547,18 +554,19 @@ public void serviceChanged(ServiceEvent event)
* @param eventType the event type for which we fire a notification
* @param messageTitle the title of the message
* @param message the content of the message
* @return A reference to the fired notification to stop it.
*/
public static void fireNotification(String eventType,
public static NotificationData fireNotification(String eventType,
String messageTitle,
String message)
{
NotificationService notificationService
= NotificationActivator.getNotificationService();
= NotificationWiringActivator.getNotificationService();
if(notificationService == null)
return;
return null;
notificationService.fireNotification( eventType,
return notificationService.fireNotification( eventType,
messageTitle,
message,
null,
@ -581,13 +589,13 @@ public static void fireChatNotification(Object chatContact,
String message)
{
NotificationService notificationService
= NotificationActivator.getNotificationService();
= NotificationWiringActivator.getNotificationService();
if(notificationService == null)
return;
NotificationAction popupActionHandler = null;
UIService uiService = NotificationActivator.getUIService();
UIService uiService = NotificationWiringActivator.getUIService();
Chat chatPanel = null;
byte[] contactIcon = null;
@ -619,7 +627,7 @@ else if (chatContact instanceof ChatRoom)
if (chatPanel != null)
{
if (eventType.equals(NotificationManager.INCOMING_MESSAGE)
if (eventType.equals(INCOMING_MESSAGE)
&& chatPanel.isChatFocused())
{
popupActionHandler = notificationService
@ -646,28 +654,29 @@ else if (chatContact instanceof ChatRoom)
* constants defined in this class.
*
* @param eventType the event type for which we want to fire a notification
* @return A reference to the fired notification to stop it.
*/
public static void fireNotification(String eventType)
public static NotificationData fireNotification(String eventType)
{
NotificationService notificationService
= NotificationActivator.getNotificationService();
= NotificationWiringActivator.getNotificationService();
if(notificationService == null)
return;
return null;
notificationService.fireNotification(eventType);
return notificationService.fireNotification(eventType);
}
/**
* Stops all sounds for the given event type.
*
* @param eventType the event type for which we should stop sounds. One of
* @param notificationData the event type for which we should stop sounds. One of
* the static event types defined in this class.
*/
public static void stopSound(String eventType)
public static void stopSound(NotificationData data)
{
NotificationService notificationService
= NotificationActivator.getNotificationService();
= NotificationWiringActivator.getNotificationService();
if(notificationService == null)
return;
@ -676,11 +685,10 @@ public static void stopSound(String eventType)
notificationService.getActionHandlers(
NotificationAction.ACTION_SOUND);
//TODO make SoundNotificationHandler handle multiple sound at once
// There can be no sound action handler for this event type
// There could be no sound action handler for this event type
if(soundHandlers != null)
for(NotificationHandler handler : soundHandlers)
((SoundNotificationHandler)handler).stop();
((SoundNotificationHandler)handler).stop(data);
}
/**
@ -699,7 +707,7 @@ public static BufferedImage getImage(ImageID imageID)
}
else
{
URL path = NotificationActivator.getResources()
URL path = NotificationWiringActivator.getResources()
.getImageURL(imageID.getId());
if (path != null)
@ -720,17 +728,6 @@ public static BufferedImage getImage(ImageID imageID)
return image;
}
/**
* Stops all telephony related sounds.
*/
private static void stopAllTelephonySounds()
{
NotificationManager.stopSound(NotificationManager.DIALING);
NotificationManager.stopSound(NotificationManager.BUSY_CALL);
NotificationManager.stopSound(NotificationManager.INCOMING_CALL);
NotificationManager.stopSound(NotificationManager.OUTGOING_CALL);
}
/**
* Checks if the contained call is a conference call.
*
@ -807,13 +804,13 @@ public void messageReceived(MessageReceivedEvent evt)
try
{
// Fire notification
String title = NotificationActivator.getResources().getI18NString(
String title = NotificationWiringActivator.getResources().getI18NString(
"service.gui.MSG_RECEIVED",
new String[]{evt.getSourceContact().getDisplayName()});
fireChatNotification(
evt.getSourceContact(),
NotificationManager.INCOMING_MESSAGE,
INCOMING_MESSAGE,
title,
evt.getSourceMessage().getContent());
}
@ -853,14 +850,13 @@ public void fileTransferRequestReceived(FileTransferRequestEvent event)
Contact sourceContact = request.getSender();
//Fire notification
String title = NotificationActivator.getResources().getI18NString(
String title = NotificationWiringActivator.getResources().getI18NString(
"service.gui.FILE_RECEIVING_FROM",
new String[]{sourceContact.getDisplayName()});
NotificationManager
.fireChatNotification(
fireChatNotification(
sourceContact,
NotificationManager.INCOMING_FILE,
INCOMING_FILE,
title,
request.getFileName());
}
@ -912,7 +908,7 @@ public void typingNotificationReceived(TypingNotificationEvent event)
// check whether the current chat window shows the
// chat we received a typing info for and in such case don't show
// notifications
UIService uiService = NotificationActivator.getUIService();
UIService uiService = NotificationWiringActivator.getUIService();
if(uiService != null)
{
@ -958,11 +954,11 @@ public void typingNotificationReceived(TypingNotificationEvent event)
this.proactiveTimer.put(contact, currentTime);
NotificationManager.fireChatNotification(
fireChatNotification(
contact,
NotificationManager.PROACTIVE_NOTIFICATION,
PROACTIVE_NOTIFICATION,
contact.getDisplayName(),
NotificationActivator.getResources()
NotificationWiringActivator.getResources()
.getI18NString("service.gui.PROACTIVE_NOTIFICATION"));
}
catch(Throwable t)
@ -984,12 +980,13 @@ public void incomingCallReceived(CallEvent event)
String peerName = event.getSourceCall()
.getCallPeers().next().getDisplayName();
NotificationManager.fireNotification(
NotificationManager.INCOMING_CALL,
callNotifications.put(event.getSourceCall(),
fireNotification(
INCOMING_CALL,
"",
NotificationActivator.getResources()
NotificationWiringActivator.getResources()
.getI18NString("service.gui.INCOMING_CALL",
new String[]{peerName}));
new String[]{peerName})));
call.addCallChangeListener(this);
@ -1035,10 +1032,11 @@ public void callEnded(CallEvent event)
try
{
// Stop all telephony related sounds.
stopAllTelephonySounds();
// stopAllTelephonySounds();
stopSound(callNotifications.get(event.getSourceCall()));
// Play the hangup sound.
NotificationManager.fireNotification(NotificationManager.HANG_UP);
fireNotification(HANG_UP);
}
catch(Throwable t)
{
@ -1096,6 +1094,7 @@ public void peerStateChanged(CallPeerChangeEvent evt)
try
{
CallPeer sourcePeer = evt.getSourceCallPeer();
Call call = sourcePeer.getCall();
CallPeerState newState = (CallPeerState) evt.getNewValue();
CallPeerState oldState = (CallPeerState) evt.getOldValue();
@ -1104,12 +1103,11 @@ public void peerStateChanged(CallPeerChangeEvent evt)
if (newState == CallPeerState.INITIATING_CALL
|| newState == CallPeerState.CONNECTING)
{
NotificationManager
.fireNotification(NotificationManager.DIALING);
callNotifications.put(call, fireNotification(DIALING));
}
else
{
NotificationManager.stopSound(NotificationManager.DIALING);
stopSound(callNotifications.get(call));
}
if (newState == CallPeerState.ALERTING_REMOTE_SIDE
@ -1118,54 +1116,20 @@ public void peerStateChanged(CallPeerChangeEvent evt)
//need to fire a notification here.
&& oldState != CallPeerState.CONNECTING_WITH_EARLY_MEDIA)
{
NotificationManager
.fireNotification(NotificationManager.OUTGOING_CALL);
callNotifications.put(call, fireNotification(OUTGOING_CALL));
}
else if (newState == CallPeerState.BUSY)
{
NotificationManager.stopSound(NotificationManager.OUTGOING_CALL);
// We start the busy sound only if we're in a simple call.
if (!isConference(sourcePeer.getCall()))
{
NotificationManager.fireNotification(
NotificationManager.BUSY_CALL);
}
}
else if (newState == CallPeerState.CONNECTING_INCOMING_CALL ||
newState == CallPeerState.CONNECTING_INCOMING_CALL_WITH_MEDIA)
{
if (!CallPeerState.isOnHold(oldState))
{
NotificationManager
.stopSound(NotificationManager.OUTGOING_CALL);
NotificationManager
.stopSound(NotificationManager.INCOMING_CALL);
}
}
else if (newState == CallPeerState.CONNECTING_WITH_EARLY_MEDIA)
{
//this means a call with early media. make sure that we are not
//playing local notifications any more.
NotificationManager
.stopSound(NotificationManager.OUTGOING_CALL);
}
else if (newState == CallPeerState.CONNECTED)
{
if (!CallPeerState.isOnHold(oldState))
if (!isConference(call))
{
NotificationManager
.stopSound(NotificationManager.OUTGOING_CALL);
NotificationManager
.stopSound(NotificationManager.INCOMING_CALL);
callNotifications.put(call, fireNotification(BUSY_CALL));
}
}
else if (newState == CallPeerState.DISCONNECTED
|| newState == CallPeerState.FAILED)
{
stopAllTelephonySounds();
NotificationManager.fireNotification(NotificationManager.HANG_UP);
callNotifications.put(call, fireNotification(HANG_UP));
}
}
catch(Throwable t)
@ -1220,8 +1184,7 @@ public void securityOn(CallPeerSecurityOnEvent evt)
&& peer.getProtocolProvider().isSignalingTransportSecure())
|| !evt.getSecurityController().requiresSecureSignalingTransport())
{
NotificationManager.fireNotification(
NotificationManager.CALL_SECURITY_ON);
fireNotification(CALL_SECURITY_ON);
}
}
catch(Throwable t)
@ -1254,13 +1217,13 @@ public void securityMessageRecieved(CallPeerSecurityMessageEvent event)
// Don't play alert sound for Info or warning.
case CallPeerSecurityMessageEvent.INFORMATION:
{
messageTitle = NotificationActivator.getResources()
messageTitle = NotificationWiringActivator.getResources()
.getI18NString("service.gui.SECURITY_INFO");
break;
}
case CallPeerSecurityMessageEvent.WARNING:
{
messageTitle = NotificationActivator.getResources()
messageTitle = NotificationWiringActivator.getResources()
.getI18NString("service.gui.SECURITY_WARNING");
break;
}
@ -1268,15 +1231,14 @@ public void securityMessageRecieved(CallPeerSecurityMessageEvent event)
case CallPeerSecurityMessageEvent.SEVERE:
case CallPeerSecurityMessageEvent.ERROR:
{
messageTitle = NotificationActivator.getResources()
messageTitle = NotificationWiringActivator.getResources()
.getI18NString("service.gui.SECURITY_ERROR");
NotificationManager.fireNotification(
NotificationManager.CALL_SECURITY_ERROR);
fireNotification(CALL_SECURITY_ERROR);
}
}
NotificationManager.fireNotification(
NotificationManager.SECURITY_MESSAGE,
fireNotification(
SECURITY_MESSAGE,
messageTitle,
event.getI18nMessage());
}
@ -1335,13 +1297,13 @@ public void messageReceived(ChatRoomMessageReceivedEvent evt)
if (fireChatNotification)
{
String title
= NotificationActivator.getResources().getI18NString(
= NotificationWiringActivator.getResources().getI18NString(
"service.gui.MSG_RECEIVED",
new String[] { sourceMember.getName() });
NotificationManager.fireChatNotification(
fireChatNotification(
sourceChatRoom,
NotificationManager.INCOMING_MESSAGE,
INCOMING_MESSAGE,
title,
messageContent);
}
@ -1455,13 +1417,13 @@ public void messageReceived(AdHocChatRoomMessageReceivedEvent evt)
if (fireChatNotification)
{
String title
= NotificationActivator.getResources().getI18NString(
= NotificationWiringActivator.getResources().getI18NString(
"service.gui.MSG_RECEIVED",
new String[] { sourceParticipant.getDisplayName() });
NotificationManager.fireChatNotification(
fireChatNotification(
sourceChatRoom,
NotificationManager.INCOMING_MESSAGE,
INCOMING_MESSAGE,
title,
messageContent);
}
@ -1521,8 +1483,7 @@ public void conferenceMemberAdded(CallPeerConferenceEvent conferenceEvent)
if (securityEvent instanceof CallPeerSecurityOnEvent)
{
NotificationManager.fireNotification(
NotificationManager.CALL_SECURITY_ON);
fireNotification(CALL_SECURITY_ON);
}
}
}
@ -1552,11 +1513,11 @@ public void recorderStopped(Recorder recorder)
{
try
{
NotificationManager.fireNotification(
NotificationManager.CALL_SAVED,
NotificationActivator.getResources().getI18NString(
fireNotification(
CALL_SAVED,
NotificationWiringActivator.getResources().getI18NString(
"plugin.callrecordingconfig.CALL_SAVED"),
NotificationActivator.getResources().getI18NString(
NotificationWiringActivator.getResources().getI18NString(
"plugin.callrecordingconfig.CALL_SAVED_TO",
new String[] { recorder.getFilename() }));
}

@ -0,0 +1,125 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.notificationwiring;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.neomedia.*;
import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* The <tt>NotificationActivator</tt> is the activator of the notification
* bundle.
*
* @author Yana Stamcheva
*/
public class NotificationWiringActivator
implements BundleActivator
{
private final Logger logger =
Logger.getLogger(NotificationWiringActivator.class);
protected static BundleContext bundleContext;
private static NotificationService notificationService;
private static ResourceManagementService resourcesService;
private static UIService uiService = null;
private static MediaService mediaService;
public void start(BundleContext bc) throws Exception
{
bundleContext = bc;
try
{
logger.logEntry();
logger.info("Notification wiring plugin...[ STARTED ]");
// Get the notification service implementation
ServiceReference notifReference = bundleContext
.getServiceReference(NotificationService.class.getName());
notificationService = (NotificationService) bundleContext
.getService(notifReference);
new NotificationManager().init();
logger.info("Notification wiring plugin ...[REGISTERED]");
}
finally
{
logger.logExit();
}
}
public void stop(BundleContext bc) throws Exception
{
logger.info("Notification handler Service ...[STOPPED]");
}
/**
* Returns the <tt>NotificationService</tt> obtained from the bundle context.
*
* @return the <tt>NotificationService</tt> obtained from the bundle context
*/
public static NotificationService getNotificationService()
{
return notificationService;
}
/**
* Returns the <tt>ResourceManagementService</tt>, through which we will
* access all resources.
*
* @return the <tt>ResourceManagementService</tt>, through which we will
* access all resources.
*/
public static ResourceManagementService getResources()
{
if (resourcesService == null)
{
resourcesService
= ServiceUtils.getService(
bundleContext,
ResourceManagementService.class);
}
return resourcesService;
}
/**
* Returns the current implementation of the <tt>UIService</tt>.
* @return the current implementation of the <tt>UIService</tt>
*/
public static UIService getUIService()
{
if (uiService == null)
{
uiService = ServiceUtils.getService(bundleContext, UIService.class);
}
return uiService;
}
/**
* Returns an instance of the <tt>MediaService</tt> obtained from the
* bundle context.
* @return an instance of the <tt>MediaService</tt> obtained from the
* bundle context
*/
public static MediaService getMediaService()
{
if (mediaService == null)
{
mediaService
= ServiceUtils.getService(bundleContext, MediaService.class);
}
return mediaService;
}
}

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.notification;
package net.java.sip.communicator.plugin.notificationwiring;
import net.java.sip.communicator.service.resources.*;
@ -72,7 +72,7 @@ public final class SoundProperties
* because it will be accessing a field, not a local variable).
*/
ResourceManagementService resources =
NotificationActivator.getResources();
NotificationWiringActivator.getResources();
INCOMING_MESSAGE = resources.getSoundPath("INCOMING_MESSAGE");
INCOMING_FILE = resources.getSoundPath("INCOMING_FILE");

@ -0,0 +1,16 @@
Bundle-Activator: net.java.sip.communicator.plugin.notificationwiring.NotificationWiringActivator
Bundle-Name: Notification-Wiring
Bundle-Description: Wires events from various bundles to the notification service
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
System-Bundle: yes
Import-Package: org.osgi.framework,
javax.imageio,
net.java.sip.communicator.util,
net.java.sip.communicator.service.contactlist,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.neomedia,
net.java.sip.communicator.service.notification,
net.java.sip.communicator.service.protocol,
net.java.sip.communicator.service.protocol.event,
net.java.sip.communicator.service.resources

@ -38,6 +38,11 @@ public abstract class NotificationAction
*/
public static final String ACTION_COMMAND = "CommandAction";
/**
* Defines the number of actions.
*/
public static final int NUM_ACTIONS = 4;
/**
* Indicates if this handler is enabled.
*/

@ -0,0 +1,94 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.notification;
/**
* Object to cache fired notifications before all handler implementations are
* ready registered.
*
* @author Ingo Bauersachs
*/
public class NotificationData
{
private final String eventType;
private final String title;
private final String message;
private final byte[] icon;
private final Object tag;
/**
* Creates a new instance of this class.
*
* @param eventType the type of the event that we'd like to fire a
* notification for.
* @param title the title of the given message
* @param message the message to use if and where appropriate (e.g. with
* systray or log notification.)
* @param icon the icon to show in the notification if and where appropriate
* @param tag additional info to be used by the notification handler
*/
NotificationData(String eventType, String title, String message,
byte[] icon, Object tag)
{
this.eventType = eventType;
this.title = title;
this.message = message;
this.icon = icon;
this.tag = tag;
}
/**
* Gets the type of the event that we'd like to fire a notification for
*
* @return the eventType
*/
String getEventType()
{
return eventType;
}
/**
* Gets the title of the given message.
*
* @return the title
*/
String getTitle()
{
return title;
}
/**
* Gets the message to use if and where appropriate (e.g. with systray or
* log notification).
*
* @return the message
*/
String getMessage()
{
return message;
}
/**
* Gets the icon to show in the notification if and where appropriate.
*
* @return the icon
*/
byte[] getIcon()
{
return icon;
}
/**
* Gets additional info to be used by the notification handler.
*
* @return the tag
*/
Object getTag()
{
return tag;
}
}

@ -234,16 +234,18 @@ public void removeNotificationChangeListener(
* in the list of registered event types.
*
* @param eventType the type of the event that we'd like to fire a
* notification for.
* notification for.
* @param messageTitle the message title to use if and where appropriate
* (e.g. with systray)
* (e.g. with systray)
* @param message the message to use if and where appropriate (e.g. with
* systray or log notification.)
* @param icon the icon to show in the notification if and where
* appropriate
* systray or log notification.)
* @param icon the icon to show in the notification if and where appropriate
* @param tag additional info to be used by the notification handler
* @return An object referencing the notification. It may be used to stop a
* still running notification. Can be null if the eventType is
* unknown or the notification is not active.
*/
public void fireNotification( String eventType,
public NotificationData fireNotification( String eventType,
String messageTitle,
String message,
byte[] icon,
@ -260,8 +262,12 @@ public void fireNotification( String eventType,
*
* @param eventType the type of the event that we'd like to fire a
* notification for.
*
* @return An object referencing the notification. It may be used to stop a
* still running notification. Can be null if the eventType is
* unknown or the notification is not active.
*/
public void fireNotification(String eventType);
public NotificationData fireNotification(String eventType);
/**
* Activates or deactivates all notification actions related to the

@ -19,6 +19,7 @@
* The implementation of the <tt>NotificationService</tt>.
*
* @author Yana Stamcheva
* @author Ingo Bauersachs
*/
class NotificationServiceImpl
implements NotificationService
@ -56,6 +57,12 @@ class NotificationServiceImpl
private final List<NotificationChangeListener> changeListeners
= new Vector<NotificationChangeListener>();
/**
* Queue to cache fired notifications before all handlers are registered.
*/
private Queue<NotificationData> notificationCache
= new LinkedList<NotificationData>();
/**
* Creates an instance of <tt>NotificationServiceImpl</tt> by loading all
* previously saved notifications.
@ -295,6 +302,14 @@ public void addActionHandler(NotificationHandler handler)
synchronized(handlers)
{
handlers.put(handler.getActionType(), handler);
if(handlers.size() == NUM_ACTIONS && notificationCache != null)
{
for(NotificationData event : notificationCache)
fireNotification(event);
notificationCache.clear();
notificationCache = null;
}
}
}
@ -328,26 +343,12 @@ public Iterable<NotificationHandler> getActionHandlers(String actionType)
}
/**
* If there is a registered event notification of the given
* <tt>eventType</tt> and the event notification is currently activated, the
* list of registered actions is executed.
*
* @param eventType the type of the event that we'd like to fire a
* notification for.
* @param title the title of the given message
* @param message the message to use if and where appropriate (e.g. with
* systray or log notification.)
* @param icon the icon to show in the notification if and where appropriate
* @param tag additional info to be used by the notification handler
* Executes a notification data object on the handlers.
* @param data The notification data to act upon.
*/
public void fireNotification(
String eventType,
String title,
String message,
byte[] icon,
Object tag)
private void fireNotification(NotificationData data)
{
Notification notification = notifications.get(eventType);
Notification notification = notifications.get(data.getEventType());
if(notification == null || !notification.isActive())
return;
@ -362,18 +363,19 @@ public void fireNotification(
{
((PopupMessageNotificationHandler) handler)
.popupMessage((PopupMessageNotificationAction) action,
title, message, icon, tag);
data.getTitle(), data.getMessage(),
data.getIcon(), data.getTag());
}
else if (actionType.equals(ACTION_LOG_MESSAGE))
{
((LogMessageNotificationHandler) handler)
.logMessage((LogMessageNotificationAction) action,
message);
data.getMessage());
}
else if (actionType.equals(ACTION_SOUND))
{
((SoundNotificationHandler) handler)
.start((SoundNotificationAction) action);
.start((SoundNotificationAction) action, data);
}
else if (actionType.equals(ACTION_COMMAND))
{
@ -383,17 +385,61 @@ else if (actionType.equals(ACTION_COMMAND))
}
}
/**
* If there is a registered event notification of the given
* <tt>eventType</tt> and the event notification is currently activated, the
* list of registered actions is executed.
*
* @param eventType the type of the event that we'd like to fire a
* notification for.
* @param title the title of the given message
* @param message the message to use if and where appropriate (e.g. with
* systray or log notification.)
* @param icon the icon to show in the notification if and where appropriate
* @param tag additional info to be used by the notification handler
*
* @return An object referencing the notification. It may be used to stop a
* still running notification. Can be null if the eventType is
* unknown or the notification is not active.
*/
public NotificationData fireNotification(
String eventType,
String title,
String message,
byte[] icon,
Object tag)
{
Notification notification = notifications.get(eventType);
if(notification == null || !notification.isActive())
return null;
NotificationData data = new NotificationData(eventType, title,
message, icon, tag);
//cache the notification when the handlers are not yet ready
if (notificationCache != null)
notificationCache.add(data);
else
fireNotification(data);
return data;
}
/**
* If there is a registered event notification of the given
* <tt>eventType</tt> and the event notification is currently activated, we
* go through the list of registered actions and execute them.
*
* @param eventType the type of the event that we'd like to fire a
* notification for.
* notification for.
*
* @return An object referencing the notification. It may be used to stop a
* still running notification. Can be null if the eventType is
* unknown or the notification is not active.
*/
public void fireNotification(String eventType)
public NotificationData fireNotification(String eventType)
{
this.fireNotification(eventType, null, null, null, null);
return this.fireNotification(eventType, null, null, null, null);
}
/**

@ -21,12 +21,14 @@ public interface SoundNotificationHandler
* method should check the loopInterval value to distinguish whether to play
* a simple sound or to play it in loop.
* @param action the action to act upon
* @param data Additional data for the event.
*/
public void start(SoundNotificationAction action);
public void start(SoundNotificationAction action, NotificationData data);
/**
* Stops playing the sound pointing by <tt>getDescriptor</tt>. This method
* is meant to be used to stop sounds that are played in loop.
* @param data Additional data for the event.
*/
public void stop();
public void stop(NotificationData data);
}
Loading…
Cancel
Save