aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llpaneldirbrowser.cpp
blob: 732a9190d1e7bbe3d9c1a0f8e447fe76eb050384 (plain)
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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
/** 
 * @file llpaneldirbrowser.cpp
 * @brief LLPanelDirBrowser class implementation
 *
 * $LicenseInfo:firstyear=2001&license=viewergpl$
 * 
 * Copyright (c) 2001-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$
 */

// Base class for the various search panels/results browsers
// in the Find floater.  For example, Find > Popular Places
// is derived from this.

#include "llviewerprecompiledheaders.h"

#include "llpaneldirbrowser.h"

// linden library includes
#include "lldir.h"
#include "lleventflags.h"
#include "llfontgl.h"
#include "llqueryflags.h"
#include "message.h"

// viewer project includes
#include "llagent.h"
#include "llbutton.h"
#include "llcheckboxctrl.h"
#include "llcombobox.h"
#include "llfloateravatarinfo.h"
#include "llfloaterdirectory.h" 
#include "lllineeditor.h"
#include "llmenucommands.h"
#include "llmenugl.h"
#include "llpanelavatar.h"
#include "llpanelevent.h"
#include "llpanelgroup.h"
#include "llpanelclassified.h"
#include "llpanelpick.h"
#include "llpanelplace.h"
#include "llpaneldirland.h"
#include "llscrolllistctrl.h"
#include "lltextbox.h"
#include "lluiconstants.h"
#include "llviewercontrol.h"
#include "llviewerimagelist.h"
#include "llviewermessage.h"
#include "lluictrlfactory.h"

#include <string>
#include <sstream>
#include <vector>
#include <algorithm>


//
// Globals
//

LLMap< const LLUUID, LLPanelDirBrowser* > gDirBrowserInstances;

LLPanelDirBrowser::LLPanelDirBrowser(const std::string& name, LLFloaterDirectory* floater)
:	LLPanel(name),
	mSearchID(),
	mWantSelectID(),
	mCurrentSortColumn("name"),
	mCurrentSortAscending(TRUE),
	mSearchStart(0),
	mResultsPerPage(100),
	mResultsReceived(0),
	mMinSearchChars(1),
	mResultsContents(),
	mHaveSearchResults(FALSE),
	mDidAutoSelect(TRUE),
	mLastResultTimer(),
	mFloaterDirectory(floater)
{
	//updateResultCount();
}

BOOL LLPanelDirBrowser::postBuild()
{
	childSetCommitCallback("results", onCommitList, this);

	childSetAction("< Prev", onClickPrev, this);
	childHide("< Prev");

	childSetAction("Next >", onClickNext, this);
	childHide("Next >");

	return TRUE;
}

LLPanelDirBrowser::~LLPanelDirBrowser()
{
	// Children all cleaned up by default view destructor.

	gDirBrowserInstances.removeData(mSearchID);
}


// virtual
void LLPanelDirBrowser::draw()
{
	// HACK: If the results panel has data, we want to select the first
	// item.  Unfortunately, we don't know when the find is actually done,
	// so only do this if it's been some time since the last packet of
	// results was received.
	if (mLastResultTimer.getElapsedTimeF32() > 0.5)
	{
		if (!mDidAutoSelect &&
			!childHasFocus("results"))
		{
			LLCtrlListInterface *list = childGetListInterface("results");
			if (list)
			{
				if (list->getCanSelect())
				{
					list->selectFirstItem(); // select first item by default
					childSetFocus("results", TRUE);
				}
				// Request specific data from the server
				onCommitList(NULL, this);
			}
		}
		mDidAutoSelect = TRUE;
	}
	
	LLPanel::draw();
}


// virtual
void LLPanelDirBrowser::nextPage()
{
	mSearchStart += mResultsPerPage;
	childShow("< Prev");

	performQuery();
}


// virtual
void LLPanelDirBrowser::prevPage()
{
	mSearchStart -= mResultsPerPage;
	childSetVisible("< Prev", mSearchStart > 0);

	performQuery();
}


void LLPanelDirBrowser::resetSearchStart()
{
	mSearchStart = 0;
	childHide("Next >");
	childHide("< Prev");
}

