aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamian Minkov <damencho@jitsi.org>2012-09-03 15:24:12 +0000
committerDamian Minkov <damencho@jitsi.org>2012-09-03 15:24:12 +0000
commit51d8e560d0fa23a3143cff0f4ebd8b894e3db235 (patch)
tree5aa8217c325a568d072a2a49115893a66817e2cb
parent2836fe726f7d106c9bac9e3ae474e4c59d5b4c35 (diff)
downloadjitsi-51d8e560d0fa23a3143cff0f4ebd8b894e3db235.zip
jitsi-51d8e560d0fa23a3143cff0f4ebd8b894e3db235.tar.gz
jitsi-51d8e560d0fa23a3143cff0f4ebd8b894e3db235.tar.bz2
Changes extracting auto away configurations.
-rw-r--r--src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java3
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java2
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayConfigurationPanel.java48
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayWatcher.java23
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/autoaway/Preferences.java118
-rw-r--r--src/net/java/sip/communicator/plugin/generalconfig/autoaway/StatusUpdateThread.java33
6 files changed, 132 insertions, 95 deletions
diff --git a/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java b/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java
index f7b7a78..e8891ad 100644
--- a/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/sysactivity/SystemActivityNotificationsServiceImpl.java
@@ -186,7 +186,8 @@ public class SystemActivityNotificationsServiceImpl
{
synchronized (idleChangeListeners)
{
- if (!idleChangeListeners.containsKey(listener))
+ if (idleTime > 0
+ && !idleChangeListeners.containsKey(listener))
idleChangeListeners.put(listener, idleTime);
}
}
diff --git a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java
index f89971d..ca7b592 100644
--- a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java
+++ b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigPluginActivator.java
@@ -275,7 +275,7 @@ public class GeneralConfigPluginActivator
private static void startThread()
{
if (runner == null)
- runner = new AutoAwayWatcher(getConfigurationService());
+ runner = new AutoAwayWatcher();
}
/**
diff --git a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayConfigurationPanel.java b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayConfigurationPanel.java
index 8069997..891f537 100644
--- a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayConfigurationPanel.java
+++ b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayConfigurationPanel.java
@@ -32,12 +32,6 @@ public class AutoAwayConfigurationPanel
*/
private static final long serialVersionUID = 0L;
- /**
- * The default value to be displayed in {@link #timer} and to be considered
- * for {@link Preferences#TIMER}.
- */
- private static final int DEFAULT_TIMER = 15;
-
private JCheckBox enable;
private JSpinner timer;
@@ -87,7 +81,8 @@ public class AutoAwayConfigurationPanel
GeneralConfigPluginActivator.getResources()
.getI18NString("plugin.autoaway.AWAY_MINUTES")));
// Spinner
- timer = new JSpinner(new SpinnerNumberModel(DEFAULT_TIMER, 1, 180, 1));
+ timer = new JSpinner(new SpinnerNumberModel(
+ Preferences.DEFAULT_TIMER, 1, 180, 1));
timerPanel.add(timer);
timer.addChangeListener(new ChangeListener()
{
@@ -108,33 +103,12 @@ public class AutoAwayConfigurationPanel
*/
private void initValues()
{
- ConfigurationService configService
- = GeneralConfigPluginActivator.getConfigurationService();
- ResourceManagementService resources
- = GeneralConfigPluginActivator.getResources();
+ boolean enabled = Preferences.isEnabled();
- String enabledDefault = resources.getSettingsString(Preferences.ENABLE);
- String timerDefaultStr = resources.getSettingsString(Preferences.TIMER);
- int timerDefault = DEFAULT_TIMER;
+ this.enable.setSelected(enabled);
+ this.timer.setEnabled(enabled);
- if(timerDefaultStr != null)
- {
- try
- {
- timerDefault = Integer.parseInt(timerDefaultStr);
- }
- catch(NumberFormatException r){}
- }
-
- boolean e
- = configService.getBoolean(
- Preferences.ENABLE,
- Boolean.parseBoolean(enabledDefault));
- this.enable.setSelected(e);
- this.timer.setEnabled(e);
-
- int t = configService.getInt(Preferences.TIMER, timerDefault);
- this.timer.setValue(t);
+ this.timer.setValue(Preferences.getTimer());
}
/**
@@ -142,14 +116,6 @@ public class AutoAwayConfigurationPanel
*/
private void saveData()
{
- ConfigurationService configService
- = GeneralConfigPluginActivator.getConfigurationService();
-
- configService.setProperty(
- Preferences.ENABLE,
- Boolean.toString(enable.isSelected()));
- configService.setProperty(
- Preferences.TIMER,
- timer.getValue().toString());
+ Preferences.saveData(enable.isSelected(), timer.getValue().toString());
}
}
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 780f050..308fa62 100644
--- a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayWatcher.java
+++ b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/AutoAwayWatcher.java
@@ -47,25 +47,15 @@ public class AutoAwayWatcher
/**
* Creates AutoAway handler.
- * @param configurationService the config service.
*/
- public AutoAwayWatcher(ConfigurationService configurationService)
+ public AutoAwayWatcher()
{
- // if enabled start
- String enabledDefault
- = GeneralConfigPluginActivator.getResources().getSettingsString(
- Preferences.ENABLE);
-
- if (configurationService.getBoolean(
- Preferences.ENABLE,
- Boolean.parseBoolean(enabledDefault)))
+ if (Preferences.isEnabled())
{
start();
}
- // listens for changes in configuration enable/disable
- configurationService.addPropertyChangeListener(
- Preferences.ENABLE,
+ Preferences.addEnableChangeListener(
new PropertyChangeListener()
{
public void propertyChange(PropertyChangeEvent evt)
@@ -79,8 +69,7 @@ public class AutoAwayWatcher
);
// listens for changes in configured value.
- configurationService.addPropertyChangeListener(
- Preferences.TIMER,
+ Preferences.addTimerChangeListener(
new PropertyChangeListener()
{
public void propertyChange(PropertyChangeEvent evt)
@@ -107,7 +96,7 @@ public class AutoAwayWatcher
= getSystemActivityNotificationsService();
systemActivityNotificationsService.addIdleSystemChangeListener(
- StatusUpdateThread.getTimer() * 60 * 1000,
+ Preferences.getTimer() * 60 * 1000,
idleListener);
systemActivityNotificationsService
.addSystemActivityChangeListener(idleListener);
@@ -423,7 +412,7 @@ public class AutoAwayWatcher
// or check are we away
if(getSystemActivityNotificationsService()
.getTimeSinceLastInput()
- > StatusUpdateThread.getTimer()*60*1000)
+ > Preferences.getTimer()*60*1000)
{
// we are away, so update the newly registered provider
// do it in new thread to give the provider
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 80faf2a..3e8b6c2 100644
--- a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/Preferences.java
+++ b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/Preferences.java
@@ -6,6 +6,12 @@
*/
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
*
@@ -14,8 +20,114 @@ package net.java.sip.communicator.plugin.generalconfig.autoaway;
*/
public final class Preferences
{
- public static final String ENABLE =
+ /**
+ * Property indicating whether status change on away is enabled.
+ */
+ private static final String ENABLE =
"net.java.sip.communicator.plugin.statusupdate.enable";
- public static final String TIMER =
+
+ /**
+ * 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 configService
+ = GeneralConfigPluginActivator.getConfigurationService();
+ ResourceManagementService resources
+ = GeneralConfigPluginActivator.getResources();
+
+ String enabledDefault = resources.getSettingsString(Preferences.ENABLE);
+
+ String timerDefaultStr = resources.getSettingsString(Preferences.TIMER);
+ int timerDefault = 0;
+
+ if (timerDefaultStr != null)
+ {
+ try
+ {
+ timerDefault = Integer.parseInt(timerDefaultStr);
+ }
+ catch (NumberFormatException r)
+ {
+ }
+ }
+ else
+ timerDefault = DEFAULT_TIMER;
+
+ return
+ configService.getBoolean(
+ Preferences.ENABLE,
+ Boolean.parseBoolean(enabledDefault))
+ ? configService.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 configService
+ = GeneralConfigPluginActivator.getConfigurationService();
+
+ configService.setProperty(
+ Preferences.ENABLE,
+ Boolean.toString(enabled));
+ configService.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);
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/StatusUpdateThread.java b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/StatusUpdateThread.java
index 749de02..908e99f 100644
--- a/src/net/java/sip/communicator/plugin/generalconfig/autoaway/StatusUpdateThread.java
+++ b/src/net/java/sip/communicator/plugin/generalconfig/autoaway/StatusUpdateThread.java
@@ -77,7 +77,7 @@ public class StatusUpdateThread
lastStates.remove(protocolProviderService);
}
}
- timer = getTimer() * 1000 * 60;
+ timer = Preferences.getTimer() * 1000 * 60;
} else
{
// position has not changed!
@@ -168,37 +168,6 @@ public class StatusUpdateThread
return status;
}
- static int getTimer()
- {
- ConfigurationService configService
- = GeneralConfigPluginActivator.getConfigurationService();
- ResourceManagementService resources
- = GeneralConfigPluginActivator.getResources();
-
- String enabledDefault = resources.getSettingsString(Preferences.ENABLE);
-
- String timerDefaultStr = resources.getSettingsString(Preferences.TIMER);
- int timerDefault = 0;
-
- if (timerDefaultStr != null)
- {
- try
- {
- timerDefault = Integer.parseInt(timerDefaultStr);
- }
- catch (NumberFormatException r)
- {
- }
- }
-
- return
- configService.getBoolean(
- Preferences.ENABLE,
- Boolean.parseBoolean(enabledDefault))
- ? configService.getInt(Preferences.TIMER, timerDefault)
- : 0;
- }
-
public boolean isRunning()
{
return run;