From 0bf621360b14a0060a4cded64d3168ed95394524 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Fri, 14 Mar 2014 16:59:32 +0200 Subject: Fixes initial status set for protocols and UI to reflect changes. --- .../util/account/AccountStatusUtils.java | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'src/net/java/sip/communicator/util') 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 AccountStatusUtils 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 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 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 -- cgit v1.1