forked from Ken98045/On-Guard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotificationOptionsDialog.cs
250 lines (200 loc) · 6.28 KB
/
NotificationOptionsDialog.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
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
using System;
using System.Windows.Forms;
namespace SAAI
{
public partial class NotificationOptionsDialog : Form
{
readonly AreaOfInterest _area;
public NotificationOptionsDialog(AreaOfInterest area)
{
_area = area;
InitializeComponent();
int count = 0;
if (area.Notifications != null && area.Notifications.Urls != null)
{
foreach (var urlOptions in area.Notifications.Urls)
{
ListViewItem urlItem = new ListViewItem(new string[] { urlOptions.Url, urlOptions.WaitTime.ToString(), urlOptions.CoolDown.CooldownTime.ToString() });
urlsList.Items.Add(urlItem);
urlItem.Tag = urlOptions;
++count;
}
if (urlsList.Items.Count > 0)
{
urlsList.Items[0].Selected = true;
urlsList.Select();
}
NoMotionUrlNotify.Text = area.Notifications.NoMotionUrlNotify;
NoMotionMQTTCheck.Checked = area.Notifications.NoMotionMQTTNotify;
UseMQTTBox.Checked = area.Notifications.UseMQTT;
}
count = 0;
if (area.Notifications.Email != null)
{
foreach (var address in area.Notifications.Email)
{
ListViewItem emailItem = new ListViewItem(address);
emailsList.Items.Add(emailItem);
++count;
}
if (emailsList.Items.Count > 0)
{
emailsList.Items[0].Selected = true;
emailsList.Select();
}
}
UseMQTTBox.Checked = area.Notifications.UseMQTT;
}
private void OkButton_Click(object sender, EventArgs e)
{
_area.Notifications.Email.Clear();
if (_area.Notifications.Urls != null)
{
_area.Notifications.Urls.Clear();
_area.Notifications.Urls.Clear();
foreach (ListViewItem url in urlsList.Items)
{
UrlOptions option = (UrlOptions)url.Tag;
_area.Notifications.Urls.Add(option);
}
}
if (emailsList.Items != null)
{
foreach (ListViewItem email in emailsList.Items)
{
_area.Notifications.Email.Add(email.Text);
}
}
_area.Notifications.NoMotionMQTTNotify = NoMotionMQTTCheck.Checked;
_area.Notifications.NoMotionUrlNotify = NoMotionUrlNotify.Text;
_area.Notifications.UseMQTT = UseMQTTBox.Checked;
DialogResult = DialogResult.OK;
}
private void CancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void AddUrlButton_Click(object sender, EventArgs e)
{
AddEditURL(null);
}
private void OnActivateURL(object sender, EventArgs e)
{
ListViewItem item = urlsList.Items[urlsList.SelectedIndices[0]];
UrlOptions options = (UrlOptions)item.Tag;
AddEditURL(options);
}
private void AddEditURL(UrlOptions options)
{
bool added = false;
if (null == options)
{
added = true;
}
using (AddUrlDialog dlg = new AddUrlDialog(options))
{
if (dlg.ShowDialog() == DialogResult.OK)
{
ListViewItem item;
int index = 0;
if (added)
{
item = new ListViewItem(new string[] { dlg.Options.Url, dlg.Options.WaitTime.ToString(), dlg.Options.CoolDown.CooldownTime.ToString() });
urlsList.Items.Add(item);
index = item.Index;
}
else
{
// editing
item = urlsList.Items[urlsList.SelectedIndices[0]];
index = item.Index;
item.SubItems[0].Text = dlg.Options.Url; // update the stuff
item.SubItems[1].Text = dlg.Options.WaitTime.ToString();
item.SubItems[2].Text = dlg.Options.CoolDown.CooldownTime.ToString();
}
urlsList.Items[index].Tag = dlg.Options;
urlsList.Items[index].Focused = true;
urlsList.Items[index].Selected = true;
}
}
}
private void RemoveUrlButton_Click(object sender, EventArgs e)
{
if (!(urlsList.SelectedIndices.Count > 0))
{
MessageBox.Show("You must select a row in order to delete it");
}
else
{
urlsList.Items.RemoveAt(urlsList.SelectedIndices[0]);
}
}
private void AddEmailButton_Click(object sender, EventArgs e)
{
using (AddEmailDlg dlg = new AddEmailDlg())
{
if (dlg.ShowDialog() == DialogResult.OK)
{
bool duplicate = false;
foreach (ListViewItem anItem in emailsList.Items)
{
if (anItem.SubItems[0].Text == dlg.EmailAddress)
{
duplicate = true;
break;
}
}
if (duplicate)
{
MessageBox.Show(this, "Every email address must be unique", "Duplicate Found!");
}
else
{
ListViewItem item;
ListViewItem[] items = emailsList.Items.Find(dlg.EmailAddress, false);
if (items.Length == 0)
{
item = emailsList.Items.Add(dlg.EmailAddress);
}
else
{
item = items[0];
}
item.Checked = true;
item.Selected = true;
emailsList.Select();
}
}
}
}
private void RemoveEmailButton_Click(object sender, EventArgs e)
{
if (!(emailsList.SelectedIndices.Count > 0))
{
MessageBox.Show("You must select a row in order to delete it");
}
else
{
emailsList.Items.RemoveAt(emailsList.SelectedIndices[0]);
}
}
private void Check247_Checked(object sender, EventArgs e)
{
}
private void bs_CurrentChanged(object sender, EventArgs e)
{
}
private void SelectionChanged(object sender, EventArgs e)
{
}
private void OnItemCheckChanged(object sender, ItemCheckEventArgs e)
{
}
private void NumberOfImages_ValueChanged(object sender, EventArgs e)
{
}
private void SizeImageToNumeric_ValueChanged(object sender, EventArgs e)
{
}
}
}