Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search_engine_module.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. **
  3. ** Copyright (C) 1995-2011 Opera Software ASA. All rights reserved.
  4. **
  5. ** This file is part of the Opera web browser.
  6. ** It may not be distributed under any circumstances.
  7. */
  8. #include "core/pch.h"
  9. #ifdef VISITED_PAGES_SEARCH
  10. #include "modules/hardcore/opera/module.h"
  11. #include "modules/prefs/prefsmanager/collections/pc_network.h"
  12. #include "modules/prefs/prefsmanager/collections/pc_core.h"
  13. #include "modules/search_engine/VisitedSearch.h"
  14. void SearchEngineModule::InitL(const OperaInitInfo& info)
  15. {
  16. #ifndef HISTORY_SUPPORT
  17. g_pcnet->RegisterListenerL(this);
  18. #endif
  19. g_pccore->RegisterListenerL(this);
  20. LEAVE_IF_ERROR(OpenVisitedSearch());
  21. empty_visited_search_result = OP_NEW_L(VisitedSearch::Result, ());
  22. ((VisitedSearch::Result*)empty_visited_search_result)->url = const_cast<char*>("");
  23. }
  24. void SearchEngineModule::Destroy()
  25. {
  26. #ifndef HISTORY_SUPPORT
  27. if (g_pcnet)
  28. g_pcnet->UnregisterListener(this);
  29. #endif
  30. if (g_pccore)
  31. g_pccore->UnregisterListener(this);
  32. CloseVisitedSearch(TRUE);
  33. OP_DELETE((VisitedSearch::Result*)empty_visited_search_result);
  34. }
  35. void SearchEngineModule::PrefChanged(enum OpPrefsCollection::Collections id, int pref, int newvalue)
  36. {
  37. if (id == OpPrefsCollection::Core && pref == PrefsCollectionCore::VisitedPages)
  38. OpStatus::Ignore(OpenVisitedSearch());
  39. #ifndef HISTORY_SUPPORT
  40. if (id == OpPrefsCollection::Network && pref == PrefsCollectionNetwork::VSMaxIndexSize)
  41. OpStatus::Ignore(OpenVisitedSearch());
  42. #else // HISTORY_SUPPORT
  43. if (id == OpPrefsCollection::Core && pref == PrefsCollectionCore::MaxGlobalHistory)
  44. OpStatus::Ignore(OpenVisitedSearch());
  45. #endif // HISTORY_SUPPORT
  46. }
  47. OP_STATUS SearchEngineModule::OpenVisitedSearch()
  48. {
  49. OpString directory;
  50. int max_size;
  51. #ifdef UTIL_VPS_FOLDER
  52. RETURN_IF_ERROR(g_folder_manager->GetFolderPath(OPFILE_VPS_FOLDER, directory));
  53. #else
  54. RETURN_IF_ERROR(g_folder_manager->GetFolderPath(OPFILE_HOME_FOLDER, directory));
  55. RETURN_IF_ERROR(directory.AppendFormat(UNI_L("%c%s"), PATHSEPCHAR, UNI_L("vps")));
  56. #endif
  57. #ifndef HISTORY_SUPPORT
  58. max_size = g_pcnet->GetIntegerPref(PrefsCollectionNetwork::VSMaxIndexSize);
  59. #else
  60. max_size = g_pccore->GetIntegerPref(PrefsCollectionCore::MaxGlobalHistory);
  61. #endif
  62. // See if we are enabled or disabled
  63. if (!g_pccore->GetIntegerPref(PrefsCollectionCore::VisitedPages))
  64. max_size = 0;
  65. if (visited_search == NULL)
  66. #ifdef VPS_WRAPPER
  67. visited_search = AsyncVisitedSearch::Create();
  68. #else
  69. visited_search = OP_NEW(VisitedSearch, ());
  70. #endif
  71. RETURN_OOM_IF_NULL(visited_search);
  72. if (max_size == 0)
  73. {
  74. if (visited_search->IsOpen())
  75. RETURN_IF_ERROR(visited_search->Clear(FALSE));
  76. else
  77. OpStatus::Ignore(BlockStorage::DeleteFile(directory.CStr()));
  78. }
  79. else
  80. {
  81. if (!visited_search->IsOpen())
  82. OpStatus::Ignore(visited_search->Open(directory.CStr())); // on error, let's rather start Opera anyway without this service running
  83. }
  84. #ifndef HISTORY_SUPPORT
  85. visited_search->SetMaxSize(max_size);
  86. #else
  87. visited_search->SetMaxItems(max_size);
  88. #endif
  89. return OpStatus::OK;
  90. }
  91. void SearchEngineModule::CloseVisitedSearch(BOOL force_close)
  92. {
  93. if (visited_search == NULL)
  94. return;
  95. if (visited_search->IsOpen() && OpStatus::IsError(visited_search->Close(force_close)) && !force_close)
  96. return;
  97. OP_DELETE(visited_search);
  98. visited_search = NULL;
  99. }
  100. #endif // VISITED_PAGES_SEARCH