diff --git a/Greenshot/Destinations/ClipboardDestination.cs b/Greenshot/Destinations/ClipboardDestination.cs index 3d415aed8..9cfb0aec5 100644 --- a/Greenshot/Destinations/ClipboardDestination.cs +++ b/Greenshot/Destinations/ClipboardDestination.cs @@ -58,7 +58,7 @@ namespace Greenshot.Destinations { public override Image DisplayIcon { get { - return GreenshotResources.getImage("Clipboard.Image"); + return GreenshotResources.GetImage("Clipboard.Image"); } } diff --git a/Greenshot/Destinations/EditorDestination.cs b/Greenshot/Destinations/EditorDestination.cs index 2e9252d8b..09cce0f56 100644 --- a/Greenshot/Destinations/EditorDestination.cs +++ b/Greenshot/Destinations/EditorDestination.cs @@ -37,7 +37,7 @@ namespace Greenshot.Destinations { private static readonly EditorConfiguration editorConfiguration = IniConfig.GetIniSection(); public const string DESIGNATION = "Editor"; private readonly IImageEditor editor; - private static readonly Image greenshotIcon = GreenshotResources.getGreenshotIcon().ToBitmap(); + private static readonly Image greenshotIcon = GreenshotResources.GetGreenshotIcon().ToBitmap(); public EditorDestination() { } diff --git a/Greenshot/Destinations/EmailDestination.cs b/Greenshot/Destinations/EmailDestination.cs index 4f8ab24e2..abda77c7c 100644 --- a/Greenshot/Destinations/EmailDestination.cs +++ b/Greenshot/Destinations/EmailDestination.cs @@ -32,7 +32,7 @@ namespace Greenshot.Destinations { /// Description of EmailDestination. /// public class EmailDestination : AbstractDestination { - private static readonly Image MailIcon = GreenshotResources.getImage("Email.Image"); + private static readonly Image MailIcon = GreenshotResources.GetImage("Email.Image"); private static bool _isActiveFlag; private static string _mapiClient; public const string DESIGNATION = "EMail"; diff --git a/Greenshot/Destinations/FileDestination.cs b/Greenshot/Destinations/FileDestination.cs index 568337ac6..559d28135 100644 --- a/Greenshot/Destinations/FileDestination.cs +++ b/Greenshot/Destinations/FileDestination.cs @@ -48,7 +48,7 @@ namespace Greenshot.Destinations { public override Keys EditorShortcutKeys => Keys.Control | Keys.S; - public override Image DisplayIcon => GreenshotResources.getImage("Save.Image"); + public override Image DisplayIcon => GreenshotResources.GetImage("Save.Image"); public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { ExportInformation exportInformation = new ExportInformation(Designation, Description); diff --git a/Greenshot/Destinations/FileWithDialogDestination.cs b/Greenshot/Destinations/FileWithDialogDestination.cs index 6acb60088..e211d14f7 100644 --- a/Greenshot/Destinations/FileWithDialogDestination.cs +++ b/Greenshot/Destinations/FileWithDialogDestination.cs @@ -61,7 +61,7 @@ namespace Greenshot.Destinations { public override Image DisplayIcon { get { - return GreenshotResources.getImage("Save.Image"); + return GreenshotResources.GetImage("Save.Image"); } } diff --git a/Greenshot/Destinations/PrinterDestination.cs b/Greenshot/Destinations/PrinterDestination.cs index b9781d286..e2156256b 100644 --- a/Greenshot/Destinations/PrinterDestination.cs +++ b/Greenshot/Destinations/PrinterDestination.cs @@ -59,7 +59,7 @@ namespace Greenshot.Destinations { public override Keys EditorShortcutKeys => Keys.Control | Keys.P; - public override Image DisplayIcon => GreenshotResources.getImage("Printer.Image"); + public override Image DisplayIcon => GreenshotResources.GetImage("Printer.Image"); public override bool IsDynamic => true; diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index dc5332708..e415d1053 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -59,7 +59,7 @@ namespace Greenshot.Forms { /// Initialize the background brush /// static CaptureForm() { - Image backgroundForTransparency = GreenshotResources.getImage("Checkerboard.Image"); + Image backgroundForTransparency = GreenshotResources.GetImage("Checkerboard.Image"); BackgroundBrush = new TextureBrush(backgroundForTransparency, WrapMode.Tile); } @@ -415,7 +415,7 @@ namespace Greenshot.Forms { } /// - /// + /// /// /// /// diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index a40c96b4a..bcb8c275c 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -175,7 +175,7 @@ namespace Greenshot { { panel1.Controls.Add(_surface); } - Image backgroundForTransparency = GreenshotResources.getImage("Checkerboard.Image"); + Image backgroundForTransparency = GreenshotResources.GetImage("Checkerboard.Image"); if (_surface != null) { _surface.TransparencyBackgroundBrush = new TextureBrush(backgroundForTransparency, WrapMode.Tile); diff --git a/Greenshot/Forms/LanguageDialog.cs b/Greenshot/Forms/LanguageDialog.cs index 7565285b8..7d6ba2f33 100644 --- a/Greenshot/Forms/LanguageDialog.cs +++ b/Greenshot/Forms/LanguageDialog.cs @@ -38,7 +38,7 @@ namespace Greenshot.Forms { // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); - Icon = GreenshotResources.getGreenshotIcon(); + Icon = GreenshotResources.GetGreenshotIcon(); Load += FormLoad; FormClosing += PreventFormClose; } diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index c880aa209..a197a8cf5 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -231,7 +231,7 @@ namespace Greenshot { // A dirty fix to make sure the message box is visible as a Greenshot window on the taskbar using Form dummyForm = new Form { - Icon = GreenshotResources.getGreenshotIcon(), + Icon = GreenshotResources.GetGreenshotIcon(), ShowInTaskbar = true, FormBorderStyle = FormBorderStyle.None, Location = new Point(int.MinValue, int.MinValue) @@ -345,7 +345,7 @@ namespace Greenshot { // Make the main menu available SimpleServiceProvider.Current.AddService(contextMenu); - notifyIcon.Icon = GreenshotResources.getGreenshotIcon(); + notifyIcon.Icon = GreenshotResources.GetGreenshotIcon(); // Make the notify icon available SimpleServiceProvider.Current.AddService(notifyIcon); @@ -371,6 +371,7 @@ namespace Greenshot { // Check to see if there is already another INotificationService if (SimpleServiceProvider.Current.GetInstance() == null) { + // If not we add the internal NotifyIcon notification service SimpleServiceProvider.Current.AddService(new NotifyIconNotificationService()); } diff --git a/Greenshot/Helpers/NotifyIconNotificationService.cs b/Greenshot/Helpers/NotifyIconNotificationService.cs index e69464f84..e5d49a643 100644 --- a/Greenshot/Helpers/NotifyIconNotificationService.cs +++ b/Greenshot/Helpers/NotifyIconNotificationService.cs @@ -22,6 +22,8 @@ using System; using System.Windows.Forms; using GreenshotPlugin.Core; +using GreenshotPlugin.IniFile; +using GreenshotPlugin.Interfaces; using log4net; namespace Greenshot.Helpers @@ -32,6 +34,7 @@ namespace Greenshot.Helpers public class NotifyIconNotificationService : INotificationService { private static readonly ILog Log = LogManager.GetLogger(typeof(NotifyIconNotificationService)); + private static readonly CoreConfiguration CoreConfiguration = IniConfig.GetIniSection(); private readonly NotifyIcon _notifyIcon; public NotifyIconNotificationService() @@ -83,7 +86,13 @@ namespace Greenshot.Helpers /// ToolTipIcon /// Action /// Action - public void ShowMessage(string message, int timeout, ToolTipIcon level, Action onClickAction = null, Action onClosedAction = null) { + private void ShowMessage(string message, int timeout, ToolTipIcon level, Action onClickAction = null, Action onClosedAction = null) { + // Do not inform the user if this is disabled + if (!CoreConfiguration.ShowTrayNotification) + { + return; + } + void BalloonClickedHandler(object s, EventArgs e) { try diff --git a/GreenshotJiraPlugin/Forms/JiraForm.cs b/GreenshotJiraPlugin/Forms/JiraForm.cs index 9bf669083..551fadadc 100644 --- a/GreenshotJiraPlugin/Forms/JiraForm.cs +++ b/GreenshotJiraPlugin/Forms/JiraForm.cs @@ -40,7 +40,7 @@ namespace GreenshotJiraPlugin.Forms { public JiraForm(JiraConnector jiraConnector) { InitializeComponent(); - Icon = GreenshotResources.getGreenshotIcon(); + Icon = GreenshotResources.GetGreenshotIcon(); AcceptButton = uploadButton; CancelButton = cancelButton; diff --git a/GreenshotOfficePlugin/Destinations/OutlookDestination.cs b/GreenshotOfficePlugin/Destinations/OutlookDestination.cs index 91e58b273..ac88ec091 100644 --- a/GreenshotOfficePlugin/Destinations/OutlookDestination.cs +++ b/GreenshotOfficePlugin/Destinations/OutlookDestination.cs @@ -40,7 +40,7 @@ namespace GreenshotOfficePlugin.Destinations { private const int IconApplication = 0; private const int IconMeeting = 2; - private static readonly Image MailIcon = GreenshotResources.getImage("Email.Image"); + private static readonly Image MailIcon = GreenshotResources.GetImage("Email.Image"); private static readonly OfficeConfiguration OfficeConfig = IniConfig.GetIniSection(); private static readonly string ExePath; private static readonly bool IsActiveFlag; diff --git a/GreenshotPlugin/Controls/BackgroundForm.cs b/GreenshotPlugin/Controls/BackgroundForm.cs index a3152ac4a..5d90c6920 100644 --- a/GreenshotPlugin/Controls/BackgroundForm.cs +++ b/GreenshotPlugin/Controls/BackgroundForm.cs @@ -51,7 +51,7 @@ namespace GreenshotPlugin.Controls { // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); - Icon = GreenshotResources.getGreenshotIcon(); + Icon = GreenshotResources.GetGreenshotIcon(); _shouldClose = false; Text = title; label_pleasewait.Text = text; diff --git a/GreenshotPlugin/Controls/GreenshotForm.cs b/GreenshotPlugin/Controls/GreenshotForm.cs index 32a9fb64f..a7926095f 100644 --- a/GreenshotPlugin/Controls/GreenshotForm.cs +++ b/GreenshotPlugin/Controls/GreenshotForm.cs @@ -146,7 +146,7 @@ namespace GreenshotPlugin.Controls { protected override void OnLoad(EventArgs e) { // Every GreenshotForm should have it's default icon // And it might not ne needed for a Tool Window, but still for the task manager / switcher it's important - Icon = GreenshotResources.getGreenshotIcon(); + Icon = GreenshotResources.GetGreenshotIcon(); if (!DesignMode) { if (!_applyLanguageManually) { ApplyLanguage(); diff --git a/GreenshotPlugin/Controls/OAuthLoginForm.cs b/GreenshotPlugin/Controls/OAuthLoginForm.cs index 2c788893c..2b834d128 100644 --- a/GreenshotPlugin/Controls/OAuthLoginForm.cs +++ b/GreenshotPlugin/Controls/OAuthLoginForm.cs @@ -50,7 +50,7 @@ namespace GreenshotPlugin.Controls { } InitializeComponent(); ClientSize = size; - Icon = GreenshotResources.getGreenshotIcon(); + Icon = GreenshotResources.GetGreenshotIcon(); Text = browserTitle; _addressTextBox.Text = authorizationLink; diff --git a/GreenshotPlugin/Controls/PleaseWaitForm.cs b/GreenshotPlugin/Controls/PleaseWaitForm.cs index 430520267..995b0c17c 100644 --- a/GreenshotPlugin/Controls/PleaseWaitForm.cs +++ b/GreenshotPlugin/Controls/PleaseWaitForm.cs @@ -37,7 +37,7 @@ namespace GreenshotPlugin.Controls { // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); - Icon = GreenshotResources.getGreenshotIcon(); + Icon = GreenshotResources.GetGreenshotIcon(); } /// diff --git a/GreenshotPlugin/Core/AbstractDestination.cs b/GreenshotPlugin/Core/AbstractDestination.cs index df4d2163d..886dd5dab 100644 --- a/GreenshotPlugin/Core/AbstractDestination.cs +++ b/GreenshotPlugin/Core/AbstractDestination.cs @@ -234,7 +234,7 @@ namespace GreenshotPlugin.Core { menu.Items.Add(new ToolStripSeparator()); ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString("editor_close")) { - Image = GreenshotResources.getImage("Close.Image") + Image = GreenshotResources.GetImage("Close.Image") }; closeItem.Click += delegate { // This menu entry is the close itself, we can dispose the surface diff --git a/GreenshotPlugin/Core/GreenshotResources.cs b/GreenshotPlugin/Core/GreenshotResources.cs index 358dbab46..8f59dee91 100644 --- a/GreenshotPlugin/Core/GreenshotResources.cs +++ b/GreenshotPlugin/Core/GreenshotResources.cs @@ -1,20 +1,20 @@ /* * Greenshot - a free and open source screenshot tool * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom - * + * * For more information see: http://getgreenshot.org/ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 1 of the License, or * (at your option) any later version. - * + * * 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -26,21 +26,18 @@ namespace GreenshotPlugin.Core { /// Centralized storage of the icons & bitmaps /// public static class GreenshotResources { - private static readonly ComponentResourceManager greenshotResources = new ComponentResourceManager(typeof(GreenshotResources)); + private static readonly ComponentResourceManager GreenshotResourceManager = new ComponentResourceManager(typeof(GreenshotResources)); - public static Image getImage(string imageName) { - return (Image)greenshotResources.GetObject(imageName); + public static Image GetImage(string imageName) { + return (Image)GreenshotResourceManager.GetObject(imageName); } - public static Icon getIcon(string imageName) { - return (Icon)greenshotResources.GetObject(imageName); - } - - public static Icon getGreenshotIcon() { - return getIcon("Greenshot.Icon"); + public static Icon GetIcon(string imageName) { + return (Icon)GreenshotResourceManager.GetObject(imageName); } - public static Image getGreenshotImage() { - return getImage("Greenshot.Image"); + public static Icon GetGreenshotIcon() { + return GetIcon("Greenshot.Icon"); } + } } diff --git a/GreenshotPlugin/Interfaces/INotificationService.cs b/GreenshotPlugin/Interfaces/INotificationService.cs index a6605e588..922d718ba 100644 --- a/GreenshotPlugin/Interfaces/INotificationService.cs +++ b/GreenshotPlugin/Interfaces/INotificationService.cs @@ -21,8 +21,11 @@ using System; -namespace Greenshot.Helpers +namespace GreenshotPlugin.Interfaces { + /// + /// This is the interface for the different notification service implementations + /// public interface INotificationService { /// diff --git a/GreenshotWin10Plugin/Destinations/Win10ShareDestination.cs b/GreenshotWin10Plugin/Destinations/Win10ShareDestination.cs index 7fc82a1b8..a01ae2216 100644 --- a/GreenshotWin10Plugin/Destinations/Win10ShareDestination.cs +++ b/GreenshotWin10Plugin/Destinations/Win10ShareDestination.cs @@ -167,7 +167,7 @@ namespace GreenshotWin10Plugin.Destinations // Create logo RandomAccessStreamReference logoRandomAccessStreamReference; - using (var logo = GreenshotResources.getGreenshotIcon().ToBitmap()) + using (var logo = GreenshotResources.GetGreenshotIcon().ToBitmap()) using (var logoThumbnail = ImageHelper.CreateThumbnail(logo, 30, 30)) { ImageOutput.SaveToStream(logoThumbnail, null, logoStream, outputSettings); diff --git a/GreenshotWin10Plugin/ToastNotificationService.cs b/GreenshotWin10Plugin/ToastNotificationService.cs index e21bf0389..1c3ad9dda 100644 --- a/GreenshotWin10Plugin/ToastNotificationService.cs +++ b/GreenshotWin10Plugin/ToastNotificationService.cs @@ -20,20 +20,51 @@ */ using System; +using System.Drawing.Imaging; using System.IO; using System.Linq; using Windows.UI.Notifications; -using Greenshot.Helpers; +using GreenshotPlugin.Core; +using GreenshotPlugin.IniFile; +using GreenshotPlugin.Interfaces; using log4net; namespace GreenshotWin10Plugin { + /// + /// This service provides a way to inform (notify) the user. + /// public class ToastNotificationService : INotificationService { private static readonly ILog Log = LogManager.GetLogger(typeof(ToastNotificationService)); + private static readonly CoreConfiguration CoreConfiguration = IniConfig.GetIniSection(); + + private readonly string _imageFilePath; + public ToastNotificationService() + { + var localAppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Greenshot"); + if (!Directory.Exists(localAppData)) + { + Directory.CreateDirectory(localAppData); + } + _imageFilePath = Path.Combine(localAppData, "greenshot.png"); + + if (File.Exists(_imageFilePath)) + { + return; + } + + using var greenshotImage = GreenshotResources.GetGreenshotIcon().ToBitmap(); + greenshotImage.Save(_imageFilePath, ImageFormat.Png); + } private void ShowMessage(string message, Action onClickAction, Action onClosedAction) { + // Do not inform the user if this is disabled + if (!CoreConfiguration.ShowTrayNotification) + { + return; + } // Get a toast XML template var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01); @@ -41,10 +72,17 @@ namespace GreenshotWin10Plugin var stringElement = toastXml.GetElementsByTagName("text").First(); stringElement.AppendChild(toastXml.CreateTextNode(message)); - // Specify the absolute path to an image - //string imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png"); - //var imageElement = toastXml.GetElementsByTagName("image").First(); - //imageElement.Attributes.GetNamedItem("src").NodeValue = imagePath; + if (_imageFilePath != null && File.Exists(_imageFilePath)) + { + // Specify the absolute path to an image + var imageElement = toastXml.GetElementsByTagName("image").First(); + var imageSrcNode = imageElement.Attributes.GetNamedItem("src"); + if (imageSrcNode != null) + { + imageSrcNode.NodeValue = _imageFilePath; + } + } + // Create the toast and attach event listeners var toast = new ToastNotification(toastXml); diff --git a/GreenshotWin10Plugin/Win10Plugin.cs b/GreenshotWin10Plugin/Win10Plugin.cs index d21fa269e..947ce180c 100644 --- a/GreenshotWin10Plugin/Win10Plugin.cs +++ b/GreenshotWin10Plugin/Win10Plugin.cs @@ -20,7 +20,6 @@ */ using System; -using Greenshot.Helpers; using GreenshotPlugin.Core; using GreenshotPlugin.Interfaces; using GreenshotPlugin.Interfaces.Ocr;