Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntHistoryPresentationModel.cpp
index 737e294..cabc82f 100644 (file)
@@ -2,7 +2,7 @@
 
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// 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
 //
@@ -70,6 +70,7 @@ void HistoryPresentationModel::DestroyInstance(void)
 {
        if (__pHistoryPresentationModel)
        {
+               __pHistoryPresentationModel->UnInitialize();
                delete __pHistoryPresentationModel;
                __pHistoryPresentationModel = null;
        }
@@ -77,7 +78,7 @@ void HistoryPresentationModel::DestroyInstance(void)
 
 HistoryPresentationModel::HistoryPresentationModel(void)
 {
-
+       __pDataList = null;
 }
 
 HistoryPresentationModel::~HistoryPresentationModel(void)
@@ -124,7 +125,7 @@ HistoryPresentationModel::SaveHistory(History& history)
        ArrayList* pMostVisitedSites = null;
        bool isAlreadyExist = false;
        bool isEligibleForMostVisitedSites = true;
-       int i;
+       int count;
        String thumbnailPath;
        int todaysCount = 0;
        DateTime todayStart;
@@ -165,9 +166,9 @@ HistoryPresentationModel::SaveHistory(History& history)
        PresentationModelBase::GetCurrentDateTime(date);
        GetMostVisitedSites(*pMostVisitedSites);
        GetUrlCount(historyUrl, urlCount);
-       for (i = 0; i < pMostVisitedSites->GetCount(); i++)
+       for (count = 0; count < pMostVisitedSites->GetCount(); count++)
        {
-               History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
+               History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(count));
                if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
                {
                        AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
@@ -203,62 +204,34 @@ HistoryPresentationModel::SaveHistory(History& history)
        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"TITLE, ");
-               columnNames.Append(L"URL, ");
-               columnNames.Append(L"VISITED_TIME, ");
-               columnNames.Append(L"ICON_PATH, ");
-               columnNames.Append(L"FAVICON_ID, ");
-               columnNames.Append(L"THUMBNAIL_PATH");
 
-               query.Append(L"INSERT INTO ");
-               query.Append(historyTable);
-               query.Append("(");
-               query.Append(columnNames);
-               query.Append(") ");
-               query.Append("VALUES(");
-               query.Append("'");
-               query.Append(historyTitle);
-               query.Append("'");
-               query.Append(", ");
-               query.Append("'");
-               query.Append(historyUrl);
-               query.Append("', ");
-               query.Append("DateTime(");
-               query.Append("'");
-               query.Append(GetStringFromDate(date));
-               query.Append("'), ");
-               query.Append("'");
-               query.Append(history.GetHistoryIconPath());
-               query.Append("'");
-               query.Append(", ");
-               query.Append("'");
-               query.Append(history.GetFaviconId());
-               query.Append("'");
-               query.Append(", ");
-               query.Append("'");
-               query.Append(thumbnailPath);
-               query.Append("'");
-               query.Append(")");
-        */
                columnNames.Append(L"ADDRESS, ");
                columnNames.Append(L"TITLE, ");
-               //columnNames.Append(L"COUNTER, ");
-               columnNames.Append(L"VISITDATE");
-       //      columnNames.Append(L"FAVICON, ");
-       //      columnNames.Append(L"FAVICON_LENGTH, ");
-       //      columnNames.Append(L"FAVICON_W, ");
-       //      columnNames.Append(L"FAVICON_H, ");
-       //      columnNames.Append(L"SNAPSHOT, ");
-       //      columnNames.Append(L"SNAPSHOT_STRIDE, ");
-       //      columnNames.Append(L"SNAPSHOT_W, ");
-       //      columnNames.Append(L"SNAPSHOT_H");
-       //      columnNames.Append(L"ICON_PATH, ");
-       //      columnNames.Append(L"FAVICON_ID, ");
-       //      columnNames.Append(L"THUMBNAIL_PATH");
+               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);
@@ -276,53 +249,247 @@ HistoryPresentationModel::SaveHistory(History& history)
                query.Append("DateTime(");
                query.Append("'");
                query.Append(GetStringFromDate(date));
