1
0
mirror of https://github.com/Kopano-dev/kopano-ol-extension.git synced 2023-10-10 13:37:40 +02:00
This commit is contained in:
Patrick Simpson 2017-03-22 11:08:37 +01:00
commit 0c254f44d0
2 changed files with 53 additions and 13 deletions

View File

@ -26,6 +26,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Acacia.DebugOptions;
namespace Acacia.Features.OutOfOffice
{
@ -34,6 +35,19 @@ namespace Acacia.Features.OutOfOffice
:
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;
public FeatureOutOfOffice()
@ -53,11 +67,29 @@ namespace Acacia.Features.OutOfOffice
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)
return false;
return settings.State != ActiveSync.OOFState.Disabled;
return 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)
@ -135,7 +167,7 @@ namespace Acacia.Features.OutOfOffice
{
// Show dialog
if (new OutOfOfficeDialog(account, settings).ShowDialog() != DialogResult.OK)
if (new OutOfOfficeDialog(this, account, settings).ShowDialog() != DialogResult.OK)
return;
try
@ -229,7 +261,7 @@ namespace Acacia.Features.OutOfOffice
StoreOOFSettings(account, oof);
// Show a message if OOF is enabled
if (oof.State != ActiveSync.OOFState.Disabled)
if (IsOOFEnabled(oof))
{
if (MessageBox.Show(
string.Format(Properties.Resources.OOFStartup_Message, account.Account.SmtpAddress),

View File

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