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