// protected
void LLPanelDirBrowser::updateResultCount()
{
	LLScrollListCtrl* list = getChild<LLScrollListCtrl>("results");

	S32 result_count = list->getItemCount();
	std::string result_text;

	if (!mHaveSearchResults) result_count = 0;

	if (childIsVisible("Next >")) 
	{
		// Item count be off by a few if bogus items sent from database
		// Just use the number of results per page. JC
		result_text = llformat(">%d found", mResultsPerPage);
	}
	else 
	{
		result_text = llformat("%d found", result_count);
	}
	
	childSetValue("result_text", result_text);
	
	if (result_count == 0)
	{
		// add none found response
		if (list->getItemCount() == 0)
		{
			list->addCommentText(std::string("None found.")); // *TODO: Translate
			list->operateOnAll(LLCtrlListInterface::OP_DESELECT);
		}
	}
	else
	{
		childEnable("results");
	}
}

// static
void LLPanelDirBrowser::onClickPrev(void* data)
{
	LLPanelDirBrowser* self = (LLPanelDirBrowser*)data;
	self->prevPage();
}


// static
void LLPanelDirBrowser::onClickNext(void* data)
{
	LLPanelDirBrowser* self = (LLPanelDirBrowser*)data;
	self->nextPage();
}

// static
std::string LLPanelDirBrowser::filterShortWords( const std::string source_string, 
															int shortest_word_length, 
																bool& was_filtered )
{
	// degenerate case
	if ( source_string.length() < 1 ) 
		return "";

	std::stringstream codec( source_string );
	std::string each_word;
	std::vector< std::string > all_words;
    
	while( codec >> each_word )
        all_words.push_back( each_word );

	std::ostringstream dest_string( "" ); 

	was_filtered = false;

	std::vector< std::string >::iterator iter = all_words.begin();
	while( iter != all_words.end() )
	{
		if ( (int)(*iter).length() >= shortest_word_length )
		{
			dest_string << *iter;
			dest_string << " ";
		}
		else
		{
			was_filtered = true;
		}

		++iter;
	};

	return dest_string.str();
}

void LLPanelDirBrowser::selectByUUID(const LLUUID& id)
{
	LLCtrlListInterface *list = childGetListInterface("results");
	if (!list) return;
	BOOL found = list->setCurrentByID(id);
	if (found)
	{
		// we got it, don't wait for network
		// Don't bother looking for this in the draw loop.
		mWantSelectID.setNull();
		// Make sure UI updates.
		onCommitList(NULL, this);
	}
	else
	{
		// waiting for this item from the network
		mWantSelectID = id;
	}
}

void LLPanelDirBrowser::selectEventByID(S32 event_id)
{
	if (mFloaterDirectory)
	{
		if (mFloaterDirectory->mPanelEventp)
		{
			mFloaterDirectory->mPanelEventp->setVisible(TRUE);
			mFloaterDirectory->mPanelEventp->setEventID(event_id);
		}
	}
}

U32 LLPanelDirBrowser::getSelectedEventID() const
{
	if (mFloaterDirectory)
	{
		if (mFloaterDirectory->mPanelEventp)
		{
			return mFloaterDirectory->mPanelEventp->getEventID();
		}
	}
	return 0;
}

void LLPanelDirBrowser::getSelectedInfo(LLUUID* id, S32 *type)
{
	LLCtrlListInterface *list = childGetListInterface("results");
	if (!list) return;

	LLSD id_sd = childGetValue("results");

	*id = id_sd.asUUID();

	std::string id_str = id_sd.asString();
	*type = mResultsContents[id_str]["type"];
}


// static
void LLPanelDirBrowser::onCommitList(LLUICtrl* ctrl, void* data)
{
	LLPanelDirBrowser* self = (LLPanelDirBrowser*)data;
	LLCtrlListInterface *list = self->childGetListInterface("results");
	if (!list) return;

	// Start with everyone invisible
	if (self->mFloaterDirectory)
	{
		self->mFloaterDirectory->hideAllDetailPanels();
	}
	
	if (FALSE == list->getCanSelect())
	{
		return;
	}

	std::string id_str = self->childGetValue("results").asString();
	if (id_str.empty())
	{
		return;
	}

	LLSD item_id = list->getCurrentID();
	S32 type = self->mResultsContents[id_str]["type"];
	if (type == EVENT_CODE)
	{
		// all but events use the UUID above
		item_id = self->mResultsContents[id_str]["event_id"];
	}

	//std::string name = self->mResultsContents[id_str]["name"].asString();
	self->showDetailPanel(type, item_id);
}

