llpaneldirclassified.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * @file llpaneldirclassified.cpp
  3. * @brief Classified panel in the Search floater.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llpaneldirclassified.h"
  34. #include "llcheckboxctrl.h"
  35. #include "llclassifiedflags.h"
  36. #include "lllineeditor.h"
  37. #include "llqueryflags.h"
  38. #include "lluictrlfactory.h"
  39. #include "llmessage.h"
  40. #include "llagent.h"
  41. #include "llfloateravatarinfo.h"
  42. #include "hbfloatersearch.h"
  43. #include "llpaneldirbrowser.h"
  44. LLPanelDirClassified::LLPanelDirClassified(const std::string& name,
  45. HBFloaterSearch* floater)
  46. : LLPanelDirBrowser(name, floater)
  47. {
  48. }
  49. bool LLPanelDirClassified::postBuild()
  50. {
  51. LLPanelDirBrowser::postBuild();
  52. // 0 or 3+ character searches allowed, exciting
  53. mSearchEditor = getChild<LLSearchEditor>("search_text");
  54. mSearchEditor->setSearchCallback(onSearchEditClassified, this);
  55. childSetAction("search_btn", onClickSearchCore, this);
  56. childSetAction("browse_btn", onClickSearchCore, this);
  57. setDefaultBtn("browse_btn");
  58. childSetAction("Place an Ad...", onClickCreateNewClassified, this);
  59. mDeleteButton = getChild<LLButton>("Delete");
  60. mDeleteButton->setClickedCallback(onClickDelete, this);
  61. mDeleteButton->setEnabled(false);
  62. mDeleteButton->setVisible(false);
  63. #if 0 // Do not do this every time we open find, it is expensive; require
  64. // clicking 'search'
  65. requestClassified();
  66. #endif
  67. return true;
  68. }
  69. void LLPanelDirClassified::draw()
  70. {
  71. refresh();
  72. LLPanelDirBrowser::draw();
  73. }
  74. void LLPanelDirClassified::refresh()
  75. {
  76. bool godlike = gAgent.isGodlike();
  77. mDeleteButton->setEnabled(godlike);
  78. mDeleteButton->setVisible(godlike);
  79. updateMaturityCheckbox();
  80. }
  81. // Open Profile to Classifieds tab
  82. void LLPanelDirClassified::onClickCreateNewClassified(void* userdata)
  83. {
  84. LLFloaterAvatarInfo::showFromObject(gAgentID, "Classified");
  85. }
  86. //static
  87. void LLPanelDirClassified::onClickDelete(void* userdata)
  88. {
  89. LLPanelDirClassified* self = (LLPanelDirClassified*)userdata;
  90. LLUUID classified_id;
  91. S32 type;
  92. self->getSelectedInfo(&classified_id, &type);
  93. // Clear out the list. Deleting a classified will cause a refresh to be
  94. // sent.
  95. self->setupNewSearch();
  96. LLMessageSystem* msg = gMessageSystemp;
  97. msg->newMessageFast(_PREHASH_ClassifiedGodDelete);
  98. msg->nextBlockFast(_PREHASH_AgentData);
  99. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  100. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  101. msg->nextBlockFast(_PREHASH_Data);
  102. msg->addUUIDFast(_PREHASH_ClassifiedID, classified_id);
  103. msg->addUUIDFast(_PREHASH_QueryID, self->mSearchID);
  104. gAgent.sendReliableMessage();
  105. }
  106. void LLPanelDirClassified::performQuery()
  107. {
  108. bool inc_pg = !mIncPGCheck || mIncPGCheck->getValue().asBoolean();
  109. bool inc_mature = mIncMatureCheck && mIncMatureCheck->getValue().asBoolean();
  110. bool inc_adult = mIncAdultCheck && mIncAdultCheck->getValue().asBoolean();
  111. if (!(inc_pg || inc_mature || inc_adult))
  112. {
  113. gNotifications.add("NoContentToSearch");
  114. return;
  115. }
  116. // This sets mSearchID and clears the list of results
  117. setupNewSearch();
  118. // send the message
  119. LLMessageSystem* msg = gMessageSystemp;
  120. msg->newMessageFast(_PREHASH_DirClassifiedQuery);
  121. msg->nextBlockFast(_PREHASH_AgentData);
  122. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  123. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  124. bool filter_auto_renew = false;
  125. U32 query_flags = pack_classified_flags_request(filter_auto_renew,
  126. inc_pg, inc_mature,
  127. inc_adult);
  128. #if 0
  129. if (gAgent.isTeen()) query_flags |= DFQ_PG_SIMS_ONLY;
  130. #endif
  131. U32 category = childGetValue("Category").asInteger();
  132. msg->nextBlockFast(_PREHASH_QueryData);
  133. msg->addUUIDFast(_PREHASH_QueryID, mSearchID);
  134. msg->addStringFast(_PREHASH_QueryText, mSearchEditor->getText());
  135. msg->addU32Fast(_PREHASH_QueryFlags, query_flags);
  136. msg->addU32Fast(_PREHASH_Category, category);
  137. msg->addS32Fast(_PREHASH_QueryStart, mSearchStart);
  138. gAgent.sendReliableMessage();
  139. }
  140. void LLPanelDirClassified::onSearchEditClassified(const std::string& text,
  141. void* data)
  142. {
  143. LLPanelDirClassified* self = (LLPanelDirClassified*)data;
  144. if (!self) return;
  145. S32 len = text.length();
  146. if (len == 0 || len >= 3)
  147. {
  148. // Ho text searches are cheap, as are longer searches
  149. self->setDefaultBtn("search_btn");
  150. self->childEnable("search_btn");
  151. }
  152. else
  153. {
  154. self->setDefaultBtn();
  155. self->childDisable("search_btn");
  156. }
  157. // Change the Browse to Search or vice versa
  158. if (len > 0)
  159. {
  160. self->childSetVisible("search_btn", true);
  161. self->childSetVisible("browse_btn", false);
  162. }
  163. else
  164. {
  165. self->setDefaultBtn("browse_btn");
  166. self->childSetVisible("search_btn", false);
  167. self->childSetVisible("browse_btn", true);
  168. }
  169. }