From c9028add6cdd62868a0bcd75db927ae80a2de5cf Mon Sep 17 00:00:00 2001 From: Epameinondas Rontogiannis Date: Sun, 23 Feb 2014 00:21:37 +0200 Subject: [PATCH] v.1.3 - allowing user to mute door events --- PSpaceStatusChanger/Options.Designer.cs | 83 +++++++++++-------- PSpaceStatusChanger/Options.cs | 54 +++++++++--- .../PSpaceStatusChanger.csproj | 2 +- PSpaceStatusChanger/Program.cs | 22 +++-- .../Properties/Settings.Designer.cs | 12 +++ .../Properties/Settings.settings | 3 + PSpaceStatusChanger/app.config | 3 + 7 files changed, 127 insertions(+), 52 deletions(-) diff --git a/PSpaceStatusChanger/Options.Designer.cs b/PSpaceStatusChanger/Options.Designer.cs index c58049f..946dc73 100644 --- a/PSpaceStatusChanger/Options.Designer.cs +++ b/PSpaceStatusChanger/Options.Designer.cs @@ -28,59 +28,40 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); this.IsEnabledLbl = new System.Windows.Forms.Label(); - this.ToggleActionBtn = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.TimeIntTxt = new System.Windows.Forms.TextBox(); this.SetTimeBtn = new System.Windows.Forms.Button(); + this.SilentIsEnabledLbl = new System.Windows.Forms.Label(); + this.AutoRunChkBox = new System.Windows.Forms.CheckBox(); + this.SilentChkBox = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(161))); - this.label1.Location = new System.Drawing.Point(31, 24); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(121, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Autorun Status:"; - // // IsEnabledLbl // this.IsEnabledLbl.AutoSize = true; this.IsEnabledLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(161))); - this.IsEnabledLbl.Location = new System.Drawing.Point(171, 24); + this.IsEnabledLbl.Location = new System.Drawing.Point(186, 24); this.IsEnabledLbl.Name = "IsEnabledLbl"; this.IsEnabledLbl.Size = new System.Drawing.Size(92, 20); this.IsEnabledLbl.TabIndex = 1; this.IsEnabledLbl.Text = "ENABLED"; // - // ToggleActionBtn - // - this.ToggleActionBtn.Location = new System.Drawing.Point(102, 54); - this.ToggleActionBtn.Name = "ToggleActionBtn"; - this.ToggleActionBtn.Size = new System.Drawing.Size(111, 23); - this.ToggleActionBtn.TabIndex = 2; - this.ToggleActionBtn.Text = "button1"; - this.ToggleActionBtn.UseVisualStyleBackColor = true; - this.ToggleActionBtn.Click += new System.EventHandler(this.ToggleActionBtn_Click); - // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(34, 170); + this.label3.Location = new System.Drawing.Point(45, 160); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(260, 13); this.label3.TabIndex = 3; - this.label3.Text = "P-Space Status and Event Notifier 1.2 # eparon-2014"; + this.label3.Text = "P-Space Status and Event Notifier 1.3 # eparon-2014"; // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(161))); - this.label2.Location = new System.Drawing.Point(31, 95); + this.label2.Location = new System.Drawing.Point(31, 85); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(165, 20); this.label2.TabIndex = 4; @@ -88,14 +69,14 @@ private void InitializeComponent() // // TimeIntTxt // - this.TimeIntTxt.Location = new System.Drawing.Point(202, 95); + this.TimeIntTxt.Location = new System.Drawing.Point(202, 85); this.TimeIntTxt.Name = "TimeIntTxt"; this.TimeIntTxt.Size = new System.Drawing.Size(61, 20); this.TimeIntTxt.TabIndex = 5; // // SetTimeBtn // - this.SetTimeBtn.Location = new System.Drawing.Point(102, 128); + this.SetTimeBtn.Location = new System.Drawing.Point(102, 118); this.SetTimeBtn.Name = "SetTimeBtn"; this.SetTimeBtn.Size = new System.Drawing.Size(111, 23); this.SetTimeBtn.TabIndex = 6; @@ -103,18 +84,53 @@ private void InitializeComponent() this.SetTimeBtn.UseVisualStyleBackColor = true; this.SetTimeBtn.Click += new System.EventHandler(this.SetTimeBtn_Click); // + // SilentIsEnabledLbl + // + this.SilentIsEnabledLbl.AutoSize = true; + this.SilentIsEnabledLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(161))); + this.SilentIsEnabledLbl.Location = new System.Drawing.Point(186, 49); + this.SilentIsEnabledLbl.Name = "SilentIsEnabledLbl"; + this.SilentIsEnabledLbl.Size = new System.Drawing.Size(92, 20); + this.SilentIsEnabledLbl.TabIndex = 8; + this.SilentIsEnabledLbl.Text = "ENABLED"; + // + // AutoRunChkBox + // + this.AutoRunChkBox.AutoSize = true; + this.AutoRunChkBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(161))); + this.AutoRunChkBox.Location = new System.Drawing.Point(35, 24); + this.AutoRunChkBox.Name = "AutoRunChkBox"; + this.AutoRunChkBox.Size = new System.Drawing.Size(110, 22); + this.AutoRunChkBox.TabIndex = 9; + this.AutoRunChkBox.Text = "Autorun app:"; + this.AutoRunChkBox.UseVisualStyleBackColor = true; + this.AutoRunChkBox.CheckedChanged += new System.EventHandler(this.AutoRunChkBox_CheckedChanged); + // + // SilentChkBox + // + this.SilentChkBox.AutoSize = true; + this.SilentChkBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(161))); + this.SilentChkBox.Location = new System.Drawing.Point(35, 49); + this.SilentChkBox.Name = "SilentChkBox"; + this.SilentChkBox.Size = new System.Drawing.Size(146, 22); + this.SilentChkBox.TabIndex = 10; + this.SilentChkBox.Text = "Mute door events:"; + this.SilentChkBox.UseVisualStyleBackColor = true; + this.SilentChkBox.CheckedChanged += new System.EventHandler(this.SilentChkBox_CheckedChanged); + // // Options // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(306, 186); + this.ClientSize = new System.Drawing.Size(306, 176); + this.Controls.Add(this.SilentChkBox); + this.Controls.Add(this.AutoRunChkBox); + this.Controls.Add(this.SilentIsEnabledLbl); this.Controls.Add(this.SetTimeBtn); this.Controls.Add(this.TimeIntTxt); this.Controls.Add(this.label2); this.Controls.Add(this.label3); - this.Controls.Add(this.ToggleActionBtn); this.Controls.Add(this.IsEnabledLbl); - this.Controls.Add(this.label1); this.Name = "Options"; this.Text = "Options"; this.ResumeLayout(false); @@ -124,12 +140,13 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.Label label1; private System.Windows.Forms.Label IsEnabledLbl; - private System.Windows.Forms.Button ToggleActionBtn; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox TimeIntTxt; private System.Windows.Forms.Button SetTimeBtn; + private System.Windows.Forms.Label SilentIsEnabledLbl; + private System.Windows.Forms.CheckBox AutoRunChkBox; + private System.Windows.Forms.CheckBox SilentChkBox; } } \ No newline at end of file diff --git a/PSpaceStatusChanger/Options.cs b/PSpaceStatusChanger/Options.cs index 2e27513..0d87552 100644 --- a/PSpaceStatusChanger/Options.cs +++ b/PSpaceStatusChanger/Options.cs @@ -12,6 +12,7 @@ namespace PSpaceStatusChanger public partial class Options : Form { bool autorun_enabled = false; + int silent = 0; public Options() { @@ -22,34 +23,35 @@ public Options() void Options_Load(object sender, EventArgs e) { autorun_enabled = Program.IsStartupItem(); + silent = Properties.Settings.Default.silent_mode; if (autorun_enabled) { IsEnabledLbl.Text = "ENABLED"; IsEnabledLbl.ForeColor = Color.DarkGreen; - ToggleActionBtn.Text = "Disable Autorun"; + AutoRunChkBox.Checked = true; } else { IsEnabledLbl.Text = "DISABLED"; IsEnabledLbl.ForeColor = Color.DarkRed; - ToggleActionBtn.Text = "Enable Autorun"; + AutoRunChkBox.Checked = false; } - TimeIntTxt.Text = Properties.Settings.Default.refresh_interval.ToString(); - } - - private void ToggleActionBtn_Click(object sender, EventArgs e) - { - if (autorun_enabled) + if (silent==1) { - Program.DisableAutoStartup(); + SilentIsEnabledLbl.Text = "ENABLED"; + SilentIsEnabledLbl.ForeColor = Color.DarkGreen; + SilentChkBox.Checked = true; } else { - Program.EnableAutoStartup(); + SilentIsEnabledLbl.Text = "DISABLED"; + SilentIsEnabledLbl.ForeColor = Color.DarkRed; + SilentChkBox.Checked = false; } - Options_Load(null, null); + + TimeIntTxt.Text = Properties.Settings.Default.refresh_interval.ToString(); } private void SetTimeBtn_Click(object sender, EventArgs e) @@ -64,9 +66,37 @@ private void SetTimeBtn_Click(object sender, EventArgs e) SetTimeBtn.Text = "Done!"; SetTimeBtn.Enabled = false; - Program.UpdateTime(); + Properties.Settings.Default.Save(); + + Program.UpdateTime(); + } + + private void AutoRunChkBox_CheckedChanged(object sender, EventArgs e) + { + if (autorun_enabled) + { + Program.DisableAutoStartup(); + } + else + { + Program.EnableAutoStartup(); + } + Options_Load(null, null); + } + private void SilentChkBox_CheckedChanged(object sender, EventArgs e) + { + if (silent==1) + { + Properties.Settings.Default.silent_mode = 0; + } + else + { + Properties.Settings.Default.silent_mode = 1; + } + Options_Load(null, null); Properties.Settings.Default.Save(); + Program.UpdateSilent(); } } diff --git a/PSpaceStatusChanger/PSpaceStatusChanger.csproj b/PSpaceStatusChanger/PSpaceStatusChanger.csproj index 475db99..de9f347 100644 --- a/PSpaceStatusChanger/PSpaceStatusChanger.csproj +++ b/PSpaceStatusChanger/PSpaceStatusChanger.csproj @@ -25,7 +25,7 @@ false true http://www.p-space.gr - 0 + 2 1.1.0.%2a false true diff --git a/PSpaceStatusChanger/Program.cs b/PSpaceStatusChanger/Program.cs index 1491cd2..900e5f6 100644 --- a/PSpaceStatusChanger/Program.cs +++ b/PSpaceStatusChanger/Program.cs @@ -12,6 +12,7 @@ public static class Program static Timer tim; static int oldstatus = -5; static int olddate = 0; + static int silent = 0; static void Main() { @@ -27,6 +28,7 @@ static void Main() System.Diagnostics.Process.GetCurrentProcess().Kill(); } + silent = Properties.Settings.Default.silent_mode; pi = new TrayIcon(); pi.Display(); // Make sure the application runs! @@ -57,14 +59,17 @@ static void tim_Tick(object sender, EventArgs e) oldstatus = newstatus; } - var lastevents = Requests.GetLastEvents(1); - if (lastevents!=null && lastevents[0].t != olddate) + if (silent!=1) { - if (olddate!=0) + var lastevents = Requests.GetLastEvents(1); + if (lastevents != null && lastevents[0].t != olddate) { - pi.ShowMessage("P-Space Door Event", lastevents[0].extra); - } - olddate = lastevents[0].t; + if (olddate != 0) + { + pi.ShowMessage("P-Space Door Event", lastevents[0].extra); + } + olddate = lastevents[0].t; + } } } @@ -73,6 +78,11 @@ public static void UpdateTime() tim.Interval = Properties.Settings.Default.refresh_interval * 1000; } + public static void UpdateSilent() + { + silent = Properties.Settings.Default.silent_mode; + } + public static void EnableAutoStartup() { // The path to the key where Windows looks for startup applications diff --git a/PSpaceStatusChanger/Properties/Settings.Designer.cs b/PSpaceStatusChanger/Properties/Settings.Designer.cs index f5bbb83..8fa1f7e 100644 --- a/PSpaceStatusChanger/Properties/Settings.Designer.cs +++ b/PSpaceStatusChanger/Properties/Settings.Designer.cs @@ -34,5 +34,17 @@ public int refresh_interval { this["refresh_interval"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public int silent_mode { + get { + return ((int)(this["silent_mode"])); + } + set { + this["silent_mode"] = value; + } + } } } diff --git a/PSpaceStatusChanger/Properties/Settings.settings b/PSpaceStatusChanger/Properties/Settings.settings index 1598d2c..de07ffd 100644 --- a/PSpaceStatusChanger/Properties/Settings.settings +++ b/PSpaceStatusChanger/Properties/Settings.settings @@ -5,5 +5,8 @@ 1 + + 0 + \ No newline at end of file diff --git a/PSpaceStatusChanger/app.config b/PSpaceStatusChanger/app.config index 7313206..e3a3dc7 100644 --- a/PSpaceStatusChanger/app.config +++ b/PSpaceStatusChanger/app.config @@ -10,6 +10,9 @@ 1 + + 0 + \ No newline at end of file