void LLPanelDirBrowser::showDetailPanel(S32 type, LLSD id)
{
	switch(type)
	{
	case AVATAR_CODE:
		if (mFloaterDirectory && mFloaterDirectory->mPanelAvatarp)
		{
			mFloaterDirectory->mPanelAvatarp->setVisible(TRUE);
			mFloaterDirectory->mPanelAvatarp->setAvatarID(id.asUUID(), LLStringUtil::null, ONLINE_STATUS_NO);
		}
		break;
	case EVENT_CODE:
		{
			U32 event_id = (U32)id.asInteger();
			showEvent(event_id);
		}
		break;
	case GROUP_CODE:
		if (mFloaterDirectory && mFloaterDirectory->mPanelGroupHolderp)
		{
			mFloaterDirectory->mPanelGroupHolderp->setVisible(TRUE);
		}
		if (mFloaterDirectory && mFloaterDirectory->mPanelGroupp)
		{
			mFloaterDirectory->mPanelGroupp->setVisible(TRUE);
			mFloaterDirectory->mPanelGroupp->setGroupID(id.asUUID());
		}
		break;
	case CLASSIFIED_CODE:
		if (mFloaterDirectory && mFloaterDirectory->mPanelClassifiedp)
		{
			mFloaterDirectory->mPanelClassifiedp->setVisible(TRUE);
			mFloaterDirectory->mPanelClassifiedp->setClassifiedID(id.asUUID());
			mFloaterDirectory->mPanelClassifiedp->sendClassifiedInfoRequest();
		}
		break;
	case FOR_SALE_CODE:
	case AUCTION_CODE:
		if (mFloaterDirectory && mFloaterDirectory->mPanelPlaceSmallp)
		{
			mFloaterDirectory->mPanelPlaceSmallp->setVisible(TRUE);
			mFloaterDirectory->mPanelPlaceSmallp->resetLocation();
			mFloaterDirectory->mPanelPlaceSmallp->setParcelID(id.asUUID());
		}
		break;
	case PLACE_CODE:
	case POPULAR_CODE:
		if (mFloaterDirectory && mFloaterDirectory->mPanelPlacep)
		{
			mFloaterDirectory->mPanelPlacep->setVisible(TRUE);
			mFloaterDirectory->mPanelPlacep->resetLocation();
			mFloaterDirectory->mPanelPlacep->setParcelID(id.asUUID());
		}
		break;
	default:
		{
			llwarns << "Unknown event type!" << llendl;
		}
		break;
	}
}


void LLPanelDirBrowser::showEvent(const U32 event_id)
{
	// Start with everyone invisible
	if (mFloaterDirectory)
	{
		mFloaterDirectory->hideAllDetailPanels();
		if (mFloaterDirectory->mPanelEventp)
		{
			mFloaterDirectory->mPanelEventp->setVisible(TRUE);
			mFloaterDirectory->mPanelEventp->setEventID(event_id);
		}
	}
}

void LLPanelDirBrowser::processDirPeopleReply(LLMessageSystem *msg, void**)
{
	LLUUID query_id;
	std::string   first_name;
	std::string   last_name;
	LLUUID agent_id;

	msg->getUUIDFast(_PREHASH_QueryData,_PREHASH_QueryID, query_id);

	LLPanelDirBrowser* self;
	self = gDirBrowserInstances.getIfThere(query_id);
	if (!self) 
	{
		// data from an old query
		return;
	}

	self->mHaveSearchResults = TRUE;

	LLCtrlListInterface *list = self->childGetListInterface("results");
	if (!list) return;

	if (!list->getCanSelect())
	{
		list->operateOnAll(LLCtrlListInterface::OP_DELETE);
		self->mResultsContents = LLSD();
	}

	S32 rows = msg->getNumberOfBlocksFast(_PREHASH_QueryReplies);
	self->mResultsReceived += rows;

	rows = self->showNextButton(rows);

	for (S32 i = 0; i < rows; i++)
	{			
		msg->getStringFast(_PREHASH_QueryReplies,_PREHASH_FirstName, first_name, i);
		msg->getStringFast(_PREHASH_QueryReplies,_PREHASH_LastName,	last_name, i);
		msg->getUUIDFast(  _PREHASH_QueryReplies,_PREHASH_AgentID, agent_id, i);
		// msg->getU8Fast(    _PREHASH_QueryReplies,_PREHASH_Online, online, i);
		// unused
		// msg->getStringFast(_PREHASH_QueryReplies,_PREHASH_Group, group, i);
		// msg->getS32Fast(   _PREHASH_QueryReplies,_PREHASH_Reputation, reputation, i);

		if (agent_id.isNull())
		{
			continue;
		}

		LLSD content;

		LLSD row;
		row["id"] = agent_id;

		// We don't show online status in the finder anymore,
		// so just use the 'offline' icon as the generic 'person' icon
		row["columns"][0]["column"] = "icon";
		row["columns"][0]["type"] = "icon";
		row["columns"][0]["value"] = "icon_avatar_offline.tga";

		content["type"] = AVATAR_CODE;

		std::string fullname = first_name + " " + last_name;
		row["columns"][1]["column"] = "name";
		row["columns"][1]["value"] = fullname;
		row["columns"][1]["font"] = "SANSSERIF";

		content["name"] = fullname;

		list->addElement(row);
		self->mResultsContents[agent_id.asString()] = content;
	}

	list->sortByColumn(self->mCurrentSortColumn, self->mCurrentSortAscending);
	self->updateResultCount();

	// Poke the result received timer
	self->mLastResultTimer.reset();
	self->mDidAutoSelect = FALSE;
}


