Separate notification service from its handlers

cusax-fix
Ingo Bauersachs 14 years ago
parent 6102f58f12
commit c543e54197

@ -915,8 +915,9 @@
bundle-sparkle, bundle-plugin-branding, bundle-sparkle, bundle-plugin-branding,
bundle-systemactivitynotifications, bundle-systemactivitynotifications,
bundle-osdependent,bundle-browserlauncher, bundle-osdependent,bundle-browserlauncher,
bundle-pluginmanager,bundle-skinmanager,bundle-notification, bundle-pluginmanager,bundle-skinmanager,
bundle-notification-config,bundle-contacteventhandler, bundle-notification-service,bundle-notification-handlers,bundle-notification-config,
bundle-contacteventhandler,
bundle-plugin-contactinfo,bundle-plugin-chatalerter, bundle-keybindings, bundle-plugin-contactinfo,bundle-plugin-chatalerter, bundle-keybindings,
bundle-plugin-keybindingChooser,bundle-plugin-globalproxyconfig, bundle-plugin-keybindingChooser,bundle-plugin-globalproxyconfig,
bundle-jfontchooserlib,bundle-update,bundle-plugin-update, bundle-jfontchooserlib,bundle-update,bundle-plugin-update,
@ -2050,12 +2051,19 @@ javax.swing.event, javax.swing.border"/>
</target> </target>
<!-- BUNDLE-NOTIFICATION --> <!-- BUNDLE-NOTIFICATION -->
<target name="bundle-notification"> <target name="bundle-notification-service">
<!-- Creates a bundle for the notifications.--> <!-- Creates a bundle for the notifications.-->
<jar compress="false" destfile="${bundles.dest}/notification.jar" <jar compress="false" destfile="${bundles.dest}/notification-service.jar"
manifest="${src}/net/java/sip/communicator/impl/notification/notification.manifest.mf"> manifest="${src}/net/java/sip/communicator/service/notification/notification.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/service/notification" <zipfileset dir="${dest}/net/java/sip/communicator/service/notification"
prefix="net/java/sip/communicator/service/notification"/> prefix="net/java/sip/communicator/service/notification"/>
</jar>
</target>
<target name="bundle-notification-handlers">
<!-- Creates a bundle for the notifications.-->
<jar compress="false" destfile="${bundles.dest}/notification-handlers.jar"
manifest="${src}/net/java/sip/communicator/impl/notification/notification.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/notification" <zipfileset dir="${dest}/net/java/sip/communicator/impl/notification"
prefix="net/java/sip/communicator/impl/notification"/> prefix="net/java/sip/communicator/impl/notification"/>
</jar> </jar>

@ -33,17 +33,18 @@ felix.auto.start.10= \
felix.auto.start.20= \ felix.auto.start.20= \
reference:file:sc-bundles/util.jar \ reference:file:sc-bundles/util.jar \
reference:file:lib/bundle/log4j.jar \ reference:file:lib/bundle/log4j.jar \
reference:file:lib/bundle/commons-logging.jar reference:file:lib/bundle/commons-logging.jar \
reference:file:sc-bundles/fileaccess.jar
felix.auto.start.30= \ felix.auto.start.30= \
reference:file:sc-bundles/fileaccess.jar reference:file:sc-bundles/configuration.jar \
reference:file:sc-bundles/notification-service.jar \
felix.auto.start.35= \ felix.auto.start.35= \
reference:file:sc-bundles/commons-codec.jar \ reference:file:sc-bundles/commons-codec.jar \
reference:file:sc-bundles/httputil.jar reference:file:sc-bundles/httputil.jar
felix.auto.start.40= \ felix.auto.start.40= \
reference:file:sc-bundles/configuration.jar \
reference:file:sc-bundles/jmdnslib.jar \ reference:file:sc-bundles/jmdnslib.jar \
reference:file:sc-bundles/jnalib.jar \ reference:file:sc-bundles/jnalib.jar \
reference:file:sc-bundles/provdisc.jar \ reference:file:sc-bundles/provdisc.jar \
@ -108,7 +109,7 @@ felix.auto.start.60= \
reference:file:sc-bundles/filehistory.jar \ reference:file:sc-bundles/filehistory.jar \
reference:file:sc-bundles/metahistory.jar \ reference:file:sc-bundles/metahistory.jar \
reference:file:sc-bundles/keybindings.jar \ reference:file:sc-bundles/keybindings.jar \
reference:file:sc-bundles/notification.jar \ reference:file:sc-bundles/notification-handlers.jar \
reference:file:sc-bundles/contactsource.jar reference:file:sc-bundles/contactsource.jar
felix.auto.start.66= \ felix.auto.start.66= \

@ -22,77 +22,33 @@ public class CommandNotificationHandlerImpl
private Logger logger private Logger logger
= Logger.getLogger(CommandNotificationHandlerImpl.class); = Logger.getLogger(CommandNotificationHandlerImpl.class);
private String commandDescriptor;
private boolean isEnabled = true;
/** /**
* Creates an instance of <tt>CommandNotificationHandlerImpl</tt> by * {@inheritDoc}
* specifying the <tt>commandDescriptor</tt>, which will point us to the
* command to execute.
*
* @param commandDescriptor a String that should point us to the command to
* execute
*/ */
public CommandNotificationHandlerImpl(String commandDescriptor) public String getActionType()
{ {
this.commandDescriptor = commandDescriptor; return NotificationAction.ACTION_COMMAND;
} }
/** /**
* Executes the <tt>command</tt>, given by the containing * Executes the command, given by the <tt>commandDescriptor</tt> of the
* <tt>commandDescriptor</tt>. * action.
*
* @param action the action to act upon.
*/ */
public void execute() public void execute(CommandNotificationAction action)
{ {
if(StringUtils.isNullOrEmpty(commandDescriptor, true)) if(StringUtils.isNullOrEmpty(action.getDescriptor(), true))
return; return;
try try
{ {
Runtime.getRuntime().exec(commandDescriptor); Runtime.getRuntime().exec(action.getDescriptor());
} }
catch (IOException e) catch (IOException e)
{ {
logger.error("Failed execute the following command: " logger.error("Failed execute the following command: "
+ commandDescriptor, e); + action.getDescriptor(), e);
} }
} }
/**
* Returns the command descriptor.
*
* @return the command descriptor
*/
public String getDescriptor()
{
return commandDescriptor;
}
/**
* Returns TRUE if this notification action handler is enabled and FALSE
* otherwise. While the notification handler for the command action type
* is disabled no programs will be executed when the
* <tt>fireNotification</tt> method is called.
*
* @return TRUE if this notification action handler is enabled and FALSE
* otherwise
*/
public boolean isEnabled()
{
return isEnabled;
}
/**
* Enables or disables this notification handler. While the notification
* handler for the command action type is disabled no programs will be
* executed when the <tt>fireNotification</tt> method is called.
*
* @param isEnabled TRUE to enable this notification handler, FALSE to
* disable it.
*/
public void setEnabled(boolean isEnabled)
{
this.isEnabled = isEnabled;
}
} }

@ -8,6 +8,7 @@
import net.java.sip.communicator.service.notification.*; import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.*;
import static net.java.sip.communicator.service.notification.LogMessageNotificationAction.*;
/** /**
* An implementation of the <tt>LogMessageNotificationHandler</tt> interface. * An implementation of the <tt>LogMessageNotificationHandler</tt> interface.
@ -23,72 +24,27 @@ public class LogMessageNotificationHandlerImpl
private Logger logger private Logger logger
= Logger.getLogger(LogMessageNotificationHandlerImpl.class); = Logger.getLogger(LogMessageNotificationHandlerImpl.class);
private String logType;
private boolean isEnabled = true;
/**
* Creates an instance of <tt>LogMessageNotificationHandlerImpl</tt> by
* specifying the log type.
*
* @param logType the type of the log
*/
public LogMessageNotificationHandlerImpl(String logType)
{
this.logType = logType;
}
/** /**
* Returns the type of the log * {@inheritDoc}
*
* @return the type of the log
*/ */
public String getLogType() public String getActionType()
{ {
return logType; return NotificationAction.ACTION_LOG_MESSAGE;
} }
/** /**
* Logs a message through the sip communicator Logger. * Logs a message through the sip communicator Logger.
* *
* @param action the action to act upon
* @param message the message coming from the event * @param message the message coming from the event
*/ */
public void logMessage(String message) public void logMessage(LogMessageNotificationAction action, String message)
{ {
if (logType.equals(LogMessageNotificationHandler.ERROR_LOG_TYPE)) if (action.getLogType().equals(ERROR_LOG_TYPE))
logger.error(message); logger.error(message);
else if(logType.equals(LogMessageNotificationHandler.INFO_LOG_TYPE)) else if(action.getLogType().equals(INFO_LOG_TYPE))
if (logger.isInfoEnabled()) logger.info(message);
logger.info(message); else if(action.getLogType().equals(TRACE_LOG_TYPE))
else if(logType.equals(LogMessageNotificationHandler.TRACE_LOG_TYPE)) logger.trace(message);
if (logger.isTraceEnabled())
logger.trace(message);
}
/**
* Returns TRUE if this notification action handler is enabled and FALSE
* otherwise. While the notification handler for the log message action type
* is disabled no messages will be logged when the
* <tt>fireNotification</tt> method is called.
*
* @return TRUE if this notification action handler is enabled and FALSE
* otherwise
*/
public boolean isEnabled()
{
return isEnabled;
}
/**
* Enables or disables this notification handler. While the notification
* handler for the log message action type is disabled no messages will be
* logged when the <tt>fireNotification</tt> method is called.
*
* @param isEnabled TRUE to enable this notification handler, FALSE to
* disable it.
*/
public void setEnabled(boolean isEnabled)
{
this.isEnabled = isEnabled;
} }
} }

