aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lggautocorrectfloater.cpp
diff options
context:
space:
mode:
authorPatrick Sapinski2010-08-24 21:19:42 -0400
committerMcCabe Maxsted2010-08-30 17:19:35 -0700
commit46ce6b78d479a0da264f933a694cb84b00a6c6c8 (patch)
treec5eb7724973f12f047847f243a18db6971c6d847 /linden/indra/newview/lggautocorrectfloater.cpp
parentupdated chatbar command line and added the necessary settings and hooks to us... (diff)
downloadmeta-impy-46ce6b78d479a0da264f933a694cb84b00a6c6c8.zip
meta-impy-46ce6b78d479a0da264f933a694cb84b00a6c6c8.tar.gz
meta-impy-46ce6b78d479a0da264f933a694cb84b00a6c6c8.tar.bz2
meta-impy-46ce6b78d479a0da264f933a694cb84b00a6c6c8.tar.xz
added autocorrect functionality and floater
Diffstat (limited to 'linden/indra/newview/lggautocorrectfloater.cpp')
-rw-r--r--linden/indra/newview/lggautocorrectfloater.cpp444
1 files changed, 444 insertions, 0 deletions
diff --git a/linden/indra/newview/lggautocorrectfloater.cpp b/linden/indra/newview/lggautocorrectfloater.cpp
new file mode 100644
index 0000000..9d68b25
--- /dev/null
+++ b/linden/indra/newview/lggautocorrectfloater.cpp
@@ -0,0 +1,444 @@
1/* Copyright (c) 2009
2*
3* Greg Hendrickson (LordGregGreg Back). All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or
6* without modification, are permitted provided that the following
7* conditions are met:
8*
9* 1. Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* 2. Redistributions in binary form must reproduce the above
12* copyright notice, this list of conditions and the following
13* disclaimer in the documentation and/or other materials provided
14* with the distribution.
15* 3. Neither the name Modular Systems nor the names of its contributors
16* may be used to endorse or promote products derived from this
17* software without specific prior written permission.
18*
19* THIS SOFTWARE IS PROVIDED BY MODULAR SYSTEMS AND CONTRIBUTORS "AS IS"
20* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MODULAR SYSTEMS OR CONTRIBUTORS
23* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29* THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32#include "llviewerprecompiledheaders.h"
33
34#include "lggautocorrectfloater.h"
35
36#include "llagentdata.h"
37#include "llcommandhandler.h"
38#include "llfloater.h"
39#include "lluictrlfactory.h"
40#include "llagent.h"
41#include "llpanel.h"
42#include "llbutton.h"
43#include "llcolorswatch.h"
44#include "llcombobox.h"
45#include "llview.h"
46#include "llprefsadvanced.h"
47#include "llhttpclient.h"
48#include "llbufferstream.h"
49#include "llcheckboxctrl.h"
50#include "llviewercontrol.h"
51
52#include "llui.h"
53#include "llcontrol.h"
54#include "llscrolllistctrl.h"
55#include "llscrollingpanellist.h"
56#include "lggautocorrect.h"
57#include "llfilepicker.h"
58#include "llfile.h"
59#include "llsdserialize.h"
60#include "llfloaterchat.h"
61#include "llchat.h"
62#include "llviewerinventory.h"
63#include "llinventorymodel.h"
64#include "llhost.h"
65#include "llassetstorage.h"
66#include "roles_constants.h"
67#include "llviewertexteditor.h"
68#include <boost/tokenizer.hpp>
69
70#include <iosfwd>
71
72class lggAutoCorrectFloater;
73class lggAutoCorrectFloater : public LLFloater, public LLFloaterSingleton<lggAutoCorrectFloater>
74{
75public:
76 lggAutoCorrectFloater(const LLSD& seed);
77 virtual ~lggAutoCorrectFloater();
78 BOOL postBuild(void);
79 void setData(void * data);
80 void updateEnabledStuff();
81 void updateNamesList();
82 void updateListControlsEnabled(BOOL selected);
83 void updateItemsList();
84
85
86 LLScrollListCtrl *namesList;
87
88 LLScrollListCtrl *entryList;
89 LLPrefsAdvanced * empanel;
90private:
91 static lggAutoCorrectFloater* sInstance;
92 static JCInvDropTarget* mNotecardDropTarget;
93 static void onBoxCommitEnabled(LLUICtrl* caller, void* user_data);
94 static void onEntrySettingChange(LLUICtrl* caller, void* user_data);
95 static void onSelectName(LLUICtrl* caller, void* user_data);
96 static void ResponseItemDrop(LLViewerInventoryItem* item);
97 static void onNotecardLoadComplete(LLVFS *vfs,const LLUUID& asset_uuid,LLAssetType::EType type,void* user_data, S32 status, LLExtStat ext_status);
98
99
100 static void deleteEntry(void* data);
101 static void addEntry(void* data);
102 static void exportList(void* data);
103 static void removeList(void* data);
104 static void loadList(void* data);
105
106};
107
108
109
110JCInvDropTarget * lggAutoCorrectFloater::mNotecardDropTarget;
111lggAutoCorrectFloater* lggAutoCorrectFloater::sInstance;
112
113lggAutoCorrectFloater::~lggAutoCorrectFloater()
114{
115 sInstance = NULL;
116 delete mNotecardDropTarget;
117 mNotecardDropTarget = NULL;
118}
119lggAutoCorrectFloater::lggAutoCorrectFloater(const LLSD& seed)
120{
121 LLUICtrlFactory::getInstance()->buildFloater(this, "floater_autocorrect.xml");
122
123 if (getRect().mLeft == 0
124 && getRect().mBottom == 0)
125 {
126 center();
127 }
128 if(sInstance)delete sInstance;
129 sInstance = this;
130
131}
132
133BOOL lggAutoCorrectFloater::postBuild(void)
134{
135
136 namesList = getChild<LLScrollListCtrl>("em_ac_list_name");
137 entryList = getChild<LLScrollListCtrl>("em_ac_list_entry");
138
139 childSetCommitCallback("em_ac_enable",onBoxCommitEnabled);
140
141 childSetCommitCallback("em_ac_list_enabled",onEntrySettingChange);
142 childSetCommitCallback("em_ac_list_show",onEntrySettingChange);
143 childSetCommitCallback("em_ac_list_style",onEntrySettingChange);
144 childSetCommitCallback("em_ac_priority",onEntrySettingChange);
145
146
147
148 updateEnabledStuff();
149 updateNamesList();
150
151
152 namesList->setCommitOnSelectionChange(TRUE);
153 childSetCommitCallback("em_ac_list_name", onSelectName, this);
154
155 childSetAction("em_ac_deletelist",removeList,this);
156 childSetAction("em_ac_rementry",deleteEntry,this);
157 childSetAction("em_ac_exportlist",exportList,this);
158 childSetAction("em_ac_addentry",addEntry,this);
159 childSetAction("em_ac_loadlist",loadList,this);
160
161 LLView *target_view = getChild<LLView>("em_ac_notecard_target");
162 if(target_view)
163 {
164 if (mNotecardDropTarget)//shouldn't happen
165 {
166 delete mNotecardDropTarget;
167 }
168 mNotecardDropTarget = new JCInvDropTarget("drop target", target_view->getRect(), ResponseItemDrop);//, mAvatarID);
169 addChild(mNotecardDropTarget);
170 }
171 return true;
172}
173void lggAutoCorrectFloater::ResponseItemDrop(LLViewerInventoryItem* item)
174{
175 if(item)
176 {
177 if (gAgent.allowOperation(PERM_COPY, item->getPermissions(),GP_OBJECT_MANIPULATE) || gAgent.isGodlike())
178 {
179 if(!item->getAssetUUID().isNull())
180 gAssetStorage->getInvItemAsset(LLHost::invalid,
181 gAgent.getID(),
182 gAgent.getSessionID(),
183 item->getPermissions().getOwner(),
184 LLUUID::null,
185 item->getUUID(),
186 item->getAssetUUID(),
187 item->getType(),
188 &onNotecardLoadComplete,
189 (void*)item,
190 TRUE);
191 gSavedSettings.setBOOL("EmeraldEnableAutoCorrect",true);
192
193 }
194 }
195}
196void lggAutoCorrectFloater::onNotecardLoadComplete(LLVFS *vfs,const LLUUID& asset_uuid,LLAssetType::EType type,void* user_data, S32 status, LLExtStat ext_status)
197{
198 if(status == LL_ERR_NOERR)
199 {
200 S32 size = vfs->getSize(asset_uuid, type);
201 U8* buffer = new U8[size];
202 vfs->getData(asset_uuid, type, buffer, 0, size);
203
204 if(type == LLAssetType::AT_NOTECARD)
205 {
206 LLViewerTextEditor* edit = new LLViewerTextEditor("",LLRect(0,0,0,0),S32_MAX,"");
207 if(edit->importBuffer((char*)buffer, (S32)size))
208 {
209 llinfos << "decode success" << llendl;
210 std::string card = edit->getText();
211 edit->die();
212 LLSD info;
213 std::istringstream ins; // Declare an input string stream.
214 ins.str(card); // Specify string to read.
215
216 LLSDSerialize::fromXML(info,ins);
217
218 LGGAutoCorrect::getInstance()->addCorrectionList(info);
219 llinfos << "read success" << llendl;
220 sInstance->updateEnabledStuff();
221 }
222 else
223 {
224 llinfos << "decode error" << llendl;
225 }
226 }
227 }
228 else
229 {
230 llinfos << "read error" << llendl;
231 }
232}
233
234
235void lggAutoCorrectFloater::onSelectName(LLUICtrl* ctrl, void* user_data)
236{
237 sInstance->updateItemsList();
238}
239void lggAutoCorrectFloater::updateItemsList()
240{
241 entryList->deleteAllItems();
242 if((namesList->getAllSelected().size())<=0)
243 {
244
245 updateListControlsEnabled(FALSE);
246 return;
247 }
248
249 updateListControlsEnabled(TRUE);
250 std::string listName= namesList->getFirstSelected()->getColumn(0)->getValue().asString();
251
252 LLSD listData = LGGAutoCorrect::getInstance()->getAutoCorrectEntries(listName);
253 childSetValue("em_ac_list_enabled",listData["enabled"].asBoolean());
254 childSetValue("em_ac_list_style",listData["wordStyle"].asBoolean());
255 childSetValue("em_ac_list_show",listData["announce"].asBoolean());
256 childSetValue("em_ac_text_name",listName);
257 childSetValue("em_ac_text_author",listData["author"]);
258 childSetValue("em_ac_priority",listData["priority"]);
259 static S32 *countAuto= rebind_llcontrol<S32>("EmeraldAutoCorrectCount", &gSavedSettings, true);
260 childSetValue("em_ac_stats",*countAuto);
261
262 LLSD autoCorrects = listData["data"];
263 LLSD::map_const_iterator loc_it = autoCorrects.beginMap();
264 LLSD::map_const_iterator loc_end = autoCorrects.endMap();
265 for ( ; loc_it != loc_end; ++loc_it)
266 {
267 const std::string& wrong = (*loc_it).first;
268 const std::string& right = (*loc_it).second;
269
270 //std::string lentry(wrong+"=>"+right);
271
272 LLSD element;
273 element["id"] = wrong;
274 LLSD& s_column = element["columns"][0];
275 s_column["column"] = "Search";
276 s_column["value"] = wrong;
277 s_column["font"] = "SANSSERIF";
278 LLSD& r_column = element["columns"][1];
279 r_column["column"] = "Replace";
280 r_column["value"] = right;
281 r_column["font"] = "SANSSERIF";
282
283 entryList->addElement(element, ADD_BOTTOM);
284 }
285
286}
287void lggAutoCorrectFloater::updateNamesList()
288{
289 namesList->deleteAllItems();
290 static BOOL *enabledd = rebind_llcontrol<BOOL>("EmeraldEnableAutoCorrect", &gSavedSettings, true);
291 if(!(*enabledd))
292 {
293 updateItemsList();
294 return;
295 }
296 static S32 *countAuto= rebind_llcontrol<S32>("EmeraldAutoCorrectCount", &gSavedSettings, true);
297 childSetValue("em_ac_stats",*countAuto);
298 LLSD autoCorrects = LGGAutoCorrect::getInstance()->getAutoCorrects();
299 LLSD::map_const_iterator loc_it = autoCorrects.beginMap();
300 LLSD::map_const_iterator loc_end = autoCorrects.endMap();
301 for ( ; loc_it != loc_end; ++loc_it)
302 {
303 const std::string& listName = (*loc_it).first;
304
305 LLSD element;
306 element["id"] = listName;
307 LLSD& friend_column = element["columns"][0];
308 friend_column["column"] = "Entries";
309 friend_column["value"] = listName;
310 friend_column["font"] = "SANSSERIF";
311 const LLSD& loc_map = (*loc_it).second;
312 if(loc_map["enabled"].asBoolean())
313 friend_column["font-style"] = "BOLD";
314 else
315 friend_column["font-style"] = "NORMAL";
316 if(namesList)
317 namesList->addElement(element, ADD_BOTTOM);
318 }
319 updateItemsList();
320}
321void lggAutoCorrectFloater::updateListControlsEnabled(BOOL selected)
322{
323
324 childSetEnabled("em_ac_text1",selected);
325 childSetEnabled("em_ac_text2",selected);
326 childSetEnabled("em_ac_text_name",selected);
327 childSetEnabled("em_ac_text_author",selected);
328 childSetEnabled("em_ac_list_enabled",selected);
329 childSetEnabled("em_ac_list_show",selected);
330 childSetEnabled("em_ac_list_style",selected);
331 childSetEnabled("em_ac_deletelist",selected);
332 childSetEnabled("em_ac_exportlist",selected);
333 childSetEnabled("em_ac_addentry",selected);
334 childSetEnabled("em_ac_rementry",selected);
335 childSetEnabled("em_ac_priority",selected);
336
337}
338void lggAutoCorrectFloater::updateEnabledStuff()
339{
340 static BOOL *enabledd = rebind_llcontrol<BOOL>("EmeraldEnableAutoCorrect", &gSavedSettings, true);
341 if(!(*enabledd))
342 {
343 getChild<LLCheckBoxCtrl>("em_ac_enable")->setEnabledColor(LLColor4(1.0f,0.0f,0.0f,1.0f));
344 }else
345 {
346 getChild<LLCheckBoxCtrl>("em_ac_enable")->setEnabledColor(LLUI::sColorsGroup->getColor( "LabelTextColor" ));
347 }
348
349 childSetEnabled("em_ac_list_name",*enabledd);
350 childSetEnabled("em_ac_list_entry",*enabledd);
351 updateListControlsEnabled(*enabledd);
352 updateNamesList();
353 LGGAutoCorrect::getInstance()->save();
354
355}
356void lggAutoCorrectFloater::setData(void * data)
357{
358 empanel = (LLPrefsAdvanced*)data;
359}
360void lggAutoCorrectFloater::onBoxCommitEnabled(LLUICtrl* caller, void* user_data)
361{
362 sInstance->updateEnabledStuff();
363}
364void lggAutoCorrectFloater::onEntrySettingChange(LLUICtrl* caller, void* user_data)
365{
366 std::string listName= sInstance->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
367 LGGAutoCorrect::getInstance()->setListEnabled(listName,sInstance->childGetValue("em_ac_list_enabled").asBoolean());
368 LGGAutoCorrect::getInstance()->setListAnnounceeState(listName,sInstance->childGetValue("em_ac_list_show").asBoolean());
369 LGGAutoCorrect::getInstance()->setListStyle(listName,sInstance->childGetValue("em_ac_list_style").asBoolean());
370 LGGAutoCorrect::getInstance()->setListPriority(listName,sInstance->childGetValue("em_ac_priority").asInteger());
371
372 //sInstance->updateEnabledStuff();
373 sInstance->updateItemsList();
374 LGGAutoCorrect::getInstance()->save();
375}
376void lggAutoCorrectFloater::deleteEntry(void* data)
377{
378 std::string listName= sInstance->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
379
380 if((sInstance->entryList->getAllSelected().size())>0)
381 {
382 std::string wrong= sInstance->entryList->getFirstSelected()->getColumn(0)->getValue().asString();
383 LGGAutoCorrect::getInstance()->removeEntryFromList(wrong,listName);
384 sInstance->updateItemsList();
385 LGGAutoCorrect::getInstance()->save();
386 }
387}
388void lggAutoCorrectFloater::loadList(void* data)
389{
390 LLFilePicker& picker = LLFilePicker::instance();
391
392 if(!picker.getOpenFile( LLFilePicker::FFLOAD_XML) )
393 {return;
394 }
395 llifstream file;
396 file.open(picker.getFirstFile().c_str());
397 LLSD blankllsd;
398 if (file.is_open())
399 {
400 LLSDSerialize::fromXMLDocument(blankllsd, file);
401 }
402 file.close();
403 gSavedSettings.setBOOL("EmeraldEnableAutoCorrect",true);
404 LGGAutoCorrect::getInstance()->addCorrectionList(blankllsd);
405 sInstance->updateEnabledStuff();
406}
407void lggAutoCorrectFloater::removeList(void* data)
408{
409 std::string listName= sInstance->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
410 LGGAutoCorrect::getInstance()->removeCorrectionList(listName);
411 sInstance->updateEnabledStuff();
412
413}
414void lggAutoCorrectFloater::exportList(void *data)
415{
416 std::string listName= sInstance->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
417
418 LLFilePicker& picker = LLFilePicker::instance();
419
420 if(!picker.getSaveFile( LLFilePicker::FFSAVE_XML) )
421 {return;
422 }
423 llofstream file;
424 file.open(picker.getFirstFile().c_str());
425 LLSDSerialize::toPrettyXML(LGGAutoCorrect::getInstance()->exportList(listName), file);
426 file.close();
427}
428void lggAutoCorrectFloater::addEntry(void* data)
429{
430 std::string listName= sInstance->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
431 LLChat chat;
432 chat.mText = "To add an entry, please type in chat \""+gSavedSettings.getString("EmeraldCmdLineAutocorrect")+" "+listName+"|wrongWord|rightWord\"";
433 chat.mSourceType = CHAT_SOURCE_SYSTEM;
434 LLFloaterChat::addChat(chat, FALSE, FALSE);
435}
436
437void lggAutoCorrectFloaterStart::show(BOOL showin,void * data)
438{
439 if(showin)
440 {
441 lggAutoCorrectFloater* dic_floater = lggAutoCorrectFloater::showInstance();
442 dic_floater->setData(data);
443 }
444}