void LLPanelDirBrowser::processDirPlacesReply(LLMessageSystem* msg, void**)
{
	LLUUID	agent_id;
	LLUUID	query_id;
	LLUUID	parcel_id;
	std::string	name;
	BOOL	is_for_sale;
	BOOL	is_auction;
	F32		dwell;

	msg->getUUID("AgentData", "AgentID", agent_id);
	msg->getUUID("QueryData", "QueryID", query_id );

	LLPanelDirBrowser* self;
	self = gDirBrowserInstances.getIfThere(query_id);
	if (!self) 
	{
		// data from an old query
		return;
	}

	self->mHaveSearchResults = TRUE;

	LLCtrlListInterface *list = self->childGetListInterface("results");
	if (!list) return;

	if (!list->getCanSelect())
	{
		list->operateOnAll(LLCtrlListInterface::OP_DELETE);
		self->mResultsContents = LLSD();
	}

	S32 count = msg->getNumberOfBlocks("QueryReplies");
	self->mResultsReceived += count;

	count = self->showNextButton(count);

	for (S32 i = 0; i < count ; i++)
	{
		msg->getUUID("QueryReplies", "ParcelID", parcel_id, i);
		msg->getString("QueryReplies", "Name", name, i);
		msg->getBOOL("QueryReplies", "ForSale", is_for_sale, i);
		msg->getBOOL("QueryReplies", "Auction", is_auction, i);
		msg->getF32("QueryReplies", "Dwell", dwell, i);
		
		if (parcel_id.isNull())
		{
			continue;
		}

		LLSD content;
		S32 type;

		LLSD row = self->createLandSale(parcel_id, is_auction, is_for_sale, name, &type);

		content["type"] = type;
		content["name"] = name;

		std::string buffer = llformat("%.0f", (F64)dwell);
		row["columns"][3]["column"] = "dwell";
		row["columns"][3]["value"] = buffer;
		row["columns"][3]["font"] = "SANSSERIFSMALL";

		list->addElement(row);
		self->mResultsContents[parcel_id.asString()] = content;
	}

	list->sortByColumn(self->mCurrentSortColumn, self->mCurrentSortAscending);
	self->updateResultCount();

	// Poke the result received timer
	self->mLastResultTimer.reset();
	self->mDidAutoSelect = FALSE;
}


