llinventoryfilter.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:23k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2. * @file llinventoryfilter.cpp
  3. * @brief Support for filtering your inventory to only display a subset of the
  4. * available items.
  5. *
  6. * $LicenseInfo:firstyear=2005&license=viewergpl$
  7. * Copyright (c) 2005-2010, Linden Research, Inc.
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab.  Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. * There are special exceptions to the terms and conditions of the GPL as
  16. * it is applied to this Source Code. View the full text of the exception
  17. * in the file doc/FLOSS-exception.txt in this software distribution, or
  18. * online at
  19. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  20. * By copying, modifying or distributing this software, you acknowledge
  21. * that you have read and understood your obligations described above,
  22. * and agree to abide by those obligations.
  23. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  24. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  25. * COMPLETENESS OR PERFORMANCE.
  26. * $/LicenseInfo$
  27. */
  28. #include "llviewerprecompiledheaders.h"
  29. #include "llinventoryfilter.h"
  30. // viewer includes
  31. #include "llfoldervieweventlistener.h"
  32. #include "llfolderviewitem.h"
  33. #include "llinventorymodel.h" // gInventory.backgroundFetchActive()
  34. #include "llviewercontrol.h"
  35. #include "llfolderview.h"
  36. // linden library includes
  37. #include "lltrans.h"
  38. LLInventoryFilter::FilterOps::FilterOps() :
  39. mFilterObjectTypes(0xffffffffffffffffULL),
  40. mFilterCategoryTypes(0xffffffffffffffffULL),
  41. mMinDate(time_min()),
  42. mMaxDate(time_max()),
  43. mHoursAgo(0),
  44. mShowFolderState(SHOW_NON_EMPTY_FOLDERS),
  45. mPermissions(PERM_NONE),
  46. mFilterTypes(FILTERTYPE_OBJECT),
  47. mFilterUUID(LLUUID::null)
  48. {
  49. }
  50. ///----------------------------------------------------------------------------
  51. /// Class LLInventoryFilter
  52. ///----------------------------------------------------------------------------
  53. LLInventoryFilter::LLInventoryFilter(const std::string& name)
  54. : mName(name),
  55. mModified(FALSE),
  56. mNeedTextRebuild(TRUE),
  57. mEmptyLookupMessage("InventoryNoMatchingItems")
  58. {
  59. mOrder = SO_FOLDERS_BY_NAME; // This gets overridden by a pref immediately
  60. mSubStringMatchOffset = 0;
  61. mFilterSubString.clear();
  62. mFilterGeneration = 0;
  63. mMustPassGeneration = S32_MAX;
  64. mMinRequiredGeneration = 0;
  65. mFilterCount = 0;
  66. mNextFilterGeneration = mFilterGeneration + 1;
  67. mLastLogoff = gSavedPerAccountSettings.getU32("LastLogoff");
  68. mFilterBehavior = FILTER_NONE;
  69. // copy mFilterOps into mDefaultFilterOps
  70. markDefault();
  71. }
  72. LLInventoryFilter::~LLInventoryFilter()
  73. {
  74. }
  75. BOOL LLInventoryFilter::check(const LLFolderViewItem* item) 
  76. {
  77. // If it's a folder and we're showing all folders, return TRUE automatically.
  78. const BOOL is_folder = (dynamic_cast<const LLFolderViewFolder*>(item) != NULL);
  79. if (is_folder && (mFilterOps.mShowFolderState == LLInventoryFilter::SHOW_ALL_FOLDERS))
  80. {
  81. return TRUE;
  82. }
  83. const LLFolderViewEventListener* listener = item->getListener();
  84. mSubStringMatchOffset = mFilterSubString.size() ? item->getSearchableLabel().find(mFilterSubString) : std::string::npos;
  85. const BOOL passed_filtertype = checkAgainstFilterType(item);
  86. const BOOL passed = passed_filtertype &&
  87. (mFilterSubString.size() == 0 || mSubStringMatchOffset != std::string::npos) &&
  88. ((listener->getPermissionMask() & mFilterOps.mPermissions) == mFilterOps.mPermissions);
  89. return passed;
  90. }
  91. BOOL LLInventoryFilter::checkAgainstFilterType(const LLFolderViewItem* item)
  92. {
  93. const LLFolderViewEventListener* listener = item->getListener();
  94. if (!listener) return FALSE;
  95. const LLInventoryType::EType object_type = listener->getInventoryType();
  96. const LLUUID object_id = listener->getUUID();
  97. const LLInventoryObject *object = gInventory.getObject(object_id);
  98. const U32 filterTypes = mFilterOps.mFilterTypes;
  99. ////////////////////////////////////////////////////////////////////////////////
  100. // FILTERTYPE_OBJECT
  101. // Pass if this item's type is of the correct filter type
  102. if (filterTypes & FILTERTYPE_OBJECT)
  103. {
  104. // If it has no type, pass it, unless it's a link.
  105. if (object_type == LLInventoryType::IT_NONE)
  106. {
  107. if (object && object->getIsLinkType())
  108. return FALSE;
  109. }
  110. else if ((1LL << object_type & mFilterOps.mFilterObjectTypes) == U64(0))
  111. {
  112. return FALSE;
  113. }
  114. }
  115. //
  116. ////////////////////////////////////////////////////////////////////////////////
  117. ////////////////////////////////////////////////////////////////////////////////
  118. // FILTERTYPE_CATEGORY
  119. // Pass if this item is a category of the filter type, or
  120. // if its parent is a category of the filter type.
  121. if (filterTypes & FILTERTYPE_CATEGORY)
  122. {
  123. // Can only filter categories for items in your inventory 
  124. // (e.g. versus in-world object contents).
  125. if (!object) return FALSE;
  126. LLUUID cat_id = object_id;
  127. if (listener->getInventoryType() != LLInventoryType::IT_CATEGORY)
  128. {
  129. cat_id = object->getParentUUID();
  130. }
  131. const LLViewerInventoryCategory *cat = gInventory.getCategory(cat_id);
  132. if (!cat) 
  133. return FALSE;
  134. if ((1LL << cat->getPreferredType() & mFilterOps.mFilterCategoryTypes) == U64(0))
  135. return FALSE;
  136. }
  137. //
  138. ////////////////////////////////////////////////////////////////////////////////
  139. ////////////////////////////////////////////////////////////////////////////////
  140. // FILTERTYPE_UUID
  141. // Pass if this item is the target UUID or if it links to the target UUID
  142. if (filterTypes & FILTERTYPE_UUID)
  143. {
  144. if (!object) return FALSE;
  145. if (object->getLinkedUUID() != mFilterOps.mFilterUUID)
  146. return FALSE;
  147. }
  148. //
  149. ////////////////////////////////////////////////////////////////////////////////
  150. ////////////////////////////////////////////////////////////////////////////////
  151. // FILTERTYPE_DATE
  152. // Pass if this item is within the date range.
  153. if (filterTypes & FILTERTYPE_DATE)
  154. {
  155. const U16 HOURS_TO_SECONDS = 3600;
  156. time_t earliest = time_corrected() - mFilterOps.mHoursAgo * HOURS_TO_SECONDS;
  157. if (mFilterOps.mMinDate > time_min() && mFilterOps.mMinDate < earliest)
  158. {
  159. earliest = mFilterOps.mMinDate;
  160. }
  161. else if (!mFilterOps.mHoursAgo)
  162. {
  163. earliest = 0;
  164. }
  165. if (listener->getCreationDate() < earliest ||
  166. listener->getCreationDate() > mFilterOps.mMaxDate)
  167. return FALSE;
  168. }
  169. //
  170. ////////////////////////////////////////////////////////////////////////////////
  171. return TRUE;
  172. }
  173. const std::string& LLInventoryFilter::getFilterSubString(BOOL trim) const
  174. {
  175. return mFilterSubString;
  176. }
  177. std::string::size_type LLInventoryFilter::getStringMatchOffset() const
  178. {
  179. return mSubStringMatchOffset;
  180. }
  181. // has user modified default filter params?
  182. BOOL LLInventoryFilter::isNotDefault() const
  183. {
  184. return mFilterOps.mFilterObjectTypes != mDefaultFilterOps.mFilterObjectTypes 
  185. || mFilterOps.mFilterTypes != FILTERTYPE_OBJECT
  186. || mFilterSubString.size() 
  187. || mFilterOps.mPermissions != mDefaultFilterOps.mPermissions
  188. || mFilterOps.mMinDate != mDefaultFilterOps.mMinDate 
  189. || mFilterOps.mMaxDate != mDefaultFilterOps.mMaxDate
  190. || mFilterOps.mHoursAgo != mDefaultFilterOps.mHoursAgo;
  191. }
  192. BOOL LLInventoryFilter::isActive() const
  193. {
  194. return mFilterOps.mFilterObjectTypes != 0xffffffffffffffffULL
  195. || mFilterOps.mFilterTypes != FILTERTYPE_OBJECT
  196. || mFilterSubString.size() 
  197. || mFilterOps.mPermissions != PERM_NONE 
  198. || mFilterOps.mMinDate != time_min()
  199. || mFilterOps.mMaxDate != time_max()
  200. || mFilterOps.mHoursAgo != 0;
  201. }
  202. BOOL LLInventoryFilter::isModified() const
  203. {
  204. return mModified;
  205. }
  206. BOOL LLInventoryFilter::isModifiedAndClear()
  207. {
  208. BOOL ret = mModified;
  209. mModified = FALSE;
  210. return ret;
  211. }
  212. void LLInventoryFilter::setFilterObjectTypes(U64 types)
  213. {
  214. if (mFilterOps.mFilterObjectTypes != types)
  215. {
  216. // keep current items only if no type bits getting turned off
  217. BOOL fewer_bits_set = (mFilterOps.mFilterObjectTypes & ~types);
  218. BOOL more_bits_set = (~mFilterOps.mFilterObjectTypes & types);
  219. mFilterOps.mFilterObjectTypes = types;
  220. if (more_bits_set && fewer_bits_set)
  221. {
  222. // neither less or more restrive, both simultaneously
  223. // so we need to filter from scratch
  224. setModified(FILTER_RESTART);
  225. }
  226. else if (more_bits_set)
  227. {
  228. // target is only one of all requested types so more type bits == less restrictive
  229. setModified(FILTER_LESS_RESTRICTIVE);
  230. }
  231. else if (fewer_bits_set)
  232. {
  233. setModified(FILTER_MORE_RESTRICTIVE);
  234. }
  235. }
  236. mFilterOps.mFilterTypes |= FILTERTYPE_OBJECT;
  237. }
  238. void LLInventoryFilter::setFilterCategoryTypes(U64 types)
  239. {
  240. if (mFilterOps.mFilterCategoryTypes != types)
  241. {
  242. // keep current items only if no type bits getting turned off
  243. BOOL fewer_bits_set = (mFilterOps.mFilterCategoryTypes & ~types);
  244. BOOL more_bits_set = (~mFilterOps.mFilterCategoryTypes & types);
  245. mFilterOps.mFilterCategoryTypes = types;
  246. if (more_bits_set && fewer_bits_set)
  247. {
  248. // neither less or more restrive, both simultaneously
  249. // so we need to filter from scratch
  250. setModified(FILTER_RESTART);
  251. }
  252. else if (more_bits_set)
  253. {
  254. // target is only one of all requested types so more type bits == less restrictive
  255. setModified(FILTER_LESS_RESTRICTIVE);
  256. }
  257. else if (fewer_bits_set)
  258. {
  259. setModified(FILTER_MORE_RESTRICTIVE);
  260. }
  261. }
  262. mFilterOps.mFilterTypes |= FILTERTYPE_CATEGORY;
  263. }
  264. void LLInventoryFilter::setFilterUUID(const LLUUID& object_id)
  265. {
  266. if (mFilterOps.mFilterUUID == LLUUID::null)
  267. {
  268. setModified(FILTER_MORE_RESTRICTIVE);
  269. }
  270. else
  271. {
  272. setModified(FILTER_RESTART);
  273. }
  274. mFilterOps.mFilterUUID = object_id;
  275. mFilterOps.mFilterTypes = FILTERTYPE_UUID;
  276. }
  277. void LLInventoryFilter::setFilterSubString(const std::string& string)
  278. {
  279. if (mFilterSubString != string)
  280. {
  281. // hitting BACKSPACE, for example
  282. const BOOL less_restrictive = mFilterSubString.size() >= string.size() && !mFilterSubString.substr(0, string.size()).compare(string);
  283. // appending new characters
  284. const BOOL more_restrictive = mFilterSubString.size() < string.size() && !string.substr(0, mFilterSubString.size()).compare(mFilterSubString);
  285. mFilterSubString = string;
  286. LLStringUtil::toUpper(mFilterSubString);
  287. LLStringUtil::trimHead(mFilterSubString);
  288. if (less_restrictive)
  289. {
  290. setModified(FILTER_LESS_RESTRICTIVE);
  291. }
  292. else if (more_restrictive)
  293. {
  294. setModified(FILTER_MORE_RESTRICTIVE);
  295. }
  296. else
  297. {
  298. setModified(FILTER_RESTART);
  299. }
  300. // Cancel out UUID once the search string is modified
  301. if (mFilterOps.mFilterTypes == FILTERTYPE_UUID)
  302. {
  303. mFilterOps.mFilterTypes &= ~FILTERTYPE_UUID;
  304. mFilterOps.mFilterUUID == LLUUID::null;
  305. setModified(FILTER_RESTART);
  306. }
  307. }
  308. }
  309. void LLInventoryFilter::setFilterPermissions(PermissionMask perms)
  310. {
  311. if (mFilterOps.mPermissions != perms)
  312. {
  313. // keep current items only if no perm bits getting turned off
  314. BOOL fewer_bits_set = (mFilterOps.mPermissions & ~perms);
  315. BOOL more_bits_set = (~mFilterOps.mPermissions & perms);
  316. mFilterOps.mPermissions = perms;
  317. if (more_bits_set && fewer_bits_set)
  318. {
  319. setModified(FILTER_RESTART);
  320. }
  321. else if (more_bits_set)
  322. {
  323. // target must have all requested permission bits, so more bits == more restrictive
  324. setModified(FILTER_MORE_RESTRICTIVE);
  325. }
  326. else if (fewer_bits_set)
  327. {
  328. setModified(FILTER_LESS_RESTRICTIVE);
  329. }
  330. }
  331. }
  332. void LLInventoryFilter::setDateRange(time_t min_date, time_t max_date)
  333. {
  334. mFilterOps.mHoursAgo = 0;
  335. if (mFilterOps.mMinDate != min_date)
  336. {
  337. mFilterOps.mMinDate = min_date;
  338. setModified();
  339. }
  340. if (mFilterOps.mMaxDate != llmax(mFilterOps.mMinDate, max_date))
  341. {
  342. mFilterOps.mMaxDate = llmax(mFilterOps.mMinDate, max_date);
  343. setModified();
  344. }
  345. mFilterOps.mFilterTypes |= FILTERTYPE_DATE;
  346. }
  347. void LLInventoryFilter::setDateRangeLastLogoff(BOOL sl)
  348. {
  349. if (sl && !isSinceLogoff())
  350. {
  351. setDateRange(mLastLogoff, time_max());
  352. setModified();
  353. }
  354. if (!sl && isSinceLogoff())
  355. {
  356. setDateRange(0, time_max());
  357. setModified();
  358. }
  359. mFilterOps.mFilterTypes |= FILTERTYPE_DATE;
  360. }
  361. BOOL LLInventoryFilter::isSinceLogoff() const
  362. {
  363. return (mFilterOps.mMinDate == (time_t)mLastLogoff) &&
  364. (mFilterOps.mMaxDate == time_max()) &&
  365. (mFilterOps.mFilterTypes & FILTERTYPE_DATE);
  366. }
  367. void LLInventoryFilter::clearModified()
  368. {
  369. mModified = FALSE; 
  370. mFilterBehavior = FILTER_NONE;
  371. }
  372. void LLInventoryFilter::setHoursAgo(U32 hours)
  373. {
  374. if (mFilterOps.mHoursAgo != hours)
  375. {
  376. // *NOTE: need to cache last filter time, in case filter goes stale
  377. BOOL less_restrictive = (mFilterOps.mMinDate == time_min() && mFilterOps.mMaxDate == time_max() && hours > mFilterOps.mHoursAgo);
  378. BOOL more_restrictive = (mFilterOps.mMinDate == time_min() && mFilterOps.mMaxDate == time_max() && hours <= mFilterOps.mHoursAgo);
  379. mFilterOps.mHoursAgo = hours;
  380. mFilterOps.mMinDate = time_min();
  381. mFilterOps.mMaxDate = time_max();
  382. if (less_restrictive)
  383. {
  384. setModified(FILTER_LESS_RESTRICTIVE);
  385. }
  386. else if (more_restrictive)
  387. {
  388. setModified(FILTER_MORE_RESTRICTIVE);
  389. }
  390. else
  391. {
  392. setModified(FILTER_RESTART);
  393. }
  394. }
  395. mFilterOps.mFilterTypes |= FILTERTYPE_DATE;
  396. }
  397. void LLInventoryFilter::setShowFolderState(EFolderShow state)
  398. {
  399. if (mFilterOps.mShowFolderState != state)
  400. {
  401. mFilterOps.mShowFolderState = state;
  402. if (state == SHOW_NON_EMPTY_FOLDERS)
  403. {
  404. // showing fewer folders than before
  405. setModified(FILTER_MORE_RESTRICTIVE);
  406. }
  407. else if (state == SHOW_ALL_FOLDERS)
  408. {
  409. // showing same folders as before and then some
  410. setModified(FILTER_LESS_RESTRICTIVE);
  411. }
  412. else
  413. {
  414. setModified();
  415. }
  416. }
  417. }
  418. void LLInventoryFilter::setSortOrder(U32 order)
  419. {
  420. if (mOrder != order)
  421. {
  422. mOrder = order;
  423. setModified();
  424. }
  425. }
  426. void LLInventoryFilter::markDefault()
  427. {
  428. mDefaultFilterOps = mFilterOps;
  429. }
  430. void LLInventoryFilter::resetDefault()
  431. {
  432. mFilterOps = mDefaultFilterOps;
  433. setModified();
  434. }
  435. void LLInventoryFilter::setModified(EFilterBehavior behavior)
  436. {
  437. mModified = TRUE;
  438. mNeedTextRebuild = TRUE;
  439. mFilterGeneration = mNextFilterGeneration++;
  440. if (mFilterBehavior == FILTER_NONE)
  441. {
  442. mFilterBehavior = behavior;
  443. }
  444. else if (mFilterBehavior != behavior)
  445. {
  446. // trying to do both less restrictive and more restrictive filter
  447. // basically means restart from scratch
  448. mFilterBehavior = FILTER_RESTART;
  449. }
  450. if (isNotDefault())
  451. {
  452. // if not keeping current filter results, update last valid as well
  453. switch(mFilterBehavior)
  454. {
  455. case FILTER_RESTART:
  456. mMustPassGeneration = mFilterGeneration;
  457. mMinRequiredGeneration = mFilterGeneration;
  458. break;
  459. case FILTER_LESS_RESTRICTIVE:
  460. mMustPassGeneration = mFilterGeneration;
  461. break;
  462. case FILTER_MORE_RESTRICTIVE:
  463. mMinRequiredGeneration = mFilterGeneration;
  464. // must have passed either current filter generation (meaningless, as it hasn't been run yet)
  465. // or some older generation, so keep the value
  466. mMustPassGeneration = llmin(mMustPassGeneration, mFilterGeneration);
  467. break;
  468. default:
  469. llerrs << "Bad filter behavior specified" << llendl;
  470. }
  471. }
  472. else
  473. {
  474. // shortcut disabled filters to show everything immediately
  475. mMinRequiredGeneration = 0;
  476. mMustPassGeneration = S32_MAX;
  477. }
  478. }
  479. BOOL LLInventoryFilter::isFilterObjectTypesWith(LLInventoryType::EType t) const
  480. {
  481. return mFilterOps.mFilterObjectTypes & (1LL << t);
  482. }
  483. const std::string& LLInventoryFilter::getFilterText()
  484. {
  485. if (!mNeedTextRebuild)
  486. {
  487. return mFilterText;
  488. }
  489. mNeedTextRebuild = FALSE;
  490. std::string filtered_types;
  491. std::string not_filtered_types;
  492. BOOL filtered_by_type = FALSE;
  493. BOOL filtered_by_all_types = TRUE;
  494. S32 num_filter_types = 0;
  495. mFilterText.clear();
  496. if (isFilterObjectTypesWith(LLInventoryType::IT_ANIMATION))
  497. {
  498. //filtered_types += " Animations,";
  499. filtered_types += LLTrans::getString("Animations");
  500. filtered_by_type = TRUE;
  501. num_filter_types++;
  502. }
  503. else
  504. {
  505. //not_filtered_types += " Animations,";
  506. not_filtered_types += LLTrans::getString("Animations");
  507. filtered_by_all_types = FALSE;
  508. }
  509. if (isFilterObjectTypesWith(LLInventoryType::IT_CALLINGCARD))
  510. {
  511. //filtered_types += " Calling Cards,";
  512. filtered_types += LLTrans::getString("Calling Cards");
  513. filtered_by_type = TRUE;
  514. num_filter_types++;
  515. }
  516. else
  517. {
  518. //not_filtered_types += " Calling Cards,";
  519. not_filtered_types += LLTrans::getString("Calling Cards");
  520. filtered_by_all_types = FALSE;
  521. }
  522. if (isFilterObjectTypesWith(LLInventoryType::IT_WEARABLE))
  523. {
  524. //filtered_types += " Clothing,";
  525. filtered_types +=  LLTrans::getString("Clothing");
  526. filtered_by_type = TRUE;
  527. num_filter_types++;
  528. }
  529. else
  530. {
  531. //not_filtered_types += " Clothing,";
  532. not_filtered_types +=  LLTrans::getString("Clothing");
  533. filtered_by_all_types = FALSE;
  534. }
  535. if (isFilterObjectTypesWith(LLInventoryType::IT_GESTURE))
  536. {
  537. //filtered_types += " Gestures,";
  538. filtered_types +=  LLTrans::getString("Gestures");
  539. filtered_by_type = TRUE;
  540. num_filter_types++;
  541. }
  542. else
  543. {
  544. //not_filtered_types += " Gestures,";
  545. not_filtered_types +=  LLTrans::getString("Gestures");
  546. filtered_by_all_types = FALSE;
  547. }
  548. if (isFilterObjectTypesWith(LLInventoryType::IT_LANDMARK))
  549. {
  550. //filtered_types += " Landmarks,";
  551. filtered_types +=  LLTrans::getString("Landmarks");
  552. filtered_by_type = TRUE;
  553. num_filter_types++;
  554. }
  555. else
  556. {
  557. //not_filtered_types += " Landmarks,";
  558. not_filtered_types +=  LLTrans::getString("Landmarks");
  559. filtered_by_all_types = FALSE;
  560. }
  561. if (isFilterObjectTypesWith(LLInventoryType::IT_NOTECARD))
  562. {
  563. //filtered_types += " Notecards,";
  564. filtered_types +=  LLTrans::getString("Notecards");
  565. filtered_by_type = TRUE;
  566. num_filter_types++;
  567. }
  568. else
  569. {
  570. //not_filtered_types += " Notecards,";
  571. not_filtered_types +=  LLTrans::getString("Notecards");
  572. filtered_by_all_types = FALSE;
  573. }
  574. if (isFilterObjectTypesWith(LLInventoryType::IT_OBJECT) && isFilterObjectTypesWith(LLInventoryType::IT_ATTACHMENT))
  575. {
  576. //filtered_types += " Objects,";
  577. filtered_types +=  LLTrans::getString("Objects");
  578. filtered_by_type = TRUE;
  579. num_filter_types++;
  580. }
  581. else
  582. {
  583. //not_filtered_types += " Objects,";
  584. not_filtered_types +=  LLTrans::getString("Objects");
  585. filtered_by_all_types = FALSE;
  586. }
  587. if (isFilterObjectTypesWith(LLInventoryType::IT_LSL))
  588. {
  589. //filtered_types += " Scripts,";
  590. filtered_types +=  LLTrans::getString("Scripts");
  591. filtered_by_type = TRUE;
  592. num_filter_types++;
  593. }
  594. else
  595. {
  596. //not_filtered_types += " Scripts,";
  597. not_filtered_types +=  LLTrans::getString("Scripts");
  598. filtered_by_all_types = FALSE;
  599. }
  600. if (isFilterObjectTypesWith(LLInventoryType::IT_SOUND))
  601. {
  602. //filtered_types += " Sounds,";
  603. filtered_types +=  LLTrans::getString("Sounds");
  604. filtered_by_type = TRUE;
  605. num_filter_types++;
  606. }
  607. else
  608. {
  609. //not_filtered_types += " Sounds,";
  610. not_filtered_types +=  LLTrans::getString("Sounds");
  611. filtered_by_all_types = FALSE;
  612. }
  613. if (isFilterObjectTypesWith(LLInventoryType::IT_TEXTURE))
  614. {
  615. //filtered_types += " Textures,";
  616. filtered_types +=  LLTrans::getString("Textures");
  617. filtered_by_type = TRUE;
  618. num_filter_types++;
  619. }
  620. else
  621. {
  622. //not_filtered_types += " Textures,";
  623. not_filtered_types +=  LLTrans::getString("Textures");
  624. filtered_by_all_types = FALSE;
  625. }
  626. if (isFilterObjectTypesWith(LLInventoryType::IT_SNAPSHOT))
  627. {
  628. //filtered_types += " Snapshots,";
  629. filtered_types +=  LLTrans::getString("Snapshots");
  630. filtered_by_type = TRUE;
  631. num_filter_types++;
  632. }
  633. else
  634. {
  635. //not_filtered_types += " Snapshots,";
  636. not_filtered_types +=  LLTrans::getString("Snapshots");
  637. filtered_by_all_types = FALSE;
  638. }
  639. if (!gInventory.backgroundFetchActive()
  640. && filtered_by_type
  641. && !filtered_by_all_types)
  642. {
  643. mFilterText += " - ";
  644. if (num_filter_types < 5)
  645. {
  646. mFilterText += filtered_types;
  647. }
  648. else
  649. {
  650. //mFilterText += "No ";
  651. mFilterText += LLTrans::getString("No Filters");
  652. mFilterText += not_filtered_types;
  653. }
  654. // remove the ',' at the end
  655. mFilterText.erase(mFilterText.size() - 1, 1);
  656. }
  657. if (isSinceLogoff())
  658. {
  659. //mFilterText += " - Since Logoff";
  660. mFilterText += LLTrans::getString("Since Logoff");
  661. }
  662. return mFilterText;
  663. }
  664. void LLInventoryFilter::toLLSD(LLSD& data) const
  665. {
  666. data["filter_types"] = (LLSD::Integer)getFilterObjectTypes();
  667. data["min_date"] = (LLSD::Integer)getMinDate();
  668. data["max_date"] = (LLSD::Integer)getMaxDate();
  669. data["hours_ago"] = (LLSD::Integer)getHoursAgo();
  670. data["show_folder_state"] = (LLSD::Integer)getShowFolderState();
  671. data["permissions"] = (LLSD::Integer)getFilterPermissions();
  672. data["substring"] = (LLSD::String)getFilterSubString();
  673. data["sort_order"] = (LLSD::Integer)getSortOrder();
  674. data["since_logoff"] = (LLSD::Boolean)isSinceLogoff();
  675. }
  676. void LLInventoryFilter::fromLLSD(LLSD& data)
  677. {
  678. if(data.has("filter_types"))
  679. {
  680. setFilterObjectTypes((U32)data["filter_types"].asInteger());
  681. }
  682. if(data.has("min_date") && data.has("max_date"))
  683. {
  684. setDateRange(data["min_date"].asInteger(), data["max_date"].asInteger());
  685. }
  686. if(data.has("hours_ago"))
  687. {
  688. setHoursAgo((U32)data["hours_ago"].asInteger());
  689. }
  690. if(data.has("show_folder_state"))
  691. {
  692. setShowFolderState((EFolderShow)data["show_folder_state"].asInteger());
  693. }
  694. if(data.has("permissions"))
  695. {
  696. setFilterPermissions((PermissionMask)data["permissions"].asInteger());
  697. }
  698. if(data.has("substring"))
  699. {
  700. setFilterSubString(std::string(data["substring"].asString()));
  701. }
  702. if(data.has("sort_order"))
  703. {
  704. setSortOrder((U32)data["sort_order"].asInteger());
  705. }
  706. if(data.has("since_logoff"))
  707. {
  708. setDateRangeLastLogoff((bool)data["since_logoff"].asBoolean());
  709. }
  710. }
  711. U32 LLInventoryFilter::getFilterObjectTypes() const
  712. {
  713. return mFilterOps.mFilterObjectTypes;
  714. }
  715. BOOL LLInventoryFilter::hasFilterString() const
  716. {
  717. return mFilterSubString.size() > 0;
  718. }
  719. PermissionMask LLInventoryFilter::getFilterPermissions() const
  720. {
  721. return mFilterOps.mPermissions;
  722. }
  723. time_t LLInventoryFilter::getMinDate() const
  724. {
  725. return mFilterOps.mMinDate;
  726. }
  727. time_t LLInventoryFilter::getMaxDate() const 
  728. return mFilterOps.mMaxDate; 
  729. }
  730. U32 LLInventoryFilter::getHoursAgo() const 
  731. return mFilterOps.mHoursAgo; 
  732. }
  733. LLInventoryFilter::EFolderShow LLInventoryFilter::getShowFolderState() const
  734. return mFilterOps.mShowFolderState; 
  735. }
  736. U32 LLInventoryFilter::getSortOrder() const 
  737. return mOrder; 
  738. }
  739. const std::string& LLInventoryFilter::getName() const 
  740. return mName; 
  741. }
  742. void LLInventoryFilter::setFilterCount(S32 count) 
  743. mFilterCount = count; 
  744. }
  745. S32 LLInventoryFilter::getFilterCount() const
  746. {
  747. return mFilterCount;
  748. }
  749. void LLInventoryFilter::decrementFilterCount() 
  750. mFilterCount--; 
  751. }
  752. S32 LLInventoryFilter::getCurrentGeneration() const 
  753. return mFilterGeneration; 
  754. }
  755. S32 LLInventoryFilter::getMinRequiredGeneration() const 
  756. return mMinRequiredGeneration; 
  757. }
  758. S32 LLInventoryFilter::getMustPassGeneration() const 
  759. return mMustPassGeneration; 
  760. }
  761. void LLInventoryFilter::setEmptyLookupMessage(const std::string& message)
  762. {
  763. mEmptyLookupMessage = message;
  764. }
  765. const std::string& LLInventoryFilter::getEmptyLookupMessage() const
  766. {
  767. return mEmptyLookupMessage;
  768. }