[KOE-89] Improved handling of expired time-based Out-of-Office

This commit is contained in:
Patrick Simpson 2017-03-20 11:29:24 +01:00
parent 0fa8b2b949
commit 7700d68b47
2 changed files with 53 additions and 13 deletions

View File

@ -26,6 +26,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using static Acacia.DebugOptions;
namespace Acacia.Features.OutOfOffice namespace Acacia.Features.OutOfOffice
{ {
@ -34,6 +35,19 @@ namespace Acacia.Features.OutOfOffice
: :
Feature, FeatureWithRibbon Feature, FeatureWithRibbon
{ {
#region Debug options
[AcaciaOption("Enables or disables the handling of expired time-based Out-of-Office. If enabled (the default) " +
"an expired Out-of-Office is treated as disabled. Otherwise it's treated as enabled.")]
public bool IgnoreExpired
{
get { return GetOption(OPTION_IGNORE_EXPIRED); }
set { SetOption(OPTION_IGNORE_EXPIRED, value); }
}
private static readonly BoolOption OPTION_IGNORE_EXPIRED = new BoolOption("IgnoreExpired", true);
#endregion
private RibbonToggleButton _button; private RibbonToggleButton _button;
public FeatureOutOfOffice() public FeatureOutOfOffice()
@ -53,11 +67,29 @@ namespace Acacia.Features.OutOfOffice
caps.Add("ooftime"); caps.Add("ooftime");
} }
private static bool IsOOFEnabled(ActiveSync.SettingsOOF settings) internal bool IsOOFEnabled(ActiveSync.SettingsOOF settings)
{
return GetEffectiveState(settings) != ActiveSync.OOFState.Disabled;
}
internal ActiveSync.OOFState GetEffectiveState(ActiveSync.SettingsOOF settings)
{ {
if (settings == null) if (settings == null)
return false; return ActiveSync.OOFState.Disabled;
return settings.State != ActiveSync.OOFState.Disabled;
if (settings.State == ActiveSync.OOFState.Disabled)
return ActiveSync.OOFState.Disabled;
// If there's a time-based OOF, and it has expired, OOF if effectively disabled
if (settings.State == ActiveSync.OOFState.EnabledTimeBased && IgnoreExpired)
{
if (settings.Till != null && settings.Till.Value.CompareTo(DateTime.Now) < 0)
{
return ActiveSync.OOFState.Disabled;
}
}
return settings.State;
} }
private void Watcher_ZPushAccountChange(ZPushAccount account) private void Watcher_ZPushAccountChange(ZPushAccount account)
@ -135,7 +167,7 @@ namespace Acacia.Features.OutOfOffice
{ {
// Show dialog // Show dialog
if (new OutOfOfficeDialog(account, settings).ShowDialog() != DialogResult.OK) if (new OutOfOfficeDialog(this, account, settings).ShowDialog() != DialogResult.OK)
return; return;
try try
@ -229,7 +261,7 @@ namespace Acacia.Features.OutOfOffice
StoreOOFSettings(account, oof); StoreOOFSettings(account, oof);
// Show a message if OOF is enabled // Show a message if OOF is enabled
if (oof.State != ActiveSync.OOFState.Disabled) if (IsOOFEnabled(oof))
{ {
if (MessageBox.Show( if (MessageBox.Show(
string.Format(Properties.Resources.OOFStartup_Message, account.Account.SmtpAddress), string.Format(Properties.Resources.OOFStartup_Message, account.Account.SmtpAddress),

View File

@ -34,9 +34,13 @@ namespace Acacia.Features.OutOfOffice
public partial class OutOfOfficeDialog : KopanoDialog public partial class OutOfOfficeDialog : KopanoDialog
{ {
private ActiveSync.SettingsOOF _settings; private ActiveSync.SettingsOOF _settings;
private readonly bool haveTimes; private readonly bool _haveTimes;
/// <summary>
/// Set if an old date is fetched from the settings. In this case, the date limit is relaxed to allow setting it.
/// </summary>
private readonly bool _haveOldDate;
public OutOfOfficeDialog(ZPushAccount account, ActiveSync.SettingsOOF settings) public OutOfOfficeDialog(FeatureOutOfOffice owner, ZPushAccount account, ActiveSync.SettingsOOF settings)
{ {
this._settings = settings; this._settings = settings;
@ -64,14 +68,14 @@ namespace Acacia.Features.OutOfOffice
radioTime_CheckedChanged(radioTime, null); radioTime_CheckedChanged(radioTime, null);
// Hide time options, only if it is known that these are not supported // Hide time options, only if it is known that these are not supported
haveTimes = _settings.SupportsTimes != false; _haveTimes = _settings.SupportsTimes != false;
if (!haveTimes) if (!_haveTimes)
{ {
tableDates.Visible = false; tableDates.Visible = false;
} }
// Load settings // Load settings
switch(settings.State) switch(owner.GetEffectiveState(settings))
{ {
case ActiveSync.OOFState.Disabled: case ActiveSync.OOFState.Disabled:
chkEnable.Checked = false; chkEnable.Checked = false;
@ -83,8 +87,11 @@ namespace Acacia.Features.OutOfOffice
case ActiveSync.OOFState.EnabledTimeBased: case ActiveSync.OOFState.EnabledTimeBased:
chkEnable.Checked = true; chkEnable.Checked = true;
radioTime.Checked = true; radioTime.Checked = true;
_haveOldDate = settings.Till.Value.CompareTo(DateTime.Today) <= 0;
dateFrom.Value = settings.From.Value; dateFrom.Value = settings.From.Value;
timeFrom.Value = settings.From.Value; timeFrom.Value = settings.From.Value;
dateTill.Value = settings.Till.Value; dateTill.Value = settings.Till.Value;
timeTill.Value = settings.Till.Value; timeTill.Value = settings.Till.Value;
break; break;
@ -116,7 +123,7 @@ namespace Acacia.Features.OutOfOffice
if (chkEnable.Checked) if (chkEnable.Checked)
{ {
if (radioNoTime.Checked || !haveTimes) if (radioNoTime.Checked || !_haveTimes)
{ {
_settings.State = ActiveSync.OOFState.Enabled; _settings.State = ActiveSync.OOFState.Enabled;
} }
@ -174,8 +181,9 @@ namespace Acacia.Features.OutOfOffice
private void SetTillTimeLimit() private void SetTillTimeLimit()
{ {
// Don't allow setting till to before from, or before now // Don't allow setting till to before from, or before now (unless we got an old date from the server).
dateTill.MinDate = new DateTime(Math.Max(dateFrom.Value.Ticks, DateTime.Today.Ticks)); DateTime minDate = _haveOldDate ? dateFrom.Value : new DateTime(Math.Max(dateFrom.Value.Ticks, DateTime.Today.Ticks));
dateTill.MinDate = minDate;
if (dateTill.Value.Date == dateFrom.Value.Date) if (dateTill.Value.Date == dateFrom.Value.Date)
{ {