OSDN Git Service

RAD-207: Add option to disable syntax highlighting which crashes some mono installs
[radegast/radegast.git] / Radegast / GUI / Dialogs / Settings.cs
1 
2 // 
3 // Radegast Metaverse Client
4 // Copyright (c) 2009-2010, 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
89         }
90
91         public frmSettings(RadegastInstance instance)
92         {
93             if (settingInitialized)
94             {
95                 frmSettings.InitSettigs(instance.GlobalSettings);
96             }
97
98             InitializeComponent();
99             s = instance.GlobalSettings;
100
101             cbChatTimestamps.Checked = s["chat_timestamps"].AsBoolean();
102
103             cbIMTimeStamps.Checked = s["im_timestamps"].AsBoolean();
104
105             cbChatTimestamps.CheckedChanged += new EventHandler(cbChatTimestamps_CheckedChanged);
106             cbIMTimeStamps.CheckedChanged += new EventHandler(cbIMTimeStamps_CheckedChanged);
107
108             cbTrasactDialog.Checked = s["transaction_notification_dialog"].AsBoolean();
109             cbTrasactChat.Checked = s["transaction_notification_chat"].AsBoolean();
110
111             cbFriendsNotifications.Checked = s["show_friends_online_notifications"].AsBoolean();
112             cbFriendsNotifications.CheckedChanged += new EventHandler(cbFriendsNotifications_CheckedChanged);
113
114             cbAutoReconnect.Checked = s["auto_reconnect"].AsBoolean();
115             cbAutoReconnect.CheckedChanged += new EventHandler(cbAutoReconnect_CheckedChanged);
116
117             cbHideLoginGraphics.Checked = s["hide_login_graphics"].AsBoolean();
118             cbHideLoginGraphics.CheckedChanged += new EventHandler(cbHideLoginGraphics_CheckedChanged);
119
120             cbRLV.Checked = s["rlv_enabled"].AsBoolean();
121             cbRLV.CheckedChanged += (object sender, EventArgs e) =>
122             {
123                 s["rlv_enabled"] = new OSDBoolean(cbRLV.Checked);
124             };
125
126             cbMUEmotes.Checked = s["mu_emotes"].AsBoolean();
127             cbMUEmotes.CheckedChanged += (object sender, EventArgs e) =>
128             {
129                 s["mu_emotes"] = new OSDBoolean(cbMUEmotes.Checked);
130             };
131
132             cbFriendsHighlight.Checked = s["friends_notification_highlight"].AsBoolean();
133             cbFriendsHighlight.CheckedChanged += (object sender, EventArgs e) =>
134             {
135                 s["friends_notification_highlight"] = new OSDBoolean(cbFriendsHighlight.Checked);
136             };
137
138             if (s["chat_font_size"].Type != OSDType.Real)
139             {
140                 s["chat_font_size"] = OSD.FromReal(((ChatConsole)instance.TabConsole.Tabs["chat"].Control).cbxInput.Font.Size);
141             }
142
143             cbFontSize.Text = s["chat_font_size"].AsReal().ToString(System.Globalization.CultureInfo.InvariantCulture);
144
145             if (!s.ContainsKey("minimize_to_tray")) s["minimize_to_tray"] = OSD.FromBoolean(false);
146             cbMinToTrey.Checked = s["minimize_to_tray"].AsBoolean();
147             cbMinToTrey.CheckedChanged += (object sender, EventArgs e) =>
148                 {
149                     s["minimize_to_tray"] = OSD.FromBoolean(cbMinToTrey.Checked);
150                 };
151
152
153             cbNoTyping.Checked = s["no_typing_anim"].AsBoolean();
154             cbNoTyping.CheckedChanged += (object sender, EventArgs e) =>
155             {
156                 s["no_typing_anim"] = OSD.FromBoolean(cbNoTyping.Checked);
157             };
158
159             txtAutoResponse.Text = s["auto_response_text"];
160             txtAutoResponse.TextChanged += (object sender, EventArgs e) =>
161                 {
162                     s["auto_response_text"] = txtAutoResponse.Text;
163                 };
164             AutoResponseType art = (AutoResponseType)s["auto_response_type"].AsInteger();
165             switch (art)
166             {
167                 case AutoResponseType.WhenBusy: rbAutobusy.Checked = true; break;
168                 case AutoResponseType.WhenFromNonFriend: rbAutoNonFriend.Checked = true; break;
169                 case AutoResponseType.Always: rbAutoAlways.Checked = true; break;
170             }
171
172             cbSyntaxHighlight.Checked = s["script_syntax_highlight"].AsBoolean();
173             cbSyntaxHighlight.CheckedChanged += (object sender, EventArgs e) =>
174             {
175                 s["script_syntax_highlight"] = OSD.FromBoolean(cbSyntaxHighlight.Checked);
176             };
177
178
179         }
180
181         void cbHideLoginGraphics_CheckedChanged(object sender, EventArgs e)
182         {
183             s["hide_login_graphics"] = OSD.FromBoolean(cbHideLoginGraphics.Checked);
184         }
185
186         void cbAutoReconnect_CheckedChanged(object sender, EventArgs e)
187         {
188             s["auto_reconnect"] = OSD.FromBoolean(cbAutoReconnect.Checked);
189         }
190
191         void cbFriendsNotifications_CheckedChanged(object sender, EventArgs e)
192         {
193             s["show_friends_online_notifications"] = OSD.FromBoolean(cbFriendsNotifications.Checked);
194         }
195
196         void cbChatTimestamps_CheckedChanged(object sender, EventArgs e)
197         {
198             s["chat_timestamps"] = OSD.FromBoolean(cbChatTimestamps.Checked);
199         }
200
201         void cbIMTimeStamps_CheckedChanged(object sender, EventArgs e)
202         {
203             s["im_timestamps"] = OSD.FromBoolean(cbIMTimeStamps.Checked);
204         }
205
206         private void cbTrasactDialog_CheckedChanged(object sender, EventArgs e)
207         {
208             s["transaction_notification_dialog"] = OSD.FromBoolean(cbTrasactDialog.Checked);
209         }
210
211         private void cbTrasactChat_CheckedChanged(object sender, EventArgs e)
212         {
213             s["transaction_notification_chat"] = OSD.FromBoolean(cbTrasactChat.Checked);
214         }
215
216         private void UpdateFontSize()
217         {
218             double f = 8.25;
219             double existing = s["chat_font_size"].AsReal();
220
221             if (!double.TryParse(cbFontSize.Text, out f))
222             {
223                 cbFontSize.Text = s["chat_font_size"].AsReal().ToString(System.Globalization.CultureInfo.InvariantCulture);
224                 return;
225             }
226
227             if (Math.Abs(existing - f) > 0.0001f)
228                 s["chat_font_size"] = OSD.FromReal(f);
229
230         }
231
232         private void cbFontSize_SelectedIndexChanged(object sender, EventArgs e)
233         {
234             UpdateFontSize();
235         }
236
237         private void cbFontSize_KeyDown(object sender, KeyEventArgs e)
238         {
239             if (e.KeyCode == Keys.Enter)
240             {
241                 UpdateFontSize();
242                 e.Handled = e.SuppressKeyPress = true;
243             }
244         }
245
246         private void cbFontSize_Leave(object sender, EventArgs e)
247         {
248             UpdateFontSize();
249         }
250
251         private void rbAutobusy_CheckedChanged(object sender, EventArgs e)
252         {
253             s["auto_response_type"] = (int)AutoResponseType.WhenBusy;
254         }
255
256         private void rbAutoNonFriend_CheckedChanged(object sender, EventArgs e)
257         {
258             s["auto_response_type"] = (int)AutoResponseType.WhenFromNonFriend;
259         }
260
261         private void rbAutoAlways_CheckedChanged(object sender, EventArgs e)
262         {
263             s["auto_response_type"] = (int)AutoResponseType.Always;
264         }
265     }
266 }