This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotificationIcon.cs
206 lines (182 loc) · 5.35 KB
/
NotificationIcon.cs
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
/*
* Erstellt mit SharpDevelop.
* Benutzer: rschmidt
* Datum: 11.08.2008
* Zeit: 13:20
*
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
*/
using System;
using System.Diagnostics;
using System.Collections;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using Text2Speech;
using WLA;
namespace V_Learning_Aid
{
/**
* Handles notification icon
*/
public sealed class NotificationIcon
{
private NotifyIcon notifyIcon;
private ContextMenu notificationMenu;
private ConfigForm1 cfgform = new ConfigForm1 ();
public NotificationIcon notificationIcon;
private System.Timers.Timer earTimer = new System.Timers.Timer ();
private Speech voice = new Speech ();
#region
/**
* Initialize icon and menu
*/
public NotificationIcon ()
{
notifyIcon = new NotifyIcon ();
notificationMenu = new ContextMenu (InitializeMenu ());
notifyIcon.DoubleClick += IconDoubleClick;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager (typeof(NotificationIcon));
notifyIcon.Icon = (Icon)resources.GetObject ("$this.Icon");
notifyIcon.ContextMenu = notificationMenu;
VLA testvla = new VLA ();
earTimer.AutoReset = true;
earTimer.Interval = 5000;
earTimer.Elapsed += new System.Timers.ElapsedEventHandler (this.t_Elapsed);
earTimer.Start ();
this.setInterval ();
}
/**
* Set interval
*/
private void setInterval ()
{
int i = 5;
int u = 0;
i = Settings.getInt ("intervalInt");
u = Settings.getInt ("intervalUnit");
switch (u) {
case 1:
i = i * 1000 * 60;
break;
case 2:
i = i * 1000 * 60 * 60;
break;
case 0:
default:
i = i * 1000;
break;
}
if (earTimer.Interval != i) {
earTimer.Interval = i + 1;
earTimer.Stop ();
earTimer.Start ();
}
}
/**
* Supply comment
*/
private void t_Elapsed (object sender, System.Timers.ElapsedEventArgs e)
{
if (cfgform.Visible || cfgform.newitems.ytems.Count == 0) {
return;
}
this.setInterval ();
if (!cfgform.newitems.Dice ()) {
return;
}
Item item = cfgform.newitems.Next ();
String content = item.head + "\n\n" + item.body;
if (content.Length > 252) {
content = content.Substring (0, 252) + "...";
}
notifyIcon.ShowBalloonTip (10000, "WLA", content, ToolTipIcon.Info);
voice.SpeakBalloonTip (item.head, item.body, Settings.getBool ("speakTooltip"));
}
/**
* Initialize menu
*/
private MenuItem[] InitializeMenu ()
{
MenuItem[] menu = new MenuItem[] {
new MenuItem ("About", menuAboutClick),
new MenuItem ("Config", menuConfigClick),
new MenuItem ("Exit", menuExitClick)
};
return menu;
}
#endregion
#region Main - Program entry point
/// <summary>Program entry point.</summary>
/// <param name="args">Command Line Arguments</param>
[STAThread]
/**
* Program entry point
*/
public static void Main (string[] args)
{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault (false);
bool isFirstInstance;
// Please use a unique name for the mutex to prevent conflicts with other programs
using (Mutex mtx = new Mutex(true, "V_Learning_Aid", out isFirstInstance)) {
if (isFirstInstance) {
NotificationIcon notificationIcon = new NotificationIcon ();
notificationIcon.notifyIcon.Visible = true;
//notificationIcon.notifyIcon.ShowBalloonTip(100,((Item)items[0]).o,((Item)items[1]).t,ToolTipIcon.Info);
notificationIcon.notifyIcon.ShowBalloonTip (100, "Message", "WLA started", ToolTipIcon.Info);
Application.Run ();
notificationIcon.notifyIcon.Dispose ();
} else {
// The application is already running
// TODO: Display message box or change focus to existing application instance
}
} // releases the Mutex
}
#endregion
#region Event Handlers
/**
* "About" menu event handler
*/
private void menuAboutClick (object sender, EventArgs e)
{
String txt = "Win Learning Aid v0.5.4b Copyright (C) 2008-2012 René Schmidt\n\nWin Learning Aid is a small tray icon tool that periodically shows nodes from Freemind files in a tray icon tooltip. See http://freemind.sourceforge.net/ for information regarding Freemind.\n\nThis program comes with NO WARRANTY, to the extent permitted by applicable law. See the file named GPL.txt for details.";
String title = "About";
MessageBox.Show (txt, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/**
* "Config" menu event handler
*/
private void menuConfigClick (object sender, EventArgs e)
{
earTimer.Interval = 10000;
cfgform.Show ();
}
/**
* "Exit" menu event handler
*/
private void menuExitClick (object sender, EventArgs e)
{
Application.Exit ();
}
/**
* Icon double click event handler
*/
private void IconDoubleClick (object sender, EventArgs e)
{
earTimer.Interval = 10000;
cfgform.Show ();
}
/**
* Disposer
*/
public void Dispose ()
{
earTimer.Dispose ();
cfgform.Dispose ();
notificationIcon.Dispose ();
notifyIcon.Dispose ();
}
#endregion
}
}