-//\r
-\r
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
-//\r
-// Licensed under the Flora License, Version 1.0 (the License);\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-// http://floralicense.org/license/\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an AS IS BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-\r
-\r
-//!Internet\r
-/*@file: IntHistoryPresentationModel.cpp\r
- *@brief: Provides functionalities to handle/maintain Browser History.\r
- */\r
-\r
-#include <cstdlib>\r
-#include "IntHistoryData.h"\r
-#include "IntHistoryPresentationModel.h"\r
-#include "IntTypes.h"\r
-\r
-using namespace Tizen::App;\r
-using namespace Tizen::Base;\r
-using namespace Tizen::Base::Collection;\r
-using namespace Tizen::Base::Utility;\r
-using namespace Tizen::Graphics;\r
-using namespace Tizen::Io;\r
-using namespace Tizen::Locales;\r
-using namespace Tizen::Media;\r
-using namespace Tizen::System;\r
-\r
-extern const wchar_t* HISTORY_DATA_TABLE;\r
-extern const wchar_t* BOOKMARK_URL_TABLE;\r
-\r
-HistoryPresentationModel* HistoryPresentationModel::__pHistoryPresentationModel = null;\r
-\r
-void HistoryPresentationModel::CreateInstance(void)\r
-{\r
- if (__pHistoryPresentationModel == null)\r
- __pHistoryPresentationModel = new(std::nothrow) HistoryPresentationModel();\r
- result r = __pHistoryPresentationModel->Construct();\r
- if (IsFailed(r))\r
- {\r
- delete __pHistoryPresentationModel;\r
- __pHistoryPresentationModel = null;\r
- return;\r
- }\r
- std::atexit(DestroyInstance);\r
-}\r
-\r
-\r
-HistoryPresentationModel* HistoryPresentationModel::GetInstance(void)\r
-{\r
- if (__pHistoryPresentationModel == null)\r
- {\r
- CreateInstance();\r
- }\r
- return __pHistoryPresentationModel;\r
-\r
-}\r
-\r
-void HistoryPresentationModel::DestroyInstance(void)\r
-{\r
- if (__pHistoryPresentationModel)\r
- {\r
- delete __pHistoryPresentationModel;\r
- __pHistoryPresentationModel = null;\r
- }\r
-}\r
-\r
-HistoryPresentationModel::HistoryPresentationModel(void)\r
-{\r
-\r
-}\r
-\r
-HistoryPresentationModel::~HistoryPresentationModel(void)\r
-{\r
-\r
-}\r
-\r
-HistoryPresentationModel::HistoryPresentationModel(const HistoryPresentationModel& historyModelObj)\r
-{\r
-\r
-}\r
-\r
-HistoryPresentationModel& HistoryPresentationModel::operator=(const HistoryPresentationModel& historyModelObj)\r
-{\r
- return *this;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::Construct(void)\r
-{\r
- result r = E_SUCCESS;\r
- DB_FILE_PATH = L"/opt/usr/dbspace/.browser-history.db";\r
- r = PresentationModelBase::Initialize();\r
- TryCatch( !IsFailed(r),,"Failed to initialize HistoryPresentationModel Model %s",GetErrorMessage(r));\r
-\r
- CATCH: return r;\r
-\r
-}\r
-\r
-result\r
-HistoryPresentationModel::SaveHistory(History& history)\r
-{\r
- AppLog("HistoryPresentationModel::saveHistory");\r
- result r = E_FAILURE;\r
- String historyTable(HISTORY_DATA_TABLE);\r
- String query;\r
- String columnNames;\r
- String attachment;\r
- int resultCount = -1;\r
- int rowId = -1;\r
- DateTime date;\r
- String historyId;\r
- int urlCount = 0;\r
- ArrayList* pMostVisitedSites = null;\r
- bool isAlreadyExist = false;\r
- bool isEligibleForMostVisitedSites = true;\r
- int i;\r
- String thumbnailPath;\r
- int todaysCount = 0;\r
- DateTime todayStart;\r
- DateTime todayEnd;\r
- SystemTime::GetCurrentTime(todayStart);\r
- SystemTime::GetCurrentTime(todayEnd);\r
- todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);\r
- todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);\r
-\r
- ArrayList* pTodaysList = new(std::nothrow) ArrayList();\r
- pTodaysList->Construct();\r
- GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);\r
- GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);\r
-\r
- for(int count = 0; count < todaysCount; count++)\r
- {\r
- History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));\r
- //AppLog("HistoryPresentationModel::saveHistory pHistoryItem id is %ls",pHistoryItem->GetHistoryId().GetPointer());\r
- AppLog("SaveHistory pHistoryItem url is %ls",pHistoryItem->GetHistoryUrl().GetPointer());\r
- AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());\r
-\r
- if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)\r
- {\r
- history.SetHistoryId(pHistoryItem->GetHistoryId());\r
- AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());\r
- break;\r
- }\r
- }\r
-\r
- pMostVisitedSites = new(std::nothrow) ArrayList();\r
- pMostVisitedSites->Construct();\r
- String historyTitle = history.GetHistoryTitle();\r
- historyTitle.Replace(L"'", L"''");\r
-\r
- String historyUrl = history.GetHistoryUrl();\r
- historyUrl.Replace(L"'", L"''");\r
-\r
- PresentationModelBase::GetCurrentDateTime(date);\r
- GetMostVisitedSites(*pMostVisitedSites);\r
- GetUrlCount(historyUrl, urlCount);\r
- for (i = 0; i < pMostVisitedSites->GetCount(); i++)\r
- {\r
- History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));\r
- if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)\r
- {\r
- AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");\r
- isAlreadyExist = true;\r
- break;\r
- }\r
- if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())\r
- {\r
- isEligibleForMostVisitedSites = true;\r
- }\r
- else\r
- {\r
- isEligibleForMostVisitedSites = false;\r
- }\r
- }\r
-\r
- if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))\r
- {\r
- AppLog("HistoryPresentationModel::SaveHistory coming here");\r
-\r
- thumbnailPath = GenerateFileName();\r
- AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());\r
- Image* pImage = new(std::nothrow) Image();\r
- pImage->Construct();\r
- result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);\r
- delete pImage;\r
- if(IsFailed(r))\r
- {\r
- AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));\r
- return r;\r
- }\r
- }\r
- delete pMostVisitedSites;\r
- pMostVisitedSites = NULL ;\r
-\r
- if (history.GetHistoryId() == "")\r
- {\r
- AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");\r
- /*\r
- columnNames.Append(L"TITLE, ");\r
- columnNames.Append(L"URL, ");\r
- columnNames.Append(L"VISITED_TIME, ");\r
- columnNames.Append(L"ICON_PATH, ");\r
- columnNames.Append(L"FAVICON_ID, ");\r
- columnNames.Append(L"THUMBNAIL_PATH");\r
-\r
- query.Append(L"INSERT INTO ");\r
- query.Append(historyTable);\r
- query.Append("(");\r
- query.Append(columnNames);\r
- query.Append(") ");\r
- query.Append("VALUES(");\r
- query.Append("'");\r
- query.Append(historyTitle);\r
- query.Append("'");\r
- query.Append(", ");\r
- query.Append("'");\r
- query.Append(historyUrl);\r
- query.Append("', ");\r
- query.Append("DateTime(");\r
- query.Append("'");\r
- query.Append(GetStringFromDate(date));\r
- query.Append("'), ");\r
- query.Append("'");\r
- query.Append(history.GetHistoryIconPath());\r
- query.Append("'");\r
- query.Append(", ");\r
- query.Append("'");\r
- query.Append(history.GetFaviconId());\r
- query.Append("'");\r
- query.Append(", ");\r
- query.Append("'");\r
- query.Append(thumbnailPath);\r
- query.Append("'");\r
- query.Append(")");\r
- */\r
- columnNames.Append(L"ADDRESS, ");\r
- columnNames.Append(L"TITLE, ");\r
- //columnNames.Append(L"COUNTER, ");\r
- columnNames.Append(L"VISITDATE");\r
- // columnNames.Append(L"FAVICON, ");\r
- // columnNames.Append(L"FAVICON_LENGTH, ");\r
- // columnNames.Append(L"FAVICON_W, ");\r
- // columnNames.Append(L"FAVICON_H, ");\r
- // columnNames.Append(L"SNAPSHOT, ");\r
- // columnNames.Append(L"SNAPSHOT_STRIDE, ");\r
- // columnNames.Append(L"SNAPSHOT_W, ");\r
- // columnNames.Append(L"SNAPSHOT_H");\r
- // columnNames.Append(L"ICON_PATH, ");\r
- // columnNames.Append(L"FAVICON_ID, ");\r
- // columnNames.Append(L"THUMBNAIL_PATH");\r
-\r
- query.Append(L"INSERT INTO ");\r
- query.Append(historyTable);\r
- query.Append("(");\r
- query.Append(columnNames);\r
- query.Append(") ");\r
- query.Append("VALUES(");\r
- query.Append("'");\r
- query.Append(historyUrl);\r
- query.Append("'");\r
- query.Append(", ");\r
- query.Append("'");\r
- query.Append(historyTitle);\r
- query.Append("', ");\r
- query.Append("DateTime(");\r
- query.Append("'");\r
- query.Append(GetStringFromDate(date));\r
- query.Append("'))");\r
-\r
- //query.Append("'), ");\r
- //query.Append("'");\r
- //query.Append(history.GetHistoryIconPath());\r
- //query.Append("'");\r
- //query.Append(", ");\r
- //query.Append("'");\r
- //query.Append(history.GetFaviconId());\r
- //query.Append("'");\r
- //query.Append(", ");\r
- //query.Append("'");\r
- //query.Append(thumbnailPath);\r
- //query.Append("'");\r
- //query.Append(")");\r
- }\r
- else\r
- {\r
- /*query.Append(L"UPDATE ");\r
- query.Append(historyTable);\r
- query.Append(" SET TITLE = ");\r
- query.Append("'");\r
- query.Append(historyTitle);\r
- query.Append("'");\r
- query.Append(", URL = ");\r
- query.Append("'");\r
- query.Append(historyUrl);\r
- query.Append("'");\r
- query.Append(", VISITED_TIME = ");\r
- query.Append("DateTime(");\r
- query.Append("'");\r
- query.Append(GetStringFromDate(date));\r
- query.Append("')");\r
- query.Append(", ICON_PATH = ");\r
- query.Append("'");\r
- query.Append(history.GetHistoryIconPath());\r
- query.Append("'");\r
- query.Append(", ");\r
- query.Append("'");\r
- query.Append(history.GetFaviconId());\r
- query.Append("'");\r
- query.Append(", ");\r
- query.Append("'");\r
- query.Append(thumbnailPath);\r
- query.Append("'");\r
- query.Append(" WHERE ID = ");\r
- query.Append(history.GetHistoryId());*/\r
- query.Append(L"UPDATE ");\r
- query.Append(historyTable);\r
- query.Append(" SET ADDRESS = ");\r
- query.Append("'");\r
- query.Append(historyUrl);\r
- query.Append("'");\r
- query.Append(", TITLE = ");\r
- query.Append("'");\r
- query.Append(historyTitle);\r
- query.Append("'");\r
- query.Append(", VISITED_TIME = ");\r
- query.Append("DateTime(");\r
- query.Append("'");\r
- query.Append(GetStringFromDate(date));\r
- query.Append("')");\r
- /*query.Append(", ICON_PATH = ");\r
- query.Append("'");\r
- query.Append(history.GetHistoryIconPath());\r
- query.Append("'");\r
- query.Append(", ");\r
- query.Append("'");\r
- query.Append(history.GetFaviconId());\r
- query.Append("'");\r
- query.Append(", ");\r
- query.Append("'");\r
- query.Append(thumbnailPath);*/\r
- query.Append("'");\r
- query.Append(" WHERE ID = ");\r
- query.Append(history.GetHistoryId());\r
-\r
- }\r
-\r
- AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());\r
-\r
- r = PresentationModelBase::ExecuteQuery(query, resultCount);\r
- if (r == E_SUCCESS)\r
- {\r
- AppLog("HistoryPresentationModel::SaveHistory result is success");\r
- }\r
- else\r
- {\r
- AppLog("HistoryPresentationModel::SaveHistory result is failure");\r
- }\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));\r
-\r
- r = PresentationModelBase::CommitDb();\r
-\r
- r = GetLastInsertedId(historyTable, rowId);\r
- if (IsFailed(r))\r
- {\r
- AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));\r
- return r;\r
- }\r
- if (rowId < 0)\r
- return E_FAILURE;\r
-\r
- historyId.Append(rowId);\r
- if (historyId.GetLength() < 0)\r
- {\r
- return E_FAILURE;\r
- }\r
- //Set the generated ID to History\r
- history.SetHistoryId(historyId);\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)\r
-{\r
- result r = E_FAILURE;\r
- String query;\r
- String historyTable = HISTORY_DATA_TABLE;\r
- int resultCount = -1;\r
-\r
- if (pHistoryIdList == null)\r
- {\r
- return E_FAILURE;\r
- }\r
-\r
- query.Append(L"DELETE FROM ");\r
- query.Append(historyTable);\r
- query.Append(" WHERE");\r
- for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)\r
- {\r
- query.Append(" ID = ");\r
- String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));\r
- query.Append(*hisId);\r
- query.Append(" OR ");\r
- }\r
- query.Append(" ID = ");\r
- String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));\r
- if(hisId == null)\r
- {\r
- return E_FAILURE;\r
- }\r
- query.Append(*hisId);\r
-\r
- r = PresentationModelBase::ExecuteQuery(query, resultCount);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));\r
-\r
- r = PresentationModelBase::CommitDb();\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::DeleteHistory(const int historyId)\r
-{\r
- result r = E_FAILURE;\r
- String query;\r
- String historyTable = HISTORY_DATA_TABLE;\r
- int resultCount = -1;\r
-\r
- if (historyId < 1)\r
- {\r
- return E_INVALID_ARG;\r
- }\r
-\r
- query.Append(L"DELETE FROM ");\r
- query.Append(historyTable);\r
- query.Append(" WHERE ID = ");\r
- query.Append(historyId);\r
-\r
- r = PresentationModelBase::ExecuteQuery(query, resultCount);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));\r
-\r
- r = PresentationModelBase::CommitDb();\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::DeleteHistory(String& historyUrl)\r
-{\r
- result r = E_FAILURE;\r
- String query;\r
- String historyTable = HISTORY_DATA_TABLE;\r
- int resultCount = -1;\r
-\r
- query.Append(L"DELETE FROM ");\r
- query.Append(historyTable);\r
- query.Append(" WHERE URL = '");\r
- query.Append(historyUrl);\r
- query.Append("'");\r
-\r
- r = PresentationModelBase::ExecuteQuery(query, resultCount);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));\r
-\r
- r = PresentationModelBase::CommitDb();\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::ClearHistory(void)\r
-{\r
- result r = E_FAILURE;\r
- String query;\r
- String historyTable = HISTORY_DATA_TABLE;\r
- int resultCount = -1;\r
-\r
- query.Append(L"DELETE FROM ");\r
- query.Append(historyTable);\r
-\r
- r = PresentationModelBase::ExecuteQuery(query, resultCount);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));\r
-\r
- r = PresentationModelBase::CommitDb();\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::GetHistoryCount(int& historyCount)\r
-{\r
- int count = -1;\r
- int intVal = -1;\r
- String query;\r
- String historyTable(HISTORY_DATA_TABLE);\r
- result r = E_FAILURE;\r
- bool nextRowPresent = false;\r
-\r
- query.Append(L"SELECT COUNT(ID) FROM ");\r
- query.Append(historyTable);\r
-\r
- r = PresentationModelBase::ExecuteQuery(query, count);\r
- AppLog("the count is %d", count);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));\r
-\r
- r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);\r
- if (IsFailed(r) != null)\r
- return r;\r
- if (nextRowPresent == true)\r
- {\r
- r = PresentationModelBase::GetColumn(0, intVal);\r
- if (IsFailed(r) != null)\r
- {\r
- AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));\r
- return r;\r
- }\r
- }\r
- historyCount = intVal;\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)\r
-{\r
-\r
- int count = -1;\r
- int intVal = -1;\r
- String query;\r
- String historyTable(HISTORY_DATA_TABLE);\r
- result r = E_FAILURE;\r
- bool nextRowPresent = false;\r
-\r
- query.Append(L"SELECT COUNT(ID) FROM ");\r
- query.Append(historyTable);\r
- query.Append(" WHERE VISITDATE >= ");\r
- query.Append("DateTime(");\r
- query.Append("'");\r
- query.Append(GetStringFromDate(startTime));\r
- query.Append("')");\r
- query.Append(" AND VISITDATE <= ");\r
- query.Append("DateTime(");\r
- query.Append("'");\r
- query.Append(GetStringFromDate(endTime));\r
- query.Append("')");\r
-\r
- r = PresentationModelBase::ExecuteQuery(query, count);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCountWithTimeRange query failed %s",GetErrorMessage(r));\r
-\r
- r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);\r
- if (IsFailed(r))\r
- return r;\r
- if (nextRowPresent == true)\r
- {\r
- r = PresentationModelBase::GetColumn(0, intVal);\r
- if (IsFailed(r))\r
- {\r
- AppLogDebug("Error:PresentationModelBase::DbGetColumn:%s", GetErrorMessage(r));\r
- return r;\r
- }\r
- }\r
- historyCount = intVal;\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)\r
-{\r
-\r
- int count = -1;\r
- String query;\r
- String historyTable(HISTORY_DATA_TABLE);\r
- result r = E_FAILURE;\r
-\r
- query.Append(L"SELECT");\r
- query.Append(historyTable);\r
- query.Append(L".*, ");\r
- query.Append(BOOKMARK_URL_TABLE);\r
- query.Append(L".ID ");\r
- query.Append(L"FROM ");\r
- query.Append(historyTable);\r
- query.Append(L", ");\r
- query.Append(BOOKMARK_URL_TABLE);\r
- query.Append(L" WHERE ");\r
- query.Append(historyTable);\r
- query.Append(L".ADDRESS ");\r
- query.Append(L"IN");\r
- query.Append(L"(");\r
- query.Append(L"SELECT");\r
- query.Append(historyTable);\r
- query.Append(L".ADDRESS ");\r
- query.Append(L"FROM ");\r
- query.Append(BOOKMARK_URL_TABLE);\r
- query.Append(L" LEFT JOIN ");\r
- query.Append(historyTable);\r
- query.Append(L"ON");\r
- query.Append(BOOKMARK_URL_TABLE);\r
- query.Append(L".ADDRESS = ");\r
- query.Append(historyTable);\r
- query.Append(L".ADDRESS ");\r
- query.Append(" ORDER BY");\r
- query.Append(historyTable);\r
- query.Append(L".VISITDATE DESC");\r
- query.Append(")");\r
- query.Append(" GROUP BY ");\r
- query.Append(historyTable);\r
- query.Append(L".ADDRESS ");\r
- query.Append(" ORDER BY");\r
- query.Append(L"COUNT(");\r
- query.Append(historyTable);\r
- query.Append(L".ADDRESS) DESC ");\r
-\r
-\r
- //Append LIMIT\r
- if (limit > 0)\r
- {\r
- query.Append(" LIMIT ");\r
- query.Append(limit);\r
-\r
- //Append OFFESET\r
- if (startIndex >= 0)\r
- {\r
- query.Append(" OFFSET ");\r
- query.Append(startIndex);\r
- }\r
- }\r
-\r
- r = PresentationModelBase::ExecuteQuery(query, count);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));\r
-\r
- r = CreateHistoryList(count, pHistoryList);\r
- if (IsFailed(r))\r
- {\r
- AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));\r
- }\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)\r
-{\r
-\r
- History* pHistory = null;\r
- int intVal = -1;\r
- String stringVal;\r
- DateTime dateVal;\r
- result r = E_FAILURE;\r
- String historyId;\r
- String faviconId;\r
- String bookmarkId;\r
- int visitedCount;\r
- DateTime visitedTime;\r
- String iconPath;\r
- String thumbnailPath;\r
- bool nextRowPresent = false;\r
- Image image;\r
- Bitmap* pThumnailBitmap = null;\r
-\r
- image.Construct();\r
- if (historyCount < 1)\r
- {\r
- return E_SUCCESS;\r
- }\r
-\r
- for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)\r
- {\r
- r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);\r
- if (IsFailed(r))\r
- {\r
- return E_SUCCESS;\r
- }\r
- if (nextRowPresent == true)\r
- {\r
- pHistory = new(std::nothrow) History;\r
- if (pHistory)\r
- {\r
- for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)\r
- {\r
-\r
- switch (columnCount)\r
- {\r
- case HISTORY_ID:\r
- r = PresentationModelBase::GetColumn(columnCount, intVal);\r
- if (!IsFailed(r))\r
- {\r
- if (intVal > 0)\r
- {\r
- historyId.Clear();\r
- historyId.Append(intVal);\r
- if (historyId.GetLength() > 0)\r
- {\r
- pHistory->SetHistoryId(historyId);\r
- }\r
- }\r
-\r
- }\r
- break;\r
- case HISTORY_URL:\r
- r = PresentationModelBase::GetColumn(columnCount, stringVal);\r
- if (!IsFailed(r))\r
- {\r
- pHistory->SetHistoryUrl(stringVal);\r
- }\r
- break;\r
- case HISTORY_TITLE:\r
- r = PresentationModelBase::GetColumn(columnCount, stringVal);\r
- if (!IsFailed(r))\r
- {\r
- pHistory->SetHistoryTitle(stringVal);\r
- }\r
- break;\r
- case HISTORY_VISITED_TIME:\r
- r = PresentationModelBase::GetColumn(columnCount, dateVal);\r
- if (!IsFailed(r))\r
- {\r
- visitedTime = dateVal;\r
- pHistory->SetVisitedTime(visitedTime);\r
- }\r
- break;\r
-\r
- /*case HISTORY_ICON_PATH:\r
- r = PresentationModelBase::GetColumn(columnCount, stringVal);\r
- if (!IsFailed(r))\r
- {\r
- iconPath = stringVal;\r
- pHistory->SetIconPath(iconPath);\r
- }\r
- break;\r
-\r
- case HISTORY_FAVICONID:\r
-\r
- r = PresentationModelBase::GetColumn(columnCount, intVal);\r
- if (!IsFailed(r))\r
- {\r
- if (intVal >= 0)\r
- {\r
- faviconId.Clear();\r
- faviconId.Append(intVal);\r
- if (faviconId.GetLength() > 0)\r
- {\r
- pHistory->SetFaviconId(faviconId);\r
- }\r
- }\r
- }\r
- break;\r
- case HISTORY_THUMBNAIL:\r
- r = PresentationModelBase::GetColumn(columnCount, stringVal);\r
- if (!IsFailed(r))\r
- {\r
-\r
- thumbnailPath = stringVal;\r
- pThumnailBitmap = image.DecodeN(thumbnailPath, BITMAP_PIXEL_FORMAT_RGB565);\r
- if (pThumnailBitmap != null)\r
- {\r
- pHistory->SetThumbnail(pThumnailBitmap);\r
- pHistory->SetThumbnailPath(thumbnailPath);\r
- }\r
- }\r
- break;*/\r
- /* case HISTORY_BOOKMARK_ID:\r
- r = PresentationModelBase::GetColumn(columnCount, intVal);\r
- if (!IsFailed(r))\r
- {\r
- if (intVal > 0)\r
- {\r
- bookmarkId.Clear();\r
- bookmarkId.Append(intVal);\r
- if (bookmarkId.GetLength() > 0)\r
- {\r
- pHistory->SetBookmarkId(bookmarkId);\r
- }\r
- }\r
-\r
- }\r
- break;\r
- */\r
- case HISTORY_VISITED_COUNT:\r
- r = PresentationModelBase::GetColumn(columnCount, intVal);\r
- if (!IsFailed(r))\r
- {\r
- if (intVal > 0)\r
- {\r
- pHistory->SetVisitedCount(intVal);\r
-\r
- }\r
-\r
- }\r
- break;\r
-\r
- default:\r
- break;\r
- }\r
-\r
- }\r
- r = historyList.Add(*pHistory);\r
-\r
- if (IsFailed(r))\r
- {\r
- delete pHistory;\r
- return r;\r
- }\r
- }\r
- }\r
- }\r
- return E_SUCCESS;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)\r
-{\r
- text.Replace(L"'", L"''");\r
-\r
- int count = -1;\r
- String query;\r
- String historyTable(HISTORY_DATA_TABLE);\r
- result r = E_FAILURE;\r
-\r
- query.Append(L"SELECT ");\r
- query.Append(historyTable);\r
- query.Append(L".* ");\r
- query.Append(L"FROM ");\r
- query.Append(historyTable);\r
- query.Append(L" WHERE (");\r
- query.Append(historyTable);\r
- query.Append(L".TITLE LIKE '%");\r
- query.Append(text);\r
- query.Append("%')");\r
- query.Append(" OR ");\r
- query.Append(L"(");\r
- query.Append(historyTable);\r
- query.Append(L".ADDRESS LIKE '%");\r
- query.Append(text);\r
- query.Append("%')");\r
- query.Append(" ORDER BY VISITDATE DESC");\r
-\r
- //Append LIMIT\r
- if (limit > 0)\r
- {\r
- query.Append(" LIMIT ");\r
- query.Append(limit);\r
-\r
- //Append OFFESET\r
- if (startIndex >= 0)\r
- {\r
- query.Append(" OFFSET ");\r
- query.Append(startIndex);\r
- }\r
- }\r
-\r
- r = HistoryPresentationModel::ExecuteQuery(query, count);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));\r
-\r
- r = CreateHistoryList(count, pHistoryList);\r
- if (IsFailed(r))\r
- {\r
- AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));\r
- }\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)\r
-{\r
- int count = -1;\r
- int intVal = -1;\r
- String query;\r
- String historyTable(HISTORY_DATA_TABLE);\r
- result r = E_FAILURE;\r
- bool nextRowPresent = false;\r
-\r
- text.Replace(L"'", L"''");\r
- query.Append(L"SELECT COUNT(ID) FROM ");\r
- query.Append(historyTable);\r
- query.Append(L" WHERE (TITLE LIKE '%");\r
- query.Append(text);\r
- query.Append("%')");\r
- query.Append(" OR ");\r
- query.Append(L"(ADDRESS LIKE '%");\r
- query.Append(text);\r
- query.Append("%')");\r
-\r
- r = HistoryPresentationModel::ExecuteQuery(query, count);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));\r
-\r
- r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);\r
- if (IsFailed(r) != null)\r
- return r;\r
- if (nextRowPresent == true)\r
- {\r
- r = HistoryPresentationModel::GetColumn(0, intVal);\r
- if (IsFailed(r) != null)\r
- {\r
- AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));\r
- return r;\r
- }\r
- }\r
- historyCount = intVal;\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)\r
-{\r
- int count = -1;\r
- String query;\r
- String historyTable(HISTORY_DATA_TABLE);\r
- result r = E_FAILURE;\r
-\r
- query.Append(L"SELECT ");\r
- //query.Append(historyTable);\r
- query.Append(L"* ");\r
- query.Append(L"FROM ");\r
- query.Append(historyTable);\r
- query.Append(" WHERE ");\r
- //query.Append(historyTable);\r
- query.Append(L"VISITDATE >= ");\r
- query.Append("DateTime(");\r
- query.Append("'");\r
- query.Append(GetStringFromDate(startTime));\r
- query.Append("')");\r
- query.Append(" AND ");\r
- //query.Append(historyTable);\r
- query.Append(L"VISITDATE <= ");\r
- query.Append("DateTime(");\r
- query.Append("'");\r
- query.Append(GetStringFromDate(endTime));\r
- query.Append("')");\r
- query.Append(" ORDER BY VISITDATE DESC");\r
-\r
- //Append LIMIT\r
- if (limit > 0)\r
- {\r
- query.Append(" LIMIT ");\r
- query.Append(limit);\r
-\r
- //Append OFFESET\r
- if (startIndex >= 0)\r
- {\r
- query.Append(" OFFSET ");\r
- query.Append(startIndex);\r
- }\r
- }\r
-\r
- r = HistoryPresentationModel::ExecuteQuery(query, count);\r
- AppLog("the count is %d",count);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));\r
-\r
- r = CreateHistoryList(count, pHistoryList);\r
- if (IsFailed(r))\r
- {\r
- AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));\r
- }\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)\r
-{\r
-\r
- int count = -1;\r
- String query;\r
- String historyTable(HISTORY_DATA_TABLE);\r
- result r = E_FAILURE;\r
-\r
-\r
- //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";\r
- query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";\r
-\r
- r = HistoryPresentationModel::ExecuteQuery(query, count);\r
- AppLog("the count is %d",count);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));\r
-\r
- r = CreateHistoryList(count, pHistoryList, 9);\r
- if (IsFailed(r))\r
- {\r
- AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));\r
- }\r
-\r
- CATCH: return r;\r
-}\r
-\r
-result\r
-HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)\r
-{\r
- int count = -1;\r
- int intVal = -1;\r
- String query;\r
- String historyTable(HISTORY_DATA_TABLE);\r
- result r = E_FAILURE;\r
- bool nextRowPresent = false;\r
-\r
- query.Append(L"SELECT COUNT(ADDRESS) FROM ");\r
- query.Append(historyTable);\r
- query.Append(L" WHERE ADDRESS = ");\r
- query.Append("'");\r
- query.Append(Url);\r
- query.Append("'");\r
-\r
- r = PresentationModelBase::ExecuteQuery(query, count);\r
- AppLog("the count is %d", count);\r
- TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));\r
-\r
- r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);\r
- if (IsFailed(r))\r
- return r;\r
- if (nextRowPresent == true)\r
- {\r
- r = PresentationModelBase::GetColumn(0, intVal);\r
- if (IsFailed(r))\r
- {\r
- AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));\r
- return r;\r
- }\r
- }\r
- historyCount = intVal;\r
-\r
- CATCH: return r;\r
-}\r
-\r
-String\r
-HistoryPresentationModel::GenerateFileName(void)\r
-{\r
- AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();\r
- if ( pAppRegistry == NULL )\r
- {\r
- return NULL ;\r
- }\r
- String keyCount("ThumbnailCount");\r
- String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";\r
- result r = E_SUCCESS;\r
- int keyValue = 1;\r
- r = pAppRegistry->Get(keyCount, keyValue);\r
-\r
- if (r == E_KEY_NOT_FOUND)\r
- {\r
- keyValue = 1;\r
- pAppRegistry->Add(keyCount, keyValue);\r
- }\r
- else\r
- {\r
- keyValue++;\r
- pAppRegistry->Set(keyCount, keyValue);\r
- }\r
-\r
- fileName.Append(keyValue);\r
- fileName.Append(".jpg");\r
- pAppRegistry->Save();\r
-\r
- return fileName;\r
-}\r
-\r
-String\r
-HistoryPresentationModel::GetStringFromDate(DateTime& date)\r
-{\r
- String dateFormat = L"";\r
- dateFormat.Append(date.GetYear());\r
- dateFormat.Append('-');\r
- if(date.GetMonth() < 10)\r
- {\r
- dateFormat.Append('0');\r
- }\r
- dateFormat.Append(date.GetMonth());\r
- dateFormat.Append('-');\r
- if(date.GetDay() < 10)\r
- {\r
- dateFormat.Append('0');\r
- }\r
- dateFormat.Append(date.GetDay());\r
- dateFormat.Append(' ');\r
- if(date.GetHour() < 10)\r
- {\r
- dateFormat.Append('0');\r
- }\r
- dateFormat.Append(date.GetHour());\r
- dateFormat.Append(':');\r
- if(date.GetMinute() < 10)\r
- {\r
- dateFormat.Append('0');\r
- }\r
- dateFormat.Append(date.GetMinute());\r
- dateFormat.Append(':');\r
- if(date.GetSecond() < 10)\r
- {\r
- dateFormat.Append('0');\r
- }\r
- dateFormat.Append(date.GetSecond());\r
- return dateFormat;\r
-}\r
+//
+
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.1 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+//!Internet
+/*@file: IntHistoryPresentationModel.cpp
+ *@brief: Provides functionalities to handle/maintain Browser History.
+ */
+
+#include <cstdlib>
+#include "IntHistoryData.h"
+#include "IntHistoryPresentationModel.h"
+#include "IntTypes.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Graphics;
+using namespace Tizen::Io;
+using namespace Tizen::Locales;
+using namespace Tizen::Media;
+using namespace Tizen::System;
+
+extern const wchar_t* HISTORY_DATA_TABLE;
+extern const wchar_t* BOOKMARK_URL_TABLE;
+
+HistoryPresentationModel* HistoryPresentationModel::__pHistoryPresentationModel = null;
+
+void HistoryPresentationModel::CreateInstance(void)
+{
+ if (__pHistoryPresentationModel == null)
+ __pHistoryPresentationModel = new(std::nothrow) HistoryPresentationModel();
+ result r = __pHistoryPresentationModel->Construct();
+ if (IsFailed(r))
+ {
+ delete __pHistoryPresentationModel;
+ __pHistoryPresentationModel = null;
+ return;
+ }
+ std::atexit(DestroyInstance);
+}
+
+
+HistoryPresentationModel* HistoryPresentationModel::GetInstance(void)
+{
+ if (__pHistoryPresentationModel == null)
+ {
+ CreateInstance();
+ }
+ return __pHistoryPresentationModel;
+
+}
+
+void HistoryPresentationModel::DestroyInstance(void)
+{
+ if (__pHistoryPresentationModel)
+ {
+ __pHistoryPresentationModel->UnInitialize();
+ delete __pHistoryPresentationModel;
+ __pHistoryPresentationModel = null;
+ }
+}
+
+HistoryPresentationModel::HistoryPresentationModel(void)
+{
+ __pDataList = null;
+}
+
+HistoryPresentationModel::~HistoryPresentationModel(void)
+{
+
+}
+
+HistoryPresentationModel::HistoryPresentationModel(const HistoryPresentationModel& historyModelObj)
+{
+
+}
+
+HistoryPresentationModel& HistoryPresentationModel::operator=(const HistoryPresentationModel& historyModelObj)
+{
+ return *this;
+}
+
+result
+HistoryPresentationModel::Construct(void)
+{
+ result r = E_SUCCESS;
+ DB_FILE_PATH = L"/opt/usr/dbspace/.browser-history.db";
+ r = PresentationModelBase::Initialize();
+ TryCatch( !IsFailed(r),,"Failed to initialize HistoryPresentationModel Model %s",GetErrorMessage(r));
+
+ CATCH: return r;
+
+}
+
+result
+HistoryPresentationModel::SaveHistory(History& history)
+{
+ AppLog("HistoryPresentationModel::saveHistory");
+ result r = E_FAILURE;
+ String historyTable(HISTORY_DATA_TABLE);
+ String query;
+ String columnNames;
+ String attachment;
+ int resultCount = -1;
+ int rowId = -1;
+ DateTime date;
+ String historyId;
+ int urlCount = 0;
+ ArrayList* pMostVisitedSites = null;
+ bool isAlreadyExist = false;
+ bool isEligibleForMostVisitedSites = true;
+ int count;
+ String thumbnailPath;
+ int todaysCount = 0;
+ DateTime todayStart;
+ DateTime todayEnd;
+ SystemTime::GetCurrentTime(todayStart);
+ SystemTime::GetCurrentTime(todayEnd);
+ todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
+ todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
+
+ ArrayList* pTodaysList = new(std::nothrow) ArrayList();
+ pTodaysList->Construct();
+ GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
+ GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
+
+ for(int count = 0; count < todaysCount; count++)
+ {
+ History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
+ //AppLog("HistoryPresentationModel::saveHistory pHistoryItem id is %ls",pHistoryItem->GetHistoryId().GetPointer());
+ AppLog("SaveHistory pHistoryItem url is %ls",pHistoryItem->GetHistoryUrl().GetPointer());
+ AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
+
+ if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
+ {
+ history.SetHistoryId(pHistoryItem->GetHistoryId());
+ AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
+ break;
+ }
+ }
+
+ pMostVisitedSites = new(std::nothrow) ArrayList();
+ pMostVisitedSites->Construct();
+ String historyTitle = history.GetHistoryTitle();
+ historyTitle.Replace(L"'", L"''");
+
+ String historyUrl = history.GetHistoryUrl();
+ historyUrl.Replace(L"'", L"''");
+
+ PresentationModelBase::GetCurrentDateTime(date);
+ GetMostVisitedSites(*pMostVisitedSites);
+ GetUrlCount(historyUrl, urlCount);
+ for (count = 0; count < pMostVisitedSites->GetCount(); count++)
+ {
+ History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(count));
+ if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
+ {
+ AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
+ isAlreadyExist = true;
+ break;
+ }
+ if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
+ {
+ isEligibleForMostVisitedSites = true;
+ }
+ else
+ {
+ isEligibleForMostVisitedSites = false;
+ }
+ }
+
+ if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
+ {
+ AppLog("HistoryPresentationModel::SaveHistory coming here");
+
+ thumbnailPath = GenerateFileName();
+ AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
+ Image* pImage = new(std::nothrow) Image();
+ pImage->Construct();
+ result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
+ delete pImage;
+ if(IsFailed(r))
+ {
+ AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
+ return r;
+ }
+ }
+ delete pMostVisitedSites;
+ pMostVisitedSites = NULL ;
+
+ String pFavArray;
+ ByteBuffer* pFavBuffer = history.GetFavIconBuffer();
+ if(pFavBuffer != null)
+ {
+ AppLog("Buffer found");
+ pFavBuffer->Flip();
+
+ wchar_t value;
+
+ AppLog("BookmarkPresentationModel::SaveBookmark 0 ");
+
+ while(pFavBuffer->HasRemaining())
+ {
+ pFavBuffer->GetWchar(value);
+ pFavArray.Append(value);
+ }
+ }
+
+ if (history.GetHistoryId() == "")
+ {
+ AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
+
+ columnNames.Append(L"ADDRESS, ");
+ columnNames.Append(L"TITLE, ");
+ columnNames.Append(L"VISITDATE, ");
+ columnNames.Append(L"FAVICON, ");
+ columnNames.Append(L"FAVICON_W, ");
+ columnNames.Append(L"FAVICON_H");
+
+ query.Append(L"INSERT INTO ");
+ query.Append(historyTable);
+ query.Append("(");
+ query.Append(columnNames);
+ query.Append(") ");
+ query.Append("VALUES(");
+ query.Append("'");
+ query.Append(historyUrl);
+ query.Append("'");
+ query.Append(", ");
+ query.Append("'");
+ query.Append(historyTitle);
+ query.Append("', ");
+ query.Append("DateTime(");
+ query.Append("'");
+ query.Append(GetStringFromDate(date));
+ query.Append(")', ");
+ query.Append("'");
+ query.Append(pFavArray);
+ query.Append("', ");
+ query.Append(history.GetFavIconWidth());
+ query.Append(", ");
+ query.Append(history.GetFavIconHeight());
+ query.Append(")");
+ }
+ else
+ {
+ query.Append(L"UPDATE ");
+ query.Append(historyTable);
+ query.Append(" SET ADDRESS = ");
+ query.Append("'");
+ query.Append(historyUrl);
+ query.Append("'");
+ query.Append(", TITLE = ");
+ query.Append("'");
+ query.Append(historyTitle);
+ query.Append("'");
+ query.Append(", VISITED_TIME = ");
+ query.Append("DateTime(");
+ query.Append("'");
+ query.Append(GetStringFromDate(date));
+ query.Append("')");
+ query.Append("', ");
+ query.Append("'");
+ query.Append(pFavArray);
+ query.Append("', ");
+ query.Append(history.GetFavIconWidth());
+ query.Append(", ");
+ query.Append(history.GetFavIconHeight());
+ query.Append(" WHERE ID = ");
+ query.Append(history.GetHistoryId());
+
+ }
+
+ AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
+
+ r = PresentationModelBase::ExecuteQuery(query, resultCount);
+ if (r == E_SUCCESS)
+ {
+ AppLog("HistoryPresentationModel::SaveHistory result is success");
+ }
+ else
+ {
+ AppLog("HistoryPresentationModel::SaveHistory result is failure");
+ }
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
+
+ r = PresentationModelBase::CommitDb();
+
+ r = GetLastInsertedId(historyTable, rowId);
+ if (IsFailed(r))
+ {
+ AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
+ return r;
+ }
+ if (rowId < 0)
+ return E_FAILURE;
+
+ historyId.Append(rowId);
+ if (historyId.GetLength() < 0)
+ {
+ return E_FAILURE;
+ }
+ //Set the generated ID to History
+ history.SetHistoryId(historyId);
+
+ CATCH: return r;
+}
+
+void HistoryPresentationModel::UpdateHistoryFavIcon(History& history, Tizen::Graphics::Bitmap& favIconImage)
+{
+ result r = E_FAILURE;
+ String historyTable(HISTORY_DATA_TABLE);
+ String query;
+ String columnNames;
+ int resultCount = -1;
+
+ Image* pImage = null;
+ pImage = new Image();
+ pImage->Construct();
+
+ Tizen::Base::ByteBuffer* pFavBuffer = pImage->EncodeToBufferN(favIconImage, IMG_FORMAT_PNG);
+ // added because conversion may fail
+ if(GetLastResult() != E_SUCCESS)
+ return;
+ delete pFavBuffer;
+ history.SetFavIconBitmap(favIconImage);
+
+ delete pImage;
+
+ query.Append(L"UPDATE ");
+ query.Append(historyTable);
+ query.Append(" SET FAVICON = ");
+ query.Append("?");
+ query.Append(", FAVICON_W = ");
+ query.Append("?");
+ query.Append(", FAVICON_H = ");
+ query.Append("?");
+ query.Append(" WHERE ID = ");
+ query.Append("?");
+
+ AppLog("query is %ls", query.GetPointer());
+
+ r = PresentationModelBase::ExecuteUpdateHistoryFavIconQuery(query, resultCount, history);
+ if (r == E_SUCCESS)
+ {
+ AppLog("HistoryPresentationModel::SaveHistory result is success");
+ }
+ else
+ {
+ AppLog("HistoryPresentationModel::SaveHistory result is failure");
+ }
+ r = PresentationModelBase::CommitDb();
+
+}
+
+result
+HistoryPresentationModel::SaveTempHistory(History& history)
+{
+ AppLog("HistoryPresentationModel::saveHistory");
+ result r = E_FAILURE;
+ String historyTable(HISTORY_DATA_TABLE);
+ String query;
+ String columnNames;
+ String attachment;
+ int resultCount = -1;
+ int rowId = -1;
+ DateTime date;
+ String historyId;
+ int urlCount = 0;
+ ArrayList* pMostVisitedSites = null;
+ bool isAlreadyExist = false;
+ bool isEligibleForMostVisitedSites = true;
+ int i;
+ String thumbnailPath;
+ int todaysCount = 0;
+ DateTime todayStart;
+ DateTime todayEnd;
+ SystemTime::GetCurrentTime(todayStart);
+ SystemTime::GetCurrentTime(todayEnd);
+ todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
+ todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
+
+ ArrayList* pTodaysList = new(std::nothrow) ArrayList();
+ pTodaysList->Construct();
+ GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
+ GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
+
+ for(int count = 0; count < todaysCount; count++)
+ {
+ History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
+ AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
+
+ if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
+ {
+ history.SetHistoryId(pHistoryItem->GetHistoryId());
+ AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
+ break;
+ }
+ }
+
+ if (pTodaysList)
+ {
+ pTodaysList->RemoveAll();
+ delete pTodaysList;
+ }
+
+ pMostVisitedSites = new(std::nothrow) ArrayList();
+ pMostVisitedSites->Construct();
+ String historyTitle = history.GetHistoryTitle();
+ historyTitle.Replace(L"'", L"''");
+
+ String historyUrl = history.GetHistoryUrl();
+ historyUrl.Replace(L"'", L"''");
+
+ PresentationModelBase::GetCurrentDateTime(date);
+ GetMostVisitedSites(*pMostVisitedSites);
+ GetUrlCount(historyUrl, urlCount);
+ for (i = 0; i < pMostVisitedSites->GetCount(); i++)
+ {
+ History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
+ if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
+ {
+ AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
+ isAlreadyExist = true;
+ break;
+ }
+ if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
+ {
+ isEligibleForMostVisitedSites = true;
+ }
+ else
+ {
+ isEligibleForMostVisitedSites = false;
+ }
+ }
+
+ if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
+ {
+ AppLog("HistoryPresentationModel::SaveHistory coming here");
+
+ thumbnailPath = GenerateFileName();
+ AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
+ Image* pImage = new(std::nothrow) Image();
+ pImage->Construct();
+ result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
+ delete pImage;
+ if(IsFailed(r))
+ {
+ AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
+ return r;
+ }
+ }
+ delete pMostVisitedSites;
+ pMostVisitedSites = NULL ;
+
+ if (history.GetHistoryId() == "")
+ {
+ AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
+
+ columnNames.Append(L"ADDRESS, ");
+ columnNames.Append(L"TITLE, ");
+ columnNames.Append(L"VISITDATE, ");
+ columnNames.Append(L"FAVICON, ");
+ columnNames.Append(L"FAVICON_W, ");
+ columnNames.Append(L"FAVICON_H");
+
+ query.Append(L"INSERT INTO ");
+ query.Append(historyTable);
+ query.Append("(");
+ query.Append(columnNames);
+ query.Append(") ");
+ query.Append("VALUES");
+ query.Append(" (?,?,?,?,?,?)");
+ }
+ else
+ {
+ query.Append(L"UPDATE ");
+ query.Append(historyTable);
+ query.Append(" SET ADDRESS = ");
+ query.Append("'");
+ query.Append(historyUrl);
+ query.Append("'");
+ query.Append(", TITLE = ");
+ query.Append("'");
+ query.Append(historyTitle);
+ query.Append("'");
+ query.Append(", VISITED_TIME = ");
+ query.Append("DateTime(");
+ query.Append("'");
+ query.Append(GetStringFromDate(date));
+ query.Append("')");
+ query.Append("'");
+ query.Append(" WHERE ID = ");
+ query.Append(history.GetHistoryId());
+ }
+
+ AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
+
+ r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
+ if (r == E_SUCCESS)
+ {
+ AppLog("HistoryPresentationModel::SaveHistory result is success");
+ }
+ else
+ {
+ AppLog("HistoryPresentationModel::SaveHistory result is failure");
+ }
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
+
+ r = PresentationModelBase::CommitDb();
+
+ r = GetLastInsertedId(historyTable, rowId);
+ if (IsFailed(r))
+ {
+ AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
+ return r;
+ }
+ if (rowId < 0)
+ return E_FAILURE;
+
+ historyId.Append(rowId);
+ if (historyId.GetLength() < 0)
+ {
+ return E_FAILURE;
+ }
+ //Set the generated ID to History
+ history.SetHistoryId(historyId);
+
+ if(__pDataList)
+ {
+ delete __pDataList;
+ __pDataList = null;
+ }
+
+ CATCH: return r;
+
+}
+
+result
+HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
+{
+ result r = E_FAILURE;
+ String query;
+ String historyTable = HISTORY_DATA_TABLE;
+ int resultCount = -1;
+
+ if (pHistoryIdList == null)
+ {
+ return E_FAILURE;
+ }
+
+ query.Append(L"DELETE FROM ");
+ query.Append(historyTable);
+ query.Append(" WHERE");
+ for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
+ {
+ query.Append(" ID = ");
+ String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
+ query.Append(*hisId);
+ query.Append(" OR ");
+ }
+ query.Append(" ID = ");
+ String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
+ if(hisId == null)
+ {
+ return E_FAILURE;
+ }
+ query.Append(*hisId);
+
+ r = PresentationModelBase::ExecuteQuery(query, resultCount);
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
+
+ r = PresentationModelBase::CommitDb();
+
+ if(__pDataList)
+ {
+ delete __pDataList;
+ __pDataList = null;
+ }
+
+ CATCH: return r;
+}
+
+result
+HistoryPresentationModel::DeleteHistory(const int historyId)
+{
+ result r = E_FAILURE;
+ String query;
+ String historyTable = HISTORY_DATA_TABLE;
+ int resultCount = -1;
+
+ if (historyId < 1)
+ {
+ return E_INVALID_ARG;
+ }
+
+ query.Append(L"DELETE FROM ");
+ query.Append(historyTable);
+ query.Append(" WHERE ID = ");
+ query.Append(historyId);
+
+ r = PresentationModelBase::ExecuteQuery(query, resultCount);
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
+
+ r = PresentationModelBase::CommitDb();
+
+ if(__pDataList)
+ {
+ delete __pDataList;
+ __pDataList = null;
+ }
+
+ CATCH: return r;
+}
+
+result
+HistoryPresentationModel::DeleteHistory(String& historyUrl)
+{
+ result r = E_FAILURE;
+ String query;
+ String historyTable = HISTORY_DATA_TABLE;
+ int resultCount = -1;
+
+ query.Append(L"DELETE FROM ");
+ query.Append(historyTable);
+ query.Append(" WHERE ADDRESS = '");
+ query.Append(historyUrl);
+ query.Append("'");
+
+ r = PresentationModelBase::ExecuteQuery(query, resultCount);
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
+
+ r = PresentationModelBase::CommitDb();
+
+ if(__pDataList)
+ {
+ delete __pDataList;
+ __pDataList = null;
+ }
+
+ CATCH: return r;
+}
+
+result
+HistoryPresentationModel::ClearHistory(void)
+{
+ result r = E_FAILURE;
+ String query;
+ String historyTable = HISTORY_DATA_TABLE;
+ int resultCount = -1;
+
+ query.Append(L"DELETE FROM ");
+ query.Append(historyTable);
+
+ r = PresentationModelBase::ExecuteQuery(query, resultCount);
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
+
+ r = PresentationModelBase::CommitDb();
+
+ CATCH: return r;
+}
+
+result
+HistoryPresentationModel::GetHistoryCount(int& historyCount)
+{
+ int count = -1;
+ int intVal = -1;
+ String query;
+ String historyTable(HISTORY_DATA_TABLE);
+ result r = E_FAILURE;
+ bool nextRowPresent = false;
+
+ query.Append(L"SELECT COUNT(ID) FROM ");
+ query.Append(historyTable);
+
+ r = PresentationModelBase::ExecuteQuery(query, count);
+ AppLog("the count is %d", count);
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
+
+ r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
+ if (IsFailed(r) != null)
+ return r;
+ if (nextRowPresent == true)
+ {
+ r = PresentationModelBase::GetColumn(0, intVal);
+ if (IsFailed(r) != null)
+ {
+ AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
+ return r;
+ }
+ }
+ historyCount = intVal;
+
+ CATCH: return r;
+}
+
+result
+HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
+{
+ int count = 0;
+ result r = E_SUCCESS;
+
+ if(__pDataList != null)
+ {
+ delete __pDataList;
+ __pDataList = null;
+ }
+
+ //if(__pDataList == null)
+ //{
+ __pDataList = new(std::nothrow) ArrayList();
+ __pDataList->Construct();
+
+ r = GetHistoryCount(count);
+ if(IsFailed(r))
+ {
+ return r;
+ }
+ if(count > 0)
+ {
+ r = GetHistory(0, count, *__pDataList);
+ if (IsFailed(r))
+ {
+ delete __pDataList;
+ __pDataList = null;
+ return r;
+ }
+ }
+ //}
+ //else
+ //{
+ count = __pDataList->GetCount();
+ //}
+
+ for (int counter = 0 ; counter < count; counter++)
+ {
+ History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
+ AppLog("vinayhistorytimecomparison %d, %d",pHistory->GetVisitedTime().CompareTo(startTime),pHistory->GetVisitedTime().CompareTo(endTime));
+ if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
+ {
+ historyCount++;
+ }
+ }
+ return r;
+}
+
+result
+HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
+{
+
+ int count = -1;
+ String query;
+ String historyTable(HISTORY_DATA_TABLE);
+ result r = E_FAILURE;
+
+ query.Append(L"SELECT * from ");
+ query.Append(historyTable);
+ query.Append(" ORDER BY VISITDATE DESC");
+
+
+ //Append LIMIT
+ if (limit > 0)
+ {
+ query.Append(" LIMIT ");
+ query.Append(limit);
+
+ //Append OFFESET
+ if (startIndex >= 0)
+ {
+ query.Append(" OFFSET ");
+ query.Append(startIndex);
+ }
+ }
+
+ r = PresentationModelBase::ExecuteQuery(query, count);
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
+
+ r = CreateHistoryList(count, pHistoryList);
+ if (IsFailed(r))
+ {
+ AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
+ }
+ CATCH: return r;
+}
+
+result
+HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
+{
+
+ History* pHistory = null;
+ int intVal = -1;
+ String stringVal;
+ DateTime dateVal;
+ result r = E_FAILURE;
+ String historyId;
+ String faviconId;
+ String bookmarkId;
+ int visitedCount;
+ DateTime visitedTime;
+ String iconPath;
+ String thumbnailPath;
+ bool nextRowPresent = false;
+ Image image;
+ Bitmap* pThumnailBitmap = null;
+ ByteBuffer *pFavIconBuffer;
+
+ image.Construct();
+ if (historyCount < 1)
+ {
+ return E_SUCCESS;
+ }
+
+ for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
+ {
+ r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
+ if (IsFailed(r))
+ {
+ return E_SUCCESS;
+ }
+ if (nextRowPresent == true)
+ {
+ pHistory = new(std::nothrow) History;
+ if (pHistory)
+ {
+ for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
+ {
+
+ switch (columnCount)
+ {
+ case HISTORY_ID:
+ r = PresentationModelBase::GetColumn(columnCount, intVal);
+ if (!IsFailed(r))
+ {
+ if (intVal > 0)
+ {
+ historyId.Clear();
+ historyId.Append(intVal);
+ if (historyId.GetLength() > 0)
+ {
+ pHistory->SetHistoryId(historyId);
+ }
+ }
+
+ }
+ break;
+ case HISTORY_URL:
+ r = PresentationModelBase::GetColumn(columnCount, stringVal);
+ if (!IsFailed(r))
+ {
+ pHistory->SetHistoryUrl(stringVal);
+ }
+ break;
+ case HISTORY_TITLE:
+ r = PresentationModelBase::GetColumn(columnCount, stringVal);
+ if (!IsFailed(r))
+ {
+ pHistory->SetHistoryTitle(stringVal);
+ }
+ break;
+
+ case HISTORY_VISITED_TIME:
+ r = PresentationModelBase::GetColumn(columnCount, dateVal);
+ if (!IsFailed(r))
+ {
+ visitedTime = dateVal;
+ pHistory->SetVisitedTime(visitedTime);
+ }
+ break;
+
+ case HISTORY_FAVICON:
+ {
+ pFavIconBuffer = new ByteBuffer();
+ r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
+ if (!IsFailed(r) && pFavIconBuffer->GetCapacity() > 0)
+ {
+ pHistory->SetFavIconBuffer(*pFavIconBuffer);
+ }
+ }
+ break;
+ case HISTORY_FAVICON_LENGTH:
+ {
+
+ }
+ break;
+ case HISTORY_FAVICON_W:
+ {
+ r = PresentationModelBase::GetColumn(columnCount, intVal);
+ if (!IsFailed(r))
+ {
+ if (intVal > 0)
+ {
+ pHistory->SetFavIconWidth(intVal);
+ }
+ }
+ }
+ break;
+ case HISTORY_FAVICON_H:
+ {
+ r = PresentationModelBase::GetColumn(columnCount, intVal);
+ if (!IsFailed(r))
+ {
+ if (intVal > 0)
+ {
+ pHistory->SetFavIconHeight(intVal);
+ }
+ }
+ }
+ break;
+
+ case HISTORY_VISITED_COUNT:
+ r = PresentationModelBase::GetColumn(columnCount, intVal);
+ if (!IsFailed(r))
+ {
+ if (intVal > 0)
+ {
+ pHistory->SetVisitedCount(intVal);
+
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ }
+ r = historyList.Add(*pHistory);
+
+ if (IsFailed(r))
+ {
+ delete pHistory;
+ return r;
+ }
+ }
+ }
+ }
+ return E_SUCCESS;
+}
+
+result
+HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
+{
+ DateTime endTime;
+ SystemTime::GetCurrentTime(endTime);
+
+ text.Replace(L"'", L"''");
+
+ int count = -1;
+ String query;
+ String historyTable(HISTORY_DATA_TABLE);
+ result r = E_FAILURE;
+
+ query.Append(L"SELECT ");
+ query.Append(historyTable);
+ query.Append(L".* ");
+ query.Append(L"FROM ");
+ query.Append(historyTable);
+ query.Append(L" WHERE (");
+ query.Append(historyTable);
+ query.Append(L".TITLE LIKE '%");
+ query.Append(text);
+ query.Append("%' ESCAPE '/')");
+ query.Append(" OR ");
+ query.Append(L"(");
+ query.Append(historyTable);
+ query.Append(L".ADDRESS LIKE '%");
+ query.Append(text);
+ query.Append("%' ESCAPE '/')");
+ query.Append(" ORDER BY VISITDATE DESC");
+
+
+ r = HistoryPresentationModel::ExecuteQuery(query, count);
+// TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
+
+ ArrayList pAllSearchList;
+
+ r = CreateHistoryList(count, pAllSearchList);
+
+ int itemsFoundIndex = -1;
+ for (int counter = 0 ; counter < count; counter++)
+ {
+ History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
+ if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
+ {
+ itemsFoundIndex++;
+ if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
+ {
+ pHistoryList.Add(*pHistory);
+ }
+ else if(itemsFoundIndex > (limit + startIndex))
+ {
+ break;
+ }
+ }
+ }
+
+
+ if (IsFailed(r))
+ {
+ AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
+ }
+ CATCH: return r;
+}
+
+result
+HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
+{
+ DateTime endTime;
+ SystemTime::GetCurrentTime(endTime);
+ text.Replace(L"'", L"''");
+
+ int count = -1;
+ String query;
+ String historyTable(HISTORY_DATA_TABLE);
+ result r = E_FAILURE;
+
+ query.Append(L"SELECT ");
+ query.Append(historyTable);
+ query.Append(L".* ");
+ query.Append(L"FROM ");
+ query.Append(historyTable);
+ query.Append(L" WHERE (");
+ query.Append(historyTable);
+ query.Append(L".TITLE LIKE '%");
+ query.Append(text);
+ query.Append("%'ESCAPE '/')");
+ query.Append(" OR ");
+ query.Append(L"(");
+ query.Append(historyTable);
+ query.Append(L".ADDRESS LIKE '%");
+ query.Append(text);
+ query.Append("%' ESCAPE '/')");
+ query.Append(" ORDER BY VISITDATE DESC");
+
+ r = HistoryPresentationModel::ExecuteQuery(query, count);
+// TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
+
+ ArrayList pAllSearchList;
+
+ r = CreateHistoryList(count, pAllSearchList);
+
+ historyCount = 0;
+ for (int counter = 0 ; counter < count; counter++)
+ {
+ History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
+ if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
+ {
+ historyCount++;
+ }
+ }
+
+
+ if (IsFailed(r))
+ {
+ AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
+ }
+ CATCH: return r;
+}
+
+result
+HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
+{
+ int count = 0;
+ result r = E_SUCCESS;
+ if(__pDataList == null)
+ {
+ __pDataList = new(std::nothrow) ArrayList();
+ __pDataList->Construct();
+
+ r = GetHistoryCount(count);
+ if(IsFailed(r))
+ {
+ return r;
+ }
+ if(count > 0)
+ {
+ r = GetHistory(0, count, *__pDataList);
+ if(IsFailed(r))
+ {
+ delete __pDataList;
+ __pDataList = null;
+ return r;
+ }
+ }
+ }
+ else
+ {
+ count = __pDataList->GetCount();
+ }
+ int itemsFoundIndex = -1;
+ for (int counter = 0 ; counter < count; counter++)
+ {
+ History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
+ if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
+ {
+ itemsFoundIndex++;
+ if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
+ {
+ pHistoryList.Add(*pHistory);
+ }
+ else if(itemsFoundIndex > (limit + startIndex))
+ {
+ break;
+ }
+ }
+ }
+ return r;
+}
+
+result
+HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
+{
+
+ int count = -1;
+ String query;
+ String historyTable(HISTORY_DATA_TABLE);
+ result r = E_FAILURE;
+
+
+ //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
+ query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
+
+ r = HistoryPresentationModel::ExecuteQuery(query, count);
+ AppLog("the count is %d",count);
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
+
+ r = CreateHistoryList(count, pHistoryList, 9);
+ if (IsFailed(r))
+ {
+ AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
+ }
+
+ CATCH: return r;
+}
+
+result
+HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
+{
+ int count = -1;
+ int intVal = -1;
+ String query;
+ String historyTable(HISTORY_DATA_TABLE);
+ result r = E_FAILURE;
+ bool nextRowPresent = false;
+
+ query.Append(L"SELECT COUNT(ADDRESS) FROM ");
+ query.Append(historyTable);
+ query.Append(L" WHERE ADDRESS = ");
+ query.Append("'");
+ query.Append(Url);
+ query.Append("'");
+
+ r = PresentationModelBase::ExecuteQuery(query, count);
+ AppLog("the count is %d", count);
+ TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
+
+ r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
+ if (IsFailed(r))
+ return r;
+ if (nextRowPresent == true)
+ {
+ r = PresentationModelBase::GetColumn(0, intVal);
+ if (IsFailed(r))
+ {
+ AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
+ return r;
+ }
+ }
+ historyCount = intVal;
+
+ CATCH: return r;
+}
+
+String
+HistoryPresentationModel::GenerateFileName(void)
+{
+ AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
+ if ( pAppRegistry == NULL )
+ {
+ return NULL ;
+ }
+ String keyCount("ThumbnailCount");
+ String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
+ result r = E_SUCCESS;
+ int keyValue = 1;
+ r = pAppRegistry->Get(keyCount, keyValue);
+
+ if (r == E_KEY_NOT_FOUND)
+ {
+ keyValue = 1;
+ pAppRegistry->Add(keyCount, keyValue);
+ }
+ else
+ {
+ keyValue++;
+ pAppRegistry->Set(keyCount, keyValue);
+ }
+
+ fileName.Append(keyValue);
+ fileName.Append(".jpg");
+ pAppRegistry->Save();
+
+ return fileName;
+}
+
+String
+HistoryPresentationModel::GetStringFromDate(DateTime& date)
+{
+ String dateFormat = L"";
+ dateFormat.Append(date.GetYear());
+ dateFormat.Append('-');
+ if(date.GetMonth() < 10)
+ {
+ dateFormat.Append('0');
+ }
+ dateFormat.Append(date.GetMonth());
+ dateFormat.Append('-');
+ if(date.GetDay() < 10)
+ {
+ dateFormat.Append('0');
+ }
+ dateFormat.Append(date.GetDay());
+ dateFormat.Append(' ');
+ if(date.GetHour() < 10)
+ {
+ dateFormat.Append('0');
+ }
+ dateFormat.Append(date.GetHour());
+ dateFormat.Append(':');
+ if(date.GetMinute() < 10)
+ {
+ dateFormat.Append('0');
+ }
+ dateFormat.Append(date.GetMinute());
+ dateFormat.Append(':');
+ if(date.GetSecond() < 10)
+ {
+ dateFormat.Append('0');
+ }
+ dateFormat.Append(date.GetSecond());
+ return dateFormat;
+}