diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index 2d1749f79..7aed75795 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -932,4 +932,7 @@ plugin.globalproxy.PROTOCOL_SUPPORT= \ \ \ \ -
MSN++--
JABBER++++
ICQ/AIM++++
\ No newline at end of file +NotificationService obtained from the bundle context. * @@ -254,7 +316,7 @@ public void serviceChanged(ServiceEvent serviceEvent) ServiceReference serviceRef = serviceEvent.getServiceReference(); // if the event is caused by a bundle being stopped, we don't want to - // know + // know we are shutting down if (serviceRef.getBundle().getState() == Bundle.STOPPING) { return; @@ -311,24 +373,37 @@ public void serviceChanged(ServiceEvent serviceEvent) */ private void handleProviderAdded(ProtocolProviderService provider) { - logger.debug("Adding protocol provider " + provider.getProtocolName()); + logger.trace("New protocol provider is comming " + + provider.getProtocolName()); - if(provider instanceof ProtocolProviderService) - { - provider.addRegistrationStateChangeListener(this); - } + provider.addRegistrationStateChangeListener(this); } /** * Stop listening for events as the provider is removed. + * Providers are removed this way only when there are modified + * in the configuration. So as the provider is modified we will erase + * every instance we got. * * @param provider the ProtocolProviderService that has been unregistered. */ private void handleProviderRemoved(ProtocolProviderService provider) { - if(provider instanceof ProtocolProviderService) + logger.trace("Provider modified forget every instance of it"); + + if(hasAtLeastOneSuccessfulConnection(provider)) + { + setAtLeastOneSuccessfulConnection(provider, false); + } + + provider.removeRegistrationStateChangeListener(this); + + autoReconnEnabledProviders.remove(provider); + needsReconnection.remove(provider); + + if(currentlyReconnecting.containsKey(provider)) { - provider.removeRegistrationStateChangeListener(this); + currentlyReconnecting.remove(provider).cancel(); } } @@ -452,6 +527,25 @@ public synchronized void registrationStateChanged(RegistrationStateChangeEvent e if(evt.getNewState().equals(RegistrationState.CONNECTION_FAILED)) { + if(!hasAtLeastOneSuccessfulConnection(pp)) + { + // ignore providers which haven't registered successfully + // till now, they maybe misconfigured + // todo show dialog + String msgText = getResources().getI18NString( + "plugin.reconnectplugin.CONNECTION_FAILED_MSG", + new String[] + { pp.getAccountID().getUserID(), + pp.getAccountID().getService() }); + + getUIService().getPopupDialog().showMessagePopupDialog( + msgText, + getResources().getI18NString("service.gui.ERROR"), + PopupDialog.ERROR_MESSAGE); + + return; + } + // if this pp is already in needsReconnection, it means // we got conn failed cause the pp has tried to unregister // with sending network packet @@ -474,16 +568,20 @@ public synchronized void registrationStateChanged(RegistrationStateChangeEvent e } else if(evt.getNewState().equals(RegistrationState.REGISTERED)) { + if(!hasAtLeastOneSuccessfulConnection(pp)) + { + setAtLeastOneSuccessfulConnection(pp, true); + } + autoReconnEnabledProviders.put( - (ProtocolProviderService)evt.getSource(), + pp, new ArrayList(connectedInterfaces)); currentlyReconnecting.remove(pp); } else if(evt.getNewState().equals(RegistrationState.UNREGISTERED)) { - autoReconnEnabledProviders.remove( - (ProtocolProviderService)evt.getSource()); + autoReconnEnabledProviders.remove(pp); if(!unregisteredProviders.contains(pp) && currentlyReconnecting.containsKey(pp)) @@ -578,4 +676,36 @@ public void run() } } } + + /** + * Check does the supplied protocol has the property set for at least + * one successful connection. + * @param pp the protocol provider + * @return true if property exists. + */ + private boolean hasAtLeastOneSuccessfulConnection(ProtocolProviderService pp) + { + String value = (String)getConfigurationService().getProperty( + ATLEAST_ONE_CONNECTION_PROP + "." + + pp.getAccountID().getAccountUniqueID()); + + if(value == null || !value.equals(Boolean.TRUE.toString())) + return false; + else + return true; + } + + /** + * Changes the property about at least one successful connection. + * @param pp the protocol provider + * @param value the new value true or false. + */ + private void setAtLeastOneSuccessfulConnection( + ProtocolProviderService pp, boolean value) + { + getConfigurationService().setProperty( + ATLEAST_ONE_CONNECTION_PROP + "." + + pp.getAccountID().getAccountUniqueID(), + Boolean.valueOf(value).toString()); + } }