Changes the priority of the "On the phone" and "In a meeting" presence

statuses.
fix-message-formatting
hristoterezov 12 years ago
parent 29b071b095
commit e5f5e7acb6

@ -402,6 +402,7 @@ static void startCalendarService()
false))
{
calendarService = new CalendarServiceImpl();
try
{
MsOutlookAddrBookContactSourceService.initMAPI(null);
@ -425,6 +426,8 @@ static void startCalendarService()
}
pps.addRegistrationStateChangeListener(providerListener);
}
bundleContext.registerService(CalendarService.class.getName(),
calendarService, null);
calendarService.start();
}
}

@ -16,3 +16,4 @@ Import-Package: javax.swing,
net.java.sip.communicator.util,
net.java.sip.communicator.plugin.desktoputil,
org.osgi.framework
Export-Package: net.java.sip.communicator.service.calendar

@ -492,6 +492,23 @@ protected void setCurrentState(BusyStatusEnum state)
}
}
/**
* Handles presence status changed from "On the Phone"
*
* @param presenceStatuses the remembered presence statuses
* @return <tt>true</tt> if the status is changed.
*/
public boolean onThePhoneStatusChanged(
Map<ProtocolProviderService,PresenceStatus> presenceStatuses)
{
if(currentState != BusyStatusEnum.FREE)
{
inMeetingStatusPolicy.onThePhoneStatusChanged(presenceStatuses);
return true;
}
return false;
}
/**
* Calculates and changes the value of current status using the current
@ -551,7 +568,7 @@ private class InMeetingStatusPolicy
* instances in order to recognize the <tt>PresenceStatus</tt> which
* represents &quot;In meeting&quot;.
*/
private final Pattern inMeetingPresenceStatusNameWhitespace
private final Pattern presenceStatusNameWhitespace
= Pattern.compile("\\p{Space}");
/**
@ -569,9 +586,30 @@ private class InMeetingStatusPolicy
*/
public void freeBusyStateChanged()
{
run();
run(false);
}
/**
* Handles presence status changed from "On the Phone"
* @param presenceStatuses the remembered presence statuses
*/
public void onThePhoneStatusChanged(
Map<ProtocolProviderService,PresenceStatus> presenceStatuses)
{
run(true);
for(ProtocolProviderService pps : presenceStatuses.keySet())
rememberPresenceStatus(pps, presenceStatuses.get(pps));
}
/**
* Returns the remembered presence statuses
* @return the remembered presence statuses
*/
public Map<ProtocolProviderService,PresenceStatus> getRememberedStatuses()
{
return presenceStatuses;
}
/**
* Finds the first <tt>PresenceStatus</tt> among the set of
* <tt>PresenceStatus</tt>es supported by a specific
@ -593,7 +631,7 @@ private PresenceStatus findInMeetingPresenceStatus(
{
PresenceStatus presenceStatus = i.next();
if (inMeetingPresenceStatusNameWhitespace
if (presenceStatusNameWhitespace
.matcher(presenceStatus.getStatusName())
.replaceAll("")
.equalsIgnoreCase("InAMeeting"))
@ -604,6 +642,38 @@ private PresenceStatus findInMeetingPresenceStatus(
return null;
}
/**
* Finds the first <tt>PresenceStatus</tt> among the set of
* <tt>PresenceStatus</tt>es supported by a specific
* <tt>OperationSetPresence</tt> which represents
* &quot;On the phone&quot;.
*
* @param presence the <tt>OperationSetPresence</tt> which represents
* the set of supported <tt>PresenceStatus</tt>es
* @return the first <tt>PresenceStatus</tt> among the set of
* <tt>PresenceStatus</tt>es supported by <tt>presence</tt> which
* represents &quot;On the phone&quot; if such a <tt>PresenceStatus</tt>
* was found; otherwise, <tt>null</tt>
*/
private PresenceStatus findOnThePhonePresenceStatus(
OperationSetPresence presence)
{
for (Iterator<PresenceStatus> i = presence.getSupportedStatusSet();
i.hasNext();)
{
PresenceStatus presenceStatus = i.next();
if (presenceStatusNameWhitespace
.matcher(presenceStatus.getStatusName())
.replaceAll("")
.equalsIgnoreCase("OnThePhone"))
{
return presenceStatus;
}
}
return null;
}
/**
* Removes the remembered presence status for given provider
* @param pps the provider
@ -671,7 +741,7 @@ private PresenceStatus rememberPresenceStatus(
/**
* Applies this policy to the current state of the application.
*/
private void run()
private void run(boolean onThePhoneStatusChanged)
{
List<ProtocolProviderService> providers
= AddrBookActivator.getProtocolProviders();
@ -689,13 +759,13 @@ private void run()
if (pps == null)
continue;
handleProtocolProvider(pps, isInMeeting);
handleProtocolProvider(pps, isInMeeting, onThePhoneStatusChanged);
}
}
}
public void handleProtocolProvider(ProtocolProviderService pps,
Boolean isInMeeting)
Boolean isInMeeting, boolean onThePhoneStatusChanged)
{
if(isInMeeting == null)
isInMeeting = isInMeeting();
@ -716,6 +786,9 @@ else if (pps.isRegistered())
{
PresenceStatus inMeetingPresenceStatus
= findInMeetingPresenceStatus(presence);
PresenceStatus onThePhone
= findOnThePhonePresenceStatus(presence);
if (inMeetingPresenceStatus == null)
{
@ -741,7 +814,9 @@ else if (isInMeeting)
forgetPresenceStatus(pps);
}
else if (!inMeetingPresenceStatus.equals(
presenceStatus))
presenceStatus)
&& (!presenceStatus.equals(onThePhone)
|| onThePhoneStatusChanged))
{
publishPresenceStatus(
presence,
@ -863,6 +938,15 @@ public boolean callback(String id)
public void handleProviderAdded(ProtocolProviderService pps)
{
inMeetingStatusPolicy.handleProtocolProvider(pps, null);
inMeetingStatusPolicy.handleProtocolProvider(pps, null, false);
}
/**
* Returns the remembered presence statuses
* @return the remembered presence statuses
*/
public Map<ProtocolProviderService,PresenceStatus> getRememberedStatuses()
{
return inMeetingStatusPolicy.getRememberedStatuses();
}
}

@ -5,6 +5,10 @@
*/
package net.java.sip.communicator.service.calendar;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
/**
* A service for calendar. It defines for accessing the current free busy status
* and add / remove listeners for the free busy status.
@ -125,5 +129,19 @@ public int getPriority()
* @param listener the listener to be removed.
*/
public void removeFreeBusySateListener(FreeBusySateListener listener);
/**
* Handles presence status changed from "On the Phone"
*
* @param presenceStatuses the remembered presence statuses
* @return <tt>true</tt> if the status is changed.
*/
public boolean onThePhoneStatusChanged(
Map<ProtocolProviderService,PresenceStatus> presenceStatuses);
/**
* Returns the remembered presence statuses
* @return the remembered presence statuses
*/
public Map<ProtocolProviderService,PresenceStatus> getRememberedStatuses();
}

