00001
00033 #include "llviewerprecompiledheaders.h"
00034
00035 #include "llprefsim.h"
00036
00037 #include "llpanel.h"
00038 #include "llcheckboxctrl.h"
00039 #include "llstring.h"
00040 #include "lltexteditor.h"
00041 #include "llavatarconstants.h"
00042 #include "llagent.h"
00043 #include "llviewercontrol.h"
00044 #include "llviewernetwork.h"
00045 #include "llvieweruictrlfactory.h"
00046
00047 #include "lldirpicker.h"
00048
00049 class LLPrefsIMImpl : public LLPanel
00050 {
00051 public:
00052 LLPrefsIMImpl();
00053 ~LLPrefsIMImpl(){};
00054
00055 BOOL postBuild();
00056
00057 void apply();
00058 void refresh();
00059 void cancel();
00060 void setPersonalInfo(
00061 const std::string& visibility,
00062 bool im_via_email,
00063 const std::string& email);
00064 void enableHistory();
00065 static void onClickLogPath(void* user_data);
00066 static void onCommitLogging( LLUICtrl* ctrl, void* user_data);
00067
00068 protected:
00069 BOOL mIMInChatHistory;
00070 BOOL mLogInstantMessages;
00071 BOOL mLogChat;
00072 BOOL mLogShowHistory;
00073 BOOL mShowTimestamps;
00074 BOOL mIMLogTimestamp;
00075 BOOL mLogChatTimestamp;
00076 BOOL mLogIMChat;
00077 BOOL mLogTimestampDate;
00078
00079 LLString mIMBusyResponse;
00080 LLString mLogPath;
00081
00082 bool mGotPersonalInfo;
00083 bool mOriginalIMViaEmail;
00084
00085
00086 bool mOriginalHideOnlineStatus;
00087 std::string mDirectoryVisibility;
00088 };
00089
00090
00091 LLPrefsIMImpl::LLPrefsIMImpl()
00092 : LLPanel("IM Prefs Panel")
00093 {
00094 gUICtrlFactory->buildPanel(this, "panel_preferences_im.xml");
00095 }
00096
00097 void LLPrefsIMImpl::refresh()
00098 {
00099 mIMInChatHistory = gSavedSettings.getBOOL("IMInChatHistory");
00100 mShowTimestamps = gSavedSettings.getBOOL("IMShowTimestamps");
00101 mIMBusyResponse = gSavedPerAccountSettings.getString("BusyModeResponse");
00102 mLogPath = gSavedPerAccountSettings.getString("InstantMessageLogPath");
00103 mLogInstantMessages= gSavedPerAccountSettings.getBOOL("LogInstantMessages");
00104 mLogChat = gSavedPerAccountSettings.getBOOL("LogChat");
00105 mLogShowHistory = gSavedPerAccountSettings.getBOOL("LogShowHistory");
00106 mIMLogTimestamp = gSavedPerAccountSettings.getBOOL("IMLogTimestamp");
00107 mLogChatTimestamp = gSavedPerAccountSettings.getBOOL("LogChatTimestamp");
00108 mLogIMChat = gSavedPerAccountSettings.getBOOL("LogChatIM");
00109 mLogTimestampDate = gSavedPerAccountSettings.getBOOL("LogTimestampDate");
00110 }
00111
00112 void LLPrefsIMImpl::cancel()
00113 {
00114 gSavedSettings.setBOOL("IMInChatHistory", mIMInChatHistory);
00115 gSavedSettings.setBOOL("IMShowTimestamps", mShowTimestamps);
00116 gSavedPerAccountSettings.setString("BusyModeResponse", mIMBusyResponse);
00117 gSavedPerAccountSettings.setString("InstantMessageLogPath",mLogPath);
00118 gSavedPerAccountSettings.setBOOL("LogInstantMessages",mLogInstantMessages);
00119 gSavedPerAccountSettings.setBOOL("LogChat",mLogChat);
00120 gSavedPerAccountSettings.setBOOL("LogShowHistory",mLogShowHistory);
00121 gSavedPerAccountSettings.setBOOL("IMLogTimestamp",mIMLogTimestamp);
00122 gSavedPerAccountSettings.setBOOL("LogChatTimestamp",mLogChatTimestamp);
00123 gSavedPerAccountSettings.setBOOL("LogChatIM",mLogIMChat);
00124 gSavedPerAccountSettings.setBOOL("LogTimestampDate",mLogTimestampDate);
00125 }
00126
00127 BOOL LLPrefsIMImpl::postBuild()
00128 {
00129 requires("online_visibility");
00130 requires("send_im_to_email");
00131 if (!checkRequirements())
00132 {
00133 return FALSE;
00134 }
00135
00136 mGotPersonalInfo = false;
00137 mOriginalIMViaEmail = false;
00138 mOriginalHideOnlineStatus = true;
00139 childSetLabelArg("send_im_to_email", "[EMAIL]", childGetText("log_in_to_change"));
00140
00141
00142 childDisable("online_visibility");
00143 childDisable("send_im_to_email");
00144 childDisable("log_instant_messages");
00145 childDisable("log_chat");
00146 childDisable("log_show_history");
00147 childDisable("log_path_button");
00148 childDisable("busy_response");
00149 childDisable("log_instant_messages_timestamp");
00150 childDisable("log_chat_timestamp");
00151 childDisable("log_chat_IM");
00152 childDisable("log_date_timestamp");
00153
00154 childSetText("busy_response", childGetText("log_in_to_change"));
00155
00156 refresh();
00157
00158 childSetText("log_path_string", mLogPath);
00159 childSetValue("log_instant_messages", mLogInstantMessages);
00160 childSetValue("log_chat", mLogChat);
00161 childSetValue("log_show_history", mLogShowHistory);
00162 childSetValue("log_instant_messages_timestamp", mIMLogTimestamp);
00163 childSetValue("log_chat_timestamp", mLogChatTimestamp);
00164 childSetValue("log_chat_IM", mLogIMChat);
00165 childSetValue("log_date_timestamp",mLogTimestampDate);
00166 childSetAction("log_path_button", onClickLogPath, this);
00167 childSetCommitCallback("log_chat",onCommitLogging,this);
00168 childSetCommitCallback("log_instant_messages",onCommitLogging,this);
00169
00170 return TRUE;
00171 }
00172
00173 void LLPrefsIMImpl::enableHistory()
00174 {
00175
00176 if (childGetValue("log_instant_messages").asBoolean() || childGetValue("log_chat").asBoolean())
00177 {
00178 childEnable("log_show_history");
00179 childEnable("log_path_button");
00180 }
00181 else
00182 {
00183 childDisable("log_show_history");
00184 childDisable("log_path_button");
00185 }
00186 }
00187
00188 void LLPrefsIMImpl::apply()
00189 {
00190 LLTextEditor* busy = LLUICtrlFactory::getTextEditorByName(this, "busy_response");
00191 LLWString busy_response;
00192 if (busy) busy_response = busy->getWText();
00193 LLWString::replaceTabsWithSpaces(busy_response, 4);
00194 LLWString::replaceChar(busy_response, '\n', '^');
00195 LLWString::replaceChar(busy_response, ' ', '%');
00196
00197 if(mGotPersonalInfo)
00198 {
00199
00200 gSavedPerAccountSettings.setString("BusyModeResponse", LLString(wstring_to_utf8str(busy_response)));
00201
00202 gSavedPerAccountSettings.setString("InstantMessageLogPath", childGetText("log_path_string").c_str());
00203 gSavedPerAccountSettings.setBOOL("LogInstantMessages",childGetValue("log_instant_messages").asBoolean());
00204 gSavedPerAccountSettings.setBOOL("LogChat",childGetValue("log_chat").asBoolean());
00205 gSavedPerAccountSettings.setBOOL("LogShowHistory",childGetValue("log_show_history").asBoolean());
00206 gSavedPerAccountSettings.setBOOL("IMLogTimestamp",childGetValue("log_instant_messages_timestamp").asBoolean());
00207 gSavedPerAccountSettings.setBOOL("LogChatTimestamp",childGetValue("log_chat_timestamp").asBoolean());
00208 gSavedPerAccountSettings.setBOOL("LogChatIM",childGetValue("log_chat_IM").asBoolean());
00209 gSavedPerAccountSettings.setBOOL("LogTimestampDate",childGetValue("log_date_timestamp").asBoolean());
00210
00211 gDirUtilp->setChatLogsDir(gSavedPerAccountSettings.getString("InstantMessageLogPath"));
00212
00213 gDirUtilp->setPerAccountChatLogsDir(gSavedSettings.getString("FirstName").c_str(),
00214 gSavedSettings.getString("LastName").c_str() );
00215 LLFile::mkdir(gDirUtilp->getPerAccountChatLogsDir().c_str());
00216
00217 bool new_im_via_email = childGetValue("send_im_to_email").asBoolean();
00218 bool new_hide_online = childGetValue("online_visibility").asBoolean();
00219
00220 if((new_im_via_email != mOriginalIMViaEmail)
00221 ||(new_hide_online != mOriginalHideOnlineStatus))
00222 {
00223 LLMessageSystem* msg = gMessageSystem;
00224 msg->newMessageFast(_PREHASH_UpdateUserInfo);
00225 msg->nextBlockFast(_PREHASH_AgentData);
00226 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00227 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00228 msg->nextBlockFast(_PREHASH_UserData);
00229 msg->addBOOLFast(_PREHASH_IMViaEMail, new_im_via_email);
00230
00231
00232
00233
00234
00235 if(new_hide_online != mOriginalHideOnlineStatus)
00236 {
00237 if(new_hide_online) mDirectoryVisibility = VISIBILITY_HIDDEN;
00238 else mDirectoryVisibility = VISIBILITY_DEFAULT;
00239
00240 mOriginalHideOnlineStatus = new_hide_online;
00241 }
00242 msg->addString("DirectoryVisibility", mDirectoryVisibility);
00243 gAgent.sendReliableMessage();
00244 }
00245 }
00246 }
00247
00248 void LLPrefsIMImpl::setPersonalInfo(
00249 const std::string& visibility,
00250 bool im_via_email,
00251 const std::string& email)
00252 {
00253 mGotPersonalInfo = true;
00254 mOriginalIMViaEmail = im_via_email;
00255 mDirectoryVisibility = visibility;
00256 if(visibility == VISIBILITY_DEFAULT)
00257 {
00258 mOriginalHideOnlineStatus = false;
00259 childEnable("online_visibility");
00260 }
00261 else if(visibility == VISIBILITY_HIDDEN)
00262 {
00263 mOriginalHideOnlineStatus = true;
00264 childEnable("online_visibility");
00265 }
00266 else
00267 {
00268 mOriginalHideOnlineStatus = true;
00269 }
00270 childSetValue("online_visibility", mOriginalHideOnlineStatus);
00271 childSetLabelArg("online_visibility", "[DIR_VIS]", mDirectoryVisibility);
00272 childEnable("send_im_to_email");
00273 childSetValue("send_im_to_email", im_via_email);
00274 childEnable("log_instant_messages");
00275 childEnable("log_chat");
00276 childEnable("busy_response");
00277 childEnable("log_instant_messages_timestamp");
00278 childEnable("log_chat_timestamp");
00279 childEnable("log_chat_IM");
00280 childEnable("log_date_timestamp");
00281
00282
00283 LLWString busy_response = utf8str_to_wstring( gSavedPerAccountSettings.getString("BusyModeResponse") );
00284 LLWString::replaceChar(busy_response, '^', '\n');
00285 LLWString::replaceChar(busy_response, '%', ' ');
00286 childSetText("busy_response", wstring_to_utf8str(busy_response));
00287
00288 enableHistory();
00289
00290
00291
00292 std::string display_email(email);
00293 if(display_email.size() > 30)
00294 {
00295 display_email.resize(30);
00296 display_email += "...";
00297 }
00298
00299 childSetLabelArg("send_im_to_email", "[EMAIL]", display_email);
00300 }
00301
00302
00303
00304 void LLPrefsIMImpl::onClickLogPath(void* user_data)
00305 {
00306 LLPrefsIMImpl* self=(LLPrefsIMImpl*)user_data;
00307
00308 LLString proposed_name(self->childGetText("log_path_string"));
00309
00310 LLDirPicker& picker = LLDirPicker::instance();
00311 if (! picker.getDir(&proposed_name ) )
00312 {
00313 return;
00314 }
00315
00316 self->childSetText("log_path_string", picker.getDirName());
00317 }
00318
00319
00320
00321 void LLPrefsIMImpl::onCommitLogging( LLUICtrl* ctrl, void* user_data)
00322 {
00323 LLPrefsIMImpl* self=(LLPrefsIMImpl*)user_data;
00324 self->enableHistory();
00325 }
00326
00327
00328
00329
00330 LLPrefsIM::LLPrefsIM()
00331 : impl( * new LLPrefsIMImpl() )
00332 { }
00333
00334 LLPrefsIM::~LLPrefsIM()
00335 {
00336 delete &impl;
00337 }
00338
00339 void LLPrefsIM::apply()
00340 {
00341 impl.apply();
00342 }
00343
00344 void LLPrefsIM::cancel()
00345 {
00346 impl.cancel();
00347 }
00348
00349 void LLPrefsIM::setPersonalInfo(
00350 const char* visibility,
00351 bool im_via_email,
00352 const char* email)
00353 {
00354 impl.setPersonalInfo(
00355 ll_safe_string(visibility),
00356 im_via_email,
00357 ll_safe_string(email));
00358 }
00359
00360 LLPanel* LLPrefsIM::getPanel()
00361 {
00362 return &impl;
00363 }