Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntHistoryPresentationModel.cpp
index 6c592c6..cabc82f 100644 (file)
@@ -70,6 +70,7 @@ void HistoryPresentationModel::DestroyInstance(void)
 {
        if (__pHistoryPresentationModel)
        {
+               __pHistoryPresentationModel->UnInitialize();
                delete __pHistoryPresentationModel;
                __pHistoryPresentationModel = null;
        }
@@ -337,6 +338,7 @@ void HistoryPresentationModel::UpdateHistoryFavIcon(History& history, Tizen::Gra
        // added because conversion may fail
        if(GetLastResult() != E_SUCCESS)
                return;
+       delete pFavBuffer;
        history.SetFavIconBitmap(favIconImage);
 
        delete pImage;
@@ -412,6 +414,12 @@ HistoryPresentationModel::SaveTempHistory(History& history)
                }
        }
 
+       if (pTodaysList)
+       {
+               pTodaysList->RemoveAll();
+               delete pTodaysList;
+       }
+
        pMostVisitedSites = new(std::nothrow) ArrayList();
        pMostVisitedSites->Construct();
        String historyTitle = history.GetHistoryTitle();
@@ -879,7 +887,7 @@ HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& history
                                        {
                                                pFavIconBuffer = new ByteBuffer();
                                                r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
-                                               if (!IsFailed(r))
+                                               if (!IsFailed(r) && pFavIconBuffer->GetCapacity() > 0)
                                                {
                                                        pHistory->SetFavIconBuffer(*pFavIconBuffer);
                                                }
@@ -948,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;
@@ -964,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));
@@ -1001,41 +1021,55 @@ 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 (");
        query.Append(historyTable);
-       query.Append(L" WHERE (TITLE LIKE '%");
+       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;
 }