diff options
author | Ingo Bauersachs <ingo@jitsi.org> | 2012-05-07 16:57:52 +0000 |
---|---|---|
committer | Ingo Bauersachs <ingo@jitsi.org> | 2012-05-07 16:57:52 +0000 |
commit | 1e33a5f4c04034bb25ef6749ebfcd118095e8731 (patch) | |
tree | 636ba6cc6029853ba81a992347f87a45e4646393 /src/net | |
parent | fe20f058ff735edf25031444e4ff58f374b4c58f (diff) | |
download | jitsi-1e33a5f4c04034bb25ef6749ebfcd118095e8731.zip jitsi-1e33a5f4c04034bb25ef6749ebfcd118095e8731.tar.gz jitsi-1e33a5f4c04034bb25ef6749ebfcd118095e8731.tar.bz2 |
JITSI-1035 #resolve fixed Allows caller information to be passed to the command action handler on the incoming call event.
Patch by Vieri Di Paola.
Diffstat (limited to 'src/net')
6 files changed, 154 insertions, 12 deletions
diff --git a/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java index 4ab6621..47ccb43 100644 --- a/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java +++ b/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java @@ -7,6 +7,7 @@ package net.java.sip.communicator.impl.notification; import java.io.*; +import java.util.*; import net.java.sip.communicator.service.notification.*; import net.java.sip.communicator.util.*; @@ -35,15 +36,32 @@ public class CommandNotificationHandlerImpl * action. * * @param action the action to act upon. + * @param cmdargs command-line arguments. */ - public void execute(CommandNotificationAction action) + public void execute(CommandNotificationAction action, + Map<String,String> cmdargs) { if(StringUtils.isNullOrEmpty(action.getDescriptor(), true)) return; + String actionDescriptor = action.getDescriptor(); + if (cmdargs != null) + { + for (Map.Entry<String, String> entry : cmdargs.entrySet()) + { + if(actionDescriptor.indexOf("${" + entry.getKey() + "}") != -1) + { + actionDescriptor = actionDescriptor.replace( + "${" + entry.getKey() + "}", + entry.getValue() + ); + } + } + } + try { - Runtime.getRuntime().exec(action.getDescriptor()); + Runtime.getRuntime().exec(actionDescriptor); } catch (IOException e) { diff --git a/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java b/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java index 837055e..b717013 100644 --- a/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java +++ b/src/net/java/sip/communicator/plugin/notificationwiring/NotificationManager.java @@ -574,6 +574,35 @@ public class NotificationManager } /** + * Fires a message notification for the given event type through the + * <tt>NotificationService</tt>. + * + * @param eventType the event type for which we fire a notification + * @param messageTitle the title of the message + * @param message the content of the message + * @param extra additional event data for external processing + * @return A reference to the fired notification to stop it. + */ + public static NotificationData fireNotification(String eventType, + String messageTitle, + String message, + Map<String,String> extra) + { + NotificationService notificationService + = NotificationWiringActivator.getNotificationService(); + + if(notificationService == null) + return null; + + return notificationService.fireNotification(eventType, + messageTitle, + message, + extra, + null, + null); + } + + /** * Fires a chat message notification for the given event type through the * <tt>NotificationService</tt>. * @@ -641,6 +670,7 @@ public class NotificationManager notificationService.fireNotification( eventType, messageTitle, message, + null, contactIcon, chatContact); @@ -969,7 +999,8 @@ public class NotificationManager /** * Implements CallListener.incomingCallReceived. When a call is received - * plays the ring phone sound to the user. + * plays the ring phone sound to the user and gathers caller information + * that may be used by a user-specified command (incomingCall event trigger). * @param event the <tt>CallEvent</tt> */ public void incomingCallReceived(CallEvent event) @@ -977,8 +1008,14 @@ public class NotificationManager try { Call call = event.getSourceCall(); - String peerName = event.getSourceCall() - .getCallPeers().next().getDisplayName(); + CallPeer firstPeer = call.getCallPeers().next(); + String peerName = firstPeer.getDisplayName(); + + Map<String,String> peerInfo = new HashMap<String, String>(); + peerInfo.put("caller.uri", firstPeer.getURI()); + peerInfo.put("caller.address", firstPeer.getAddress()); + peerInfo.put("caller.name", firstPeer.getDisplayName()); + peerInfo.put("caller.id", firstPeer.getPeerID()); callNotifications.put(event.getSourceCall(), fireNotification( @@ -986,7 +1023,8 @@ public class NotificationManager "", NotificationWiringActivator.getResources() .getI18NString("service.gui.INCOMING_CALL", - new String[]{peerName}))); + new String[]{peerName}), + peerInfo)); call.addCallChangeListener(this); diff --git a/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java b/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java index c528ed6..095fd6d 100644 --- a/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java +++ b/src/net/java/sip/communicator/service/notification/CommandNotificationHandler.java @@ -6,6 +6,8 @@ */ package net.java.sip.communicator.service.notification; +import java.util.Map; + /** * The <tt>CommandNotificationHandler</tt> interface is meant to be implemented * by the notification bundle in order to provide handling of command actions. @@ -18,6 +20,9 @@ public interface CommandNotificationHandler /** * Executes the program pointed by the descriptor. * @param action the action to act upon + * @param cmdargs arguments that are passed to the command line specified + * in the action */ - public void execute(CommandNotificationAction action); + public void execute(CommandNotificationAction action, + Map<String,String> cmdargs); } diff --git a/src/net/java/sip/communicator/service/notification/NotificationData.java b/src/net/java/sip/communicator/service/notification/NotificationData.java index b1540cb..4ff59fe 100644 --- a/src/net/java/sip/communicator/service/notification/NotificationData.java +++ b/src/net/java/sip/communicator/service/notification/NotificationData.java @@ -6,6 +6,8 @@ */
package net.java.sip.communicator.service.notification;
+import java.util.Map;
+
/**
* Object to cache fired notifications before all handler implementations are
* ready registered.
@@ -17,6 +19,7 @@ public class NotificationData private final String eventType;
private final String title;
private final String message;
+ private final Map<String,String> extra;
private final byte[] icon;
private final Object tag;
@@ -28,15 +31,17 @@ public class NotificationData * @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 extra additional data (such as caller information)
* @param icon the icon to show in the notification if and where appropriate
* @param tag additional info to be used by the notification handler
*/
NotificationData(String eventType, String title, String message,
- byte[] icon, Object tag)
+ Map<String,String> extra, byte[] icon, Object tag)
{
this.eventType = eventType;
this.title = title;
this.message = message;
+ this.extra = extra;
this.icon = icon;
this.tag = tag;
}
@@ -46,7 +51,7 @@ public class NotificationData *
* @return the eventType
*/
- String getEventType()
+ public String getEventType()
{
return eventType;
}
@@ -73,6 +78,16 @@ public class NotificationData }
/**
+ * Gets additional data (such as caller information).
+ *
+ * @return the extra data
+ */
+ public Map<String,String> getExtra()
+ {
+ return extra;
+ }
+
+ /**
* Gets the icon to show in the notification if and where appropriate.
*
* @return the icon
diff --git a/src/net/java/sip/communicator/service/notification/NotificationService.java b/src/net/java/sip/communicator/service/notification/NotificationService.java index d594f28..de73d13 100644 --- a/src/net/java/sip/communicator/service/notification/NotificationService.java +++ b/src/net/java/sip/communicator/service/notification/NotificationService.java @@ -6,6 +6,8 @@ */ 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 @@ -254,6 +256,34 @@ public interface NotificationService /** * 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.) + * <p> + * This method does nothing if the given <tt>eventType</tt> is not contained + * in the list of registered event types. + * + * @param eventType the type of the event that we'd like to fire a + * notification for. + * @param messageTitle the message title to use if and where appropriate + * (e.g. with systray) + * @param message the message to use if and where appropriate (e.g. with + * systray or log notification.) + * @param extra the extra data to pass (especially for Command execution) + * @param icon the icon to show in the notification if and where appropriate + * @param tag additional info to be used by the notification handler + * @return An object referencing the notification. It may be used to stop a + * still running notification. Can be null if the eventType is + * unknown or the notification is not active. + */ + public NotificationData fireNotification( String eventType, + String messageTitle, + String message, + Map<String,String> extra, + byte[] icon, + Object tag); + + /** + * Fires all notifications registered for the specified <tt>eventType</tt> * using the default message specified upon registration as a notification * message wherever appropriate. * (e.g. systray notifications, logs, etc.) diff --git a/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java b/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java index bfaeb79..d34fd0c 100644 --- a/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java +++ b/src/net/java/sip/communicator/service/notification/NotificationServiceImpl.java @@ -386,7 +386,9 @@ class NotificationServiceImpl else if (actionType.equals(ACTION_COMMAND)) { ((CommandNotificationHandler) handler) - .execute((CommandNotificationAction) action); + .execute( + (CommandNotificationAction)action, + data.getExtra()); } } } @@ -415,12 +417,46 @@ class NotificationServiceImpl byte[] icon, Object tag) { + return fireNotification(eventType, + title, + message, + null, + icon, + tag); + } + + /** + * If there is a registered event notification of the given + * <tt>eventType</tt> and the event notification is currently activated, the + * list of registered actions is executed. + * + * @param eventType the type of the event that we'd like to fire a + * notification for. + * @param title the title of the given message + * @param message the message to use if and where appropriate (e.g. with + * systray or log notification.) + * @param extra the extra data to pass (especially for Command execution) + * @param icon the icon to show in the notification if and where appropriate + * @param tag additional info to be used by the notification handler + * + * @return An object referencing the notification. It may be used to stop a + * still running notification. Can be null if the eventType is + * unknown or the notification is not active. + */ + public NotificationData fireNotification( + String eventType, + String title, + String message, + Map<String,String> extra, + byte[] icon, + Object tag) + { Notification notification = notifications.get(eventType); if(notification == null || !notification.isActive()) return null; NotificationData data = new NotificationData(eventType, title, - message, icon, tag); + message, extra, icon, tag); //cache the notification when the handlers are not yet ready if (notificationCache != null) @@ -445,7 +481,7 @@ class NotificationServiceImpl */ public NotificationData fireNotification(String eventType) { - return this.fireNotification(eventType, null, null, null, null); + return this.fireNotification(eventType, null, null, null, null, null); } /** |