diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index 450d9621a..8a6751609 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -694,6 +694,8 @@ service.gui.AUTO_ANSWER_FWD_CALLS=Forward Calls service.gui.AUTO_ANSWER_FWD_CALLS_TO=Forward all calls to the following number or URI: service.gui.AUTO_ANSWER_VIDEO=Video service.gui.AUTO_ANSWER_VIDEO_CALLS_WITH_VIDEO=Answer video calls with video +service.gui.LOCAL_VIDEO_ERROR_TITLE=Local video error +service.gui.LOCAL_VIDEO_ERROR_MESSAGE=Failed to enable/disable the local video. service.gui.security.SECURE_AUDIO=Secure audio service.gui.security.AUDIO_NOT_SECURED=Audio not secure diff --git a/src/net/java/sip/communicator/impl/gui/AlertUIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/AlertUIServiceImpl.java index 67d774d43..8b2a7c197 100644 --- a/src/net/java/sip/communicator/impl/gui/AlertUIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/AlertUIServiceImpl.java @@ -6,8 +6,12 @@ */ package net.java.sip.communicator.impl.gui; +import java.util.*; + import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.notification.*; +import net.java.sip.communicator.service.systray.event.*; /** * The AlertUIServiceImpl is an implementation of the @@ -18,6 +22,23 @@ public class AlertUIServiceImpl implements AlertUIService { + /** + * The event type name for the notification pop-ups. + */ + private static final String NOTIFICATION_EVENT_TYPE = "AlertUI"; + + /** + * A boolean used to verify that this listener registers only once to + * the popup message notification handler. + */ + private boolean isRegisteredToPopupMessageListener = false; + + /** + * The pop-up notification listener which handles the clicking on the + * pop-up notification. + */ + private SystrayPopupMessageListener listener = null; + /** * Shows an alert dialog with the given title and message. * @@ -61,4 +82,216 @@ public void showAlertDialog(String title, String message, int type) message, type).showDialog(); } + + /** + * Shows an notification pop-up which can be clicked. An error dialog is + * shown when the notification is clicked. + * + * @param title the title of the error dialog and the notification pop-up + * @param message the message to be displayed in the error dialog and the + * pop-up + */ + public void showPopUpNotification(String title, String message) + { + showPopUpNotification(title, message, title, message, null); + } + + /** + * Shows an notification pop-up which can be clicked. An error dialog is + * shown when the notification is clicked. + * + * @param title the title of the error dialog and the notification pop-up + * @param message the message to be displayed in the error dialog and the + * pop-up + * @param e the exception that can be shown in the error dialog + */ + public void showPopUpNotification(String title, String message, Throwable e) + { + showPopUpNotification(title, message, title, message, e); + } + + /** + * Shows an notification pop-up which can be clicked. An error dialog is + * shown when the notification is clicked. + * + * @param title the title of the notification pop-up + * @param message the message of the pop-up + * @param errorDialogTitle the title of the error dialog + * @param errorDialogMessage the message of the error dialog + */ + public void showPopUpNotification(String title, String message, + String errorDialogTitle, String errorDialogMessage) + { + showPopUpNotification(title, message, errorDialogTitle, + errorDialogMessage, null); + } + + /** + * Shows an notification pop-up which can be clicked. An error dialog is + * shown when the notification is clicked. + * + * @param title the title of the notification pop-up + * @param message the message of the pop-up + * @param errorDialogTitle the title of the error dialog + * @param errorDialogMessage the message of the error dialog + * @param e the exception that can be shown in the error dialog + */ + public void showPopUpNotification(String title, String message, + String errorDialogTitle, String errorDialogMessage, Throwable e) + { + NotificationService notificationService + = GuiActivator.getNotificationService(); + + if(notificationService == null) + return; + + // Registers only once to the popup message notification + // handler. + if(!isRegisteredToPopupMessageListener ) + { + notificationService.registerDefaultNotificationForEvent( + NOTIFICATION_EVENT_TYPE, + NotificationAction.ACTION_POPUP_MESSAGE, + null, null); + isRegisteredToPopupMessageListener = true; + addOrRemovePopupMessageListener(true); + } + + // Fires the popup notification. + Map extras = new HashMap(); + + extras.put(NotificationData.POPUP_MESSAGE_HANDLER_TAG_EXTRA, + new ErrorDialogParams(title, message, e)); + notificationService.fireNotification(NOTIFICATION_EVENT_TYPE, title, + message, null, extras); + + } + + /** + * Adds/removes the listener instance as a PopupMessageListener + * to/from theNotificationService in order to be able to detect + * when the user clicks on a pop-up notification displayed by this instance + * + * @param add true to add the listener instance as a + * PopupMessageListener to the NotificationService or + * false to remove it + */ + private void addOrRemovePopupMessageListener(boolean add) + { + Iterable popupHandlers + = GuiActivator.getNotificationService() + .getActionHandlers(NotificationAction.ACTION_POPUP_MESSAGE); + + for(NotificationHandler popupHandler : popupHandlers) + { + if(!(popupHandler instanceof PopupMessageNotificationHandler)) + continue; + + PopupMessageNotificationHandler popupMessageNotificationHandler + = (PopupMessageNotificationHandler) popupHandler; + + if(listener == null) + { + listener = new SystrayPopupMessageListener() + { + public void popupMessageClicked( + SystrayPopupMessageEvent evt) + { + Object tag = evt.getTag(); + if(tag instanceof ErrorDialogParams) + { + ErrorDialogParams params = (ErrorDialogParams)tag; + if(params.getEx() != null) + { + showAlertDialog(params.getTitle(), + params.getMessage(), params.getEx()); + } + else + { + showAlertDialog(params.getTitle(), + params.getMessage()); + } + } + + } + + }; + } + + if(add) + { + popupMessageNotificationHandler.addPopupMessageListener( + listener); + } + else + { + popupMessageNotificationHandler.removePopupMessageListener( + listener); + } + + } + + } + + /** + * Releases the resources acquired by this instance throughout its lifetime + * and removes the listeners. + */ + public void dispose() + { + addOrRemovePopupMessageListener(false); + } + + /** + * The ErrorDialogParams class is holder for the parameters needed by the + * error dialog to be shown. + */ + class ErrorDialogParams + { + /** + * The title parameter. + */ + private String title; + + /** + * The message parameter. + */ + private String message; + + /** + * The exception parameter. + */ + private Throwable e; + + public ErrorDialogParams(String title, String message, Throwable e) + { + this.title = title; + this.message = message; + this.e = e; + } + + /** + * @return the title + */ + public String getTitle() + { + return title; + } + + /** + * @return the message + */ + public String getMessage() + { + return message; + } + + /** + * @return the exception + */ + public Throwable getEx() + { + return e; + } + } } diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index 802293fbf..0d6c79f1d 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -100,6 +100,8 @@ public class GuiActivator implements BundleActivator private static DemuxContactSourceService demuxContactSourceService; private static GlobalDisplayDetailsService globalDisplayDetailsService; + + private static AlertUIService alertUIService; private static final Map providerFactoriesMap = new Hashtable(); @@ -139,10 +141,11 @@ public void start(BundleContext bContext) bundleContext.registerService(GlobalStatusService.class.getName(), new GlobalStatusServiceImpl(), null); - + + alertUIService = new AlertUIServiceImpl(); // Registers an implementation of the AlertUIService. bundleContext.registerService( AlertUIService.class.getName(), - new AlertUIServiceImpl(), + alertUIService, null); // Create the ui service @@ -215,6 +218,7 @@ public void stop(BundleContext bContext) throws Exception .removePropertyChangeListener(uiService); bContext.removeServiceListener(uiService); + alertUIService.dispose(); } /** @@ -405,6 +409,15 @@ public static UIServiceImpl getUIService() { return uiService; } + + /** + * Returns the implementation of the AlertUIService. + * @return the implementation of the AlertUIService + */ + public static AlertUIService getAlertUIService() + { + return alertUIService; + } /** * Returns the SystrayService obtained from the bundle context. diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java index 47b07ee30..b2fef299d 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java @@ -2849,6 +2849,14 @@ public void run() logger.error( "Failed to toggle the streaming of local video.", ex); + ResourceManagementService resources + = GuiActivator.getResources(); + String title = resources.getI18NString( + "service.gui.LOCAL_VIDEO_ERROR_TITLE"); + String message = resources.getI18NString( + "service.gui.LOCAL_VIDEO_ERROR_MESSAGE"); + GuiActivator.getAlertUIService().showPopUpNotification( + title, message, ex); } } diff --git a/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf b/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf index 626ecd918..5f8f0e3b4 100644 --- a/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf +++ b/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf @@ -47,6 +47,7 @@ Import-Package: com.apple.eawt, net.java.sip.communicator.service.resources, net.java.sip.communicator.service.shutdown, net.java.sip.communicator.service.systray, + net.java.sip.communicator.service.systray.event, net.java.sip.communicator.util, net.java.sip.communicator.util.skin, net.java.sip.communicator.util.account, diff --git a/src/net/java/sip/communicator/service/gui/AlertUIService.java b/src/net/java/sip/communicator/service/gui/AlertUIService.java index f8f203249..1adf3d657 100644 --- a/src/net/java/sip/communicator/service/gui/AlertUIService.java +++ b/src/net/java/sip/communicator/service/gui/AlertUIService.java @@ -72,4 +72,57 @@ public void showAlertDialog(String title, public void showAlertDialog(String title, String message, int type); + + /** + * Shows an notification pop-up which can be clicked. An error dialog is + * shown when the notification is clicked. + * + * @param title the title of the error dialog and the notification pop-up + * @param message the message to be displayed in the error dialog and the + * pop-up + */ + public void showPopUpNotification(String title, String message); + + /** + * Shows an notification pop-up which can be clicked. An error dialog is + * shown when the notification is clicked. + * + * @param title the title of the error dialog and the notification pop-up + * @param message the message to be displayed in the error dialog and the + * pop-up + * @param e the exception that can be shown in the error dialog + */ + public void showPopUpNotification(String title, String message, + Throwable e); + + /** + * Shows an notification pop-up which can be clicked. An error dialog is + * shown when the notification is clicked. + * + * @param title the title of the notification pop-up + * @param message the message of the pop-up + * @param errorDialogTitle the title of the error dialog + * @param errorDialogMessage the message of the error dialog + */ + public void showPopUpNotification(String title, String message, + String errorDialogTitle, String errorDialogMessage); + + /** + * Shows an notification pop-up which can be clicked. An error dialog is + * shown when the notification is clicked. + * + * @param title the title of the notification pop-up + * @param message the message of the pop-up + * @param errorDialogTitle the title of the error dialog + * @param errorDialogMessage the message of the error dialog + * @param e the exception that can be shown in the error dialog + */ + public void showPopUpNotification(String title, String message, + String errorDialogTitle, String errorDialogMessage, Throwable e); + + /** + * Releases the resources acquired by this instance throughout its lifetime + * and removes the listeners. + */ + public void dispose(); }