@ -7,7 +7,6 @@
package net.java.sip.communicator.impl.notification; package net.java.sip.communicator.impl.notification;
import net.java.sip.communicator.service.audionotifier.*; import net.java.sip.communicator.service.audionotifier.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.neomedia.*; import net.java.sip.communicator.service.neomedia.*;
import net.java.sip.communicator.service.notification.*; import net.java.sip.communicator.service.notification.*;
@ -29,73 +28,65 @@ public class NotificationActivator
private final Logger logger = Logger.getLogger(NotificationActivator.class); private final Logger logger = Logger.getLogger(NotificationActivator.class);
protected static BundleContext bundleContext; protected static BundleContext bundleContext;
private static ConfigurationService configService;
private static AudioNotifierService audioNotifierService; private static AudioNotifierService audioNotifierService;
private static SystrayService systrayService; private static SystrayService systrayService;
private static NotificationService notificationService; private static NotificationService notificationService;
private static ResourceManagementService resourcesService; private static ResourceManagementService resourcesService;
private static UIService uiService = null; private static UIService uiService = null;
private static MediaService mediaService; private static MediaService mediaService;
private CommandNotificationHandler commandHandler;
private LogMessageNotificationHandler logMessageHandler;
private PopupMessageNotificationHandler popupMessageHandler;
private SoundNotificationHandler soundHandler;
public void start(BundleContext bc) throws Exception public void start(BundleContext bc) throws Exception
{ {
bundleContext = bc; bundleContext = bc;
try
{
logger.logEntry();
logger.info("Notification handler Service...[ STARTED ]");
try { // Get the notification service implementation
// Create the notification service implementation ServiceReference notifReference = bundleContext
notificationService = new NotificationServiceImpl(); .getServiceReference(NotificationService.class.getName());
if (logger.isInfoEnabled()) notificationService = (NotificationService) bundleContext
logger.info("Notification Service...[ STARTED ]"); .getService(notifReference);
bundleContext.registerService(NotificationService.class.getName(), commandHandler = new CommandNotificationHandlerImpl();
notificationService, null); logMessageHandler = new LogMessageNotificationHandlerImpl();
popupMessageHandler = new PopupMessageNotificationHandlerImpl();
soundHandler = new SoundNotificationHandlerImpl();
notificationService.addActionHandler(commandHandler);
notificationService.addActionHandler(logMessageHandler);
notificationService.addActionHandler(popupMessageHandler);
notificationService.addActionHandler(soundHandler);
new NotificationManager().init(); new NotificationManager().init();
if (logger.isInfoEnabled()) logger.info("Notification handler Service ...[REGISTERED]");
logger.info("Notification Service ...[REGISTERED]");
logger.logEntry();
} }
finally { finally
{
logger.logExit(); logger.logExit();
} }
} }
public void stop(BundleContext bc) throws Exception public void stop(BundleContext bc) throws Exception
{ {
if (logger.isInfoEnabled()) notificationService.removeActionHandler(commandHandler.getActionType());
logger.info("UI Service ...[STOPPED]"); notificationService.removeActionHandler(logMessageHandler.getActionType());
} notificationService.removeActionHandler(popupMessageHandler.getActionType());
notificationService.removeActionHandler(soundHandler.getActionType());
/**
* Returns the <tt>ConfigurationService</tt> obtained from the bundle
* context.
* @return the <tt>ConfigurationService</tt> obtained from the bundle
* context
*/
public static ConfigurationService getConfigurationService()
{
if(configService == null)
{
ServiceReference configReference = bundleContext
.getServiceReference(ConfigurationService.class.getName());
configService = (ConfigurationService) bundleContext
.getService(configReference);
}
return configService; logger.info("Notification handler Service ...[STOPPED]");
} }
/** /**
* Returns the <tt>AudioNotifierService</tt> obtained from the bundle * Returns the <tt>AudioNotifierService</tt> obtained from the bundle
* context. * context.
@ -118,7 +109,7 @@ public static AudioNotifierService getAudioNotifier()
return audioNotifierService; return audioNotifierService;
} }
/** /**
* Returns the <tt>SystrayService</tt> obtained from the bundle context. * Returns the <tt>SystrayService</tt> obtained from the bundle context.
* *

@ -68,6 +68,67 @@ public class NotificationManager
*/ */
private Map<Contact,Long> proactiveTimer = new HashMap<Contact, Long>(); private Map<Contact,Long> proactiveTimer = new HashMap<Contact, Long>();
/**
* Default event type for call been saved using a recorder.
*/
public static final String CALL_SAVED = "CallSaved";
/**
* Default event type for incoming file transfers.
*/
public static final String INCOMING_FILE = "IncomingFile";
/**
* Default event type for security error on a call.
*/
public static final String CALL_SECURITY_ERROR = "CallSecurityError";
/**
* Default event type for activated security on a call.
*/
public static final String CALL_SECURITY_ON = "CallSecurityOn";
/**
* Default event type when a secure message received.
*/
public static final String SECURITY_MESSAGE = "SecurityMessage";
/**
* Default event type for
* proactive notifications (typing notifications when chatting).
*/
public static final String PROACTIVE_NOTIFICATION = "ProactiveNotification";
/**
* Default event type for hanging up calls.
*/
public static final String HANG_UP = "HangUp";
/**
* Default event type for dialing.
*/
public static final String DIALING = "Dialing";
/**
* Default event type for a busy call.
*/
public static final String BUSY_CALL = "BusyCall";
/**
* Default event type for outgoing calls.
*/
public static final String OUTGOING_CALL = "OutgoingCall";
/**
* Default event type for receiving calls (incoming calls).
*/
public static final String INCOMING_CALL = "IncomingCall";
/**
* Default event type for receiving messages.
*/
public static final String INCOMING_MESSAGE = "IncomingMessage";
/** /**
* Initialize, register default notifications and start listening for * Initialize, register default notifications and start listening for
* new protocols or removed one and find any that are already registered. * new protocols or removed one and find any that are already registered.
@ -101,120 +162,108 @@ private void registerDefaultNotifications()
// Register incoming message notifications. // Register incoming message notifications.
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.INCOMING_MESSAGE, NotificationManager.INCOMING_MESSAGE,
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
null, null,
null); null);
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.INCOMING_MESSAGE, NotificationManager.INCOMING_MESSAGE,
NotificationService.ACTION_SOUND, NotificationAction.ACTION_SOUND,
SoundProperties.INCOMING_MESSAGE, SoundProperties.INCOMING_MESSAGE,
null); null);
// Register incoming call notifications. // Register incoming call notifications.
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.INCOMING_CALL, NotificationManager.INCOMING_CALL,
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
null, null,
null); null);
SoundNotificationHandler inCallSoundHandler SoundNotificationAction inCallSoundHandler
= notificationService = new SoundNotificationAction(SoundProperties.INCOMING_CALL, 2000);
.createSoundNotificationHandler(SoundProperties.INCOMING_CALL,
2000);
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.INCOMING_CALL, NotificationManager.INCOMING_CALL,
NotificationService.ACTION_SOUND,
inCallSoundHandler); inCallSoundHandler);
// Register outgoing call notifications. // Register outgoing call notifications.
SoundNotificationHandler outCallSoundHandler SoundNotificationAction outCallSoundHandler
= notificationService = new SoundNotificationAction(SoundProperties.OUTGOING_CALL, 3000);
.createSoundNotificationHandler(SoundProperties.OUTGOING_CALL,
3000);
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.OUTGOING_CALL, NotificationManager.OUTGOING_CALL,
NotificationService.ACTION_SOUND,
outCallSoundHandler); outCallSoundHandler);
// Register busy call notifications. // Register busy call notifications.
SoundNotificationHandler busyCallSoundHandler SoundNotificationAction busyCallSoundHandler
= notificationService = new SoundNotificationAction(SoundProperties.BUSY, 1);
.createSoundNotificationHandler(SoundProperties.BUSY, 1);
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.BUSY_CALL, NotificationManager.BUSY_CALL,
NotificationService.ACTION_SOUND,
busyCallSoundHandler); busyCallSoundHandler);
// Register dial notifications. // Register dial notifications.
SoundNotificationHandler dialSoundHandler SoundNotificationAction dialSoundHandler
= notificationService = new SoundNotificationAction(SoundProperties.DIALING, 0);
.createSoundNotificationHandler(SoundProperties.DIALING, 0);
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.DIALING, NotificationManager.DIALING,
NotificationService.ACTION_SOUND,
dialSoundHandler); dialSoundHandler);
// Register the hangup sound notification. // Register the hangup sound notification.
SoundNotificationHandler hangupSoundHandler SoundNotificationAction hangupSoundHandler
= notificationService = new SoundNotificationAction(SoundProperties.HANG_UP, -1);
.createSoundNotificationHandler(SoundProperties.HANG_UP, -1);
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.HANG_UP, NotificationManager.HANG_UP,
NotificationService.ACTION_SOUND,
hangupSoundHandler); hangupSoundHandler);
// Register proactive notifications. // Register proactive notifications.
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.PROACTIVE_NOTIFICATION, NotificationManager.PROACTIVE_NOTIFICATION,
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
null, null,
null); null);
// Register warning message notifications. // Register warning message notifications.
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.SECURITY_MESSAGE, NotificationManager.SECURITY_MESSAGE,
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
null, null,
null); null);
// Register sound notification for security state on during a call. // Register sound notification for security state on during a call.
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.CALL_SECURITY_ON, NotificationManager.CALL_SECURITY_ON,
NotificationService.ACTION_SOUND, NotificationAction.ACTION_SOUND,
SoundProperties.CALL_SECURITY_ON, SoundProperties.CALL_SECURITY_ON,
null); null);
// Register sound notification for security state off during a call. // Register sound notification for security state off during a call.
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.CALL_SECURITY_ERROR, NotificationManager.CALL_SECURITY_ERROR,
NotificationService.ACTION_SOUND, NotificationAction.ACTION_SOUND,
SoundProperties.CALL_SECURITY_ERROR, SoundProperties.CALL_SECURITY_ERROR,
null); null);
// Register sound notification for incoming files. // Register sound notification for incoming files.
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.INCOMING_FILE, NotificationManager.INCOMING_FILE,
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
null, null,
null); null);
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.INCOMING_FILE, NotificationManager.INCOMING_FILE,
NotificationService.ACTION_SOUND, NotificationAction.ACTION_SOUND,
SoundProperties.INCOMING_FILE, SoundProperties.INCOMING_FILE,
null); null);
// Register notification for saved calls. // Register notification for saved calls.
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NotificationService.CALL_SAVED, NotificationManager.CALL_SAVED,
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
null, null,
null); null);
} }
@ -537,7 +586,7 @@ public static void fireChatNotification(Object chatContact,
if(notificationService == null) if(notificationService == null)
return; return;
NotificationActionHandler popupActionHandler = null; NotificationAction popupActionHandler = null;
UIService uiService = NotificationActivator.getUIService(); UIService uiService = NotificationActivator.getUIService();
Chat chatPanel = null; Chat chatPanel = null;
@ -570,12 +619,12 @@ else if (chatContact instanceof ChatRoom)
if (chatPanel != null) if (chatPanel != null)
{ {
if (eventType.equals(NotificationService.INCOMING_MESSAGE) if (eventType.equals(NotificationManager.INCOMING_MESSAGE)
&& chatPanel.isChatFocused()) && chatPanel.isChatFocused())
{ {
popupActionHandler = notificationService popupActionHandler = notificationService
.getEventNotificationActionHandler(eventType, .getEventNotificationAction(eventType,
NotificationService.ACTION_POPUP_MESSAGE); NotificationAction.ACTION_POPUP_MESSAGE);
popupActionHandler.setEnabled(false); popupActionHandler.setEnabled(false);
} }
@ -623,14 +672,15 @@ public static void stopSound(String eventType)
if(notificationService == null) if(notificationService == null)
return; return;
SoundNotificationHandler soundHandler Iterable<NotificationHandler> soundHandlers =
= (SoundNotificationHandler) notificationService notificationService.getActionHandlers(
.getEventNotificationActionHandler( NotificationAction.ACTION_SOUND);
eventType, NotificationService.ACTION_SOUND);
//TODO make SoundNotificationHandler handle multiple sound at once
// There can be no sound action handler for this event type // There can be no sound action handler for this event type
if(soundHandler != null) if(soundHandlers != null)
soundHandler.stop(); for(NotificationHandler handler : soundHandlers)
((SoundNotificationHandler)handler).stop();
} }
/** /**
@ -675,10 +725,10 @@ public static BufferedImage getImage(ImageID imageID)
*/ */
private static void stopAllTelephonySounds() private static void stopAllTelephonySounds()
{ {
NotificationManager.stopSound(NotificationService.DIALING); NotificationManager.stopSound(NotificationManager.DIALING);
NotificationManager.stopSound(NotificationService.BUSY_CALL); NotificationManager.stopSound(NotificationManager.BUSY_CALL);
NotificationManager.stopSound(NotificationService.INCOMING_CALL); NotificationManager.stopSound(NotificationManager.INCOMING_CALL);
NotificationManager.stopSound(NotificationService.OUTGOING_CALL); NotificationManager.stopSound(NotificationManager.OUTGOING_CALL);
} }
/** /**
@ -763,7 +813,7 @@ public void messageReceived(MessageReceivedEvent evt)
fireChatNotification( fireChatNotification(
evt.getSourceContact(), evt.getSourceContact(),
NotificationService.INCOMING_MESSAGE, NotificationManager.INCOMING_MESSAGE,
title, title,
evt.getSourceMessage().getContent()); evt.getSourceMessage().getContent());
} }
@ -810,7 +860,7 @@ public void fileTransferRequestReceived(FileTransferRequestEvent event)
NotificationManager NotificationManager
.fireChatNotification( .fireChatNotification(
sourceContact, sourceContact,
NotificationService.INCOMING_FILE, NotificationManager.INCOMING_FILE,
title, title,
request.getFileName()); request.getFileName());
} }
@ -910,7 +960,7 @@ public void typingNotificationReceived(TypingNotificationEvent event)
NotificationManager.fireChatNotification( NotificationManager.fireChatNotification(
contact, contact,
NotificationService.PROACTIVE_NOTIFICATION, NotificationManager.PROACTIVE_NOTIFICATION,
contact.getDisplayName(), contact.getDisplayName(),
NotificationActivator.getResources() NotificationActivator.getResources()
.getI18NString("service.gui.PROACTIVE_NOTIFICATION")); .getI18NString("service.gui.PROACTIVE_NOTIFICATION"));
@ -935,7 +985,7 @@ public void incomingCallReceived(CallEvent event)
.getCallPeers().next().getDisplayName(); .getCallPeers().next().getDisplayName();
NotificationManager.fireNotification( NotificationManager.fireNotification(
NotificationService.INCOMING_CALL, NotificationManager.INCOMING_CALL,
"", "",
NotificationActivator.getResources() NotificationActivator.getResources()
.getI18NString("service.gui.INCOMING_CALL", .getI18NString("service.gui.INCOMING_CALL",
@ -988,7 +1038,7 @@ public void callEnded(CallEvent event)
stopAllTelephonySounds(); stopAllTelephonySounds();
// Play the hangup sound. // Play the hangup sound.
NotificationManager.fireNotification(NotificationService.HANG_UP); NotificationManager.fireNotification(NotificationManager.HANG_UP);
} }
catch(Throwable t) catch(Throwable t)
{ {
@ -1055,11 +1105,11 @@ public void peerStateChanged(CallPeerChangeEvent evt)
|| newState == CallPeerState.CONNECTING) || newState == CallPeerState.CONNECTING)
{ {
NotificationManager NotificationManager
.fireNotification(NotificationService.DIALING); .fireNotification(NotificationManager.DIALING);
} }
else else
{ {
NotificationManager.stopSound(NotificationService.DIALING); NotificationManager.stopSound(NotificationManager.DIALING);
} }
if (newState == CallPeerState.ALERTING_REMOTE_SIDE if (newState == CallPeerState.ALERTING_REMOTE_SIDE
@ -1069,17 +1119,17 @@ public void peerStateChanged(CallPeerChangeEvent evt)
&& oldState != CallPeerState.CONNECTING_WITH_EARLY_MEDIA) && oldState != CallPeerState.CONNECTING_WITH_EARLY_MEDIA)
{ {
NotificationManager NotificationManager
.fireNotification(NotificationService.OUTGOING_CALL); .fireNotification(NotificationManager.OUTGOING_CALL);
} }
else if (newState == CallPeerState.BUSY) else if (newState == CallPeerState.BUSY)
{ {
NotificationManager.stopSound(NotificationService.OUTGOING_CALL); NotificationManager.stopSound(NotificationManager.OUTGOING_CALL);
// We start the busy sound only if we're in a simple call. // We start the busy sound only if we're in a simple call.
if (!isConference(sourcePeer.getCall())) if (!isConference(sourcePeer.getCall()))
{ {
NotificationManager.fireNotification( NotificationManager.fireNotification(
NotificationService.BUSY_CALL); NotificationManager.BUSY_CALL);
} }
} }
else if (newState == CallPeerState.CONNECTING_INCOMING_CALL || else if (newState == CallPeerState.CONNECTING_INCOMING_CALL ||
@ -1088,9 +1138,9 @@ else if (newState == CallPeerState.CONNECTING_INCOMING_CALL ||
if (!CallPeerState.isOnHold(oldState)) if (!CallPeerState.isOnHold(oldState))
{ {
NotificationManager NotificationManager
.stopSound(NotificationService.OUTGOING_CALL); .stopSound(NotificationManager.OUTGOING_CALL);
NotificationManager NotificationManager
.stopSound(NotificationService.INCOMING_CALL); .stopSound(NotificationManager.INCOMING_CALL);
} }
} }
else if (newState == CallPeerState.CONNECTING_WITH_EARLY_MEDIA) else if (newState == CallPeerState.CONNECTING_WITH_EARLY_MEDIA)
@ -1098,16 +1148,16 @@ else if (newState == CallPeerState.CONNECTING_WITH_EARLY_MEDIA)
//this means a call with early media. make sure that we are not //this means a call with early media. make sure that we are not
//playing local notifications any more. //playing local notifications any more.
NotificationManager NotificationManager
.stopSound(NotificationService.OUTGOING_CALL); .stopSound(NotificationManager.OUTGOING_CALL);
} }
else if (newState == CallPeerState.CONNECTED) else if (newState == CallPeerState.CONNECTED)
{ {
if (!CallPeerState.isOnHold(oldState)) if (!CallPeerState.isOnHold(oldState))
{ {
NotificationManager NotificationManager
.stopSound(NotificationService.OUTGOING_CALL); .stopSound(NotificationManager.OUTGOING_CALL);
NotificationManager NotificationManager
.stopSound(NotificationService.INCOMING_CALL); .stopSound(NotificationManager.INCOMING_CALL);
} }
} }
else if (newState == CallPeerState.DISCONNECTED else if (newState == CallPeerState.DISCONNECTED
@ -1115,7 +1165,7 @@ else if (newState == CallPeerState.DISCONNECTED
{ {
stopAllTelephonySounds(); stopAllTelephonySounds();
NotificationManager.fireNotification(NotificationService.HANG_UP); NotificationManager.fireNotification(NotificationManager.HANG_UP);
} }
} }
catch(Throwable t) catch(Throwable t)
@ -1171,7 +1221,7 @@ public void securityOn(CallPeerSecurityOnEvent evt)
|| !evt.getSecurityController().requiresSecureSignalingTransport()) || !evt.getSecurityController().requiresSecureSignalingTransport())
{ {
NotificationManager.fireNotification( NotificationManager.fireNotification(
NotificationService.CALL_SECURITY_ON); NotificationManager.CALL_SECURITY_ON);
} }
} }
catch(Throwable t) catch(Throwable t)
@ -1221,12 +1271,12 @@ public void securityMessageRecieved(CallPeerSecurityMessageEvent event)
messageTitle = NotificationActivator.getResources() messageTitle = NotificationActivator.getResources()
.getI18NString("service.gui.SECURITY_ERROR"); .getI18NString("service.gui.SECURITY_ERROR");
NotificationManager.fireNotification( NotificationManager.fireNotification(
NotificationService.CALL_SECURITY_ERROR); NotificationManager.CALL_SECURITY_ERROR);
} }
} }
NotificationManager.fireNotification( NotificationManager.fireNotification(
NotificationService.SECURITY_MESSAGE, NotificationManager.SECURITY_MESSAGE,
messageTitle, messageTitle,
event.getI18nMessage()); event.getI18nMessage());
} }
@ -1291,7 +1341,7 @@ public void messageReceived(ChatRoomMessageReceivedEvent evt)
NotificationManager.fireChatNotification( NotificationManager.fireChatNotification(
sourceChatRoom, sourceChatRoom,
NotificationService.INCOMING_MESSAGE, NotificationManager.INCOMING_MESSAGE,
title, title,
messageContent); messageContent);
} }
@ -1411,7 +1461,7 @@ public void messageReceived(AdHocChatRoomMessageReceivedEvent evt)
NotificationManager.fireChatNotification( NotificationManager.fireChatNotification(
sourceChatRoom, sourceChatRoom,
NotificationService.INCOMING_MESSAGE, NotificationManager.INCOMING_MESSAGE,
title, title,
messageContent); messageContent);
} }
@ -1472,7 +1522,7 @@ public void conferenceMemberAdded(CallPeerConferenceEvent conferenceEvent)
if (securityEvent instanceof CallPeerSecurityOnEvent) if (securityEvent instanceof CallPeerSecurityOnEvent)
{ {
NotificationManager.fireNotification( NotificationManager.fireNotification(
NotificationService.CALL_SECURITY_ON); NotificationManager.CALL_SECURITY_ON);
} }
} }
} }
@ -1503,7 +1553,7 @@ public void recorderStopped(Recorder recorder)
try try
{ {
NotificationManager.fireNotification( NotificationManager.fireNotification(
NotificationService.CALL_SAVED, NotificationManager.CALL_SAVED,
NotificationActivator.getResources().getI18NString( NotificationActivator.getResources().getI18NString(
"plugin.callrecordingconfig.CALL_SAVED"), "plugin.callrecordingconfig.CALL_SAVED"),
NotificationActivator.getResources().getI18NString( NotificationActivator.getResources().getI18NString(

@ -18,71 +18,35 @@
public class PopupMessageNotificationHandlerImpl public class PopupMessageNotificationHandlerImpl
implements PopupMessageNotificationHandler implements PopupMessageNotificationHandler
{ {
private String defaultMessage;
private boolean isEnabled = true;
/** /**
* Creates an instance of <tt>PopupMessageNotificationHandlerImpl</tt> by * {@inheritDoc}
* specifying the default message to use if no message is specified.
*
* @param defaultMessage the default message to use if no message is
* specified
*/ */
public PopupMessageNotificationHandlerImpl(String defaultMessage) public String getActionType()
{ {
this.defaultMessage = defaultMessage; return NotificationAction.ACTION_POPUP_MESSAGE;
}
/**
* Return the default message to use if no message is specified.
*
* @return the default message to use if no message is specified.
*/
public String getDefaultMessage()
{
return defaultMessage;
} }
/** /**
* Shows a popup message through the <tt>SystrayService</tt>. * Shows the given <tt>PopupMessage</tt>
* *
* @param message the message to show in the popup * @param action the action to act upon
* @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
*/ */
public void popupMessage(PopupMessage message) public void popupMessage(PopupMessageNotificationAction action,
String title,
String message,
byte[] icon,
Object tag)
{ {
SystrayService systray = NotificationActivator.getSystray(); SystrayService systray = NotificationActivator.getSystray();
if(systray == null) if(systray == null)
return; return;
systray.showPopupMessage(message); systray.showPopupMessage(new PopupMessage(title, message, icon, tag));
}
/**
* Returns TRUE if this notification action handler is enabled and FALSE
* otherwise. While the notification handler for the pop-up message action
* type is disabled no messages will be popped up when the
* <tt>fireNotification</tt> method is called.
*
* @return TRUE if this notification action handler is enabled and FALSE
* otherwise
*/
public boolean isEnabled()
{
return isEnabled;
}
/**
* Enables or disables this notification handler. While the notification
* handler for the pop-up message action type is disabled no messages will
* be popped up when the <tt>fireNotification</tt> method is called.
*
* @param isEnabled TRUE to enable this notification handler, FALSE to
* disable it.
*/
public void setEnabled(boolean isEnabled)
{
this.isEnabled = isEnabled;
} }
} }

