mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
[KOE-14] Added possibility to set icon for folder, though this coomes out looking weird. Leaving for now.
This commit is contained in:
parent
4a57e014c2
commit
86dbc32b51
@ -296,6 +296,7 @@
|
||||
<Compile Include="Stubs\IItemEvents.cs" />
|
||||
<Compile Include="Stubs\IItems.cs" />
|
||||
<Compile Include="Stubs\IOutlookWindow.cs" />
|
||||
<Compile Include="Stubs\IPicture.cs" />
|
||||
<Compile Include="Stubs\IRecipient.cs" />
|
||||
<Compile Include="Stubs\IStores.cs" />
|
||||
<Compile Include="Stubs\ISyncObject.cs" />
|
||||
@ -308,6 +309,7 @@
|
||||
<Compile Include="Stubs\OutlookWrappers\ItemEventsWrapper.cs" />
|
||||
<Compile Include="Stubs\OutlookWrappers\ItemsWrapper.cs" />
|
||||
<Compile Include="Stubs\OutlookWrappers\OutlookItemWrapper.cs" />
|
||||
<Compile Include="Stubs\OutlookWrappers\PictureWrapper.cs" />
|
||||
<Compile Include="Stubs\OutlookWrappers\RecipientWrapper.cs" />
|
||||
<Compile Include="Stubs\OutlookWrappers\StoresWrapper.cs" />
|
||||
<Compile Include="Stubs\OutlookWrappers\SyncObjectWrapper.cs" />
|
||||
|
@ -22,6 +22,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -68,8 +69,7 @@ namespace Acacia.Features.SecondaryContacts
|
||||
|
||||
public override void Startup()
|
||||
{
|
||||
Watcher.WatchFolder(new FolderRegistrationSecondaryContacts(this),
|
||||
OnUnpatchedFolderDiscovered);
|
||||
Watcher.WatchFolder(new FolderRegistrationSecondaryContacts(this), OnUnpatchedFolderDiscovered);
|
||||
}
|
||||
|
||||
private void OnUnpatchedFolderDiscovered(IFolder folder)
|
||||
@ -93,7 +93,7 @@ namespace Acacia.Features.SecondaryContacts
|
||||
// Stage 1
|
||||
|
||||
// Sync type
|
||||
Logger.Instance.Trace(this, "Setting sync type");
|
||||
Logger.Instance.Trace(this, "Settin7g sync type");
|
||||
folder.SetProperty(OutlookConstants.PR_EAS_SYNCTYPE, (int)OutlookConstants.SyncType.UserContact);
|
||||
|
||||
// Container type
|
||||
@ -102,15 +102,42 @@ namespace Acacia.Features.SecondaryContacts
|
||||
|
||||
// Make it invisible.
|
||||
folder.AttrHidden = true;
|
||||
folder.Save();
|
||||
|
||||
Logger.Instance.Debug(this, "Patched secondary contacts folder: {0}", strippedName);
|
||||
// Register and show a warning, if not already done.
|
||||
// Note that patching may be done multiple times.
|
||||
if (!_warnedFolders.Contains(folder.EntryID))
|
||||
{
|
||||
_warnedFolders.Add(folder.EntryID);
|
||||
WarnRestart(folder);
|
||||
}
|
||||
// If _warnedFolders does not contain the folder (and it's hidden), this means Outlook was restarted.
|
||||
else if (!_warnedFolders.Contains(folder.EntryID))
|
||||
{
|
||||
// Stage 2
|
||||
|
||||
if (MessageBox.Show(StringUtil.GetResourceString("SecondaryContactsPatched_Body", strippedName),
|
||||
// Patch the name
|
||||
Logger.Instance.Trace(this, "Patching name");
|
||||
folder.Name = strippedName;
|
||||
|
||||
// Show it
|
||||
folder.AttrHidden = false;
|
||||
Logger.Instance.Debug(this, "Shown secondary contacts folder: {0}", strippedName);
|
||||
}
|
||||
Logger.Instance.Debug(this, "Patching done: {0}: {1}", strippedName, folder.AttrHidden);
|
||||
}
|
||||
|
||||
private DateTime? _lastWarning;
|
||||
|
||||
private void WarnRestart(IFolder folder)
|
||||
{
|
||||
// Register and show a warning, if not already done.
|
||||
// Note that patching may be done multiple times.
|
||||
if (!_warnedFolders.Contains(folder.EntryID))
|
||||
{
|
||||
_warnedFolders.Add(folder.EntryID);
|
||||
|
||||
// TODO: configurable constant for warning time
|
||||
if (_lastWarning == null || DateTime.Now - _lastWarning >= TimeSpan.FromHours(1))
|
||||
{
|
||||
_lastWarning = DateTime.Now;
|
||||
if (MessageBox.Show(StringUtil.GetResourceString("SecondaryContactsPatched_Body", folder.Name),
|
||||
StringUtil.GetResourceString("SecondaryContactsPatched_Title"),
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Warning
|
||||
@ -120,19 +147,6 @@ namespace Acacia.Features.SecondaryContacts
|
||||
}
|
||||
}
|
||||
}
|
||||
// If _warnedFolders does not contain the folder (and it's hidden), this means Outlook was restarted.
|
||||
else if (!_warnedFolders.Contains(folder.EntryID))
|
||||
{
|
||||
// Stage 2
|
||||
|
||||
// Patch the name
|
||||
Logger.Instance.Trace(this, "Patching name");
|
||||
folder.Name = strippedName;
|
||||
|
||||
// Show it
|
||||
folder.AttrHidden = false;
|
||||
Logger.Instance.Debug(this, "Shown secondary contacts folder: {0}", strippedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ namespace Acacia.Stubs
|
||||
{
|
||||
public interface IMSOCommand
|
||||
{
|
||||
IPicture GetPicture(Size imageSize);
|
||||
Bitmap GetImage(Size imageSize);
|
||||
}
|
||||
|
||||
|
@ -120,5 +120,9 @@ namespace Acacia.Stubs
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
void Save();
|
||||
|
||||
void SetCustomIcon(IPicture icon);
|
||||
}
|
||||
}
|
||||
|
12
src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IPicture.cs
Normal file
12
src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IPicture.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Acacia.Stubs
|
||||
{
|
||||
public interface IPicture : IComWrapper
|
||||
{
|
||||
}
|
||||
}
|
@ -39,6 +39,11 @@ namespace Acacia.Stubs.OutlookWrappers
|
||||
this._id = id;
|
||||
}
|
||||
|
||||
public IPicture GetPicture(Size imageSize)
|
||||
{
|
||||
return _commands._item.GetImageMso(_id, imageSize.Width, imageSize.Height).Wrap();
|
||||
}
|
||||
|
||||
public Bitmap GetImage(Size imageSize)
|
||||
{
|
||||
IPictureDisp pict = _commands._item.GetImageMso(_id, imageSize.Width, imageSize.Height);
|
||||
|
@ -24,6 +24,7 @@ using Acacia.Utils;
|
||||
using Acacia.ZPush;
|
||||
using NSOutlook = Microsoft.Office.Interop.Outlook;
|
||||
using Acacia.Native.MAPI;
|
||||
using stdole;
|
||||
|
||||
namespace Acacia.Stubs.OutlookWrappers
|
||||
{
|
||||
@ -56,6 +57,19 @@ namespace Acacia.Stubs.OutlookWrappers
|
||||
return new FolderWrapper(CloneComObject());
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
IMAPIFolder imapi = _item.MAPIOBJECT as IMAPIFolder;
|
||||
try
|
||||
{
|
||||
imapi.SaveChanges(SaveChangesFlags.FORCE_SAVE);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ComRelease.Release(imapi);
|
||||
}
|
||||
}
|
||||
|
||||
internal NSOutlook.Folder RawItem { get { return _item; } }
|
||||
|
||||
protected override NSOutlook.PropertyAccessor GetPropertyAccessor()
|
||||
@ -360,6 +374,11 @@ namespace Acacia.Stubs.OutlookWrappers
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCustomIcon(IPicture icon)
|
||||
{
|
||||
_item.SetCustomIcon(((PictureWrapper)icon).RawItem as StdPicture);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public ItemType DefaultItemType
|
||||
@ -395,7 +414,8 @@ namespace Acacia.Stubs.OutlookWrappers
|
||||
|
||||
set
|
||||
{
|
||||
|
||||
// TODO
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,15 @@ namespace Acacia.Stubs.OutlookWrappers
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
public static IPicture Wrap(stdole.IPictureDisp obj, bool mustRelease = true)
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
PictureWrapper wrapped = new PictureWrapper(obj);
|
||||
wrapped.MustRelease = mustRelease;
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
// TODO: extension methods for this
|
||||
public static IStore Wrap(NSOutlook.Store obj, bool mustRelease = true)
|
||||
{
|
||||
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Acacia.Stubs.OutlookWrappers
|
||||
{
|
||||
class PictureWrapper : ComWrapper<stdole.IPictureDisp>, IPicture
|
||||
{
|
||||
internal PictureWrapper(stdole.IPictureDisp item) : base(item)
|
||||
{
|
||||
}
|
||||
|
||||
internal stdole.IPictureDisp RawItem { get { return _item; } }
|
||||
}
|
||||
}
|
@ -62,5 +62,10 @@ namespace Acacia.Stubs
|
||||
{
|
||||
return Mapping.WrapOrDefault<WrapType>(o, mustRelease);
|
||||
}
|
||||
|
||||
public static IPicture Wrap(this stdole.IPictureDisp picture)
|
||||
{
|
||||
return Mapping.Wrap(picture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user