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 history.SetFavIconBitmap(favIconImage);
341 query.Append(L"UPDATE ");
342 query.Append(historyTable);
343 query.Append(" SET FAVICON = ");
345 query.Append(", FAVICON_W = ");
347 query.Append(", FAVICON_H = ");
349 query.Append(" WHERE ID = ");
352 AppLog("query is %ls", query.GetPointer());
354 r = PresentationModelBase::ExecuteUpdateHistoryFavIconQuery(query, resultCount, history);
357 AppLog("HistoryPresentationModel::SaveHistory result is success");
361 AppLog("HistoryPresentationModel::SaveHistory result is failure");
363 r = PresentationModelBase::CommitDb();
368 HistoryPresentationModel::SaveTempHistory(History& history)
370 AppLog("HistoryPresentationModel::saveHistory");
371 result r = E_FAILURE;
372 String historyTable(HISTORY_DATA_TABLE);
376 int resultCount = -1;
381 ArrayList* pMostVisitedSites = null;
382 bool isAlreadyExist = false;
383 bool isEligibleForMostVisitedSites = true;
385 String thumbnailPath;
389 SystemTime::GetCurrentTime(todayStart);
390 SystemTime::GetCurrentTime(todayEnd);
391 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
392 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
394 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
395 pTodaysList->Construct();
396 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
397 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
399 for(int count = 0; count < todaysCount; count++)
401 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
402 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
404 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
406 history.SetHistoryId(pHistoryItem->GetHistoryId());
407 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
412 pMostVisitedSites = new(std::nothrow) ArrayList();
413 pMostVisitedSites->Construct();
414 String historyTitle = history.GetHistoryTitle();
415 historyTitle.Replace(L"'", L"''");
417 String historyUrl = history.GetHistoryUrl();
418 historyUrl.Replace(L"'", L"''");
420 PresentationModelBase::GetCurrentDateTime(date);
421 GetMostVisitedSites(*pMostVisitedSites);
422 GetUrlCount(historyUrl, urlCount);
423 for (i = 0; i < pMostVisitedSites->GetCount(); i++)
425 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
426 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
428 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
429 isAlreadyExist = true;
432 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
434 isEligibleForMostVisitedSites = true;
438 isEligibleForMostVisitedSites = false;
442 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
444 AppLog("HistoryPresentationModel::SaveHistory coming here");
446 thumbnailPath = GenerateFileName();
447 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
448 Image* pImage = new(std::nothrow) Image();
450 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
454 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
458 delete pMostVisitedSites;
459 pMostVisitedSites = NULL ;
461 if (history.GetHistoryId() == "")
463 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
465 columnNames.Append(L"ADDRESS, ");
466 columnNames.Append(L"TITLE, ");
467 columnNames.Append(L"VISITDATE, ");
468 columnNames.Append(L"FAVICON, ");
469 columnNames.Append(L"FAVICON_W, ");
470 columnNames.Append(L"FAVICON_H");
472 query.Append(L"INSERT INTO ");
473 query.Append(historyTable);
475 query.Append(columnNames);
477 query.Append("VALUES");
478 query.Append(" (?,?,?,?,?,?)");
482 query.Append(L"UPDATE ");
483 query.Append(historyTable);
484 query.Append(" SET ADDRESS = ");
486 query.Append(historyUrl);
488 query.Append(", TITLE = ");
490 query.Append(historyTitle);
492 query.Append(", VISITED_TIME = ");
493 query.Append("DateTime(");
495 query.Append(GetStringFromDate(date));
498 query.Append(" WHERE ID = ");
499 query.Append(history.GetHistoryId());
502 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
504 r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
507 AppLog("HistoryPresentationModel::SaveHistory result is success");
511 AppLog("HistoryPresentationModel::SaveHistory result is failure");
513 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
515 r = PresentationModelBase::CommitDb();
517 r = GetLastInsertedId(historyTable, rowId);
520 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
526 historyId.Append(rowId);
527 if (historyId.GetLength() < 0)
531 //Set the generated ID to History
532 history.SetHistoryId(historyId);
545 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
547 result r = E_FAILURE;
549 String historyTable = HISTORY_DATA_TABLE;
550 int resultCount = -1;
552 if (pHistoryIdList == null)
557 query.Append(L"DELETE FROM ");
558 query.Append(historyTable);
559 query.Append(" WHERE");
560 for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
562 query.Append(" ID = ");
563 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
564 query.Append(*hisId);
565 query.Append(" OR ");
567 query.Append(" ID = ");
568 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
573 query.Append(*hisId);
575 r = PresentationModelBase::ExecuteQuery(query, resultCount);
576 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
578 r = PresentationModelBase::CommitDb();
590 HistoryPresentationModel::DeleteHistory(const int historyId)
592 result r = E_FAILURE;
594 String historyTable = HISTORY_DATA_TABLE;
595 int resultCount = -1;
599 return E_INVALID_ARG;
602 query.Append(L"DELETE FROM ");
603 query.Append(historyTable);
604 query.Append(" WHERE ID = ");
605 query.Append(historyId);
607 r = PresentationModelBase::ExecuteQuery(query, resultCount);
608 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
610 r = PresentationModelBase::CommitDb();
622 HistoryPresentationModel::DeleteHistory(String& historyUrl)
624 result r = E_FAILURE;
626 String historyTable = HISTORY_DATA_TABLE;
627 int resultCount = -1;
629 query.Append(L"DELETE FROM ");
630 query.Append(historyTable);
631 query.Append(" WHERE ADDRESS = '");
632 query.Append(historyUrl);
635 r = PresentationModelBase::ExecuteQuery(query, resultCount);
636 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
638 r = PresentationModelBase::CommitDb();
650 HistoryPresentationModel::ClearHistory(void)
652 result r = E_FAILURE;
654 String historyTable = HISTORY_DATA_TABLE;
655 int resultCount = -1;
657 query.Append(L"DELETE FROM ");
658 query.Append(historyTable);
660 r = PresentationModelBase::ExecuteQuery(query, resultCount);
661 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
663 r = PresentationModelBase::CommitDb();
669 HistoryPresentationModel::GetHistoryCount(int& historyCount)
674 String historyTable(HISTORY_DATA_TABLE);
675 result r = E_FAILURE;
676 bool nextRowPresent = false;
678 query.Append(L"SELECT COUNT(ID) FROM ");
679 query.Append(historyTable);
681 r = PresentationModelBase::ExecuteQuery(query, count);
682 AppLog("the count is %d", count);
683 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
685 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
686 if (IsFailed(r) != null)
688 if (nextRowPresent == true)
690 r = PresentationModelBase::GetColumn(0, intVal);
691 if (IsFailed(r) != null)
693 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
697 historyCount = intVal;
703 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
706 result r = E_SUCCESS;
708 if(__pDataList != null)
714 //if(__pDataList == null)
716 __pDataList = new(std::nothrow) ArrayList();
717 __pDataList->Construct();
719 r = GetHistoryCount(count);
726 r = GetHistory(0, count, *__pDataList);
735 count = __pDataList->GetCount();
738 for (int counter = 0 ; counter < count; counter++)
740 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
741 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
750 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
755 String historyTable(HISTORY_DATA_TABLE);
756 result r = E_FAILURE;
758 query.Append(L"SELECT * from ");
759 query.Append(historyTable);
760 query.Append(" ORDER BY VISITDATE DESC");
766 query.Append(" LIMIT ");
772 query.Append(" OFFSET ");
773 query.Append(startIndex);
777 r = PresentationModelBase::ExecuteQuery(query, count);
778 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
780 r = CreateHistoryList(count, pHistoryList);
783 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
789 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
792 History* pHistory = null;
796 result r = E_FAILURE;
801 DateTime visitedTime;
803 String thumbnailPath;
804 bool nextRowPresent = false;
806 Bitmap* pThumnailBitmap = null;
807 ByteBuffer *pFavIconBuffer;
810 if (historyCount < 1)
815 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
817 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
822 if (nextRowPresent == true)
824 pHistory = new(std::nothrow) History;
827 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
833 r = PresentationModelBase::GetColumn(columnCount, intVal);
839 historyId.Append(intVal);
840 if (historyId.GetLength() > 0)
842 pHistory->SetHistoryId(historyId);
849 r = PresentationModelBase::GetColumn(columnCount, stringVal);
852 pHistory->SetHistoryUrl(stringVal);
856 r = PresentationModelBase::GetColumn(columnCount, stringVal);
859 pHistory->SetHistoryTitle(stringVal);
863 case HISTORY_VISITED_TIME:
864 r = PresentationModelBase::GetColumn(columnCount, dateVal);
867 visitedTime = dateVal;
868 pHistory->SetVisitedTime(visitedTime);
872 case HISTORY_FAVICON:
874 pFavIconBuffer = new ByteBuffer();
875 r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
878 pHistory->SetFavIconBuffer(*pFavIconBuffer);
882 case HISTORY_FAVICON_LENGTH:
887 case HISTORY_FAVICON_W:
889 r = PresentationModelBase::GetColumn(columnCount, intVal);
894 pHistory->SetFavIconWidth(intVal);
899 case HISTORY_FAVICON_H:
901 r = PresentationModelBase::GetColumn(columnCount, intVal);
906 pHistory->SetFavIconHeight(intVal);
912 case HISTORY_VISITED_COUNT:
913 r = PresentationModelBase::GetColumn(columnCount, intVal);
918 pHistory->SetVisitedCount(intVal);
929 r = historyList.Add(*pHistory);
943 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
945 text.Replace(L"'", L"''");
949 String historyTable(HISTORY_DATA_TABLE);
950 result r = E_FAILURE;
952 query.Append(L"SELECT ");
953 query.Append(historyTable);
954 query.Append(L".* ");
955 query.Append(L"FROM ");
956 query.Append(historyTable);
957 query.Append(L" WHERE (");
958 query.Append(historyTable);
959 query.Append(L".TITLE LIKE '%");
962 query.Append(" OR ");
964 query.Append(historyTable);
965 query.Append(L".ADDRESS LIKE '%");
968 query.Append(" ORDER BY VISITDATE DESC");
973 query.Append(" LIMIT ");
979 query.Append(" OFFSET ");
980 query.Append(startIndex);
984 r = HistoryPresentationModel::ExecuteQuery(query, count);
985 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
987 r = CreateHistoryList(count, pHistoryList);
990 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
996 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
1001 String historyTable(HISTORY_DATA_TABLE);
1002 result r = E_FAILURE;
1003 bool nextRowPresent = false;
1005 text.Replace(L"'", L"''");
1006 query.Append(L"SELECT COUNT(ID) FROM ");
1007 query.Append(historyTable);
1008 query.Append(L" WHERE (TITLE LIKE '%");
1010 query.Append("%')");
1011 query.Append(" OR ");
1012 query.Append(L"(ADDRESS LIKE '%");
1014 query.Append("%')");
1016 r = HistoryPresentationModel::ExecuteQuery(query, count);
1017 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));
1019 r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);
1020 if (IsFailed(r) != null)
1022 if (nextRowPresent == true)
1024 r = HistoryPresentationModel::GetColumn(0, intVal);
1025 if (IsFailed(r) != null)
1027 AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));
1031 historyCount = intVal;
1037 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
1040 result r = E_SUCCESS;
1041 if(__pDataList == null)
1043 __pDataList = new(std::nothrow) ArrayList();
1044 __pDataList->Construct();
1046 r = GetHistoryCount(count);
1053 r = GetHistory(0, count, *__pDataList);
1062 count = __pDataList->GetCount();
1064 int itemsFoundIndex = -1;
1065 for (int counter = 0 ; counter < count; counter++)
1067 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
1068 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1071 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1073 pHistoryList.Add(*pHistory);
1075 else if(itemsFoundIndex > (limit + startIndex))
1085 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
1090 String historyTable(HISTORY_DATA_TABLE);
1091 result r = E_FAILURE;
1094 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
1095 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
1097 r = HistoryPresentationModel::ExecuteQuery(query, count);
1098 AppLog("the count is %d",count);
1099 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
1101 r = CreateHistoryList(count, pHistoryList, 9);
1104 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1111 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
1116 String historyTable(HISTORY_DATA_TABLE);
1117 result r = E_FAILURE;
1118 bool nextRowPresent = false;
1120 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
1121 query.Append(historyTable);
1122 query.Append(L" WHERE ADDRESS = ");
1127 r = PresentationModelBase::ExecuteQuery(query, count);
1128 AppLog("the count is %d", count);
1129 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
1131 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
1134 if (nextRowPresent == true)
1136 r = PresentationModelBase::GetColumn(0, intVal);
1139 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
1143 historyCount = intVal;
1149 HistoryPresentationModel::GenerateFileName(void)
1151 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
1152 if ( pAppRegistry == NULL )
1156 String keyCount("ThumbnailCount");
1157 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
1158 result r = E_SUCCESS;
1160 r = pAppRegistry->Get(keyCount, keyValue);
1162 if (r == E_KEY_NOT_FOUND)
1165 pAppRegistry->Add(keyCount, keyValue);
1170 pAppRegistry->Set(keyCount, keyValue);
1173 fileName.Append(keyValue);
1174 fileName.Append(".jpg");
1175 pAppRegistry->Save();
1181 HistoryPresentationModel::GetStringFromDate(DateTime& date)
1183 String dateFormat = L"";
1184 dateFormat.Append(date.GetYear());
1185 dateFormat.Append('-');
1186 if(date.GetMonth() < 10)
1188 dateFormat.Append('0');
1190 dateFormat.Append(date.GetMonth());
1191 dateFormat.Append('-');
1192 if(date.GetDay() < 10)
1194 dateFormat.Append('0');
1196 dateFormat.Append(date.GetDay());
1197 dateFormat.Append(' ');
1198 if(date.GetHour() < 10)
1200 dateFormat.Append('0');
1202 dateFormat.Append(date.GetHour());
1203 dateFormat.Append(':');
1204 if(date.GetMinute() < 10)
1206 dateFormat.Append('0');
1208 dateFormat.Append(date.GetMinute());
1209 dateFormat.Append(':');
1210 if(date.GetSecond() < 10)
1212 dateFormat.Append('0');
1214 dateFormat.Append(date.GetSecond());