@ -18,81 +18,47 @@
public class SoundNotificationHandlerImpl public class SoundNotificationHandlerImpl
implements SoundNotificationHandler implements SoundNotificationHandler
{ {
private String soundFileDescriptor;
/**
* By default we don't play sounds in loop.
*/
private int loopInterval = -1;
/** /**
* The audio clip that manages to play the sound. * The audio clip that manages to play the sound.
*/ */
private SCAudioClip audio; private SCAudioClip audio;
/** /**
* Indicates if this handler is enabled. * {@inheritDoc}
*/
private boolean isEnabled = true;
/**
* Creates an instance of <tt>SoundNotificationHandlerImpl</tt> by
* specifying the sound file descriptor.
*
* @param soundDescriptor the sound file descriptor
*/ */
public SoundNotificationHandlerImpl(String soundDescriptor) public String getActionType()
{ {
this.soundFileDescriptor = soundDescriptor; return NotificationAction.ACTION_SOUND;
}
/**
* Creates an instance of <tt>SoundNotificationHandlerImpl</tt> by
* specifying the sound file descriptor and the loop interval.
*
* @param soundDescriptor the sound file descriptor
* @param loopInterval the loop interval
*/
public SoundNotificationHandlerImpl( String soundDescriptor,
int loopInterval)
{
this.soundFileDescriptor = soundDescriptor;
this.loopInterval = loopInterval;
}
/**
* Returns the loop interval. This is the interval of milliseconds to wait
* before repeating the sound, when playing a sound in loop. By default this
* method returns -1.
*
* @return the loop interval
*/
public int getLoopInterval()
{
return loopInterval;
} }
/** /**
* Plays the sound given by the containing <tt>soundFileDescriptor</tt>. The * Plays the sound given by the containing <tt>soundFileDescriptor</tt>. The
* sound is played in loop if the loopInterval is defined. * sound is played in loop if the loopInterval is defined.
* @param action the action to act upon.
*/ */
public void start() public void start(SoundNotificationAction action)
{ {
AudioNotifierService audioNotifService AudioNotifierService audioNotifService
= NotificationActivator.getAudioNotifier(); = NotificationActivator.getAudioNotifier();
if(audioNotifService == null if(audioNotifService == null
|| StringUtils.isNullOrEmpty(soundFileDescriptor, true)) || StringUtils.isNullOrEmpty(action.getDescriptor(), true))
return; return;
audio = audioNotifService.createAudio(soundFileDescriptor); //stop any previous audio notification
if(audio != null)
{
stop();
}
audio = audioNotifService.createAudio(action.getDescriptor());
// it is possible that audio cannot be created // it is possible that audio cannot be created
if(audio == null) if(audio == null)
return; return;
if(loopInterval > -1) if(action.getLoopInterval() > -1)
audio.playInLoop(loopInterval); audio.playInLoop(action.getLoopInterval());
else else
audio.play(); audio.play();
} }
@ -105,51 +71,11 @@ public void stop()
AudioNotifierService audioNotifService AudioNotifierService audioNotifService
= NotificationActivator.getAudioNotifier(); = NotificationActivator.getAudioNotifier();
if(audioNotifService == null) if(audioNotifService == null || audio == null)
return;
if(audio == null)
return; return;
audio.stop(); audio.stop();
audioNotifService.destroyAudio(audio); audioNotifService.destroyAudio(audio);
} audio = null;
/**
* Returns the descriptor pointing to the sound to be played.
*
* @return the descriptor pointing to the sound to be played.
*/
public String getDescriptor()
{
return soundFileDescriptor;
}
/**
* Returns TRUE if this notification action handler is enabled and FALSE
* otherwise. While the notification handler for the sound action type is
* disabled no sounds will be played when the <tt>fireNotification</tt>
* method is called.
*
* @return TRUE if this notification action handler is enabled and FALSE
* otherwise
*/
public boolean isEnabled()
{
return isEnabled;
}
/**
* Enables or disables this notification handler. While the notification
* handler for the sound action type is disabled no sounds will be played
* when the <tt>fireNotification</tt> method is called.
*
* @param isEnabled TRUE to enable this notification handler, FALSE to
* disable it.
*/
public void setEnabled(boolean isEnabled)
{
this.isEnabled = isEnabled;
} }
} }

