Adds new methods to AlertUIServiceImpl that show a notification popup. If the popup is clicked an error dialog is shown. CallManger uses the new methods to show an error if enabling the local video fails.

cusax-fix
hristoterezov 13 years ago
parent 515f210012
commit e7467d8a84

@ -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

@ -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 <tt>AlertUIServiceImpl</tt> 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<String,Object> extras = new HashMap<String,Object>();
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 <tt>PopupMessageListener</tt>
* to/from the<tt>NotificationService</tt> in order to be able to detect
* when the user clicks on a pop-up notification displayed by this instance
*
* @param add <tt>true</tt> to add the listener instance as a
* <tt>PopupMessageListener</tt> to the <tt>NotificationService</tt> or
* <tt>false</tt> to remove it
*/
private void addOrRemovePopupMessageListener(boolean add)
{
Iterable<NotificationHandler> 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;
}
}
}

@ -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<Object, ProtocolProviderFactory>
providerFactoriesMap = new Hashtable<Object, ProtocolProviderFactory>();
@ -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 <tt>AlertUIService</tt>.
* @return the implementation of the <tt>AlertUIService</tt>
*/
public static AlertUIService getAlertUIService()
{
return alertUIService;
}
/**
* Returns the <tt>SystrayService</tt> obtained from the bundle context.

@ -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);
}
}

@ -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,

@ -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();
}

Loading…
Cancel
Save