corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) 2006-2014, openmetaverse.org |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * - Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * |
||
8 | * - Redistributions of source code must retain the above copyright notice, this |
||
9 | * list of conditions and the following disclaimer. |
||
10 | * - Neither the name of the openmetaverse.org nor the names |
||
11 | * of its contributors may be used to endorse or promote products derived from |
||
12 | * this software without specific prior written permission. |
||
13 | * |
||
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
24 | * POSSIBILITY OF SUCH DAMAGE. |
||
25 | */ |
||
26 | |||
27 | using System; |
||
28 | using System.Collections; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Drawing; |
||
31 | using System.Windows.Forms; |
||
32 | |||
33 | namespace OpenMetaverse.GUI |
||
34 | { |
||
35 | |||
36 | /// <summary> |
||
37 | /// ListView GUI component for viewing a client's friend list |
||
38 | /// </summary> |
||
39 | public class FriendList : ListView |
||
40 | { |
||
41 | private GridClient _Client; |
||
42 | private ListColumnSorter _ColumnSorter = new ListColumnSorter(); |
||
43 | |||
44 | public delegate void FriendDoubleClickCallback(FriendInfo friend); |
||
45 | |||
46 | /// <summary> |
||
47 | /// Triggered when the user double clicks on a friend in the list |
||
48 | /// </summary> |
||
49 | public event FriendDoubleClickCallback OnFriendDoubleClick; |
||
50 | |||
51 | /// <summary> |
||
52 | /// Gets or sets the GridClient associated with this control |
||
53 | /// </summary> |
||
54 | public GridClient Client |
||
55 | { |
||
56 | get { return _Client; } |
||
57 | set { if (value != null) InitializeClient(value); } |
||
58 | } |
||
59 | |||
60 | /// <summary> |
||
61 | /// TreeView control for an unspecified client's friend list |
||
62 | /// </summary> |
||
63 | public FriendList() |
||
64 | { |
||
65 | ColumnHeader header1 = this.Columns.Add("Friend"); |
||
66 | header1.Width = this.Width - 20; |
||
67 | |||
68 | ColumnHeader header2 = this.Columns.Add(" "); |
||
69 | header2.Width = 40; |
||
70 | |||
71 | _ColumnSorter.SortColumn = 1; |
||
72 | _ColumnSorter.Ascending = false; |
||
73 | |||
74 | this.DoubleBuffered = true; |
||
75 | this.ListViewItemSorter = _ColumnSorter; |
||
76 | this.View = View.Details; |
||
77 | |||
78 | this.ColumnClick += new ColumnClickEventHandler(FriendList_ColumnClick); |
||
79 | this.DoubleClick += new System.EventHandler(FriendList_DoubleClick); |
||
80 | } |
||
81 | |||
82 | /// <summary> |
||
83 | /// TreeView control for the specified client's friend list |
||
84 | /// </summary> |
||
85 | public FriendList(GridClient client) : this () |
||
86 | { |
||
87 | InitializeClient(client); |
||
88 | } |
||
89 | |||
90 | private void InitializeClient(GridClient client) |
||
91 | { |
||
92 | _Client = client; |
||
93 | _Client.Friends.FriendNames += Friends_FriendNames; |
||
94 | _Client.Friends.FriendOffline += Friends_FriendUpdate; |
||
95 | _Client.Friends.FriendOnline += Friends_FriendUpdate; |
||
96 | _Client.Network.LoginProgress += Network_OnLogin; |
||
97 | } |
||
98 | |||
99 | void Friends_FriendNames(object sender, FriendNamesEventArgs e) |
||
100 | { |
||
101 | RefreshFriends(); |
||
102 | } |
||
103 | |||
104 | void Friends_FriendUpdate(object sender, FriendInfoEventArgs e) |
||
105 | { |
||
106 | RefreshFriends(); |
||
107 | } |
||
108 | |||
109 | |||
110 | private void RefreshFriends() |
||
111 | { |
||
112 | if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { RefreshFriends(); }); |
||
113 | else |
||
114 | { |
||
115 | Client.Friends.FriendList.ForEach(delegate(FriendInfo friend) |
||
116 | { |
||
117 | string key = friend.UUID.ToString(); |
||
118 | string onlineText; |
||
119 | string name = friend.Name == null ? "(loading...)" : friend.Name; |
||
120 | int image; |
||
121 | Color color; |
||
122 | |||
123 | if (friend.IsOnline) |
||
124 | { |
||
125 | image = 1; |
||
126 | onlineText = "*"; |
||
127 | color = Color.FromKnownColor(KnownColor.ControlText); |
||
128 | } |
||
129 | else |
||
130 | { |
||
131 | image = 0; |
||
132 | onlineText = " "; |
||
133 | color = Color.FromKnownColor(KnownColor.GrayText); |
||
134 | } |
||
135 | |||
136 | if (!this.Items.ContainsKey(key)) |
||
137 | { |
||
138 | this.Items.Add(key, name, image); |
||
139 | this.Items[key].SubItems.Add(onlineText); |
||
140 | } |
||
141 | else |
||
142 | { |
||
143 | if (this.Items[key].Text == string.Empty || friend.Name != null) |
||
144 | this.Items[key].Text = name; |
||
145 | |||
146 | this.Items[key].SubItems[1].Text = onlineText; |
||
147 | } |
||
148 | |||
149 | this.Items[key].ForeColor = color; |
||
150 | this.Items[key].ImageIndex = image; |
||
151 | this.Items[key].Tag = friend; |
||
152 | }); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | private void FriendList_ColumnClick(object sender, ColumnClickEventArgs e) |
||
157 | { |
||
158 | _ColumnSorter.SortColumn = e.Column; |
||
159 | if ((_ColumnSorter.Ascending = (this.Sorting == SortOrder.Ascending))) this.Sorting = SortOrder.Descending; |
||
160 | else this.Sorting = SortOrder.Ascending; |
||
161 | this.ListViewItemSorter = _ColumnSorter; |
||
162 | } |
||
163 | |||
164 | private void FriendList_DoubleClick(object sender, System.EventArgs e) |
||
165 | { |
||
166 | if (OnFriendDoubleClick != null) |
||
167 | { |
||
168 | ListView list = (ListView)sender; |
||
169 | if (list.SelectedItems.Count > 0 && list.SelectedItems[0].Tag is FriendInfo) |
||
170 | { |
||
171 | FriendInfo friend = (FriendInfo)list.SelectedItems[0].Tag; |
||
172 | try { OnFriendDoubleClick(friend); } |
||
173 | catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | |||
178 | private void Network_OnLogin(object sender, LoginProgressEventArgs e) |
||
179 | { |
||
180 | if (e.Status == LoginStatus.Success) |
||
181 | { |
||
182 | RefreshFriends(); |
||
183 | } |
||
184 | } |
||
185 | |||
186 | } |
||
187 | } |