@ -4,11 +4,10 @@ Bundle-Description: An implementation of the Notification service.
Bundle-Vendor: sip-communicator.org Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1 Bundle-Version: 0.0.1
System-Bundle: yes System-Bundle: yes
Export-Package: net.java.sip.communicator.service.notification,
net.java.sip.communicator.service.notification.event
Import-Package: org.osgi.framework, Import-Package: org.osgi.framework,
javax.imageio, javax.imageio,
net.java.sip.communicator.util, net.java.sip.communicator.util,
net.java.sip.communicator.service.notification,
net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.contactlist, net.java.sip.communicator.service.contactlist,
net.java.sip.communicator.service.audionotifier, net.java.sip.communicator.service.audionotifier,

@ -115,7 +115,7 @@ public LoggingConfigForm()
LoggingUtilsActivator.getNotificationService() LoggingUtilsActivator.getNotificationService()
.registerDefaultNotificationForEvent( .registerDefaultNotificationForEvent(
LOGFILES_ARCHIVED, LOGFILES_ARCHIVED,
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
null, null,
null); null);
} }

@ -326,7 +326,7 @@ public void insertUpdate(DocumentEvent event)
NotificationConfigurationActivator.getNotificationService() NotificationConfigurationActivator.getNotificationService()
.registerNotificationForEvent( .registerNotificationForEvent(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_COMMAND, NotificationAction.ACTION_COMMAND,
entry.getProgramFile(), entry.getProgramFile(),
"" ""
); );
@ -338,7 +338,7 @@ public void insertUpdate(DocumentEvent event)
NotificationConfigurationActivator.getNotificationService() NotificationConfigurationActivator.getNotificationService()
.registerNotificationForEvent( .registerNotificationForEvent(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_SOUND, NotificationAction.ACTION_SOUND,
entry.getSoundFile(), entry.getSoundFile(),
"" ""
); );
@ -366,7 +366,7 @@ public void removeUpdate(DocumentEvent event)
NotificationConfigurationActivator.getNotificationService() NotificationConfigurationActivator.getNotificationService()
.registerNotificationForEvent( .registerNotificationForEvent(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_COMMAND, NotificationAction.ACTION_COMMAND,
entry.getProgramFile(), entry.getProgramFile(),
"" ""
); );
@ -378,7 +378,7 @@ public void removeUpdate(DocumentEvent event)
NotificationConfigurationActivator.getNotificationService() NotificationConfigurationActivator.getNotificationService()
.registerNotificationForEvent( .registerNotificationForEvent(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_SOUND, NotificationAction.ACTION_SOUND,
entry.getSoundFile(), entry.getSoundFile(),
"" ""
); );