void LLPanelDirBrowser::processDirEventsReply(LLMessageSystem* msg, void**)
{
	LLUUID	agent_id;
	LLUUID	query_id;
	LLUUID	owner_id;
	std::string	name;
	std::string	date;
	BOOL	show_mature = gSavedSettings.getBOOL("ShowMatureEvents");

	msg->getUUID("AgentData", "AgentID", agent_id);
	msg->getUUID("QueryData", "QueryID", query_id );

	LLPanelDirBrowser* self;
	self = gDirBrowserInstances.getIfThere(query_id);
	if (!self)
	{
		return;
	}

	self->mHaveSearchResults = TRUE;

	LLCtrlListInterface *list = self->childGetListInterface("results");
	if (!list) return;

	if (!list->getCanSelect())
	{
		list->operateOnAll(LLCtrlListInterface::OP_DELETE);
		self->mResultsContents = LLSD();
	}

	S32 rows = msg->getNumberOfBlocks("QueryReplies");
	self->mResultsReceived += rows;

	rows = self->showNextButton(rows);

	for (S32 i = 0; i < rows; i++)
	{
		U32 event_id;
		U32 unix_time;
		U32 event_flags;

		msg->getUUID("QueryReplies", "OwnerID", owner_id, i);
		msg->getString("QueryReplies", "Name", name, i);
		msg->getU32("QueryReplies", "EventID", event_id, i);
		msg->getString("QueryReplies", "Date", date, i);
		msg->getU32("QueryReplies", "UnixTime", unix_time, i);
		msg->getU32("QueryReplies", "EventFlags", event_flags, i);
	
		// Skip empty events
		if (owner_id.isNull())
		{
			//RN: should this check event_id instead?
			llwarns << "skipped event due to owner_id null, event_id " << event_id << llendl;
			continue;
		}
		// Skip mature events if not showing
		if (!show_mature
			&& (event_flags & EVENT_FLAG_MATURE))
		{
			llwarns << "Skipped due to maturity, event_id " << event_id << llendl;
			continue;
		}

		LLSD content;

		content["type"] = EVENT_CODE;
		content["name"] = name;
		content["event_id"] = (S32)event_id;

		LLSD row;
		row["id"] = llformat("%u", event_id);

		// Column 0 - event icon
		LLUUID image_id;
		if (event_flags & EVENT_FLAG_MATURE)
		{
			row["columns"][0]["column"] = "icon";
			row["columns"][0]["type"] = "icon";
			row["columns"][0]["value"] = "icon_event_mature.tga";
		}
		else
		{
			row["columns"][0]["column"] = "icon";
			row["columns"][0]["type"] = "icon";
			row["columns"][0]["value"] = "icon_event.tga";
		}

		row["columns"][1]["column"] = "name";
		row["columns"][1]["value"] = name;
		row["columns"][1]["font"] = "SANSSERIF";

		row["columns"][2]["column"] = "date";
		row["columns"][2]["value"] = date;
		row["columns"][2]["font"] = "SANSSERIFSMALL";

		row["columns"][3]["column"] = "time";
		row["columns"][3]["value"] = llformat("%u", unix_time);
		row["columns"][3]["font"] = "SANSSERIFSMALL";

		list->addElement(row, ADD_SORTED);

		std::string id_str = llformat("%u", event_id);
		self->mResultsContents[id_str] = content;
	}

	list->sortByColumn(self->mCurrentSortColumn, self->mCurrentSortAscending);
	self->updateResultCount();

	// Poke the result received timer
	self->mLastResultTimer.reset();
	self->mDidAutoSelect = FALSE;
}


// static
void LLPanelDirBrowser::processDirGroupsReply(LLMessageSystem* msg, void**)
{
	S32		i;
	
	LLUUID	query_id;
	LLUUID	group_id;
	std::string	group_name;
	S32     members;
	F32     search_order;

	msg->getUUIDFast(_PREHASH_QueryData,_PREHASH_QueryID, query_id );

	LLPanelDirBrowser* self;
	self = gDirBrowserInstances.getIfThere(query_id);
	if (!self)
	{
		return;
	}

	self->mHaveSearchResults = TRUE;

	LLCtrlListInterface *list = self->childGetListInterface("results");
	if (!list) return;

	if (!list->getCanSelect())
	{
		list->operateOnAll(LLCtrlListInterface::OP_DELETE);
		self->mResultsContents = LLSD();
	}

	S32 rows = msg->getNumberOfBlocksFast(_PREHASH_QueryReplies);
	self->mResultsReceived += rows;

	rows = self->showNextButton(rows);

	for (i = 0; i < rows; i++)
	{
		msg->getUUIDFast(_PREHASH_QueryReplies, _PREHASH_GroupID,		group_id, i );
		msg->getStringFast(_PREHASH_QueryReplies, _PREHASH_GroupName,	group_name,		i);
		msg->getS32Fast(_PREHASH_QueryReplies, _PREHASH_Members,		members, i );
		msg->getF32Fast(_PREHASH_QueryReplies, _PREHASH_SearchOrder,	search_order, i );
		
		if (group_id.isNull())
		{
			continue;
		}

		LLSD content;
		content["type"] = GROUP_CODE;
		content["name"] = group_name;

		LLSD row;
		row["id"] = group_id;

		LLUUID image_id;
		row["columns"][0]["column"] = "icon";
		row["columns"][0]["type"] = "icon";
		row["columns"][0]["value"] = "icon_group.tga";

		row["columns"][1]["column"] = "name";
		row["columns"][1]["value"] = group_name;
		row["columns"][1]["font"] = "SANSSERIF";

		row["columns"][2]["column"] = "members";
		row["columns"][2]["value"] = members;
		row["columns"][2]["font"] = "SANSSERIFSMALL";

		row["columns"][3]["column"] = "score";
		row["columns"][3]["value"] = search_order;

		list->addElement(row);
		self->mResultsContents[group_id.asString()] = content;
	}
	list->sortByColumn(self->mCurrentSortColumn, self->mCurrentSortAscending);
	self->updateResultCount();

	// Poke the result received timer
	self->mLastResultTimer.reset();
	self->mDidAutoSelect = FALSE;
}


