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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
/**
* @file llfloaterautoreplacesettings.cpp
* @brief Auto Replace List floater
*
* $LicenseInfo:firstyear=2012&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2012, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llfloaterautoreplacesettings.h"
#include "llagentdata.h"
#include "llcommandhandler.h"
#include "llfloater.h"
#include "lluictrlfactory.h"
#include "llagent.h"
#include "llpanel.h"
#include "llbutton.h"
#include "llcolorswatch.h"
#include "llcombobox.h"
#include "llview.h"
#include "llhttpclient.h"
#include "llbufferstream.h"
#include "llcheckboxctrl.h"
#include "llviewercontrol.h"
#include "llui.h"
#include "llcontrol.h"
#include "llscrollingpanellist.h"
#include "llautoreplace.h"
#include "llfilepicker.h"
#include "llfile.h"
#include "llsdserialize.h"
#include "llsdutil.h"
#include "llchat.h"
#include "llinventorymodel.h"
#include "llhost.h"
#include "llassetstorage.h"
#include "roles_constants.h"
#include "llviewertexteditor.h"
#include <boost/tokenizer.hpp>
#include <iosfwd>
#include "llfloaterreg.h"
#include "llinspecttoast.h"
#include "llnotificationhandler.h"
#include "llnotificationmanager.h"
#include "llnotificationsutil.h"
LLFloaterAutoReplaceSettings::LLFloaterAutoReplaceSettings(const LLSD& key)
: LLFloater(key)
, mSelectedListName("")
, mListNames(NULL)
, mReplacementsList(NULL)
, mKeyword(NULL)
, mPreviousKeyword("")
, mReplacement(NULL)
{
}
void LLFloaterAutoReplaceSettings::onClose(bool app_quitting)
{
cleanUp();
}
BOOL LLFloaterAutoReplaceSettings::postBuild(void)
{
// get copies of the current settings that we will operate on
mEnabled = gSavedSettings.getBOOL("AutoReplace");
LL_DEBUGS("AutoReplace") << ( mEnabled ? "enabled" : "disabled") << LL_ENDL;
mSettings = LLAutoReplace::getInstance()->getSettings();
// global checkbox for whether or not autoreplace is active
LLUICtrl* enabledCheckbox = getChild<LLUICtrl>("autoreplace_enable");
enabledCheckbox->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onAutoReplaceToggled, this));
enabledCheckbox->setValue(LLSD(mEnabled));
// top row list creation and deletion
getChild<LLUICtrl>("autoreplace_import_list")->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onImportList,this));
getChild<LLUICtrl>("autoreplace_export_list")->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onExportList,this));
getChild<LLUICtrl>("autoreplace_new_list")->setCommitCallback( boost::bind(&LLFloaterAutoReplaceSettings::onNewList,this));
getChild<LLUICtrl>("autoreplace_delete_list")->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onDeleteList,this));
// the list of keyword->replacement lists
mListNames = getChild<LLScrollListCtrl>("autoreplace_list_name");
mListNames->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onSelectList, this));
mListNames->setCommitOnSelectionChange(true);
// list ordering
getChild<LLUICtrl>("autoreplace_list_up")->setCommitCallback( boost::bind(&LLFloaterAutoReplaceSettings::onListUp,this));
getChild<LLUICtrl>("autoreplace_list_down")->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onListDown,this));
// keyword->replacement entry add / delete
getChild<LLUICtrl>("autoreplace_add_entry")->setCommitCallback( boost::bind(&LLFloaterAutoReplaceSettings::onAddEntry,this));
getChild<LLUICtrl>("autoreplace_delete_entry")->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onDeleteEntry,this));
// entry edits
mKeyword = getChild<LLLineEditor>("autoreplace_keyword");
mReplacement = getChild<LLLineEditor>("autoreplace_replacement");
getChild<LLUICtrl>("autoreplace_save_entry")->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onSaveEntry, this));
// dialog termination ( Save Changes / Cancel )
getChild<LLUICtrl>("autoreplace_save_changes")->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onSaveChanges, this));
getChild<LLUICtrl>("autoreplace_cancel")->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onCancel, this));
// the list of keyword->replacement pairs
mReplacementsList = getChild<LLScrollListCtrl>("autoreplace_list_replacements");
mReplacementsList->setCommitCallback(boost::bind(&LLFloaterAutoReplaceSettings::onSelectEntry, this));
mReplacementsList->setCommitOnSelectionChange(true);
mSelectedListName.clear();
updateListNames();
updateListNamesControls();
updateReplacementsList();
return true;
}
void LLFloaterAutoReplaceSettings::updateListNames()
{
mListNames->deleteAllItems(); // start from scratch
LLSD listNames = mSettings.getListNames(); // Array of Strings
for ( LLSD::array_const_iterator entry = listNames.beginArray(), end = listNames.endArray();
entry != end;
++entry
)
{
const std::string& listName = entry->asString();
mListNames->addSimpleElement(listName);
}
if (!mSelectedListName.empty())
{
mListNames->setSelectedByValue( LLSD(mSelectedListName), true );
}
}
void LLFloaterAutoReplaceSettings::updateListNamesControls()
{
if ( mSelectedListName.empty() )
{
// There is no selected list
// Disable all controls that operate on the selected list
getChild<LLButton>("autoreplace_export_list")->setEnabled(false);
getChild<LLButton>("autoreplace_delete_list")->setEnabled(false);
getChild<LLButton>("autoreplace_list_up")->setEnabled(false);
getChild<LLButton>("autoreplace_list_down")->setEnabled(false);
mReplacementsList->deleteAllItems();
}
else
{
// Enable the controls that operate on the selected list
getChild<LLButton>("autoreplace_export_list")->setEnabled(true);
getChild<LLButton>("autoreplace_delete_list")->setEnabled(true);
getChild<LLButton>("autoreplace_list_up")->setEnabled(!selectedListIsFirst());
getChild<LLButton>("autoreplace_list_down")->setEnabled(!selectedListIsLast());
}
}
void LLFloaterAutoReplaceSettings::onSelectList()
{
std::string previousSelectedListName = mSelectedListName;
// only one selection allowed
LLSD selected = mListNames->getSelectedValue();
if (selected.isDefined())
{
mSelectedListName = selected.asString();
LL_DEBUGS("AutoReplace")<<"selected list '"<<mSelectedListName<<"'"<<LL_ENDL;
}
else
{
mSelectedListName.clear();
LL_DEBUGS("AutoReplace")<<"unselected"<<LL_ENDL;
}
updateListNamesControls();
if ( previousSelectedListName != mSelectedListName )
{
updateReplacementsList();
}
}
void LLFloaterAutoReplaceSettings::onSelectEntry()
{
LLSD selectedRow = mReplacementsList->getSelectedValue();
if (selectedRow.isDefined())
{
mPreviousKeyword = selectedRow.asString();
LL_DEBUGS("AutoReplace")<<"selected entry '"<<mPreviousKeyword<<"'"<<LL_ENDL;
mKeyword->setValue(selectedRow);
std::string replacement = mSettings.replacementFor(mPreviousKeyword, mSelectedListName );
mReplacement->setValue(replacement);
enableReplacementEntry();
mReplacement->setFocus(true);
}
else
{
// no entry selection, so the entry panel should be off
disableReplacementEntry();
LL_DEBUGS("AutoReplace")<<"no row selected"<<LL_ENDL;
}
}
void LLFloaterAutoReplaceSettings::updateReplacementsList()
{
// start from scratch, since this should only be called when the list changes
mReplacementsList->deleteAllItems();
if ( mSelectedListName.empty() )
{
mReplacementsList->setEnabled(false);
getChild<LLButton>("autoreplace_add_entry")->setEnabled(false);
disableReplacementEntry();
}
else
{
// Populate the keyword->replacement list from the selected list
const LLSD* mappings = mSettings.getListEntries(mSelectedListName);
for ( LLSD::map_const_iterator entry = mappings->beginMap(), end = mappings->endMap();
entry != end;
entry++
)
{
LLSD row;
row["id"] = entry->first;
row["columns"][0]["column"] = "keyword";
row["columns"][0]["value"] = entry->first;
row["columns"][1]["column"] = "replacement";
row["columns"][1]["value"] = entry->second;
mReplacementsList->addElement(row, ADD_BOTTOM);
}
mReplacementsList->deselectAllItems(false /* don't call commit */);
mReplacementsList->setEnabled(true);
getChild<LLButton>("autoreplace_add_entry")->setEnabled(true);
disableReplacementEntry();
}
}
void LLFloaterAutoReplaceSettings::enableReplacementEntry()
{
LL_DEBUGS("AutoReplace")<<LL_ENDL;
mKeyword->setEnabled(true);
mReplacement->setEnabled(true);
getChild<LLButton>("autoreplace_save_entry")->setEnabled(true);
getChild<LLButton>("autoreplace_delete_entry")->setEnabled(true);
}
void LLFloaterAutoReplaceSettings::disableReplacementEntry()
{
LL_DEBUGS("AutoReplace")<<LL_ENDL;
mPreviousKeyword.clear();
mKeyword->clear();
mKeyword->setEnabled(false);
mReplacement->clear();
mReplacement->setEnabled(false);
getChild<LLButton>("autoreplace_save_entry")->setEnabled(false);
getChild<LLButton>("autoreplace_delete_entry")->setEnabled(false);
}
// called when the global settings checkbox is changed
void LLFloaterAutoReplaceSettings::onAutoReplaceToggled()
{
// set our local copy of the flag, copied to the global preference in onOk
mEnabled = childGetValue("autoreplace_enable").asBoolean();
LL_DEBUGS("AutoReplace")<< "autoreplace_enable " << ( mEnabled ? "on" : "off" ) << LL_ENDL;
}
// called when the List Up button is pressed
void LLFloaterAutoReplaceSettings::onListUp()
{
S32 selectedRow = mListNames->getFirstSelectedIndex();
LLSD selectedName = mListNames->getSelectedValue().asString();
if ( mSettings.increaseListPriority(selectedName) )
{
updateListNames();
updateListNamesControls();
}
else
{
LL_WARNS("AutoReplace")
<< "invalid row ("<<selectedRow<<") selected '"<<selectedName<<"'"
<<LL_ENDL;
}
}
// called when the List Down button is pressed
void LLFloaterAutoReplaceSettings::onListDown()
{
S32 selectedRow = mListNames->getFirstSelectedIndex();
std::string selectedName = mListNames->getSelectedValue().asString();
if ( mSettings.decreaseListPriority(selectedName) )
{
updateListNames();
updateListNamesControls();
}
else
{
LL_WARNS("AutoReplace")
<< "invalid row ("<<selectedRow<<") selected '"<<selectedName<<"'"
<<LL_ENDL;
}
}
// called when the Delete Entry button is pressed
void LLFloaterAutoReplaceSettings::onDeleteEntry()
{
LLSD selectedRow = mReplacementsList->getSelectedValue();
if (selectedRow.isDefined())
{
std::string keyword = selectedRow.asString();
mReplacementsList->deleteSelectedItems(); // delete from the control
mSettings.removeEntryFromList(keyword, mSelectedListName); // delete from the local settings copy
disableReplacementEntry(); // no selection active, so turn off the buttons
}
}
// called when the Import List button is pressed
void LLFloaterAutoReplaceSettings::onImportList()
{
LLFilePicker& picker = LLFilePicker::instance();
if( picker.getOpenFile( LLFilePicker::FFLOAD_XML) )
{
llifstream file;
file.open(picker.getFirstFile().c_str());
LLSD newList;
if (file.is_open())
{
LLSDSerialize::fromXMLDocument(newList, file);
}
file.close();
switch ( mSettings.addList(newList) )
{
case LLAutoReplaceSettings::AddListOk:
mSelectedListName = LLAutoReplaceSettings::getListName(newList);
updateListNames();
updateListNamesControls();
updateReplacementsList();
break;
case LLAutoReplaceSettings::AddListDuplicateName:
{
std::string newName = LLAutoReplaceSettings::getListName(newList);
LL_WARNS("AutoReplace")<<"name '"<<newName<<"' is in use; prompting for new name"<<LL_ENDL;
LLSD newPayload;
newPayload["list"] = newList;
LLSD args;
args["DUPNAME"] = newName;
LLNotificationsUtil::add("RenameAutoReplaceList", args, newPayload,
boost::bind(&LLFloaterAutoReplaceSettings::callbackListNameConflict, this, _1, _2));
}
break;
case LLAutoReplaceSettings::AddListInvalidList:
LLNotificationsUtil::add("InvalidAutoReplaceList");
LL_WARNS("AutoReplace") << "imported list was invalid" << LL_ENDL;
mSelectedListName.clear();
updateListNames();
updateListNamesControls();
updateReplacementsList();
break;
default:
LL_ERRS("AutoReplace") << "invalid AddListResult" << LL_ENDL;
}
}
else
{
LL_DEBUGS("AutoReplace") << "file selection failed for import list" << LL_ENDL;
}
}
void LLFloaterAutoReplaceSettings::onNewList()
{
LLSD payload;
LLSD emptyList;
LLAutoReplaceSettings::createEmptyList(emptyList);
payload["list"] = emptyList;
LLSD args;
LLNotificationsUtil::add("AddAutoReplaceList", args, payload,
boost::bind(&LLFloaterAutoReplaceSettings::callbackNewListName, this, _1, _2));
}
bool LLFloaterAutoReplaceSettings::callbackNewListName(const LLSD& notification, const LLSD& response)
{
LL_DEBUGS("AutoReplace")<<"called"<<LL_ENDL;
LLSD newList = notification["payload"]["list"];
if ( response.has("listname") && response["listname"].isString() )
{
std::string newName = response["listname"].asString();
LLAutoReplaceSettings::setListName(newList, newName);
switch ( mSettings.addList(newList) )
{
case LLAutoReplaceSettings::AddListOk:
LL_INFOS("AutoReplace") << "added new list '"<<newName<<"'"<<LL_ENDL;
mSelectedListName = newName;
updateListNames();
updateListNamesControls();
updateReplacementsList();
break;
case LLAutoReplaceSettings::AddListDuplicateName:
{
LL_WARNS("AutoReplace")<<"name '"<<newName<<"' is in use; prompting for new name"<<LL_ENDL;
LLSD newPayload;
newPayload["list"] = notification["payload"]["list"];
LLSD args;
args["DUPNAME"] = newName;
LLNotificationsUtil::add("RenameAutoReplaceList", args, newPayload,
boost::bind(&LLFloaterAutoReplaceSettings::callbackListNameConflict, this, _1, _2));
}
break;
case LLAutoReplaceSettings::AddListInvalidList:
LLNotificationsUtil::add("InvalidAutoReplaceList");
mSelectedListName.clear();
updateListNames();
updateListNamesControls();
updateReplacementsList();
break;
default:
LL_ERRS("AutoReplace") << "invalid AddListResult" << LL_ENDL;
}
}
else
{
LL_ERRS("AutoReplace") << "adding notification response" << LL_ENDL;
}
return false;
}
// callback for the RenameAutoReplaceList notification
bool LLFloaterAutoReplaceSettings::callbackListNameConflict(const LLSD& notification, const LLSD& response)
{
LLSD newList = notification["payload"]["list"];
S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
switch ( option )
{
case 0:
// Replace current list
LL_INFOS("AutoReplace")<<"option 'replace current list' selected"<<LL_ENDL;
break;
case 1:
// Use New Name
LL_INFOS("AutoReplace")<<"option 'use new name' selected"<<LL_ENDL;
callbackNewListName(notification, response);
break;
default:
LL_ERRS("AutoReplace")<<"invalid selected option "<<option<<LL_ENDL;
}
return false;
}
void LLFloaterAutoReplaceSettings::onDeleteList()
{
std::string listName= mListNames->getFirstSelected()->getColumn(0)->getValue().asString();
mSettings.removeReplacementList(listName); // remove from the copy of settings
mReplacementsList->deleteSelectedItems(); // remove from the scrolling list
mSelectedListName.clear();
updateListNames();
updateListNamesControls();
updateReplacementsList();
}
void LLFloaterAutoReplaceSettings::onExportList()
{
std::string listName=mListNames->getFirstSelected()->getColumn(0)->getValue().asString();
const LLSD* list = mSettings.exportList(listName);
std::string listFileName = listName + ".xml";
LLFilePicker& picker = LLFilePicker::instance();
if( picker.getSaveFile( LLFilePicker::FFSAVE_XML, listFileName) )
{
llofstream file;
file.open(picker.getFirstFile().c_str());
LLSDSerialize::toPrettyXML(*list, file);
file.close();
}
}
void LLFloaterAutoReplaceSettings::onAddEntry()
{
mPreviousKeyword.clear();
mReplacementsList->deselectAllItems(false /* don't call commit */);
mKeyword->clear();
mReplacement->clear();
enableReplacementEntry();
mKeyword->setFocus(true);
}
void LLFloaterAutoReplaceSettings::onSaveEntry()
{
LL_DEBUGS("AutoReplace")<<"called"<<LL_ENDL;
if ( ! mPreviousKeyword.empty() )
{
// delete any existing value for the key that was editted
LL_INFOS("AutoReplace")
<< "list '" << mSelectedListName << "' "
<< "removed '" << mPreviousKeyword
<< "'" << LL_ENDL;
mSettings.removeEntryFromList( mPreviousKeyword, mSelectedListName );
}
LLWString keyword = mKeyword->getWText();
LLWString replacement = mReplacement->getWText();
if ( mSettings.addEntryToList(keyword, replacement, mSelectedListName) )
{
// insert the new keyword->replacement pair
LL_INFOS("AutoReplace")
<< "list '" << mSelectedListName << "' "
<< "added '" << wstring_to_utf8str(keyword)
<< "' -> '" << wstring_to_utf8str(replacement)
<< "'" << LL_ENDL;
updateReplacementsList();
}
else
{
LLNotificationsUtil::add("InvalidAutoReplaceEntry");
LL_WARNS("AutoReplace")<<"invalid entry "
<< "keyword '" << wstring_to_utf8str(keyword)
<< "' replacement '" << wstring_to_utf8str(replacement)
<< "'" << LL_ENDL;
}
}
void LLFloaterAutoReplaceSettings::onCancel()
{
cleanUp();
closeFloater(false /* not quitting */);
}
void LLFloaterAutoReplaceSettings::onSaveChanges()
{
// put our local copy of the settings into the active copy
LLAutoReplace::getInstance()->setSettings( mSettings );
// save our local copy of the global feature enable/disable value
gSavedSettings.setBOOL("AutoReplace", mEnabled);
cleanUp();
closeFloater(false /* not quitting */);
}
void LLFloaterAutoReplaceSettings::cleanUp()
{
}
bool LLFloaterAutoReplaceSettings::selectedListIsFirst()
{
bool isFirst = false;
if (!mSelectedListName.empty())
{
LLSD lists = mSettings.getListNames(); // an Array of Strings
LLSD first = lists.get(0);
if ( first.isString() && first.asString() == mSelectedListName )
{
isFirst = true;
}
}
return isFirst;
}
bool LLFloaterAutoReplaceSettings::selectedListIsLast()
{
bool isLast = false;
if (!mSelectedListName.empty())
{
LLSD last;
LLSD lists = mSettings.getListNames(); // an Array of Strings
for ( LLSD::array_const_iterator list = lists.beginArray(), listEnd = lists.endArray();
list != listEnd;
list++
)
{
last = *list;
}
if ( last.isString() && last.asString() == mSelectedListName )
{
isLast = true;
}
}
return isLast;
}
/* TBD
mOldText = getChild<LLLineEditor>("autoreplace_old_text");
mNewText = getChild<LLLineEditor>("autoreplace_new_text");
*/
|