[go: up one dir, main page]

Menu

[5b1ca9]: / Startup.cs  Maximize  Restore  History

Download this file

222 lines (197 with data), 6.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/***********************************************************************************
This file is part of Clock Alert.
Clock Alert is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as published by
the Free Software Foundation.
Clock Alert 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 Clock Alert. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace Clock_Alert
{
/// <summary>
/// Defines the application properties and process
/// </summary>
class Startup: IDisposable
{
//Components
NotifyIcon ico;
ContextMenuStrip menu;
ToolStripMenuItem settings,turnoff,close,chkUpdate,about;
Timer clock;
//Modules
AudioPlayer player;
TimeKeeper keeper;
TimeTeller teller;
FileHandler handle;
//Local class variables
bool state;
int selectedSound;
public Startup()
{
player = new AudioPlayer();
keeper = new TimeKeeper();
teller = new TimeTeller();
handle = new FileHandler();
}
/// <summary>
/// Initializes the components for the application
/// </summary>
public void initializeComponents()
{
ico=new NotifyIcon();
menu=new ContextMenuStrip();
settings=new ToolStripMenuItem();
turnoff=new ToolStripMenuItem();
close = new ToolStripMenuItem();
chkUpdate = new ToolStripMenuItem();
about = new ToolStripMenuItem();
clock = new Timer();
//Tray icon properties
ico.Icon=Properties.Resources.trayIcon;
ico.Text="A clock that rings every hour";
ico.Visible=true;
ico.ContextMenuStrip = menu;
ico.MouseClick += new MouseEventHandler(ico_MouseClick);
//about properties.
about.Text = "About Clock alert";
about.Click += new EventHandler(about_Click);
menu.Items.Add(about);
//chkUpdate property
chkUpdate.Text = "Check for updates";
chkUpdate.Click += new EventHandler(chkUpdate_Click);
menu.Items.Add(chkUpdate);
// settings properties
settings.Text="Settings";
settings.Click += new EventHandler(settings_Click);
menu.Items.Add(settings);
//turnoff properties
turnoff.Text = "Turn off";
turnoff.Click += new EventHandler(turnoff_Click);
menu.Items.Add(turnoff);
//clock properties
clock.Interval = 1000;
clock.Tick += new EventHandler(clock_Tick);
//close properties
close.Text = "Close";
close.Click += new EventHandler(close_Click);
menu.Items.Add(close);
}
void about_Click(object sender, EventArgs e)
{
AboutClockAlert aboutWindow = new AboutClockAlert();
aboutWindow.Show();
}
void chkUpdate_Click(object sender, EventArgs e)
{
AppUpdate updater = new AppUpdate();
updater.checkForUpdate();
}
void ico_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
teller.talk("It's " + DateTime.Now.ToString("hh:mm tt"));
}
}
void close_Click(object sender, EventArgs e)
{
Application.Exit();
}
/// <summary>
/// Initializes the application
/// </summary>
public void startApp()
{
loadSettings();
loadSound();
initializeComponents();
clock.Start();
state = true;
}
void clock_Tick(object sender, EventArgs e)
{
if (keeper.isItTime())
{
try
{
clock.Stop();
player.play();
clock.Start();
}
catch (Exception ex)
{
clock.Stop();
//MessageBox.Show(ErrorLog.logError(ex), "Error - Clock Alert", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
CrashReporterUI reportWindow= new CrashReporterUI(ex);
reportWindow.ShowDialog();
}
}
}
void turnoff_Click(object sender, EventArgs e)
{
if (state == true)
{
clock.Stop();
turnoff.Text = "Turn On";
}
else
{
clock.Start();
turnoff.Text = "Turn Off";
}
}
void settings_Click(object sender, EventArgs e)
{
Form1 settings = new Form1();
settings.TopMost = true;
settings.Show();
//throw new NotImplementedException();
}
/// <summary>
/// Loads the application settings form disk.
/// </summary>
void loadSettings()
{
selectedSound = Properties.Settings.Default.CurrentSound;
}
/// <summary>
/// Loads the sound for playing the alert tone.
/// </summary>
void loadSound()
{
if (selectedSound == 1)
{
player = new AudioPlayer(Properties.Resources.sound);
}
else if (selectedSound == 2)
{
player = new AudioPlayer(Properties.Resources.sound2);
}
else if (selectedSound == 3)
{
player = new AudioPlayer(Properties.Resources.sound3);
}
else if (selectedSound == 4)
{
player = new AudioPlayer(Properties.Resources.sound4);
}
}
/// <summary>
/// Disposes the objects of this class.
/// </summary>
public void Dispose()
{
ico.Dispose();
clock.Dispose();
}
}
}