// static
void LLPanelDirBrowser::processDirClassifiedReply(LLMessageSystem* msg, void**)
{
	S32		i;
	S32		num_new_rows;

	LLUUID	agent_id;
	LLUUID	query_id;

	msg->getUUID("AgentData", "AgentID", agent_id);
	if (agent_id != gAgent.getID())
	{
		llwarns << "Message for wrong agent " << agent_id
			<< " in processDirClassifiedReply" << llendl;
		return;
	}

	msg->getUUID("QueryData", "QueryID", query_id);
	LLPanelDirBrowser* self = gDirBrowserInstances.getIfThere(query_id);
	if (!self)
	{
		return;
	}

	self->mHaveSearchResults = TRUE;

	LLCtrlListInterface *list = self->childGetListInterface("results");
	if (!list) return;

	if (!list->getCanSelect())
	{
		list->operateOnAll(LLCtrlListInterface::OP_DELETE);
		self->mResultsContents = LLSD();
	}

	num_new_rows = msg->getNumberOfBlocksFast(_PREHASH_QueryReplies);
	self->mResultsReceived += num_new_rows;

	num_new_rows = self->showNextButton(num_new_rows);
	for (i = 0; i < num_new_rows; i++)
	{
		LLUUID classified_id;
		std::string name;
		U32 creation_date = 0;	// unix timestamp
		U32 expiration_date = 0;	// future use
		S32 price_for_listing = 0;
		msg->getUUID("QueryReplies", "ClassifiedID", classified_id, i);
		msg->getString("QueryReplies", "Name", name, i);
		msg->getU32("QueryReplies","CreationDate",creation_date,i);
		msg->getU32("QueryReplies","ExpirationDate",expiration_date,i);
		msg->getS32("QueryReplies","PriceForListing",price_for_listing,i);

		if ( classified_id.notNull() )
		{
			self->addClassified(list, classified_id, name, creation_date, price_for_listing);

			LLSD content;
			content["type"] = CLASSIFIED_CODE;
			content["name"] = name;
			self->mResultsContents[classified_id.asString()] = content;
		}
	}
	// The server does the initial sort, by price paid per listing and date. JC
	self->updateResultCount();

	// Poke the result received timer
	self->mLastResultTimer.reset();
	self->mDidAutoSelect = FALSE;
}

