diff options
author | Ingo Bauersachs <ingo@jitsi.org> | 2011-12-05 19:40:11 +0000 |
---|---|---|
committer | Ingo Bauersachs <ingo@jitsi.org> | 2011-12-05 19:40:11 +0000 |
commit | c543e54197ffca702b75a3350fccaaf348357835 (patch) | |
tree | 552af02fa37d4d7dc9af4e5b6fedb43f137aaf25 | |
parent | 6102f58f12caa76ded763834b92f2af10e283ce8 (diff) | |
download | jitsi-c543e54197ffca702b75a3350fccaaf348357835.zip jitsi-c543e54197ffca702b75a3350fccaaf348357835.tar.gz jitsi-c543e54197ffca702b75a3350fccaaf348357835.tar.bz2 |
Separate notification service from its handlers
31 files changed, 1153 insertions, 1307 deletions
@@ -915,8 +915,9 @@ bundle-sparkle, bundle-plugin-branding, bundle-systemactivitynotifications, bundle-osdependent,bundle-browserlauncher, - bundle-pluginmanager,bundle-skinmanager,bundle-notification, - bundle-notification-config,bundle-contacteventhandler, + bundle-pluginmanager,bundle-skinmanager, + bundle-notification-service,bundle-notification-handlers,bundle-notification-config, + bundle-contacteventhandler, bundle-plugin-contactinfo,bundle-plugin-chatalerter, bundle-keybindings, bundle-plugin-keybindingChooser,bundle-plugin-globalproxyconfig, bundle-jfontchooserlib,bundle-update,bundle-plugin-update, @@ -2050,12 +2051,19 @@ javax.swing.event, javax.swing.border"/> </target> <!-- BUNDLE-NOTIFICATION --> - <target name="bundle-notification"> + <target name="bundle-notification-service"> <!-- Creates a bundle for the notifications.--> - <jar compress="false" destfile="${bundles.dest}/notification.jar" - manifest="${src}/net/java/sip/communicator/impl/notification/notification.manifest.mf"> + <jar compress="false" destfile="${bundles.dest}/notification-service.jar" + manifest="${src}/net/java/sip/communicator/service/notification/notification.manifest.mf"> <zipfileset dir="${dest}/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" prefix="net/java/sip/communicator/impl/notification"/> </jar> diff --git a/lib/felix.client.run.properties b/lib/felix.client.run.properties index e5f9887..665ec03 100644 --- a/lib/felix.client.run.properties +++ b/lib/felix.client.run.properties @@ -33,17 +33,18 @@ felix.auto.start.10= \ felix.auto.start.20= \ reference:file:sc-bundles/util.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= \ - reference:file:sc-bundles/fileaccess.jar + reference:file:sc-bundles/configuration.jar \ + reference:file:sc-bundles/notification-service.jar \ felix.auto.start.35= \ reference:file:sc-bundles/commons-codec.jar \ reference:file:sc-bundles/httputil.jar felix.auto.start.40= \ - reference:file:sc-bundles/configuration.jar \ reference:file:sc-bundles/jmdnslib.jar \ reference:file:sc-bundles/jnalib.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/metahistory.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 felix.auto.start.66= \ diff --git a/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java index 6634a41..4ab6621 100644 --- a/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java +++ b/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java @@ -22,77 +22,33 @@ public class CommandNotificationHandlerImpl private Logger logger = Logger.getLogger(CommandNotificationHandlerImpl.class); - private String commandDescriptor; - - private boolean isEnabled = true; - /** - * Creates an instance of <tt>CommandNotificationHandlerImpl</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 + * {@inheritDoc} */ - public CommandNotificationHandlerImpl(String commandDescriptor) + public String getActionType() { - this.commandDescriptor = commandDescriptor; + return NotificationAction.ACTION_COMMAND; } /** - * Executes the <tt>command</tt>, given by the containing - * <tt>commandDescriptor</tt>. + * Executes the command, given by the <tt>commandDescriptor</tt> of the + * 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; try { - Runtime.getRuntime().exec(commandDescriptor); + Runtime.getRuntime().exec(action.getDescriptor()); } catch (IOException e) { 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; - } } diff --git a/src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java index 55fe13d..7ac671b 100644 --- a/src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java +++ b/src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java @@ -8,6 +8,7 @@ package net.java.sip.communicator.impl.notification; import net.java.sip.communicator.service.notification.*; import net.java.sip.communicator.util.*; +import static net.java.sip.communicator.service.notification.LogMessageNotificationAction.*; /** * An implementation of the <tt>LogMessageNotificationHandler</tt> interface. @@ -23,72 +24,27 @@ public class LogMessageNotificationHandlerImpl private Logger logger = 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 - * - * @return the type of the log + * {@inheritDoc} */ - public String getLogType() + public String getActionType() { - return logType; + return NotificationAction.ACTION_LOG_MESSAGE; } /** * Logs a message through the sip communicator Logger. * + * @param action the action to act upon * @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); - else if(logType.equals(LogMessageNotificationHandler.INFO_LOG_TYPE)) - if (logger.isInfoEnabled()) - logger.info(message); - else if(logType.equals(LogMessageNotificationHandler.TRACE_LOG_TYPE)) - 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; + else if(action.getLogType().equals(INFO_LOG_TYPE)) + logger.info(message); + else if(action.getLogType().equals(TRACE_LOG_TYPE)) + logger.trace(message); } } diff --git a/src/net/java/sip/communicator/impl/notification/NotificationActivator.java b/src/net/java/sip/communicator/impl/notification/NotificationActivator.java index 116b29b..ef91479 100644 --- a/src/net/java/sip/communicator/impl/notification/NotificationActivator.java +++ b/src/net/java/sip/communicator/impl/notification/NotificationActivator.java @@ -7,7 +7,6 @@ package net.java.sip.communicator.impl.notification; 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.neomedia.*; import net.java.sip.communicator.service.notification.*; @@ -29,73 +28,65 @@ public class NotificationActivator private final Logger logger = Logger.getLogger(NotificationActivator.class); protected static BundleContext bundleContext; - - private static ConfigurationService configService; - + private static AudioNotifierService audioNotifierService; - private static SystrayService systrayService; - private static NotificationService notificationService; - private static ResourceManagementService resourcesService; - private static UIService uiService = null; - private static MediaService mediaService; - + + private CommandNotificationHandler commandHandler; + private LogMessageNotificationHandler logMessageHandler; + private PopupMessageNotificationHandler popupMessageHandler; + private SoundNotificationHandler soundHandler; + public void start(BundleContext bc) throws Exception { bundleContext = bc; + try + { + logger.logEntry(); + logger.info("Notification handler Service...[ STARTED ]"); + - try { - // Create the notification service implementation - notificationService = new NotificationServiceImpl(); + // Get the notification service implementation + ServiceReference notifReference = bundleContext + .getServiceReference(NotificationService.class.getName()); - if (logger.isInfoEnabled()) - logger.info("Notification Service...[ STARTED ]"); + notificationService = (NotificationService) bundleContext + .getService(notifReference); - bundleContext.registerService(NotificationService.class.getName(), - notificationService, null); + commandHandler = new CommandNotificationHandlerImpl(); + logMessageHandler = new LogMessageNotificationHandlerImpl(); + popupMessageHandler = new PopupMessageNotificationHandlerImpl(); + soundHandler = new SoundNotificationHandlerImpl(); + + notificationService.addActionHandler(commandHandler); + notificationService.addActionHandler(logMessageHandler); + notificationService.addActionHandler(popupMessageHandler); + notificationService.addActionHandler(soundHandler); new NotificationManager().init(); - if (logger.isInfoEnabled()) - logger.info("Notification Service ...[REGISTERED]"); - - logger.logEntry(); + logger.info("Notification handler Service ...[REGISTERED]"); } - finally { + finally + { logger.logExit(); } } public void stop(BundleContext bc) throws Exception { - if (logger.isInfoEnabled()) - logger.info("UI 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); - } + notificationService.removeActionHandler(commandHandler.getActionType()); + notificationService.removeActionHandler(logMessageHandler.getActionType()); + notificationService.removeActionHandler(popupMessageHandler.getActionType()); + notificationService.removeActionHandler(soundHandler.getActionType()); - return configService; + logger.info("Notification handler Service ...[STOPPED]"); } - + /** * Returns the <tt>AudioNotifierService</tt> obtained from the bundle * context. @@ -118,7 +109,7 @@ public class NotificationActivator return audioNotifierService; } - + /** * Returns the <tt>SystrayService</tt> obtained from the bundle context. * diff --git a/src/net/java/sip/communicator/impl/notification/NotificationManager.java b/src/net/java/sip/communicator/impl/notification/NotificationManager.java index a71958d..c6af7a0 100644 --- a/src/net/java/sip/communicator/impl/notification/NotificationManager.java +++ b/src/net/java/sip/communicator/impl/notification/NotificationManager.java @@ -69,6 +69,67 @@ public class NotificationManager 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 * new protocols or removed one and find any that are already registered. */ @@ -101,120 +162,108 @@ public class NotificationManager // Register incoming message notifications. notificationService.registerDefaultNotificationForEvent( - NotificationService.INCOMING_MESSAGE, - NotificationService.ACTION_POPUP_MESSAGE, + NotificationManager.INCOMING_MESSAGE, + NotificationAction.ACTION_POPUP_MESSAGE, null, null); notificationService.registerDefaultNotificationForEvent( - NotificationService.INCOMING_MESSAGE, - NotificationService.ACTION_SOUND, + NotificationManager.INCOMING_MESSAGE, + NotificationAction.ACTION_SOUND, SoundProperties.INCOMING_MESSAGE, null); // Register incoming call notifications. notificationService.registerDefaultNotificationForEvent( - NotificationService.INCOMING_CALL, - NotificationService.ACTION_POPUP_MESSAGE, + NotificationManager.INCOMING_CALL, + NotificationAction.ACTION_POPUP_MESSAGE, null, null); - SoundNotificationHandler inCallSoundHandler - = notificationService - .createSoundNotificationHandler(SoundProperties.INCOMING_CALL, - 2000); + SoundNotificationAction inCallSoundHandler + = new SoundNotificationAction(SoundProperties.INCOMING_CALL, 2000); notificationService.registerDefaultNotificationForEvent( - NotificationService.INCOMING_CALL, - NotificationService.ACTION_SOUND, + NotificationManager.INCOMING_CALL, inCallSoundHandler); // Register outgoing call notifications. - SoundNotificationHandler outCallSoundHandler - = notificationService - .createSoundNotificationHandler(SoundProperties.OUTGOING_CALL, - 3000); + SoundNotificationAction outCallSoundHandler + = new SoundNotificationAction(SoundProperties.OUTGOING_CALL, 3000); notificationService.registerDefaultNotificationForEvent( - NotificationService.OUTGOING_CALL, - NotificationService.ACTION_SOUND, + NotificationManager.OUTGOING_CALL, outCallSoundHandler); // Register busy call notifications. - SoundNotificationHandler busyCallSoundHandler - = notificationService - .createSoundNotificationHandler(SoundProperties.BUSY, 1); + SoundNotificationAction busyCallSoundHandler + = new SoundNotificationAction(SoundProperties.BUSY, 1); notificationService.registerDefaultNotificationForEvent( - NotificationService.BUSY_CALL, - NotificationService.ACTION_SOUND, + NotificationManager.BUSY_CALL, busyCallSoundHandler); // Register dial notifications. - SoundNotificationHandler dialSoundHandler - = notificationService - .createSoundNotificationHandler(SoundProperties.DIALING, 0); + SoundNotificationAction dialSoundHandler + = new SoundNotificationAction(SoundProperties.DIALING, 0); notificationService.registerDefaultNotificationForEvent( - NotificationService.DIALING, - NotificationService.ACTION_SOUND, + NotificationManager.DIALING, dialSoundHandler); // Register the hangup sound notification. - SoundNotificationHandler hangupSoundHandler - = notificationService - .createSoundNotificationHandler(SoundProperties.HANG_UP, -1); + SoundNotificationAction hangupSoundHandler + = new SoundNotificationAction(SoundProperties.HANG_UP, -1); notificationService.registerDefaultNotificationForEvent( - NotificationService.HANG_UP, - NotificationService.ACTION_SOUND, + NotificationManager.HANG_UP, hangupSoundHandler); // Register proactive notifications. notificationService.registerDefaultNotificationForEvent( - NotificationService.PROACTIVE_NOTIFICATION, - NotificationService.ACTION_POPUP_MESSAGE, + NotificationManager.PROACTIVE_NOTIFICATION, + NotificationAction.ACTION_POPUP_MESSAGE, null, null); // Register warning message notifications. notificationService.registerDefaultNotificationForEvent( - NotificationService.SECURITY_MESSAGE, - NotificationService.ACTION_POPUP_MESSAGE, + NotificationManager.SECURITY_MESSAGE, + NotificationAction.ACTION_POPUP_MESSAGE, null, null); // Register sound notification for security state on during a call. notificationService.registerDefaultNotificationForEvent( - NotificationService.CALL_SECURITY_ON, - NotificationService.ACTION_SOUND, + NotificationManager.CALL_SECURITY_ON, + NotificationAction.ACTION_SOUND, SoundProperties.CALL_SECURITY_ON, null); // Register sound notification for security state off during a call. notificationService.registerDefaultNotificationForEvent( - NotificationService.CALL_SECURITY_ERROR, - NotificationService.ACTION_SOUND, + NotificationManager.CALL_SECURITY_ERROR, + NotificationAction.ACTION_SOUND, SoundProperties.CALL_SECURITY_ERROR, null); // Register sound notification for incoming files. notificationService.registerDefaultNotificationForEvent( - NotificationService.INCOMING_FILE, - NotificationService.ACTION_POPUP_MESSAGE, + NotificationManager.INCOMING_FILE, + NotificationAction.ACTION_POPUP_MESSAGE, null, null); notificationService.registerDefaultNotificationForEvent( - NotificationService.INCOMING_FILE, - NotificationService.ACTION_SOUND, + NotificationManager.INCOMING_FILE, + NotificationAction.ACTION_SOUND, SoundProperties.INCOMING_FILE, null); // Register notification for saved calls. notificationService.registerDefaultNotificationForEvent( - NotificationService.CALL_SAVED, - NotificationService.ACTION_POPUP_MESSAGE, + NotificationManager.CALL_SAVED, + NotificationAction.ACTION_POPUP_MESSAGE, null, null); } @@ -537,7 +586,7 @@ public class NotificationManager if(notificationService == null) return; - NotificationActionHandler popupActionHandler = null; + NotificationAction popupActionHandler = null; UIService uiService = NotificationActivator.getUIService(); Chat chatPanel = null; @@ -570,12 +619,12 @@ public class NotificationManager if (chatPanel != null) { - if (eventType.equals(NotificationService.INCOMING_MESSAGE) + if (eventType.equals(NotificationManager.INCOMING_MESSAGE) && chatPanel.isChatFocused()) { popupActionHandler = notificationService - .getEventNotificationActionHandler(eventType, - NotificationService.ACTION_POPUP_MESSAGE); + .getEventNotificationAction(eventType, + NotificationAction.ACTION_POPUP_MESSAGE); popupActionHandler.setEnabled(false); } @@ -623,14 +672,15 @@ public class NotificationManager if(notificationService == null) return; - SoundNotificationHandler soundHandler - = (SoundNotificationHandler) notificationService - .getEventNotificationActionHandler( - eventType, NotificationService.ACTION_SOUND); + Iterable<NotificationHandler> soundHandlers = + notificationService.getActionHandlers( + NotificationAction.ACTION_SOUND); + //TODO make SoundNotificationHandler handle multiple sound at once // There can be no sound action handler for this event type - if(soundHandler != null) - soundHandler.stop(); + if(soundHandlers != null) + for(NotificationHandler handler : soundHandlers) + ((SoundNotificationHandler)handler).stop(); } /** @@ -675,10 +725,10 @@ public class NotificationManager */ private static void stopAllTelephonySounds() { - NotificationManager.stopSound(NotificationService.DIALING); - NotificationManager.stopSound(NotificationService.BUSY_CALL); - NotificationManager.stopSound(NotificationService.INCOMING_CALL); - NotificationManager.stopSound(NotificationService.OUTGOING_CALL); + NotificationManager.stopSound(NotificationManager.DIALING); + NotificationManager.stopSound(NotificationManager.BUSY_CALL); + NotificationManager.stopSound(NotificationManager.INCOMING_CALL); + NotificationManager.stopSound(NotificationManager.OUTGOING_CALL); } /** @@ -763,7 +813,7 @@ public class NotificationManager fireChatNotification( evt.getSourceContact(), - NotificationService.INCOMING_MESSAGE, + NotificationManager.INCOMING_MESSAGE, title, evt.getSourceMessage().getContent()); } @@ -810,7 +860,7 @@ public class NotificationManager NotificationManager .fireChatNotification( sourceContact, - NotificationService.INCOMING_FILE, + NotificationManager.INCOMING_FILE, title, request.getFileName()); } @@ -910,7 +960,7 @@ public class NotificationManager NotificationManager.fireChatNotification( contact, - NotificationService.PROACTIVE_NOTIFICATION, + NotificationManager.PROACTIVE_NOTIFICATION, contact.getDisplayName(), NotificationActivator.getResources() .getI18NString("service.gui.PROACTIVE_NOTIFICATION")); @@ -935,7 +985,7 @@ public class NotificationManager .getCallPeers().next().getDisplayName(); NotificationManager.fireNotification( - NotificationService.INCOMING_CALL, + NotificationManager.INCOMING_CALL, "", NotificationActivator.getResources() .getI18NString("service.gui.INCOMING_CALL", @@ -988,7 +1038,7 @@ public class NotificationManager stopAllTelephonySounds(); // Play the hangup sound. - NotificationManager.fireNotification(NotificationService.HANG_UP); + NotificationManager.fireNotification(NotificationManager.HANG_UP); } catch(Throwable t) { @@ -1055,11 +1105,11 @@ public class NotificationManager || newState == CallPeerState.CONNECTING) { NotificationManager - .fireNotification(NotificationService.DIALING); + .fireNotification(NotificationManager.DIALING); } else { - NotificationManager.stopSound(NotificationService.DIALING); + NotificationManager.stopSound(NotificationManager.DIALING); } if (newState == CallPeerState.ALERTING_REMOTE_SIDE @@ -1069,17 +1119,17 @@ public class NotificationManager && oldState != CallPeerState.CONNECTING_WITH_EARLY_MEDIA) { NotificationManager - .fireNotification(NotificationService.OUTGOING_CALL); + .fireNotification(NotificationManager.OUTGOING_CALL); } 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. if (!isConference(sourcePeer.getCall())) { NotificationManager.fireNotification( - NotificationService.BUSY_CALL); + NotificationManager.BUSY_CALL); } } else if (newState == CallPeerState.CONNECTING_INCOMING_CALL || @@ -1088,9 +1138,9 @@ public class NotificationManager if (!CallPeerState.isOnHold(oldState)) { NotificationManager - .stopSound(NotificationService.OUTGOING_CALL); + .stopSound(NotificationManager.OUTGOING_CALL); NotificationManager - .stopSound(NotificationService.INCOMING_CALL); + .stopSound(NotificationManager.INCOMING_CALL); } } else if (newState == CallPeerState.CONNECTING_WITH_EARLY_MEDIA) @@ -1098,16 +1148,16 @@ public class NotificationManager //this means a call with early media. make sure that we are not //playing local notifications any more. NotificationManager - .stopSound(NotificationService.OUTGOING_CALL); + .stopSound(NotificationManager.OUTGOING_CALL); } else if (newState == CallPeerState.CONNECTED) { if (!CallPeerState.isOnHold(oldState)) { NotificationManager - .stopSound(NotificationService.OUTGOING_CALL); + .stopSound(NotificationManager.OUTGOING_CALL); NotificationManager - .stopSound(NotificationService.INCOMING_CALL); + .stopSound(NotificationManager.INCOMING_CALL); } } else if (newState == CallPeerState.DISCONNECTED @@ -1115,7 +1165,7 @@ public class NotificationManager { stopAllTelephonySounds(); - NotificationManager.fireNotification(NotificationService.HANG_UP); + NotificationManager.fireNotification(NotificationManager.HANG_UP); } } catch(Throwable t) @@ -1171,7 +1221,7 @@ public class NotificationManager || !evt.getSecurityController().requiresSecureSignalingTransport()) { NotificationManager.fireNotification( - NotificationService.CALL_SECURITY_ON); + NotificationManager.CALL_SECURITY_ON); } } catch(Throwable t) @@ -1221,12 +1271,12 @@ public class NotificationManager messageTitle = NotificationActivator.getResources() .getI18NString("service.gui.SECURITY_ERROR"); NotificationManager.fireNotification( - NotificationService.CALL_SECURITY_ERROR); + NotificationManager.CALL_SECURITY_ERROR); } } NotificationManager.fireNotification( - NotificationService.SECURITY_MESSAGE, + NotificationManager.SECURITY_MESSAGE, messageTitle, event.getI18nMessage()); } @@ -1291,7 +1341,7 @@ public class NotificationManager NotificationManager.fireChatNotification( sourceChatRoom, - NotificationService.INCOMING_MESSAGE, + NotificationManager.INCOMING_MESSAGE, title, messageContent); } @@ -1411,7 +1461,7 @@ public class NotificationManager NotificationManager.fireChatNotification( sourceChatRoom, - NotificationService.INCOMING_MESSAGE, + NotificationManager.INCOMING_MESSAGE, title, messageContent); } @@ -1472,7 +1522,7 @@ public class NotificationManager if (securityEvent instanceof CallPeerSecurityOnEvent) { NotificationManager.fireNotification( - NotificationService.CALL_SECURITY_ON); + NotificationManager.CALL_SECURITY_ON); } } } @@ -1503,7 +1553,7 @@ public class NotificationManager try { NotificationManager.fireNotification( - NotificationService.CALL_SAVED, + NotificationManager.CALL_SAVED, NotificationActivator.getResources().getI18NString( "plugin.callrecordingconfig.CALL_SAVED"), NotificationActivator.getResources().getI18NString( diff --git a/src/net/java/sip/communicator/impl/notification/PopupMessageNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/PopupMessageNotificationHandlerImpl.java index 68a9924..41b68ea 100644 --- a/src/net/java/sip/communicator/impl/notification/PopupMessageNotificationHandlerImpl.java +++ b/src/net/java/sip/communicator/impl/notification/PopupMessageNotificationHandlerImpl.java @@ -18,71 +18,35 @@ import net.java.sip.communicator.service.systray.*; public class PopupMessageNotificationHandlerImpl implements PopupMessageNotificationHandler { - private String defaultMessage; - - private boolean isEnabled = true; - /** - * 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 + * {@inheritDoc} */ - public PopupMessageNotificationHandlerImpl(String defaultMessage) + public String getActionType() { - 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; + return NotificationAction.ACTION_POPUP_MESSAGE; } /** - * Shows a popup message through the <tt>SystrayService</tt>. - * - * @param message the message to show in the popup + * Shows the given <tt>PopupMessage</tt> + * + * @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(); - if(systray == null) return; - systray.showPopupMessage(message); - } - - /** - * 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; + systray.showPopupMessage(new PopupMessage(title, message, icon, tag)); } } diff --git a/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java index 9a95f34..8a568a0 100644 --- a/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java +++ b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java @@ -18,81 +18,47 @@ import net.java.sip.communicator.util.*; public class SoundNotificationHandlerImpl 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. */ private SCAudioClip audio; /** - * Indicates if this handler is enabled. - */ - private boolean isEnabled = true; - - /** - * Creates an instance of <tt>SoundNotificationHandlerImpl</tt> by - * specifying the sound file descriptor. - * - * @param soundDescriptor the sound file descriptor + * {@inheritDoc} */ - public SoundNotificationHandlerImpl(String soundDescriptor) + public String getActionType() { - this.soundFileDescriptor = soundDescriptor; - } - - /** - * 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; + return NotificationAction.ACTION_SOUND; } /** * Plays the sound given by the containing <tt>soundFileDescriptor</tt>. The * sound is played in loop if the loopInterval is defined. + * @param action the action to act upon. */ - public void start() + public void start(SoundNotificationAction action) { AudioNotifierService audioNotifService = NotificationActivator.getAudioNotifier(); if(audioNotifService == null - || StringUtils.isNullOrEmpty(soundFileDescriptor, true)) + || StringUtils.isNullOrEmpty(action.getDescriptor(), true)) 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 if(audio == null) return; - if(loopInterval > -1) - audio.playInLoop(loopInterval); + if(action.getLoopInterval() > -1) + audio.playInLoop(action.getLoopInterval()); else audio.play(); } @@ -105,51 +71,11 @@ public class SoundNotificationHandlerImpl AudioNotifierService audioNotifService = NotificationActivator.getAudioNotifier(); - if(audioNotifService == null) - return; - - if(audio == null) + if(audioNotifService == null || audio == null) return; audio.stop(); - audioNotifService.destroyAudio(audio); - } - - /** - * 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; + audio = null; } } diff --git a/src/net/java/sip/communicator/impl/notification/notification.manifest.mf b/src/net/java/sip/communicator/impl/notification/notification.manifest.mf index 16ab42c..4ac8cb2 100644 --- a/src/net/java/sip/communicator/impl/notification/notification.manifest.mf +++ b/src/net/java/sip/communicator/impl/notification/notification.manifest.mf @@ -4,11 +4,10 @@ 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, javax.imageio, net.java.sip.communicator.util, + net.java.sip.communicator.service.notification, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.contactlist, net.java.sip.communicator.service.audionotifier, diff --git a/src/net/java/sip/communicator/plugin/loggingutils/LoggingConfigForm.java b/src/net/java/sip/communicator/plugin/loggingutils/LoggingConfigForm.java index 379e2e1..b9230f5 100644 --- a/src/net/java/sip/communicator/plugin/loggingutils/LoggingConfigForm.java +++ b/src/net/java/sip/communicator/plugin/loggingutils/LoggingConfigForm.java @@ -115,7 +115,7 @@ public class LoggingConfigForm LoggingUtilsActivator.getNotificationService() .registerDefaultNotificationForEvent( LOGFILES_ARCHIVED, - NotificationService.ACTION_POPUP_MESSAGE, + NotificationAction.ACTION_POPUP_MESSAGE, null, null); } diff --git a/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationConfigurationPanel.java b/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationConfigurationPanel.java index 30061c9..5909482 100644 --- a/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationConfigurationPanel.java +++ b/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationConfigurationPanel.java @@ -326,7 +326,7 @@ public class NotificationConfigurationPanel NotificationConfigurationActivator.getNotificationService() .registerNotificationForEvent( entry.getEvent(), - NotificationService.ACTION_COMMAND, + NotificationAction.ACTION_COMMAND, entry.getProgramFile(), "" ); @@ -338,7 +338,7 @@ public class NotificationConfigurationPanel NotificationConfigurationActivator.getNotificationService() .registerNotificationForEvent( entry.getEvent(), - NotificationService.ACTION_SOUND, + NotificationAction.ACTION_SOUND, entry.getSoundFile(), "" ); @@ -366,7 +366,7 @@ public class NotificationConfigurationPanel NotificationConfigurationActivator.getNotificationService() .registerNotificationForEvent( entry.getEvent(), - NotificationService.ACTION_COMMAND, + NotificationAction.ACTION_COMMAND, entry.getProgramFile(), "" ); @@ -378,7 +378,7 @@ public class NotificationConfigurationPanel NotificationConfigurationActivator.getNotificationService() .registerNotificationForEvent( entry.getEvent(), - NotificationService.ACTION_SOUND, + NotificationAction.ACTION_SOUND, entry.getSoundFile(), "" ); diff --git a/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationsTable.java b/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationsTable.java index 3565200..a6486eb 100644 --- a/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationsTable.java +++ b/src/net/java/sip/communicator/plugin/notificationconfiguration/NotificationsTable.java @@ -8,7 +8,6 @@ package net.java.sip.communicator.plugin.notificationconfiguration; import java.awt.*; import java.awt.event.*; -import java.util.*; import javax.swing.*; import javax.swing.event.*; @@ -132,30 +131,24 @@ public class NotificationsTable */ private void initTableData() { - Iterator<String> registeredEvents - = notificationService.getRegisteredEvents(); - - NotificationEntry entry; - while (registeredEvents.hasNext()) + for(String eventType : notificationService.getRegisteredEvents()) { - String eventType = registeredEvents.next(); - - PopupMessageNotificationHandler popupHandler - = (PopupMessageNotificationHandler) notificationService - .getEventNotificationActionHandler( - eventType, NotificationService.ACTION_POPUP_MESSAGE); - - CommandNotificationHandler programHandler - = (CommandNotificationHandler) notificationService - .getEventNotificationActionHandler( - eventType, NotificationService.ACTION_COMMAND); - - SoundNotificationHandler soundHandler - = (SoundNotificationHandler) notificationService - .getEventNotificationActionHandler( - eventType, NotificationService.ACTION_SOUND); - - entry = new NotificationEntry( + PopupMessageNotificationAction popupHandler + = (PopupMessageNotificationAction) notificationService + .getEventNotificationAction( + eventType, NotificationAction.ACTION_POPUP_MESSAGE); + + CommandNotificationAction programHandler + = (CommandNotificationAction) notificationService + .getEventNotificationAction( + eventType, NotificationAction.ACTION_COMMAND); + + SoundNotificationAction soundHandler + = (SoundNotificationAction) notificationService + .getEventNotificationAction( + eventType, NotificationAction.ACTION_SOUND); + + NotificationEntry entry = new NotificationEntry( notificationService.isActive(eventType), programHandler != null && programHandler.isEnabled(), (programHandler != null) ? programHandler.getDescriptor() : null, @@ -460,7 +453,7 @@ public class NotificationsTable { notificationService.registerNotificationForEvent( entry.getEvent(), - NotificationService.ACTION_COMMAND, + NotificationAction.ACTION_COMMAND, entry.getProgramFile(), ""); } @@ -468,7 +461,7 @@ public class NotificationsTable { notificationService.removeEventNotificationAction( entry.getEvent(), - NotificationService.ACTION_COMMAND); + NotificationAction.ACTION_COMMAND); } break; case 2: @@ -479,7 +472,7 @@ public class NotificationsTable { notificationService.registerNotificationForEvent( entry.getEvent(), - NotificationService.ACTION_POPUP_MESSAGE, + NotificationAction.ACTION_POPUP_MESSAGE, "", ""); } @@ -487,7 +480,7 @@ public class NotificationsTable { notificationService.removeEventNotificationAction( entry.getEvent(), - NotificationService.ACTION_POPUP_MESSAGE); + NotificationAction.ACTION_POPUP_MESSAGE); } break; case 3: @@ -498,7 +491,7 @@ public class NotificationsTable { notificationService.registerNotificationForEvent( entry.getEvent(), - NotificationService.ACTION_SOUND, + NotificationAction.ACTION_SOUND, entry.getSoundFile(), ""); } @@ -506,7 +499,7 @@ public class NotificationsTable { notificationService.removeEventNotificationAction( entry.getEvent(), - NotificationService.ACTION_SOUND); + NotificationAction.ACTION_SOUND); } break; }; @@ -524,7 +517,7 @@ public class NotificationsTable String eventName = event.getSourceEventType(); NotificationEntry entry = getNotificationEntry(eventName); - NotificationActionHandler handler = event.getActionHandler(); + NotificationAction handler = event.getActionHandler(); boolean isActionEnabled = (handler != null && handler.isEnabled()); if(entry == null) @@ -535,25 +528,25 @@ public class NotificationsTable entry.setEvent(eventName); - if(event.getSourceActionType() - .equals(NotificationService.ACTION_POPUP_MESSAGE)) + if(event.getActionHandler().getActionType() + .equals(NotificationAction.ACTION_POPUP_MESSAGE)) { entry.setPopup(isActionEnabled); } - else if(event.getSourceActionType() - .equals(NotificationService.ACTION_COMMAND)) + else if(event.getActionHandler().getActionType() + .equals(NotificationAction.ACTION_COMMAND)) { entry.setProgram(isActionEnabled); - entry.setProgramFile(((CommandNotificationHandler)event + entry.setProgramFile(((CommandNotificationAction)event .getActionHandler()).getDescriptor()); } - else if(event.getSourceActionType() - .equals(NotificationService.ACTION_SOUND)) + else if(event.getActionHandler().getActionType() + .equals(NotificationAction.ACTION_SOUND)) { entry.setSound(isActionEnabled); - entry.setSoundFile(((SoundNotificationHandler)event + entry.setSoundFile(((SoundNotificationAction)event .getActionHandler()).getDescriptor()); } entry.setEnabled(notificationService.isActive(eventName)); @@ -574,19 +567,19 @@ public class NotificationsTable if(entry == null) return; - if(event.getSourceActionType() - .equals(NotificationService.ACTION_POPUP_MESSAGE)) + if(event.getActionHandler().getActionType() + .equals(NotificationAction.ACTION_POPUP_MESSAGE)) { entry.setPopup(false); } - else if(event.getSourceActionType() - .equals(NotificationService.ACTION_COMMAND)) + else if(event.getActionHandler().getActionType() + .equals(NotificationAction.ACTION_COMMAND)) { entry.setProgram(false); entry.setProgramFile(""); } - else if(event.getSourceActionType() - .equals(NotificationService.ACTION_SOUND)) + else if(event.getActionHandler().getActionType() + .equals(NotificationAction.ACTION_SOUND)) { entry.setSound(false); entry.setSoundFile(""); @@ -608,16 +601,16 @@ public class NotificationsTable if(entry == null) return; - if(event.getSourceActionType() - .equals(NotificationService.ACTION_COMMAND)) + if(event.getActionHandler().getActionType() + .equals(NotificationAction.ACTION_COMMAND)) { - entry.setProgramFile(((CommandNotificationHandler)event + entry.setProgramFile(((CommandNotificationAction)event .getActionHandler()).getDescriptor()); } - else if(event.getSourceActionType() - .equals(NotificationService.ACTION_SOUND)) + else if(event.getActionHandler().getActionType() + .equals(NotificationAction.ACTION_SOUND)) { - entry.setSoundFile(((SoundNotificationHandler)event + entry.setSoundFile(((SoundNotificationAction)event .getActionHandler()).getDescriptor()); } @@ -638,20 +631,20 @@ public class NotificationsTable if(entry == null) { - PopupMessageNotificationHandler popupHandler - = (PopupMessageNotificationHandler) notificationService - .getEventNotificationActionHandler( - eventName, NotificationService.ACTION_POPUP_MESSAGE); - - CommandNotificationHandler programHandler - = (CommandNotificationHandler) notificationService - .getEventNotificationActionHandler( - eventName, NotificationService.ACTION_COMMAND); - - SoundNotificationHandler soundHandler - = (SoundNotificationHandler) notificationService - .getEventNotificationActionHandler( - eventName, NotificationService.ACTION_SOUND); + PopupMessageNotificationAction popupHandler + = (PopupMessageNotificationAction) notificationService + .getEventNotificationAction( + eventName, NotificationAction.ACTION_POPUP_MESSAGE); + + CommandNotificationAction programHandler + = (CommandNotificationAction) notificationService + .getEventNotificationAction( + eventName, NotificationAction.ACTION_COMMAND); + + SoundNotificationAction soundHandler + = (SoundNotificationAction) notificationService + .getEventNotificationAction( + eventName, NotificationAction.ACTION_SOUND); entry = new NotificationEntry( notificationService.isActive(event.getSourceEventType()), diff --git a/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java b/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java index 60499c1..69ae129 100644 --- a/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java +++ b/src/net/java/sip/communicator/plugin/reconnectplugin/ReconnectPluginActivator.java @@ -299,7 +299,7 @@ public class ReconnectPluginActivator notificationService.registerDefaultNotificationForEvent( NETWORK_NOTIFICATIONS, - NotificationService.ACTION_POPUP_MESSAGE, + NotificationAction.ACTION_POPUP_MESSAGE, null, null); } diff --git a/src/net/java/sip/communicator/service/notification/CommandNotificationAction.java b/src/net/java/sip/communicator/service/notification/CommandNotificationAction.java new file mode 100644 index 0000000..47cb340 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/CommandNotificationAction.java @@ -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;
+ }
+}
diff --git a/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java b/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java index 51ef823..c528ed6 100644 --- a/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java +++ b/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java @@ -13,17 +13,11 @@ package net.java.sip.communicator.service.notification; * @author Yana Stamcheva */ 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(); - - /** - * Returns the descriptor pointing to the command to be executed. - * - * @return the descriptor pointing to the command to be executed. - */ - public String getDescriptor(); + public void execute(CommandNotificationAction action); } diff --git a/src/net/java/sip/communicator/service/notification/LogMessageNotificationAction.java b/src/net/java/sip/communicator/service/notification/LogMessageNotificationAction.java new file mode 100644 index 0000000..6efdb31 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/LogMessageNotificationAction.java @@ -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;
+ }
+}
diff --git a/src/net/java/sip/communicator/service/notification/LogMessageNotificationHandler.java b/src/net/java/sip/communicator/service/notification/LogMessageNotificationHandler.java index f4d7757..922c0f1 100644 --- a/src/net/java/sip/communicator/service/notification/LogMessageNotificationHandler.java +++ b/src/net/java/sip/communicator/service/notification/LogMessageNotificationHandler.java @@ -14,37 +14,13 @@ package net.java.sip.communicator.service.notification; * @author Yana Stamcheva */ 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. + * + * @param action the action to act upon * @param message the message to log */ - public void logMessage(String message); + public void logMessage(LogMessageNotificationAction action, String message); } diff --git a/src/net/java/sip/communicator/impl/notification/EventNotification.java b/src/net/java/sip/communicator/service/notification/Notification.java index a31a39d..81072e8 100644 --- a/src/net/java/sip/communicator/impl/notification/EventNotification.java +++ b/src/net/java/sip/communicator/service/notification/Notification.java @@ -4,18 +4,16 @@ * Distributable under LGPL license. * 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 net.java.sip.communicator.service.notification.*; - /** * Represents an event notification. * * @author Yana Stamcheva */ -public class EventNotification +public class Notification { /** * 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 * is fired. */ - private final Hashtable<String, Action> actionsTable - = new Hashtable<String, Action>(); + private final Hashtable<String, NotificationAction> actionsTable + = new Hashtable<String, NotificationAction>(); /** * Creates an instance of <tt>EventNotification</tt> by specifying the @@ -36,26 +34,22 @@ public class EventNotification * * @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 * notifications. - * - * @param actionType one of NotificationService.ACTION_XXX constants - * @param actionHandler the the handler that will process the given action + * @param action the the handler that will process the given action * type. + * * @return the previous value of the actionHandler for the given actionType, * if one existed, NULL if the actionType is a new one */ - public Object addAction(String actionType, - NotificationActionHandler actionHandler) + public Object addAction(NotificationAction action) { - Action action = new Action(actionType, actionHandler); - - return actionsTable.put(actionType, action); + return actionsTable.put(action.getActionType(), action); } /** @@ -73,7 +67,7 @@ public class EventNotification * * @return the set of actions registered for this event notification */ - public Map<String, Action> getActions() + public Map<String, NotificationAction> getActions() { return actionsTable; } @@ -87,58 +81,12 @@ public class EventNotification * @return the <tt>Action</tt> corresponding to the given * <tt>actionType</tt> */ - public Action getAction(String actionType) + public NotificationAction getAction(String 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. * * @return true if this event notification is active, false otherwise. diff --git a/src/net/java/sip/communicator/service/notification/NotificationAction.java b/src/net/java/sip/communicator/service/notification/NotificationAction.java new file mode 100644 index 0000000..50106a5 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/NotificationAction.java @@ -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;
+ }
+}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/service/notification/NotificationActionHandler.java b/src/net/java/sip/communicator/service/notification/NotificationActionHandler.java deleted file mode 100644 index 3adcd87..0000000 --- a/src/net/java/sip/communicator/service/notification/NotificationActionHandler.java +++ /dev/null @@ -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); -} diff --git a/src/net/java/sip/communicator/service/notification/NotificationHandler.java b/src/net/java/sip/communicator/service/notification/NotificationHandler.java new file mode 100644 index 0000000..b130c4e --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/NotificationHandler.java @@ -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(); +} diff --git a/src/net/java/sip/communicator/service/notification/NotificationService.java b/src/net/java/sip/communicator/service/notification/NotificationService.java index cb0e2a5..37bc71e 100644 --- a/src/net/java/sip/communicator/service/notification/NotificationService.java +++ b/src/net/java/sip/communicator/service/notification/NotificationService.java @@ -6,8 +6,6 @@ */ package net.java.sip.communicator.service.notification; -import java.util.*; - /** * This service is previewed for use by bundles that implement some kind of * user notification (e.g. playing sounds, poping systray tooltips, or @@ -23,237 +21,78 @@ import java.util.*; 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 - * the type of the action to be performed when a notification is fired for - * this event and the corresponding <tt>handler</tt> that should be used to - * handle the action. Unlike the other <tt>registerNotificationForEvent</tt> + * the action to be performed when a notification is fired for this event. + * + * Unlike the other <tt>registerNotificationForEvent</tt> * 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>. * * @param eventType the name of the event (as defined by the plug-in that's * 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 action the <tt>NotificationAction</tt>, which would be * 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, - String actionType, - NotificationActionHandler handler) - throws IllegalArgumentException; - + public void registerNotificationForEvent(String eventType, + NotificationAction action); + /** - * Registers a Default notification for the given <tt>eventType</tt> by specifying - * the type of the action to be performed when a notification is fired for - * this event and the corresponding <tt>handler</tt> that should be used to - * handle the action. Unlike the other - * <tt>registerDefaultNotificationForEvent</tt> - * method, this one allows the user to specify its own - * <tt>NotificationHandler</tt>, 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 - * missing in the configuration. Also the registered default events - * are used when restoreDefaults is called. + * Registers a default notification for the given <tt>eventType</tt> by + * specifying the action to be performed when a notification is fired for + * this event. + * + * Unlike the other <tt>registerDefaultNotificationForEvent</tt> method, + * this one allows the user to specify its own <tt>NotificationAction</tt>, + * which would be used to handle notifications. + * + * 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. * * @param eventType the name of the event (as defined by the plug-in that's - * 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). + * registering it) that we are setting an action for. * @param handler the <tt>NotificationActionHandler</tt>, which would be - * used to perform the notification action. - * @throws IllegalArgumentException if the specified <tt>handler</tt> do not - * correspond to the given <tt>actionType</tt>. + * used to perform the notification action. */ - public void registerDefaultNotificationForEvent( String eventType, - String actionType, - NotificationActionHandler handler) - throws IllegalArgumentException; - + public void registerDefaultNotificationForEvent(String eventType, + NotificationAction handler); + /** - * Registers a default notification for the given <tt>eventType</tt> by specifying - * the type of the action to be performed when a notification is fired for - * this event, the <tt>actionDescriptor</tt> for sound and command actions - * and the <tt>defaultMessage</tt> for popup and log actions. Actions - * registered by this method would be handled by some default + * Registers a default notification for the given <tt>eventType</tt> by + * specifying the type of the action to be performed when a notification is + * fired for this event, the <tt>actionDescriptor</tt> for sound and command + * actions and the <tt>defaultMessage</tt> for popup and log actions. + * + * Actions registered by this method would be handled by some default * <tt>NotificationHandler</tt>s, declared by the implementation. * <p> * The method allows registering more than one actionType for a specific - * event. Setting twice the same <tt>actionType</tt> for the same - * <tt>eventType</tt> however would cause the first setting to be + * event. Setting the same <tt>actionType</tt> for the same + * <tt>eventType</tt> twice however would cause the first setting to be * 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. - * + * * @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). + * specified event occurs (could be one of the ACTION_XXX + * fields). * @param actionDescriptor a String containing a description of the action - * (a URI to the sound file for audio notifications or a command line for - * exec action types) that should be executed when the action occurs. + * (a URI to the sound file for audio notifications or a command + * line for exec action types) that should be executed when the + * action occurs. * @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, - String actionType, - String actionDescriptor, - String defaultMessage); - + public void registerDefaultNotificationForEvent(String eventType, + String actionType, + String actionDescriptor, + String defaultMessage); + /** * 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 @@ -263,44 +102,46 @@ public interface NotificationService * <tt>NotificationHandler</tt>s, declared by the implementation. * <p> * The method allows registering more than one actionType for a specific - * event. Setting twice the same <tt>actionType</tt> for the same - * <tt>eventType</tt> however would cause the first setting to be + * event. Setting the same <tt>actionType</tt> for the same + * <tt>eventType</tt> twice however would cause the first setting to be * overridden. - * + * * @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). + * specified event occurs (could be one of the ACTION_XXX + * fields). * @param actionDescriptor a String containing a description of the action - * (a URI to the sound file for audio notifications or a command line for - * exec action types) that should be executed when the action occurs. + * (a URI to the sound file for audio notifications or a command + * line for exec action types) that should be executed when the + * action occurs. * @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, String actionType, String actionDescriptor, String defaultMessage); - + /** * Deletes all registered events and actions * and registers and saves the default events as current. */ public void restoreDefaults(); - + /** - * Removes the given <tt>eventType</tt> from the list of event notifications. - * This means that we delete here all registered notifications for the given - * <tt>eventType</tt>. + * Removes the given <tt>eventType</tt> from the list of event + * notifications. This means that we delete here all registered + * notifications for the given <tt>eventType</tt>. * <p> * This method does nothing if the given <tt>eventType</tt> is not contained * in the list of registered event types. - * + * * @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); - + /** * Removes the event notification corresponding to the specified * <tt>actionType</tt> and <tt>eventType</tt>. @@ -309,57 +150,40 @@ public interface NotificationService * <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 - * 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 - * 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, String actionType); /** * Returns an iterator over a list of all events registered in this - * notification service. Each line in the returned list consists of - * a String, representing the name of the event (as defined by the plugin - * that 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. + * notification service. Each line in the returned list consists of a + * String, representing the name of the event (as defined by the plugin that + * registered it). * - * @param eventType the name of the event that we'd like to retrieve actions - * for. - * @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>. + * @return an iterator over a list of all events registered in this + * notifications service */ - public Map<String, NotificationActionHandler> getEventNotifications( - String eventType); + public Iterable<String> getRegisteredEvents(); /** - * Returns the <tt>NotificationActionHandler</tt> corresponding to the given - * event and action types. + * Returns the <tt>NotificationAction</tt> corresponding to the given event + * and action type. * <p> * 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. - * + * * @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 - * descriptor for. - * @return the <tt>NotificationActionHandler</tt> corresponding to the given - * event and action types + * descriptor for. + * @return the <tt>NotificationAction</tt> corresponding to the given event + * and action type */ - public NotificationActionHandler getEventNotificationActionHandler( - String eventType, - String actionType); + public NotificationAction getEventNotificationAction(String eventType, + String actionType); /** * Registers a listener that would be notified of changes that have occurred @@ -382,6 +206,26 @@ public interface NotificationService 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> * using <tt>message</tt> as a notification message wherever appropriate * (e.g. systray notifications, logs, etc.) diff --git a/src/net/java/sip/communicator/service/notification/NotificationServiceActivator.java b/src/net/java/sip/communicator/service/notification/NotificationServiceActivator.java new file mode 100644 index 0000000..6599a16 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/NotificationServiceActivator.java @@ -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; + } +} diff --git a/src/net/java/sip/communicator/impl/notification/NotificationServiceImpl.java b/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java index f0eb3be..1b7e382 100644 --- a/src/net/java/sip/communicator/impl/notification/NotificationServiceImpl.java +++ b/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java @@ -4,161 +4,115 @@ * Distributable under LGPL license. * 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 net.java.sip.communicator.impl.notification.EventNotification.*; import net.java.sip.communicator.service.configuration.*; -import net.java.sip.communicator.service.notification.*; import net.java.sip.communicator.service.notification.event.*; -import net.java.sip.communicator.service.systray.*; import net.java.sip.communicator.util.*; +import static net.java.sip.communicator.service.notification.NotificationAction.*; +import static net.java.sip.communicator.service.notification.event.NotificationActionTypeEvent.*; +import static net.java.sip.communicator.service.notification.event.NotificationEventTypeEvent.*; /** * The implementation of the <tt>NotificationService</tt>. * * @author Yana Stamcheva */ -public class NotificationServiceImpl +class NotificationServiceImpl implements NotificationService { - private final Logger logger = - Logger.getLogger(NotificationServiceImpl.class); + private final Logger logger + = Logger.getLogger(NotificationServiceImpl.class); - private static final String NOTIFICATIONS_PREFIX = - "net.java.sip.communicator.impl.notifications"; + private final ConfigurationService configService = + NotificationServiceActivator.getConfigurationService(); + + private static final String NOTIFICATIONS_PREFIX + = "net.java.sip.communicator.impl.notifications"; /** * A set of all registered event notifications. */ - private final Hashtable<String, EventNotification> notificationsTable = - new Hashtable<String, EventNotification>(); + private final Map<String, Notification> notifications + = new HashMap<String, Notification>(); /** * A set of all registered event notifications. */ - private final Map<String, EventNotification> defaultNotificationsTable = - new Hashtable<String, EventNotification>(); + private final Map<String, Notification> defaultNotifications + = new HashMap<String, Notification>(); + + /** + * Contains the notification handler per action type. + */ + private final Map<String, NotificationHandler> handlers + = new HashMap<String, NotificationHandler>(); /** * A list of all registered <tt>NotificationChangeListener</tt>s. */ - private final List<NotificationChangeListener> changeListeners = - new Vector<NotificationChangeListener>(); - - private final ConfigurationService configService = - NotificationActivator.getConfigurationService(); + private final List<NotificationChangeListener> changeListeners + = new Vector<NotificationChangeListener>(); /** * Creates an instance of <tt>NotificationServiceImpl</tt> by loading all * previously saved notifications. */ - public NotificationServiceImpl() + NotificationServiceImpl() { // Load all previously saved notifications. this.loadNotifications(); } - - /** - * Returns an instance of <tt>CommandNotificationHandlerImpl</tt>. - * - * @return an instance of <tt>CommandNotificationHandlerImpl</tt>. - */ - public CommandNotificationHandler createCommandNotificationHandler( - String commandDescriptor) - { - return new CommandNotificationHandlerImpl(commandDescriptor); - } - - /** - * Returns an instance of <tt>LogMessageNotificationHandlerImpl</tt>. - * - * @return an instance of <tt>LogMessageNotificationHandlerImpl</tt>. - */ - public LogMessageNotificationHandler createLogMessageNotificationHandler( - String logType) - { - return new LogMessageNotificationHandlerImpl(logType); - } /** - * Returns an instance of <tt>PopupMessageNotificationHandlerImpl</tt>. - * - * @return an instance of <tt>PopupMessageNotificationHandlerImpl</tt>. - */ - public PopupMessageNotificationHandler createPopupMessageNotificationHandler( - String defaultMessage) - { - return new PopupMessageNotificationHandlerImpl(defaultMessage); - } - - /** - * Returns an instance of <tt>SoundNotificationHandlerImpl</tt>. - * - * @return an instance of <tt>SoundNotificationHandlerImpl</tt>. - */ - public SoundNotificationHandler createSoundNotificationHandler( - String soundFileDescriptor, int loopInterval) - { - return new SoundNotificationHandlerImpl( - soundFileDescriptor, loopInterval); - } - - /** * Creates a new <tt>EventNotification</tt> or obtains the corresponding * existing one and registers a new action in it. * * @param eventType the name of the event (as defined by the plugin that's * 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> responsible for + * @param action the <tt>NotificationAction</tt> responsible for * handling the given <tt>actionType</tt> */ public void registerNotificationForEvent( String eventType, - String actionType, - NotificationActionHandler handler) + NotificationAction action) { - EventNotification notification = null; + Notification notification = null; - if(notificationsTable.containsKey(eventType)) - notification = notificationsTable.get(eventType); + if(notifications.containsKey(eventType)) + notification = notifications.get(eventType); else { - notification = new EventNotification(eventType); - - notificationsTable.put(eventType, notification); - + notification = new Notification(eventType); + notifications.put(eventType, notification); + this.fireNotificationEventTypeEvent( - NotificationEventTypeEvent.EVENT_TYPE_ADDED, eventType); + EVENT_TYPE_ADDED, eventType); } - Object existingAction = notification.addAction(actionType, handler); + Object existingAction = notification.addAction(action); // We fire the appropriate event depending on whether this is an // already existing actionType or a new one. if (existingAction != null) { fireNotificationActionTypeEvent( - NotificationActionTypeEvent.ACTION_CHANGED, + ACTION_CHANGED, eventType, - actionType, - handler); + action); } else { fireNotificationActionTypeEvent( - NotificationActionTypeEvent.ACTION_ADDED, + ACTION_ADDED, eventType, - actionType, - handler); + action); } // Save the notification through the ConfigurationService. this.saveNotification( eventType, - actionType, - handler, + action, true, false); } @@ -185,27 +139,27 @@ public class NotificationServiceImpl if (logger.isDebugEnabled()) logger.debug("Registering event " + eventType + "/" + actionType + "/" + actionDescriptor + "/" + defaultMessage); - - if (actionType.equals(NotificationService.ACTION_SOUND)) + + if (actionType.equals(ACTION_SOUND)) { - registerNotificationForEvent (eventType, actionType, - new SoundNotificationHandlerImpl(actionDescriptor, -1)); + registerNotificationForEvent (eventType, + new SoundNotificationAction(actionDescriptor, -1)); } - else if (actionType.equals(NotificationService.ACTION_LOG_MESSAGE)) + else if (actionType.equals(ACTION_LOG_MESSAGE)) { - registerNotificationForEvent (eventType, actionType, - new LogMessageNotificationHandlerImpl( - LogMessageNotificationHandler.INFO_LOG_TYPE)); + registerNotificationForEvent (eventType, + new LogMessageNotificationAction( + LogMessageNotificationAction.INFO_LOG_TYPE)); } - else if (actionType.equals(NotificationService.ACTION_POPUP_MESSAGE)) + else if (actionType.equals(ACTION_POPUP_MESSAGE)) { - registerNotificationForEvent (eventType, actionType, - new PopupMessageNotificationHandlerImpl(defaultMessage)); + registerNotificationForEvent (eventType, + new PopupMessageNotificationAction(defaultMessage)); } - else if (actionType.equals(NotificationService.ACTION_COMMAND)) + else if (actionType.equals(ACTION_COMMAND)) { - registerNotificationForEvent (eventType, actionType, - new CommandNotificationHandlerImpl(actionDescriptor)); + registerNotificationForEvent (eventType, + new CommandNotificationAction(actionDescriptor)); } } @@ -218,10 +172,10 @@ public class NotificationServiceImpl */ public void removeEventNotification(String eventType) { - notificationsTable.remove(eventType); + notifications.remove(eventType); this.fireNotificationEventTypeEvent( - NotificationEventTypeEvent.EVENT_TYPE_REMOVED, eventType); + EVENT_TYPE_REMOVED, eventType); } /** @@ -236,31 +190,29 @@ public class NotificationServiceImpl public void removeEventNotificationAction( String eventType, String actionType) { - EventNotification notification - = notificationsTable.get(eventType); + Notification notification + = notifications.get(eventType); if(notification == null) return; - Action action = notification.getAction(actionType); + NotificationAction action = notification.getAction(actionType); if(action == null) return; notification.removeAction(actionType); - + saveNotification( eventType, - actionType, - action.getActionHandler(), + action, false, false); - + fireNotificationActionTypeEvent( - NotificationActionTypeEvent.ACTION_REMOVED, + ACTION_REMOVED, eventType, - action.getActionType(), - action.getActionHandler()); + action); } /** @@ -272,70 +224,32 @@ public class NotificationServiceImpl * @return an iterator over a list of all events registered in this * notifications service */ - public Iterator<String> getRegisteredEvents() + public Iterable<String> getRegisteredEvents() { return Collections.unmodifiableSet( - notificationsTable.keySet()).iterator(); - } - - /** - * Goes through all actions registered for the given <tt>eventType</tt> and - * returns a Map of all (actionType, actionDescriptor) key-value pairs. - * - * @param eventType the name of the event that we'd like to retrieve actions - * for - * @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(String eventType) - { - EventNotification notification = notificationsTable.get(eventType); - - if(notification == null) - return null; - - Hashtable<String, NotificationActionHandler> actions - = new Hashtable<String, NotificationActionHandler>(); - - for (Object value : notification.getActions().values()) - { - Action action = (Action) value; - NotificationActionHandler handler = action.getActionHandler(); - - actions.put(action.getActionType(), handler); - } - - return actions; + notifications.keySet()); } /** - * Returns the notification handler corresponding to the given + * Returns the notification action corresponding to the given * <tt>eventType</tt> and <tt>actionType</tt>. * * @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 * descriptor for. - * @return the notification handler of the action to be executed + * @return the notification action of the action to be executed * when an event of the specified type has occurred. */ - public NotificationActionHandler getEventNotificationActionHandler( + public NotificationAction getEventNotificationAction( String eventType, String actionType) { - EventNotification notification - = notificationsTable.get(eventType); + Notification notification = notifications.get(eventType); if(notification == null) return null; - EventNotification.Action action = notification.getAction(actionType); - - if(action == null) - return null; - - return action.getActionHandler(); + return notification.getAction(actionType); } /** @@ -368,17 +282,62 @@ public class NotificationServiceImpl } /** + * Adds an object that executes the actual action of a notification action. + * If the same action type is added twice, the last added wins. + * + * @param handler The handler that executes the action. + */ + public void addActionHandler(NotificationHandler handler) + { + if(handler == null) + throw new IllegalArgumentException("handler cannot be null"); + + synchronized(handlers) + { + handlers.put(handler.getActionType(), handler); + } + } + + /** + * Removes an object that executes the actual action of notification action. + * @param actionType The handler type to remove. + */ + public void removeActionHandler(String actionType) + { + if(actionType == null) + throw new IllegalArgumentException("actionType cannot be null"); + + synchronized(handlers) + { + handlers.remove(actionType); + } + } + + /** + * Gets a 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) + { + if (actionType != null) + return Collections.singleton(handlers.get(actionType)); + else + return handlers.values(); + } + + /** * If there is a registered event notification of the given - * <tt>eventType</tt> and the event notification is currently activated, we - * go through the list of registered actions and execute them. + * <tt>eventType</tt> and the event notification is currently activated, the + * list of registered actions is executed. * * @param eventType the type of the event that we'd like to fire a - * notification for. + * notification for. * @param title the title of the given message * @param message the message to use if and where appropriate (e.g. with - * systray or log notification.) - * @param icon the icon to show in the notification if and where - * appropriate + * 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 fireNotification( @@ -388,44 +347,38 @@ public class NotificationServiceImpl byte[] icon, Object tag) { - EventNotification notification - = notificationsTable.get(eventType); - + Notification notification = notifications.get(eventType); if(notification == null || !notification.isActive()) return; - Iterator<Action> actions = notification.getActions().values().iterator(); - - while(actions.hasNext()) + for(NotificationAction action : notification.getActions().values()) { - Action action = actions.next(); - String actionType = action.getActionType(); - - NotificationActionHandler handler = action.getActionHandler(); - - if ((handler == null) || !handler.isEnabled()) + if(!action.isEnabled() || !handlers.containsKey(actionType)) continue; - if (actionType.equals(NotificationService.ACTION_POPUP_MESSAGE)) + NotificationHandler handler = handlers.get(actionType); + if (actionType.equals(ACTION_POPUP_MESSAGE)) { ((PopupMessageNotificationHandler) handler) - .popupMessage(new PopupMessage(title, message, icon, tag)); + .popupMessage((PopupMessageNotificationAction) action, + title, message, icon, tag); } - else if (actionType.equals(NotificationService.ACTION_LOG_MESSAGE)) + else if (actionType.equals(ACTION_LOG_MESSAGE)) { ((LogMessageNotificationHandler) handler) - .logMessage(message); + .logMessage((LogMessageNotificationAction) action, + message); } - else if (actionType.equals(NotificationService.ACTION_SOUND)) + else if (actionType.equals(ACTION_SOUND)) { ((SoundNotificationHandler) handler) - .start(); + .start((SoundNotificationAction) action); } - else if (actionType.equals(NotificationService.ACTION_COMMAND)) + else if (actionType.equals(ACTION_COMMAND)) { ((CommandNotificationHandler) handler) - .execute(); + .execute((CommandNotificationAction) action); } } } @@ -449,12 +402,10 @@ public class NotificationServiceImpl * * @param eventType the name of the event * @param actionType the type of action - * @param actionHandler the notification action handler responsible for - * handling the given <tt>actionType</tt> + * @param action the notification action to change */ private void saveNotification( String eventType, - String actionType, - NotificationActionHandler actionHandler, + NotificationAction action, boolean isActive, boolean isDefault) { @@ -466,9 +417,7 @@ public class NotificationServiceImpl for (String eventTypeRootPropName : eventTypes) { - String eType - = configService.getString(eventTypeRootPropName); - + String eType = configService.getString(eventTypeRootPropName); if(eType.equals(eventType)) eventTypeNodeName = eventTypeRootPropName; } @@ -485,7 +434,7 @@ public class NotificationServiceImpl } // if we set active/inactive for the whole event notification - if(actionType == null && actionHandler == null) + if(action == null) { configService.setProperty( eventTypeNodeName + ".active", @@ -501,10 +450,8 @@ public class NotificationServiceImpl for (String actionTypeRootPropName : actionTypes) { - String aType - = configService.getString(actionTypeRootPropName); - - if(aType.equals(actionType)) + String aType = configService.getString(actionTypeRootPropName); + if(aType.equals(action.getActionType())) actionTypeNodeName = actionTypeRootPropName; } @@ -518,84 +465,59 @@ public class NotificationServiceImpl + ".actionType" + Long.toString(System.currentTimeMillis()); - configProperties.put(actionTypeNodeName, actionType); + configProperties.put(actionTypeNodeName, action.getActionType()); } - if(actionHandler instanceof SoundNotificationHandler) + if(action instanceof SoundNotificationAction) { - SoundNotificationHandler soundHandler - = (SoundNotificationHandler) actionHandler; + SoundNotificationAction soundAction + = (SoundNotificationAction) action; configProperties.put( actionTypeNodeName + ".soundFileDescriptor", - soundHandler.getDescriptor()); + soundAction.getDescriptor()); configProperties.put( actionTypeNodeName + ".loopInterval", - soundHandler.getLoopInterval()); - - configProperties.put( - actionTypeNodeName + ".enabled", - Boolean.toString(isActive)); - - configProperties.put( - actionTypeNodeName + ".default", - Boolean.toString(isDefault)); + soundAction.getLoopInterval()); } - else if(actionHandler instanceof PopupMessageNotificationHandler) + else if(action instanceof PopupMessageNotificationAction) { - PopupMessageNotificationHandler messageHandler - = (PopupMessageNotificationHandler) actionHandler; + PopupMessageNotificationAction messageAction + = (PopupMessageNotificationAction) action; configProperties.put( actionTypeNodeName + ".defaultMessage", - messageHandler.getDefaultMessage()); - - configProperties.put( - actionTypeNodeName + ".enabled", - Boolean.toString(isActive)); - - configProperties.put( - actionTypeNodeName + ".default", - Boolean.toString(isDefault)); + messageAction.getDefaultMessage()); } - else if(actionHandler instanceof LogMessageNotificationHandler) + else if(action instanceof LogMessageNotificationAction) { - LogMessageNotificationHandler logMessageHandler - = (LogMessageNotificationHandler) actionHandler; + LogMessageNotificationAction logMessageAction + = (LogMessageNotificationAction) action; configProperties.put( actionTypeNodeName + ".logType", - logMessageHandler.getLogType()); - - configProperties.put( - actionTypeNodeName + ".enabled", - Boolean.toString(isActive)); - - configProperties.put( - actionTypeNodeName + ".default", - Boolean.toString(isDefault)); + logMessageAction.getLogType()); } - else if(actionHandler instanceof CommandNotificationHandler) + else if(action instanceof CommandNotificationAction) { - CommandNotificationHandler commandHandler - = (CommandNotificationHandler) actionHandler; + CommandNotificationAction commandAction + = (CommandNotificationAction) action; configProperties.put( actionTypeNodeName + ".commandDescriptor", - commandHandler.getDescriptor()); + commandAction.getDescriptor()); + } - configProperties.put( - actionTypeNodeName + ".enabled", - Boolean.toString(isActive)); + configProperties.put( + actionTypeNodeName + ".enabled", + Boolean.toString(isActive)); - configProperties.put( - actionTypeNodeName + ".default", - Boolean.toString(isDefault)); - } + configProperties.put( + actionTypeNodeName + ".default", + Boolean.toString(isDefault)); - if (configProperties.size() > 0) - configService.setProperties(configProperties); + configService.setProperties(configProperties); } /** @@ -620,10 +542,9 @@ public class NotificationServiceImpl for (String actionPropName : actions) { - String actionType - = configService.getString(actionPropName); + String actionType = configService.getString(actionPropName); - NotificationActionHandler handler = null; + NotificationAction action = null; if(actionType.equals(ACTION_SOUND)) { @@ -635,12 +556,9 @@ public class NotificationServiceImpl = configService.getString( actionPropName + ".loopInterval"); - handler = new SoundNotificationHandlerImpl( + action = new SoundNotificationAction( soundFileDescriptor, Integer.parseInt(loopInterval)); - - handler.setEnabled( - isEnabled(actionPropName + ".enabled")); } else if(actionType.equals(ACTION_POPUP_MESSAGE)) { @@ -648,10 +566,7 @@ public class NotificationServiceImpl = configService.getString( actionPropName + ".defaultMessage"); - handler = new PopupMessageNotificationHandlerImpl( - defaultMessage); - handler.setEnabled( - isEnabled(actionPropName + ".enabled")); + action = new PopupMessageNotificationAction(defaultMessage); } else if(actionType.equals(ACTION_LOG_MESSAGE)) { @@ -659,9 +574,7 @@ public class NotificationServiceImpl = configService.getString( actionPropName + ".logType"); - handler = new LogMessageNotificationHandlerImpl(logType); - - handler.setEnabled(isEnabled(actionPropName + ".enabled")); + action = new LogMessageNotificationAction(logType); } else if(actionType.equals(ACTION_COMMAND)) { @@ -669,23 +582,20 @@ public class NotificationServiceImpl = configService.getString( actionPropName + ".commandDescriptor"); - handler = new CommandNotificationHandlerImpl( - commandDescriptor); - handler.setEnabled(isEnabled(actionPropName + ".enabled")); + action = new CommandNotificationAction(commandDescriptor); } + action.setEnabled(isEnabled(actionPropName + ".enabled")); + // Load the data in the notifications table. - EventNotification notification - = notificationsTable.get(eventType); - + Notification notification = notifications.get(eventType); if(notification == null) { - notification = new EventNotification(eventType); - notificationsTable.put(eventType, notification); + notification = new Notification(eventType); + notifications.put(eventType, notification); } notification.setActive(isEventActive); - - notification.addAction(actionType, handler); + notification.addAction(action); } } } @@ -713,15 +623,14 @@ public class NotificationServiceImpl */ public void setActive(String eventType, boolean isActive) { - EventNotification eventNotification - = notificationsTable.get(eventType); - + Notification eventNotification + = notifications.get(eventType); + if(eventNotification == null) return; - + eventNotification.setActive(isActive); - - saveNotification(eventType, null, null, isActive, false); + saveNotification(eventType, null, isActive, false); } /** @@ -737,12 +646,12 @@ public class NotificationServiceImpl */ public boolean isActive(String eventType) { - EventNotification eventNotification - = notificationsTable.get(eventType); - + Notification eventNotification + = notifications.get(eventType); + if(eventNotification == null) return false; - + return eventNotification.isActive(); } @@ -768,18 +677,17 @@ public class NotificationServiceImpl for (NotificationChangeListener listener : changeListeners) { - if (eventType.equals(NotificationEventTypeEvent.EVENT_TYPE_ADDED)) + if (eventType.equals(EVENT_TYPE_ADDED)) { listener.eventTypeAdded(event); } - else if (eventType.equals( - NotificationEventTypeEvent.EVENT_TYPE_REMOVED)) + else if (eventType.equals(EVENT_TYPE_REMOVED)) { listener.eventTypeRemoved(event); } } } - + /** * Notifies all registered <tt>NotificationChangeListener</tt>s that a * <tt>NotificationActionTypeEvent</tt> has occurred. @@ -788,40 +696,31 @@ public class NotificationServiceImpl * constants declared in the <tt>NotificationActionTypeEvent</tt> class. * @param sourceEventType the <tt>eventType</tt>, which is the parent of the * action - * @param sourceActionType the <tt>actionType</tt>, for which the event is - * about - * @param actionHandler the notification action handler + * @param action the notification action */ private void fireNotificationActionTypeEvent( String eventType, String sourceEventType, - String sourceActionType, - NotificationActionHandler actionHandler) + NotificationAction action) { NotificationActionTypeEvent event = new NotificationActionTypeEvent( this, eventType, sourceEventType, - sourceActionType, - actionHandler); + action); - NotificationChangeListener listener; - for (int i = 0 ; i < changeListeners.size(); i ++) + for(NotificationChangeListener listener : changeListeners) { - listener = changeListeners.get(i); - - if (eventType.equals(NotificationActionTypeEvent.ACTION_ADDED)) + if (eventType.equals(ACTION_ADDED)) { listener.actionAdded(event); } - else if (eventType.equals( - NotificationActionTypeEvent.ACTION_REMOVED)) + else if (eventType.equals(ACTION_REMOVED)) { listener.actionRemoved(event); } - else if (eventType.equals( - NotificationActionTypeEvent.ACTION_CHANGED)) + else if (eventType.equals(ACTION_CHANGED)) { listener.actionChanged(event); } @@ -873,70 +772,65 @@ public class NotificationServiceImpl * * @param eventType the name of the event (as defined by the plugin that's * 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> responsible for - * handling the given <tt>actionType</tt> + * @param action the <tt>NotificationAction</tt> to register */ public void registerDefaultNotificationForEvent( String eventType, - String actionType, - NotificationActionHandler handler) - throws IllegalArgumentException + NotificationAction action) { - if(isDefault(eventType, actionType)) + if(isDefault(eventType, action.getActionType())) { - NotificationActionHandler h = - getEventNotificationActionHandler(eventType, actionType); - + NotificationAction h = + getEventNotificationAction(eventType, + action.getActionType()); + boolean isNew = false; - if(h == null) { isNew = true; - h = handler; + h = action; } - + this.saveNotification( eventType, - actionType, - handler, + action, h.isEnabled(), true); - EventNotification notification = null; + Notification notification = null; - if(notificationsTable.containsKey(eventType)) - notification = notificationsTable.get(eventType); + if(notifications.containsKey(eventType)) + notification = notifications.get(eventType); else { - notification = new EventNotification(eventType); - - notificationsTable.put(eventType, notification); + notification = new Notification(eventType); + notifications.put(eventType, notification); } - notification.addAction(actionType, handler); + notification.addAction(action); // We fire the appropriate event depending on whether this is an // already existing actionType or a new one. fireNotificationActionTypeEvent( - isNew ? NotificationActionTypeEvent.ACTION_ADDED - : NotificationActionTypeEvent.ACTION_CHANGED, eventType, - actionType, handler); + isNew + ? ACTION_ADDED + : ACTION_CHANGED, + eventType, + action); } // now store this default events if we want to restore them - EventNotification notification = null; + Notification notification = null; - if(defaultNotificationsTable.containsKey(eventType)) - notification = defaultNotificationsTable.get(eventType); + if(defaultNotifications.containsKey(eventType)) + notification = defaultNotifications.get(eventType); else { - notification = new EventNotification(eventType); + notification = new Notification(eventType); - defaultNotificationsTable.put(eventType, notification); + defaultNotifications.put(eventType, notification); } - notification.addAction(actionType, handler); + notification.addAction(action); } /** @@ -964,93 +858,91 @@ public class NotificationServiceImpl if(isDefault(eventType, actionType)) { - NotificationActionHandler handler = - getEventNotificationActionHandler(eventType, actionType); + NotificationAction action = + getEventNotificationAction(eventType, actionType); boolean isNew = false; - if(handler == null) + if(action == null) { isNew = true; - if (actionType.equals(NotificationService.ACTION_SOUND)) + if (actionType.equals(ACTION_SOUND)) { - handler = new SoundNotificationHandlerImpl(actionDescriptor, -1); + action = new SoundNotificationAction(actionDescriptor, -1); } - else if (actionType.equals(NotificationService.ACTION_LOG_MESSAGE)) + else if (actionType.equals(ACTION_LOG_MESSAGE)) { - handler = new LogMessageNotificationHandlerImpl( - LogMessageNotificationHandler.INFO_LOG_TYPE); + action = new LogMessageNotificationAction( + LogMessageNotificationAction.INFO_LOG_TYPE); } - else if (actionType.equals(NotificationService.ACTION_POPUP_MESSAGE)) + else if (actionType.equals(ACTION_POPUP_MESSAGE)) { - handler = new PopupMessageNotificationHandlerImpl(defaultMessage); + action = new PopupMessageNotificationAction(defaultMessage); } - else if (actionType.equals(NotificationService.ACTION_COMMAND)) + else if (actionType.equals(ACTION_COMMAND)) { - handler = new CommandNotificationHandlerImpl(actionDescriptor); + action = new CommandNotificationAction(actionDescriptor); } } this.saveNotification( eventType, - actionType, - handler, - handler.isEnabled(), + action, + action.isEnabled(), true); - EventNotification notification = null; + Notification notification = null; - if(notificationsTable.containsKey(eventType)) - notification = notificationsTable.get(eventType); + if(notifications.containsKey(eventType)) + notification = notifications.get(eventType); else { - notification = new EventNotification(eventType); - - notificationsTable.put(eventType, notification); + notification = new Notification(eventType); + notifications.put(eventType, notification); } - - notification.addAction(actionType, handler); - + + notification.addAction(action); + // We fire the appropriate event depending on whether this is an // already existing actionType or a new one. fireNotificationActionTypeEvent( - isNew ? NotificationActionTypeEvent.ACTION_ADDED - : NotificationActionTypeEvent.ACTION_CHANGED, eventType, - actionType, handler); + isNew + ? ACTION_ADDED + : ACTION_CHANGED, + eventType, + action); } - + // now store this default events if we want to restore them - EventNotification notification = null; + Notification notification = null; - if(defaultNotificationsTable.containsKey(eventType)) - notification = defaultNotificationsTable.get(eventType); + if(defaultNotifications.containsKey(eventType)) + notification = defaultNotifications.get(eventType); else { - notification = new EventNotification(eventType); - - defaultNotificationsTable.put(eventType, notification); + notification = new Notification(eventType); + defaultNotifications.put(eventType, notification); } - NotificationActionHandler handler = null; - - if (actionType.equals(NotificationService.ACTION_SOUND)) + NotificationAction action = null; + if (actionType.equals(ACTION_SOUND)) { - handler = new SoundNotificationHandlerImpl(actionDescriptor, -1); + action = new SoundNotificationAction(actionDescriptor, -1); } - else if (actionType.equals(NotificationService.ACTION_LOG_MESSAGE)) + else if (actionType.equals(ACTION_LOG_MESSAGE)) { - handler = new LogMessageNotificationHandlerImpl( - LogMessageNotificationHandler.INFO_LOG_TYPE); + action = new LogMessageNotificationAction( + LogMessageNotificationAction.INFO_LOG_TYPE); } - else if (actionType.equals(NotificationService.ACTION_POPUP_MESSAGE)) + else if (actionType.equals(ACTION_POPUP_MESSAGE)) { - handler = new PopupMessageNotificationHandlerImpl(defaultMessage); + action = new PopupMessageNotificationAction(defaultMessage); } - else if (actionType.equals(NotificationService.ACTION_COMMAND)) + else if (actionType.equals(ACTION_COMMAND)) { - handler = new CommandNotificationHandlerImpl(actionDescriptor); + action = new CommandNotificationAction(actionDescriptor); } - - notification.addAction(actionType, handler); + + notification.addAction(action); } /** @@ -1059,9 +951,9 @@ public class NotificationServiceImpl */ public void restoreDefaults() { - for (String eventType : new Vector<String>(notificationsTable.keySet())) + for (String eventType : new Vector<String>(notifications.keySet())) { - EventNotification notification = notificationsTable.get(eventType); + Notification notification = notifications.get(eventType); for (String actionType : new Vector<String>(notification.getActions().keySet())) @@ -1070,17 +962,14 @@ public class NotificationServiceImpl removeEventNotification(eventType); } - for (Map.Entry<String, EventNotification> entry - : defaultNotificationsTable.entrySet()) + for (Map.Entry<String, Notification> entry + : defaultNotifications.entrySet()) { String eventType = entry.getKey(); - EventNotification notification = entry.getValue(); + Notification notification = entry.getValue(); - for (String actionType : notification.getActions().keySet()) - registerNotificationForEvent( - eventType, - actionType, - notification.getAction(actionType).getActionHandler()); + for (NotificationAction action : notification.getActions().values()) + registerNotificationForEvent(eventType, action); } } } diff --git a/src/net/java/sip/communicator/service/notification/PopupMessageNotificationAction.java b/src/net/java/sip/communicator/service/notification/PopupMessageNotificationAction.java new file mode 100644 index 0000000..6f43ca2 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/PopupMessageNotificationAction.java @@ -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;
+ }
+}
diff --git a/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java b/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java index 6df0247..6327afc 100644 --- a/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java +++ b/src/net/java/sip/communicator/service/notification/PopupMessageNotificationHandler.java @@ -6,8 +6,6 @@ */ package net.java.sip.communicator.service.notification; -import net.java.sip.communicator.service.systray.*; - /** * The <tt>PopupMessageNotificationHandler</tt> interface is meant to be * implemented by the notification bundle in order to provide handling of @@ -16,21 +14,22 @@ import net.java.sip.communicator.service.systray.*; * @author Yana Stamcheva */ 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> * - * @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); } diff --git a/src/net/java/sip/communicator/service/notification/SoundNotificationAction.java b/src/net/java/sip/communicator/service/notification/SoundNotificationAction.java new file mode 100644 index 0000000..879c2f0 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/SoundNotificationAction.java @@ -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;
+ }
+}
diff --git a/src/net/java/sip/communicator/service/notification/SoundNotificationHandler.java b/src/net/java/sip/communicator/service/notification/SoundNotificationHandler.java index 3dc13e6..f98cb6f 100644 --- a/src/net/java/sip/communicator/service/notification/SoundNotificationHandler.java +++ b/src/net/java/sip/communicator/service/notification/SoundNotificationHandler.java @@ -14,30 +14,15 @@ package net.java.sip.communicator.service.notification; * @author Yana Stamcheva */ 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 * method should check the loopInterval value to distinguish whether to play * a simple sound or to play it in loop. + * @param action the action to act upon */ - public void start(); + public void start(SoundNotificationAction action); /** * Stops playing the sound pointing by <tt>getDescriptor</tt>. This method diff --git a/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java b/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java index 3bd7852..8773537 100644 --- a/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java +++ b/src/net/java/sip/communicator/service/notification/event/NotificationActionTypeEvent.java @@ -40,11 +40,6 @@ public class NotificationActionTypeEvent 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. */ private String sourceEventType = null; @@ -54,7 +49,7 @@ public class NotificationActionTypeEvent * string) that will be performed when notifications are being fired for * 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 @@ -69,35 +64,22 @@ public class NotificationActionTypeEvent * @param eventType the type of this event. One of the static fields * declared in this class * @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 * the given action */ public NotificationActionTypeEvent( NotificationService source, String eventType, String sourceEventType, - String sourceActionType, - NotificationActionHandler actionHandler) + NotificationAction actionHandler) { super(source); this.eventType = eventType; this.sourceEventType = sourceEventType; - this.sourceActionType = sourceActionType; 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. * * @return the event type, to which the given action belongs @@ -114,7 +96,7 @@ public class NotificationActionTypeEvent * @return the <tt>NotificationActionHandler</tt> that handles the action, * for which this event is about. */ - public NotificationActionHandler getActionHandler() + public NotificationAction getActionHandler() { return actionHandler; } diff --git a/src/net/java/sip/communicator/service/notification/notification.manifest.mf b/src/net/java/sip/communicator/service/notification/notification.manifest.mf new file mode 100644 index 0000000..33106a4 --- /dev/null +++ b/src/net/java/sip/communicator/service/notification/notification.manifest.mf @@ -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 diff --git a/test/net/java/sip/communicator/slick/popupmessagehandler/TestPopupMessageHandler.java b/test/net/java/sip/communicator/slick/popupmessagehandler/TestPopupMessageHandler.java index 31f7e49..b8c47a9 100644 --- a/test/net/java/sip/communicator/slick/popupmessagehandler/TestPopupMessageHandler.java +++ b/test/net/java/sip/communicator/slick/popupmessagehandler/TestPopupMessageHandler.java @@ -127,7 +127,7 @@ public class TestPopupMessageHandler = (NotificationService) bc.getService(serviceReference); notificationService.fireNotification( - NotificationService.ACTION_POPUP_MESSAGE, + NotificationAction.ACTION_POPUP_MESSAGE, messageStart, messageStart, null, |