From c9dff4a04aae1568f73dbde0cd3c1004dc19217e Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 23 Dec 2013 22:10:28 +0200 Subject: [PATCH] Added "Show toast window with image preview after task is completed" setting --- ShareX/Forms/MainForm.cs | 1 - ...signer.cs => NotificationForm.Designer.cs} | 8 ++- .../{ToastForm.cs => NotificationForm.cs} | 63 +++++++++++++++---- .../{ToastForm.resx => NotificationForm.resx} | 0 ShareX/Forms/TaskSettingsForm.Designer.cs | 18 +++++- ShareX/Forms/TaskSettingsForm.cs | 6 ++ ShareX/ShareX.csproj | 10 +-- ShareX/TaskManager.cs | 14 ++++- ShareX/TaskSettings.cs | 3 +- 9 files changed, 95 insertions(+), 28 deletions(-) rename ShareX/Forms/{ToastForm.Designer.cs => NotificationForm.Designer.cs} (86%) rename ShareX/Forms/{ToastForm.cs => NotificationForm.cs} (57%) rename ShareX/Forms/{ToastForm.resx => NotificationForm.resx} (100%) diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 29fd5a228..cdce50cfe 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -70,7 +70,6 @@ private void MainForm_HandleCreated(object sender, EventArgs e) private void AfterShownJobs() { this.ShowActivate(); - ToastForm.ShowAsync("test", ShareXResources.Logo); } private void InitControls() diff --git a/ShareX/Forms/ToastForm.Designer.cs b/ShareX/Forms/NotificationForm.Designer.cs similarity index 86% rename from ShareX/Forms/ToastForm.Designer.cs rename to ShareX/Forms/NotificationForm.Designer.cs index ac3714041..99bbd268a 100644 --- a/ShareX/Forms/ToastForm.Designer.cs +++ b/ShareX/Forms/NotificationForm.Designer.cs @@ -1,6 +1,6 @@ namespace ShareX { - partial class ToastForm + partial class NotificationForm { /// /// Required designer variable. @@ -36,16 +36,18 @@ private void InitializeComponent() // this.tDuration.Tick += new System.EventHandler(this.tDuration_Tick); // - // ToastForm + // NotificationForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(300, 150); + this.Cursor = System.Windows.Forms.Cursors.Hand; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; - this.Name = "ToastForm"; + this.Name = "NotificationForm"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "ToastForm"; + this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.NotificationForm_MouseClick); this.ResumeLayout(false); } diff --git a/ShareX/Forms/ToastForm.cs b/ShareX/Forms/NotificationForm.cs similarity index 57% rename from ShareX/Forms/ToastForm.cs rename to ShareX/Forms/NotificationForm.cs index 007ee88b4..1a4d93898 100644 --- a/ShareX/Forms/ToastForm.cs +++ b/ShareX/Forms/NotificationForm.cs @@ -29,6 +29,8 @@ using System.ComponentModel; using System.Data; using System.Drawing; +using System.Drawing.Drawing2D; +using System.IO; using System.Linq; using System.Text; using System.Threading; @@ -36,20 +38,25 @@ namespace ShareX { - public partial class ToastForm : Form + public partial class NotificationForm : Form { public string ToastText { get; private set; } public Image ToastImage { get; private set; } + public string URL { get; private set; } - public ToastForm(int duration, string text, Image image) + private int windowOffset = 3; + + public NotificationForm(int duration, Size size, string text, Image image, string url) { InitializeComponent(); + Size = size; ToastText = text; image = ImageHelpers.ResizeImage(image, ClientRectangle.Size.Offset(-2), true, true); image = ImageHelpers.DrawCheckers(image); ToastImage = image; + URL = url; SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); - Location = new Point(Screen.PrimaryScreen.WorkingArea.Right - Width, Screen.PrimaryScreen.WorkingArea.Bottom - Height); + Location = new Point(Screen.PrimaryScreen.WorkingArea.Right - Width - windowOffset, Screen.PrimaryScreen.WorkingArea.Bottom - Height - windowOffset); NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_BLEND); tDuration.Interval = duration; tDuration.Start(); @@ -58,30 +65,60 @@ public ToastForm(int duration, string text, Image image) private void tDuration_Tick(object sender, EventArgs e) { tDuration.Stop(); - NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_HIDE | AnimateWindowFlags.AW_BLEND); + NativeMethods.AnimateWindow(Handle, 2000, AnimateWindowFlags.AW_HIDE | AnimateWindowFlags.AW_BLEND); Close(); } protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; + g.DrawImage(ToastImage, 1, 1, ToastImage.Width, ToastImage.Height); + + using (SolidBrush brush = new SolidBrush(Color.FromArgb(200, 255, 255, 255))) + { + g.FillRectangle(brush, new Rectangle(0, 0, e.ClipRectangle.Width, 40)); + } + + using (Font font = new Font("Arial", 10)) + { + g.DrawString(ToastText, font, Brushes.Black, e.ClipRectangle.RectangleOffset(-5)); + } + g.DrawRectangleProper(Pens.Black, e.ClipRectangle); } - public static void ShowAsync(string text, Image image) + public static void ShowAsync(string text, string imagePath, string url) { - Image cloneImage = (Image)image.Clone(); - - Thread thread = new Thread(() => + if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath)) { - using (ToastForm toastForm = new ToastForm(5000, text, cloneImage)) + Thread thread = new Thread(() => { - toastForm.ShowDialog(); - } - }); + using (Image img = ImageHelpers.LoadImage(imagePath)) + using (NotificationForm toastForm = new NotificationForm(5000, new Size(400, 300), text, img, url)) + { + toastForm.ShowDialog(); + } + }); - thread.Start(); + thread.Start(); + } + } + + private void NotificationForm_MouseClick(object sender, MouseEventArgs e) + { + if (e.Button == System.Windows.Forms.MouseButtons.Left) + { + if (!string.IsNullOrEmpty(URL)) + { + Helpers.LoadBrowserAsync(URL); + } + } + else if (e.Button == MouseButtons.Right) + { + tDuration.Stop(); + Close(); + } } } } \ No newline at end of file diff --git a/ShareX/Forms/ToastForm.resx b/ShareX/Forms/NotificationForm.resx similarity index 100% rename from ShareX/Forms/ToastForm.resx rename to ShareX/Forms/NotificationForm.resx diff --git a/ShareX/Forms/TaskSettingsForm.Designer.cs b/ShareX/Forms/TaskSettingsForm.Designer.cs index b9f7c1aab..236c0b1b8 100644 --- a/ShareX/Forms/TaskSettingsForm.Designer.cs +++ b/ShareX/Forms/TaskSettingsForm.Designer.cs @@ -155,6 +155,7 @@ private void InitializeComponent() this.tpAdvanced = new System.Windows.Forms.TabPage(); this.pgTaskSettings = new System.Windows.Forms.PropertyGrid(); this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox(); + this.cbShowToastWindowAfterTask = new System.Windows.Forms.CheckBox(); this.tcHotkeySettings.SuspendLayout(); this.tpTask.SuspendLayout(); this.tpGeneral.SuspendLayout(); @@ -454,6 +455,7 @@ private void InitializeComponent() // panelGeneral // this.panelGeneral.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panelGeneral.Controls.Add(this.cbShowToastWindowAfterTask); this.panelGeneral.Controls.Add(this.chkShowAfterUploadForm); this.panelGeneral.Controls.Add(this.cbShowAfterCaptureTasksForm); this.panelGeneral.Controls.Add(this.cbTrayBalloonTipAfterUpload); @@ -469,7 +471,7 @@ private void InitializeComponent() // chkShowAfterUploadForm // this.chkShowAfterUploadForm.AutoSize = true; - this.chkShowAfterUploadForm.Location = new System.Drawing.Point(8, 104); + this.chkShowAfterUploadForm.Location = new System.Drawing.Point(8, 128); this.chkShowAfterUploadForm.Name = "chkShowAfterUploadForm"; this.chkShowAfterUploadForm.Size = new System.Drawing.Size(271, 17); this.chkShowAfterUploadForm.TabIndex = 18; @@ -513,7 +515,7 @@ private void InitializeComponent() // cbHistorySave // this.cbHistorySave.AutoSize = true; - this.cbHistorySave.Location = new System.Drawing.Point(8, 128); + this.cbHistorySave.Location = new System.Drawing.Point(8, 152); this.cbHistorySave.Name = "cbHistorySave"; this.cbHistorySave.Size = new System.Drawing.Size(139, 17); this.cbHistorySave.TabIndex = 17; @@ -1633,6 +1635,17 @@ private void InitializeComponent() this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true; this.chkUseDefaultAdvancedSettings.CheckedChanged += new System.EventHandler(this.chkUseDefaultAdvancedSettings_CheckedChanged); // + // cbShowToastWindowAfterTask + // + this.cbShowToastWindowAfterTask.AutoSize = true; + this.cbShowToastWindowAfterTask.Location = new System.Drawing.Point(8, 104); + this.cbShowToastWindowAfterTask.Name = "cbShowToastWindowAfterTask"; + this.cbShowToastWindowAfterTask.Size = new System.Drawing.Size(320, 17); + this.cbShowToastWindowAfterTask.TabIndex = 19; + this.cbShowToastWindowAfterTask.Text = "Show toast window with image preview after task is completed"; + this.cbShowToastWindowAfterTask.UseVisualStyleBackColor = true; + this.cbShowToastWindowAfterTask.CheckedChanged += new System.EventHandler(this.cbShowToastWindowAfterTask_CheckedChanged); + // // TaskSettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1828,6 +1841,7 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox chkShowImageEffectsWindowAfterCapture; private System.Windows.Forms.CheckBox chkOverrideFTP; private System.Windows.Forms.ComboBox cboFTPaccounts; + private System.Windows.Forms.CheckBox cbShowToastWindowAfterTask; diff --git a/ShareX/Forms/TaskSettingsForm.cs b/ShareX/Forms/TaskSettingsForm.cs index 27104b622..29131f6b3 100644 --- a/ShareX/Forms/TaskSettingsForm.cs +++ b/ShareX/Forms/TaskSettingsForm.cs @@ -110,6 +110,7 @@ public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false) cbPlaySoundAfterUpload.Checked = TaskSettings.GeneralSettings.PlaySoundAfterUpload; chkShowAfterUploadForm.Checked = TaskSettings.GeneralSettings.ShowAfterUploadForm; cbTrayBalloonTipAfterUpload.Checked = TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload; + cbShowToastWindowAfterTask.Checked = TaskSettings.GeneralSettings.ShowToastWindowAfterTask; cbHistorySave.Checked = TaskSettings.GeneralSettings.SaveHistory; // Image - Quality @@ -422,6 +423,11 @@ private void cbTrayBalloonTipAfterUpload_CheckedChanged(object sender, EventArgs TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload = cbTrayBalloonTipAfterUpload.Checked; } + private void cbShowToastWindowAfterTask_CheckedChanged(object sender, EventArgs e) + { + TaskSettings.GeneralSettings.ShowToastWindowAfterTask = cbShowToastWindowAfterTask.Checked; + } + private void cbHistorySave_CheckedChanged(object sender, EventArgs e) { TaskSettings.GeneralSettings.SaveHistory = cbHistorySave.Checked; diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index bd5a9d749..8f2b0785c 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -140,11 +140,11 @@ SettingsForm.cs - + Form - - ToastForm.cs + + NotificationForm.cs Form @@ -244,8 +244,8 @@ MainForm.cs - - ToastForm.cs + + NotificationForm.cs UploadTestForm.cs diff --git a/ShareX/TaskManager.cs b/ShareX/TaskManager.cs index 95a6e89c3..86028ff74 100644 --- a/ShareX/TaskManager.cs +++ b/ShareX/TaskManager.cs @@ -314,10 +314,18 @@ private static void task_UploadCompleted(UploadTask task) balloonTipText = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat); } - if (!string.IsNullOrEmpty(balloonTipText) && task.Info.TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload && Program.MainForm.niTray.Visible) + if (!string.IsNullOrEmpty(balloonTipText)) { - Program.MainForm.niTray.Tag = result; - Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Task completed", balloonTipText, ToolTipIcon.Info); + if (task.Info.TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload && Program.MainForm.niTray.Visible) + { + Program.MainForm.niTray.Tag = result; + Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Task completed", balloonTipText, ToolTipIcon.Info); + } + + if (task.Info.TaskSettings.GeneralSettings.ShowToastWindowAfterTask) + { + NotificationForm.ShowAsync(balloonTipText, info.FilePath, result); + } } if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm) diff --git a/ShareX/TaskSettings.cs b/ShareX/TaskSettings.cs index 6fcdfbdac..9565ee721 100644 --- a/ShareX/TaskSettings.cs +++ b/ShareX/TaskSettings.cs @@ -193,9 +193,10 @@ private void SetDefaultSettings() public class TaskSettingsGeneral { public bool PlaySoundAfterCapture = true; + public bool ShowAfterCaptureTasksForm = false; public bool PlaySoundAfterUpload = true; public bool TrayBalloonTipAfterUpload = true; - public bool ShowAfterCaptureTasksForm = false; + public bool ShowToastWindowAfterTask = false; public bool ShowAfterUploadForm = false; public bool SaveHistory = true; }