void LLPanelDirBrowser::processDirLandReply(LLMessageSystem *msg, void**)
{
	LLUUID	agent_id;
	LLUUID	query_id;
	LLUUID	parcel_id;
	std::string	name;
	BOOL	auction;
	BOOL	for_sale;
	S32		sale_price;
	S32		actual_area;

	msg->getUUID("AgentData", "AgentID", agent_id);
	msg->getUUID("QueryData", "QueryID", query_id );

	LLPanelDirBrowser* browser;
	browser = gDirBrowserInstances.getIfThere(query_id);
	if (!browser) 
	{
		// data from an old query
		return;
	}

	// Only handled by LLPanelDirLand
	LLPanelDirLand* self = (LLPanelDirLand*)browser;

	self->mHaveSearchResults = TRUE;

	LLCtrlListInterface *list = self->childGetListInterface("results");
	if (!list) return;

	if (!list->getCanSelect())
	{
		list->operateOnAll(LLCtrlListInterface::OP_DELETE);
		self->mResultsContents = LLSD();
	}

	BOOL use_price = gSavedSettings.getBOOL("FindLandPrice");
	S32 limit_price = self->childGetValue("priceedit").asInteger();

	BOOL use_area = gSavedSettings.getBOOL("FindLandArea");
	S32 limit_area = self->childGetValue("areaedit").asInteger();

	S32 i;
	S32 count = msg->getNumberOfBlocks("QueryReplies");
	self->mResultsReceived += count;
	
	S32 non_auction_count = 0;
	for (i = 0; i < count; i++)
	{
		msg->getUUID(	"QueryReplies", "ParcelID", parcel_id, i);
		msg->getString(	"QueryReplies", "Name", name, i);
		msg->getBOOL(	"QueryReplies", "Auction", auction, i);
		msg->getBOOL(	"QueryReplies", "ForSale", for_sale, i);
		msg->getS32(	"QueryReplies", "SalePrice", sale_price, i);
		msg->getS32(	"QueryReplies", "ActualArea", actual_area, i);
		
		if (parcel_id.isNull()) continue;

		if (use_price && (sale_price > limit_price)) continue;

		if (use_area && (actual_area < limit_area)) continue;

		LLSD content;
		S32 type;

		LLSD row = self->createLandSale(parcel_id, auction, for_sale,  name, &type);

		content["type"] = type;
		content["name"] = name;

		std::string buffer = "Auction";
		if (!auction)
		{
			buffer = llformat("%d", sale_price);
			non_auction_count++;
		}
		row["columns"][3]["column"] = "price";
		row["columns"][3]["value"] = buffer;
		row["columns"][3]["font"] = "SANSSERIFSMALL";

		buffer = llformat("%d", actual_area);
		row["columns"][4]["column"] = "area";
		row["columns"][4]["value"] = buffer;
		row["columns"][4]["font"] = "SANSSERIFSMALL";

		if (!auction)
		{
			F32 price_per_meter;
			if (actual_area > 0)
			{
				price_per_meter = (F32)sale_price / (F32)actual_area;
			}
			else
			{
				price_per_meter = 0.f;
			}
			// Prices are usually L$1 - L$10 / meter
			buffer = llformat("%.1f", price_per_meter);
			row["columns"][5]["column"] = "per_meter";
			row["columns"][5]["value"] = buffer;
			row["columns"][5]["font"] = "SANSSERIFSMALL";
		}
		else
		{
			// Auctions start at L$1 per meter
			row["columns"][5]["column"] = "per_meter";
			row["columns"][5]["value"] = "1.0";
			row["columns"][5]["font"] = "SANSSERIFSMALL";
		}

		list->addElement(row);
		self->mResultsContents[parcel_id.asString()] = content;
	}

	// All auction results are shown on the first page
	// But they don't count towards the 100 / page limit
	// So figure out the next button here, when we know how many aren't auctions
	count = self->showNextButton(non_auction_count);

	self->updateResultCount();

	// Poke the result received timer
	self->mLastResultTimer.reset();
	self->mDidAutoSelect = FALSE;
}

void LLPanelDirBrowser::addClassified(LLCtrlListInterface *list, const LLUUID& pick_id, const std::string& name, const U32 creation_date, const S32 price_for_listing)
{
	std::string type = llformat("%d", CLASSIFIED_CODE);

	LLSD row;
	row["id"] = pick_id;

	row["columns"][0]["column"] = "icon";
	row["columns"][0]["type"] = "icon";
	row["columns"][0]["value"] = "icon_top_pick.tga";

	row["columns"][1]["column"] = "name";
	row["columns"][1]["value"] = name;
	row["columns"][1]["font"] = "SANSSERIF";

	row["columns"][2]["column"] = "price";
	row["columns"][2]["value"] = price_for_listing;
	row["columns"][2]["font"] = "SANSSERIFSMALL";

	list->addElement(row);
}

LLSD LLPanelDirBrowser::createLandSale(const LLUUID& parcel_id, BOOL is_auction, BOOL is_for_sale,  const std::string& name, S32 *type)
{
	LLSD row;
	row["id"] = parcel_id;
	LLUUID image_id;

	// Icon and type
	if(is_auction)
	{
		row["columns"][0]["column"] = "icon";
		row["columns"][0]["type"] = "icon";
		row["columns"][0]["value"] = "icon_auction.tga";

		*type = AUCTION_CODE;
	}
	else if (is_for_sale)
	{
		row["columns"][0]["column"] = "icon";
		row["columns"][0]["type"] = "icon";
		row["columns"][0]["value"] = "icon_for_sale.tga";

		*type = FOR_SALE_CODE;
	}
	else
	{
		row["columns"][0]["column"] = "icon";
		row["columns"][0]["type"] = "icon";
		row["columns"][0]["value"] = "icon_place.tga";

		*type = PLACE_CODE;
	}

	row["columns"][2]["column"] = "name";
	row["columns"][2]["value"] = name;
	row["columns"][2]["font"] = "SANSSERIF";

	return row;
}

