diff options
author | Yana Stamcheva <yana@jitsi.org> | 2013-01-29 14:14:48 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2013-01-29 14:14:48 +0000 |
commit | 07a34a3f1382f817c6ab328963ce9b8c699afd30 (patch) | |
tree | 617f211b82681851653ef58e17e83641595a7c71 | |
parent | 0052044d0509495615e72d8ac054c4ea0d1d1d36 (diff) | |
download | jitsi-07a34a3f1382f817c6ab328963ce9b8c699afd30.zip jitsi-07a34a3f1382f817c6ab328963ce9b8c699afd30.tar.gz jitsi-07a34a3f1382f817c6ab328963ce9b8c699afd30.tar.bz2 |
Separates account status related methods to AccountStatusUtils class in the util package. Moves LoginManager to util package and creates a LoginRenderer interface that allows to provide a different UI implementation for login related operations.
16 files changed, 1159 insertions, 728 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/AlertUIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/AlertUIServiceImpl.java new file mode 100644 index 0000000..67d774d --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/AlertUIServiceImpl.java @@ -0,0 +1,64 @@ +/* + * 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.impl.gui; + +import net.java.sip.communicator.plugin.desktoputil.*; +import net.java.sip.communicator.service.gui.*; + +/** + * The <tt>AlertUIServiceImpl</tt> is an implementation of the + * <tt>AlertUIService</tt> that allows to show swing error dialogs. + * + * @author Yana Stamcheva + */ +public class AlertUIServiceImpl + implements AlertUIService +{ + /** + * Shows an alert dialog with the given title and message. + * + * @param title the title of the dialog + * @param message the message to be displayed + */ + public void showAlertDialog(String title, String message) + { + new ErrorDialog(GuiActivator.getUIService().getMainFrame(), + title, + message).showDialog(); + } + + /** + * Shows an alert dialog with the given title message and exception + * corresponding to the error. + * + * @param title the title of the dialog + * @param message the message to be displayed + * @param e the exception corresponding to the error + */ + public void showAlertDialog(String title, String message, Throwable e) + { + new ErrorDialog(GuiActivator.getUIService().getMainFrame(), + title, + message, + e).showDialog(); + } + + /** + * Shows an alert dialog with the given title, message and type of message. + * + * @param title the title of the error dialog + * @param message the message to be displayed + * @param type the dialog type (warning or error) + */ + public void showAlertDialog(String title, String message, int type) + { + new ErrorDialog(GuiActivator.getUIService().getMainFrame(), + title, + message, + type).showDialog(); + } +} diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index 90c261f..6afe6a2 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -137,6 +137,11 @@ public class GuiActivator implements BundleActivator new GlobalStatusServiceImpl(), null); + // Registers an implementation of the AlertUIService. + bundleContext.registerService( AlertUIService.class.getName(), + new AlertUIServiceImpl(), + null); + // Create the ui service uiService = new UIServiceImpl(); diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java index cb2bee9..d9cdf03 100644 --- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java @@ -38,6 +38,7 @@ import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.shutdown.*; import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.Logger; +import net.java.sip.communicator.util.account.*; import net.java.sip.communicator.util.skin.*; import org.jitsi.service.resources.*; @@ -163,7 +164,8 @@ public class UIServiceImpl GuiActivator.getUIService().registerExportedWindow(mainFrame); // Initialize the login manager. - this.loginManager = new LoginManager(mainFrame); + this.loginManager + = new LoginManager(new LoginRendererSwingImpl()); this.popupDialog = new PopupDialogImpl(); @@ -819,7 +821,7 @@ public class UIServiceImpl */ private class RunLoginGui implements Runnable { public void run() { - loginManager.runLogin(mainFrame); + loginManager.runLogin(); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java index eb35397..d8214cb 100644 --- a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java +++ b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java @@ -987,25 +987,6 @@ public class MainFrame } /** - * Returns the presence operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the - * presence operation set is searched. - * @return the presence operation set for the given protocol provider. - */ - public static OperationSetPresence getProtocolPresenceOpSet( - ProtocolProviderService protocolProvider) - { - OperationSet opSet - = protocolProvider.getOperationSet(OperationSetPresence.class); - - return - (opSet instanceof OperationSetPresence) - ? (OperationSetPresence) opSet - : null; - } - - /** * Returns the Web Contact Info operation set for the given * protocol provider. * @@ -1292,23 +1273,6 @@ public class MainFrame } /** - * If the protocol provider supports presence operation set searches the - * last status which was selected, otherwise returns null. - * - * @param protocolProvider the protocol provider we're interested in. - * @return the last protocol provider presence status, or null if this - * provider doesn't support presence operation set - */ - public Object getProtocolProviderLastStatus( - ProtocolProviderService protocolProvider) - { - if(getProtocolPresenceOpSet(protocolProvider) != null) - return accountStatusPanel.getLastPresenceStatus(protocolProvider); - else - return accountStatusPanel.getLastStatusString(protocolProvider); - } - - /** * Overwrites the <tt>SIPCommFrame</tt> close method. This method is * invoked when user presses the Escape key. * @param isEscaped indicates if this window has been closed by pressing diff --git a/src/net/java/sip/communicator/impl/gui/main/login/LoginRendererSwingImpl.java b/src/net/java/sip/communicator/impl/gui/main/login/LoginRendererSwingImpl.java new file mode 100644 index 0000000..ac946b8 --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/main/login/LoginRendererSwingImpl.java @@ -0,0 +1,168 @@ +/* + * 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.impl.gui.main.login; + +import net.java.sip.communicator.impl.gui.*; +import net.java.sip.communicator.impl.gui.customcontrols.*; +import net.java.sip.communicator.impl.gui.main.*; +import net.java.sip.communicator.impl.gui.main.authorization.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.account.*; +import net.java.sip.communicator.util.account.LoginManager; + +/** + * The <tt>LoginRendererSwingImpl</tt> provides a Swing base implementation of + * the <tt>LoginRenderer</tt> interface. + * + * @author Yana Stamcheva + */ +public class LoginRendererSwingImpl + implements LoginRenderer +{ + private final MainFrame mainFrame + = GuiActivator.getUIService().getMainFrame(); + + /** + * Adds the user interface related to the given protocol provider. + * + * @param protocolProvider the protocol provider for which we add the user + * interface + */ + public void addProtocolProviderUI(ProtocolProviderService protocolProvider) + { + GuiActivator.getUIService() + .getMainFrame().addProtocolProvider(protocolProvider); + } + + /** + * Removes the user interface related to the given protocol provider. + * + * @param protocolProvider the protocol provider to remove + */ + public void removeProtocolProviderUI( + ProtocolProviderService protocolProvider) + { + this.mainFrame.removeProtocolProvider(protocolProvider); + } + + /** + * Starts the connecting user interface for the given protocol provider. + * + * @param protocolProvider the protocol provider for which we add the + * connecting user interface + */ + public void startConnectingUI(ProtocolProviderService protocolProvider) + { + mainFrame.getAccountStatusPanel().startConnecting(protocolProvider); + } + + /** + * Stops the connecting user interface for the given protocol provider. + * + * @param protocolProvider the protocol provider for which we remove the + * connecting user interface + */ + public void stopConnectingUI(ProtocolProviderService protocolProvider) + { + mainFrame.getAccountStatusPanel().stopConnecting(protocolProvider); + } + + /** + * Indicates that the given protocol provider is now connected. + * + * @param protocolProvider the <tt>ProtocolProviderService</tt> that is + * connected + * @param date the date on which the event occured + */ + public void protocolProviderConnected( + ProtocolProviderService protocolProvider, long date) + { + OperationSetPresence presence + = AccountStatusUtils.getProtocolPresenceOpSet(protocolProvider); + + OperationSetMultiUserChat multiUserChat = + mainFrame.getMultiUserChatOpSet(protocolProvider); + + if (presence != null) + { + presence.setAuthorizationHandler(new AuthorizationHandlerImpl( + mainFrame)); + } + + if(multiUserChat != null) + { + GuiActivator.getUIService().getConferenceChatManager() + .getChatRoomList().synchronizeOpSetWithLocalContactList( + protocolProvider, multiUserChat); + } + } + + /** + * Indicates that a protocol provider connection has failed. + * + * @param protocolProvider the <tt>ProtocolProviderService</tt>, which + * connection failed + * @param loginManagerCallback the <tt>LoginManager</tt> implementation, + * which is managing the process + */ + public void protocolProviderConnectionFailed( + ProtocolProviderService protocolProvider, + LoginManager loginManagerCallback) + { + AccountID accountID = protocolProvider.getAccountID(); + String errorMessage = GuiActivator.getResources().getI18NString( + "service.gui.LOGIN_NETWORK_ERROR", + new String[] + { accountID.getUserID(), accountID.getService() }); + + int result = + new MessageDialog( + null, + GuiActivator.getResources() + .getI18NString("service.gui.ERROR"), + errorMessage, + GuiActivator.getResources() + .getI18NString("service.gui.RETRY"), false) + .showDialog(); + + if (result == MessageDialog.OK_RETURN_CODE) + { + loginManagerCallback.login(protocolProvider); + } + } + + /** + * Returns the <tt>SecurityAuthority</tt> implementation related to this + * login renderer. + * + * @param protocolProvider the specific <tt>ProtocolProviderService</tt>, + * for which we're obtaining a security authority + * @return the <tt>SecurityAuthority</tt> implementation related to this + * login renderer + */ + public SecurityAuthority getSecurityAuthorityImpl( + ProtocolProviderService protocolProvider) + { + return GuiActivator.getUIService() + .getDefaultSecurityAuthority(protocolProvider); + } + + /** + * Indicates if the given <tt>protocolProvider</tt> related user interface + * is already rendered. + * + * @param protocolProvider the <tt>ProtocolProviderService</tt>, which + * related user interface we're looking for + * @return <tt>true</tt> if the given <tt>protocolProvider</tt> related user + * interface is already rendered + */ + public boolean containsProtocolProviderUI( + ProtocolProviderService protocolProvider) + { + return mainFrame.hasProtocolProvider(protocolProvider); + } +} diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java b/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java index d73e86b..bd20336 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java @@ -29,7 +29,6 @@ import net.java.sip.communicator.plugin.desktoputil.SwingWorker; import net.java.sip.communicator.plugin.desktoputil.TransparentPanel; import org.jitsi.util.*; -import org.jitsi.util.swing.*; /** * The panel shown on the top of the contact list. It contains user name, @@ -279,33 +278,6 @@ public class AccountStatusPanel } /** - * Returns the last used presence status for the given - * <tt>protocolProvider</tt>. - * @param protocolProvider the <tt>ProtocolProviderService</tt> - * corresponding to the account we're looking for - * @return the last used presence status for the given - * <tt>protocolProvider</tt> - */ - public Object getLastPresenceStatus( - ProtocolProviderService protocolProvider) - { - return statusComboBox.getLastPresenceStatus(protocolProvider); - } - - /** - * Returns the last used status for the given <tt>protocolProvider</tt> - * as a String. - * @param protocolProvider the <tt>ProtocolProviderService</tt> - * corresponding to the account we're looking for - * @return a String representation of the last used status for the given - * <tt>protocolProvider</tt> - */ - public String getLastStatusString(ProtocolProviderService protocolProvider) - { - return statusComboBox.getLastStatusString(protocolProvider); - } - - /** * Updates the current status of the <tt>protocolProvider</tt> with the * <tt>newStatus</tt>. If status is null uses the current status. * @param protocolProvider the <tt>ProtocolProviderService</tt> to update diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusSelectorBox.java b/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusSelectorBox.java index f137609..7700ea1 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusSelectorBox.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusSelectorBox.java @@ -21,6 +21,7 @@ import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.globalstatus.*; import net.java.sip.communicator.service.systray.*; import net.java.sip.communicator.util.*; +import net.java.sip.communicator.util.account.*; /** * The <tt>GlobalStatusSelectorBox</tt> is a global status selector box, which @@ -352,7 +353,8 @@ public class GlobalStatusSelectorBox presenceStatus = presenceStatusMenu.getOfflineStatus(); else { - presenceStatus = getLastPresenceStatus(protocolProvider); + presenceStatus + = AccountStatusUtils.getLastPresenceStatus(protocolProvider); if (presenceStatus == null) presenceStatus = presenceStatusMenu.getOnlineStatus(); } @@ -546,34 +548,6 @@ public class GlobalStatusSelectorBox } /** - * Returns the last status that was stored in the configuration xml for the - * given protocol provider. - * - * @param protocolProvider the protocol provider - * @return the last status that was stored in the configuration xml for the - * given protocol provider - */ - public PresenceStatus getLastPresenceStatus( - ProtocolProviderService protocolProvider) - { - return GuiActivator.getGlobalStatusService() - .getLastPresenceStatus(protocolProvider); - } - - /** - * Returns the last contact status saved in the configuration. - * - * @param protocolProvider the protocol provider to which the status - * corresponds - * @return the last contact status saved in the configuration. - */ - public String getLastStatusString(ProtocolProviderService protocolProvider) - { - return GuiActivator.getGlobalStatusService() - .getLastStatusString(protocolProvider); - } - - /** * Overwrites the <tt>paintComponent(Graphics g)</tt> method in order to * provide a new look and the mouse moves over this component. * @param g the <tt>Graphics</tt> object used for painting diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusServiceImpl.java b/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusServiceImpl.java index 389a7f8..c03c3a7 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusServiceImpl.java @@ -6,11 +6,12 @@ package net.java.sip.communicator.impl.gui.main.presence; import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.main.login.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.globalstatus.*; import net.java.sip.communicator.util.*; +import net.java.sip.communicator.util.account.*; + import org.jitsi.service.configuration.*; import java.util.*; diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/PresenceStatusMenu.java b/src/net/java/sip/communicator/impl/gui/main/presence/PresenceStatusMenu.java index 3f458ab..f60b295 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/PresenceStatusMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/PresenceStatusMenu.java @@ -20,6 +20,8 @@ import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.plugin.desktoputil.presence.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.Logger; +import net.java.sip.communicator.util.account.*; + import org.jitsi.util.*; /** @@ -201,7 +203,7 @@ public class PresenceStatusMenu public void updateStatus(PresenceStatus presenceStatus) { OperationSetPresence presence - = MainFrame.getProtocolPresenceOpSet(protocolProvider); + = AccountStatusUtils.getProtocolPresenceOpSet(protocolProvider); if (logger.isTraceEnabled()) logger.trace("Update status for provider: " diff --git a/src/net/java/sip/communicator/service/gui/AlertUIService.java b/src/net/java/sip/communicator/service/gui/AlertUIService.java new file mode 100644 index 0000000..f8f2032 --- /dev/null +++ b/src/net/java/sip/communicator/service/gui/AlertUIService.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.gui;
+
+/**
+ * The <tt>AlertUIService</tt> is a service that allows to show error messages
+ * and warnings.
+ *
+ * @author Yana Stamcheva
+ */
+public interface AlertUIService
+{
+ /**
+ * Indicates that the OK button is pressed.
+ */
+ public static final int OK_RETURN_CODE = 0;
+
+ /**
+ * Indicates that the Cancel button is pressed.
+ */
+ public static final int CANCEL_RETURN_CODE = 1;
+
+ /**
+ * Indicates that the OK button is pressed and the Don't ask check box is
+ * checked.
+ */
+ public static final int OK_DONT_ASK_CODE = 2;
+
+ /**
+ * The type of the alert dialog, which displays a warning instead of an
+ * error.
+ */
+ public static final int WARNING = 1;
+
+ /**
+ * The type of alert dialog which displays a warning instead of an error.
+ */
+ public static final int ERROR = 0;
+
+ /**
+ * Shows an alert dialog with the given title and message.
+ *
+ * @param title the title of the dialog
+ * @param message the message to be displayed
+ */
+ public void showAlertDialog(String title,
+ String message);
+
+ /**
+ * Shows an alert dialog with the given title message and exception
+ * corresponding to the error.
+ *
+ * @param title the title of the dialog
+ * @param message the message to be displayed
+ * @param e the exception corresponding to the error
+ */
+ public void showAlertDialog(String title,
+ String message,
+ Throwable e);
+
+ /**
+ * Shows an alert dialog with the given title, message and type of message.
+ *
+ * @param title the title of the error dialog
+ * @param message the message to be displayed
+ * @param type the dialog type (warning or error)
+ */
+ public void showAlertDialog(String title,
+ String message,
+ int type);
+}
diff --git a/src/net/java/sip/communicator/util/UtilActivator.java b/src/net/java/sip/communicator/util/UtilActivator.java index ab9678f..0bafaca 100644 --- a/src/net/java/sip/communicator/util/UtilActivator.java +++ b/src/net/java/sip/communicator/util/UtilActivator.java @@ -54,6 +54,10 @@ public class UtilActivator public static BundleContext bundleContext; + private static AccountManager accountManager; + + private static AlertUIService alertUIService; + /** * Network address manager service will inform us for changes in * network configuration. @@ -280,4 +284,37 @@ public class UtilActivator } return parallelResolver; } + + /** + * Returns the <tt>AccountManager</tt> obtained from the bundle context. + * @return the <tt>AccountManager</tt> obtained from the bundle context + */ + public static AccountManager getAccountManager() + { + if(accountManager == null) + { + accountManager + = ServiceUtils.getService(bundleContext, AccountManager.class); + } + return accountManager; + } + + + /** + * Returns the <tt>MetaContactListService</tt> obtained from the bundle + * context. + * @return the <tt>MetaContactListService</tt> obtained from the bundle + * context + */ + public static AlertUIService getAlertUIService() + { + if (alertUIService == null) + { + alertUIService + = ServiceUtils.getService( + bundleContext, + AlertUIService.class); + } + return alertUIService; + } } diff --git a/src/net/java/sip/communicator/util/account/AccountStatusUtils.java b/src/net/java/sip/communicator/util/account/AccountStatusUtils.java new file mode 100644 index 0000000..ee42942 --- /dev/null +++ b/src/net/java/sip/communicator/util/account/AccountStatusUtils.java @@ -0,0 +1,108 @@ +/*
+ * 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.util.account;
+
+import net.java.sip.communicator.service.protocol.*;
+import net.java.sip.communicator.service.protocol.globalstatus.*;
+import net.java.sip.communicator.util.*;
+
+/**
+ * The <tt>AccountStatusUtils</tt> provides utility methods for account status
+ * management.
+ *
+ * @author Yana Stamcheva
+ */
+public class AccountStatusUtils
+{
+ private static GlobalStatusService globalStatusService;
+
+ /**
+ * If the protocol provider supports presence operation set searches the
+ * last status which was selected, otherwise returns null.
+ *
+ * @param protocolProvider the protocol provider we're interested in.
+ * @return the last protocol provider presence status, or null if this
+ * provider doesn't support presence operation set
+ */
+ public static Object getProtocolProviderLastStatus(
+ ProtocolProviderService protocolProvider)
+ {
+ if(getProtocolPresenceOpSet(protocolProvider) != null)
+ return getLastPresenceStatus(protocolProvider);
+ else
+ return getGlobalStatusService()
+ .getLastStatusString(protocolProvider);
+ }
+
+ /**
+ * Returns the presence operation set for the given protocol provider.
+ *
+ * @param protocolProvider The protocol provider for which the
+ * presence operation set is searched.
+ * @return the presence operation set for the given protocol provider.
+ */
+ public static OperationSetPresence getProtocolPresenceOpSet(
+ ProtocolProviderService protocolProvider)
+ {
+ OperationSet opSet
+ = protocolProvider.getOperationSet(OperationSetPresence.class);
+
+ return
+ (opSet instanceof OperationSetPresence)
+ ? (OperationSetPresence) opSet
+ : null;
+ }
+
+ /**
+ * Returns the last status that was stored in the configuration xml for the
+ * given protocol provider.
+ *
+ * @param protocolProvider the protocol provider
+ * @return the last status that was stored in the configuration xml for the
+ * given protocol provider
+ */
+ public static PresenceStatus getLastPresenceStatus(
+ ProtocolProviderService protocolProvider)
+ {
+ if (getGlobalStatusService() != null)
+ return getGlobalStatusService().getLastPresenceStatus(
+ protocolProvider);
+
+ return null;
+ }
+
+ /**
+ * Returns the last contact status saved in the configuration.
+ *
+ * @param protocolProvider the protocol provider to which the status
+ * corresponds
+ * @return the last contact status saved in the configuration.
+ */
+ public String getLastStatusString(ProtocolProviderService protocolProvider)
+ {
+ return getGlobalStatusService().getLastStatusString(protocolProvider);
+ }
+
+ /**
+ * Returns the <tt>GlobalStatusService</tt> obtained from the bundle
+ * context.
+ * @return the <tt>GlobalStatusService</tt> obtained from the bundle
+ * context
+ */
+ public static GlobalStatusService getGlobalStatusService()
+ {
+ if (globalStatusService == null)
+ {
+ globalStatusService
+ = ServiceUtils.getService(
+ UtilActivator.bundleContext,
+ GlobalStatusService.class);
+ }
+
+ return globalStatusService;
+ }
+}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/util/account/AccountUtils.java b/src/net/java/sip/communicator/util/account/AccountUtils.java index 5134362..4dfe918 100644 --- a/src/net/java/sip/communicator/util/account/AccountUtils.java +++ b/src/net/java/sip/communicator/util/account/AccountUtils.java @@ -14,6 +14,9 @@ import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*;
/**
+ * The <tt>AccountUtils</tt> provides utility methods helping us to easily
+ * obtain an account or a groups of accounts or protocol providers by some
+ * specific criteria.
*
* @author Yana Stamcheva
*/
diff --git a/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java b/src/net/java/sip/communicator/util/account/LoginManager.java index 89d75e6..ab0d7fe 100644 --- a/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java +++ b/src/net/java/sip/communicator/util/account/LoginManager.java @@ -1,631 +1,588 @@ -/* - * 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.impl.gui.main.login; - -import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.customcontrols.*; -import net.java.sip.communicator.impl.gui.main.*; -import net.java.sip.communicator.impl.gui.main.authorization.*; -import net.java.sip.communicator.plugin.desktoputil.*; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.service.protocol.globalstatus.*; -import net.java.sip.communicator.util.*; - -import org.osgi.framework.*; - -/** - * The <tt>LoginManager</tt> manages the login operation. Here we obtain the - * <tt>ProtocolProviderFactory</tt>, we make the account installation and we - * handle all events related to the registration state. - * <p> - * The <tt>LoginManager</tt> is the one that opens one or more - * <tt>LoginWindow</tt>s for each <tt>ProtocolProviderFactory</tt>. The - * <tt>LoginWindow</tt> is where user could enter an identifier and password. - * <p> - * Note that the behavior of this class will be changed when the Configuration - * Service is ready. - * - * @author Yana Stamcheva - */ -public class LoginManager - implements ServiceListener, - RegistrationStateChangeListener, - AccountManagerListener -{ - private final Logger logger = Logger.getLogger(LoginManager.class); - - private final MainFrame mainFrame; - - private boolean manuallyDisconnected = false; - - /** - * Creates an instance of the <tt>LoginManager</tt>, by specifying the main - * application window. - * - * @param mainFrame the main application window - */ - public LoginManager(MainFrame mainFrame) - { - this.mainFrame = mainFrame; - - GuiActivator.bundleContext.addServiceListener(this); - } - - /** - * Registers the given protocol provider. - * - * @param protocolProvider the ProtocolProviderService to register. - */ - public void login(ProtocolProviderService protocolProvider) - { - SecurityAuthority secAuth - = GuiActivator.getUIService() - .getDefaultSecurityAuthority(protocolProvider); - - mainFrame.getAccountStatusPanel().startConnecting(protocolProvider); - - new RegisterProvider(protocolProvider, secAuth).start(); - } - - /** - * Unregisters the given protocol provider. - * - * @param protocolProvider the ProtocolProviderService to unregister - */ - public void logoff(ProtocolProviderService protocolProvider) - { - new UnregisterProvider(protocolProvider).start(); - } - - /** - * Shows login window for each registered account. - * - * @param parent The parent MainFrame window. - */ - public void runLogin(MainFrame parent) - { - // if someone is late registering catch it - GuiActivator.getAccountManager().addListener(this); - - for (ProtocolProviderFactory providerFactory : GuiActivator - .getProtocolProviderFactories().values()) - { - addAccountsForProtocolProviderFactory(providerFactory); - } - } - - /** - * Notifies that the loading of the stored accounts of a - * specific <code>ProtocolProviderFactory</code> has finished. - * - * @param event the <code>AccountManagerEvent</code> describing the - * <code>AccountManager</code> firing the notification and the - * other details of the specific notification. - */ - public void handleAccountManagerEvent(AccountManagerEvent event) - { - if(event.getType() - == AccountManagerEvent.STORED_ACCOUNTS_LOADED) - { - addAccountsForProtocolProviderFactory(event.getFactory()); - } - } - - /** - * Handles stored accounts for a protocol provider factory and add them - * to the UI and register them if needed. - * @param providerFactory the factory to handle. - */ - private void addAccountsForProtocolProviderFactory( - ProtocolProviderFactory providerFactory) - { - ServiceReference serRef; - ProtocolProviderService protocolProvider; - - for (AccountID accountID : providerFactory.getRegisteredAccounts()) - { - serRef = providerFactory.getProviderForAccount(accountID); - - protocolProvider = - (ProtocolProviderService) GuiActivator.bundleContext - .getService(serRef); - - // check whether we have already loaded this provider - if(this.mainFrame.hasProtocolProvider(protocolProvider)) - continue; - - protocolProvider.addRegistrationStateChangeListener(this); - - this.mainFrame.addProtocolProvider(protocolProvider); - - Object status = - this.mainFrame - .getProtocolProviderLastStatus(protocolProvider); - - if (status == null - || status.equals(GlobalStatusEnum.ONLINE_STATUS) - || ((status instanceof PresenceStatus) - && (((PresenceStatus) status) - .getStatus() >= PresenceStatus.ONLINE_THRESHOLD))) - { - this.login(protocolProvider); - } - } - } - - /** - * The method is called by a ProtocolProvider implementation whenever a - * change in the registration state of the corresponding provider had - * occurred. - * - * @param evt ProviderStatusChangeEvent the event describing the status - * change. - */ - public void registrationStateChanged(RegistrationStateChangeEvent evt) - { - RegistrationState newState = evt.getNewState(); - ProtocolProviderService protocolProvider = evt.getProvider(); - AccountID accountID = protocolProvider.getAccountID(); - - if (logger.isTraceEnabled()) - logger.trace("Protocol provider: " + protocolProvider - + " changed its state to: " + evt.getNewState().getStateName()); - - if (newState.equals(RegistrationState.REGISTERED) - || newState.equals(RegistrationState.UNREGISTERED) - || newState.equals(RegistrationState.EXPIRED) - || newState.equals(RegistrationState.AUTHENTICATION_FAILED) - || newState.equals(RegistrationState.CONNECTION_FAILED) - || newState.equals(RegistrationState.CHALLENGED_FOR_AUTHENTICATION) - || newState.equals(RegistrationState.REGISTERED)) - { - mainFrame.getAccountStatusPanel().stopConnecting(protocolProvider); - } - - if (newState.equals(RegistrationState.REGISTERED)) - { - OperationSetPresence presence - = MainFrame.getProtocolPresenceOpSet(protocolProvider); - - OperationSetMultiUserChat multiUserChat = - mainFrame.getMultiUserChatOpSet(protocolProvider); - - if (presence != null) - { - presence.setAuthorizationHandler(new AuthorizationHandlerImpl( - mainFrame)); - } - - if(multiUserChat != null) - { - GuiActivator.getUIService().getConferenceChatManager() - .getChatRoomList().synchronizeOpSetWithLocalContactList( - protocolProvider, multiUserChat); - } - } - else if (newState.equals(RegistrationState.AUTHENTICATION_FAILED)) - { - if (evt.getReasonCode() == RegistrationStateChangeEvent - .REASON_RECONNECTION_RATE_LIMIT_EXCEEDED) - { - - String msgText = GuiActivator.getResources().getI18NString( - "service.gui.RECONNECTION_LIMIT_EXCEEDED", new String[] - { accountID.getUserID(), accountID.getService() }); - - new ErrorDialog( - null, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - msgText).showDialog(); - } - else if (evt.getReasonCode() == RegistrationStateChangeEvent - .REASON_NON_EXISTING_USER_ID) - { - String msgText = GuiActivator.getResources().getI18NString( - "service.gui.NON_EXISTING_USER_ID", - new String[] - { protocolProvider.getProtocolDisplayName() }); - - new ErrorDialog( - null, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - msgText).showDialog(); - } - else if (evt.getReasonCode() == RegistrationStateChangeEvent - .REASON_TLS_REQUIRED) - { - String msgText = GuiActivator.getResources().getI18NString( - "service.gui.NON_SECURE_CONNECTION", - new String[] - { accountID.getAccountAddress() }); - - new ErrorDialog( - null, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - msgText).showDialog(); - } - - if (logger.isTraceEnabled()) - logger.trace(evt.getReason()); - } -// CONNECTION_FAILED events are now dispatched in reconnect plugin -// else if (newState.equals(RegistrationState.CONNECTION_FAILED)) -// { -// String msgText = GuiActivator.getResources().getI18NString( -// "service.gui.CONNECTION_FAILED_MSG", -// new String[] -// { accountID.getUserID(), -// accountID.getService() }); -// -// int result = new MessageDialog( -// null, -// GuiActivator.getResources().getI18NString("service.gui.ERROR"), -// msgText, -// GuiActivator.getResources().getI18NString("service.gui.RETRY"), -// false).showDialog(); -// -// if (result == MessageDialog.OK_RETURN_CODE) -// { -// this.login(protocolProvider); -// } -// -// logger.trace(evt.getReason()); -// } - else if (newState.equals(RegistrationState.EXPIRED)) - { - String msgText = GuiActivator.getResources().getI18NString( - "service.gui.CONNECTION_EXPIRED_MSG", - new String[] - { protocolProvider.getProtocolDisplayName() }); - - new ErrorDialog(null, - GuiActivator.getResources().getI18NString("service.gui.ERROR"), - msgText).showDialog(); - - logger.error(evt.getReason()); - } - else if (newState.equals(RegistrationState.UNREGISTERED)) - { - if (!manuallyDisconnected) - { - if (evt.getReasonCode() == RegistrationStateChangeEvent - .REASON_MULTIPLE_LOGINS) - { - String msgText = GuiActivator.getResources().getI18NString( - "service.gui.MULTIPLE_LOGINS", - new String[] - { accountID.getUserID(), accountID.getService() }); - - new ErrorDialog(null, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - msgText).showDialog(); - } - else if (evt.getReasonCode() == RegistrationStateChangeEvent - .REASON_CLIENT_LIMIT_REACHED_FOR_IP) - { - String msgText = GuiActivator.getResources().getI18NString( - "service.gui.LIMIT_REACHED_FOR_IP", new String[] - { protocolProvider.getProtocolDisplayName() }); - - new ErrorDialog(null, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - msgText).showDialog(); - } - else if (evt.getReasonCode() == RegistrationStateChangeEvent - .REASON_USER_REQUEST) - { - // do nothing - } - else - { - String msgText = GuiActivator.getResources().getI18NString( - "service.gui.UNREGISTERED_MESSAGE", new String[] - { accountID.getUserID(), accountID.getService() }); - - new ErrorDialog(null, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - msgText).showDialog(); - } - if (logger.isTraceEnabled()) - logger.trace(evt.getReason()); - } - } - } - - /** - * Implements the <tt>ServiceListener</tt> method. Verifies whether the - * passed event concerns a <tt>ProtocolProviderService</tt> and adds the - * corresponding UI controls. - * - * @param event The <tt>ServiceEvent</tt> object. - */ - public void serviceChanged(ServiceEvent event) - { - ServiceReference serviceRef = event.getServiceReference(); - - // if the event is caused by a bundle being stopped, we don't want to - // know - if (serviceRef.getBundle().getState() == Bundle.STOPPING) - { - return; - } - - Object service = GuiActivator.bundleContext.getService(serviceRef); - - // we don't care if the source service is not a protocol provider - if (!(service instanceof ProtocolProviderService)) - { - return; - } - - switch (event.getType()) - { - case ServiceEvent.REGISTERED: - this.handleProviderAdded((ProtocolProviderService) service); - break; - case ServiceEvent.UNREGISTERING: - this.handleProviderRemoved((ProtocolProviderService) service); - break; - } - } - - /** - * Adds all UI components (status selector box, etc) related to the given - * protocol provider. - * - * @param protocolProvider the <tt>ProtocolProviderService</tt> - */ - private void handleProviderAdded(ProtocolProviderService protocolProvider) - { - if (logger.isTraceEnabled()) - logger.trace("The following protocol provider was just added: " - + protocolProvider.getAccountID().getAccountAddress()); - - protocolProvider.addRegistrationStateChangeListener(this); - this.mainFrame.addProtocolProvider(protocolProvider); - - Object status = this.mainFrame - .getProtocolProviderLastStatus(protocolProvider); - - if (status == null - || status.equals(GlobalStatusEnum.ONLINE_STATUS) - || ((status instanceof PresenceStatus) && (((PresenceStatus) status) - .getStatus() >= PresenceStatus.ONLINE_THRESHOLD))) - { - this.login(protocolProvider); - } - } - - /** - * Removes all UI components related to the given protocol provider. - * - * @param protocolProvider the <tt>ProtocolProviderService</tt> - */ - private void handleProviderRemoved(ProtocolProviderService protocolProvider) - { - this.mainFrame.removeProtocolProvider(protocolProvider); - } - - public boolean isManuallyDisconnected() - { - return manuallyDisconnected; - } - - public void setManuallyDisconnected(boolean manuallyDisconnected) - { - this.manuallyDisconnected = manuallyDisconnected; - } - - /** - * Registers a protocol provider in a separate thread. - */ - private class RegisterProvider - extends Thread - { - private final ProtocolProviderService protocolProvider; - - private final SecurityAuthority secAuth; - - RegisterProvider(ProtocolProviderService protocolProvider, - SecurityAuthority secAuth) - { - this.protocolProvider = protocolProvider; - this.secAuth = secAuth; - } - - /** - * Registers the contained protocol provider and process all possible - * errors that may occur during the registration process. - */ - public void run() - { - try - { - protocolProvider.register(secAuth); - } - catch (OperationFailedException ex) - { - handleOperationFailedException(ex); - } - catch (Throwable ex) - { - logger.error("Failed to register protocol provider. ", ex); - - AccountID accountID = protocolProvider.getAccountID(); - new ErrorDialog( - mainFrame, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - GuiActivator.getResources() - .getI18NString("service.gui.LOGIN_GENERAL_ERROR", - new String[] - { accountID.getUserID(), - accountID.getProtocolName(), - accountID.getService() })) - .showDialog(); - } - } - - private void handleOperationFailedException(OperationFailedException ex) - { - String errorMessage = ""; - - switch (ex.getErrorCode()) - { - case OperationFailedException.GENERAL_ERROR: - { - logger.error("Provider could not be registered" - + " due to the following general error: ", ex); - - AccountID accountID = protocolProvider.getAccountID(); - errorMessage = - GuiActivator.getResources().getI18NString( - "service.gui.LOGIN_GENERAL_ERROR", - new String[] - { accountID.getUserID(), - accountID.getProtocolName(), - accountID.getService() }); - - new ErrorDialog(mainFrame, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), errorMessage, ex) - .showDialog(); - } - break; - case OperationFailedException.INTERNAL_ERROR: - { - logger.error("Provider could not be registered" - + " due to the following internal error: ", ex); - - AccountID accountID = protocolProvider.getAccountID(); - errorMessage = - GuiActivator.getResources().getI18NString( - "service.gui.LOGIN_INTERNAL_ERROR", - new String[] - { accountID.getUserID(), accountID.getService() }); - - new ErrorDialog(mainFrame, - GuiActivator.getResources().getI18NString( - "service.gui.ERROR"), errorMessage, ex).showDialog(); - } - break; - case OperationFailedException.NETWORK_FAILURE: - { - if (logger.isInfoEnabled()) - { - logger.info("Provider could not be registered" - + " due to a network failure: " + ex); - } - - AccountID accountID = protocolProvider.getAccountID(); - errorMessage = GuiActivator.getResources().getI18NString( - "service.gui.LOGIN_NETWORK_ERROR", - new String[] - { accountID.getUserID(), accountID.getService() }); - - int result = - new MessageDialog( - null, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - errorMessage, - GuiActivator.getResources() - .getI18NString("service.gui.RETRY"), false) - .showDialog(); - - if (result == MessageDialog.OK_RETURN_CODE) - { - login(protocolProvider); - } - } - break; - case OperationFailedException.INVALID_ACCOUNT_PROPERTIES: - { - logger.error("Provider could not be registered" - + " due to an invalid account property: ", ex); - - AccountID accountID = protocolProvider.getAccountID(); - errorMessage = - GuiActivator.getResources().getI18NString( - "service.gui.LOGIN_INVALID_PROPERTIES_ERROR", - new String[] - { accountID.getUserID(), accountID.getService() }); - - new ErrorDialog(mainFrame, - GuiActivator.getResources().getI18NString("service.gui.ERROR"), - errorMessage, ex).showDialog(); - } - break; - default: - logger.error("Provider could not be registered.", ex); - } - } - } - - /** - * Unregisters a protocol provider in a separate thread. - */ - private class UnregisterProvider - extends Thread - { - ProtocolProviderService protocolProvider; - - UnregisterProvider(ProtocolProviderService protocolProvider) - { - this.protocolProvider = protocolProvider; - } - - /** - * Unregisters the contained protocol provider and process all possible - * errors that may occur during the un-registration process. - */ - public void run() - { - try - { - protocolProvider.unregister(); - } - catch (OperationFailedException ex) - { - int errorCode = ex.getErrorCode(); - - if (errorCode == OperationFailedException.GENERAL_ERROR) - { - logger.error("Provider could not be unregistered" - + " due to the following general error: " + ex); - } - else if (errorCode == OperationFailedException.INTERNAL_ERROR) - { - logger.error("Provider could not be unregistered" - + " due to the following internal error: " + ex); - } - else if (errorCode == OperationFailedException.NETWORK_FAILURE) - { - logger.error("Provider could not be unregistered" - + " due to a network failure: " + ex); - } - - new ErrorDialog(mainFrame, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - GuiActivator.getResources() - .getI18NString("service.gui.LOGOFF_NOT_SUCCEEDED", - new String[] - { protocolProvider.getAccountID().getUserID(), - protocolProvider.getAccountID().getService() })) - .showDialog(); - } - } - } -} +/*
+ * 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.util.account;
+
+import net.java.sip.communicator.service.protocol.*;
+import net.java.sip.communicator.service.protocol.event.*;
+import net.java.sip.communicator.service.protocol.globalstatus.*;
+import net.java.sip.communicator.util.*;
+
+import org.osgi.framework.*;
+
+/**
+ * The <tt>LoginManager</tt> manages the login operation. Here we obtain the
+ * <tt>ProtocolProviderFactory</tt>, we make the account installation and we
+ * handle all events related to the registration state.
+ * <p>
+ * The <tt>LoginManager</tt> is the one that opens one or more
+ * <tt>LoginWindow</tt>s for each <tt>ProtocolProviderFactory</tt>. The
+ * <tt>LoginWindow</tt> is where user could enter an identifier and password.
+ * <p>
+ * Note that the behavior of this class will be changed when the Configuration
+ * Service is ready.
+ *
+ * @author Yana Stamcheva
+ */
+public class LoginManager
+ implements ServiceListener,
+ RegistrationStateChangeListener,
+ AccountManagerListener
+{
+ private static final Logger logger = Logger.getLogger(LoginManager.class);
+
+ private boolean manuallyDisconnected = false;
+
+ private final LoginRenderer loginRenderer;
+
+ /**
+ * Creates an instance of the <tt>LoginManager</tt>, by specifying the main
+ * application window.
+ *
+ * @param loginRenderer the main application window
+ */
+ public LoginManager(LoginRenderer loginRenderer)
+ {
+ this.loginRenderer = loginRenderer;
+
+ UtilActivator.bundleContext.addServiceListener(this);
+ }
+
+ /**
+ * Registers the given protocol provider.
+ *
+ * @param protocolProvider the ProtocolProviderService to register.
+ */
+ public void login(ProtocolProviderService protocolProvider)
+ {
+ loginRenderer.startConnectingUI(protocolProvider);
+
+ new RegisterProvider(protocolProvider,
+ loginRenderer.getSecurityAuthorityImpl(protocolProvider)).start();
+ }
+
+ /**
+ * Unregisters the given protocol provider.
+ *
+ * @param protocolProvider the ProtocolProviderService to unregister
+ */
+ public static void logoff(ProtocolProviderService protocolProvider)
+ {
+ new UnregisterProvider(protocolProvider).start();
+ }
+
+ /**
+ * Shows login window for each registered account.
+ */
+ public void runLogin()
+ {
+ // if someone is late registering catch it
+ UtilActivator.getAccountManager().addListener(this);
+
+ for (ProtocolProviderFactory providerFactory : UtilActivator
+ .getProtocolProviderFactories().values())
+ {
+ addAccountsForProtocolProviderFactory(providerFactory);
+ }
+ }
+
+ /**
+ * Notifies that the loading of the stored accounts of a
+ * specific <code>ProtocolProviderFactory</code> has finished.
+ *
+ * @param event the <code>AccountManagerEvent</code> describing the
+ * <code>AccountManager</code> firing the notification and the
+ * other details of the specific notification.
+ */
+ public void handleAccountManagerEvent(AccountManagerEvent event)
+ {
+ if(event.getType()
+ == AccountManagerEvent.STORED_ACCOUNTS_LOADED)
+ {
+ addAccountsForProtocolProviderFactory(event.getFactory());
+ }
+ }
+
+ /**
+ * Handles stored accounts for a protocol provider factory and add them
+ * to the UI and register them if needed.
+ * @param providerFactory the factory to handle.
+ */
+ private void addAccountsForProtocolProviderFactory(
+ ProtocolProviderFactory providerFactory)
+ {
+ ServiceReference serRef;
+ ProtocolProviderService protocolProvider;
+
+ for (AccountID accountID : providerFactory.getRegisteredAccounts())
+ {
+ serRef = providerFactory.getProviderForAccount(accountID);
+
+ protocolProvider =
+ (ProtocolProviderService) UtilActivator.bundleContext
+ .getService(serRef);
+
+ // check whether we have already loaded this provider
+ if(loginRenderer.containsProtocolProviderUI(protocolProvider))
+ continue;
+
+ protocolProvider.addRegistrationStateChangeListener(this);
+
+ loginRenderer.addProtocolProviderUI(protocolProvider);
+
+ Object status =
+ AccountStatusUtils
+ .getProtocolProviderLastStatus(protocolProvider);
+
+ if (status == null
+ || status.equals(GlobalStatusEnum.ONLINE_STATUS)
+ || ((status instanceof PresenceStatus)
+ && (((PresenceStatus) status)
+ .getStatus() >= PresenceStatus.ONLINE_THRESHOLD)))
+ {
+ login(protocolProvider);
+ }
+ }
+ }
+
+ /**
+ * The method is called by a ProtocolProvider implementation whenever a
+ * change in the registration state of the corresponding provider had
+ * occurred.
+ *
+ * @param evt ProviderStatusChangeEvent the event describing the status
+ * change.
+ */
+ public void registrationStateChanged(RegistrationStateChangeEvent evt)
+ {
+ RegistrationState newState = evt.getNewState();
+ ProtocolProviderService protocolProvider = evt.getProvider();
+ AccountID accountID = protocolProvider.getAccountID();
+
+ if (logger.isTraceEnabled())
+ logger.trace("Protocol provider: " + protocolProvider
+ + " changed its state to: " + evt.getNewState().getStateName());
+
+ if (newState.equals(RegistrationState.REGISTERED)
+ || newState.equals(RegistrationState.UNREGISTERED)
+ || newState.equals(RegistrationState.EXPIRED)
+ || newState.equals(RegistrationState.AUTHENTICATION_FAILED)
+ || newState.equals(RegistrationState.CONNECTION_FAILED)
+ || newState.equals(RegistrationState.CHALLENGED_FOR_AUTHENTICATION)
+ || newState.equals(RegistrationState.REGISTERED))
+ {
+ loginRenderer.stopConnectingUI(protocolProvider);
+ }
+
+ if (newState.equals(RegistrationState.REGISTERED))
+ {
+ loginRenderer.protocolProviderConnected(protocolProvider,
+ System.currentTimeMillis());
+ }
+ else
+ {
+ String msgText;
+ if (newState.equals(RegistrationState.AUTHENTICATION_FAILED))
+ {
+ switch (evt.getReasonCode())
+ {
+ case RegistrationStateChangeEvent
+ .REASON_RECONNECTION_RATE_LIMIT_EXCEEDED:
+
+ msgText = UtilActivator.getResources().getI18NString(
+ "service.gui.RECONNECTION_LIMIT_EXCEEDED", new String[]
+ { accountID.getUserID(), accountID.getService() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ msgText);
+ break;
+
+ case RegistrationStateChangeEvent.REASON_NON_EXISTING_USER_ID:
+ msgText = UtilActivator.getResources().getI18NString(
+ "service.gui.NON_EXISTING_USER_ID",
+ new String[]
+ { protocolProvider.getProtocolDisplayName() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ msgText);
+ break;
+ case RegistrationStateChangeEvent.REASON_TLS_REQUIRED:
+ msgText = UtilActivator.getResources().getI18NString(
+ "service.gui.NON_SECURE_CONNECTION",
+ new String[]
+ { accountID.getAccountAddress() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ msgText);
+ break;
+ default:
+ break;
+ }
+
+ if (logger.isTraceEnabled())
+ logger.trace(evt.getReason());
+ }
+// CONNECTION_FAILED events are now dispatched in reconnect plugin
+// else if (newState.equals(RegistrationState.CONNECTION_FAILED))
+// {
+// loginRenderer.protocolProviderConnectionFailed(
+// protocolProvider,
+// this);
+//
+// logger.trace(evt.getReason());
+// }
+ else if (newState.equals(RegistrationState.EXPIRED))
+ {
+ msgText = UtilActivator.getResources().getI18NString(
+ "service.gui.CONNECTION_EXPIRED_MSG",
+ new String[]
+ { protocolProvider.getProtocolDisplayName() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ msgText);
+
+ logger.error(evt.getReason());
+ }
+ else if (newState.equals(RegistrationState.UNREGISTERED))
+ {
+ if (!manuallyDisconnected)
+ {
+ if (evt.getReasonCode() == RegistrationStateChangeEvent
+ .REASON_MULTIPLE_LOGINS)
+ {
+ msgText = UtilActivator.getResources().getI18NString(
+ "service.gui.MULTIPLE_LOGINS",
+ new String[]
+ { accountID.getUserID(), accountID.getService() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ msgText);
+ }
+ else if (evt.getReasonCode() == RegistrationStateChangeEvent
+ .REASON_CLIENT_LIMIT_REACHED_FOR_IP)
+ {
+ msgText = UtilActivator.getResources().getI18NString(
+ "service.gui.LIMIT_REACHED_FOR_IP", new String[]
+ { protocolProvider.getProtocolDisplayName() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ msgText);
+ }
+ else if (evt.getReasonCode() == RegistrationStateChangeEvent
+ .REASON_USER_REQUEST)
+ {
+ // do nothing
+ }
+ else
+ {
+ msgText = UtilActivator.getResources().getI18NString(
+ "service.gui.UNREGISTERED_MESSAGE", new String[]
+ { accountID.getUserID(), accountID.getService() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ msgText);
+ }
+ if (logger.isTraceEnabled())
+ logger.trace(evt.getReason());
+ }
+ }
+ }
+ }
+
+ /**
+ * Implements the <tt>ServiceListener</tt> method. Verifies whether the
+ * passed event concerns a <tt>ProtocolProviderService</tt> and adds the
+ * corresponding UI controls.
+ *
+ * @param event The <tt>ServiceEvent</tt> object.
+ */
+ public void serviceChanged(ServiceEvent event)
+ {
+ ServiceReference serviceRef = event.getServiceReference();
+
+ // if the event is caused by a bundle being stopped, we don't want to
+ // know
+ if (serviceRef.getBundle().getState() == Bundle.STOPPING)
+ {
+ return;
+ }
+
+ Object service
+ = UtilActivator.bundleContext.getService(serviceRef);
+
+ // we don't care if the source service is not a protocol provider
+ if (!(service instanceof ProtocolProviderService))
+ {
+ return;
+ }
+
+ switch (event.getType())
+ {
+ case ServiceEvent.REGISTERED:
+ this.handleProviderAdded((ProtocolProviderService) service);
+ break;
+ case ServiceEvent.UNREGISTERING:
+ this.handleProviderRemoved((ProtocolProviderService) service);
+ break;
+ }
+ }
+
+ /**
+ * Adds all UI components (status selector box, etc) related to the given
+ * protocol provider.
+ *
+ * @param protocolProvider the <tt>ProtocolProviderService</tt>
+ */
+ private void handleProviderAdded(ProtocolProviderService protocolProvider)
+ {
+ if (logger.isTraceEnabled())
+ logger.trace("The following protocol provider was just added: "
+ + protocolProvider.getAccountID().getAccountAddress());
+
+ protocolProvider.addRegistrationStateChangeListener(this);
+ loginRenderer.addProtocolProviderUI(protocolProvider);
+
+ Object status = AccountStatusUtils
+ .getProtocolProviderLastStatus(protocolProvider);
+
+ if (status == null
+ || status.equals(GlobalStatusEnum.ONLINE_STATUS)
+ || ((status instanceof PresenceStatus) && (((PresenceStatus) status)
+ .getStatus() >= PresenceStatus.ONLINE_THRESHOLD)))
+ {
+ login(protocolProvider);
+ }
+ }
+
+ /**
+ * Removes all UI components related to the given protocol provider.
+ *
+ * @param protocolProvider the <tt>ProtocolProviderService</tt>
+ */
+ private void handleProviderRemoved(ProtocolProviderService protocolProvider)
+ {
+ loginRenderer.removeProtocolProviderUI(protocolProvider);
+ }
+
+ /**
+ * Returns <tt>true</tt> to indicate the jitsi has been manually
+ * disconnected, <tt>false</tt> - otherwise.
+ *
+ * @return <tt>true</tt> to indicate the jitsi has been manually
+ * disconnected, <tt>false</tt> - otherwise
+ */
+ public boolean isManuallyDisconnected()
+ {
+ return manuallyDisconnected;
+ }
+
+ /**
+ * Sets the manually disconnected property.
+ *
+ * @param manuallyDisconnected <tt>true</tt> to indicate the jitsi has been
+ * manually disconnected, <tt>false</tt> - otherwise
+ */
+ public void setManuallyDisconnected(boolean manuallyDisconnected)
+ {
+ this.manuallyDisconnected = manuallyDisconnected;
+ }
+
+ /**
+ * Registers a protocol provider in a separate thread.
+ */
+ private class RegisterProvider
+ extends Thread
+ {
+ private final ProtocolProviderService protocolProvider;
+
+ private final SecurityAuthority secAuth;
+
+ RegisterProvider( ProtocolProviderService protocolProvider,
+ SecurityAuthority secAuth)
+ {
+ this.protocolProvider = protocolProvider;
+ this.secAuth = secAuth;
+ }
+
+ /**
+ * Registers the contained protocol provider and process all possible
+ * errors that may occur during the registration process.
+ */
+ public void run()
+ {
+ try
+ {
+ protocolProvider.register(secAuth);
+ }
+ catch (OperationFailedException ex)
+ {
+ handleOperationFailedException(ex);
+ }
+ catch (Throwable ex)
+ {
+ logger.error("Failed to register protocol provider. ", ex);
+
+ AccountID accountID = protocolProvider.getAccountID();
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ UtilActivator.getResources()
+ .getI18NString("service.gui.LOGIN_GENERAL_ERROR",
+ new String[]
+ { accountID.getUserID(),
+ accountID.getProtocolName(),
+ accountID.getService() }));
+ }
+ }
+
+ private void handleOperationFailedException(OperationFailedException ex)
+ {
+ String errorMessage = "";
+
+ switch (ex.getErrorCode())
+ {
+ case OperationFailedException.GENERAL_ERROR:
+ {
+ logger.error("Provider could not be registered"
+ + " due to the following general error: ", ex);
+
+ AccountID accountID = protocolProvider.getAccountID();
+ errorMessage =
+ UtilActivator.getResources().getI18NString(
+ "service.gui.LOGIN_GENERAL_ERROR",
+ new String[]
+ { accountID.getUserID(),
+ accountID.getProtocolName(),
+ accountID.getService() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"), errorMessage, ex);
+ }
+ break;
+ case OperationFailedException.INTERNAL_ERROR:
+ {
+ logger.error("Provider could not be registered"
+ + " due to the following internal error: ", ex);
+
+ AccountID accountID = protocolProvider.getAccountID();
+ errorMessage =
+ UtilActivator.getResources().getI18NString(
+ "service.gui.LOGIN_INTERNAL_ERROR",
+ new String[]
+ { accountID.getUserID(), accountID.getService() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources().getI18NString(
+ "service.gui.ERROR"), errorMessage, ex);
+ }
+ break;
+ case OperationFailedException.NETWORK_FAILURE:
+ {
+ if (logger.isInfoEnabled())
+ {
+ logger.info("Provider could not be registered"
+ + " due to a network failure: " + ex);
+ }
+
+ loginRenderer.protocolProviderConnectionFailed(
+ protocolProvider,
+ LoginManager.this);
+ }
+ break;
+ case OperationFailedException.INVALID_ACCOUNT_PROPERTIES:
+ {
+ logger.error("Provider could not be registered"
+ + " due to an invalid account property: ", ex);
+
+ AccountID accountID = protocolProvider.getAccountID();
+ errorMessage =
+ UtilActivator.getResources().getI18NString(
+ "service.gui.LOGIN_INVALID_PROPERTIES_ERROR",
+ new String[]
+ { accountID.getUserID(), accountID.getService() });
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ errorMessage, ex);
+ }
+ break;
+ default:
+ logger.error("Provider could not be registered.", ex);
+ }
+ }
+ }
+
+ /**
+ * Unregisters a protocol provider in a separate thread.
+ */
+ private static class UnregisterProvider
+ extends Thread
+ {
+ ProtocolProviderService protocolProvider;
+
+ UnregisterProvider(ProtocolProviderService protocolProvider)
+ {
+ this.protocolProvider = protocolProvider;
+ }
+
+ /**
+ * Unregisters the contained protocol provider and process all possible
+ * errors that may occur during the un-registration process.
+ */
+ public void run()
+ {
+ try
+ {
+ protocolProvider.unregister();
+ }
+ catch (OperationFailedException ex)
+ {
+ int errorCode = ex.getErrorCode();
+
+ if (errorCode == OperationFailedException.GENERAL_ERROR)
+ {
+ logger.error("Provider could not be unregistered"
+ + " due to the following general error: " + ex);
+ }
+ else if (errorCode == OperationFailedException.INTERNAL_ERROR)
+ {
+ logger.error("Provider could not be unregistered"
+ + " due to the following internal error: " + ex);
+ }
+ else if (errorCode == OperationFailedException.NETWORK_FAILURE)
+ {
+ logger.error("Provider could not be unregistered"
+ + " due to a network failure: " + ex);
+ }
+
+ UtilActivator.getAlertUIService().showAlertDialog(
+ UtilActivator.getResources()
+ .getI18NString("service.gui.ERROR"),
+ UtilActivator.getResources()
+ .getI18NString("service.gui.LOGOFF_NOT_SUCCEEDED",
+ new String[]
+ { protocolProvider.getAccountID().getUserID(),
+ protocolProvider.getAccountID().getService() }));
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/util/account/LoginRenderer.java b/src/net/java/sip/communicator/util/account/LoginRenderer.java new file mode 100644 index 0000000..9806ff1 --- /dev/null +++ b/src/net/java/sip/communicator/util/account/LoginRenderer.java @@ -0,0 +1,97 @@ +/*
+ * 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.util.account;
+
+import net.java.sip.communicator.service.protocol.*;
+
+/**
+ * The <tt>LoginRenderer</tt> is the renderer of all login related operations.
+ *
+ * @author Yana Stamcheva
+ */
+public interface LoginRenderer
+{
+ /**
+ * Adds the user interface related to the given protocol provider.
+ *
+ * @param protocolProvider the protocol provider for which we add the user
+ * interface
+ */
+ public void addProtocolProviderUI(
+ ProtocolProviderService protocolProvider);
+
+ /**
+ * Removes the user interface related to the given protocol provider.
+ *
+ * @param protocolProvider the protocol provider to remove
+ */
+ public void removeProtocolProviderUI(
+ ProtocolProviderService protocolProvider);
+
+ /**
+ * Starts the connecting user interface for the given protocol provider.
+ *
+ * @param protocolProvider the protocol provider for which we add the
+ * connecting user interface
+ */
+ public void startConnectingUI(ProtocolProviderService protocolProvider);
+
+ /**
+ * Stops the connecting user interface for the given protocol provider.
+ *
+ * @param protocolProvider the protocol provider for which we remove the
+ * connecting user interface
+ */
+ public void stopConnectingUI(ProtocolProviderService protocolProvider);
+
+ /**
+ * Indicates that the given protocol provider is now connected.
+ *
+ * @param protocolProvider the <tt>ProtocolProviderService</tt> that is
+ * connected
+ * @param date the date on which the event occured
+ */
+ public void protocolProviderConnected(
+ ProtocolProviderService protocolProvider,
+ long date);
+
+ /**
+ * Indicates that a protocol provider connection has failed.
+ *
+ * @param protocolProvider the <tt>ProtocolProviderService</tt>, which
+ * connection failed
+ * @param loginManagerCallback the <tt>LoginManager</tt> implementation,
+ * which is managing the process
+ */
+ public void protocolProviderConnectionFailed(
+ ProtocolProviderService protocolProvider,
+ LoginManager loginManagerCallback);
+
+ /**
+ * Returns the <tt>SecurityAuthority</tt> implementation related to this
+ * login renderer.
+ *
+ * @param protocolProvider the specific <tt>ProtocolProviderService</tt>,
+ * for which we're obtaining a security authority
+ * @return the <tt>SecurityAuthority</tt> implementation related to this
+ * login renderer
+ */
+ public SecurityAuthority getSecurityAuthorityImpl(
+ ProtocolProviderService protocolProvider);
+
+ /**
+ * Indicates if the given <tt>protocolProvider</tt> related user interface
+ * is already rendered.
+ *
+ * @param protocolProvider the <tt>ProtocolProviderService</tt>, which
+ * related user interface we're looking for
+ * @return <tt>true</tt> if the given <tt>protocolProvider</tt> related user
+ * interface is already rendered
+ */
+ public boolean containsProtocolProviderUI(
+ ProtocolProviderService protocolProvider);
+}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/util/util.manifest.mf b/src/net/java/sip/communicator/util/util.manifest.mf index 0d7de8f..54512ed 100644 --- a/src/net/java/sip/communicator/util/util.manifest.mf +++ b/src/net/java/sip/communicator/util/util.manifest.mf @@ -38,6 +38,8 @@ Import-Package: com.sun.awt, net.java.sip.communicator.service.contactlist, net.java.sip.communicator.service.browserlauncher, net.java.sip.communicator.service.protocol, + net.java.sip.communicator.service.protocol.event, + net.java.sip.communicator.service.protocol.globalstatus, net.java.sip.communicator.service.dns, org.apache.xml.serialize, org.jitsi.service.configuration, |