@ -6,6 +6,7 @@
*/
package net.java.sip.communicator.service.protocol;
import net.java.sip.communicator.service.calendar.*;
import net.java.sip.communicator.util.*;
import org.jitsi.service.configuration.*;
@ -62,6 +63,11 @@ public class ProtocolProviderActivator
*/
private static ResourceManagementService resourceService;
/**
* The calendar service instance.
*/
private static CalendarService calendarService;
/**
* The <code>SingleCallInProgressPolicy</code> making sure that the
* <code>Call</code>s accessible in the <code>BundleContext</code> of this
@ -112,6 +118,27 @@ public static ResourceManagementService getResourceService()
return resourceService;
}
/**
* Gets the <code>CalendarService</code> to be used by the classes
* in the bundle represented by <code>ProtocolProviderActivator</code>.
*
* @return the <code>CalendarService</code> to be used by the
* classes in the bundle represented by
* <code>ProtocolProviderActivator</code>
*/
public static CalendarService getCalendarService()
{
if (calendarService == null)
{
calendarService
= (CalendarService)
bundleContext.getService(
bundleContext.getServiceReference(
CalendarService.class.getName()));
}
return calendarService;
}
/**
* Returns a <tt>ProtocolProviderFactory</tt> for a given protocol
* provider.

@ -11,6 +11,7 @@
import java.util.*;
import java.util.regex.*;
import net.java.sip.communicator.service.calendar.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -23,6 +24,7 @@
*
* @author Lyubomir Marinov
* @author Damian Minkov
* @author Hristo Terezov
*/
public class SingleCallInProgressPolicy
{
@ -516,7 +518,7 @@ private class OnThePhoneStatusPolicy
* instances in order to recognize the <tt>PresenceStatus</tt> which
* represents &quot;On the phone&quot;.
*/
private final Pattern onThePhonePresenceStatusNameWhitespace
private final Pattern presenceStatusNameWhitespace
= Pattern.compile("\\p{Space}");
/**
@ -574,7 +576,7 @@ private PresenceStatus findOnThePhonePresenceStatus(
{
PresenceStatus presenceStatus = i.next();
if (onThePhonePresenceStatusNameWhitespace
if (presenceStatusNameWhitespace
.matcher(presenceStatus.getStatusName())
.replaceAll("")
.equalsIgnoreCase("OnThePhone"))
@ -668,6 +670,38 @@ private PresenceStatus rememberPresenceStatus(
return presenceStatuses.put(pps, presenceStatus);
}
/**
* Finds the first <tt>PresenceStatus</tt> among the set of
* <tt>PresenceStatus</tt>es supported by a specific
* <tt>OperationSetPresence</tt> which represents
* &quot;In meeting&quot;.
*
* @param presence the <tt>OperationSetPresence</tt> which represents
* the set of supported <tt>PresenceStatus</tt>es
* @return the first <tt>PresenceStatus</tt> among the set of
* <tt>PresenceStatus</tt>es supported by <tt>presence</tt> which
* represents &quot;In meeting&quot; if such a <tt>PresenceStatus</tt>
* was found; otherwise, <tt>null</tt>
*/
private PresenceStatus findInMeetingPresenceStatus(
OperationSetPresence presence)
{
for (Iterator<PresenceStatus> i = presence.getSupportedStatusSet();
i.hasNext();)
{
PresenceStatus presenceStatus = i.next();
if (presenceStatusNameWhitespace
.matcher(presenceStatus.getStatusName())
.replaceAll("")
.equalsIgnoreCase("InAMeeting"))
{
return presenceStatus;
}
}
return null;
}
/**
* Applies this policy to the current state of the application.
*/
@ -701,6 +735,16 @@ private void run()
else
{
boolean isOnThePhone = isOnThePhone();
CalendarService calendar
= ProtocolProviderActivator.getCalendarService();
if(!isOnThePhone &&
calendar.onThePhoneStatusChanged(presenceStatuses))
{
forgetPresenceStatuses();
return;
}
for (ServiceReference ppsRef : ppsRefs)
{
@ -757,7 +801,19 @@ else if (!onThePhonePresenceStatus.equals(
publishPresenceStatus(
presence,
onThePhonePresenceStatus);
if (onThePhonePresenceStatus.equals(
if(presenceStatus.equals(
findInMeetingPresenceStatus(presence)))
{
Map<ProtocolProviderService,PresenceStatus>
statuses
= calendar.getRememberedStatuses();
for(ProtocolProviderService provider
: statuses.keySet())
rememberPresenceStatus(provider,
statuses.get(provider));
}
else if (onThePhonePresenceStatus.equals(
presence.getPresenceStatus()))
{
rememberPresenceStatus(pps, presenceStatus);

@ -7,6 +7,7 @@ Bundle-SymbolicName: net.java.sip.communicator.service.protocol
Import-Package: net.java.sip.communicator.service.credentialsstorage,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.util,
net.java.sip.communicator.service.calendar,
org.jitsi.service.configuration,
org.jitsi.service.neomedia,
org.jitsi.service.neomedia.codec,

Loading…
Cancel
Save