void LLPanelDirBrowser::newClassified()
{
	LLCtrlListInterface *list = childGetListInterface("results");
	if (!list) return;

	if (mFloaterDirectory->mPanelClassifiedp)
	{
		// Clear the panel on the right
		mFloaterDirectory->mPanelClassifiedp->reset();

		// Set up the classified with the info we've created
		// and a sane default position.
		mFloaterDirectory->mPanelClassifiedp->initNewClassified();

		// We need the ID to select in the list.
		LLUUID classified_id = mFloaterDirectory->mPanelClassifiedp->getClassifiedID();

		// Put it in the list on the left
		addClassified(list, classified_id, mFloaterDirectory->mPanelClassifiedp->getClassifiedName(),0,0);

		// Select it.
		list->setCurrentByID(classified_id);

		// Make the right panel visible (should already be)
		mFloaterDirectory->mPanelClassifiedp->setVisible(TRUE);
	}
}

void LLPanelDirBrowser::setupNewSearch()
{
	LLScrollListCtrl* list = getChild<LLScrollListCtrl>("results");

	gDirBrowserInstances.removeData(mSearchID);
	// Make a new query ID
	mSearchID.generate();

	gDirBrowserInstances.addData(mSearchID, this);

	// ready the list for results
	list->operateOnAll(LLCtrlListInterface::OP_DELETE);
	list->addCommentText(std::string("Searching...")); // *TODO: Translate
	childDisable("results");

	mResultsReceived = 0;
	mHaveSearchResults = FALSE;

	// Set all panels to be invisible
	mFloaterDirectory->hideAllDetailPanels();

	updateResultCount();
}


// static
// called from calssifieds, events, groups, land, people, and places
void LLPanelDirBrowser::onClickSearchCore(void* userdata)
{
	LLPanelDirBrowser* self = (LLPanelDirBrowser*)userdata;
	if (!self) return;

	self->resetSearchStart();
	self->performQuery();

	LLFloaterDirectory::sOldSearchCount++;
}


// static
void LLPanelDirBrowser::sendDirFindQuery(
	LLMessageSystem* msg,
	const LLUUID& query_id,
	const std::string& text,
	U32 flags,
	S32 query_start)
{
	msg->newMessage("DirFindQuery");
	msg->nextBlock("AgentData");
	msg->addUUID("AgentID", gAgent.getID());
	msg->addUUID("SessionID", gAgent.getSessionID());
	msg->nextBlock("QueryData");
	msg->addUUID("QueryID", query_id);
	msg->addString("QueryText", text);
	msg->addU32("QueryFlags", flags);
	msg->addS32("QueryStart", query_start);
	gAgent.sendReliableMessage();
}


void LLPanelDirBrowser::onKeystrokeName(LLLineEditor* line, void* data)
{
	LLPanelDirBrowser *self = (LLPanelDirBrowser*)data;
	if (line->getLength() >= (S32)self->mMinSearchChars)
	{
		self->setDefaultBtn( "Search" );
		self->childEnable("Search");
	}
	else
	{
		self->setDefaultBtn();
		self->childDisable("Search");
	}
}

// setup results when shown
void LLPanelDirBrowser::onVisibilityChange(BOOL new_visibility)
{
	if (new_visibility)
	{
		onCommitList(NULL, this);
	}
	LLPanel::onVisibilityChange(new_visibility);
}

S32 LLPanelDirBrowser::showNextButton(S32 rows)
{
	// HACK: This hack doesn't work for llpaneldirfind (ALL) 
	// because other data is being returned as well.
	if ( getName() != "find_all_old_panel")
	{
		// HACK: The (mResultsPerPage)+1th entry indicates there are 'more'
		bool show_next = (mResultsReceived > mResultsPerPage);
		childSetVisible("Next >", show_next);
		if (show_next)
		{
			rows -= (mResultsReceived - mResultsPerPage);
		}
	}
	else
	{
		// Hide page buttons
		childHide("Next >");
		childHide("< Prev");
	}
	return rows;
}