ECSearchObjectTable.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <new>
  18. #include <kopano/platform.h>
  19. #include <kopano/lockhelper.hpp>
  20. #include "ECDatabase.h"
  21. #include <mapidefs.h>
  22. #include "ECSessionManager.h"
  23. #include "ECSearchObjectTable.h"
  24. #include "ECSession.h"
  25. namespace KC {
  26. ECSearchObjectTable::ECSearchObjectTable(ECSession *lpSession, unsigned int ulStoreId, LPGUID lpGuid, unsigned int ulFolderId, unsigned int ulObjType, unsigned int ulFlags, const ECLocale &locale) : ECStoreObjectTable(lpSession, ulStoreId, lpGuid, 0, ulObjType, ulFlags, 0, locale) {
  27. // We don't pass ulFolderId to ECStoreObjectTable (see constructor above passing '0'), because
  28. // it will assume that all rows are in that folder if we do that. But we still want to
  29. // remember the folder ID for our own use.
  30. m_ulFolderId = ulFolderId;
  31. m_ulStoreId = ulStoreId;
  32. }
  33. ECRESULT ECSearchObjectTable::Create(ECSession *lpSession,
  34. unsigned int ulStoreId, GUID *lpGuid, unsigned int ulFolderId,
  35. unsigned int ulObjType, unsigned int ulFlags, const ECLocale &locale,
  36. ECStoreObjectTable **lppTable)
  37. {
  38. *lppTable = new(std::nothrow) ECSearchObjectTable(lpSession, ulStoreId,
  39. lpGuid, ulFolderId, ulObjType, ulFlags, locale);
  40. if (*lppTable == nullptr)
  41. return KCERR_NOT_ENOUGH_MEMORY;
  42. (*lppTable)->AddRef();
  43. return erSuccess;
  44. }
  45. ECRESULT ECSearchObjectTable::Load() {
  46. ECRESULT er = erSuccess;
  47. sObjectTableKey sRowItem;
  48. std::list<unsigned int> lstObjId;
  49. scoped_rlock biglock(m_hLock);
  50. if(m_ulFolderId) {
  51. // Get the search results
  52. er = lpSession->GetSessionManager()->GetSearchFolders()->GetSearchResults(m_ulStoreId, m_ulFolderId, &lstObjId);
  53. if(er != erSuccess)
  54. return er;
  55. er = UpdateRows(ECKeyTable::TABLE_ROW_ADD, &lstObjId, 0, true);
  56. if(er != hrSuccess)
  57. return er;
  58. }
  59. return er;
  60. }
  61. } /* namespace */