OSDN Git Service

RAD-79 (progress) Added resident picker for group invitations
[radegast/radegast.git] / Radegast / GUI / Consoles / AvatarPicker.cs
1 // \r
2 // Radegast Metaverse Client\r
3 // Copyright (c) 2009, Radegast Development Team\r
4 // All rights reserved.\r
5 // \r
6 // Redistribution and use in source and binary forms, with or without\r
7 // modification, are permitted provided that the following conditions are met:\r
8 // \r
9 //     * Redistributions of source code must retain the above copyright notice,\r
10 //       this list of conditions and the following disclaimer.\r
11 //     * Redistributions in binary form must reproduce the above copyright\r
12 //       notice, this list of conditions and the following disclaimer in the\r
13 //       documentation and/or other materials provided with the distribution.\r
14 //     * Neither the name of the application "Radegast", nor the names of its\r
15 //       contributors may be used to endorse or promote products derived from\r
16 //       this software without specific prior written permission.\r
17 // \r
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 //\r
29 // $Id$\r
30 //\r
31 \r
32 using System;\r
33 using System.Collections.Generic;\r
34 using System.ComponentModel;\r
35 using System.Drawing;\r
36 using System.Data;\r
37 using System.Linq;\r
38 using System.Text;\r
39 using System.Windows.Forms;\r
40 using OpenMetaverse;\r
41 \r
42 namespace Radegast\r
43 {\r
44     public partial class AvatarPicker : UserControl\r
45     {\r
46         RadegastInstance instance;\r
47         GridClient client { get { return instance.Client; } }\r
48         UUID searchID;\r
49         public ListView currentList;\r
50 \r
51         [Browsable(true)]\r
52         public event EventHandler SelectionChaged;\r
53 \r
54         [Browsable(false)]\r
55         public Dictionary<UUID, string> SelectedAvatars\r
56         {\r
57             get\r
58             {\r
59                 Dictionary<UUID, string> res = new Dictionary<UUID,string>();\r
60                 if (currentList != null)\r
61                 {\r
62                     foreach (ListViewItem item in currentList.SelectedItems)\r
63                     {\r
64                         res.Add((UUID)item.Tag, item.Text);\r
65                     }\r
66                 }\r
67                 return res;\r
68             }\r
69         }\r
70 \r
71         public AvatarPicker() { }\r
72 \r
73         public AvatarPicker(RadegastInstance instance)\r
74         {\r
75             InitializeComponent();\r
76             Disposed += new EventHandler(AvatarPicker_Disposed);\r
77             \r
78             this.instance = instance;\r
79 \r
80             // events\r
81             client.Avatars.AvatarPickerReply += new EventHandler<AvatarPickerReplyEventArgs>(Avatars_AvatarPickerReply);\r
82         }\r
83 \r
84         void AvatarPicker_Disposed(object sender, EventArgs e)\r
85         {\r
86             client.Avatars.AvatarPickerReply -= new EventHandler<AvatarPickerReplyEventArgs>(Avatars_AvatarPickerReply);\r
87         }\r
88 \r
89         void Avatars_AvatarPickerReply(object sender, AvatarPickerReplyEventArgs e)\r
90         {\r
91             if (searchID == e.QueryID && e.Avatars.Count > 0)\r
92             {\r
93                 BeginInvoke(new MethodInvoker(() =>\r
94                     {\r
95                         foreach (KeyValuePair<UUID, string> kvp in e.Avatars)\r
96                         {\r
97                             lvwSearch.Items.Add(new ListViewItem(kvp.Value) { Text = kvp.Value, Tag = kvp.Key });\r
98                         }\r
99                     }));\r
100             }\r
101         }\r
102 \r
103         private void btnSearch_Click(object sender, EventArgs e)\r
104         {\r
105             if (txtSearch.Text.Length > 2)\r
106             {\r
107                 searchID = UUID.Random();\r
108                 lvwSearch.Items.Clear();\r
109                 client.Avatars.RequestAvatarNameSearch(txtSearch.Text, searchID);\r
110             }\r
111         }\r
112 \r
113         private void txtSearch_TextChanged(object sender, EventArgs e)\r
114         {\r
115             btnSearch.Enabled = txtSearch.Text.Length > 2;\r
116         }\r
117 \r
118         private void lvwNear_SelectedIndexChanged(object sender, EventArgs e)\r
119         {\r
120             currentList = lvwNear;\r
121             if (SelectionChaged != null)\r
122                 SelectionChaged(this, EventArgs.Empty);\r
123         }\r
124 \r
125         private void lvwSearch_SelectedIndexChanged(object sender, EventArgs e)\r
126         {\r
127             currentList = lvwSearch;\r
128             if (SelectionChaged != null)\r
129                 SelectionChaged(this, EventArgs.Empty);\r
130         }\r
131 \r
132         private void lvwSearch_SizeChanged(object sender, EventArgs e)\r
133         {\r
134             ListView view = (ListView)sender;\r
135             view.Columns[0].Width = view.Width - 30;\r
136         }\r
137 \r
138         private void txtSearch_KeyDown(object sender, KeyEventArgs e)\r
139         {\r
140             if (e.KeyCode == Keys.Enter)\r
141             {\r
142                 e.SuppressKeyPress = e.Handled = true;\r
143                 if (btnSearch.Enabled)\r
144                     btnSearch.PerformClick();\r
145             }\r
146         }\r
147 \r
148     }\r
149 }\r