-               query.Append("'))");
-
-               //query.Append("'), ");
-               //query.Append("'");
-               //query.Append(history.GetHistoryIconPath());
-               //query.Append("'");
-               //query.Append(", ");
-               //query.Append("'");
-               //query.Append(history.GetFaviconId());
-               //query.Append("'");
-               //query.Append(", ");
-               //query.Append("'");
-               //query.Append(thumbnailPath);
-               //query.Append("'");
-               //query.Append(")");
+               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(L"UPDATE ");
                query.Append(historyTable);
-               query.Append(" SET TITLE = ");
+               query.Append(" SET ADDRESS = ");
                query.Append("'");
-               query.Append(historyTitle);
+               query.Append(historyUrl);
                query.Append("'");
-               query.Append(", URL = ");
+               query.Append(", TITLE = ");
                query.Append("'");
-               query.Append(historyUrl);
+               query.Append(historyTitle);
                query.Append("'");
                query.Append(", VISITED_TIME = ");
                query.Append("DateTime(");
                query.Append("'");
                query.Append(GetStringFromDate(date));
                query.Append("')");
-               query.Append(", ICON_PATH = ");
-               query.Append("'");
-               query.Append(history.GetHistoryIconPath());
-               query.Append("'");
-               query.Append(", ");
-               query.Append("'");
-               query.Append(history.GetFaviconId());
+               query.Append("', ");
                query.Append("'");
+               query.Append(pFavArray);
+               query.Append("', ");
+               query.Append(history.GetFavIconWidth());
                query.Append(", ");
-               query.Append("'");
-               query.Append(thumbnailPath);
-               query.Append("'");
+               query.Append(history.GetFavIconHeight());
                query.Append(" WHERE ID = ");
-               query.Append(history.GetHistoryId());*/
+               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 = ");
@@ -338,26 +505,14 @@ HistoryPresentationModel::SaveHistory(History& history)
                query.Append("'");
                query.Append(GetStringFromDate(date));
                query.Append("')");
-               /*query.Append(", ICON_PATH = ");
-               query.Append("'");
-               query.Append(history.GetHistoryIconPath());
-               query.Append("'");
-               query.Append(", ");
-               query.Append("'");
-               query.Append(history.GetFaviconId());
-               query.Append("'");
-               query.Append(", ");
-               query.Append("'");
-               query.Append(thumbnailPath);*/
                query.Append("'");
                query.Append(" WHERE ID = ");
                query.Append(history.GetHistoryId());
-
        }
 
        AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
 
-       r = PresentationModelBase::ExecuteQuery(query, resultCount);
+       r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
        if (r == E_SUCCESS)
        {
                AppLog("HistoryPresentationModel::SaveHistory result is success");
@@ -387,7 +542,14 @@ HistoryPresentationModel::SaveHistory(History& history)
        //Set the generated ID to History
        history.SetHistoryId(historyId);
 
+       if(__pDataList)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
+
        CATCH: return r;
+
 }
 
 result
@@ -426,6 +588,12 @@ HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
 
        r = PresentationModelBase::CommitDb();
 
+       if(__pDataList)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
+
        CATCH: return r;
 }
 
@@ -452,6 +620,12 @@ HistoryPresentationModel::DeleteHistory(const int historyId)
 
        r = PresentationModelBase::CommitDb();
 
+       if(__pDataList)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
+
        CATCH: return r;
 }
 
@@ -474,6 +648,12 @@ HistoryPresentationModel::DeleteHistory(String& historyUrl)
 
        r = PresentationModelBase::CommitDb();
 
+       if(__pDataList)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
+
        CATCH: return r;
 }
 
