OSDN Git Service

RAD-237: Auto Item accept/discard
[radegast/radegast.git] / Radegast / GUI / Dialogs / Settings.cs
1 
2 // 
3 // Radegast Metaverse Client
4 // Copyright (c) 2009-2011, Radegast Development Team
5 // All rights reserved.
6 // 
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // 
10 //     * Redistributions of source code must retain the above copyright notice,
11 //       this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above copyright
13 //       notice, this list of conditions and the following disclaimer in the
14 //       documentation and/or other materials provided with the distribution.
15 //     * Neither the name of the application "Radegast", nor the names of its
16 //       contributors may be used to endorse or promote products derived from
17 //       this software without specific prior written permission.
18 // 
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // $Id$
31 //
32 using System;
33 using System.Collections.Generic;
34 using System.ComponentModel;
35 using System.Data;
36 using System.Drawing;
37 using System.Linq;
38 using System.Text;
39 using System.Windows.Forms;
40 using OpenMetaverse.StructuredData;
41
42 namespace Radegast
43 {
44     public enum AutoResponseType : int
45     {
46         WhenBusy = 0,
47         WhenFromNonFriend = 1,
48         Always = 2
49     }
50
51     public partial class frmSettings : RadegastForm
52     {
53         private Settings s;
54         private static bool settingInitialized = false;
55
56         public static void InitSettigs(Settings s)
57         {
58             if (s["im_timestamps"].Type == OSDType.Unknown)
59             {
60                 s["im_timestamps"] = OSD.FromBoolean(true);
61             }
62
63             if (s["rlv_enabled"].Type == OSDType.Unknown)
64             {
65                 s["rlv_enabled"] = new OSDBoolean(false);
66             }
67
68             if (s["mu_emotes"].Type == OSDType.Unknown)
69             {
70                 s["mu_emotes"] = new OSDBoolean(false);
71             }
72
73             if (s["friends_notification_highlight"].Type == OSDType.Unknown)
74             {
75                 s["friends_notification_highlight"] = new OSDBoolean(true);
76             }
77
78             if (!s.ContainsKey("no_typing_anim")) s["no_typing_anim"] = OSD.FromBoolean(false);
79
80             if (!s.ContainsKey("auto_response_type"))
81             {
82                 s["auto_response_type"] = (int)AutoResponseType.WhenBusy;
83                 s["auto_response_text"] = "The Resident you messaged is in 'busy mode' which means they have requested not to be disturbed.  Your message will still be shown in their IM panel for later viewing.";
84             }
85
86             if (!s.ContainsKey("script_syntax_highlight")) s["script_syntax_highlight"] = OSD.FromBoolean(true);
87
88             if (!s.ContainsKey("display_name_mode")) s["display_name_mode"] = (int)NameMode.Smart;
89
90             // Convert legacy settings from first last name to username
91             if (!s.ContainsKey("username") && (s.ContainsKey("first_name") && s.ContainsKey("last_name")))
92             {
93                 s["username"] = s["first_name"] + " " + s["last_name"];
94                 s.Remove("first_name");
95                 s.Remove("last_name");
96             }
97
98             if (!s.ContainsKey("reconnect_time")) s["reconnect_time"] = 120;
99
100             if (!s.ContainsKey("transaction_notification_chat")) s["transaction_notification_chat"] = true;
101
102             if (!s.ContainsKey("transaction_notification_dialog")) s["transaction_notification_dialog"] = true;
103
104             if (!s.ContainsKey("minimize_to_tray")) s["minimize_to_tray"] = false;
105
106             if (!s.ContainsKey("scene_window_docked")) s["scene_window_docked"] = true;
107
108             if (!s.ContainsKey("taskbar_highlight")) s["taskbar_highlight"] = true;
109
110             if (!s.ContainsKey("rendering_occlusion_culling_enabled")) s["rendering_occlusion_culling_enabled"] = true;
111
112             if (!s.ContainsKey("rendering_use_vbo")) s["rendering_use_vbo"] = true;
113
114             if (!s.ContainsKey("send_rad_client_tag")) s["send_rad_client_tag"] = true;
115
116
117         }
118
119         public frmSettings(RadegastInstance instance)
120         {
121             if (settingInitialized)
122             {
123                 frmSettings.InitSettigs(instance.GlobalSettings);
124             }
125
126             InitializeComponent();
127
128             s = instance.GlobalSettings;
129             tbpGraphics.Controls.Add(new Radegast.Rendering.GraphicsPreferences(instance));
130             cbChatTimestamps.Checked = s["chat_timestamps"].AsBoolean();
131
132             cbIMTimeStamps.Checked = s["im_timestamps"].AsBoolean();
133
134             cbChatTimestamps.CheckedChanged += new EventHandler(cbChatTimestamps_CheckedChanged);
135             cbIMTimeStamps.CheckedChanged += new EventHandler(cbIMTimeStamps_CheckedChanged);
136
137             cbTrasactDialog.Checked = s["transaction_notification_dialog"].AsBoolean();
138             cbTrasactChat.Checked = s["transaction_notification_chat"].AsBoolean();
139
140             cbFriendsNotifications.Checked = s["show_friends_online_notifications"].AsBoolean();
141             cbFriendsNotifications.CheckedChanged += new EventHandler(cbFriendsNotifications_CheckedChanged);
142
143             cbAutoReconnect.Checked = s["auto_reconnect"].AsBoolean();
144             cbAutoReconnect.CheckedChanged += new EventHandler(cbAutoReconnect_CheckedChanged);
145
146             cbHideLoginGraphics.Checked = s["hide_login_graphics"].AsBoolean();
147             cbHideLoginGraphics.CheckedChanged += new EventHandler(cbHideLoginGraphics_CheckedChanged);
148
149             cbRLV.Checked = s["rlv_enabled"].AsBoolean();
150             cbRLV.CheckedChanged += (object sender, EventArgs e) =>
151             {
152                 s["rlv_enabled"] = new OSDBoolean(cbRLV.Checked);
153             };
154
155             cbMUEmotes.Checked = s["mu_emotes"].AsBoolean();
156             cbMUEmotes.CheckedChanged += (object sender, EventArgs e) =>
157             {
158                 s["mu_emotes"] = new OSDBoolean(cbMUEmotes.Checked);
159             };
160
161             cbFriendsHighlight.Checked = s["friends_notification_highlight"].AsBoolean();
162             cbFriendsHighlight.CheckedChanged += (object sender, EventArgs e) =>
163             {
164                 s["friends_notification_highlight"] = new OSDBoolean(cbFriendsHighlight.Checked);
165             };
166
167             if (s["chat_font_size"].Type != OSDType.Real)
168             {
169                 s["chat_font_size"] = OSD.FromReal(((ChatConsole)instance.TabConsole.Tabs["chat"].Control).cbxInput.Font.Size);
170             }
171
172             cbFontSize.Text = s["chat_font_size"].AsReal().ToString(System.Globalization.CultureInfo.InvariantCulture);
173
174             if (!s.ContainsKey("minimize_to_tray")) s["minimize_to_tray"] = OSD.FromBoolean(false);
175             cbMinToTrey.Checked = s["minimize_to_tray"].AsBoolean();
176             cbMinToTrey.CheckedChanged += (object sender, EventArgs e) =>
177                 {
178                     s["minimize_to_tray"] = OSD.FromBoolean(cbMinToTrey.Checked);
179                 };
180
181
182             cbNoTyping.Checked = s["no_typing_anim"].AsBoolean();
183             cbNoTyping.CheckedChanged += (object sender, EventArgs e) =>
184             {
185                 s["no_typing_anim"] = OSD.FromBoolean(cbNoTyping.Checked);
186             };
187
188             txtAutoResponse.Text = s["auto_response_text"];
189             txtAutoResponse.TextChanged += (object sender, EventArgs e) =>
190                 {
191                     s["auto_response_text"] = txtAutoResponse.Text;
192                 };
193             AutoResponseType art = (AutoResponseType)s["auto_response_type"].AsInteger();
194             switch (art)
195             {
196                 case AutoResponseType.WhenBusy: rbAutobusy.Checked = true; break;
197                 case AutoResponseType.WhenFromNonFriend: rbAutoNonFriend.Checked = true; break;
198                 case AutoResponseType.Always: rbAutoAlways.Checked = true; break;
199             }
200
201             cbSyntaxHighlight.Checked = s["script_syntax_highlight"].AsBoolean();
202             cbSyntaxHighlight.CheckedChanged += (object sender, EventArgs e) =>
203             {
204                 s["script_syntax_highlight"] = OSD.FromBoolean(cbSyntaxHighlight.Checked);
205             };
206
207             switch ((NameMode)s["display_name_mode"].AsInteger())
208             {
209                 case NameMode.Standard: rbDNOff.Checked = true; break;
210                 case NameMode.Smart: rbDNSmart.Checked = true; break;
211                 case NameMode.DisplayNameAndUserName: rbDNDandUsernme.Checked = true; break;
212                 case NameMode.OnlyDisplayName: rbDNOnlyDN.Checked = true; break;
213             }
214
215             txtReconnectTime.Text = s["reconnect_time"].AsInteger().ToString();
216
217             cbTaskBarHighLight.Checked = s["taskbar_highlight"];
218             cbTaskBarHighLight.CheckedChanged += (sender, e) =>
219             {
220                 s["taskbar_highlight"] = cbTaskBarHighLight.Checked;
221             };
222
223             cbRadegastClientTag.Checked = s["send_rad_client_tag"];
224             cbRadegastClientTag.CheckedChanged += (sender, e) =>
225             {
226                 s["send_rad_client_tag"] = cbRadegastClientTag.Checked;
227                 instance.SetClientTag();
228             };
229
230             cbOnInvOffer.SelectedIndex = s["inv_auto_accept_mode"].AsInteger();
231             cbOnInvOffer.SelectedIndexChanged += (sender, e) =>
232             {
233                 s["inv_auto_accept_mode"] = cbOnInvOffer.SelectedIndex;
234             };
235         }
236
237         void cbHideLoginGraphics_CheckedChanged(object sender, EventArgs e)
238         {
239             s["hide_login_graphics"] = OSD.FromBoolean(cbHideLoginGraphics.Checked);
240         }
241
242         void cbAutoReconnect_CheckedChanged(object sender, EventArgs e)
243         {
244             s["auto_reconnect"] = OSD.FromBoolean(cbAutoReconnect.Checked);
245         }
246
247         void cbFriendsNotifications_CheckedChanged(object sender, EventArgs e)
248         {
249             s["show_friends_online_notifications"] = OSD.FromBoolean(cbFriendsNotifications.Checked);
250         }
251
252         void cbChatTimestamps_CheckedChanged(object sender, EventArgs e)
253         {
254             s["chat_timestamps"] = OSD.FromBoolean(cbChatTimestamps.Checked);
255         }
256
257         void cbIMTimeStamps_CheckedChanged(object sender, EventArgs e)
258         {
259             s["im_timestamps"] = OSD.FromBoolean(cbIMTimeStamps.Checked);
260         }
261
262         private void cbTrasactDialog_CheckedChanged(object sender, EventArgs e)
263         {
264             s["transaction_notification_dialog"] = OSD.FromBoolean(cbTrasactDialog.Checked);
265         }
266
267         private void cbTrasactChat_CheckedChanged(object sender, EventArgs e)
268         {
269             s["transaction_notification_chat"] = OSD.FromBoolean(cbTrasactChat.Checked);
270         }
271
272         private void UpdateFontSize()
273         {
274             double f = 8.25;
275             double existing = s["chat_font_size"].AsReal();
276
277             if (!double.TryParse(cbFontSize.Text, out f))
278             {
279                 cbFontSize.Text = s["chat_font_size"].AsReal().ToString(System.Globalization.CultureInfo.InvariantCulture);
280                 return;
281             }
282
283             if (Math.Abs(existing - f) > 0.0001f)
284                 s["chat_font_size"] = OSD.FromReal(f);
285
286         }
287
288         private void cbFontSize_SelectedIndexChanged(object sender, EventArgs e)
289         {
290             UpdateFontSize();
291         }
292
293         private void cbFontSize_KeyDown(object sender, KeyEventArgs e)
294         {
295             if (e.KeyCode == Keys.Enter)
296             {
297                 UpdateFontSize();
298                 e.Handled = e.SuppressKeyPress = true;
299             }
300         }
301
302         private void cbFontSize_Leave(object sender, EventArgs e)
303         {
304             UpdateFontSize();
305         }
306
307         private void rbAutobusy_CheckedChanged(object sender, EventArgs e)
308         {
309             s["auto_response_type"] = (int)AutoResponseType.WhenBusy;
310         }
311
312         private void rbAutoNonFriend_CheckedChanged(object sender, EventArgs e)
313         {
314             s["auto_response_type"] = (int)AutoResponseType.WhenFromNonFriend;
315         }
316
317         private void rbAutoAlways_CheckedChanged(object sender, EventArgs e)
318         {
319             s["auto_response_type"] = (int)AutoResponseType.Always;
320         }
321
322         private void rbDNOff_CheckedChanged(object sender, EventArgs e)
323         {
324             if (rbDNOff.Checked)
325                 s["display_name_mode"] = (int)NameMode.Standard;
326         }
327
328         private void rbDNSmart_CheckedChanged(object sender, EventArgs e)
329         {
330             if (rbDNSmart.Checked)
331                 s["display_name_mode"] = (int)NameMode.Smart;
332         }
333
334         private void rbDNDandUsernme_CheckedChanged(object sender, EventArgs e)
335         {
336             if (rbDNDandUsernme.Checked)
337                 s["display_name_mode"] = (int)NameMode.DisplayNameAndUserName;
338         }
339
340         private void rbDNOnlyDN_CheckedChanged(object sender, EventArgs e)
341         {
342             if (rbDNOnlyDN.Checked)
343                 s["display_name_mode"] = (int)NameMode.OnlyDisplayName;
344         }
345
346         private void txtReconnectTime_TextChanged(object sender, EventArgs e)
347         {
348             string input = System.Text.RegularExpressions.Regex.Replace(txtReconnectTime.Text, @"[^\d]", "");
349             int t = 120;
350             int.TryParse(input, out t);
351             
352             if (txtReconnectTime.Text != t.ToString())
353             {
354                 txtReconnectTime.Text = t.ToString();
355                 txtReconnectTime.Select(txtReconnectTime.Text.Length, 0);
356             }
357             
358             s["reconnect_time"] = t;
359         }
360     }
361 }