From be0569bb21be5446dc570e881847d6b303682259 Mon Sep 17 00:00:00 2001 From: RKrom Date: Mon, 20 Feb 2012 12:13:59 +0000 Subject: [PATCH] Improved differentiating office icons, the actual application has a different icon as the "document". For Outlook this is even different for the email & meeting. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1666 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Destinations/EmailDestination.cs | 39 +++++++++----- Greenshot/Destinations/ExcelDestination.cs | 13 +++-- .../Destinations/PowerpointDestination.cs | 14 +++-- Greenshot/Destinations/WordDestination.cs | 23 +++++---- .../Helpers/OfficeInterop/OutlookWrapper.cs | 10 ++-- .../releases/additional_files/readme.txt | 2 +- GreenshotPlugin/Core/AbstractDestination.cs | 12 +++-- GreenshotPlugin/Core/ImageHelper.cs | 51 ++++++++++++++++--- 8 files changed, 117 insertions(+), 47 deletions(-) diff --git a/Greenshot/Destinations/EmailDestination.cs b/Greenshot/Destinations/EmailDestination.cs index aa959aa48..b254955b2 100644 --- a/Greenshot/Destinations/EmailDestination.cs +++ b/Greenshot/Destinations/EmailDestination.cs @@ -40,12 +40,15 @@ namespace Greenshot.Destinations { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(EmailDestination)); private static CoreConfiguration conf = IniConfig.GetIniSection(); private static string exePath = null; - private static Image icon = null; + private static Image applicationIcon = null; + private static Image mailIcon = null; + private static Image meetingIcon = null; private static bool isActiveFlag = false; private static bool isOutlookUsed = false; private static string mapiClient = null; public const string DESIGNATION = "EMail"; - private string outlookInspectorCaption = null; + private string outlookInspectorCaption; + private OlObjectClass outlookInspectorType; private ILanguage lang = Language.GetInstance(); static EmailDestination() { @@ -63,11 +66,15 @@ namespace Greenshot.Destinations { isActiveFlag = true; isOutlookUsed = true; } - + // Use default email icon + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm)); + mailIcon = ((System.Drawing.Image)(resources.GetObject("btnEmail.Image"))); + if (isOutlookUsed) { exePath = GetExePath("OUTLOOK.EXE"); if (exePath != null && File.Exists(exePath)) { - icon = GetExeIcon(exePath); + applicationIcon = GetExeIcon(exePath, 0); + meetingIcon = GetExeIcon(exePath, 2); } else { exePath = null; } @@ -80,16 +87,16 @@ namespace Greenshot.Destinations { } if (isActiveFlag && !isOutlookUsed) { // Use default email icon - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm)); - icon = ((System.Drawing.Image)(resources.GetObject("btnEmail.Image"))); + applicationIcon = mailIcon; } } public EmailDestination() { } - public EmailDestination(string outlookInspectorCaption) { + public EmailDestination(string outlookInspectorCaption, OlObjectClass outlookInspectorType) { this.outlookInspectorCaption = outlookInspectorCaption; + this.outlookInspectorType = outlookInspectorType; } public override string Designation { @@ -108,7 +115,7 @@ namespace Greenshot.Destinations { if (outlookInspectorCaption == null) { return mapiClient; } else { - return mapiClient + " - " + outlookInspectorCaption; + return outlookInspectorCaption; } } } @@ -139,7 +146,15 @@ namespace Greenshot.Destinations { public override Image DisplayIcon { get { - return icon; + if (isOutlookUsed && outlookInspectorCaption != null) { + if (OlObjectClass.olAppointment.Equals(outlookInspectorType)) { + return meetingIcon; + } else { + return mailIcon; + } + } else { + return applicationIcon; + } } } @@ -147,10 +162,10 @@ namespace Greenshot.Destinations { if (!isOutlookUsed) { yield break; } - List inspectorCaptions = OutlookExporter.RetrievePossibleTargets(); + Dictionary inspectorCaptions = OutlookExporter.RetrievePossibleTargets(); if (inspectorCaptions != null) { - foreach (string inspectorCaption in inspectorCaptions) { - yield return new EmailDestination(inspectorCaption); + foreach (string inspectorCaption in inspectorCaptions.Keys) { + yield return new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption]); } } } diff --git a/Greenshot/Destinations/ExcelDestination.cs b/Greenshot/Destinations/ExcelDestination.cs index 5a237c2aa..6c0e715b5 100644 --- a/Greenshot/Destinations/ExcelDestination.cs +++ b/Greenshot/Destinations/ExcelDestination.cs @@ -39,14 +39,16 @@ namespace Greenshot.Destinations { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExcelDestination)); private static CoreConfiguration conf = IniConfig.GetIniSection(); private static string exePath = null; - private static Image icon = null; + private static Image applicationIcon = null; + private static Image workbookIcon = null; private ILanguage lang = Language.GetInstance(); private string workbookName = null; static ExcelDestination() { exePath = GetExePath("EXCEL.EXE"); if (exePath != null && File.Exists(exePath)) { - icon = GetExeIcon(exePath); + applicationIcon = GetExeIcon(exePath, 0); + workbookIcon = GetExeIcon(exePath, 1); } else { exePath = null; } @@ -70,7 +72,7 @@ namespace Greenshot.Destinations { if (workbookName == null) { return "Microsoft Excel"; } else { - return "Microsoft Excel - " + workbookName; + return workbookName; } } } @@ -95,7 +97,10 @@ namespace Greenshot.Destinations { public override Image DisplayIcon { get { - return icon; + if (!string.IsNullOrEmpty(workbookName)) { + return workbookIcon; + } + return applicationIcon; } } diff --git a/Greenshot/Destinations/PowerpointDestination.cs b/Greenshot/Destinations/PowerpointDestination.cs index 835135cad..089bb133f 100644 --- a/Greenshot/Destinations/PowerpointDestination.cs +++ b/Greenshot/Destinations/PowerpointDestination.cs @@ -39,14 +39,16 @@ namespace Greenshot.Destinations { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PowerpointDestination)); private static CoreConfiguration conf = IniConfig.GetIniSection(); private static string exePath = null; - private static Image icon = null; + private static Image applicationIcon = null; + private static Image presentationIcon = null; private ILanguage lang = Language.GetInstance(); private string presentationName = null; static PowerpointDestination() { exePath = GetExePath("POWERPNT.EXE"); if (exePath != null && File.Exists(exePath)) { - icon = GetExeIcon(exePath); + applicationIcon = GetExeIcon(exePath, 0); + presentationIcon = GetExeIcon(exePath, 1); } else { exePath = null; } @@ -70,7 +72,7 @@ namespace Greenshot.Destinations { if (presentationName == null) { return "Microsoft Powerpoint"; } else { - return "Microsoft Powerpoint - " + presentationName; + return presentationName; } } } @@ -95,7 +97,11 @@ namespace Greenshot.Destinations { public override Image DisplayIcon { get { - return icon; + if (!string.IsNullOrEmpty(presentationName)) { + return presentationIcon; + } + + return applicationIcon; } } diff --git a/Greenshot/Destinations/WordDestination.cs b/Greenshot/Destinations/WordDestination.cs index 3e7e73579..4bd02e684 100644 --- a/Greenshot/Destinations/WordDestination.cs +++ b/Greenshot/Destinations/WordDestination.cs @@ -40,14 +40,16 @@ namespace Greenshot.Destinations { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WordDestination)); private static CoreConfiguration conf = IniConfig.GetIniSection(); private static string exePath = null; - private static Image icon = null; + private static Image applicationIcon = null; + private static Image documentIcon = null; private ILanguage lang = Language.GetInstance(); - private string wordCaption = null; + private string documentCaption = null; static WordDestination() { exePath = GetExePath("WINWORD.EXE"); if (exePath != null && File.Exists(exePath)) { - icon = GetExeIcon(exePath); + applicationIcon = GetExeIcon(exePath, 0); + documentIcon = GetExeIcon(exePath, 1); } else { exePath = null; } @@ -58,7 +60,7 @@ namespace Greenshot.Destinations { } public WordDestination(string wordCaption) { - this.wordCaption = wordCaption; + this.documentCaption = wordCaption; } public override string Designation { @@ -69,10 +71,10 @@ namespace Greenshot.Destinations { public override string Description { get { - if (wordCaption == null) { + if (documentCaption == null) { return "Microsoft Word"; } else { - return "Microsoft Word - " + wordCaption; + return documentCaption; } } } @@ -97,7 +99,10 @@ namespace Greenshot.Destinations { public override Image DisplayIcon { get { - return icon; + if (!string.IsNullOrEmpty(documentCaption)) { + return documentIcon; + } + return applicationIcon; } } @@ -114,8 +119,8 @@ namespace Greenshot.Destinations { tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality); } } - if (wordCaption != null) { - WordExporter.InsertIntoExistingDocument(wordCaption, tmpFile); + if (documentCaption != null) { + WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile); } else { WordExporter.InsertIntoNewDocument(tmpFile); } diff --git a/Greenshot/Helpers/OfficeInterop/OutlookWrapper.cs b/Greenshot/Helpers/OfficeInterop/OutlookWrapper.cs index 88cd9c302..64ae4384d 100644 --- a/Greenshot/Helpers/OfficeInterop/OutlookWrapper.cs +++ b/Greenshot/Helpers/OfficeInterop/OutlookWrapper.cs @@ -111,8 +111,8 @@ namespace Greenshot.Helpers.OfficeInterop { /// /// IOutlookApplication /// List with inspector captions (window title) - public static List RetrievePossibleTargets() { - List inspectorCaptions = new List(); + public static Dictionary RetrievePossibleTargets() { + Dictionary inspectorCaptions = new Dictionary(); try { using ( IOutlookApplication outlookApplication = GetOutlookApplication()) { if (outlookApplication == null) { @@ -124,7 +124,9 @@ namespace Greenshot.Helpers.OfficeInterop { for(int i=1; i <= inspectors.Count; i++) { Inspector inspector = outlookApplication.Inspectors[i]; if (canExportToInspector(inspector)) { - inspectorCaptions.Add(inspector.Caption); + Item currentItem = inspector.CurrentItem; + OlObjectClass currentItemClass = currentItem.Class; + inspectorCaptions.Add(inspector.Caption, currentItemClass); } } } @@ -150,7 +152,7 @@ namespace Greenshot.Helpers.OfficeInterop { return true; } } else if (outlookVersion.Major >=12 && OlObjectClass.olAppointment.Equals(currentItemClass)) { - if (currentUser != null && currentUser.Equals(currentItem.Organizer)) { + if (string.IsNullOrEmpty(currentItem.Organizer) || (currentUser == null && currentUser.Equals(currentItem.Organizer))) { return true; } else { LOG.DebugFormat("Not exporting to {0}, as organizer is {1} and currentuser {2}", inspector.Caption, currentItem.Organizer, currentUser); diff --git a/Greenshot/releases/additional_files/readme.txt b/Greenshot/releases/additional_files/readme.txt index fcb304d14..1f3509da4 100644 --- a/Greenshot/releases/additional_files/readme.txt +++ b/Greenshot/releases/additional_files/readme.txt @@ -3,7 +3,7 @@ Greenshot: A screenshot tool optimized for productivity. Save a screenshot or a CHANGE LOG: -0.9.0 Build 1660 +0.9.0 Build 1667 We changed the version to 0.9.0 as the amount of features in 0.8.1 was more than planned. diff --git a/GreenshotPlugin/Core/AbstractDestination.cs b/GreenshotPlugin/Core/AbstractDestination.cs index a107db0da..c110895cb 100644 --- a/GreenshotPlugin/Core/AbstractDestination.cs +++ b/GreenshotPlugin/Core/AbstractDestination.cs @@ -51,19 +51,21 @@ namespace GreenshotPlugin.Core { /// /// Internaly used to create an icon /// - /// - /// - public static Bitmap GetExeIcon(string path) { + /// path to the exe or dll + /// index of the icon + /// Bitmap with the icon or null if something happended + public static Bitmap GetExeIcon(string path, int index) { if (!File.Exists(path)) { return null; } try { - using (Icon appIcon = Icon.ExtractAssociatedIcon(path)) { + using (Icon appIcon = ImageHelper.ExtractAssociatedIcon(path, index, false)) { if (appIcon != null) { return appIcon.ToBitmap(); } } - } catch { + } catch (Exception exIcon) { + LOG.Error("error retrieving icon: ", exIcon); } return null; } diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 4ec6b4218..5ea34b639 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -268,20 +268,55 @@ namespace GreenshotPlugin.Core { return bmpPngExtracted; } - public static Icon ExtractAssociatedIcon(this Icon icon, string location) { + /// + /// See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms648069%28v=vs.85%29.aspx + /// + /// The icon to + /// The file (EXE or DLL) to get the icon from + /// Index of the icon + /// true if the large icon is wanted + /// Icon + public static Icon ExtractAssociatedIcon(string location, int index, bool takeLarge) { IntPtr large; IntPtr small; - Shell32.ExtractIconEx(location, 0, out large, out small, 1); - Icon returnIcon = Icon.FromHandle(small); - if (!IntPtr.Zero.Equals(small)){ - User32.DestroyIcon(small); - } - if (!IntPtr.Zero.Equals(large)){ - User32.DestroyIcon(large); + Shell32.ExtractIconEx(location, index, out large, out small, 1); + Icon returnIcon = null; + bool isLarge = false; + bool isSmall = false; + try { + if (takeLarge && !IntPtr.Zero.Equals(large)) { + returnIcon = Icon.FromHandle(large); + isLarge = true; + } else if (!IntPtr.Zero.Equals(small)) { + returnIcon = Icon.FromHandle(small); + isSmall = true; + } else if (!IntPtr.Zero.Equals(large)) { + returnIcon = Icon.FromHandle(large); + isLarge = true; + } + } finally { + if (isLarge && !IntPtr.Zero.Equals(small)) { + User32.DestroyIcon(small); + } + if (isSmall && !IntPtr.Zero.Equals(large)) { + User32.DestroyIcon(large); + } } return returnIcon; } + /// + /// Get the number of icon in the file + /// + /// + /// Location of the EXE or DLL + /// + public static int CountAssociatedIcons(string location) { + IntPtr large = IntPtr.Zero; + IntPtr small = IntPtr.Zero; + return Shell32.ExtractIconEx(location, -1, out large, out small, 0); + } + /// /// Make the picture look like it's torn ///