@@ -533,45 +713,51 @@ HistoryPresentationModel::GetHistoryCount(int& historyCount)
 result
 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
 {
+       int count = 0;
+       result r = E_SUCCESS;
 
-       int count = -1;
-       int intVal = -1;
-       String query;
-       String historyTable(HISTORY_DATA_TABLE);
-       result r = E_FAILURE;
-       bool nextRowPresent = false;
+       if(__pDataList != null)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
 
-       query.Append(L"SELECT COUNT(ID) FROM ");
-       query.Append(historyTable);
-       query.Append(" WHERE VISITDATE >= ");
-       query.Append("DateTime(");
-       query.Append("'");
-       query.Append(GetStringFromDate(startTime));
-       query.Append("')");
-       query.Append(" AND VISITDATE <= ");
-       query.Append("DateTime(");
-       query.Append("'");
-       query.Append(GetStringFromDate(endTime));
-       query.Append("')");
+       //if(__pDataList == null)
+       //{
+               __pDataList = new(std::nothrow) ArrayList();
+               __pDataList->Construct();
 
-       r = PresentationModelBase::ExecuteQuery(query, count);
-       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCountWithTimeRange query failed %s",GetErrorMessage(r));
+               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();
+       //}
 
-       r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
-       if (IsFailed(r))
-               return r;
-       if (nextRowPresent == true)
+       for (int counter = 0 ; counter < count; counter++)
        {
-               r = PresentationModelBase::GetColumn(0, intVal);
-               if (IsFailed(r))
+               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)
                {
-                       AppLogDebug("Error:PresentationModelBase::DbGetColumn:%s", GetErrorMessage(r));
-                       return r;
+                       historyCount++;
                }
        }
-       historyCount = intVal;
-
-       CATCH: return r;
+       return r;
 }
 
 result
