3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 /*@file: IntHistoryPresentationModel.cpp
21 *@brief: Provides functionalities to handle/maintain Browser History.
25 #include "IntHistoryData.h"
26 #include "IntHistoryPresentationModel.h"
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Base::Utility;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Io;
35 using namespace Tizen::Locales;
36 using namespace Tizen::Media;
37 using namespace Tizen::System;
39 extern const wchar_t* HISTORY_DATA_TABLE;
40 extern const wchar_t* BOOKMARK_URL_TABLE;
42 HistoryPresentationModel* HistoryPresentationModel::__pHistoryPresentationModel = null;
44 void HistoryPresentationModel::CreateInstance(void)
46 if (__pHistoryPresentationModel == null)
47 __pHistoryPresentationModel = new(std::nothrow) HistoryPresentationModel();
48 result r = __pHistoryPresentationModel->Construct();
51 delete __pHistoryPresentationModel;
52 __pHistoryPresentationModel = null;
55 std::atexit(DestroyInstance);
59 HistoryPresentationModel* HistoryPresentationModel::GetInstance(void)
61 if (__pHistoryPresentationModel == null)
65 return __pHistoryPresentationModel;
69 void HistoryPresentationModel::DestroyInstance(void)
71 if (__pHistoryPresentationModel)
73 delete __pHistoryPresentationModel;
74 __pHistoryPresentationModel = null;
78 HistoryPresentationModel::HistoryPresentationModel(void)
83 HistoryPresentationModel::~HistoryPresentationModel(void)
88 HistoryPresentationModel::HistoryPresentationModel(const HistoryPresentationModel& historyModelObj)
93 HistoryPresentationModel& HistoryPresentationModel::operator=(const HistoryPresentationModel& historyModelObj)
99 HistoryPresentationModel::Construct(void)
101 result r = E_SUCCESS;
102 DB_FILE_PATH = L"/opt/usr/dbspace/.browser-history.db";
103 r = PresentationModelBase::Initialize();
104 TryCatch( !IsFailed(r),,"Failed to initialize HistoryPresentationModel Model %s",GetErrorMessage(r));
111 HistoryPresentationModel::SaveHistory(History& history)
113 AppLog("HistoryPresentationModel::saveHistory");
114 result r = E_FAILURE;
115 String historyTable(HISTORY_DATA_TABLE);
119 int resultCount = -1;
124 ArrayList* pMostVisitedSites = null;
125 bool isAlreadyExist = false;
126 bool isEligibleForMostVisitedSites = true;
128 String thumbnailPath;
132 SystemTime::GetCurrentTime(todayStart);
133 SystemTime::GetCurrentTime(todayEnd);
134 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
135 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
137 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
138 pTodaysList->Construct();
139 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
140 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
142 for(int count = 0; count < todaysCount; count++)
144 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
145 //AppLog("HistoryPresentationModel::saveHistory pHistoryItem id is %ls",pHistoryItem->GetHistoryId().GetPointer());
146 AppLog("SaveHistory pHistoryItem url is %ls",pHistoryItem->GetHistoryUrl().GetPointer());
147 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
149 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
151 history.SetHistoryId(pHistoryItem->GetHistoryId());
152 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
157 pMostVisitedSites = new(std::nothrow) ArrayList();
158 pMostVisitedSites->Construct();
159 String historyTitle = history.GetHistoryTitle();
160 historyTitle.Replace(L"'", L"''");
162 String historyUrl = history.GetHistoryUrl();
163 historyUrl.Replace(L"'", L"''");
165 PresentationModelBase::GetCurrentDateTime(date);
166 GetMostVisitedSites(*pMostVisitedSites);
167 GetUrlCount(historyUrl, urlCount);
168 for (count = 0; count < pMostVisitedSites->GetCount(); count++)
170 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(count));
171 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
173 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
174 isAlreadyExist = true;
177 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
179 isEligibleForMostVisitedSites = true;
183 isEligibleForMostVisitedSites = false;
187 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
189 AppLog("HistoryPresentationModel::SaveHistory coming here");
191 thumbnailPath = GenerateFileName();
192 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
193 Image* pImage = new(std::nothrow) Image();
195 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
199 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
203 delete pMostVisitedSites;
204 pMostVisitedSites = NULL ;
207 ByteBuffer* pFavBuffer = history.GetFavIconBuffer();
208 if(pFavBuffer != null)
210 AppLog("Buffer found");
215 AppLog("BookmarkPresentationModel::SaveBookmark 0 ");
217 while(pFavBuffer->HasRemaining())
219 pFavBuffer->GetWchar(value);
220 pFavArray.Append(value);
224 if (history.GetHistoryId() == "")
226 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
228 columnNames.Append(L"ADDRESS, ");
229 columnNames.Append(L"TITLE, ");
230 columnNames.Append(L"VISITDATE, ");
231 columnNames.Append(L"FAVICON, ");
232 columnNames.Append(L"FAVICON_W, ");
233 columnNames.Append(L"FAVICON_H");
235 query.Append(L"INSERT INTO ");
236 query.Append(historyTable);
238 query.Append(columnNames);
240 query.Append("VALUES(");
242 query.Append(historyUrl);
246 query.Append(historyTitle);
248 query.Append("DateTime(");
250 query.Append(GetStringFromDate(date));
251 query.Append(")', ");
253 query.Append(pFavArray);
255 query.Append(history.GetFavIconWidth());
257 query.Append(history.GetFavIconHeight());
262 query.Append(L"UPDATE ");
263 query.Append(historyTable);
264 query.Append(" SET ADDRESS = ");
266 query.Append(historyUrl);
268 query.Append(", TITLE = ");
270 query.Append(historyTitle);
272 query.Append(", VISITED_TIME = ");
273 query.Append("DateTime(");
275 query.Append(GetStringFromDate(date));
279 query.Append(pFavArray);
281 query.Append(history.GetFavIconWidth());
283 query.Append(history.GetFavIconHeight());
284 query.Append(" WHERE ID = ");
285 query.Append(history.GetHistoryId());
289 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
291 r = PresentationModelBase::ExecuteQuery(query, resultCount);
294 AppLog("HistoryPresentationModel::SaveHistory result is success");
298 AppLog("HistoryPresentationModel::SaveHistory result is failure");
300 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
302 r = PresentationModelBase::CommitDb();
304 r = GetLastInsertedId(historyTable, rowId);
307 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
313 historyId.Append(rowId);
314 if (historyId.GetLength() < 0)
318 //Set the generated ID to History
319 history.SetHistoryId(historyId);
325 HistoryPresentationModel::SaveTempHistory(History& history)
327 AppLog("HistoryPresentationModel::saveHistory");
328 result r = E_FAILURE;
329 String historyTable(HISTORY_DATA_TABLE);
333 int resultCount = -1;
338 ArrayList* pMostVisitedSites = null;
339 bool isAlreadyExist = false;
340 bool isEligibleForMostVisitedSites = true;
342 String thumbnailPath;
346 SystemTime::GetCurrentTime(todayStart);
347 SystemTime::GetCurrentTime(todayEnd);
348 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
349 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
351 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
352 pTodaysList->Construct();
353 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
354 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
356 for(int count = 0; count < todaysCount; count++)
358 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
359 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
361 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
363 history.SetHistoryId(pHistoryItem->GetHistoryId());
364 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
369 pMostVisitedSites = new(std::nothrow) ArrayList();
370 pMostVisitedSites->Construct();
371 String historyTitle = history.GetHistoryTitle();
372 historyTitle.Replace(L"'", L"''");
374 String historyUrl = history.GetHistoryUrl();
375 historyUrl.Replace(L"'", L"''");
377 PresentationModelBase::GetCurrentDateTime(date);
378 GetMostVisitedSites(*pMostVisitedSites);
379 GetUrlCount(historyUrl, urlCount);
380 for (i = 0; i < pMostVisitedSites->GetCount(); i++)
382 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
383 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
385 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
386 isAlreadyExist = true;
389 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
391 isEligibleForMostVisitedSites = true;
395 isEligibleForMostVisitedSites = false;
399 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
401 AppLog("HistoryPresentationModel::SaveHistory coming here");
403 thumbnailPath = GenerateFileName();
404 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
405 Image* pImage = new(std::nothrow) Image();
407 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
411 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
415 delete pMostVisitedSites;
416 pMostVisitedSites = NULL ;
418 if (history.GetHistoryId() == "")
420 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
422 columnNames.Append(L"ADDRESS, ");
423 columnNames.Append(L"TITLE, ");
424 columnNames.Append(L"VISITDATE, ");
425 columnNames.Append(L"FAVICON, ");
426 columnNames.Append(L"FAVICON_W, ");
427 columnNames.Append(L"FAVICON_H");
429 query.Append(L"INSERT INTO ");
430 query.Append(historyTable);
432 query.Append(columnNames);
434 query.Append("VALUES");
435 query.Append(" (?,?,?,?,?,?)");
439 query.Append(L"UPDATE ");
440 query.Append(historyTable);
441 query.Append(" SET ADDRESS = ");
443 query.Append(historyUrl);
445 query.Append(", TITLE = ");
447 query.Append(historyTitle);
449 query.Append(", VISITED_TIME = ");
450 query.Append("DateTime(");
452 query.Append(GetStringFromDate(date));
455 query.Append(" WHERE ID = ");
456 query.Append(history.GetHistoryId());
459 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
461 r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
464 AppLog("HistoryPresentationModel::SaveHistory result is success");
468 AppLog("HistoryPresentationModel::SaveHistory result is failure");
470 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
472 r = PresentationModelBase::CommitDb();
474 r = GetLastInsertedId(historyTable, rowId);
477 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
483 historyId.Append(rowId);
484 if (historyId.GetLength() < 0)
488 //Set the generated ID to History
489 history.SetHistoryId(historyId);
502 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
504 result r = E_FAILURE;
506 String historyTable = HISTORY_DATA_TABLE;
507 int resultCount = -1;
509 if (pHistoryIdList == null)
514 query.Append(L"DELETE FROM ");
515 query.Append(historyTable);
516 query.Append(" WHERE");
517 for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
519 query.Append(" ID = ");
520 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
521 query.Append(*hisId);
522 query.Append(" OR ");
524 query.Append(" ID = ");
525 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
530 query.Append(*hisId);
532 r = PresentationModelBase::ExecuteQuery(query, resultCount);
533 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
535 r = PresentationModelBase::CommitDb();
547 HistoryPresentationModel::DeleteHistory(const int historyId)
549 result r = E_FAILURE;
551 String historyTable = HISTORY_DATA_TABLE;
552 int resultCount = -1;
556 return E_INVALID_ARG;
559 query.Append(L"DELETE FROM ");
560 query.Append(historyTable);
561 query.Append(" WHERE ID = ");
562 query.Append(historyId);
564 r = PresentationModelBase::ExecuteQuery(query, resultCount);
565 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
567 r = PresentationModelBase::CommitDb();
579 HistoryPresentationModel::DeleteHistory(String& historyUrl)
581 result r = E_FAILURE;
583 String historyTable = HISTORY_DATA_TABLE;
584 int resultCount = -1;
586 query.Append(L"DELETE FROM ");
587 query.Append(historyTable);
588 query.Append(" WHERE ADDRESS = '");
589 query.Append(historyUrl);
592 r = PresentationModelBase::ExecuteQuery(query, resultCount);
593 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
595 r = PresentationModelBase::CommitDb();
607 HistoryPresentationModel::ClearHistory(void)
609 result r = E_FAILURE;
611 String historyTable = HISTORY_DATA_TABLE;
612 int resultCount = -1;
614 query.Append(L"DELETE FROM ");
615 query.Append(historyTable);
617 r = PresentationModelBase::ExecuteQuery(query, resultCount);
618 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
620 r = PresentationModelBase::CommitDb();
626 HistoryPresentationModel::GetHistoryCount(int& historyCount)
631 String historyTable(HISTORY_DATA_TABLE);
632 result r = E_FAILURE;
633 bool nextRowPresent = false;
635 query.Append(L"SELECT COUNT(ID) FROM ");
636 query.Append(historyTable);
638 r = PresentationModelBase::ExecuteQuery(query, count);
639 AppLog("the count is %d", count);
640 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
642 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
643 if (IsFailed(r) != null)
645 if (nextRowPresent == true)
647 r = PresentationModelBase::GetColumn(0, intVal);
648 if (IsFailed(r) != null)
650 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
654 historyCount = intVal;
660 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
663 result r = E_SUCCESS;
665 if(__pDataList != null)
671 //if(__pDataList == null)
673 __pDataList = new(std::nothrow) ArrayList();
674 __pDataList->Construct();
676 r = GetHistoryCount(count);
683 r = GetHistory(0, count, *__pDataList);
692 count = __pDataList->GetCount();
695 for (int counter = 0 ; counter < count; counter++)
697 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
698 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
707 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
712 String historyTable(HISTORY_DATA_TABLE);
713 result r = E_FAILURE;
715 query.Append(L"SELECT * from ");
716 query.Append(historyTable);
717 query.Append(" ORDER BY VISITDATE DESC");
723 query.Append(" LIMIT ");
729 query.Append(" OFFSET ");
730 query.Append(startIndex);
734 r = PresentationModelBase::ExecuteQuery(query, count);
735 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
737 r = CreateHistoryList(count, pHistoryList);
740 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
746 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
749 History* pHistory = null;
753 result r = E_FAILURE;
758 DateTime visitedTime;
760 String thumbnailPath;
761 bool nextRowPresent = false;
763 Bitmap* pThumnailBitmap = null;
764 ByteBuffer *pFavIconBuffer;
767 if (historyCount < 1)
772 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
774 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
779 if (nextRowPresent == true)
781 pHistory = new(std::nothrow) History;
784 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
790 r = PresentationModelBase::GetColumn(columnCount, intVal);
796 historyId.Append(intVal);
797 if (historyId.GetLength() > 0)
799 pHistory->SetHistoryId(historyId);
806 r = PresentationModelBase::GetColumn(columnCount, stringVal);
809 pHistory->SetHistoryUrl(stringVal);
813 r = PresentationModelBase::GetColumn(columnCount, stringVal);
816 pHistory->SetHistoryTitle(stringVal);
820 case HISTORY_VISITED_TIME:
821 r = PresentationModelBase::GetColumn(columnCount, dateVal);
824 visitedTime = dateVal;
825 pHistory->SetVisitedTime(visitedTime);
829 case HISTORY_FAVICON:
831 pFavIconBuffer = new ByteBuffer();
832 r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
835 pHistory->SetFavIconBuffer(*pFavIconBuffer);
839 case HISTORY_FAVICON_LENGTH:
844 case HISTORY_FAVICON_W:
846 r = PresentationModelBase::GetColumn(columnCount, intVal);
851 pHistory->SetFavIconWidth(intVal);
856 case HISTORY_FAVICON_H:
858 r = PresentationModelBase::GetColumn(columnCount, intVal);
863 pHistory->SetFavIconHeight(intVal);
869 case HISTORY_VISITED_COUNT:
870 r = PresentationModelBase::GetColumn(columnCount, intVal);
875 pHistory->SetVisitedCount(intVal);
886 r = historyList.Add(*pHistory);
900 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
902 text.Replace(L"'", L"''");
906 String historyTable(HISTORY_DATA_TABLE);
907 result r = E_FAILURE;
909 query.Append(L"SELECT ");
910 query.Append(historyTable);
911 query.Append(L".* ");
912 query.Append(L"FROM ");
913 query.Append(historyTable);
914 query.Append(L" WHERE (");
915 query.Append(historyTable);
916 query.Append(L".TITLE LIKE '%");
919 query.Append(" OR ");
921 query.Append(historyTable);
922 query.Append(L".ADDRESS LIKE '%");
925 query.Append(" ORDER BY VISITDATE DESC");
930 query.Append(" LIMIT ");
936 query.Append(" OFFSET ");
937 query.Append(startIndex);
941 r = HistoryPresentationModel::ExecuteQuery(query, count);
942 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
944 r = CreateHistoryList(count, pHistoryList);
947 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
953 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
958 String historyTable(HISTORY_DATA_TABLE);
959 result r = E_FAILURE;
960 bool nextRowPresent = false;
962 text.Replace(L"'", L"''");
963 query.Append(L"SELECT COUNT(ID) FROM ");
964 query.Append(historyTable);
965 query.Append(L" WHERE (TITLE LIKE '%");
968 query.Append(" OR ");
969 query.Append(L"(ADDRESS LIKE '%");
973 r = HistoryPresentationModel::ExecuteQuery(query, count);
974 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));
976 r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);
977 if (IsFailed(r) != null)
979 if (nextRowPresent == true)
981 r = HistoryPresentationModel::GetColumn(0, intVal);
982 if (IsFailed(r) != null)
984 AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));
988 historyCount = intVal;
994 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
997 result r = E_SUCCESS;
998 if(__pDataList == null)
1000 __pDataList = new(std::nothrow) ArrayList();
1001 __pDataList->Construct();
1003 r = GetHistoryCount(count);
1010 r = GetHistory(0, count, *__pDataList);
1019 count = __pDataList->GetCount();
1021 int itemsFoundIndex = -1;
1022 for (int counter = 0 ; counter < count; counter++)
1024 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
1025 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1028 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1030 pHistoryList.Add(*pHistory);
1032 else if(itemsFoundIndex > (limit + startIndex))
1042 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
1047 String historyTable(HISTORY_DATA_TABLE);
1048 result r = E_FAILURE;
1051 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
1052 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
1054 r = HistoryPresentationModel::ExecuteQuery(query, count);
1055 AppLog("the count is %d",count);
1056 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
1058 r = CreateHistoryList(count, pHistoryList, 9);
1061 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1068 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
1073 String historyTable(HISTORY_DATA_TABLE);
1074 result r = E_FAILURE;
1075 bool nextRowPresent = false;
1077 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
1078 query.Append(historyTable);
1079 query.Append(L" WHERE ADDRESS = ");
1084 r = PresentationModelBase::ExecuteQuery(query, count);
1085 AppLog("the count is %d", count);
1086 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
1088 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
1091 if (nextRowPresent == true)
1093 r = PresentationModelBase::GetColumn(0, intVal);
1096 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
1100 historyCount = intVal;
1106 HistoryPresentationModel::GenerateFileName(void)
1108 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
1109 if ( pAppRegistry == NULL )
1113 String keyCount("ThumbnailCount");
1114 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
1115 result r = E_SUCCESS;
1117 r = pAppRegistry->Get(keyCount, keyValue);
1119 if (r == E_KEY_NOT_FOUND)
1122 pAppRegistry->Add(keyCount, keyValue);
1127 pAppRegistry->Set(keyCount, keyValue);
1130 fileName.Append(keyValue);
1131 fileName.Append(".jpg");
1132 pAppRegistry->Save();
1138 HistoryPresentationModel::GetStringFromDate(DateTime& date)
1140 String dateFormat = L"";
1141 dateFormat.Append(date.GetYear());
1142 dateFormat.Append('-');
1143 if(date.GetMonth() < 10)
1145 dateFormat.Append('0');
1147 dateFormat.Append(date.GetMonth());
1148 dateFormat.Append('-');
1149 if(date.GetDay() < 10)
1151 dateFormat.Append('0');
1153 dateFormat.Append(date.GetDay());
1154 dateFormat.Append(' ');
1155 if(date.GetHour() < 10)
1157 dateFormat.Append('0');
1159 dateFormat.Append(date.GetHour());
1160 dateFormat.Append(':');
1161 if(date.GetMinute() < 10)
1163 dateFormat.Append('0');
1165 dateFormat.Append(date.GetMinute());
1166 dateFormat.Append(':');
1167 if(date.GetSecond() < 10)
1169 dateFormat.Append('0');
1171 dateFormat.Append(date.GetSecond());