[go: up one dir, main page]

Menu

[9454be]: / Startup.cs  Maximize  Restore  History

Download this file

290 lines (264 with data), 10.7 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/***********************************************************************************
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;
using System.ComponentModel;
using System.Globalization;
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;
//private readonly ComponentResourceManager _resource;
public CultureInfo currentCulture;
//Modules
AudioPlayer player;
TimeKeeper keeper;
TimeTeller teller;
FileHandler handle;
//Localization localization;
//Local class variables
bool state, clickToTalk, alertIntrvl, tellTime;
int selectedSound;
string start, end;
public Startup()
{
player = new AudioPlayer();
keeper = new TimeKeeper();
teller = new TimeTeller();
handle = new FileHandler();
//localization = new Localization();
//_resource = new ComponentResourceManager(typeof(Startup));
//System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("ta");
//currentCulture = CultureInfo.CreateSpecificCulture("en");
}
/// <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
//_resource.ApplyResources(this.ico, "ico");
this.ico.Icon=Properties.Resources.trayIcon;
ico.Text = Contents.icoText;//"A clock that rings every hour";
this.ico.Visible=true;
this.ico.ContextMenuStrip = menu;
this.ico.MouseClick += new MouseEventHandler(ico_MouseClick);
//about properties.
//_resource.ApplyResources(this.about, "about");
about.Text = Contents.aboutText;//"About Clock alert";
about.Name = "about";
about.Click += new EventHandler(about_Click);
menu.Items.Add(about);
//chkUpdate property
//_resource.ApplyResources(this.chkUpdate, "chkUpdate");
chkUpdate.Text = Contents.chkUpdateText;//"Check for updates";
chkUpdate.Click += new EventHandler(chkUpdate_Click);
menu.Items.Add(chkUpdate);
// settings properties
//_resource.ApplyResources(this.settings, "settings");
settings.Text = Contents.settingsText;//"Settings";
settings.AutoSize = true;
settings.Click += new EventHandler(settings_Click);
menu.Items.Add(settings);
//turnoff properties
//_resource.ApplyResources(this.turnoff, "turnoff");
turnoff.Text = Contents.turnoffText;//"Turn off";
turnoff.AutoSize = true;
turnoff.Click += new EventHandler(turnoff_Click);
menu.Items.Add(turnoff);
//clock properties
clock.Interval = 1000;
clock.Tick += new EventHandler(clock_Tick);
//close properties
//_resource.ApplyResources(this.close, "close");
close.Text = Contents.closeText;//"Close";
close.AutoSize = true;
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)
{
if (clickToTalk)
{
teller.talk(Contents.speakText + DateTime.Now.ToString("hh:mm tt"));
}
}
}
void close_Click(object sender, EventArgs e)
{
Application.Exit();
}
/// <summary>
/// Initializes the application
/// </summary>
public void startApp()
{
//localization.configure();
loadSettings();
if (tellTime == false)
{
loadSound();
}
initializeComponents();
clock.Start();
state = true;
}
void clock_Tick(object sender, EventArgs e)
{
if (alertIntrvl)
{
if (keeper.isBetween(DateTime.Now, Convert.ToDateTime(start), Convert.ToDateTime(end)))
{
if (keeper.isItTime())
{
try
{
clock.Stop();
if (tellTime == false)
player.playAsynch();
else
teller.talk("The time is " + DateTime.Now.ToString("hh:mm tt"));
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();
}
}
}
}
else
{
if (keeper.isItTime())
{
try
{
clock.Stop();
if (tellTime == false)
player.playAsynch();
else
teller.talk("The time is " + DateTime.Now.ToString("hh:mm tt"));
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 = Contents.clockOn;//_resource.GetString("clock on");
state = false;
}
else
{
clock.Start();
turnoff.Text = Contents.clockOff;//_resource.GetString("clock off");
state = true;
}
}
void settings_Click(object sender, EventArgs e)
{
SettingsForm settings = new SettingsForm();
settings.TopMost = true;
settings.ShowDialog();
//throw new NotImplementedException();
}
/// <summary>
/// Loads the application settings form disk.
/// </summary>
void loadSettings()
{
//MessageBox.Show(Properties.Settings.Default.TellTime.ToString());
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.SelectedLanguage);
selectedSound = Properties.Settings.Default.CurrentSound;
clickToTalk = Properties.Settings.Default.ClickToTalk;
alertIntrvl = Properties.Settings.Default.AlertInterval;
start = Properties.Settings.Default.StartHour + ":" + Properties.Settings.Default.StartMin + " " + ((Properties.Settings.Default.StartTT == 0) ? "AM" : "PM");
end = Properties.Settings.Default.EndHour + ":" + Properties.Settings.Default.EndMin + " " + ((Properties.Settings.Default.EndTT == 0) ? "AM" : "PM");
tellTime = Properties.Settings.Default.TellTime;
}
/// <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();
}
}
}