3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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 __pHistoryPresentationModel->UnInitialize();
74 delete __pHistoryPresentationModel;
75 __pHistoryPresentationModel = null;
79 HistoryPresentationModel::HistoryPresentationModel(void)
84 HistoryPresentationModel::~HistoryPresentationModel(void)
89 HistoryPresentationModel::HistoryPresentationModel(const HistoryPresentationModel& historyModelObj)
94 HistoryPresentationModel& HistoryPresentationModel::operator=(const HistoryPresentationModel& historyModelObj)
100 HistoryPresentationModel::Construct(void)
102 result r = E_SUCCESS;
103 DB_FILE_PATH = L"/opt/usr/dbspace/.browser-history.db";
104 r = PresentationModelBase::Initialize();
105 TryCatch( !IsFailed(r),,"Failed to initialize HistoryPresentationModel Model %s",GetErrorMessage(r));
112 HistoryPresentationModel::SaveHistory(History& history)
114 AppLog("HistoryPresentationModel::saveHistory");
115 result r = E_FAILURE;
116 String historyTable(HISTORY_DATA_TABLE);
120 int resultCount = -1;
125 ArrayList* pMostVisitedSites = null;
126 bool isAlreadyExist = false;
127 bool isEligibleForMostVisitedSites = true;
129 String thumbnailPath;
133 SystemTime::GetCurrentTime(todayStart);
134 SystemTime::GetCurrentTime(todayEnd);
135 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
136 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
138 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
139 pTodaysList->Construct();
140 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
141 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
143 for (int count = 0; count < todaysCount; count++)
145 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
147 if (pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
149 AppLog("SaveHistory pHistoryItem url is %ls",pHistoryItem->GetHistoryUrl().GetPointer());
150 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
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);
324 void HistoryPresentationModel::UpdateHistoryFavIcon(History& history, Tizen::Graphics::Bitmap& favIconImage)
326 result r = E_FAILURE;
327 String historyTable(HISTORY_DATA_TABLE);
330 int resultCount = -1;
332 Image* pImage = null;
333 pImage = new Image();
336 Tizen::Base::ByteBuffer* pFavBuffer = pImage->EncodeToBufferN(favIconImage, IMG_FORMAT_PNG);
337 // added because conversion may fail
338 if (GetLastResult() != E_SUCCESS)
344 history.SetFavIconBitmap(favIconImage);
348 query.Append(L"UPDATE ");
349 query.Append(historyTable);
350 query.Append(" SET FAVICON = ");
352 query.Append(", FAVICON_W = ");
354 query.Append(", FAVICON_H = ");
356 query.Append(" WHERE ID = ");
359 AppLog("query is %ls", query.GetPointer());
361 r = PresentationModelBase::ExecuteUpdateHistoryFavIconQuery(query, resultCount, history);
364 AppLog("HistoryPresentationModel::SaveHistory result is success");
368 AppLog("HistoryPresentationModel::SaveHistory result is failure");
370 r = PresentationModelBase::CommitDb();
375 HistoryPresentationModel::SaveTempHistory(History& history)
377 AppLog("HistoryPresentationModel::saveHistory");
378 result r = E_FAILURE;
379 String historyTable(HISTORY_DATA_TABLE);
383 int resultCount = -1;
388 ArrayList* pMostVisitedSites = null;
389 bool isAlreadyExist = false;
390 bool isEligibleForMostVisitedSites = true;
392 String thumbnailPath;
396 SystemTime::GetCurrentTime(todayStart);
397 SystemTime::GetCurrentTime(todayEnd);
398 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
399 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
401 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
402 pTodaysList->Construct();
403 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
404 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
406 for(int count = 0; count < todaysCount; count++)
408 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
409 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
411 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
413 history.SetHistoryId(pHistoryItem->GetHistoryId());
414 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
421 pTodaysList->RemoveAll();
425 pMostVisitedSites = new(std::nothrow) ArrayList();
426 pMostVisitedSites->Construct();
427 String historyTitle = history.GetHistoryTitle();
428 historyTitle.Replace(L"'", L"''");
430 String historyUrl = history.GetHistoryUrl();
431 historyUrl.Replace(L"'", L"''");
433 PresentationModelBase::GetCurrentDateTime(date);
434 GetMostVisitedSites(*pMostVisitedSites);
435 GetUrlCount(historyUrl, urlCount);
436 for (i = 0; i < pMostVisitedSites->GetCount(); i++)
438 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
439 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
441 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
442 isAlreadyExist = true;
445 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
447 isEligibleForMostVisitedSites = true;
451 isEligibleForMostVisitedSites = false;
455 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
457 AppLog("HistoryPresentationModel::SaveHistory coming here");
459 thumbnailPath = GenerateFileName();
460 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
461 Image* pImage = new(std::nothrow) Image();
463 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
467 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
471 delete pMostVisitedSites;
472 pMostVisitedSites = NULL ;
474 if (history.GetHistoryId() == "")
476 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
478 columnNames.Append(L"ADDRESS, ");
479 columnNames.Append(L"TITLE, ");
480 columnNames.Append(L"VISITDATE, ");
481 columnNames.Append(L"FAVICON, ");
482 columnNames.Append(L"FAVICON_W, ");
483 columnNames.Append(L"FAVICON_H");
485 query.Append(L"INSERT INTO ");
486 query.Append(historyTable);
488 query.Append(columnNames);
490 query.Append("VALUES");
491 query.Append(" (?,?,?,?,?,?)");
495 query.Append(L"UPDATE ");
496 query.Append(historyTable);
497 query.Append(" SET ADDRESS = ");
499 query.Append(historyUrl);
501 query.Append(", TITLE = ");
503 query.Append(historyTitle);
505 query.Append(", VISITED_TIME = ");
506 query.Append("DateTime(");
508 query.Append(GetStringFromDate(date));
511 query.Append(" WHERE ID = ");
512 query.Append(history.GetHistoryId());
515 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
517 r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
520 AppLog("HistoryPresentationModel::SaveHistory result is success");
524 AppLog("HistoryPresentationModel::SaveHistory result is failure");
526 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
528 r = PresentationModelBase::CommitDb();
530 r = GetLastInsertedId(historyTable, rowId);
533 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
539 historyId.Append(rowId);
540 if (historyId.GetLength() < 0)
544 //Set the generated ID to History
545 history.SetHistoryId(historyId);
558 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
560 result r = E_FAILURE;
562 String historyTable = HISTORY_DATA_TABLE;
563 int resultCount = -1;
565 if (pHistoryIdList == null)
570 query.Append(L"DELETE FROM ");
571 query.Append(historyTable);
572 query.Append(" WHERE");
573 for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
575 query.Append(" ID = ");
576 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
577 query.Append(*hisId);
578 query.Append(" OR ");
580 query.Append(" ID = ");
581 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
586 query.Append(*hisId);
588 r = PresentationModelBase::ExecuteQuery(query, resultCount);
589 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
591 r = PresentationModelBase::CommitDb();
603 HistoryPresentationModel::DeleteHistory(const int historyId)
605 result r = E_FAILURE;
607 String historyTable = HISTORY_DATA_TABLE;
608 int resultCount = -1;
612 return E_INVALID_ARG;
615 query.Append(L"DELETE FROM ");
616 query.Append(historyTable);
617 query.Append(" WHERE ID = ");
618 query.Append(historyId);
620 r = PresentationModelBase::ExecuteQuery(query, resultCount);
621 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
623 r = PresentationModelBase::CommitDb();
635 HistoryPresentationModel::DeleteHistory(String& historyUrl)
637 result r = E_FAILURE;
639 String historyTable = HISTORY_DATA_TABLE;
640 int resultCount = -1;
642 query.Append(L"DELETE FROM ");
643 query.Append(historyTable);
644 query.Append(" WHERE ADDRESS = '");
645 query.Append(historyUrl);
648 r = PresentationModelBase::ExecuteQuery(query, resultCount);
649 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
651 r = PresentationModelBase::CommitDb();
663 HistoryPresentationModel::ClearHistory(void)
665 result r = E_FAILURE;
667 String historyTable = HISTORY_DATA_TABLE;
668 int resultCount = -1;
670 query.Append(L"DELETE FROM ");
671 query.Append(historyTable);
673 r = PresentationModelBase::ExecuteQuery(query, resultCount);
674 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
676 r = PresentationModelBase::CommitDb();
682 HistoryPresentationModel::GetHistoryCount(int& historyCount)
687 String historyTable(HISTORY_DATA_TABLE);
688 result r = E_FAILURE;
689 bool nextRowPresent = false;
691 query.Append(L"SELECT COUNT(ID) FROM ");
692 query.Append(historyTable);
694 r = PresentationModelBase::ExecuteQuery(query, count);
695 AppLog("the count is %d", count);
696 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
698 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
699 if (IsFailed(r) != null)
701 if (nextRowPresent == true)
703 r = PresentationModelBase::GetColumn(0, intVal);
704 if (IsFailed(r) != null)
706 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
710 historyCount = intVal;
716 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
719 result r = E_SUCCESS;
721 if(__pDataList != null)
727 //if(__pDataList == null)
729 __pDataList = new(std::nothrow) ArrayList();
730 __pDataList->Construct();
732 r = GetHistoryCount(count);
739 r = GetHistory(0, count, *__pDataList);
750 count = __pDataList->GetCount();
753 for (int counter = 0 ; counter < count; counter++)
755 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
757 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
766 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
771 String historyTable(HISTORY_DATA_TABLE);
772 result r = E_FAILURE;
774 query.Append(L"SELECT * from ");
775 query.Append(historyTable);
776 query.Append(" ORDER BY VISITDATE DESC");
782 query.Append(" LIMIT ");
788 query.Append(" OFFSET ");
789 query.Append(startIndex);
793 r = PresentationModelBase::ExecuteQuery(query, count);
794 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
796 r = CreateHistoryList(count, pHistoryList);
799 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
805 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
808 History* pHistory = null;
812 result r = E_FAILURE;
817 DateTime visitedTime;
819 String thumbnailPath;
820 bool nextRowPresent = false;
822 Bitmap* pThumnailBitmap = null;
823 ByteBuffer *pFavIconBuffer;
826 if (historyCount < 1)
831 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
833 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
838 if (nextRowPresent == true)
840 pHistory = new(std::nothrow) History;
843 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
849 r = PresentationModelBase::GetColumn(columnCount, intVal);
855 historyId.Append(intVal);
856 if (historyId.GetLength() > 0)
858 pHistory->SetHistoryId(historyId);
865 r = PresentationModelBase::GetColumn(columnCount, stringVal);
868 pHistory->SetHistoryUrl(stringVal);
872 r = PresentationModelBase::GetColumn(columnCount, stringVal);
875 pHistory->SetHistoryTitle(stringVal);
879 case HISTORY_VISITED_TIME:
880 r = PresentationModelBase::GetColumn(columnCount, dateVal);
883 visitedTime = dateVal;
884 pHistory->SetVisitedTime(visitedTime);
888 case HISTORY_FAVICON:
890 pFavIconBuffer = new ByteBuffer();
891 r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
892 if (!IsFailed(r) && pFavIconBuffer->GetCapacity() > 0)
894 pHistory->SetFavIconBuffer(*pFavIconBuffer);
898 case HISTORY_FAVICON_LENGTH:
903 case HISTORY_FAVICON_W:
905 r = PresentationModelBase::GetColumn(columnCount, intVal);
910 pHistory->SetFavIconWidth(intVal);
915 case HISTORY_FAVICON_H:
917 r = PresentationModelBase::GetColumn(columnCount, intVal);
922 pHistory->SetFavIconHeight(intVal);
928 case HISTORY_VISITED_COUNT:
929 r = PresentationModelBase::GetColumn(columnCount, intVal);
934 pHistory->SetVisitedCount(intVal);
945 r = historyList.Add(*pHistory);
959 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
962 SystemTime::GetCurrentTime(endTime);
964 text.Replace(L"'", L"''");
968 String historyTable(HISTORY_DATA_TABLE);
969 result r = E_FAILURE;
971 query.Append(L"SELECT ");
972 query.Append(historyTable);
973 query.Append(L".* ");
974 query.Append(L"FROM ");
975 query.Append(historyTable);
976 query.Append(L" WHERE (");
977 query.Append(historyTable);
978 query.Append(L".TITLE LIKE '%");
980 query.Append("%' ESCAPE '/')");
981 query.Append(" OR ");
983 query.Append(historyTable);
984 query.Append(L".ADDRESS LIKE '%");
986 query.Append("%' ESCAPE '/')");
987 query.Append(" ORDER BY VISITDATE DESC");
990 r = HistoryPresentationModel::ExecuteQuery(query, count);
991 // TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
993 ArrayList pAllSearchList;
995 r = CreateHistoryList(count, pAllSearchList);
997 int itemsFoundIndex = -1;
998 for (int counter = 0 ; counter < count; counter++)
1000 History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
1001 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1004 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1006 pHistoryList.Add(*pHistory);
1008 else if(itemsFoundIndex > (limit + startIndex))
1018 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1024 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
1027 SystemTime::GetCurrentTime(endTime);
1028 text.Replace(L"'", L"''");
1032 String historyTable(HISTORY_DATA_TABLE);
1033 result r = E_FAILURE;
1035 query.Append(L"SELECT ");
1036 query.Append(historyTable);
1037 query.Append(L".* ");
1038 query.Append(L"FROM ");
1039 query.Append(historyTable);
1040 query.Append(L" WHERE (");
1041 query.Append(historyTable);
1042 query.Append(L".TITLE LIKE '%");
1044 query.Append("%'ESCAPE '/')");
1045 query.Append(" OR ");
1047 query.Append(historyTable);
1048 query.Append(L".ADDRESS LIKE '%");
1050 query.Append("%' ESCAPE '/')");
1051 query.Append(" ORDER BY VISITDATE DESC");
1053 r = HistoryPresentationModel::ExecuteQuery(query, count);
1054 // TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
1056 ArrayList pAllSearchList;
1058 r = CreateHistoryList(count, pAllSearchList);
1061 for (int counter = 0 ; counter < count; counter++)
1063 History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
1064 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1073 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1079 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
1082 result r = E_SUCCESS;
1083 if(__pDataList == null)
1085 __pDataList = new(std::nothrow) ArrayList();
1086 __pDataList->Construct();
1088 r = GetHistoryCount(count);
1095 r = GetHistory(0, count, *__pDataList);
1106 count = __pDataList->GetCount();
1108 int itemsFoundIndex = -1;
1109 for (int counter = 0 ; counter < count; counter++)
1111 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
1112 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1115 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1117 pHistoryList.Add(*pHistory);
1119 else if(itemsFoundIndex > (limit + startIndex))
1129 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
1134 String historyTable(HISTORY_DATA_TABLE);
1135 result r = E_FAILURE;
1138 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
1139 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
1141 r = HistoryPresentationModel::ExecuteQuery(query, count);
1142 AppLog("the count is %d",count);
1143 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
1145 r = CreateHistoryList(count, pHistoryList, 9);
1148 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1155 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
1160 String historyTable(HISTORY_DATA_TABLE);
1161 result r = E_FAILURE;
1162 bool nextRowPresent = false;
1164 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
1165 query.Append(historyTable);
1166 query.Append(L" WHERE ADDRESS = ");
1171 r = PresentationModelBase::ExecuteQuery(query, count);
1172 AppLog("the count is %d", count);
1173 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
1175 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
1178 if (nextRowPresent == true)
1180 r = PresentationModelBase::GetColumn(0, intVal);
1183 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
1187 historyCount = intVal;
1193 HistoryPresentationModel::GenerateFileName(void)
1195 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
1196 if ( pAppRegistry == NULL )
1200 String keyCount("ThumbnailCount");
1201 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail";
1202 result r = E_SUCCESS;
1205 fileName.Append(L"/thumbnails");
1206 r = pAppRegistry->Get(keyCount, keyValue);
1208 if (r == E_KEY_NOT_FOUND)
1211 pAppRegistry->Add(keyCount, keyValue);
1216 pAppRegistry->Set(keyCount, keyValue);
1219 fileName.Append(keyValue);
1220 fileName.Append(".jpg");
1221 pAppRegistry->Save();
1227 HistoryPresentationModel::GetStringFromDate(DateTime& date)
1229 String dateFormat = L"";
1230 dateFormat.Append(date.GetYear());
1231 dateFormat.Append('-');
1232 if(date.GetMonth() < 10)
1234 dateFormat.Append('0');
1236 dateFormat.Append(date.GetMonth());
1237 dateFormat.Append('-');
1238 if(date.GetDay() < 10)
1240 dateFormat.Append('0');
1242 dateFormat.Append(date.GetDay());
1243 dateFormat.Append(' ');
1244 if(date.GetHour() < 10)
1246 dateFormat.Append('0');
1248 dateFormat.Append(date.GetHour());
1249 dateFormat.Append(':');
1250 if(date.GetMinute() < 10)
1252 dateFormat.Append('0');
1254 dateFormat.Append(date.GetMinute());
1255 dateFormat.Append(':');
1256 if(date.GetSecond() < 10)
1258 dateFormat.Append('0');
1260 dateFormat.Append(date.GetSecond());