diff options
author | Damian Minkov <damencho@jitsi.org> | 2014-03-14 16:59:32 +0200 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2014-03-14 17:02:18 +0200 |
commit | 0bf621360b14a0060a4cded64d3168ed95394524 (patch) | |
tree | 298a611156aaa3c33c5af3d97937c6639fa0bb94 /src/net/java/sip/communicator | |
parent | ac886ebbed3606140f5ec7806399558a48345c30 (diff) | |
download | jitsi-0bf621360b14a0060a4cded64d3168ed95394524.zip jitsi-0bf621360b14a0060a4cded64d3168ed95394524.tar.gz jitsi-0bf621360b14a0060a4cded64d3168ed95394524.tar.bz2 |
Fixes initial status set for protocols and UI to reflect changes.
Diffstat (limited to 'src/net/java/sip/communicator')
8 files changed, 152 insertions, 87 deletions
diff --git a/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalDisplayDetailsActivator.java b/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalDisplayDetailsActivator.java index 55dc3df..8b5a3d1 100644 --- a/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalDisplayDetailsActivator.java +++ b/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalDisplayDetailsActivator.java @@ -54,6 +54,8 @@ public class GlobalDisplayDetailsActivator */ static GlobalDisplayDetailsImpl displayDetailsImpl; + static GlobalStatusServiceImpl globalStatusService; + /** * Initialize and start file service * @@ -74,9 +76,10 @@ public class GlobalDisplayDetailsActivator displayDetailsImpl, null); + globalStatusService = new GlobalStatusServiceImpl(); bundleContext.registerService( GlobalStatusService.class.getName(), - new GlobalStatusServiceImpl(), + globalStatusService, null); } @@ -191,15 +194,17 @@ public class GlobalDisplayDetailsActivator return; } + ProtocolProviderService pps = (ProtocolProviderService) service; + switch (event.getType()) { case ServiceEvent.REGISTERED: - ((ProtocolProviderService) service) - .addRegistrationStateChangeListener(displayDetailsImpl); + pps.addRegistrationStateChangeListener(displayDetailsImpl); + pps.addRegistrationStateChangeListener(globalStatusService); break; case ServiceEvent.UNREGISTERING: - ((ProtocolProviderService) service) - .removeRegistrationStateChangeListener(displayDetailsImpl); + pps.removeRegistrationStateChangeListener(displayDetailsImpl); + pps.removeRegistrationStateChangeListener(globalStatusService); break; } } diff --git a/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java b/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java index 7ee00ad..349f88d 100644 --- a/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java +++ b/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java @@ -6,6 +6,7 @@ package net.java.sip.communicator.impl.globaldisplaydetails; 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 net.java.sip.communicator.util.account.*; @@ -22,7 +23,8 @@ import java.util.*; * @author Damian Minkov */ public class GlobalStatusServiceImpl - implements GlobalStatusService + implements GlobalStatusService, + RegistrationStateChangeListener { /** * The object used for logging. @@ -627,6 +629,34 @@ public class GlobalStatusServiceImpl } /** + * Waits for providers to register and then checks for its last status + * saved if any and used it to restore its status. + * @param evt a <tt>RegistrationStateChangeEvent</tt> which describes the + */ + @Override + public void registrationStateChanged(RegistrationStateChangeEvent evt) + { + if(!evt.getNewState().equals(RegistrationState.REGISTERED)) + return; + + ProtocolProviderService pps = evt.getProvider(); + + PresenceStatus status = getLastPresenceStatus(pps); + + if(status == null) + { + // lets publish just online + status = AccountStatusUtils.getOnlineStatus(pps); + } + + if (status != null + && status.getStatus() >= PresenceStatus.ONLINE_THRESHOLD) + { + publishStatus(pps, status); + } + } + + /** * Publishes the given status to the given presence operation set. */ private class PublishPresenceStatusThread 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 3a424bd..3325ca3 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 @@ -369,17 +369,18 @@ public class GlobalStatusSelectorBox if (accountMenu == null) return; - PresenceStatus presenceStatus; + PresenceStatus presenceStatus; - if (!protocolProvider.isRegistered()) - presenceStatus = accountMenu.getOfflineStatus(); - else - { - presenceStatus - = AccountStatusUtils.getLastPresenceStatus(protocolProvider); - if (presenceStatus == null) - presenceStatus = accountMenu.getOnlineStatus(); - } + if (!protocolProvider.isRegistered()) + presenceStatus = accountMenu.getOfflineStatus(); + else + { + presenceStatus + = AccountStatusUtils.getPresenceStatus(protocolProvider); + + if (presenceStatus == null) + presenceStatus = accountMenu.getOnlineStatus(); + } accountMenu.updateStatus(presenceStatus); diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/ReadonlyStatusItem.java b/src/net/java/sip/communicator/impl/gui/main/presence/ReadonlyStatusItem.java index b899af3..453fb90 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/ReadonlyStatusItem.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/ReadonlyStatusItem.java @@ -74,29 +74,10 @@ public class ReadonlyStatusItem this.setToolTipText(tooltip); - OperationSetPresence presence - = protocolProvider.getOperationSet(OperationSetPresence.class); - - Iterator<PresenceStatus> statusIterator - = presence.getSupportedStatusSet(); - - while (statusIterator.hasNext()) - { - PresenceStatus status = statusIterator.next(); - int connectivity = status.getStatus(); - - if (connectivity < 1) - { - this.offlineStatus = status; - } - else if ((onlineStatus != null - && (onlineStatus.getStatus() < connectivity)) - || (onlineStatus == null - && (connectivity > 50 && connectivity < 80))) - { - this.onlineStatus = status; - } - } + this.offlineStatus + = AccountStatusUtils.getOfflineStatus(protocolProvider); + this.onlineStatus + = AccountStatusUtils.getOnlineStatus(protocolProvider); this.setSelectedStatus(offlineStatus); updateStatus(offlineStatus); diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/StatusSelectorMenu.java b/src/net/java/sip/communicator/impl/gui/main/presence/StatusSelectorMenu.java index b8800ca..dea782a 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/StatusSelectorMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/StatusSelectorMenu.java @@ -15,6 +15,7 @@ import javax.swing.*; import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.account.*; import net.java.sip.communicator.util.skin.*; /** @@ -89,29 +90,10 @@ public abstract class StatusSelectorMenu this.presence = protocolProvider.getOperationSet(OperationSetPresence.class); - // presence can be not supported - if(this.presence != null) - { - Iterator<PresenceStatus> statusIterator - = this.presence.getSupportedStatusSet(); - while (statusIterator.hasNext()) - { - PresenceStatus status = statusIterator.next(); - int connectivity = status.getStatus(); - - if (connectivity < 1) - { - this.offlineStatus = status; - } - else if ((onlineStatus != null - && (onlineStatus.getStatus() < connectivity)) - || (onlineStatus == null - && (connectivity > 50 && connectivity < 80))) - { - this.onlineStatus = status; - } - } - } + this.onlineStatus + = AccountStatusUtils.getOnlineStatus(protocolProvider); + this.offlineStatus + = AccountStatusUtils.getOfflineStatus(protocolProvider); loadSkin(); } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java index 060b41e..eed5270 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java @@ -912,12 +912,6 @@ public class OperationSetPersistentPresenceJabberImpl } else if(evt.getNewState() == RegistrationState.REGISTERED) { - fireProviderStatusChangeEvent( - currentStatus, - parentProvider - .getJabberStatusEnum() - .getStatus(JabberStatusEnum.AVAILABLE)); - createContactPhotoPresenceListener(); createAccountPhotoPresenceInterceptor(); } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java index 51bece0..4e465c9 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java @@ -1260,25 +1260,6 @@ public class ProtocolProviderServiceJabberImpl RegistrationState.REGISTERED,
RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, null);
- /* The initial presence message is sent by smack stack and does not
- * include priority information. In case the original status is
- * AVAILABLE, we will not update our presence information (such as
- * our priority) when we registered.
- */
- OperationSetPersistentPresenceJabberImpl opSet =
- (OperationSetPersistentPresenceJabberImpl)
- this.getOperationSet(OperationSetPersistentPresence.class);
-
- try
- {
- opSet.publishPresenceStatus(getJabberStatusEnum().getStatus(
- JabberStatusEnum.AVAILABLE), "");
- }
- catch(Exception e)
- {
- logger.error("Failed to publish presence status");
- }
-
return ConnectState.STOP_TRYING;
}
else
diff --git a/src/net/java/sip/communicator/util/account/AccountStatusUtils.java b/src/net/java/sip/communicator/util/account/AccountStatusUtils.java index bc32980..728fc83 100644 --- a/src/net/java/sip/communicator/util/account/AccountStatusUtils.java +++ b/src/net/java/sip/communicator/util/account/AccountStatusUtils.java @@ -10,6 +10,8 @@ import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.globalstatus.*;
import net.java.sip.communicator.util.*;
+import java.util.*;
+
/**
* The <tt>AccountStatusUtils</tt> provides utility methods for account status
* management.
@@ -76,6 +78,95 @@ public class AccountStatusUtils }
/**
+ * Returns the current status for protocol provider.
+ *
+ * @param protocolProvider the protocol provider
+ * @return the current status for protocol provider
+ */
+ public static PresenceStatus getPresenceStatus(
+ ProtocolProviderService protocolProvider)
+ {
+ PresenceStatus status = null;
+
+ OperationSetPresence opSet
+ = protocolProvider.getOperationSet(OperationSetPresence.class);
+
+ if(opSet != null)
+ status = opSet.getPresenceStatus();
+
+ return status;
+ }
+
+ /**
+ * Returns the online status of provider.
+ * @param protocolProvider the protocol provider
+ * @return the online status of provider.
+ */
+ public static PresenceStatus getOnlineStatus(
+ ProtocolProviderService protocolProvider)
+ {
+ PresenceStatus onlineStatus = null;
+
+ OperationSetPresence presence
+ = protocolProvider.getOperationSet(OperationSetPresence.class);
+
+ // presence can be not supported
+ if(presence != null)
+ {
+ Iterator<PresenceStatus> statusIterator
+ = presence.getSupportedStatusSet();
+ while (statusIterator.hasNext())
+ {
+ PresenceStatus status = statusIterator.next();
+ int connectivity = status.getStatus();
+
+ if ((onlineStatus != null
+ && (onlineStatus.getStatus() < connectivity))
+ || (onlineStatus == null
+ && (connectivity > 50 && connectivity < 80)))
+ {
+ onlineStatus = status;
+ }
+ }
+ }
+
+ return onlineStatus;
+ }
+
+ /**
+ * Returns the offline status of provider.
+ * @param protocolProvider the protocol provider
+ * @return the offline status of provider.
+ */
+ public static PresenceStatus getOfflineStatus(
+ ProtocolProviderService protocolProvider)
+ {
+ PresenceStatus offlineStatus = null;
+
+ OperationSetPresence presence
+ = protocolProvider.getOperationSet(OperationSetPresence.class);
+
+ // presence can be not supported
+ if(presence != null)
+ {
+ Iterator<PresenceStatus> statusIterator
+ = presence.getSupportedStatusSet();
+ while (statusIterator.hasNext())
+ {
+ PresenceStatus status = statusIterator.next();
+ int connectivity = status.getStatus();
+
+ if (connectivity < 1)
+ {
+ offlineStatus = status;
+ }
+ }
+ }
+
+ return offlineStatus;
+ }
+
+ /**
* Returns the last contact status saved in the configuration.
*
* @param protocolProvider the protocol provider to which the status
|