From e98240ab472137ec39f82827541a5ea26761b355 Mon Sep 17 00:00:00 2001
From: Patrick Simpson
Date: Mon, 27 Feb 2017 13:51:42 +0100
Subject: [PATCH] [KOE-17] Added settings dialog with resynchronise button.
Added option to overwrite local signatures.
---
.../AcaciaZPushPlugin.csproj | 9 +
.../Features/Signatures/FeatureSignatures.cs | 86 ++++--
.../Signatures/SignaturesSettings.Designer.cs | 79 ++++++
.../Features/Signatures/SignaturesSettings.cs | 84 ++++++
.../Signatures/SignaturesSettings.resx | 252 ++++++++++++++++++
.../Properties/Resources.Designer.cs | 27 ++
.../Properties/Resources.resx | 9 +
.../AcaciaZPushPlugin/UI/SettingsDialog.resx | 41 +--
8 files changed, 542 insertions(+), 45 deletions(-)
create mode 100644 src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.Designer.cs
create mode 100644 src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.cs
create mode 100644 src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.resx
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj
index fb76988..69353fd 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj
@@ -275,6 +275,12 @@
+
+ UserControl
+
+
+ SignaturesSettings.cs
+
@@ -549,6 +555,9 @@
SharedFoldersDialog.cs
+
+ SignaturesSettings.cs
+
ResXFileCodeGenerator
Resources.Designer.cs
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/FeatureSignatures.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/FeatureSignatures.cs
index 32faec6..4d0fc38 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/FeatureSignatures.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/FeatureSignatures.cs
@@ -17,6 +17,7 @@ using Acacia.Features.GAB;
/// Consult LICENSE file for details
using Acacia.Stubs;
using Acacia.Stubs.OutlookWrappers;
+using Acacia.UI;
using Acacia.Utils;
using Acacia.ZPush;
using Acacia.ZPush.Connect;
@@ -39,6 +40,15 @@ namespace Acacia.Features.Signatures
{
#region Debug options
+ [AcaciaOption("If set, the local signature is always set to the server signature. If not set, the local signature will be set " +
+ "only if it is unspecified. ")]
+ public bool AlwaysSetLocal
+ {
+ get { return GetOption(OPTION_ALWAYS_SET_LOCAL); }
+ set { SetOption(OPTION_ALWAYS_SET_LOCAL, value); }
+ }
+ private static readonly BoolOption OPTION_ALWAYS_SET_LOCAL = new BoolOption("AlwaysSetLocal", false);
+
[AcaciaOption("The format for local names of synchronised signatures, to prevent overwriting local signatures. May contain %account% and %name%.")]
public string SignatureLocalName
{
@@ -93,29 +103,49 @@ namespace Acacia.Features.Signatures
}
}
+
+ internal void ResyncAll()
+ {
+ foreach(ZPushAccount account in Watcher.Accounts.GetAccounts())
+ {
+ if (account.Confirmed == ZPushAccount.ConfirmationType.IsZPush)
+ {
+ SyncSignatures(account, null);
+ }
+ }
+ }
+
+ ///
+ /// Syncs the signatures for the account.
+ ///
+ /// The account
+ /// The signature hash. If null, the hash will not be checked and a hard sync will be done.
private void SyncSignatures(ZPushAccount account, string serverSignatureHash)
{
if (!account.Capabilities.Has("signatures"))
return;
- Logger.Instance.Trace(this, "Checking signature hash for account {0}: {1}", account, serverSignatureHash);
+ // Check hash if needed
+ if (serverSignatureHash != null)
+ {
+ Logger.Instance.Trace(this, "Checking signature hash for account {0}: {1}", account, serverSignatureHash);
+ if (serverSignatureHash == account.Account.LocalSignaturesHash)
+ return;
+ }
// Fetch signatures if there is a change
- if (serverSignatureHash != account.Account.LocalSignaturesHash)
+ try
{
- try
- {
- Logger.Instance.Debug(this, "Updating signatures: {0}", account);
- FetchSignatures(account);
+ Logger.Instance.Debug(this, "Updating signatures: {0}", account);
+ string hash = FetchSignatures(account);
- // Store updated hash
- account.Account.LocalSignaturesHash = serverSignatureHash;
- Logger.Instance.Debug(this, "Updated signatures: {0}", account);
- }
- catch (Exception e)
- {
- Logger.Instance.Error(this, "Error fetching signatures: {0}: {1}", account, e);
- }
+ // Store updated hash
+ account.Account.LocalSignaturesHash = hash;
+ Logger.Instance.Debug(this, "Updated signatures: {0}: {1}", account, hash);
+ }
+ catch (Exception e)
+ {
+ Logger.Instance.Error(this, "Error fetching signatures: {0}: {1}", account, e);
}
}
@@ -146,7 +176,12 @@ namespace Acacia.Features.Signatures
{
}
- private void FetchSignatures(ZPushAccount account)
+ ///
+ /// Fetches the signatures for the account.
+ ///
+ /// The account.
+ /// The signature hash
+ private string FetchSignatures(ZPushAccount account)
{
Logger.Instance.Debug(this, "Fetching signatures for account {0}", account);
using (ZPushConnection connection = account.Connect())
@@ -166,17 +201,25 @@ namespace Acacia.Features.Signatures
}
// Set default signatures if available and none are set
- if (!string.IsNullOrEmpty(result.new_message) && string.IsNullOrEmpty(account.Account.SignatureNewMessage))
+ if (!string.IsNullOrEmpty(result.new_message) && ShouldSetSignature(account.Account.SignatureNewMessage))
{
account.Account.SignatureNewMessage = fullNames[result.new_message];
}
- if (!string.IsNullOrEmpty(result.replyforward_message) && string.IsNullOrEmpty(account.Account.SignatureReplyForwardMessage))
+ if (!string.IsNullOrEmpty(result.replyforward_message) && ShouldSetSignature(account.Account.SignatureReplyForwardMessage))
{
account.Account.SignatureReplyForwardMessage = fullNames[result.replyforward_message];
}
+
+ return result.hash;
}
}
+ private bool ShouldSetSignature(string currentSignature)
+ {
+ return string.IsNullOrEmpty(currentSignature) || AlwaysSetLocal;
+ }
+
+
#endregion
private string StoreSignature(ISignatures signatures, ZPushAccount account, Signature signatureInfo)
@@ -334,5 +377,14 @@ namespace Acacia.Features.Signatures
}
}
}
+
+ #region Settings
+
+ public override FeatureSettings GetSettings()
+ {
+ return new SignaturesSettings(this);
+ }
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.Designer.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.Designer.cs
new file mode 100644
index 0000000..9740c08
--- /dev/null
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.Designer.cs
@@ -0,0 +1,79 @@
+namespace Acacia.Features.Signatures
+{
+ partial class SignaturesSettings
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SignaturesSettings));
+ this._layout = new System.Windows.Forms.TableLayoutPanel();
+ this.checkForceSet = new System.Windows.Forms.CheckBox();
+ this.buttonResync = new System.Windows.Forms.Button();
+ this._layout.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // _layout
+ //
+ resources.ApplyResources(this._layout, "_layout");
+ this._layout.Controls.Add(this.checkForceSet, 0, 0);
+ this._layout.Controls.Add(this.buttonResync, 0, 1);
+ this._layout.Name = "_layout";
+ //
+ // checkForceSet
+ //
+ resources.ApplyResources(this.checkForceSet, "checkForceSet");
+ this.checkForceSet.Name = "checkForceSet";
+ this.checkForceSet.UseVisualStyleBackColor = true;
+ this.checkForceSet.CheckedChanged += new System.EventHandler(this.checkForceSet_CheckedChanged);
+ //
+ // buttonResync
+ //
+ resources.ApplyResources(this.buttonResync, "buttonResync");
+ this.buttonResync.Name = "buttonResync";
+ this.buttonResync.UseVisualStyleBackColor = true;
+ this.buttonResync.Click += new System.EventHandler(this.buttonResync_Click);
+ //
+ // SignaturesSettings
+ //
+ resources.ApplyResources(this, "$this");
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.BackColor = System.Drawing.SystemColors.Window;
+ this.Controls.Add(this._layout);
+ this.Name = "SignaturesSettings";
+ this._layout.ResumeLayout(false);
+ this._layout.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TableLayoutPanel _layout;
+ private System.Windows.Forms.CheckBox checkForceSet;
+ private System.Windows.Forms.Button buttonResync;
+ }
+}
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.cs
new file mode 100644
index 0000000..87ad446
--- /dev/null
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.cs
@@ -0,0 +1,84 @@
+/// Copyright 2016 Kopano b.v.
+///
+/// This program is free software: you can redistribute it and/or modify
+/// it under the terms of the GNU Affero General Public License, version 3,
+/// as published by the Free Software Foundation.
+///
+/// This program is distributed in the hope that it will be useful,
+/// but WITHOUT ANY WARRANTY; without even the implied warranty of
+/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
+/// GNU Affero General Public License for more details.
+///
+/// You should have received a copy of the GNU Affero General Public License
+/// along with this program.If not, see.
+///
+/// Consult LICENSE file for details
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Acacia.ZPush;
+using Acacia.UI;
+
+namespace Acacia.Features.Signatures
+{
+ public partial class SignaturesSettings : FeatureSettings
+ {
+ private readonly FeatureSignatures _feature;
+ public override Feature Feature
+ {
+ get
+ {
+ return _feature;
+ }
+ }
+
+ public SignaturesSettings(FeatureSignatures feature = null)
+ {
+ this._feature = feature;
+
+ InitializeComponent();
+
+ // Allow null feature for designer
+ if (feature != null)
+ {
+ checkForceSet.Checked = feature.AlwaysSetLocal;
+ }
+ }
+
+ override public void Apply()
+ {
+ }
+
+ private void CheckDirty()
+ {
+ Dirty = false;
+ }
+
+ private void buttonResync_Click(object sender, EventArgs e)
+ {
+ if (_feature != null)
+ {
+ ProgressDialog.Execute("SignaturesSync",
+ (ct) =>
+ {
+ _feature.ResyncAll();
+ return 0;
+ }
+ );
+ }
+ }
+
+ private void checkForceSet_CheckedChanged(object sender, EventArgs e)
+ {
+ if (_feature != null)
+ _feature.AlwaysSetLocal = checkForceSet.Checked;
+ }
+ }
+}
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.resx b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.resx
new file mode 100644
index 0000000..49becf8
--- /dev/null
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Signatures/SignaturesSettings.resx
@@ -0,0 +1,252 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+
+ True
+
+
+
+ GrowAndShrink
+
+
+ 1
+
+
+ True
+
+
+ Fill
+
+
+
+ 4, 4
+
+
+ 4, 4, 4, 4
+
+
+ 152, 17
+
+
+ 0
+
+
+ Override local signatures
+
+
+ checkForceSet
+
+
+ System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ _layout
+
+
+ 0
+
+
+ True
+
+
+ 3, 28
+
+
+ 8, 0, 8, 0
+
+
+ 154, 23
+
+
+ 1
+
+
+ Resynchronise signatures
+
+
+ buttonResync
+
+
+ System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ _layout
+
+
+ 1
+
+
+ Fill
+
+
+ 0, 0
+
+
+ 2, 2, 2, 2
+
+
+ 2
+
+
+ 160, 54
+
+
+ 0
+
+
+ _layout
+
+
+ System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ $this
+
+
+ 0
+
+
+ <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="checkForceSet" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="buttonResync" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100,Absolute,20" /><Rows Styles="AutoSize,0,AutoSize,0" /></TableLayoutSettings>
+
+
+ True
+
+
+ 6, 13
+
+
+ True
+
+
+ GrowAndShrink
+
+
+ 2, 2, 2, 2
+
+
+ 160, 54
+
+
+ SignaturesSettings
+
+
+ Acacia.UI.FeatureSettings, Kopano, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null
+
+
\ No newline at end of file
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.Designer.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.Designer.cs
index 204b24a..ae43403 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.Designer.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.Designer.cs
@@ -132,6 +132,15 @@ namespace Acacia.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Signatures.
+ ///
+ internal static string Feature_Signatures {
+ get {
+ return ResourceManager.GetString("Feature_Signatures", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Address Book for {0}.
///
@@ -1019,6 +1028,24 @@ namespace Acacia.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to The signatures are being synchronised..
+ ///
+ internal static string SignaturesSync_Label {
+ get {
+ return ResourceManager.GetString("SignaturesSync_Label", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Signatures.
+ ///
+ internal static string SignaturesSync_Title {
+ get {
+ return ResourceManager.GetString("SignaturesSync_Title", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to There is an error with the security certificate for server {0}. Do you want to allow the connection anyway?.
///
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.resx b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.resx
index a8eb0c0..c75b51b 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.resx
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Properties/Resources.resx
@@ -445,4 +445,13 @@
Password unavailable
+
+ Signatures
+
+
+ The signatures are being synchronised.
+
+
+ Signatures
+
\ No newline at end of file
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/SettingsDialog.resx b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/SettingsDialog.resx
index fae433e..65262a9 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/SettingsDialog.resx
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/SettingsDialog.resx
@@ -126,14 +126,10 @@
- 358, 4
-
-
-
- 4, 4, 4, 4
+ 269, 3
- 100, 33
+ 75, 27
0
@@ -157,13 +153,10 @@
True
- 250, 4
-
-
- 4, 4, 4, 4
+ 188, 3
- 100, 33
+ 75, 27
1
@@ -187,13 +180,10 @@
True
- 142, 4
-
-
- 4, 4, 4, 4
+ 107, 3
- 100, 33
+ 75, 27
2
@@ -213,6 +203,7 @@
2
+
Bottom
@@ -220,16 +211,13 @@
RightToLeft
- 0, 394
-
-
- 4, 4, 4, 4
+ 0, 374
- 0, 0, 7, 0
+ 0, 0, 5, 0
- 469, 37
+ 352, 30
0
@@ -250,16 +238,13 @@
True
- 8, 16
+ 6, 13
True
- 469, 431
-
-
- 4, 4, 4, 4
+ 352, 404
CenterParent
@@ -271,6 +256,6 @@
SettingsDialog
- System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ Acacia.UI.KopanoDialog, Kopano, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null
\ No newline at end of file