1
0
mirror of https://github.com/Kopano-dev/kopano-ol-extension.git synced 2023-10-10 11:37:40 +00:00

[KOE-124] Implemented removing of shared stores

This commit is contained in:
Patrick Simpson 2017-12-07 16:08:31 +02:00
parent 96e4c37450
commit 1b6dabff05
9 changed files with 133 additions and 15 deletions

View File

@ -449,9 +449,41 @@ namespace Acacia.Features.SharedFolders
MessageBoxButtons.OK,
MessageBoxIcon.Warning
);
//folder.Delete();
// TODO: is this used?
}
#endregion
public void RemoveSharedStore(ZPushAccount account, GABUser shareUser)
{
// Find the store
Logger.Instance.Trace(this, "Request to remove shared store: {0} - {1}", account, shareUser.UserName);
ZPushAccount share = account.FindSharedAccount(shareUser.UserName);
if (share == null)
{
Logger.Instance.Warning(this, "Shared store not found: {0} - {1}", account, shareUser.UserName);
return;
}
Logger.Instance.Trace(this, "Removing shared store: {0} - {1}", account, share);
try
{
string path = share.Account.BackingFilePath;
ThisAddIn.Instance.Stores.RemoveStore(share.Account.Store);
// Clean up the .ost
// TODO: this always fails
/*if (path != null && path.EndsWith(".ost"))
{
Logger.Instance.Trace(this, "Removing .ost: {0}", path);
System.IO.File.Delete(path);
}*/
}
catch(Exception e)
{
Logger.Instance.Error(this, "Error removing shared store: {0}: {1}", share, e);
}
}
}
}

View File

@ -288,15 +288,7 @@ namespace Acacia.Features.SharedFolders
ctx.AddBusy(-state.folders);
if (state.folders != 0)
{
// Sync account
_account.Account.SendReceive();
// Show success
ShowCompletion(Properties.Resources.SharedFolders_Applying_Success);
}
// Handle stores
if (state.stores.Count > 0)
{
List<StoreTreeNode> add = new List<StoreTreeNode>();
@ -312,7 +304,9 @@ namespace Acacia.Features.SharedFolders
else
{
// Remove it
_feature.RemoveSharedStore(store.User);
_feature.RemoveSharedStore(_account, store.User);
store.IsShared = false;
WholeStoreShareChanged(store);
}
}
@ -321,8 +315,8 @@ namespace Acacia.Features.SharedFolders
if (add.Count > 0)
{
bool restart = MessageBox.Show(ThisAddIn.Instance.Window,
"Outlook will be restarted to open the new stores",
"Open stores",
Properties.Resources.SharedFolders_WholeStoreRestart_Body,
Properties.Resources.SharedFolders_WholeStoreRestart_Title,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Information
) == DialogResult.OK;
@ -341,6 +335,21 @@ namespace Acacia.Features.SharedFolders
restarter.OpenShare(_account, node.User);
restarter.Restart();
}
// Update UI state
foreach (StoreTreeNode storeNode in _userFolders.Values)
storeNode.ChangesApplied();
CheckDirty();
if (state.folders != 0)
{
// Sync account
_account.Account.SendReceive();
// Show success
ShowCompletion(Properties.Resources.SharedFolders_Applying_Success);
}
}
}, true)
.OnError((x) =>
@ -656,9 +665,11 @@ namespace Acacia.Features.SharedFolders
if (_optionWholeStoreNodes.Count > 0)
{
bool isShared = _optionWholeStoreNodes.First().WantShare;
bool wasShared = _optionWholeStoreNodes.First().IsShared;
if (_optionWholeStoreNodes.All(x => x.WantShare == isShared))
{
OptionWholeStore = isShared ? CheckState.Checked : CheckState.Unchecked;
checkWholeStore.ThreeState = false;
}
else
@ -666,6 +677,8 @@ namespace Acacia.Features.SharedFolders
OptionWholeStore = CheckState.Indeterminate;
checkWholeStore.ThreeState = true;
}
_labelRestartRequired.Visible = isShared && !wasShared;
}
}

View File

@ -47,7 +47,19 @@ namespace Acacia.Features.SharedFolders
private readonly GABUser _user;
public readonly bool IsReadOnly;
public readonly bool IsShared;
private bool _isShared;
public bool IsShared
{
get { return _isShared; }
set
{
if (value != _isShared)
{
_isShared = value;
}
}
}
public StoreTreeNode(SharedFoldersManager folders, GABHandler gab, GABUser user, string text,
Dictionary<BackendId, SharedFolder> currentFolders, bool isShared)
@ -59,7 +71,7 @@ namespace Acacia.Features.SharedFolders
this._gab = gab;
this._user = user;
this.IsReadOnly = false;
this.IsShared = isShared;
this._isShared = isShared;
// Create an empty current state. When loading the nodes, the shares will be added. This has the benefit of
// cleaning up automatically any obsolote shares.

View File

@ -96,6 +96,8 @@ namespace Acacia
#endregion
public const string PR_PROFILE_OFFLINE_STORE_PATH_W = PROP + "6610" + PT_UNICODE;
#region Email specific
public const string PR_LAST_VERB_EXECUTED = PROP + "1081" + PT_LONG;

View File

@ -1175,6 +1175,24 @@ namespace Acacia.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Outlook will be restarted to open the new stores.
/// </summary>
internal static string SharedFolders_WholeStoreRestart_Body {
get {
return ResourceManager.GetString("SharedFolders_WholeStoreRestart_Body", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Open stores.
/// </summary>
internal static string SharedFolders_WholeStoreRestart_Title {
get {
return ResourceManager.GetString("SharedFolders_WholeStoreRestart_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The signatures are being synchronised..
/// </summary>

View File

@ -524,4 +524,10 @@
<value>The folder has been configured by your system administrator and cannot be modified.
Please contact your system administrator for any required changes.</value>
</data>
<data name="SharedFolders_WholeStoreRestart_Body" xml:space="preserve">
<value>Outlook will be restarted to open the new stores</value>
</data>
<data name="SharedFolders_WholeStoreRestart_Title" xml:space="preserve">
<value>Open stores</value>
</data>
</root>

View File

@ -44,5 +44,10 @@ namespace Acacia.Stubs
/// <param name="path">The path.</param>
/// <returns>The store. The caller is responsible for disposing.</returns>
IStore AddFileStore(string path);
/// <summary>
/// Removes the store
/// </summary>
void RemoveStore(IStore account);
}
}

View File

@ -231,6 +231,17 @@ namespace Acacia.Stubs.OutlookWrappers
}
}
public void RemoveStore(IStore store)
{
using (store)
using (ComRelease com = new ComRelease())
{
NSOutlook.NameSpace session = com.Add(_item.Session);
NSOutlook.MAPIFolder rootFolder = com.Add(((FolderWrapper)store.GetRootFolder()).RawItem);
session.RemoveStore(rootFolder);
}
}
public IEnumerator<IStore> GetEnumerator()
{
foreach (NSOutlook.Store store in IteratorStoresSafe())

View File

@ -264,6 +264,25 @@ namespace Acacia.ZPush
}
}
public ZPushAccount FindSharedAccount(string username)
{
if (ShareFor != null)
return null;
List<ZPushAccount> shares = new List<ZPushAccount>();
foreach (ZPushAccount account in _zPushAccounts.GetAccounts())
{
if (account == this)
continue;
if (account.ShareFor != null && account.ShareFor == this.Account.SmtpAddress &&
account.ShareUserName == username)
return account;
}
return null;
}
#endregion
}
}