-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfrmContactList.cs
304 lines (262 loc) · 9.27 KB
/
frmContactList.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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using jabber.client;
using System.Net;
using System.IO;
using LolChatWin.Properties;
namespace LolChatWin
{
public partial class frmContactList : Form
{
public frmContactList()
{
InitializeComponent();
}
JabberManager jm = new JabberManager();
public Dictionary<User, frmMessage> msgWindows = new Dictionary<User, frmMessage>();
Dictionary<string, ListViewGroup> grps = new Dictionary<string, ListViewGroup>();
private bool Started = false;
private int getServer()
{
if (radioButton1.Checked)
{
return 0;
}
else if (radioButton2.Checked)
{
return 1;
}
else
{
return 2;
}
}
private void setServer(int value)
{
if (value == 0)
{
radioButton1.Checked = true;
}
else if (value == 1)
{
radioButton2.Checked = true;
}
else
{
radioButton3.Checked = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
Settings.Default.Username = txtUsername.Text;
Settings.Default.Password = JabberManager.EncryptString(JabberManager.ToSecureString(txtPassword.Text));
Settings.Default.Server = getServer();
Settings.Default.Save();
Connect();
}
void jm_OnMessage(User From, string message, DateTime Date)
{
ShowWindow(From);
msgWindows[From].gotMessage(Date, message);
}
private void ShowWindow(User From)
{
if (msgWindows.ContainsKey(From))
{
msgWindows[From].Show();
msgWindows[From].Activate();
}
else
{
frmMessage newWindow = new frmMessage();
newWindow.Images = imgChamps;
newWindow.StartPosition = FormStartPosition.Manual;
newWindow.Location = new Point(SystemInformation.VirtualScreen.Width / 2 - 100 + msgWindows.Count * 30, SystemInformation.VirtualScreen.Height / 2 - 100 + msgWindows.Count * 30);
newWindow.theUser = From;
newWindow.Closed += new frmMessage.CloseHandler(newWindow_Closed);
newWindow.jm = jm;
msgWindows.Add(From, newWindow);
newWindow.Show();
}
}
void newWindow_Closed(User e)
{
if (msgWindows.ContainsKey(e))
{
msgWindows.Remove(e);
}
}
void jm_UserChanged(User e)
{
UpdateNode(e);
}
private void UpdateNode(User u)
{
if ( (!u.isOnline) || (u.status == null))
{
if (lstBuddies.Items.ContainsKey(u.JID))
{
lstBuddies.Items.RemoveByKey(u.JID);
if (jm.theUsers.Where(p => p.Group == u.Group).Count() == 1)
{
grps.Remove(u.Group);
}
}
}
else
{
ListViewItem k;
if (!lstBuddies.Items.ContainsKey(u.JID))
{
k = lstBuddies.Items.Add(u.JID, u.Nickname, u.State);
k.SubItems.Add("");
k.SubItems.Add("");
k.SubItems.Add("");
k.UseItemStyleForSubItems = false;
}
else
{
k = lstBuddies.Items[u.JID];
}
k.SubItems[0].Text = u.Nickname;
k.SubItems[0].Font = new Font(k.SubItems[0].Font.FontFamily, 9, FontStyle.Bold);
if (u.State == "outOfGame")
{
k.SubItems[0].ForeColor = Color.Green;
}
else
{
k.SubItems[0].ForeColor = Color.OrangeRed;
}
if (u.State == "")
k.SubItems[1].Text = "";
else
{
k.SubItems[1].Text = (u.State + " for " + u.duration + " mins");
}
k.SubItems[2].Text = ("Normal: " + u.wins + " wins " + u.leaves + " leaves");
if (u.rankedRating != "0")
k.SubItems[3].Text = ("Ranked: " + u.rankedRating + " rating " + u.rankedWins + " wins " + u.rankedLosses + " losses");
k.ImageKey = u.State;
if (!grps.ContainsKey(u.Group))
{
grps.Add(u.Group, lstBuddies.Groups.Add(u.Group, u.Group));
((ListViewGroupSorter)lstBuddies).SortGroups(true);
}
k.Group = grps[u.Group];
}
}
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
ShowInTaskbar = false;
else
ShowInTaskbar = true;
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
WindowState = FormWindowState.Normal;
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
try
{
ShowWindow(jm.users[lstBuddies.SelectedItems[0].Name]);
}
catch (Exception ex)
{
}
}
private void btnDisconnect_Click(object sender, EventArgs e)
{
btnDisconnect.Text = "Disconnecting...";
jm.Disconnect();
}
private void frmContactList_Load(object sender, EventArgs e)
{
Settings.Default.Reload();
if (Settings.Default.Top > 0)
{
Location = new Point( Settings.Default.Left, Settings.Default.Top);
}
Started = true;
foreach (string file in Directory.GetFiles(Path.Combine( Path.GetDirectoryName( Application.ExecutablePath ) ,"Champs")))
{
imgChamps.Images.Add(Path.GetFileNameWithoutExtension( file), Image.FromFile(file));
}
lstBuddies.Columns.Add("Nickname");
lstBuddies.Columns.Add("duration");
lstBuddies.Columns.Add("rankedRating");
lstBuddies.Columns.Add("State");
jm.UserChanged += new JabberManager.UserChangedHandler(jm_UserChanged);
jm.OnMessage += new JabberManager.MsgHandler(jm_OnMessage);
jm.OnConnect += new JabberManager.ConnectedHandler(jm_OnConnect);
jm.OnDisconnect += new JabberManager.ConnectedHandler(jm_OnDisconnect);
jm.OnError += new JabberManager.ErrorHandler(jm_OnError);
txtUsername.Text = Settings.Default.Username;
txtPassword.Text = JabberManager.ToInsecureString(JabberManager.DecryptString(Settings.Default.Password));
setServer(Settings.Default.Server);
if ((Settings.Default.Username != "") && (Settings.Default.Password != ""))
{
Connect();
}
else
{
pblConnect.Visible = true;
btnDisconnect.Text = "Connect";
}
}
void jm_OnError(string error)
{
MessageBox.Show(error,"Error");
}
void jm_OnDisconnect()
{
pblConnect.Visible = true;
btnDisconnect.Text = "Connect";
}
void jm_OnConnect()
{
pblConnect.Visible = false;
btnDisconnect.Text = "Disconnect";
}
private void Connect()
{
btnDisconnect.Text = "Connecting...";
try
{
jm.Initialize(txtUsername.Text, txtPassword.Text, getServer(), this);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void frmContactList_Move(object sender, EventArgs e)
{
try
{
if (Started && (WindowState == FormWindowState.Normal))
{
Settings.Default.Top = Location.Y;
Settings.Default.Left = Location.X;
Settings.Default.Save();
}
}
catch
{
}
}
private void btnAbout_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://vrokolos.github.com/LeagueChat/");
}
}
}