@@ -583,43 +769,9 @@ HistoryPresentationModel::GetHistory(const int startIndex,const int limit, Array
        String historyTable(HISTORY_DATA_TABLE);
        result r = E_FAILURE;
 
-       query.Append(L"SELECT");
-       query.Append(historyTable);
-       query.Append(L".*, ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L".ID ");
-       query.Append(L"FROM ");
-       query.Append(historyTable);
-       query.Append(L", ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L" WHERE ");
-       query.Append(historyTable);
-       query.Append(L".ADDRESS ");
-       query.Append(L"IN");
-       query.Append(L"(");
-       query.Append(L"SELECT");
-       query.Append(historyTable);
-       query.Append(L".ADDRESS ");
-       query.Append(L"FROM ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L" LEFT JOIN ");
-       query.Append(historyTable);
-       query.Append(L"ON");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L".ADDRESS = ");
+       query.Append(L"SELECT * from ");
        query.Append(historyTable);
-       query.Append(L".ADDRESS ");
-       query.Append(" ORDER BY");
-       query.Append(historyTable);
-       query.Append(L".VISITDATE DESC");
-       query.Append(")");
-       query.Append(" GROUP BY ");
-       query.Append(historyTable);
-       query.Append(L".ADDRESS ");
-       query.Append(" ORDER BY");
-       query.Append(L"COUNT(");
-       query.Append(historyTable);
-       query.Append(L".ADDRESS) DESC ");
+       query.Append(" ORDER BY VISITDATE DESC");
 
 
        //Append LIMIT
@@ -666,6 +818,7 @@ HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& history
        bool nextRowPresent = false;
        Image image;
        Bitmap* pThumnailBitmap = null;
+       ByteBuffer *pFavIconBuffer;
 
        image.Construct();
        if (historyCount < 1)
@@ -720,6 +873,7 @@ HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& history
                                                        pHistory->SetHistoryTitle(stringVal);
                                                }
                                                break;
+
                                        case HISTORY_VISITED_TIME:
                                                r = PresentationModelBase::GetColumn(columnCount, dateVal);
                                                if (!IsFailed(r))
@@ -729,62 +883,46 @@ HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& history
                                                }
                                                break;
 
-                                               /*case HISTORY_ICON_PATH:
-                                                       r = PresentationModelBase::GetColumn(columnCount, stringVal);
-                                                       if (!IsFailed(r))
-                                                       {
-                                                               iconPath = stringVal;
-                                                               pHistory->SetIconPath(iconPath);
-                                                       }
-                                                       break;
-
-                                               case HISTORY_FAVICONID:
+                                       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:
+                                       {
 
-                                                       r = PresentationModelBase::GetColumn(columnCount, intVal);
-                                                       if (!IsFailed(r))
-                                                       {
-                                                               if (intVal >= 0)
-                                                               {
-                                                                       faviconId.Clear();
-                                                                       faviconId.Append(intVal);
-                                                                       if (faviconId.GetLength() > 0)
-                                                                       {
-                                                                               pHistory->SetFaviconId(faviconId);
-                                                                       }
-                                                               }
-                                                       }
-                                                       break;
-                                               case HISTORY_THUMBNAIL:
-                                                       r = PresentationModelBase::GetColumn(columnCount, stringVal);
-                                                       if (!IsFailed(r))
+                                       }
+                                       break;
+                                       case HISTORY_FAVICON_W:
+                                       {
+                                               r = PresentationModelBase::GetColumn(columnCount, intVal);
+                                               if (!IsFailed(r))
+                                               {
+                                                       if (intVal > 0)
                                                        {
-
-                                                               thumbnailPath = stringVal;
-                                                               pThumnailBitmap = image.DecodeN(thumbnailPath, BITMAP_PIXEL_FORMAT_RGB565);
-                                                               if (pThumnailBitmap != null)
-                                                               {
-                                                                       pHistory->SetThumbnail(pThumnailBitmap);
-                                                                       pHistory->SetThumbnailPath(thumbnailPath);
-                                                               }
+                                                               pHistory->SetFavIconWidth(intVal);
                                                        }
-                                                       break;*/
-                               /*      case HISTORY_BOOKMARK_ID:
+                                               }
+                                       }
+                                       break;
+                                       case HISTORY_FAVICON_H:
+                                       {
                                                r = PresentationModelBase::GetColumn(columnCount, intVal);
                                                if (!IsFailed(r))
                                                {
                                                        if (intVal > 0)
                                                        {
-                                                               bookmarkId.Clear();
-                                                               bookmarkId.Append(intVal);
-                                                               if (bookmarkId.GetLength() > 0)
-                                                               {
-                                                                       pHistory->SetBookmarkId(bookmarkId);
-                                                               }
+                                                               pHistory->SetFavIconHeight(intVal);
                                                        }
-
                                                }
-                                               break;
-                                               */
+                                       }
+                                       break;
+
                                        case HISTORY_VISITED_COUNT:
                                                r = PresentationModelBase::GetColumn(columnCount, intVal);
                                                if (!IsFailed(r))
@@ -794,7 +932,6 @@ HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& history
                                                                pHistory->SetVisitedCount(intVal);
 
                                                        }
-
                                                }
                                                break;
 
@@ -819,6 +956,9 @@ HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& history
 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;
@@ -835,33 +975,42 @@ HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit,
        query.Append(historyTable);
        query.Append(L".TITLE LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%' ESCAPE '/')");
        query.Append(" OR ");
        query.Append(L"(");
        query.Append(historyTable);
        query.Append(L".ADDRESS LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%' ESCAPE '/')");
        query.Append(" ORDER BY VISITDATE DESC");
 
-       //Append LIMIT
-       if (limit > 0)
-       {
-               query.Append(" LIMIT ");
-               query.Append(limit);
 
-               //Append OFFESET
-               if (startIndex >= 0)
+       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)
                {
-                       query.Append(" OFFSET ");
-                       query.Append(startIndex);
+                       itemsFoundIndex++;
+                       if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
+                       {
+                               pHistoryList.Add(*pHistory);
+                       }
+                       else if(itemsFoundIndex > (limit + startIndex))
+                       {
+                               break;
+                       }
                }
        }
 
