Adds a global status method in the GlobalStatusService.

modified:   src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java
	modified:   src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java
	modified:   src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusSelectorBox.java
	modified:   src/net/java/sip/communicator/service/protocol/globalstatus/GlobalStatusService.java
cusax-fix
yanas 13 years ago
parent 9e5dfb611e
commit 4398906ee2

@ -30,6 +30,103 @@ public class GlobalStatusServiceImpl
private final Logger logger private final Logger logger
= Logger.getLogger(GlobalStatusServiceImpl.class); = Logger.getLogger(GlobalStatusServiceImpl.class);
/**
* Returns the global presence status.
*
* @return the current global presence status
*/
public PresenceStatus getGlobalPresenceStatus()
{
int status = 0;
Collection<ProtocolProviderService> pProviders
= AccountUtils.getRegisteredProviders();
// If we don't have registered providers we return offline status.
if (pProviders == null || pProviders.size() <= 0)
return getPresenceStatus(status);
Iterator<ProtocolProviderService> providersIter = pProviders.iterator();
boolean hasAvailableProvider = false;
while (providersIter.hasNext())
{
ProtocolProviderService protocolProvider = providersIter.next();
// We do not show hidden protocols in our status bar, so we do not
// care about their status here.
boolean isProtocolHidden =
protocolProvider.getAccountID().getAccountProperty(
ProtocolProviderFactory.IS_PROTOCOL_HIDDEN) != null;
if (isProtocolHidden)
continue;
if (!protocolProvider.isRegistered())
continue;
OperationSetPresence presence
= protocolProvider.getOperationSet(OperationSetPresence.class);
if(presence == null)
{
hasAvailableProvider = true;
continue;
}
int presenceStatus
= (presence == null)
? PresenceStatus.AVAILABLE_THRESHOLD
: presence.getPresenceStatus().getStatus();
if (status < presenceStatus)
status = presenceStatus;
}
// if we have at least one online provider
if(status == 0 && hasAvailableProvider)
status = PresenceStatus.AVAILABLE_THRESHOLD;
return getPresenceStatus(status);
}
/**
* Returns the <tt>JCheckBoxMenuItem</tt> corresponding to the given status.
* For status constants we use here the values defined in the
* <tt>PresenceStatus</tt>, but this is only for convenience.
*
* @param status the status to which the item should correspond
* @return the <tt>JCheckBoxMenuItem</tt> corresponding to the given status
*/
private PresenceStatus getPresenceStatus(int status)
{
if(status < PresenceStatus.ONLINE_THRESHOLD)
{
return GlobalStatusEnum.OFFLINE;
}
else if(status < PresenceStatus.AWAY_THRESHOLD)
{
return GlobalStatusEnum.DO_NOT_DISTURB;
}
else if(status < PresenceStatus.AVAILABLE_THRESHOLD)
{
return GlobalStatusEnum.AWAY;
}
else if(status < PresenceStatus.EAGER_TO_COMMUNICATE_THRESHOLD)
{
return GlobalStatusEnum.ONLINE;
}
else if(status < PresenceStatus.MAX_STATUS_VALUE)
{
return GlobalStatusEnum.FREE_FOR_CHAT;
}
else
{
return GlobalStatusEnum.OFFLINE;
}
}
/** /**
* Returns the last status that was stored in the configuration for the * Returns the last status that was stored in the configuration for the
* given protocol provider. * given protocol provider.

@ -147,7 +147,7 @@ public AccountStatusPanel(MainFrame mainFrame)
accountNameLabel.getFont().deriveFont(12f)); accountNameLabel.getFont().deriveFont(12f));
accountNameLabel.setOpaque(false); accountNameLabel.setOpaque(false);
statusComboBox = new GlobalStatusSelectorBox(mainFrame); statusComboBox = new GlobalStatusSelectorBox();
// Align status combo box with account name field. // Align status combo box with account name field.
statusComboBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); statusComboBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

@ -8,13 +8,11 @@
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.*;
import javax.swing.*; import javax.swing.*;
import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.lookandfeel.*; import net.java.sip.communicator.impl.gui.lookandfeel.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.*;
@ -68,11 +66,6 @@ public class GlobalStatusSelectorBox
private Image arrowImage private Image arrowImage
= ImageLoader.getImage(ImageLoader.DOWN_ARROW_ICON); = ImageLoader.getImage(ImageLoader.DOWN_ARROW_ICON);
/**
* The main application window.
*/
private final MainFrame mainFrame;
/** /**
* The width of the text. * The width of the text.
*/ */
@ -90,15 +83,11 @@ public class GlobalStatusSelectorBox
/** /**
* Creates an instance of <tt>SimpleStatusSelectorBox</tt>. * Creates an instance of <tt>SimpleStatusSelectorBox</tt>.
*
* @param mainFrame The main application window.
*/ */
public GlobalStatusSelectorBox(MainFrame mainFrame) public GlobalStatusSelectorBox()
{ {
super(); super();
this.mainFrame = mainFrame;
JLabel titleLabel = new JLabel(GuiActivator.getResources() JLabel titleLabel = new JLabel(GuiActivator.getResources()
.getI18NString("service.gui.SET_GLOBAL_STATUS")); .getI18NString("service.gui.SET_GLOBAL_STATUS"));
titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
@ -138,6 +127,8 @@ public GlobalStatusSelectorBox(MainFrame mainFrame)
/** /**
* Creates a menu item with the given <tt>textKey</tt>, <tt>iconID</tt> and * Creates a menu item with the given <tt>textKey</tt>, <tt>iconID</tt> and
* <tt>name</tt>. * <tt>name</tt>.
*
* @param status the global status
* @return the created <tt>JCheckBoxMenuItem</tt> * @return the created <tt>JCheckBoxMenuItem</tt>
*/ */
private JCheckBoxMenuItem createMenuItem(GlobalStatusEnum status) private JCheckBoxMenuItem createMenuItem(GlobalStatusEnum status)
@ -392,66 +383,25 @@ public void updateStatus(ProtocolProviderService protocolProvider,
*/ */
private void updateGlobalStatus() private void updateGlobalStatus()
{ {
int status = 0; PresenceStatus globalStatus
= GuiActivator.getGlobalStatusService().getGlobalPresenceStatus();
Iterator<ProtocolProviderService> pProviders
= mainFrame.getProtocolProviders();
boolean hasAvailableProvider = false;
while (pProviders.hasNext())
{
ProtocolProviderService protocolProvider = pProviders.next();
// We do not show hidden protocols in our status bar, so we do not
// care about their status here.
boolean isProtocolHidden =
protocolProvider.getAccountID().getAccountProperty(
ProtocolProviderFactory.IS_PROTOCOL_HIDDEN) != null;
if (isProtocolHidden)
continue;
if (!protocolProvider.isRegistered())
continue;
OperationSetPresence presence
= protocolProvider.getOperationSet(OperationSetPresence.class);
if(presence == null)
{
hasAvailableProvider = true;
continue;
}
int presenceStatus
= (presence == null)
? PresenceStatus.AVAILABLE_THRESHOLD
: presence.getPresenceStatus().getStatus();
if (status < presenceStatus)
status = presenceStatus;
}
// if we have at least one online provider
if(status == 0 && hasAvailableProvider)
status = PresenceStatus.AVAILABLE_THRESHOLD;
JCheckBoxMenuItem item = getItemFromStatus(status); JCheckBoxMenuItem item = getItemFromStatus(globalStatus);
item.setSelected(true); item.setSelected(true);
setSelected(new SelectedObject(item.getText(), item.getIcon(), item)); setSelected(new SelectedObject(item.getText(), item.getIcon(), item));
fitSizeToText(); fitSizeToText();
this.revalidate(); this.revalidate();
setSystrayIcon(status); setSystrayIcon(globalStatus);
} }
/** /**
* Sets the systray icon corresponding to the given status. * Sets the systray icon corresponding to the given status.
* *
* @param status the status, for which we're setting the systray icon. * @param globalStatus the status, for which we're setting the systray icon.
*/ */
private void setSystrayIcon(int status) private void setSystrayIcon(PresenceStatus globalStatus)
{ {
SystrayService trayService = GuiActivator.getSystrayService(); SystrayService trayService = GuiActivator.getSystrayService();
if(trayService == null) if(trayService == null)
@ -459,23 +409,23 @@ private void setSystrayIcon(int status)
int imgType = SystrayService.SC_IMG_OFFLINE_TYPE; int imgType = SystrayService.SC_IMG_OFFLINE_TYPE;
if(status < PresenceStatus.ONLINE_THRESHOLD) if (globalStatus.equals(GlobalStatusEnum.OFFLINE))
{ {
imgType = SystrayService.SC_IMG_OFFLINE_TYPE; imgType = SystrayService.SC_IMG_OFFLINE_TYPE;
} }
else if(status < PresenceStatus.AWAY_THRESHOLD) else if (globalStatus.equals(GlobalStatusEnum.DO_NOT_DISTURB))
{ {
imgType = SystrayService.SC_IMG_DND_TYPE; imgType = SystrayService.SC_IMG_DND_TYPE;
} }
else if(status < PresenceStatus.AVAILABLE_THRESHOLD) else if (globalStatus.equals(GlobalStatusEnum.AWAY))
{ {
imgType = SystrayService.SC_IMG_AWAY_TYPE; imgType = SystrayService.SC_IMG_AWAY_TYPE;
} }
else if(status < PresenceStatus.EAGER_TO_COMMUNICATE_THRESHOLD) else if (globalStatus.equals(GlobalStatusEnum.ONLINE))
{ {
imgType = SystrayService.SC_IMG_TYPE; imgType = SystrayService.SC_IMG_TYPE;
} }
else if(status < PresenceStatus.MAX_STATUS_VALUE) else if (globalStatus.equals(GlobalStatusEnum.FREE_FOR_CHAT))
{ {
imgType = SystrayService.SC_IMG_FFC_TYPE; imgType = SystrayService.SC_IMG_FFC_TYPE;
} }
@ -488,53 +438,17 @@ else if(status < PresenceStatus.MAX_STATUS_VALUE)
* For status constants we use here the values defined in the * For status constants we use here the values defined in the
* <tt>PresenceStatus</tt>, but this is only for convenience. * <tt>PresenceStatus</tt>, but this is only for convenience.
* *
* @param status the status to which the item should correspond * @param globalStatus the status to which the item should correspond
* @return the <tt>JCheckBoxMenuItem</tt> corresponding to the given status
*/
private JCheckBoxMenuItem getItemFromStatus(int status)
{
if(status < PresenceStatus.ONLINE_THRESHOLD)
{
return getItemFromName(GlobalStatusEnum.OFFLINE_STATUS);
}
else if(status < PresenceStatus.AWAY_THRESHOLD)
{
return getItemFromName(GlobalStatusEnum.DO_NOT_DISTURB_STATUS);
}
else if(status < PresenceStatus.AVAILABLE_THRESHOLD)
{
return getItemFromName(GlobalStatusEnum.AWAY_STATUS);
}
else if(status < PresenceStatus.EAGER_TO_COMMUNICATE_THRESHOLD)
{
return getItemFromName(GlobalStatusEnum.ONLINE_STATUS);
}
else if(status < PresenceStatus.MAX_STATUS_VALUE)
{
return getItemFromName(GlobalStatusEnum.FREE_FOR_CHAT_STATUS);
}
else
{
return getItemFromName(GlobalStatusEnum.OFFLINE_STATUS);
}
}
/**
* Returns the <tt>JCheckBoxMenuItem</tt> corresponding to the given status
* name.
*
* @param statusName the status name to which the item should correspond
* @return the <tt>JCheckBoxMenuItem</tt> corresponding to the given status * @return the <tt>JCheckBoxMenuItem</tt> corresponding to the given status
* name.
*/ */
private JCheckBoxMenuItem getItemFromName(String statusName) private JCheckBoxMenuItem getItemFromStatus(PresenceStatus globalStatus)
{ {
for(Component c : getMenuComponents()) for(Component c : getMenuComponents())
{ {
if(c instanceof JCheckBoxMenuItem if(c instanceof JCheckBoxMenuItem
&& statusName.equals(c.getName())) && globalStatus.getStatusName().equals(c.getName()))
{ {
return (JCheckBoxMenuItem)c; return (JCheckBoxMenuItem) c;
} }
} }

@ -16,6 +16,13 @@
*/ */
public interface GlobalStatusService public interface GlobalStatusService
{ {
/**
* Returns the global presence status.
*
* @return the current global presence status
*/
public PresenceStatus getGlobalPresenceStatus();
/** /**
* Returns the last status that was stored in the configuration for the * Returns the last status that was stored in the configuration for the
* given protocol provider. * given protocol provider.

Loading…
Cancel
Save