OSDN Git Service

Removed unused usings, thanks nephrael for the patch.
[radegast/radegast.git] / Radegast / GUI / Consoles / GroupIMTabWindow.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 using System;\r
32 using System.Drawing;\r
33 using System.Windows.Forms;\r
34 using System.Threading;\r
35 using Radegast.Netcom;\r
36 using OpenMetaverse;\r
37 \r
38 namespace Radegast\r
39 {\r
40     public partial class GroupIMTabWindow : UserControl\r
41     {\r
42         private RadegastInstance instance;\r
43         private GridClient client { get { return instance.Client; } }\r
44         private RadegastNetcom netcom { get { return instance.Netcom; } }\r
45         private UUID session;\r
46         private IMTextManager textManager;\r
47 \r
48         ManualResetEvent WaitForSessionStart = new ManualResetEvent(false);\r
49 \r
50         public GroupIMTabWindow(RadegastInstance instance, UUID session, string sessionName)\r
51         {\r
52             InitializeComponent();\r
53             Disposed += new EventHandler(IMTabWindow_Disposed);\r
54 \r
55             this.instance = instance;\r
56             this.session = session;\r
57 \r
58             textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), this.session, sessionName);\r
59             ApplyConfig(this.instance.Config.CurrentConfig);\r
60             \r
61             // Callbacks\r
62             this.instance.Config.ConfigApplied += new EventHandler<ConfigAppliedEventArgs>(Config_ConfigApplied);\r
63             client.Self.OnGroupChatJoin += new AgentManager.GroupChatJoinedCallback(Self_OnGroupChatJoin);\r
64 \r
65             client.Self.RequestJoinGroupChat(session);\r
66         }\r
67 \r
68         private void IMTabWindow_Disposed(object sender, EventArgs e)\r
69         {\r
70             this.instance.Config.ConfigApplied -= new EventHandler<ConfigAppliedEventArgs>(Config_ConfigApplied);\r
71             client.Self.OnGroupChatJoin -= new AgentManager.GroupChatJoinedCallback(Self_OnGroupChatJoin);\r
72             CleanUp();\r
73         }\r
74 \r
75 \r
76         void Self_OnGroupChatJoin(UUID groupChatSessionID, string sessionName, UUID tmpSessionID, bool success)\r
77         {\r
78             if (groupChatSessionID != session && tmpSessionID != session) {\r
79                 return;\r
80             }\r
81 \r
82             if (InvokeRequired) {\r
83                 Invoke(new MethodInvoker(\r
84                     delegate()\r
85                     {\r
86                         Self_OnGroupChatJoin(groupChatSessionID, sessionName, tmpSessionID, success);\r
87                     }\r
88                     )\r
89                 );\r
90                 return;\r
91             }\r
92             if (success) {\r
93                 textManager.TextPrinter.PrintTextLine("Join Group Chat Success!", Color.Green);\r
94                 WaitForSessionStart.Set();\r
95             } else {\r
96                 textManager.TextPrinter.PrintTextLine("Join Group Chat failed.", Color.Red);\r
97             }\r
98         }\r
99 \r
100         private void Config_ConfigApplied(object sender, ConfigAppliedEventArgs e)\r
101         {\r
102             ApplyConfig(e.AppliedConfig);\r
103         }\r
104 \r
105         private void ApplyConfig(Config config)\r
106         {\r
107             /*\r
108             if (config.InterfaceStyle == 0) //System\r
109                 toolStrip1.RenderMode = ToolStripRenderMode.System;\r
110             else if (config.InterfaceStyle == 1) //Office 2003\r
111                 toolStrip1.RenderMode = ToolStripRenderMode.ManagerRenderMode;\r
112              */\r
113         }\r
114 \r
115         private void AddNetcomEvents()\r
116         {\r
117             netcom.ClientLoginStatus += new EventHandler<ClientLoginEventArgs>(netcom_ClientLoginStatus);\r
118             netcom.ClientDisconnected += new EventHandler<ClientDisconnectEventArgs>(netcom_ClientDisconnected);\r
119         }\r
120 \r
121         private void netcom_ClientLoginStatus(object sender, ClientLoginEventArgs e)\r
122         {\r
123             if (e.Status != LoginStatus.Success) return;\r
124 \r
125             RefreshControls();\r
126         }\r
127 \r
128         private void netcom_ClientDisconnected(object sender, ClientDisconnectEventArgs e)\r
129         {\r
130             RefreshControls();\r
131         }\r
132 \r
133         public void CleanUp()\r
134         {\r
135             textManager.CleanUp();\r
136             textManager = null;\r
137         }\r
138 \r
139         private void btnSend_Click(object sender, EventArgs e)\r
140         {\r
141             //netcom.SendInstantMessage(cbgInput.Text, target, session);\r
142             this.ClearIMInput();\r
143         }\r
144 \r
145         private void cbxInput_TextChanged(object sender, EventArgs e)\r
146         {\r
147             RefreshControls();\r
148         }\r
149 \r
150         private void RefreshControls()\r
151         {\r
152             if (!netcom.IsLoggedIn)\r
153             {\r
154                 cbgInput.Enabled = false;\r
155                 btnSend.Enabled = false;\r
156                 return;\r
157             }\r
158 \r
159         }\r
160 \r
161         private void cbxInput_KeyUp(object sender, KeyEventArgs e)\r
162         {\r
163             if (e.KeyCode != Keys.Enter) return;\r
164             e.SuppressKeyPress = true;\r
165             if (cbgInput.Text.Length == 0) return;\r
166 \r
167             string message = cbgInput.Text;\r
168             if (message.Length > 1023) message = message.Remove(1023);\r
169 \r
170             if (!client.Self.GroupChatSessions.ContainsKey(session)) {\r
171                 WaitForSessionStart.Reset();\r
172                 client.Self.RequestJoinGroupChat(session);\r
173             } else {\r
174                 WaitForSessionStart.Set();\r
175             }\r
176 \r
177             if (WaitForSessionStart.WaitOne(10000, false)) {\r
178                 client.Self.InstantMessageGroup(session, message);\r
179             } else {\r
180                 textManager.TextPrinter.PrintTextLine("Cannot send group IM.", Color.Red);\r
181             }\r
182             this.ClearIMInput();\r
183         }\r
184 \r
185         private void ClearIMInput()\r
186         {\r
187             cbgInput.Items.Add(cbgInput.Text);\r
188             cbgInput.Text = string.Empty;\r
189         }\r
190 \r
191         public void SelectIMInput()\r
192         {\r
193             cbgInput.Select();\r
194         }\r
195 \r
196         private void rtbIMText_LinkClicked(object sender, LinkClickedEventArgs e)\r
197         {\r
198             instance.MainForm.processLink(e.LinkText);\r
199         }\r
200 \r
201         private void cbxInput_KeyDown(object sender, KeyEventArgs e)\r
202         {\r
203             if (e.KeyCode == Keys.Enter) e.SuppressKeyPress = true;\r
204         }\r
205 \r
206         public UUID SessionId\r
207         {\r
208             get { return session; }\r
209             set { session = value; }\r
210         }\r
211 \r
212         public IMTextManager TextManager\r
213         {\r
214             get { return textManager; }\r
215             set { textManager = value; }\r
216         }\r
217     }\r
218 }\r