-       r = HistoryPresentationModel::ExecuteQuery(query, count);
-       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
 
-       r = CreateHistoryList(count, pHistoryList);
        if (IsFailed(r))
        {
                AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
@@ -872,98 +1021,106 @@ HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit,
 result
 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
 {
+       DateTime endTime;
+       SystemTime::GetCurrentTime(endTime);
+       text.Replace(L"'", L"''");
+
        int count = -1;
-       int intVal = -1;
        String query;
        String historyTable(HISTORY_DATA_TABLE);
        result r = E_FAILURE;
-       bool nextRowPresent = false;
 
-       text.Replace(L"'", L"''");
-       query.Append(L"SELECT COUNT(ID) FROM ");
+       query.Append(L"SELECT ");
+       query.Append(historyTable);
+       query.Append(L".* ");
+       query.Append(L"FROM ");
        query.Append(historyTable);
-       query.Append(L" WHERE (TITLE LIKE '%");
+       query.Append(L" WHERE (");
+       query.Append(historyTable);
+       query.Append(L".TITLE LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%'ESCAPE '/')");
        query.Append(" OR ");
-       query.Append(L"(ADDRESS LIKE '%");
+       query.Append(L"(");
+       query.Append(historyTable);
+       query.Append(L".ADDRESS LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%' ESCAPE '/')");
+       query.Append(" ORDER BY VISITDATE DESC");
 
        r = HistoryPresentationModel::ExecuteQuery(query, count);
-       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));
+//     TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
 
-       r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);
-       if (IsFailed(r) != null)
-               return r;
-       if (nextRowPresent == true)
+       ArrayList pAllSearchList;
+
+       r = CreateHistoryList(count, pAllSearchList);
+
+       historyCount = 0;
+       for (int counter = 0 ; counter < count; counter++)
        {
-               r = HistoryPresentationModel::GetColumn(0, intVal);
-               if (IsFailed(r) != null)
+               History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
+               if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
                {
-                       AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));
-                       return r;
+                       historyCount++;
                }
        }
-       historyCount = intVal;
 
+
+       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 = -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(" WHERE ");
-       //query.Append(historyTable);
-       query.Append(L"VISITDATE >= ");
-       query.Append("DateTime(");
-       query.Append("'");
-       query.Append(GetStringFromDate(startTime));
-       query.Append("')");
-       query.Append(" AND ");
-       //query.Append(historyTable);
-       query.Append(L"VISITDATE <= ");
-       query.Append("DateTime(");
-       query.Append("'");
-       query.Append(GetStringFromDate(endTime));
-       query.Append("')");
-       query.Append(" ORDER BY VISITDATE DESC");
-
-       //Append LIMIT
-       if (limit > 0)
+       int count = 0;
+       result r = E_SUCCESS;
+       if(__pDataList == null)
        {
-               query.Append(" LIMIT ");
-               query.Append(limit);
+               __pDataList = new(std::nothrow) ArrayList();
+               __pDataList->Construct();
 
-               //Append OFFESET
-               if (startIndex >= 0)
+               r = GetHistoryCount(count);
+               if(IsFailed(r))
                {
-                       query.Append(" OFFSET ");
-                       query.Append(startIndex);
+                       return r;
+               }
+               if(count > 0)
+               {
+                       r = GetHistory(0, count, *__pDataList);
+                       if(IsFailed(r))
+                       {
+                               delete __pDataList;
+                               __pDataList = null;
+                               return r;
+                       }
                }
        }
-
-       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);
-       if (IsFailed(r))
+       else
        {
-               AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
+               count = __pDataList->GetCount();
        }
-
-       CATCH: return r;
+       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