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 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);
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)
341 history.SetFavIconBitmap(favIconImage);
345 query.Append(L"UPDATE ");
346 query.Append(historyTable);
347 query.Append(" SET FAVICON = ");
349 query.Append(", FAVICON_W = ");
351 query.Append(", FAVICON_H = ");
353 query.Append(" WHERE ID = ");
356 AppLog("query is %ls", query.GetPointer());
358 r = PresentationModelBase::ExecuteUpdateHistoryFavIconQuery(query, resultCount, history);
361 AppLog("HistoryPresentationModel::SaveHistory result is success");
365 AppLog("HistoryPresentationModel::SaveHistory result is failure");
367 r = PresentationModelBase::CommitDb();
372 HistoryPresentationModel::SaveTempHistory(History& history)
374 AppLog("HistoryPresentationModel::saveHistory");
375 result r = E_FAILURE;
376 String historyTable(HISTORY_DATA_TABLE);
380 int resultCount = -1;
385 ArrayList* pMostVisitedSites = null;
386 bool isAlreadyExist = false;
387 bool isEligibleForMostVisitedSites = true;
389 String thumbnailPath;
393 SystemTime::GetCurrentTime(todayStart);
394 SystemTime::GetCurrentTime(todayEnd);
395 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
396 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
398 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
399 pTodaysList->Construct();
400 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
401 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
403 for(int count = 0; count < todaysCount; count++)
405 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
406 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
408 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
410 history.SetHistoryId(pHistoryItem->GetHistoryId());
411 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
416 pMostVisitedSites = new(std::nothrow) ArrayList();
417 pMostVisitedSites->Construct();
418 String historyTitle = history.GetHistoryTitle();
419 historyTitle.Replace(L"'", L"''");
421 String historyUrl = history.GetHistoryUrl();
422 historyUrl.Replace(L"'", L"''");
424 PresentationModelBase::GetCurrentDateTime(date);
425 GetMostVisitedSites(*pMostVisitedSites);
426 GetUrlCount(historyUrl, urlCount);
427 for (i = 0; i < pMostVisitedSites->GetCount(); i++)
429 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
430 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
432 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
433 isAlreadyExist = true;
436 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
438 isEligibleForMostVisitedSites = true;
442 isEligibleForMostVisitedSites = false;
446 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
448 AppLog("HistoryPresentationModel::SaveHistory coming here");
450 thumbnailPath = GenerateFileName();
451 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
452 Image* pImage = new(std::nothrow) Image();
454 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
458 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
462 delete pMostVisitedSites;
463 pMostVisitedSites = NULL ;
465 if (history.GetHistoryId() == "")
467 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
469 columnNames.Append(L"ADDRESS, ");
470 columnNames.Append(L"TITLE, ");
471 columnNames.Append(L"VISITDATE, ");
472 columnNames.Append(L"FAVICON, ");
473 columnNames.Append(L"FAVICON_W, ");
474 columnNames.Append(L"FAVICON_H");
476 query.Append(L"INSERT INTO ");
477 query.Append(historyTable);
479 query.Append(columnNames);
481 query.Append("VALUES");
482 query.Append(" (?,?,?,?,?,?)");
486 query.Append(L"UPDATE ");
487 query.Append(historyTable);
488 query.Append(" SET ADDRESS = ");
490 query.Append(historyUrl);
492 query.Append(", TITLE = ");
494 query.Append(historyTitle);
496 query.Append(", VISITED_TIME = ");
497 query.Append("DateTime(");
499 query.Append(GetStringFromDate(date));
502 query.Append(" WHERE ID = ");
503 query.Append(history.GetHistoryId());
506 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
508 r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
511 AppLog("HistoryPresentationModel::SaveHistory result is success");
515 AppLog("HistoryPresentationModel::SaveHistory result is failure");
517 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
519 r = PresentationModelBase::CommitDb();
521 r = GetLastInsertedId(historyTable, rowId);
524 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
530 historyId.Append(rowId);
531 if (historyId.GetLength() < 0)
535 //Set the generated ID to History
536 history.SetHistoryId(historyId);
549 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
551 result r = E_FAILURE;
553 String historyTable = HISTORY_DATA_TABLE;
554 int resultCount = -1;
556 if (pHistoryIdList == null)
561 query.Append(L"DELETE FROM ");
562 query.Append(historyTable);
563 query.Append(" WHERE");
564 for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
566 query.Append(" ID = ");
567 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
568 query.Append(*hisId);
569 query.Append(" OR ");
571 query.Append(" ID = ");
572 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
577 query.Append(*hisId);
579 r = PresentationModelBase::ExecuteQuery(query, resultCount);
580 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
582 r = PresentationModelBase::CommitDb();
594 HistoryPresentationModel::DeleteHistory(const int historyId)
596 result r = E_FAILURE;
598 String historyTable = HISTORY_DATA_TABLE;
599 int resultCount = -1;
603 return E_INVALID_ARG;
606 query.Append(L"DELETE FROM ");
607 query.Append(historyTable);
608 query.Append(" WHERE ID = ");
609 query.Append(historyId);
611 r = PresentationModelBase::ExecuteQuery(query, resultCount);
612 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
614 r = PresentationModelBase::CommitDb();
626 HistoryPresentationModel::DeleteHistory(String& historyUrl)
628 result r = E_FAILURE;
630 String historyTable = HISTORY_DATA_TABLE;
631 int resultCount = -1;
633 query.Append(L"DELETE FROM ");
634 query.Append(historyTable);
635 query.Append(" WHERE ADDRESS = '");
636 query.Append(historyUrl);
639 r = PresentationModelBase::ExecuteQuery(query, resultCount);
640 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
642 r = PresentationModelBase::CommitDb();
654 HistoryPresentationModel::ClearHistory(void)
656 result r = E_FAILURE;
658 String historyTable = HISTORY_DATA_TABLE;
659 int resultCount = -1;
661 query.Append(L"DELETE FROM ");
662 query.Append(historyTable);
664 r = PresentationModelBase::ExecuteQuery(query, resultCount);
665 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
667 r = PresentationModelBase::CommitDb();
673 HistoryPresentationModel::GetHistoryCount(int& historyCount)
678 String historyTable(HISTORY_DATA_TABLE);
679 result r = E_FAILURE;
680 bool nextRowPresent = false;
682 query.Append(L"SELECT COUNT(ID) FROM ");
683 query.Append(historyTable);
685 r = PresentationModelBase::ExecuteQuery(query, count);
686 AppLog("the count is %d", count);
687 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
689 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
690 if (IsFailed(r) != null)
692 if (nextRowPresent == true)
694 r = PresentationModelBase::GetColumn(0, intVal);
695 if (IsFailed(r) != null)
697 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
701 historyCount = intVal;
707 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
710 result r = E_SUCCESS;
712 if(__pDataList != null)
718 //if(__pDataList == null)
720 __pDataList = new(std::nothrow) ArrayList();
721 __pDataList->Construct();
723 r = GetHistoryCount(count);
730 r = GetHistory(0, count, *__pDataList);
741 count = __pDataList->GetCount();
744 for (int counter = 0 ; counter < count; counter++)
746 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
747 AppLog("vinayhistorytimecomparison %d, %d",pHistory->GetVisitedTime().CompareTo(startTime),pHistory->GetVisitedTime().CompareTo(endTime));
748 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
757 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
762 String historyTable(HISTORY_DATA_TABLE);
763 result r = E_FAILURE;
765 query.Append(L"SELECT * from ");
766 query.Append(historyTable);
767 query.Append(" ORDER BY VISITDATE DESC");
773 query.Append(" LIMIT ");
779 query.Append(" OFFSET ");
780 query.Append(startIndex);
784 r = PresentationModelBase::ExecuteQuery(query, count);
785 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
787 r = CreateHistoryList(count, pHistoryList);
790 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
796 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
799 History* pHistory = null;
803 result r = E_FAILURE;
808 DateTime visitedTime;
810 String thumbnailPath;
811 bool nextRowPresent = false;
813 Bitmap* pThumnailBitmap = null;
814 ByteBuffer *pFavIconBuffer;
817 if (historyCount < 1)
822 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
824 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
829 if (nextRowPresent == true)
831 pHistory = new(std::nothrow) History;
834 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
840 r = PresentationModelBase::GetColumn(columnCount, intVal);
846 historyId.Append(intVal);
847 if (historyId.GetLength() > 0)
849 pHistory->SetHistoryId(historyId);
856 r = PresentationModelBase::GetColumn(columnCount, stringVal);
859 pHistory->SetHistoryUrl(stringVal);
863 r = PresentationModelBase::GetColumn(columnCount, stringVal);
866 pHistory->SetHistoryTitle(stringVal);
870 case HISTORY_VISITED_TIME:
871 r = PresentationModelBase::GetColumn(columnCount, dateVal);
874 visitedTime = dateVal;
875 pHistory->SetVisitedTime(visitedTime);
879 case HISTORY_FAVICON:
881 pFavIconBuffer = new ByteBuffer();
882 r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
885 pHistory->SetFavIconBuffer(*pFavIconBuffer);
889 case HISTORY_FAVICON_LENGTH:
894 case HISTORY_FAVICON_W:
896 r = PresentationModelBase::GetColumn(columnCount, intVal);
901 pHistory->SetFavIconWidth(intVal);
906 case HISTORY_FAVICON_H:
908 r = PresentationModelBase::GetColumn(columnCount, intVal);
913 pHistory->SetFavIconHeight(intVal);
919 case HISTORY_VISITED_COUNT:
920 r = PresentationModelBase::GetColumn(columnCount, intVal);
925 pHistory->SetVisitedCount(intVal);
936 r = historyList.Add(*pHistory);
950 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
953 SystemTime::GetCurrentTime(endTime);
955 text.Replace(L"'", L"''");
959 String historyTable(HISTORY_DATA_TABLE);
960 result r = E_FAILURE;
962 query.Append(L"SELECT ");
963 query.Append(historyTable);
964 query.Append(L".* ");
965 query.Append(L"FROM ");
966 query.Append(historyTable);
967 query.Append(L" WHERE (");
968 query.Append(historyTable);
969 query.Append(L".TITLE LIKE '%");
971 query.Append("%' ESCAPE '/')");
972 query.Append(" OR ");
974 query.Append(historyTable);
975 query.Append(L".ADDRESS LIKE '%");
977 query.Append("%' ESCAPE '/')");
978 query.Append(" ORDER BY VISITDATE DESC");
981 r = HistoryPresentationModel::ExecuteQuery(query, count);
982 // TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
984 ArrayList pAllSearchList;
986 r = CreateHistoryList(count, pAllSearchList);
988 int itemsFoundIndex = -1;
989 for (int counter = 0 ; counter < count; counter++)
991 History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
992 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
995 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
997 pHistoryList.Add(*pHistory);
999 else if(itemsFoundIndex > (limit + startIndex))
1009 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1015 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
1018 SystemTime::GetCurrentTime(endTime);
1019 text.Replace(L"'", L"''");
1023 String historyTable(HISTORY_DATA_TABLE);
1024 result r = E_FAILURE;
1026 query.Append(L"SELECT ");
1027 query.Append(historyTable);
1028 query.Append(L".* ");
1029 query.Append(L"FROM ");
1030 query.Append(historyTable);
1031 query.Append(L" WHERE (");
1032 query.Append(historyTable);
1033 query.Append(L".TITLE LIKE '%");
1035 query.Append("% 'ESCAPE '/')");
1036 query.Append(" OR ");
1038 query.Append(historyTable);
1039 query.Append(L".ADDRESS LIKE '%");
1041 query.Append("%' ESCAPE '/')");
1042 query.Append(" ORDER BY VISITDATE DESC");
1044 r = HistoryPresentationModel::ExecuteQuery(query, count);
1045 // TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
1047 ArrayList pAllSearchList;
1049 r = CreateHistoryList(count, pAllSearchList);
1052 for (int counter = 0 ; counter < count; counter++)
1054 History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
1055 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1064 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1070 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
1073 result r = E_SUCCESS;
1074 if(__pDataList == null)
1076 __pDataList = new(std::nothrow) ArrayList();
1077 __pDataList->Construct();
1079 r = GetHistoryCount(count);
1086 r = GetHistory(0, count, *__pDataList);
1097 count = __pDataList->GetCount();
1099 int itemsFoundIndex = -1;
1100 for (int counter = 0 ; counter < count; counter++)
1102 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
1103 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1106 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1108 pHistoryList.Add(*pHistory);
1110 else if(itemsFoundIndex > (limit + startIndex))
1120 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
1124 String historyTable(HISTORY_DATA_TABLE);
1125 result r = E_FAILURE;
1128 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
1129 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
1131 r = HistoryPresentationModel::ExecuteQuery(query, count);
1132 AppLog("the count is %d",count);
1133 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
1135 r = CreateHistoryList(count, pHistoryList, 9);
1138 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1145 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
1150 String historyTable(HISTORY_DATA_TABLE);
1151 result r = E_FAILURE;
1152 bool nextRowPresent = false;
1154 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
1155 query.Append(historyTable);
1156 query.Append(L" WHERE ADDRESS = ");
1161 r = PresentationModelBase::ExecuteQuery(query, count);
1162 AppLog("the count is %d", count);
1163 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
1165 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
1168 if (nextRowPresent == true)
1170 r = PresentationModelBase::GetColumn(0, intVal);
1173 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
1177 historyCount = intVal;
1183 HistoryPresentationModel::GenerateFileName(void)
1185 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
1186 if ( pAppRegistry == NULL )
1190 String keyCount("ThumbnailCount");
1191 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
1192 result r = E_SUCCESS;
1194 r = pAppRegistry->Get(keyCount, keyValue);
1196 if (r == E_KEY_NOT_FOUND)
1199 pAppRegistry->Add(keyCount, keyValue);
1204 pAppRegistry->Set(keyCount, keyValue);
1207 fileName.Append(keyValue);
1208 fileName.Append(".jpg");
1209 pAppRegistry->Save();
1215 HistoryPresentationModel::GetStringFromDate(DateTime& date)
1217 String dateFormat = L"";
1218 dateFormat.Append(date.GetYear());
1219 dateFormat.Append('-');
1220 if(date.GetMonth() < 10)
1222 dateFormat.Append('0');
1224 dateFormat.Append(date.GetMonth());
1225 dateFormat.Append('-');
1226 if(date.GetDay() < 10)
1228 dateFormat.Append('0');
1230 dateFormat.Append(date.GetDay());
1231 dateFormat.Append(' ');
1232 if(date.GetHour() < 10)
1234 dateFormat.Append('0');
1236 dateFormat.Append(date.GetHour());
1237 dateFormat.Append(':');
1238 if(date.GetMinute() < 10)
1240 dateFormat.Append('0');
1242 dateFormat.Append(date.GetMinute());
1243 dateFormat.Append(':');
1244 if(date.GetSecond() < 10)
1246 dateFormat.Append('0');
1248 dateFormat.Append(date.GetSecond());