aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llprefsim.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llprefsim.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llprefsim.cpp')
-rw-r--r--linden/indra/newview/llprefsim.cpp333
1 files changed, 333 insertions, 0 deletions
diff --git a/linden/indra/newview/llprefsim.cpp b/linden/indra/newview/llprefsim.cpp
new file mode 100644
index 0000000..12ca0b1
--- /dev/null
+++ b/linden/indra/newview/llprefsim.cpp
@@ -0,0 +1,333 @@
1/**
2 * @file llprefsim.cpp
3 * @author James Cook, Richard Nelson
4 * @brief Instant messsage preferences panel
5 *
6 * Copyright (c) 2003-2007, Linden Research, Inc.
7 *
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29#include "llviewerprecompiledheaders.h"
30
31#include "llprefsim.h"
32
33#include "llpanel.h"
34#include "llcheckboxctrl.h"
35#include "llstring.h"
36#include "lltexteditor.h"
37
38#include "llagent.h"
39#include "llviewercontrol.h"
40#include "llviewernetwork.h"
41#include "llvieweruictrlfactory.h"
42
43#include "lldirpicker.h"
44
45static const std::string VISIBILITY_DEFAULT("default");
46static const std::string VISIBILITY_HIDDEN("hidden");
47
48class LLPrefsIMImpl : public LLPanel
49{
50public:
51 LLPrefsIMImpl();
52 /*virtual*/ ~LLPrefsIMImpl(){};
53
54 /*virtual*/ BOOL postBuild();
55
56 void apply();
57 void refresh();
58 void cancel();
59 void setPersonalInfo(
60 const std::string& visibility,
61 bool im_via_email,
62 const std::string& email);
63 void enableHistory();
64 static void onClickLogPath(void* user_data);
65 static void onCommitLogging( LLUICtrl* ctrl, void* user_data);
66
67protected:
68 BOOL mIMInChatHistory;
69 BOOL mLogInstantMessages;
70 BOOL mLogChat;
71 BOOL mLogShowHistory;
72 BOOL mShowTimestamps;
73 LLString mIMBusyResponse;
74 LLString mLogPath;
75
76 bool mGotPersonalInfo;
77 bool mOriginalIMViaEmail;
78
79 // online status info
80 bool mOriginalShowOnline;
81 std::string mDirectoryVisibility;
82};
83
84
85LLPrefsIMImpl::LLPrefsIMImpl()
86 : LLPanel("IM Prefs Panel")
87{
88 gUICtrlFactory->buildPanel(this, "panel_preferences_im.xml");
89}
90
91void LLPrefsIMImpl::refresh()
92{
93 mIMInChatHistory = gSavedSettings.getBOOL("IMInChatHistory");
94 mShowTimestamps = gSavedSettings.getBOOL("IMShowTimestamps");
95 mIMBusyResponse = gSavedPerAccountSettings.getString("BusyModeResponse");
96 mLogPath = gSavedPerAccountSettings.getString("InstantMessageLogPath");
97 mLogInstantMessages= gSavedPerAccountSettings.getBOOL("LogInstantMessages");
98 mLogChat = gSavedPerAccountSettings.getBOOL("LogChat");
99 mLogShowHistory = gSavedPerAccountSettings.getBOOL("LogShowHistory");
100}
101
102void LLPrefsIMImpl::cancel()
103{
104 gSavedSettings.setBOOL("IMInChatHistory", mIMInChatHistory);
105 gSavedSettings.setBOOL("IMShowTimestamps", mShowTimestamps);
106 gSavedPerAccountSettings.setString("BusyModeResponse", mIMBusyResponse);
107 gSavedPerAccountSettings.setString("InstantMessageLogPath",mLogPath);
108 gSavedPerAccountSettings.setBOOL("LogInstantMessages",mLogInstantMessages);
109 gSavedPerAccountSettings.setBOOL("LogChat",mLogChat);
110 gSavedPerAccountSettings.setBOOL("LogShowHistory",mLogShowHistory);
111}
112
113BOOL LLPrefsIMImpl::postBuild()
114{
115 requires("directory_visibility");
116 requires("send_im_to_email");
117 if (!checkRequirements())
118 {
119 return FALSE;
120 }
121
122 mGotPersonalInfo = false;
123 mOriginalIMViaEmail = false;
124 mOriginalShowOnline = false;
125 childSetLabelArg("send_im_to_email", "[EMAIL]", childGetText("log_in_to_change"));
126
127 // Don't enable this until we get personal data
128 childDisable("directory_visibility");
129 childDisable("send_im_to_email");
130 childDisable("log_instant_messages");
131 childDisable("log_chat");
132 childDisable("log_show_history");
133 childDisable("log_path_button");
134 childDisable("busy_response");
135
136 childSetText("busy_response", childGetText("log_in_to_change"));
137
138 refresh();
139
140 childSetText("log_path_string", mLogPath);
141 childSetValue("log_instant_messages", mLogInstantMessages);
142 childSetValue("log_chat", mLogChat);
143 childSetValue("log_show_history", mLogShowHistory);
144 childSetAction("log_path_button", onClickLogPath, this);
145 childSetCommitCallback("log_chat",onCommitLogging,this);
146 childSetCommitCallback("log_instant_messages",onCommitLogging,this);
147
148 return TRUE;
149}
150
151void LLPrefsIMImpl::enableHistory()
152{
153
154 if (childGetValue("log_instant_messages").asBoolean() || childGetValue("log_chat").asBoolean())
155 {
156 childEnable("log_show_history");
157 childEnable("log_path_button");
158 }
159 else
160 {
161 childDisable("log_show_history");
162 childDisable("log_path_button");
163 }
164}
165
166void LLPrefsIMImpl::apply()
167{
168 LLTextEditor* busy = LLUICtrlFactory::getTextEditorByName(this, "busy_response");
169 LLWString busy_response;
170 if (busy) busy_response = busy->getWText();
171 LLWString::replaceTabsWithSpaces(busy_response, 4);
172 LLWString::replaceChar(busy_response, '\n', '^');
173 LLWString::replaceChar(busy_response, ' ', '%');
174
175 if(mGotPersonalInfo)
176 {
177
178 gSavedPerAccountSettings.setString("BusyModeResponse", LLString(wstring_to_utf8str(busy_response)));
179
180 gSavedPerAccountSettings.setString("InstantMessageLogPath", childGetText("log_path_string").c_str());
181 gSavedPerAccountSettings.setBOOL("LogInstantMessages",childGetValue("log_instant_messages").asBoolean());
182 gSavedPerAccountSettings.setBOOL("LogChat",childGetValue("log_chat").asBoolean());
183 gSavedPerAccountSettings.setBOOL("LogShowHistory",childGetValue("log_show_history").asBoolean());
184
185 gDirUtilp->setChatLogsDir(gSavedPerAccountSettings.getString("InstantMessageLogPath"));
186
187 gDirUtilp->setPerAccountChatLogsDir(gSavedSettings.getString("FirstName").c_str(),
188 gSavedSettings.getString("LastName").c_str() );
189 LLFile::mkdir(gDirUtilp->getPerAccountChatLogsDir().c_str());
190
191 bool new_im_via_email = childGetValue("send_im_to_email").asBoolean();
192 bool new_show_online = childGetValue("directory_visibility").asBoolean();
193
194 if((new_im_via_email != mOriginalIMViaEmail)
195 ||(new_show_online != mOriginalShowOnline))
196 {
197 LLMessageSystem* msg = gMessageSystem;
198 msg->newMessageFast(_PREHASH_UpdateUserInfo);
199 msg->nextBlockFast(_PREHASH_AgentData);
200 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
201 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
202 msg->nextBlockFast(_PREHASH_UserData);
203 msg->addBOOLFast(_PREHASH_IMViaEMail, new_im_via_email);
204 // This hack is because we are representing several different
205 // possible strings with a single checkbox. Since most users
206 // can only select between 2 values, we represent it as a
207 // checkbox. This breaks down a little bit for liaisons, but
208 // works out in the end.
209 if(new_show_online != mOriginalShowOnline)
210 {
211 if(new_show_online) mDirectoryVisibility = VISIBILITY_DEFAULT;
212 else mDirectoryVisibility = VISIBILITY_HIDDEN;
213 //Update showonline value, otherwise multiple applys won't work
214 mOriginalShowOnline = new_show_online;
215 }
216 msg->addString("DirectoryVisibility", mDirectoryVisibility);
217 gAgent.sendReliableMessage();
218 }
219 }
220}
221
222void LLPrefsIMImpl::setPersonalInfo(
223 const std::string& visibility,
224 bool im_via_email,
225 const std::string& email)
226{
227 mGotPersonalInfo = true;
228 mOriginalIMViaEmail = im_via_email;
229 mDirectoryVisibility = visibility;
230 if(visibility == VISIBILITY_DEFAULT)
231 {
232 mOriginalShowOnline = true;
233 childEnable("directory_visibility");
234 }
235 else if(visibility == VISIBILITY_HIDDEN)
236 {
237 mOriginalShowOnline = false;
238 childEnable("directory_visibility");
239 }
240 else
241 {
242 mOriginalShowOnline = false;
243 }
244 childSetValue("directory_visibility", mOriginalShowOnline);
245 childSetLabelArg("directory_visibility", "[DIR_VIS]", mDirectoryVisibility);
246 childEnable("send_im_to_email");
247 childSetValue("send_im_to_email", im_via_email);
248 childEnable("log_instant_messages");
249 childEnable("log_chat");
250 childEnable("busy_response");
251
252 //RN: get wide string so replace char can work (requires fixed-width encoding)
253 LLWString busy_response = utf8str_to_wstring( gSavedPerAccountSettings.getString("BusyModeResponse") );
254 LLWString::replaceChar(busy_response, '^', '\n');
255 LLWString::replaceChar(busy_response, '%', ' ');
256 childSetText("busy_response", wstring_to_utf8str(busy_response));
257
258 enableHistory();
259
260 // Truncate the e-mail address if it's too long (to prevent going off
261 // the edge of the dialog).
262 std::string display_email(email);
263 if(display_email.size() > 30)
264 {
265 display_email.resize(30);
266 display_email += "...";
267 }
268
269 childSetLabelArg("send_im_to_email", "[EMAIL]", display_email);
270}
271
272
273// static
274void LLPrefsIMImpl::onClickLogPath(void* user_data)
275{
276 LLPrefsIMImpl* self=(LLPrefsIMImpl*)user_data;
277
278 LLString proposed_name(self->childGetText("log_path_string"));
279
280 LLDirPicker& picker = LLDirPicker::instance();
281 if (! picker.getDir(&proposed_name ) )
282 {
283 return; //Canceled!
284 }
285
286 self->childSetText("log_path_string", picker.getDirName());
287}
288
289
290// static
291void LLPrefsIMImpl::onCommitLogging( LLUICtrl* ctrl, void* user_data)
292{
293 LLPrefsIMImpl* self=(LLPrefsIMImpl*)user_data;
294 self->enableHistory();
295}
296
297
298//---------------------------------------------------------------------------
299
300LLPrefsIM::LLPrefsIM()
301: impl( * new LLPrefsIMImpl() )
302{ }
303
304LLPrefsIM::~LLPrefsIM()
305{
306 delete &impl;
307}
308
309void LLPrefsIM::apply()
310{
311 impl.apply();
312}
313
314void LLPrefsIM::cancel()
315{
316 impl.cancel();
317}
318
319void LLPrefsIM::setPersonalInfo(
320 const char* visibility,
321 bool im_via_email,
322 const char* email)
323{
324 impl.setPersonalInfo(
325 ll_safe_string(visibility),
326 im_via_email,
327 ll_safe_string(email));
328}
329
330LLPanel* LLPrefsIM::getPanel()
331{
332 return &impl;
333}