aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/generalconfig
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/java/sip/communicator/plugin/generalconfig')
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java24
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationPanel.java178
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/XMPPConfigForm.java101
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayWatcher.java920
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/autoaway/Preferences.java262
5 files changed, 839 insertions, 646 deletions
diff --git a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java
index 2f345d7..7222d97 100644
--- a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java
+++ b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java
@@ -108,6 +108,14 @@ public class GeneralConfigPluginActivator
"net.java.sip.communicator.plugin.generalconfig.sipconfig.DISABLED";
/**
+ * Indicates if the XMPP configuration form should be disabled, i.e.
+ * not visible to the user.
+ */
+ private static final String XMPP_CONFIG_DISABLED_PROP
+ =
+ "net.java.sip.communicator.plugin.generalconfig.xmppconfig.DISABLED";
+
+ /**
* Starts this bundle.
*/
@Override
@@ -155,6 +163,22 @@ public class GeneralConfigPluginActivator
52, true),
properties);
}
+ if (!getConfigurationService()
+ .getBoolean(XMPP_CONFIG_DISABLED_PROP, false))
+ {
+ // Registers the XMPP config panel as advanced configuration form.
+ properties.put( ConfigurationForm.FORM_TYPE,
+ ConfigurationForm.ADVANCED_TYPE);
+ bundleContext.registerService(
+ ConfigurationForm.class.getName(),
+ new LazyConfigurationForm(
+ XMPPConfigForm.class.getName(),
+ getClass().getClassLoader(),
+ null,
+ "plugin.generalconfig.XMPP_CONFIG",
+ 52, true),
+ properties);
+ }
properties.put( ConfigurationForm.FORM_TYPE,
ConfigurationForm.ADVANCED_TYPE);
bundleContext.registerService(
diff --git a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationPanel.java b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationPanel.java
index f5e482a..03fc308 100644
--- a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationPanel.java
+++ b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationPanel.java
@@ -98,6 +98,13 @@ public class GeneralConfigurationPanel
=
"net.java.sip.communicator.plugin.generalconfig.localeconfig.DISABLED";
+ /**
+ * Indicates if the systray config panel should be disabled, i.e. not
+ * visible to the user.
+ */
+ private static final String SYSTRAY_CONFIG_DISABLED_PROP =
+ "net.java.sip.communicator.plugin.generalconfig.systrayconfig.DISABLED";
+
/**
* Indicates if the Call configuration panel should be disabled, i.e.
* not visible to the user.
@@ -169,6 +176,13 @@ public class GeneralConfigurationPanel
}
if(!GeneralConfigPluginActivator.getConfigurationService()
+ .getBoolean(SYSTRAY_CONFIG_DISABLED_PROP, false))
+ {
+ mainPanel.add(createSystrayeConfigPanel());
+ mainPanel.add(Box.createVerticalStrut(10));
+ }
+
+ if(!GeneralConfigPluginActivator.getConfigurationService()
.getBoolean(CALL_CONFIG_DISABLED_PROP, false))
{
mainPanel.add(createCallConfigPanel());
@@ -237,6 +251,30 @@ public class GeneralConfigurationPanel
}
/**
+ * Initializes the minimize instead of hide checkbox.
+ */
+ public Component createMinimzeInsteadOfHideCheckBox()
+ {
+ JCheckBox chk = new SIPCommCheckBox();
+
+ chk.setText(
+ Resources.getString("plugin.generalconfig.MINIMIZE_NOT_HIDE"));
+ chk.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ boolean value = ((JCheckBox) e.getSource()).isSelected();
+ ConfigurationUtils.setIsMinimizeInsteadOfHide(value);
+ UtilActivator.getUIService().setMainWindowCanHide(
+ !UtilActivator.getSystrayService().checkInitialized());
+ }
+ });
+
+ chk.setSelected(ConfigurationUtils.isMinimizeInsteadOfHide());
+ return chk;
+ }
+
+ /**
* Creates the message configuration panel.
* @return the created panel
*/
@@ -832,6 +870,72 @@ public class GeneralConfigurationPanel
return localeConfigPanel;
}
+ private static class Item
+ {
+ public String key;
+ public String value;
+
+ public Item(String key, String value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public String toString()
+ {
+ return GeneralConfigPluginActivator.getResources()
+ .getI18NString(value);
+ }
+ }
+
+ /**
+ * Initializes the systray configuration panel.
+ * @return the created component
+ */
+ private Component createSystrayeConfigPanel()
+ {
+ JPanel panel = GeneralConfigPluginActivator.
+ createConfigSectionComponent(
+ Resources.getString("service.systray.MODE"));
+
+ final JComboBox<Item> systrayModes = new JComboBox<>();
+ SystrayService ss = GeneralConfigPluginActivator.getSystrayService();
+ for (Map.Entry<String, String> mode : ss.getSystrayModes().entrySet())
+ {
+ Item i = new Item(mode.getKey(), mode.getValue());
+ systrayModes.addItem(i);
+ if (mode.getKey().equals(ss.getActiveSystrayMode()))
+ {
+ systrayModes.setSelectedItem(i);
+ }
+ }
+
+ systrayModes.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ GeneralConfigPluginActivator.getConfigurationService()
+ .setProperty(SystrayService.PNMAE_TRAY_MODE,
+ ((Item) systrayModes.getSelectedItem()).key);
+ }
+ });
+
+ panel.add(systrayModes);
+ String label = "<html><body style='width:350px'>* " +
+ Resources.getString("service.systray.CLI_NOTE", new String[]{
+ Resources.getSettingsString("service.gui.APPLICATION_NAME")
+ }) + "</body></html>";
+ JLabel warnLabel = new JLabel(label);
+ warnLabel.setToolTipText(label);
+ warnLabel.setForeground(Color.GRAY);
+ warnLabel.setFont(warnLabel.getFont().deriveFont(8));
+ warnLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
+ panel.add(warnLabel);
+ return panel;
+ }
+
/**
* Creates the call configuration panel.
*
@@ -856,13 +960,11 @@ public class GeneralConfigurationPanel
*/
private Component createNormalizeNumberCheckBox()
{
- JPanel checkBoxPanel = new TransparentPanel(new BorderLayout());
-
- SIPCommCheckBox formatPhoneNumber = new SIPCommCheckBox("",
+ SIPCommCheckBox formatPhoneNumber = new SIPCommCheckBox(
+ GeneralConfigPluginActivator.getResources().getI18NString(
+ "plugin.generalconfig.REMOVE_SPECIAL_PHONE_SYMBOLS"),
ConfigurationUtils.isNormalizePhoneNumber());
- formatPhoneNumber.setAlignmentY(Component.TOP_ALIGNMENT);
-
formatPhoneNumber.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
@@ -872,22 +974,7 @@ public class GeneralConfigurationPanel
}
});
- StyledHTMLEditorPane checkBoxTextLabel = new StyledHTMLEditorPane();
-
- checkBoxTextLabel.setContentType("text/html");
- checkBoxTextLabel.appendToEnd(
- "<html>" + GeneralConfigPluginActivator.getResources().getI18NString(
- "plugin.generalconfig.REMOVE_SPECIAL_PHONE_SYMBOLS") + "</html>");
-
- checkBoxTextLabel.setBorder(
- BorderFactory.createEmptyBorder(3, 0, 0, 0));
- checkBoxTextLabel.setOpaque(false);
- checkBoxTextLabel.setEditable(false);
-
- checkBoxPanel.add(formatPhoneNumber, BorderLayout.WEST);
- checkBoxPanel.add(checkBoxTextLabel, BorderLayout.CENTER);
-
- return checkBoxPanel;
+ return formatPhoneNumber;
}
/**
@@ -897,17 +984,17 @@ public class GeneralConfigurationPanel
*/
private Component createAcceptPhoneNumberWithAlphaCharCheckBox()
{
- JPanel checkBoxPanel = new TransparentPanel(new BorderLayout());
+ JPanel checkBoxPanel = new TransparentPanel();
+ checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.Y_AXIS));
// Checkbox to accept string with alphabetical characters as potential
// phone numbers.
- SIPCommCheckBox acceptPhoneNumberWithAlphaChars
- = new SIPCommCheckBox("",
+ SIPCommCheckBox alphaCharNumbers = new SIPCommCheckBox(
+ GeneralConfigPluginActivator.getResources().getI18NString(
+ "plugin.generalconfig.ACCEPT_PHONE_NUMBER_WITH_ALPHA_CHARS"),
ConfigurationUtils.acceptPhoneNumberWithAlphaChars());
- acceptPhoneNumberWithAlphaChars.setAlignmentY(Component.TOP_ALIGNMENT);
-
- acceptPhoneNumberWithAlphaChars.addActionListener(new ActionListener()
+ alphaCharNumbers.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
@@ -916,21 +1003,6 @@ public class GeneralConfigurationPanel
}
});
- StyledHTMLEditorPane acceptPhoneNumberWithAlphaCharsTextLabel
- = new StyledHTMLEditorPane();
-
- acceptPhoneNumberWithAlphaCharsTextLabel.setContentType("text/html");
- acceptPhoneNumberWithAlphaCharsTextLabel.appendToEnd(
- "<html>"
- + GeneralConfigPluginActivator.getResources().getI18NString(
- "plugin.generalconfig.ACCEPT_PHONE_NUMBER_WITH_ALPHA_CHARS")
- + "</html>");
-
- acceptPhoneNumberWithAlphaCharsTextLabel.setBorder(
- BorderFactory.createEmptyBorder(3, 0, 0, 0));
- acceptPhoneNumberWithAlphaCharsTextLabel.setOpaque(false);
- acceptPhoneNumberWithAlphaCharsTextLabel.setEditable(false);
-
// The example of changing letters to numbers in a phone number.
String label = "* " + Resources.getString(
"plugin.generalconfig.ACCEPT_PHONE_NUMBER_WITH_ALPHA_CHARS_EXAMPLE");
@@ -942,14 +1014,8 @@ public class GeneralConfigurationPanel
exampleLabel.setHorizontalAlignment(JLabel.LEFT);
// Adds the components to the current panel.
- checkBoxPanel.add(acceptPhoneNumberWithAlphaChars, BorderLayout.WEST);
- checkBoxPanel.add(
- acceptPhoneNumberWithAlphaCharsTextLabel,
- BorderLayout.CENTER);
- checkBoxPanel.add(
- exampleLabel,
- BorderLayout.SOUTH);
-
+ checkBoxPanel.add(alphaCharNumbers);
+ checkBoxPanel.add(exampleLabel);
return checkBoxPanel;
}
@@ -959,15 +1025,17 @@ public class GeneralConfigurationPanel
*/
public Component createStartupConfigPanel()
{
- if (!OSUtils.IS_WINDOWS)
- return null;
-
JPanel updateConfigPanel = GeneralConfigPluginActivator.
createConfigSectionComponent(
Resources.getString("plugin.generalconfig.STARTUP_CONFIG"));
- updateConfigPanel.add(createAutoStartCheckBox());
- updateConfigPanel.add(createUpdateCheckBox());
+ updateConfigPanel.add(createMinimzeInsteadOfHideCheckBox());
+ if (OSUtils.IS_WINDOWS)
+ {
+ updateConfigPanel.add(createAutoStartCheckBox());
+ updateConfigPanel.add(createUpdateCheckBox());
+ }
+
return updateConfigPanel;
}
diff --git a/src/net/java/sip/communicator/plugin/generalconfig/XMPPConfigForm.java b/src/net/java/sip/communicator/plugin/generalconfig/XMPPConfigForm.java
new file mode 100644
index 0000000..0113232
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/generalconfig/XMPPConfigForm.java
@@ -0,0 +1,101 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Copyright @ 2015 Atlassian Pty Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.java.sip.communicator.plugin.generalconfig;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import javax.swing.*;
+
+import org.jitsi.service.configuration.*;
+
+import net.java.sip.communicator.plugin.desktoputil.*;
+
+/**
+ * Implementation of the configuration form.
+ *
+ * @author Timur Masar
+ */
+public class XMPPConfigForm
+extends TransparentPanel
+{
+ /**
+ * Serial version UID.
+ */
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * The name of the property used to control whether to use
+ * all resources to show capabilities
+ */
+ public static final String PROP_XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES =
+ "net.java.sip.communicator.XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES";
+
+ /**
+ * The default value for the capabilities setting
+ */
+ public static final boolean USE_ALL_RESOURCES_FOR_CAPABILITIES_DEFAULT =
+ true;
+
+ /**
+ * The <tt>ConfigurationService</tt> to be used to access configuration
+ */
+ private final ConfigurationService configurationService
+ = GeneralConfigPluginActivator.getConfigurationService();
+
+ /**
+ * Creates the form.
+ */
+ public XMPPConfigForm()
+ {
+ super(new BorderLayout());
+ Box box = Box.createVerticalBox();
+ add(box, BorderLayout.NORTH);
+
+ TransparentPanel contentPanel = new TransparentPanel();
+ contentPanel.setLayout(new BorderLayout(10, 10));
+
+ box.add(contentPanel);
+
+ TransparentPanel labelPanel
+ = new TransparentPanel(new GridLayout(0, 1, 2, 2));
+ TransparentPanel valuePanel
+ = new TransparentPanel(new GridLayout(0, 1, 2, 2));
+
+ contentPanel.add(labelPanel, BorderLayout.CENTER);
+ contentPanel.add(valuePanel, BorderLayout.WEST);
+
+ final JCheckBox useAllResourcesForCapabilitiesCheckbox =
+ new SIPCommCheckBox(Resources.getString(
+ "plugin.generalconfig.XMPP_USE_ALL_RESOURCES"));
+
+ useAllResourcesForCapabilitiesCheckbox.addActionListener(
+ new ActionListener() {
+ public void actionPerformed(ActionEvent actionEvent) {
+ configurationService.setProperty(
+ PROP_XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES,
+ useAllResourcesForCapabilitiesCheckbox.isSelected());
+ }
+ });
+ useAllResourcesForCapabilitiesCheckbox.setSelected(
+ configurationService.getBoolean(
+ PROP_XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES,
+ USE_ALL_RESOURCES_FOR_CAPABILITIES_DEFAULT));
+ valuePanel.add(useAllResourcesForCapabilitiesCheckbox);
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayWatcher.java b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayWatcher.java
index 38a51c6..37bc48f 100644
--- a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayWatcher.java
+++ b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayWatcher.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,462 +15,462 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.plugin.generalconfig.autoaway;
-
-import java.beans.*;
-import java.util.*;
-
-import net.java.sip.communicator.plugin.generalconfig.*;
-import net.java.sip.communicator.service.protocol.*;
-import net.java.sip.communicator.service.protocol.event.*;
-import net.java.sip.communicator.service.sysactivity.*;
-import net.java.sip.communicator.service.sysactivity.event.*;
-import net.java.sip.communicator.util.*;
-
-import org.osgi.framework.*;
-
-/**
- * Listens for idle events from SystemActivityNotifications Service.
- *
- * @author Damian Minkov
- */
-public class AutoAwayWatcher
- implements ServiceListener,
- RegistrationStateChangeListener
-{
- /**
- * The logger.
- */
- private static final Logger logger
- = Logger.getLogger(AutoAwayWatcher.class);
-
- /**
- * The states of providers before going to away.
- */
- private final Map<ProtocolProviderService, PresenceStatus> lastStates
- = new HashMap<ProtocolProviderService, PresenceStatus>();
-
- /**
- * Listens for idle events.
- */
- private IdleListener idleListener = null;
-
- /**
- * Creates AutoAway handler.
- */
- public AutoAwayWatcher()
- {
- if (Preferences.isEnabled())
- {
- start();
- }
-
- Preferences.addEnableChangeListener(
- new PropertyChangeListener()
- {
- public void propertyChange(PropertyChangeEvent evt)
- {
- if(Boolean.parseBoolean((String) evt.getNewValue()))
- start();
- else
- stopInner();
- }
- }
- );
-
- // listens for changes in configured value.
- Preferences.addTimerChangeListener(
- new PropertyChangeListener()
- {
- public void propertyChange(PropertyChangeEvent evt)
- {
- stopInner();
- start();
- }
- }
- );
- }
-
- /**
- * Starts and add needed listeners.
- */
- private void start()
- {
- if(idleListener == null)
- {
-
- idleListener = new IdleListener();
-
- SystemActivityNotificationsService
- systemActivityNotificationsService
- = getSystemActivityNotificationsService();
-
- systemActivityNotificationsService.addIdleSystemChangeListener(
- Preferences.getTimer() * 60 * 1000,
- idleListener);
- systemActivityNotificationsService
- .addSystemActivityChangeListener(idleListener);
-
- startListeningForNewProviders();
- }
- }
-
- /**
- * Start listening for new providers and their registration states.
- */
- private void startListeningForNewProviders()
- {
- // listen for new providers
- GeneralConfigPluginActivator.bundleContext.addServiceListener(this);
-
- // lets check current providers
- ServiceReference[] protocolProviderRefs = null;
- try
- {
- protocolProviderRefs = GeneralConfigPluginActivator.bundleContext
- .getServiceReferences(ProtocolProviderService.class.getName(),
- null);
- }
- catch (InvalidSyntaxException ex)
- {
- // this shouldn't happen since we're providing no parameter string
- // but let's log just in case.
- logger.error(
- "Error while retrieving service refs", ex);
- return;
- }
-
- // in case we found any
- if (protocolProviderRefs != null)
- {
- for (int i = 0; i < protocolProviderRefs.length; i++)
- {
- ProtocolProviderService provider = (ProtocolProviderService)
- GeneralConfigPluginActivator.bundleContext
- .getService(protocolProviderRefs[i]);
-
- this.handleProviderAdded(provider);
- }
- }
- }
-
- /**
- * Stop listening for new providers and their registration states.
- */
- private void stopListeningForNewProviders()
- {
- // stop listen for new providers
- GeneralConfigPluginActivator.bundleContext.removeServiceListener(this);
-
- // lets check current providers and remove registration state listener
- ServiceReference[] protocolProviderRefs = null;
- try
- {
- protocolProviderRefs = GeneralConfigPluginActivator.bundleContext
- .getServiceReferences(ProtocolProviderService.class.getName(),
- null);
- }
- catch (InvalidSyntaxException ex)
- {
- // this shouldn't happen since we're providing no parameter string
- // but let's log just in case.
- logger.error(
- "Error while retrieving service refs", ex);
- return;
- }
-
- // in case we found any
- if (protocolProviderRefs != null)
- {
- for (int i = 0; i < protocolProviderRefs.length; i++)
- {
- ProtocolProviderService provider = (ProtocolProviderService)
- GeneralConfigPluginActivator.bundleContext
- .getService(protocolProviderRefs[i]);
-
- this.handleProviderRemoved(provider);
- }
- }
- }
-
- /**
- * Stops and removes the listeners.
- */
- public void stop()
- {
- GeneralConfigPluginActivator.bundleContext.removeServiceListener(this);
- stopInner();
- }
-
- /**
- * Stops and removes the listeners.
- */
- private void stopInner()
- {
- if(idleListener != null)
- {
- SystemActivityNotificationsService
- systemActivityNotificationsService
- = getSystemActivityNotificationsService();
-
- systemActivityNotificationsService.removeIdleSystemChangeListener(
- idleListener);
- systemActivityNotificationsService
- .removeSystemActivityChangeListener(idleListener);
-
- stopListeningForNewProviders();
-
- idleListener = null;
- }
- }
-
- /**
- * Change protocol to away saving status so it can be set again when
- * out of idle state.
- */
- private void changeProtocolsToAway()
- {
- for (ProtocolProviderService protocolProvider
- : GeneralConfigPluginActivator.getProtocolProviders())
- {
- OperationSetPresence presence
- = protocolProvider.getOperationSet(
- OperationSetPresence.class);
-
- if(presence == null)
- continue;
-
- PresenceStatus status = presence.getPresenceStatus();
-
- if (status.getStatus() < PresenceStatus.AVAILABLE_THRESHOLD)
- {
- // already (manually) set to away or lower
- continue;
- }
-
- PresenceStatus newStatus
- = StatusUpdateThread.findAwayStatus(presence);
-
- try
- {
- if (newStatus != null && !status.equals(newStatus))
- {
- addProviderToLastStates(protocolProvider, status);
-
- presence.publishPresenceStatus(
- newStatus,
- newStatus.getStatusName());
- }
- }
- catch (IllegalArgumentException e)
- {
- }
- catch (IllegalStateException e)
- {
- }
- catch (OperationFailedException e)
- {
- }
- }
- }
-
- /**
- * Back to status which was already saved before going to idle.
- */
- private void changeProtocolsToPreviousState()
- {
- for (ProtocolProviderService protocolProvider
- : GeneralConfigPluginActivator.getProtocolProviders())
- {
- PresenceStatus lastState = lastStates.get(protocolProvider);
-
- if (lastState != null)
- {
- OperationSetPresence presence
- = protocolProvider.getOperationSet(
- OperationSetPresence.class);
- try
- {
- presence.publishPresenceStatus(lastState, "");
- }
- catch (IllegalArgumentException e)
- {
- }
- catch (IllegalStateException e)
- {
- }
- catch (OperationFailedException e)
- {
- }
- removeProviderFromLastStates(protocolProvider);
- }
- }
- }
-
- /**
- * The SystemActivityNotifications Service.
- * @return the SystemActivityNotifications Service.
- */
- private SystemActivityNotificationsService
- getSystemActivityNotificationsService()
- {
- return
- ServiceUtils.getService(
- GeneralConfigPluginActivator.bundleContext,
- SystemActivityNotificationsService.class);
- }
-
- /**
- * When new protocol provider is registered we add our
- * registration change listener.
- * If unregistered remove reference to the provider and the
- * registration change listener.
- *
- * @param serviceEvent ServiceEvent
- */
- public void serviceChanged(ServiceEvent serviceEvent)
- {
- Object service
- = GeneralConfigPluginActivator.bundleContext.getService(
- serviceEvent.getServiceReference());
-
- // we don't care if the source service is not a protocol provider
- if (service instanceof ProtocolProviderService)
- {
- int serviceEventType = serviceEvent.getType();
-
- if (serviceEventType == ServiceEvent.REGISTERED)
- handleProviderAdded((ProtocolProviderService) service);
- else if (serviceEventType == ServiceEvent.UNREGISTERING)
- handleProviderRemoved((ProtocolProviderService) service);
- }
- }
-
- /**
- * Used to set registration state change listener.
- *
- * @param provider ProtocolProviderService
- */
- private synchronized void handleProviderAdded(
- ProtocolProviderService provider)
- {
- provider.addRegistrationStateChangeListener(this);
- }
-
- /**
- * Removes the registration change listener.
- *
- * @param provider the ProtocolProviderService that has been unregistered.
- */
- private void handleProviderRemoved(ProtocolProviderService provider)
- {
- provider.removeRegistrationStateChangeListener(this);
- }
-
- /**
- * Remove provider from list with last statuses.
- * If this is the last provider stop listening for idle events.
- * @param provider
- */
- private synchronized void removeProviderFromLastStates(
- ProtocolProviderService provider)
- {
- lastStates.remove(provider);
- }
-
- /**
- * Remember provider's last status, normally before setting it to away.
- * If needed start listening for idle events.
- * @param provider the provider.
- * @param status the status to save.
- */
- private synchronized void addProviderToLastStates(
- ProtocolProviderService provider,
- PresenceStatus status)
- {
- if(lastStates.size() == 0)
- start();
-
- lastStates.put(provider, status);
- }
-
- /**
- * Listens for provider states.
- * @param evt
- */
- public void registrationStateChanged(RegistrationStateChangeEvent evt)
- {
- if(evt.getSource() instanceof ProtocolProviderService)
- {
- if(evt.getNewState().equals(RegistrationState.UNREGISTERED)
- || evt.getNewState().equals(RegistrationState.CONNECTION_FAILED))
- {
- removeProviderFromLastStates(evt.getProvider());
- }
- else if(evt.getNewState().equals(
- RegistrationState.REGISTERED))
- {
- // we have at least one provider, so lets start listening
- if(lastStates.size() == 0)
- {
- start();
- }
- else
- {
- // or check are we away
- if(getSystemActivityNotificationsService()
- .getTimeSinceLastInput()
- > Preferences.getTimer()*60*1000)
- {
- // we are away, so update the newly registered provider
- // do it in new thread to give the provider
- // time dispatch his status
- new Thread(new Runnable()
- {
- public void run()
- {
- try{
- Thread.sleep(1000);
- }
- catch(Throwable t){}
-
- changeProtocolsToAway();
- }
- }).start();
- }
- }
- }
- }
- }
-
- /**
- * Listener waiting for idle state change.
- */
- private class IdleListener
- implements SystemActivityChangeListener
- {
- /**
- * Listens for activities and set corresponding statuses.
- *
- * @param event the <tt>NotificationActionTypeEvent</tt>, which is
- */
- public void activityChanged(SystemActivityEvent event)
- {
- switch(event.getEventID())
- {
- case SystemActivityEvent.EVENT_DISPLAY_SLEEP:
- case SystemActivityEvent.EVENT_SCREEN_LOCKED:
- case SystemActivityEvent.EVENT_SCREENSAVER_START:
- case SystemActivityEvent.EVENT_SYSTEM_IDLE:
- changeProtocolsToAway();
- break;
- case SystemActivityEvent.EVENT_DISPLAY_WAKE:
- case SystemActivityEvent.EVENT_SCREEN_UNLOCKED:
- case SystemActivityEvent.EVENT_SCREENSAVER_STOP:
- case SystemActivityEvent.EVENT_SYSTEM_IDLE_END:
- changeProtocolsToPreviousState();
- break;
- }
- }
- }
-}
+package net.java.sip.communicator.plugin.generalconfig.autoaway;
+
+import java.beans.*;
+import java.util.*;
+
+import net.java.sip.communicator.plugin.generalconfig.*;
+import net.java.sip.communicator.service.protocol.*;
+import net.java.sip.communicator.service.protocol.event.*;
+import net.java.sip.communicator.service.sysactivity.*;
+import net.java.sip.communicator.service.sysactivity.event.*;
+import net.java.sip.communicator.util.*;
+
+import org.osgi.framework.*;
+
+/**
+ * Listens for idle events from SystemActivityNotifications Service.
+ *
+ * @author Damian Minkov
+ */
+public class AutoAwayWatcher
+ implements ServiceListener,
+ RegistrationStateChangeListener
+{
+ /**
+ * The logger.
+ */
+ private static final Logger logger
+ = Logger.getLogger(AutoAwayWatcher.class);
+
+ /**
+ * The states of providers before going to away.
+ */
+ private final Map<ProtocolProviderService, PresenceStatus> lastStates
+ = new HashMap<ProtocolProviderService, PresenceStatus>();
+
+ /**
+ * Listens for idle events.
+ */
+ private IdleListener idleListener = null;
+
+ /**
+ * Creates AutoAway handler.
+ */
+ public AutoAwayWatcher()
+ {
+ if (Preferences.isEnabled())
+ {
+ start();
+ }
+
+ Preferences.addEnableChangeListener(
+ new PropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ if(Boolean.parseBoolean((String) evt.getNewValue()))
+ start();
+ else
+ stopInner();
+ }
+ }
+ );
+
+ // listens for changes in configured value.
+ Preferences.addTimerChangeListener(
+ new PropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ stopInner();
+ start();
+ }
+ }
+ );
+ }
+
+ /**
+ * Starts and add needed listeners.
+ */
+ private void start()
+ {
+ if(idleListener == null)
+ {
+
+ idleListener = new IdleListener();
+
+ SystemActivityNotificationsService
+ systemActivityNotificationsService
+ = getSystemActivityNotificationsService();
+
+ systemActivityNotificationsService.addIdleSystemChangeListener(
+ Preferences.getTimer() * 60 * 1000,
+ idleListener);
+ systemActivityNotificationsService
+ .addSystemActivityChangeListener(idleListener);
+
+ startListeningForNewProviders();
+ }
+ }
+
+ /**
+ * Start listening for new providers and their registration states.
+ */
+ private void startListeningForNewProviders()
+ {
+ // listen for new providers
+ GeneralConfigPluginActivator.bundleContext.addServiceListener(this);
+
+ // lets check current providers
+ ServiceReference[] protocolProviderRefs = null;
+ try
+ {
+ protocolProviderRefs = GeneralConfigPluginActivator.bundleContext
+ .getServiceReferences(ProtocolProviderService.class.getName(),
+ null);
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ // this shouldn't happen since we're providing no parameter string
+ // but let's log just in case.
+ logger.error(
+ "Error while retrieving service refs", ex);
+ return;
+ }
+
+ // in case we found any
+ if (protocolProviderRefs != null)
+ {
+ for (int i = 0; i < protocolProviderRefs.length; i++)
+ {
+ ProtocolProviderService provider = (ProtocolProviderService)
+ GeneralConfigPluginActivator.bundleContext
+ .getService(protocolProviderRefs[i]);
+
+ this.handleProviderAdded(provider);
+ }
+ }
+ }
+
+ /**
+ * Stop listening for new providers and their registration states.
+ */
+ private void stopListeningForNewProviders()
+ {
+ // stop listen for new providers
+ GeneralConfigPluginActivator.bundleContext.removeServiceListener(this);
+
+ // lets check current providers and remove registration state listener
+ ServiceReference[] protocolProviderRefs = null;
+ try
+ {
+ protocolProviderRefs = GeneralConfigPluginActivator.bundleContext
+ .getServiceReferences(ProtocolProviderService.class.getName(),
+ null);
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ // this shouldn't happen since we're providing no parameter string
+ // but let's log just in case.
+ logger.error(
+ "Error while retrieving service refs", ex);
+ return;
+ }
+
+ // in case we found any
+ if (protocolProviderRefs != null)
+ {
+ for (int i = 0; i < protocolProviderRefs.length; i++)
+ {
+ ProtocolProviderService provider = (ProtocolProviderService)
+ GeneralConfigPluginActivator.bundleContext
+ .getService(protocolProviderRefs[i]);
+
+ this.handleProviderRemoved(provider);
+ }
+ }
+ }
+
+ /**
+ * Stops and removes the listeners.
+ */
+ public void stop()
+ {
+ GeneralConfigPluginActivator.bundleContext.removeServiceListener(this);
+ stopInner();
+ }
+
+ /**
+ * Stops and removes the listeners.
+ */
+ private void stopInner()
+ {
+ if(idleListener != null)
+ {
+ SystemActivityNotificationsService
+ systemActivityNotificationsService
+ = getSystemActivityNotificationsService();
+
+ systemActivityNotificationsService.removeIdleSystemChangeListener(
+ idleListener);
+ systemActivityNotificationsService
+ .removeSystemActivityChangeListener(idleListener);
+
+ stopListeningForNewProviders();
+
+ idleListener = null;
+ }
+ }
+
+ /**
+ * Change protocol to away saving status so it can be set again when
+ * out of idle state.
+ */
+ private void changeProtocolsToAway()
+ {
+ for (ProtocolProviderService protocolProvider
+ : GeneralConfigPluginActivator.getProtocolProviders())
+ {
+ OperationSetPresence presence
+ = protocolProvider.getOperationSet(
+ OperationSetPresence.class);
+
+ if(presence == null)
+ continue;
+
+ PresenceStatus status = presence.getPresenceStatus();
+
+ if (status.getStatus() < PresenceStatus.AVAILABLE_THRESHOLD)
+ {
+ // already (manually) set to away or lower
+ continue;
+ }
+
+ PresenceStatus newStatus
+ = StatusUpdateThread.findAwayStatus(presence);
+
+ try
+ {
+ if (newStatus != null && !status.equals(newStatus))
+ {
+ addProviderToLastStates(protocolProvider, status);
+
+ presence.publishPresenceStatus(
+ newStatus,
+ newStatus.getStatusName());
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ catch (OperationFailedException e)
+ {
+ }
+ }
+ }
+
+ /**
+ * Back to status which was already saved before going to idle.
+ */
+ private void changeProtocolsToPreviousState()
+ {
+ for (ProtocolProviderService protocolProvider
+ : GeneralConfigPluginActivator.getProtocolProviders())
+ {
+ PresenceStatus lastState = lastStates.get(protocolProvider);
+
+ if (lastState != null)
+ {
+ OperationSetPresence presence
+ = protocolProvider.getOperationSet(
+ OperationSetPresence.class);
+ try
+ {
+ presence.publishPresenceStatus(lastState, "");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ catch (OperationFailedException e)
+ {
+ }
+ removeProviderFromLastStates(protocolProvider);
+ }
+ }
+ }
+
+ /**
+ * The SystemActivityNotifications Service.
+ * @return the SystemActivityNotifications Service.
+ */
+ private SystemActivityNotificationsService
+ getSystemActivityNotificationsService()
+ {
+ return
+ ServiceUtils.getService(
+ GeneralConfigPluginActivator.bundleContext,
+ SystemActivityNotificationsService.class);
+ }
+
+ /**
+ * When new protocol provider is registered we add our
+ * registration change listener.
+ * If unregistered remove reference to the provider and the
+ * registration change listener.
+ *
+ * @param serviceEvent ServiceEvent
+ */
+ public void serviceChanged(ServiceEvent serviceEvent)
+ {
+ Object service
+ = GeneralConfigPluginActivator.bundleContext.getService(
+ serviceEvent.getServiceReference());
+
+ // we don't care if the source service is not a protocol provider
+ if (service instanceof ProtocolProviderService)
+ {
+ int serviceEventType = serviceEvent.getType();
+
+ if (serviceEventType == ServiceEvent.REGISTERED)
+ handleProviderAdded((ProtocolProviderService) service);
+ else if (serviceEventType == ServiceEvent.UNREGISTERING)
+ handleProviderRemoved((ProtocolProviderService) service);
+ }
+ }
+
+ /**
+ * Used to set registration state change listener.
+ *
+ * @param provider ProtocolProviderService
+ */
+ private synchronized void handleProviderAdded(
+ ProtocolProviderService provider)
+ {
+ provider.addRegistrationStateChangeListener(this);
+ }
+
+ /**
+ * Removes the registration change listener.
+ *
+ * @param provider the ProtocolProviderService that has been unregistered.
+ */
+ private void handleProviderRemoved(ProtocolProviderService provider)
+ {
+ provider.removeRegistrationStateChangeListener(this);
+ }
+
+ /**
+ * Remove provider from list with last statuses.
+ * If this is the last provider stop listening for idle events.
+ * @param provider
+ */
+ private synchronized void removeProviderFromLastStates(
+ ProtocolProviderService provider)
+ {
+ lastStates.remove(provider);
+ }
+
+ /**
+ * Remember provider's last status, normally before setting it to away.
+ * If needed start listening for idle events.
+ * @param provider the provider.
+ * @param status the status to save.
+ */
+ private synchronized void addProviderToLastStates(
+ ProtocolProviderService provider,
+ PresenceStatus status)
+ {
+ if(lastStates.size() == 0)
+ start();
+
+ lastStates.put(provider, status);
+ }
+
+ /**
+ * Listens for provider states.
+ * @param evt
+ */
+ public void registrationStateChanged(RegistrationStateChangeEvent evt)
+ {
+ if(evt.getSource() instanceof ProtocolProviderService)
+ {
+ if(evt.getNewState().equals(RegistrationState.UNREGISTERED)
+ || evt.getNewState().equals(RegistrationState.CONNECTION_FAILED))
+ {
+ removeProviderFromLastStates(evt.getProvider());
+ }
+ else if(evt.getNewState().equals(
+ RegistrationState.REGISTERED))
+ {
+ // we have at least one provider, so lets start listening
+ if(lastStates.size() == 0)
+ {
+ start();
+ }
+ else
+ {
+ // or check are we away
+ if(getSystemActivityNotificationsService()
+ .getTimeSinceLastInput()
+ > Preferences.getTimer()*60*1000)
+ {
+ // we are away, so update the newly registered provider
+ // do it in new thread to give the provider
+ // time dispatch his status
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try{
+ Thread.sleep(1000);
+ }
+ catch(Throwable t){}
+
+ changeProtocolsToAway();
+ }
+ }).start();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Listener waiting for idle state change.
+ */
+ private class IdleListener
+ implements SystemActivityChangeListener
+ {
+ /**
+ * Listens for activities and set corresponding statuses.
+ *
+ * @param event the <tt>NotificationActionTypeEvent</tt>, which is
+ */
+ public void activityChanged(SystemActivityEvent event)
+ {
+ switch(event.getEventID())
+ {
+ case SystemActivityEvent.EVENT_DISPLAY_SLEEP:
+ case SystemActivityEvent.EVENT_SCREEN_LOCKED:
+ case SystemActivityEvent.EVENT_SCREENSAVER_START:
+ case SystemActivityEvent.EVENT_SYSTEM_IDLE:
+ changeProtocolsToAway();
+ break;
+ case SystemActivityEvent.EVENT_DISPLAY_WAKE:
+ case SystemActivityEvent.EVENT_SCREEN_UNLOCKED:
+ case SystemActivityEvent.EVENT_SCREENSAVER_STOP:
+ case SystemActivityEvent.EVENT_SYSTEM_IDLE_END:
+ changeProtocolsToPreviousState();
+ break;
+ }
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/Preferences.java b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/Preferences.java
index 148da25..bee52df 100644
--- a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/Preferences.java
+++ b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/Preferences.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,133 +15,133 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.plugin.generalconfig.autoaway;
-
-import net.java.sip.communicator.plugin.generalconfig.*;
-import org.jitsi.service.configuration.*;
-import org.jitsi.service.resources.*;
-
-import java.beans.*;
-
-/**
- * Preferences for the Status Update
- *
- * @author Thomas Hofer
- *
- */
-public final class Preferences
-{
- /**
- * Property indicating whether status change on away is enabled.
- */
- private static final String ENABLE
- = "net.java.sip.communicator.plugin.statusupdate.enable";
-
- /**
- * Property indicating the time in minutes to consider a pc in idle state.
- */
- private static final String TIMER
- = "net.java.sip.communicator.plugin.statusupdate.timer";
-
- /**
- * The default value to be displayed and to be considered
- * for {@link Preferences#TIMER}.
- */
- public static final int DEFAULT_TIMER = 15;
-
- /**
- * Whether change status on away is enabled.
- * @return whether change status on away is enabled.
- */
- static boolean isEnabled()
- {
- // if enabled start
- String enabledDefault
- = GeneralConfigPluginActivator.getResources().getSettingsString(
- Preferences.ENABLE);
-
- return
- GeneralConfigPluginActivator
- .getConfigurationService()
- .getBoolean(
- Preferences.ENABLE,
- Boolean.parseBoolean(enabledDefault));
- }
-
- /**
- * Returns the time in minutes to consider a pc in idle state.
- * @return the time in minutes to consider a pc in idle state.
- */
- static int getTimer()
- {
- ConfigurationService cfg
- = GeneralConfigPluginActivator.getConfigurationService();
- ResourceManagementService resources
- = GeneralConfigPluginActivator.getResources();
-
- String enabledDefault = resources.getSettingsString(Preferences.ENABLE);
-
- String timerDefaultStr = resources.getSettingsString(Preferences.TIMER);
- int timerDefault = DEFAULT_TIMER;
-
- if (timerDefaultStr != null)
- {
- try
- {
- timerDefault = Integer.parseInt(timerDefaultStr);
- }
- catch (NumberFormatException nfe)
- {
- }
- }
-
- return
- cfg.getBoolean(
- Preferences.ENABLE,
- Boolean.parseBoolean(enabledDefault))
- ? cfg.getInt(Preferences.TIMER, timerDefault)
- : 0;
- }
-
- /**
- * Save data in the configuration file
- * @param enabled is enabled
- * @param timer the time value to save
- */
- static void saveData(boolean enabled, String timer)
- {
- ConfigurationService cfg
- = GeneralConfigPluginActivator.getConfigurationService();
-
- cfg.setProperty(Preferences.ENABLE, Boolean.toString(enabled));
- cfg.setProperty(Preferences.TIMER, timer);
- }
-
- /**
- * Adds listener to detect property changes.
- * @param listener the listener to notify.
- */
- static void addEnableChangeListener(PropertyChangeListener listener)
- {
- // listens for changes in configuration enable/disable
- GeneralConfigPluginActivator
- .getConfigurationService()
- .addPropertyChangeListener(
- ENABLE,
- listener);
- }
-
- /**
- * Adds listener to detect timer property changes.
- * @param listener the listener to notify.
- */
- static void addTimerChangeListener(PropertyChangeListener listener)
- {
- // listens for changes in configuration enable/disable
- GeneralConfigPluginActivator
- .getConfigurationService()
- .addPropertyChangeListener(
- TIMER,
- listener);
- }
-}
+package net.java.sip.communicator.plugin.generalconfig.autoaway;
+
+import net.java.sip.communicator.plugin.generalconfig.*;
+import org.jitsi.service.configuration.*;
+import org.jitsi.service.resources.*;
+
+import java.beans.*;
+
+/**
+ * Preferences for the Status Update
+ *
+ * @author Thomas Hofer
+ *
+ */
+public final class Preferences
+{
+ /**
+ * Property indicating whether status change on away is enabled.
+ */
+ private static final String ENABLE
+ = "net.java.sip.communicator.plugin.statusupdate.enable";
+
+ /**
+ * Property indicating the time in minutes to consider a pc in idle state.
+ */
+ private static final String TIMER
+ = "net.java.sip.communicator.plugin.statusupdate.timer";
+
+ /**
+ * The default value to be displayed and to be considered
+ * for {@link Preferences#TIMER}.
+ */
+ public static final int DEFAULT_TIMER = 15;
+
+ /**
+ * Whether change status on away is enabled.
+ * @return whether change status on away is enabled.
+ */
+ static boolean isEnabled()
+ {
+ // if enabled start
+ String enabledDefault
+ = GeneralConfigPluginActivator.getResources().getSettingsString(
+ Preferences.ENABLE);
+
+ return
+ GeneralConfigPluginActivator
+ .getConfigurationService()
+ .getBoolean(
+ Preferences.ENABLE,
+ Boolean.parseBoolean(enabledDefault));
+ }
+
+ /**
+ * Returns the time in minutes to consider a pc in idle state.
+ * @return the time in minutes to consider a pc in idle state.
+ */
+ static int getTimer()
+ {
+ ConfigurationService cfg
+ = GeneralConfigPluginActivator.getConfigurationService();
+ ResourceManagementService resources
+ = GeneralConfigPluginActivator.getResources();
+
+ String enabledDefault = resources.getSettingsString(Preferences.ENABLE);
+
+ String timerDefaultStr = resources.getSettingsString(Preferences.TIMER);
+ int timerDefault = DEFAULT_TIMER;
+
+ if (timerDefaultStr != null)
+ {
+ try
+ {
+ timerDefault = Integer.parseInt(timerDefaultStr);
+ }
+ catch (NumberFormatException nfe)
+ {
+ }
+ }
+
+ return
+ cfg.getBoolean(
+ Preferences.ENABLE,
+ Boolean.parseBoolean(enabledDefault))
+ ? cfg.getInt(Preferences.TIMER, timerDefault)
+ : 0;
+ }
+
+ /**
+ * Save data in the configuration file
+ * @param enabled is enabled
+ * @param timer the time value to save
+ */
+ static void saveData(boolean enabled, String timer)
+ {
+ ConfigurationService cfg
+ = GeneralConfigPluginActivator.getConfigurationService();
+
+ cfg.setProperty(Preferences.ENABLE, Boolean.toString(enabled));
+ cfg.setProperty(Preferences.TIMER, timer);
+ }
+
+ /**
+ * Adds listener to detect property changes.
+ * @param listener the listener to notify.
+ */
+ static void addEnableChangeListener(PropertyChangeListener listener)
+ {
+ // listens for changes in configuration enable/disable
+ GeneralConfigPluginActivator
+ .getConfigurationService()
+ .addPropertyChangeListener(
+ ENABLE,
+ listener);
+ }
+
+ /**
+ * Adds listener to detect timer property changes.
+ * @param listener the listener to notify.
+ */
+ static void addTimerChangeListener(PropertyChangeListener listener)
+ {
+ // listens for changes in configuration enable/disable
+ GeneralConfigPluginActivator
+ .getConfigurationService()
+ .addPropertyChangeListener(
+ TIMER,
+ listener);
+ }
+}