@ -8,7 +8,6 @@
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.*;
@ -132,30 +131,24 @@ public void valueChanged(ListSelectionEvent e)
*/ */
private void initTableData() private void initTableData()
{ {
Iterator<String> registeredEvents for(String eventType : notificationService.getRegisteredEvents())
= notificationService.getRegisteredEvents();
NotificationEntry entry;
while (registeredEvents.hasNext())
{ {
String eventType = registeredEvents.next(); PopupMessageNotificationAction popupHandler
= (PopupMessageNotificationAction) notificationService
PopupMessageNotificationHandler popupHandler .getEventNotificationAction(
= (PopupMessageNotificationHandler) notificationService eventType, NotificationAction.ACTION_POPUP_MESSAGE);
.getEventNotificationActionHandler(
eventType, NotificationService.ACTION_POPUP_MESSAGE); CommandNotificationAction programHandler
= (CommandNotificationAction) notificationService
CommandNotificationHandler programHandler .getEventNotificationAction(
= (CommandNotificationHandler) notificationService eventType, NotificationAction.ACTION_COMMAND);
.getEventNotificationActionHandler(
eventType, NotificationService.ACTION_COMMAND); SoundNotificationAction soundHandler
= (SoundNotificationAction) notificationService
SoundNotificationHandler soundHandler .getEventNotificationAction(
= (SoundNotificationHandler) notificationService eventType, NotificationAction.ACTION_SOUND);
.getEventNotificationActionHandler(
eventType, NotificationService.ACTION_SOUND); NotificationEntry entry = new NotificationEntry(
entry = new NotificationEntry(
notificationService.isActive(eventType), notificationService.isActive(eventType),
programHandler != null && programHandler.isEnabled(), programHandler != null && programHandler.isEnabled(),
(programHandler != null) ? programHandler.getDescriptor() : null, (programHandler != null) ? programHandler.getDescriptor() : null,
@ -460,7 +453,7 @@ public void mouseClicked(MouseEvent e)
{ {
notificationService.registerNotificationForEvent( notificationService.registerNotificationForEvent(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_COMMAND, NotificationAction.ACTION_COMMAND,
entry.getProgramFile(), entry.getProgramFile(),
""); "");
} }
@ -468,7 +461,7 @@ public void mouseClicked(MouseEvent e)
{ {
notificationService.removeEventNotificationAction( notificationService.removeEventNotificationAction(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_COMMAND); NotificationAction.ACTION_COMMAND);
} }
break; break;
case 2: case 2:
@ -479,7 +472,7 @@ public void mouseClicked(MouseEvent e)
{ {
notificationService.registerNotificationForEvent( notificationService.registerNotificationForEvent(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
"", "",
""); "");
} }
@ -487,7 +480,7 @@ public void mouseClicked(MouseEvent e)
{ {
notificationService.removeEventNotificationAction( notificationService.removeEventNotificationAction(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_POPUP_MESSAGE); NotificationAction.ACTION_POPUP_MESSAGE);
} }
break; break;
case 3: case 3:
@ -498,7 +491,7 @@ public void mouseClicked(MouseEvent e)
{ {
notificationService.registerNotificationForEvent( notificationService.registerNotificationForEvent(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_SOUND, NotificationAction.ACTION_SOUND,
entry.getSoundFile(), entry.getSoundFile(),
""); "");
} }
@ -506,7 +499,7 @@ public void mouseClicked(MouseEvent e)
{ {
notificationService.removeEventNotificationAction( notificationService.removeEventNotificationAction(
entry.getEvent(), entry.getEvent(),
NotificationService.ACTION_SOUND); NotificationAction.ACTION_SOUND);
} }
break; break;
}; };
@ -524,7 +517,7 @@ public void actionAdded(NotificationActionTypeEvent event)
String eventName = event.getSourceEventType(); String eventName = event.getSourceEventType();
NotificationEntry entry = getNotificationEntry(eventName); NotificationEntry entry = getNotificationEntry(eventName);
NotificationActionHandler handler = event.getActionHandler(); NotificationAction handler = event.getActionHandler();
boolean isActionEnabled = (handler != null && handler.isEnabled()); boolean isActionEnabled = (handler != null && handler.isEnabled());
if(entry == null) if(entry == null)
@ -535,25 +528,25 @@ public void actionAdded(NotificationActionTypeEvent event)
entry.setEvent(eventName); entry.setEvent(eventName);
if(event.getSourceActionType() if(event.getActionHandler().getActionType()
.equals(NotificationService.ACTION_POPUP_MESSAGE)) .equals(NotificationAction.ACTION_POPUP_MESSAGE))
{ {
entry.setPopup(isActionEnabled); entry.setPopup(isActionEnabled);
} }
else if(event.getSourceActionType() else if(event.getActionHandler().getActionType()
.equals(NotificationService.ACTION_COMMAND)) .equals(NotificationAction.ACTION_COMMAND))
{ {
entry.setProgram(isActionEnabled); entry.setProgram(isActionEnabled);
entry.setProgramFile(((CommandNotificationHandler)event entry.setProgramFile(((CommandNotificationAction)event
.getActionHandler()).getDescriptor()); .getActionHandler()).getDescriptor());
} }
else if(event.getSourceActionType() else if(event.getActionHandler().getActionType()
.equals(NotificationService.ACTION_SOUND)) .equals(NotificationAction.ACTION_SOUND))
{ {
entry.setSound(isActionEnabled); entry.setSound(isActionEnabled);
entry.setSoundFile(((SoundNotificationHandler)event entry.setSoundFile(((SoundNotificationAction)event
.getActionHandler()).getDescriptor()); .getActionHandler()).getDescriptor());
} }
entry.setEnabled(notificationService.isActive(eventName)); entry.setEnabled(notificationService.isActive(eventName));
@ -574,19 +567,19 @@ public void actionRemoved(NotificationActionTypeEvent event)
if(entry == null) if(entry == null)
return; return;
if(event.getSourceActionType() if(event.getActionHandler().getActionType()
.equals(NotificationService.ACTION_POPUP_MESSAGE)) .equals(NotificationAction.ACTION_POPUP_MESSAGE))
{ {
entry.setPopup(false); entry.setPopup(false);
} }
else if(event.getSourceActionType() else if(event.getActionHandler().getActionType()
.equals(NotificationService.ACTION_COMMAND)) .equals(NotificationAction.ACTION_COMMAND))
{ {
entry.setProgram(false); entry.setProgram(false);
entry.setProgramFile(""); entry.setProgramFile("");
} }
else if(event.getSourceActionType() else if(event.getActionHandler().getActionType()
.equals(NotificationService.ACTION_SOUND)) .equals(NotificationAction.ACTION_SOUND))
{ {
entry.setSound(false); entry.setSound(false);
entry.setSoundFile(""); entry.setSoundFile("");
@ -608,16 +601,16 @@ public void actionChanged(NotificationActionTypeEvent event)
if(entry == null) if(entry == null)
return; return;
if(event.getSourceActionType() if(event.getActionHandler().getActionType()
.equals(NotificationService.ACTION_COMMAND)) .equals(NotificationAction.ACTION_COMMAND))
{ {
entry.setProgramFile(((CommandNotificationHandler)event entry.setProgramFile(((CommandNotificationAction)event
.getActionHandler()).getDescriptor()); .getActionHandler()).getDescriptor());
} }
else if(event.getSourceActionType() else if(event.getActionHandler().getActionType()
.equals(NotificationService.ACTION_SOUND)) .equals(NotificationAction.ACTION_SOUND))
{ {
entry.setSoundFile(((SoundNotificationHandler)event entry.setSoundFile(((SoundNotificationAction)event
.getActionHandler()).getDescriptor()); .getActionHandler()).getDescriptor());
} }
@ -638,20 +631,20 @@ public void eventTypeAdded(NotificationEventTypeEvent event)
if(entry == null) if(entry == null)
{ {
PopupMessageNotificationHandler popupHandler PopupMessageNotificationAction popupHandler
= (PopupMessageNotificationHandler) notificationService = (PopupMessageNotificationAction) notificationService
.getEventNotificationActionHandler( .getEventNotificationAction(
eventName, NotificationService.ACTION_POPUP_MESSAGE); eventName, NotificationAction.ACTION_POPUP_MESSAGE);
CommandNotificationHandler programHandler CommandNotificationAction programHandler
= (CommandNotificationHandler) notificationService = (CommandNotificationAction) notificationService
.getEventNotificationActionHandler( .getEventNotificationAction(
eventName, NotificationService.ACTION_COMMAND); eventName, NotificationAction.ACTION_COMMAND);
SoundNotificationHandler soundHandler SoundNotificationAction soundHandler
= (SoundNotificationHandler) notificationService = (SoundNotificationAction) notificationService
.getEventNotificationActionHandler( .getEventNotificationAction(
eventName, NotificationService.ACTION_SOUND); eventName, NotificationAction.ACTION_SOUND);
entry = new NotificationEntry( entry = new NotificationEntry(
notificationService.isActive(event.getSourceEventType()), notificationService.isActive(event.getSourceEventType()),

@ -299,7 +299,7 @@ public static NotificationService getNotificationService()
notificationService.registerDefaultNotificationForEvent( notificationService.registerDefaultNotificationForEvent(
NETWORK_NOTIFICATIONS, NETWORK_NOTIFICATIONS,
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
null, null,
null); null);
} }

@ -0,0 +1,42 @@
/*
* 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;
/**
* An implementation of the <tt>CommandNotificationHandler</tt> interface.
*
* @author Yana Stamcheva
*/
public class CommandNotificationAction
extends NotificationAction
{
private String commandDescriptor;
/**
* Creates an instance of <tt>CommandNotification</tt> by
* specifying the <tt>commandDescriptor</tt>, which will point us to the
* command to execute.
*
* @param commandDescriptor a String that should point us to the command to
* execute
*/
public CommandNotificationAction(String commandDescriptor)
{
super(NotificationAction.ACTION_COMMAND);
this.commandDescriptor = commandDescriptor;
}
/**
* Returns the command descriptor.
*
* @return the command descriptor
*/
public String getDescriptor()
{
return commandDescriptor;
}
}

@ -13,17 +13,11 @@
* @author Yana Stamcheva * @author Yana Stamcheva
*/ */
public interface CommandNotificationHandler public interface CommandNotificationHandler
extends NotificationActionHandler extends NotificationHandler
{ {
/** /**
* Executes the program pointed by the descriptor. * Executes the program pointed by the descriptor.
* @param action the action to act upon
*/ */
public void execute(); public void execute(CommandNotificationAction action);
/**
* Returns the descriptor pointing to the command to be executed.
*
* @return the descriptor pointing to the command to be executed.
*/
public String getDescriptor();
} }

@ -0,0 +1,58 @@
/*
* 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;
/**
* An implementation of the <tt>LogMessageNotificationHandler</tt> interface.
*
* @author Yana Stamcheva
*/
public class LogMessageNotificationAction
extends NotificationAction
{
/**
* Indicates that this log is of type trace. If this <tt>logType</tt> is set
* the messages would be logged as trace logs.
*/
public static final String TRACE_LOG_TYPE = "TraceLog";
/**
* Indicates that this log is of type info. If this <tt>logType</tt> is set
* the messages would be logged as info logs.
*/
public static final String INFO_LOG_TYPE = "InfoLog";
/**
* Indicates that this log is of type error. If this <tt>logType</tt> is set
* the messages would be logged as error logs.
*/
public static final String ERROR_LOG_TYPE = "ErrorLog";
private String logType;
/**
* Creates an instance of <tt>LogMessageNotificationHandlerImpl</tt> by
* specifying the log type.
*
* @param logType the type of the log
*/
public LogMessageNotificationAction(String logType)
{
super(NotificationAction.ACTION_LOG_MESSAGE);
this.logType = logType;
}
/**
* Returns the type of the log
*
* @return the type of the log
*/
public String getLogType()
{
return logType;
}
}

@ -14,37 +14,13 @@
* @author Yana Stamcheva * @author Yana Stamcheva
*/ */
public interface LogMessageNotificationHandler public interface LogMessageNotificationHandler
extends NotificationActionHandler extends NotificationHandler
{ {
/**
* Indicates that this log is of type trace. If this <tt>logType</tt> is set
* the messages would be logged as trace logs.
*/
public static final String TRACE_LOG_TYPE = "TraceLog";
/**
* Indicates that this log is of type info. If this <tt>logType</tt> is set
* the messages would be logged as info logs.
*/
public static final String INFO_LOG_TYPE = "InfoLog";
/**
* Indicates that this log is of type error. If this <tt>logType</tt> is set
* the messages would be logged as error logs.
*/
public static final String ERROR_LOG_TYPE = "ErrorLog";
/**
* Returns the type of the log. One of the XXX_LOG_TYPE-s declared in this
* interface.
* @return the type of the log. One of the XXX_LOG_TYPE-s declared in this
* interface.
*/
public String getLogType();
/** /**
* Logs the given message. * Logs the given message.
*
* @param action the action to act upon
* @param message the message to log * @param message the message to log
*/ */
public void logMessage(String message); public void logMessage(LogMessageNotificationAction action, String message);
} }

@ -4,18 +4,16 @@
* Distributable under LGPL license. * Distributable under LGPL license.
* See terms of license at gnu.org. * See terms of license at gnu.org.
*/ */
package net.java.sip.communicator.impl.notification; package net.java.sip.communicator.service.notification;
import java.util.*; import java.util.*;
import net.java.sip.communicator.service.notification.*;
/** /**
* Represents an event notification. * Represents an event notification.
* *
* @author Yana Stamcheva * @author Yana Stamcheva
*/ */
public class EventNotification public class Notification
{ {
/** /**
* Indicates if this event notification is currently active. By default all * Indicates if this event notification is currently active. By default all
@ -27,8 +25,8 @@ public class EventNotification
* Contains all actions which will be executed when this event notification * Contains all actions which will be executed when this event notification
* is fired. * is fired.
*/ */
private final Hashtable<String, Action> actionsTable private final Hashtable<String, NotificationAction> actionsTable
= new Hashtable<String, Action>(); = new Hashtable<String, NotificationAction>();
/** /**
* Creates an instance of <tt>EventNotification</tt> by specifying the * Creates an instance of <tt>EventNotification</tt> by specifying the
@ -36,26 +34,22 @@ public class EventNotification
* *
* @param eventType the name of the event * @param eventType the name of the event
*/ */
public EventNotification(String eventType) public Notification(String eventType)
{ {
} }
/** /**
* Adds the given <tt>actionType</tt> to the list of actions for this event * Adds the given <tt>actionType</tt> to the list of actions for this event
* notifications. * notifications.
* * @param action the the handler that will process the given action
* @param actionType one of NotificationService.ACTION_XXX constants
* @param actionHandler the the handler that will process the given action
* type. * type.
*
* @return the previous value of the actionHandler for the given actionType, * @return the previous value of the actionHandler for the given actionType,
* if one existed, NULL if the actionType is a new one * if one existed, NULL if the actionType is a new one
*/ */
public Object addAction(String actionType, public Object addAction(NotificationAction action)
NotificationActionHandler actionHandler)
{ {
Action action = new Action(actionType, actionHandler); return actionsTable.put(action.getActionType(), action);
return actionsTable.put(actionType, action);
} }
/** /**
@ -73,7 +67,7 @@ public void removeAction(String actionType)
* *
* @return the set of actions registered for this event notification * @return the set of actions registered for this event notification
*/ */
public Map<String, Action> getActions() public Map<String, NotificationAction> getActions()
{ {
return actionsTable; return actionsTable;
} }
@ -87,57 +81,11 @@ public Map<String, Action> getActions()
* @return the <tt>Action</tt> corresponding to the given * @return the <tt>Action</tt> corresponding to the given
* <tt>actionType</tt> * <tt>actionType</tt>
*/ */
public Action getAction(String actionType) public NotificationAction getAction(String actionType)
{ {
return actionsTable.get(actionType); return actionsTable.get(actionType);
} }
/**
* The representation of an action, containing the corresponding
* action type, action descriptor and the default message associated with
* the action.
*/
public static class Action
{
private final String actionType;
private final NotificationActionHandler actionHandler;
/**
* Creates an instance of <tt>Action</tt> by specifying the type of the
* action, the descriptor and the default message.
*
* @param actionType one of NotificationService.ACTION_XXX constants
* @param actionHandler the handler that will process the given action
* type
*/
Action( String actionType,
NotificationActionHandler actionHandler)
{
this.actionType = actionType;
this.actionHandler = actionHandler;
}
/**
* Returns the the handler that will process the given action
* type.
* @return the the handler that will process the given action
* type.
*/
public NotificationActionHandler getActionHandler()
{
return actionHandler;
}
/**
* Return the action type name.
* @return the action type name.
*/
public String getActionType()
{
return actionType;
}
}
/** /**
* Indicates if this event notification is currently active. * Indicates if this event notification is currently active.
* *

@ -0,0 +1,95 @@
/*
* 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;
/**
* Base class for actions of a notification.
*
* @author Ingo Bauersachs
*/
public abstract class NotificationAction
{
/**
* The sound action type indicates that a sound would be played, when a
* notification is fired.
*/
public static final String ACTION_SOUND = "SoundAction";
/**
* The popup message action type indicates that a window (or a systray
* popup), containing the corresponding notification message would be poped
* up, when a notification is fired.
*/
public static final String ACTION_POPUP_MESSAGE = "PopupMessageAction";
/**
* The log message action type indicates that a message would be logged,
* when a notification is fired.
*/
public static final String ACTION_LOG_MESSAGE = "LogMessageAction";
/**
* The command action type indicates that a command would be executed,
* when a notification is fired.
*/
public static final String ACTION_COMMAND = "CommandAction";
/**
* Indicates if this handler is enabled.
*/
private boolean isEnabled = true;
/**
* The action type name.
*/
private String actionType;
/**
* Creates a new instance of this class.
* @param actionType The action type name.
*/
protected NotificationAction(String actionType)
{
this.actionType = actionType;
}
/**
* Return the action type name.
* @return the action type name.
*/
public String getActionType()
{
return actionType;
}
/**
* Returns TRUE if this notification action handler is enabled and FALSE
* otherwise. While the notification handler for the sound action type is
* disabled no sounds will be played when the <tt>fireNotification</tt>
* method is called.
*
* @return TRUE if this notification action handler is enabled and FALSE
* otherwise
*/
public boolean isEnabled()
{
return isEnabled;
}
/**
* Enables or disables this notification handler. While the notification
* handler for the sound action type is disabled no sounds will be played
* when the <tt>fireNotification</tt> method is called.
*
* @param isEnabled TRUE to enable this notification handler, FALSE to
* disable it.
*/
public void setEnabled(boolean isEnabled)
{
this.isEnabled = isEnabled;
}
}

@ -1,38 +0,0 @@
/*
* 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;
/**
* The <tt>NotificationActionHandler</tt> is the parent interface of all specific
* notification handlers used for handling different action types. This
* interface is used in the NotificationService in all methods dealing with
* action handlers.
*
* @author Yana Stamcheva
*/
public interface NotificationActionHandler
{
/**
* Returns TRUE if this notification action handler is enabled and FALSE
* otherwise. While the notification handler for an action type is disabled
* no notifications will be fired for this action type.
*
* @return TRUE if this notification action handler is enabled and FALSE
* otherwise
*/
public boolean isEnabled();
/**
* Enables or disables this notification handler. While the notification
* handler for an action type is disabled no notifications will be fired
* for this action type.
*
* @param isEnabled TRUE to enable this notification handler, FALSE to
* disable it.
*/
public void setEnabled(boolean isEnabled);
}

@ -0,0 +1,24 @@
/*
* 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;
/**
* The <tt>NotificationActionHandler</tt> is the parent interface of all specific
* notification handlers used for handling different action types. This
* interface is used in the NotificationService in all methods dealing with
* action handlers.
*
* @author Yana Stamcheva
*/
public interface NotificationHandler
{
/**
* Gets the type of this handler.
* @return the type of this handler.
*/
String getActionType();
}

@ -6,8 +6,6 @@
*/ */
package net.java.sip.communicator.service.notification; package net.java.sip.communicator.service.notification;
import java.util.*;
/** /**
* This service is previewed for use by bundles that implement some kind of * This service is previewed for use by bundles that implement some kind of
* user notification (e.g. playing sounds, poping systray tooltips, or * user notification (e.g. playing sounds, poping systray tooltips, or
@ -22,238 +20,79 @@
*/ */
public interface NotificationService public interface NotificationService
{ {
/**
* The log message action type indicates that a message would be logged,
* when a notification is fired.
*/
public static final String ACTION_LOG_MESSAGE = "LogMessageAction";
/**
* The popup message action type indicates that a window (or a systray
* popup), containing the corresponding notification message would be poped
* up, when a notification is fired.
*/
public static final String ACTION_POPUP_MESSAGE = "PopupMessageAction";
/**
* The sound action type indicates that a sound would be played, when a
* notification is fired.
*/
public static final String ACTION_SOUND = "SoundAction";
/**
* The command action type indicates that a command would be executed,
* when a notification is fired.
*/
public static final String ACTION_COMMAND = "CommandAction";
/**
* Default event type for receiving messages.
*/
public static final String INCOMING_MESSAGE = "IncomingMessage";
/**
* Default event type for receiving calls (incoming calls).
*/
public static final String INCOMING_CALL = "IncomingCall";
/**
* Default event type for outgoing calls.
*/
public static final String OUTGOING_CALL = "OutgoingCall";
/**
* Default event type for a busy call.
*/
public static final String BUSY_CALL = "BusyCall";
/**
* Default event type for dialing.
*/
public static final String DIALING = "Dialing";
/**
* Default event type for hanging up calls.
*/
public static final String HANG_UP = "HangUp";
/**
* Default event type for
* proactive notifications (typing notifications when chatting).
*/
public static final String PROACTIVE_NOTIFICATION = "ProactiveNotification";
/**
* Default event type when a secure message received.
*/
public static final String SECURITY_MESSAGE = "SecurityMessage";
/**
* Default event type for activated security on a call.
*/
public static final String CALL_SECURITY_ON = "CallSecurityOn";
/**
* Default event type for security error on a call.
*/
public static final String CALL_SECURITY_ERROR = "CallSecurityError";
/**
* Default event type for incoming file transfers.
*/
public static final String INCOMING_FILE = "IncomingFile";
/**
* Default event type for call been saved using a recorder.
*/
public static final String CALL_SAVED = "CallSaved";
/**
* Creates a <tt>SoundNotificationHandler</tt>, by specifying the
* path pointing to the sound file and the loop interval if the sound should
* be played in loop. If the sound should be played just once the loop
* interval should be set to -1. The <tt>SoundNotificationHandler</tt> is
* the one that would take care of playing the sound, when a notification
* is fired.
*
* @param soundFileDescriptor the path pointing to the sound file
* @param loopInterval the interval of milliseconds to repeat the sound in
* loop
* @return the <tt>SoundNotificationHandler</tt> is the one, that would take
* care of playing the given sound, when a notification is fired
*/
public SoundNotificationHandler createSoundNotificationHandler(
String soundFileDescriptor,
int loopInterval);
/**
* Creates a <tt>PopupMessageNotificationHandler</tt>, by specifying the
* default message to show, when no message is provided to the
* <tt>fireNotification</tt> method. The
* <tt>PopupMessageNotificationHandler</tt> is the one that would take care
* of showing a popup message (through the systray service for example),
* when a notification is fired.
*
* @param defaultMessage the message to show if not message is provided to
* the <tt>fireNotification</tt> method
* @return the <tt>PopupMessageNotificationHandler</tt> is the one, that
* would take care of showing a popup message (through the systray service
* for example), when a notification is fired.
*/
public PopupMessageNotificationHandler createPopupMessageNotificationHandler(
String defaultMessage);
/**
* Creates a <tt>LogMessageNotificationHandler</tt>, by specifying the
* type of the log (error, trace, info, etc.). The
* <tt>LogMessageNotificationHandler</tt> is the one that would take care
* of logging a message (through the application log system), when a
* notification is fired.
*
* @param logType the type of the log (error, trace, etc.). One of the types
* defined in the <tt>LogMessageNotificationHandler</tt> interface
* @return the <tt>LogMessageNotificationHandler</tt> is the one, that would
* take care of logging a message (through the application log system), when
* a notification is fired.
*/
public LogMessageNotificationHandler createLogMessageNotificationHandler(
String logType);
/**
* Creates a <tt>CommandNotificationHandler</tt>, by specifying the path to
* the command file to execute, when a notification is fired. The
* <tt>CommandNotificationHandler</tt> is the one that would take care
* of executing the given program, when a notification is fired.
*
* @param commandFileDescriptor the path to the file containing the program
* to execute
* @return the <tt>CommandNotificationHandler</tt> is the one, that would
* take care of executing a program, when a notification is fired.
*/
public CommandNotificationHandler createCommandNotificationHandler(
String commandFileDescriptor);
/** /**
* Registers a notification for the given <tt>eventType</tt> by specifying * Registers a notification for the given <tt>eventType</tt> by specifying
* the type of the action to be performed when a notification is fired for * the action to be performed when a notification is fired for this event.
* this event and the corresponding <tt>handler</tt> that should be used to *
* handle the action. Unlike the other <tt>registerNotificationForEvent</tt> * Unlike the other <tt>registerNotificationForEvent</tt>
* method, this one allows the user to specify its own * method, this one allows the user to specify its own
* <tt>NotificationHandler</tt>, which would be used to handle notifications * <tt>NotificationAction</tt>, which would be used to handle notifications
* for the specified <tt>actionType</tt>. * for the specified <tt>actionType</tt>.
* *
* @param eventType the name of the event (as defined by the plug-in that's * @param eventType the name of the event (as defined by the plug-in that's
* registering it) that we are setting an action for. * registering it) that we are setting an action for.
* @param actionType the type of the action that is to be executed when the * @param action the <tt>NotificationAction</tt>, which would be
* specified event occurs (could be one of the ACTION_XXX fields).
* @param handler the <tt>NotificationActionHandler</tt>, which would be
* used to perform the notification action. * used to perform the notification action.
* @throws IllegalArgumentException if the specified <tt>handler</tt> do not
* correspond to the given <tt>actionType</tt>.
*/ */
public void registerNotificationForEvent( String eventType, public void registerNotificationForEvent(String eventType,
String actionType, NotificationAction action);
NotificationActionHandler handler)
throws IllegalArgumentException;
/** /**
* Registers a Default notification for the given <tt>eventType</tt> by specifying * Registers a default notification for the given <tt>eventType</tt> by
* the type of the action to be performed when a notification is fired for * specifying the action to be performed when a notification is fired for
* this event and the corresponding <tt>handler</tt> that should be used to * this event.
* handle the action. Unlike the other *
* <tt>registerDefaultNotificationForEvent</tt> * Unlike the other <tt>registerDefaultNotificationForEvent</tt> method,
* method, this one allows the user to specify its own * this one allows the user to specify its own <tt>NotificationAction</tt>,
* <tt>NotificationHandler</tt>, which would be used to handle notifications * which would be used to handle notifications.
* for the specified <tt>actionType</tt>. *
* Default events are stored or executed at first run or when they are * Default events are stored or executed at first run or when they are
* missing in the configuration. Also the registered default events * missing in the configuration. Also the registered default events are used
* are used when restoreDefaults is called. * when restoreDefaults is called.
* *
* @param eventType the name of the event (as defined by the plug-in that's * @param eventType the name of the event (as defined by the plug-in that's
* registering it) that we are setting an action for. * registering it) that we are setting an action for.
* @param actionType the type of the action that is to be executed when the
* specified event occurs (could be one of the ACTION_XXX fields).
* @param handler the <tt>NotificationActionHandler</tt>, which would be * @param handler the <tt>NotificationActionHandler</tt>, which would be
* used to perform the notification action. * used to perform the notification action.
* @throws IllegalArgumentException if the specified <tt>handler</tt> do not
* correspond to the given <tt>actionType</tt>.
*/ */
public void registerDefaultNotificationForEvent( String eventType, public void registerDefaultNotificationForEvent(String eventType,
String actionType, NotificationAction handler);
NotificationActionHandler handler)
throws IllegalArgumentException;
/** /**
* Registers a default notification for the given <tt>eventType</tt> by specifying * Registers a default notification for the given <tt>eventType</tt> by
* the type of the action to be performed when a notification is fired for * specifying the type of the action to be performed when a notification is
* this event, the <tt>actionDescriptor</tt> for sound and command actions * fired for this event, the <tt>actionDescriptor</tt> for sound and command
* and the <tt>defaultMessage</tt> for popup and log actions. Actions * actions and the <tt>defaultMessage</tt> for popup and log actions.
* registered by this method would be handled by some default *
* Actions registered by this method would be handled by some default
* <tt>NotificationHandler</tt>s, declared by the implementation. * <tt>NotificationHandler</tt>s, declared by the implementation.
* <p> * <p>
* The method allows registering more than one actionType for a specific * The method allows registering more than one actionType for a specific
* event. Setting twice the same <tt>actionType</tt> for the same * event. Setting the same <tt>actionType</tt> for the same
* <tt>eventType</tt> however would cause the first setting to be * <tt>eventType</tt> twice however would cause the first setting to be
* overridden. * overridden.
* Default events are stored or executed at first run or when they are *
* missing in the configuration. Also the registered default events * Default events are stored or executed at first run or when
* they are missing in the configuration. Also the registered default events
* are used when restoreDefaults is called. * are used when restoreDefaults is called.
* *
* @param eventType the name of the event (as defined by the plug-in that's * @param eventType the name of the event (as defined by the plug-in that's
* registering it) that we are setting an action for. * registering it) that we are setting an action for.
* @param actionType the type of the action that is to be executed when the * @param actionType the type of the action that is to be executed when the
* specified event occurs (could be one of the ACTION_XXX fields). * specified event occurs (could be one of the ACTION_XXX
* fields).
* @param actionDescriptor a String containing a description of the action * @param actionDescriptor a String containing a description of the action
* (a URI to the sound file for audio notifications or a command line for * (a URI to the sound file for audio notifications or a command
* exec action types) that should be executed when the action occurs. * line for exec action types) that should be executed when the
* action occurs.
* @param defaultMessage the default message to use if no specific message * @param defaultMessage the default message to use if no specific message
* has been provided when firing the notification. * has been provided when firing the notification.
*/ */
public void registerDefaultNotificationForEvent( String eventType, public void registerDefaultNotificationForEvent(String eventType,
String actionType, String actionType,
String actionDescriptor, String actionDescriptor,
String defaultMessage); String defaultMessage);
/** /**
* Registers a notification for the given <tt>eventType</tt> by specifying * Registers a notification for the given <tt>eventType</tt> by specifying
* the type of the action to be performed when a notification is fired for * the type of the action to be performed when a notification is fired for
@ -263,44 +102,46 @@ public void registerDefaultNotificationForEvent( String eventType,
* <tt>NotificationHandler</tt>s, declared by the implementation. * <tt>NotificationHandler</tt>s, declared by the implementation.
* <p> * <p>
* The method allows registering more than one actionType for a specific * The method allows registering more than one actionType for a specific
* event. Setting twice the same <tt>actionType</tt> for the same * event. Setting the same <tt>actionType</tt> for the same
* <tt>eventType</tt> however would cause the first setting to be * <tt>eventType</tt> twice however would cause the first setting to be
* overridden. * overridden.
* *
* @param eventType the name of the event (as defined by the plug-in that's * @param eventType the name of the event (as defined by the plug-in that's
* registering it) that we are setting an action for. * registering it) that we are setting an action for.
* @param actionType the type of the action that is to be executed when the * @param actionType the type of the action that is to be executed when the
* specified event occurs (could be one of the ACTION_XXX fields). * specified event occurs (could be one of the ACTION_XXX
* fields).
* @param actionDescriptor a String containing a description of the action * @param actionDescriptor a String containing a description of the action
* (a URI to the sound file for audio notifications or a command line for * (a URI to the sound file for audio notifications or a command
* exec action types) that should be executed when the action occurs. * line for exec action types) that should be executed when the
* action occurs.
* @param defaultMessage the default message to use if no specific message * @param defaultMessage the default message to use if no specific message
* has been provided when firing the notification. * has been provided when firing the notification.
*/ */
public void registerNotificationForEvent( String eventType, public void registerNotificationForEvent( String eventType,
String actionType, String actionType,
String actionDescriptor, String actionDescriptor,
String defaultMessage); String defaultMessage);
/** /**
* Deletes all registered events and actions * Deletes all registered events and actions
* and registers and saves the default events as current. * and registers and saves the default events as current.
*/ */
public void restoreDefaults(); public void restoreDefaults();
/** /**
* Removes the given <tt>eventType</tt> from the list of event notifications. * Removes the given <tt>eventType</tt> from the list of event
* This means that we delete here all registered notifications for the given * notifications. This means that we delete here all registered
* <tt>eventType</tt>. * notifications for the given <tt>eventType</tt>.
* <p> * <p>
* This method does nothing if the given <tt>eventType</tt> is not contained * This method does nothing if the given <tt>eventType</tt> is not contained
* in the list of registered event types. * in the list of registered event types.
* *
* @param eventType the name of the event (as defined by the plugin that's * @param eventType the name of the event (as defined by the plugin that's
* registering it) to be removed. * registering it) to be removed.
*/ */
public void removeEventNotification(String eventType); public void removeEventNotification(String eventType);
/** /**
* Removes the event notification corresponding to the specified * Removes the event notification corresponding to the specified
* <tt>actionType</tt> and <tt>eventType</tt>. * <tt>actionType</tt> and <tt>eventType</tt>.
@ -309,57 +150,40 @@ public void registerNotificationForEvent( String eventType,
* <tt>actionType</tt> are not contained in the list of registered types. * <tt>actionType</tt> are not contained in the list of registered types.
* *
* @param eventType the name of the event (as defined by the plugin that's * @param eventType the name of the event (as defined by the plugin that's
* registering it) for which we'll remove the notification. * registering it) for which we'll remove the notification.
* @param actionType the type of the action that is to be executed when the * @param actionType the type of the action that is to be executed when the
* specified event occurs (could be one of the ACTION_XXX fields). * specified event occurs (could be one of the ACTION_XXX
* fields).
*/ */
public void removeEventNotificationAction( String eventType, public void removeEventNotificationAction( String eventType,
String actionType); String actionType);
/** /**
* Returns an iterator over a list of all events registered in this * Returns an iterator over a list of all events registered in this
* notification service. Each line in the returned list consists of * notification service. Each line in the returned list consists of a
* a String, representing the name of the event (as defined by the plugin * String, representing the name of the event (as defined by the plugin that
* that registered it). * registered it).
*
* @return an iterator over a list of all events registered in this
* notifications service
*/
public Iterator<String> getRegisteredEvents();
/**
* Returns a Map containing all action types (as keys) and actionDescriptors
* (as values) that have been registered for <tt>eventType</tt>.
* <p>
* This method returns <b>null</b> if the given <tt>eventType</tt> is not
* contained in the list of registered event types.
* *
* @param eventType the name of the event that we'd like to retrieve actions * @return an iterator over a list of all events registered in this
* for. * notifications service
* @return a <tt>Map</tt> containing the <tt>actionType</tt>s (as keys) and
* <tt>actionHandler</tt>s (as values) that should be executed when
* an event with the specified name has occurred, or null if no actions
* have been defined for <tt>eventType</tt>.
*/ */
public Map<String, NotificationActionHandler> getEventNotifications( public Iterable<String> getRegisteredEvents();
String eventType);
/** /**
* Returns the <tt>NotificationActionHandler</tt> corresponding to the given * Returns the <tt>NotificationAction</tt> corresponding to the given event
* event and action types. * and action type.
* <p> * <p>
* This method returns <b>null</b> if the given <tt>eventType</tt> or * This method returns <b>null</b> if the given <tt>eventType</tt> or
* <tt>actionType</tt> are not contained in the list of registered types. * <tt>actionType</tt> are not contained in the list of registered types.
* *
* @param eventType the type of the event that we'd like to retrieve. * @param eventType the type of the event that we'd like to retrieve.
* @param actionType the type of the action that we'd like to retrieve a * @param actionType the type of the action that we'd like to retrieve a
* descriptor for. * descriptor for.
* @return the <tt>NotificationActionHandler</tt> corresponding to the given * @return the <tt>NotificationAction</tt> corresponding to the given event
* event and action types * and action type
*/ */
public NotificationActionHandler getEventNotificationActionHandler( public NotificationAction getEventNotificationAction(String eventType,
String eventType, String actionType);
String actionType);
/** /**
* Registers a listener that would be notified of changes that have occurred * Registers a listener that would be notified of changes that have occurred
@ -381,6 +205,26 @@ public void addNotificationChangeListener(
public void removeNotificationChangeListener( public void removeNotificationChangeListener(
NotificationChangeListener listener); NotificationChangeListener listener);
/**
* Adds an object that executes the actual action of a notification action.
* @param handler The handler that executes the action.
*/
public void addActionHandler(NotificationHandler handler);
/**
* Removes an object that executes the actual action of notification action.
* @param actionType The handler type to remove.
*/
public void removeActionHandler(String actionType);
/**
* Gets at list of handler for the specified action type.
*
* @param actionType the type for which the list of handlers should be
* retrieved or <tt>null</tt> if all handlers shall be returned.
*/
public Iterable<NotificationHandler> getActionHandlers(String actionType);
/** /**
* Fires all notifications registered for the specified <tt>eventType</tt> * Fires all notifications registered for the specified <tt>eventType</tt>
* using <tt>message</tt> as a notification message wherever appropriate * using <tt>message</tt> as a notification message wherever appropriate

@ -0,0 +1,77 @@
/*
* 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;
import net.java.sip.communicator.service.configuration.*;
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 NotificationServiceActivator
implements BundleActivator
{
private final Logger logger
= Logger.getLogger(NotificationServiceActivator.class);
protected static BundleContext bundleContext;
private static ConfigurationService configService;
private ServiceRegistration notificationService;
public void start(BundleContext bc) throws Exception
{
bundleContext = bc;
try
{
logger.logEntry();
logger.info("Notification Service...[ STARTED ]");
notificationService = bundleContext.registerService(
NotificationService.class.getName(),
new NotificationServiceImpl(),
null);
logger.info("Notification Service ...[REGISTERED]");
}
finally
{
logger.logExit();
}
}
public void stop(BundleContext bc) throws Exception
{
notificationService.unregister();
logger.info("Notification Service ...[STOPPED]");
}
/**
* Returns the <tt>ConfigurationService</tt> obtained from the bundle
* context.
* @return the <tt>ConfigurationService</tt> obtained from the bundle
* context
*/
public static ConfigurationService getConfigurationService()
{
if(configService == null)
{
ServiceReference configReference = bundleContext
.getServiceReference(ConfigurationService.class.getName());
configService = (ConfigurationService) bundleContext
.getService(configReference);
}
return configService;
}
}

@ -0,0 +1,41 @@
/*
* 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;
/**
* An implementation of the <tt>PopupMessageNotificationHandler</tt> interface.
*
* @author Yana Stamcheva
*/
public class PopupMessageNotificationAction
extends NotificationAction
{
private String defaultMessage;
/**
* Creates an instance of <tt>PopupMessageNotificationHandlerImpl</tt> by
* specifying the default message to use if no message is specified.
*
* @param defaultMessage the default message to use if no message is
* specified
*/
public PopupMessageNotificationAction(String defaultMessage)
{
super(NotificationAction.ACTION_POPUP_MESSAGE);
this.defaultMessage = defaultMessage;
}
/**
* Return the default message to use if no message is specified.
*
* @return the default message to use if no message is specified.
*/
public String getDefaultMessage()
{
return defaultMessage;
}
}

@ -6,8 +6,6 @@
*/ */
package net.java.sip.communicator.service.notification; package net.java.sip.communicator.service.notification;
import net.java.sip.communicator.service.systray.*;
/** /**
* The <tt>PopupMessageNotificationHandler</tt> interface is meant to be * The <tt>PopupMessageNotificationHandler</tt> interface is meant to be
* implemented by the notification bundle in order to provide handling of * implemented by the notification bundle in order to provide handling of
@ -16,21 +14,22 @@
* @author Yana Stamcheva * @author Yana Stamcheva
*/ */
public interface PopupMessageNotificationHandler public interface PopupMessageNotificationHandler
extends NotificationActionHandler extends NotificationHandler
{ {
/**
* Returns the default message to be used when no message is provided to the
* <tt>popupMessage</tt> method.
*
* @return the default message to be used when no message is provided to the
* <tt>popupMessage</tt> method.
*/
public String getDefaultMessage();
/** /**
* Shows the given <tt>PopupMessage</tt> * Shows the given <tt>PopupMessage</tt>
* *
* @param message the message to show in the popup * @param action the action to act upon
* @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
*/ */
public void popupMessage(PopupMessage message); public void popupMessage(PopupMessageNotificationAction action,
String title,
String message,
byte[] icon,
Object tag);
} }

@ -0,0 +1,75 @@
/*
* 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;
/**
* An implementation of the <tt>SoundNotificationHandlerImpl</tt> interface.
*
* @author Yana Stamcheva
*/
public class SoundNotificationAction
extends NotificationAction
{
/**
* Interval of milliseconds to wait before repeating the sound. -1 means no
* repetition.
*/
private int loopInterval;
/**
* the descriptor pointing to the sound to be played.
*/
private String soundFileDescriptor;
/**
* Creates an instance of <tt>SoundNotification</tt> by
* specifying the sound file descriptor. The sound is played once.
*
* @param soundDescriptor the sound file descriptor
*/
public SoundNotificationAction(String soundDescriptor)
{
this(soundDescriptor, -1);
}
/**
* Creates an instance of <tt>SoundNotification</tt> by
* specifying the sound file descriptor and the loop interval.
*
* @param soundDescriptor the sound file descriptor
* @param loopInterval the loop interval
*/
public SoundNotificationAction( String soundDescriptor,
int loopInterval)
{
super(NotificationAction.ACTION_SOUND);
this.soundFileDescriptor = soundDescriptor;
this.loopInterval = loopInterval;
}
/**
* Returns the loop interval. This is the interval of milliseconds to wait
* before repeating the sound, when playing a sound in loop. By default this
* method returns -1.
*
* @return the loop interval
*/
public int getLoopInterval()
{
return loopInterval;
}
/**
* Returns the descriptor pointing to the sound to be played.
*
* @return the descriptor pointing to the sound to be played.
*/
public String getDescriptor()
{
return soundFileDescriptor;
}
}

@ -14,30 +14,15 @@
* @author Yana Stamcheva * @author Yana Stamcheva
*/ */
public interface SoundNotificationHandler public interface SoundNotificationHandler
extends NotificationActionHandler extends NotificationHandler
{ {
/**
* Returns the loop interval. This is the interval of milliseconds to wait
* before repeating the sound, when playing a sound in loop. If this method
* returns -1 the sound should not played in loop.
*
* @return the loop interval
*/
public int getLoopInterval();
/**
* Returns the descriptor pointing to the sound to be played.
*
* @return the descriptor pointing to the sound to be played.
*/
public String getDescriptor();
/** /**
* Start playing the sound pointed by <tt>getDescriotor</tt>. This * Start playing the sound pointed by <tt>getDescriotor</tt>. This
* method should check the loopInterval value to distinguish whether to play * method should check the loopInterval value to distinguish whether to play
* a simple sound or to play it in loop. * a simple sound or to play it in loop.
* @param action the action to act upon
*/ */
public void start(); public void start(SoundNotificationAction action);
/** /**
* Stops playing the sound pointing by <tt>getDescriptor</tt>. This method * Stops playing the sound pointing by <tt>getDescriptor</tt>. This method

@ -39,11 +39,6 @@ public class NotificationActionTypeEvent
*/ */
public static final String ACTION_CHANGED = "ActionChanged"; public static final String ACTION_CHANGED = "ActionChanged";
/**
* The type of the notification action that is being added.
*/
private String sourceActionType = null;
/** /**
* The type of the event that a new action is being added for. * The type of the event that a new action is being added for.
*/ */
@ -54,7 +49,7 @@ public class NotificationActionTypeEvent
* string) that will be performed when notifications are being fired for * string) that will be performed when notifications are being fired for
* the corresponding event type. * the corresponding event type.
*/ */
private NotificationActionHandler actionHandler = null; private NotificationAction actionHandler = null;
/** /**
* The type of this event. One of the static field constants declared in * The type of this event. One of the static field constants declared in
@ -69,34 +64,21 @@ public class NotificationActionTypeEvent
* @param eventType the type of this event. One of the static fields * @param eventType the type of this event. One of the static fields
* declared in this class * declared in this class
* @param sourceEventType the event type for which this event occured * @param sourceEventType the event type for which this event occured
* @param sourceActionType the action type corresponding to this event
* @param actionHandler the <tt>NotificationActionHandler</tt> that handles * @param actionHandler the <tt>NotificationActionHandler</tt> that handles
* the given action * the given action
*/ */
public NotificationActionTypeEvent( NotificationService source, public NotificationActionTypeEvent( NotificationService source,
String eventType, String eventType,
String sourceEventType, String sourceEventType,
String sourceActionType, NotificationAction actionHandler)
NotificationActionHandler actionHandler)
{ {
super(source); super(source);
this.eventType = eventType; this.eventType = eventType;
this.sourceEventType = sourceEventType; this.sourceEventType = sourceEventType;
this.sourceActionType = sourceActionType;
this.actionHandler = actionHandler; this.actionHandler = actionHandler;
} }
/**
* Returns the action type, for which this event is about.
*
* @return the action type, for which this event is about.
*/
public String getSourceActionType()
{
return sourceActionType;
}
/** /**
* Returns the event type, to which the given action belongs. * Returns the event type, to which the given action belongs.
* *
@ -114,7 +96,7 @@ public String getSourceEventType()
* @return the <tt>NotificationActionHandler</tt> that handles the action, * @return the <tt>NotificationActionHandler</tt> that handles the action,
* for which this event is about. * for which this event is about.
*/ */
public NotificationActionHandler getActionHandler() public NotificationAction getActionHandler()
{ {
return actionHandler; return actionHandler;
} }

@ -0,0 +1,11 @@
Bundle-Activator: net.java.sip.communicator.service.notification.NotificationServiceActivator
Bundle-Name: Notifications
Bundle-Description: An implementation of the Notification service.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
System-Bundle: yes
Export-Package: net.java.sip.communicator.service.notification,
net.java.sip.communicator.service.notification.event
Import-Package: org.osgi.framework,
net.java.sip.communicator.util,
net.java.sip.communicator.service.configuration

@ -127,7 +127,7 @@ public void testNotificationHandling()
= (NotificationService) bc.getService(serviceReference); = (NotificationService) bc.getService(serviceReference);
notificationService.fireNotification( notificationService.fireNotification(
NotificationService.ACTION_POPUP_MESSAGE, NotificationAction.ACTION_POPUP_MESSAGE,
messageStart, messageStart,
messageStart, messageStart,
null, null,

Loading…
Cancel
Save