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));
146 //AppLog("HistoryPresentationModel::saveHistory pHistoryItem id is %ls",pHistoryItem->GetHistoryId().GetPointer());
147 AppLog("SaveHistory pHistoryItem url is %ls",pHistoryItem->GetHistoryUrl().GetPointer());
148 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
150 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
152 history.SetHistoryId(pHistoryItem->GetHistoryId());
153 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
158 pMostVisitedSites = new(std::nothrow) ArrayList();
159 pMostVisitedSites->Construct();
160 String historyTitle = history.GetHistoryTitle();
161 historyTitle.Replace(L"'", L"''");
163 String historyUrl = history.GetHistoryUrl();
164 historyUrl.Replace(L"'", L"''");
166 PresentationModelBase::GetCurrentDateTime(date);
167 GetMostVisitedSites(*pMostVisitedSites);
168 GetUrlCount(historyUrl, urlCount);
169 for (count = 0; count < pMostVisitedSites->GetCount(); count++)
171 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(count));
172 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
174 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
175 isAlreadyExist = true;
178 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
180 isEligibleForMostVisitedSites = true;
184 isEligibleForMostVisitedSites = false;
188 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
190 AppLog("HistoryPresentationModel::SaveHistory coming here");
192 thumbnailPath = GenerateFileName();
193 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
194 Image* pImage = new(std::nothrow) Image();
196 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
200 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
204 delete pMostVisitedSites;
205 pMostVisitedSites = NULL ;
208 ByteBuffer* pFavBuffer = history.GetFavIconBuffer();
209 if(pFavBuffer != null)
211 AppLog("Buffer found");
216 AppLog("BookmarkPresentationModel::SaveBookmark 0 ");
218 while(pFavBuffer->HasRemaining())
220 pFavBuffer->GetWchar(value);
221 pFavArray.Append(value);
225 if (history.GetHistoryId() == "")
227 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
229 columnNames.Append(L"ADDRESS, ");
230 columnNames.Append(L"TITLE, ");
231 columnNames.Append(L"VISITDATE, ");
232 columnNames.Append(L"FAVICON, ");
233 columnNames.Append(L"FAVICON_W, ");
234 columnNames.Append(L"FAVICON_H");
236 query.Append(L"INSERT INTO ");
237 query.Append(historyTable);
239 query.Append(columnNames);
241 query.Append("VALUES(");
243 query.Append(historyUrl);
247 query.Append(historyTitle);
249 query.Append("DateTime(");
251 query.Append(GetStringFromDate(date));
252 query.Append(")', ");
254 query.Append(pFavArray);
256 query.Append(history.GetFavIconWidth());
258 query.Append(history.GetFavIconHeight());
263 query.Append(L"UPDATE ");
264 query.Append(historyTable);
265 query.Append(" SET ADDRESS = ");
267 query.Append(historyUrl);
269 query.Append(", TITLE = ");
271 query.Append(historyTitle);
273 query.Append(", VISITED_TIME = ");
274 query.Append("DateTime(");
276 query.Append(GetStringFromDate(date));
280 query.Append(pFavArray);
282 query.Append(history.GetFavIconWidth());
284 query.Append(history.GetFavIconHeight());
285 query.Append(" WHERE ID = ");
286 query.Append(history.GetHistoryId());
290 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
292 r = PresentationModelBase::ExecuteQuery(query, resultCount);
295 AppLog("HistoryPresentationModel::SaveHistory result is success");
299 AppLog("HistoryPresentationModel::SaveHistory result is failure");
301 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
303 r = PresentationModelBase::CommitDb();
305 r = GetLastInsertedId(historyTable, rowId);
308 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
314 historyId.Append(rowId);
315 if (historyId.GetLength() < 0)
319 //Set the generated ID to History
320 history.SetHistoryId(historyId);
325 void HistoryPresentationModel::UpdateHistoryFavIcon(History& history, Tizen::Graphics::Bitmap& favIconImage)
327 result r = E_FAILURE;
328 String historyTable(HISTORY_DATA_TABLE);
331 int resultCount = -1;
333 Image* pImage = null;
334 pImage = new Image();
337 Tizen::Base::ByteBuffer* pFavBuffer = pImage->EncodeToBufferN(favIconImage, IMG_FORMAT_PNG);
338 // added because conversion may fail
339 if(GetLastResult() != E_SUCCESS)
342 history.SetFavIconBitmap(favIconImage);
346 query.Append(L"UPDATE ");
347 query.Append(historyTable);
348 query.Append(" SET FAVICON = ");
350 query.Append(", FAVICON_W = ");
352 query.Append(", FAVICON_H = ");
354 query.Append(" WHERE ID = ");
357 AppLog("query is %ls", query.GetPointer());
359 r = PresentationModelBase::ExecuteUpdateHistoryFavIconQuery(query, resultCount, history);
362 AppLog("HistoryPresentationModel::SaveHistory result is success");
366 AppLog("HistoryPresentationModel::SaveHistory result is failure");
368 r = PresentationModelBase::CommitDb();
373 HistoryPresentationModel::SaveTempHistory(History& history)
375 AppLog("HistoryPresentationModel::saveHistory");
376 result r = E_FAILURE;
377 String historyTable(HISTORY_DATA_TABLE);
381 int resultCount = -1;
386 ArrayList* pMostVisitedSites = null;
387 bool isAlreadyExist = false;
388 bool isEligibleForMostVisitedSites = true;
390 String thumbnailPath;
394 SystemTime::GetCurrentTime(todayStart);
395 SystemTime::GetCurrentTime(todayEnd);
396 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
397 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
399 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
400 pTodaysList->Construct();
401 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
402 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
404 for(int count = 0; count < todaysCount; count++)
406 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
407 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
409 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
411 history.SetHistoryId(pHistoryItem->GetHistoryId());
412 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
419 pTodaysList->RemoveAll();
423 pMostVisitedSites = new(std::nothrow) ArrayList();
424 pMostVisitedSites->Construct();
425 String historyTitle = history.GetHistoryTitle();
426 historyTitle.Replace(L"'", L"''");
428 String historyUrl = history.GetHistoryUrl();
429 historyUrl.Replace(L"'", L"''");
431 PresentationModelBase::GetCurrentDateTime(date);
432 GetMostVisitedSites(*pMostVisitedSites);
433 GetUrlCount(historyUrl, urlCount);
434 for (i = 0; i < pMostVisitedSites->GetCount(); i++)
436 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
437 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
439 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
440 isAlreadyExist = true;
443 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
445 isEligibleForMostVisitedSites = true;
449 isEligibleForMostVisitedSites = false;
453 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
455 AppLog("HistoryPresentationModel::SaveHistory coming here");
457 thumbnailPath = GenerateFileName();
458 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
459 Image* pImage = new(std::nothrow) Image();
461 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
465 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
469 delete pMostVisitedSites;
470 pMostVisitedSites = NULL ;
472 if (history.GetHistoryId() == "")
474 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
476 columnNames.Append(L"ADDRESS, ");
477 columnNames.Append(L"TITLE, ");
478 columnNames.Append(L"VISITDATE, ");
479 columnNames.Append(L"FAVICON, ");
480 columnNames.Append(L"FAVICON_W, ");
481 columnNames.Append(L"FAVICON_H");
483 query.Append(L"INSERT INTO ");
484 query.Append(historyTable);
486 query.Append(columnNames);
488 query.Append("VALUES");
489 query.Append(" (?,?,?,?,?,?)");
493 query.Append(L"UPDATE ");
494 query.Append(historyTable);
495 query.Append(" SET ADDRESS = ");
497 query.Append(historyUrl);
499 query.Append(", TITLE = ");
501 query.Append(historyTitle);
503 query.Append(", VISITED_TIME = ");
504 query.Append("DateTime(");
506 query.Append(GetStringFromDate(date));
509 query.Append(" WHERE ID = ");
510 query.Append(history.GetHistoryId());
513 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
515 r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
518 AppLog("HistoryPresentationModel::SaveHistory result is success");
522 AppLog("HistoryPresentationModel::SaveHistory result is failure");
524 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
526 r = PresentationModelBase::CommitDb();
528 r = GetLastInsertedId(historyTable, rowId);
531 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
537 historyId.Append(rowId);
538 if (historyId.GetLength() < 0)
542 //Set the generated ID to History
543 history.SetHistoryId(historyId);
556 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
558 result r = E_FAILURE;
560 String historyTable = HISTORY_DATA_TABLE;
561 int resultCount = -1;
563 if (pHistoryIdList == null)
568 query.Append(L"DELETE FROM ");
569 query.Append(historyTable);
570 query.Append(" WHERE");
571 for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
573 query.Append(" ID = ");
574 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
575 query.Append(*hisId);
576 query.Append(" OR ");
578 query.Append(" ID = ");
579 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
584 query.Append(*hisId);
586 r = PresentationModelBase::ExecuteQuery(query, resultCount);
587 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
589 r = PresentationModelBase::CommitDb();
601 HistoryPresentationModel::DeleteHistory(const int historyId)
603 result r = E_FAILURE;
605 String historyTable = HISTORY_DATA_TABLE;
606 int resultCount = -1;
610 return E_INVALID_ARG;
613 query.Append(L"DELETE FROM ");
614 query.Append(historyTable);
615 query.Append(" WHERE ID = ");
616 query.Append(historyId);
618 r = PresentationModelBase::ExecuteQuery(query, resultCount);
619 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
621 r = PresentationModelBase::CommitDb();
633 HistoryPresentationModel::DeleteHistory(String& historyUrl)
635 result r = E_FAILURE;
637 String historyTable = HISTORY_DATA_TABLE;
638 int resultCount = -1;
640 query.Append(L"DELETE FROM ");
641 query.Append(historyTable);
642 query.Append(" WHERE ADDRESS = '");
643 query.Append(historyUrl);
646 r = PresentationModelBase::ExecuteQuery(query, resultCount);
647 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
649 r = PresentationModelBase::CommitDb();
661 HistoryPresentationModel::ClearHistory(void)
663 result r = E_FAILURE;
665 String historyTable = HISTORY_DATA_TABLE;
666 int resultCount = -1;
668 query.Append(L"DELETE FROM ");
669 query.Append(historyTable);
671 r = PresentationModelBase::ExecuteQuery(query, resultCount);
672 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
674 r = PresentationModelBase::CommitDb();
680 HistoryPresentationModel::GetHistoryCount(int& historyCount)
685 String historyTable(HISTORY_DATA_TABLE);
686 result r = E_FAILURE;
687 bool nextRowPresent = false;
689 query.Append(L"SELECT COUNT(ID) FROM ");
690 query.Append(historyTable);
692 r = PresentationModelBase::ExecuteQuery(query, count);
693 AppLog("the count is %d", count);
694 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
696 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
697 if (IsFailed(r) != null)
699 if (nextRowPresent == true)
701 r = PresentationModelBase::GetColumn(0, intVal);
702 if (IsFailed(r) != null)
704 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
708 historyCount = intVal;
714 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
717 result r = E_SUCCESS;
719 if(__pDataList != null)
725 //if(__pDataList == null)
727 __pDataList = new(std::nothrow) ArrayList();
728 __pDataList->Construct();
730 r = GetHistoryCount(count);
737 r = GetHistory(0, count, *__pDataList);
748 count = __pDataList->GetCount();
751 for (int counter = 0 ; counter < count; counter++)
753 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
754 AppLog("vinayhistorytimecomparison %d, %d",pHistory->GetVisitedTime().CompareTo(startTime),pHistory->GetVisitedTime().CompareTo(endTime));
755 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
764 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
769 String historyTable(HISTORY_DATA_TABLE);
770 result r = E_FAILURE;
772 query.Append(L"SELECT * from ");
773 query.Append(historyTable);
774 query.Append(" ORDER BY VISITDATE DESC");
780 query.Append(" LIMIT ");
786 query.Append(" OFFSET ");
787 query.Append(startIndex);
791 r = PresentationModelBase::ExecuteQuery(query, count);
792 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
794 r = CreateHistoryList(count, pHistoryList);
797 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
803 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
806 History* pHistory = null;
810 result r = E_FAILURE;
815 DateTime visitedTime;
817 String thumbnailPath;
818 bool nextRowPresent = false;
820 Bitmap* pThumnailBitmap = null;
821 ByteBuffer *pFavIconBuffer;
824 if (historyCount < 1)
829 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
831 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
836 if (nextRowPresent == true)
838 pHistory = new(std::nothrow) History;
841 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
847 r = PresentationModelBase::GetColumn(columnCount, intVal);
853 historyId.Append(intVal);
854 if (historyId.GetLength() > 0)
856 pHistory->SetHistoryId(historyId);
863 r = PresentationModelBase::GetColumn(columnCount, stringVal);
866 pHistory->SetHistoryUrl(stringVal);
870 r = PresentationModelBase::GetColumn(columnCount, stringVal);
873 pHistory->SetHistoryTitle(stringVal);
877 case HISTORY_VISITED_TIME:
878 r = PresentationModelBase::GetColumn(columnCount, dateVal);
881 visitedTime = dateVal;
882 pHistory->SetVisitedTime(visitedTime);
886 case HISTORY_FAVICON:
888 pFavIconBuffer = new ByteBuffer();
889 r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
890 if (!IsFailed(r) && pFavIconBuffer->GetCapacity() > 0)
892 pHistory->SetFavIconBuffer(*pFavIconBuffer);
896 case HISTORY_FAVICON_LENGTH:
901 case HISTORY_FAVICON_W:
903 r = PresentationModelBase::GetColumn(columnCount, intVal);
908 pHistory->SetFavIconWidth(intVal);
913 case HISTORY_FAVICON_H:
915 r = PresentationModelBase::GetColumn(columnCount, intVal);
920 pHistory->SetFavIconHeight(intVal);
926 case HISTORY_VISITED_COUNT:
927 r = PresentationModelBase::GetColumn(columnCount, intVal);
932 pHistory->SetVisitedCount(intVal);
943 r = historyList.Add(*pHistory);
957 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
960 SystemTime::GetCurrentTime(endTime);
962 text.Replace(L"'", L"''");
966 String historyTable(HISTORY_DATA_TABLE);
967 result r = E_FAILURE;
969 query.Append(L"SELECT ");
970 query.Append(historyTable);
971 query.Append(L".* ");
972 query.Append(L"FROM ");
973 query.Append(historyTable);
974 query.Append(L" WHERE (");
975 query.Append(historyTable);
976 query.Append(L".TITLE LIKE '%");
978 query.Append("%' ESCAPE '/')");
979 query.Append(" OR ");
981 query.Append(historyTable);
982 query.Append(L".ADDRESS LIKE '%");
984 query.Append("%' ESCAPE '/')");
985 query.Append(" ORDER BY VISITDATE DESC");
988 r = HistoryPresentationModel::ExecuteQuery(query, count);
989 // TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
991 ArrayList pAllSearchList;
993 r = CreateHistoryList(count, pAllSearchList);
995 int itemsFoundIndex = -1;
996 for (int counter = 0 ; counter < count; counter++)
998 History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
999 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1002 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1004 pHistoryList.Add(*pHistory);
1006 else if(itemsFoundIndex > (limit + startIndex))
1016 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1022 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
1025 SystemTime::GetCurrentTime(endTime);
1026 text.Replace(L"'", L"''");
1030 String historyTable(HISTORY_DATA_TABLE);
1031 result r = E_FAILURE;
1033 query.Append(L"SELECT ");
1034 query.Append(historyTable);
1035 query.Append(L".* ");
1036 query.Append(L"FROM ");
1037 query.Append(historyTable);
1038 query.Append(L" WHERE (");
1039 query.Append(historyTable);
1040 query.Append(L".TITLE LIKE '%");
1042 query.Append("% 'ESCAPE '/')");
1043 query.Append(" OR ");
1045 query.Append(historyTable);
1046 query.Append(L".ADDRESS LIKE '%");
1048 query.Append("%' ESCAPE '/')");
1049 query.Append(" ORDER BY VISITDATE DESC");
1051 r = HistoryPresentationModel::ExecuteQuery(query, count);
1052 // TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
1054 ArrayList pAllSearchList;
1056 r = CreateHistoryList(count, pAllSearchList);
1059 for (int counter = 0 ; counter < count; counter++)
1061 History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
1062 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1071 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1077 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
1080 result r = E_SUCCESS;
1081 if(__pDataList == null)
1083 __pDataList = new(std::nothrow) ArrayList();
1084 __pDataList->Construct();
1086 r = GetHistoryCount(count);
1093 r = GetHistory(0, count, *__pDataList);
1104 count = __pDataList->GetCount();
1106 int itemsFoundIndex = -1;
1107 for (int counter = 0 ; counter < count; counter++)
1109 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
1110 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1113 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1115 pHistoryList.Add(*pHistory);
1117 else if(itemsFoundIndex > (limit + startIndex))
1127 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
1132 String historyTable(HISTORY_DATA_TABLE);
1133 result r = E_FAILURE;
1136 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
1137 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
1139 r = HistoryPresentationModel::ExecuteQuery(query, count);
1140 AppLog("the count is %d",count);
1141 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
1143 r = CreateHistoryList(count, pHistoryList, 9);
1146 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1153 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
1158 String historyTable(HISTORY_DATA_TABLE);
1159 result r = E_FAILURE;
1160 bool nextRowPresent = false;
1162 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
1163 query.Append(historyTable);
1164 query.Append(L" WHERE ADDRESS = ");
1169 r = PresentationModelBase::ExecuteQuery(query, count);
1170 AppLog("the count is %d", count);
1171 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
1173 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
1176 if (nextRowPresent == true)
1178 r = PresentationModelBase::GetColumn(0, intVal);
1181 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
1185 historyCount = intVal;
1191 HistoryPresentationModel::GenerateFileName(void)
1193 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
1194 if ( pAppRegistry == NULL )
1198 String keyCount("ThumbnailCount");
1199 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
1200 result r = E_SUCCESS;
1202 r = pAppRegistry->Get(keyCount, keyValue);
1204 if (r == E_KEY_NOT_FOUND)
1207 pAppRegistry->Add(keyCount, keyValue);
1212 pAppRegistry->Set(keyCount, keyValue);
1215 fileName.Append(keyValue);
1216 fileName.Append(".jpg");
1217 pAppRegistry->Save();
1223 HistoryPresentationModel::GetStringFromDate(DateTime& date)
1225 String dateFormat = L"";
1226 dateFormat.Append(date.GetYear());
1227 dateFormat.Append('-');
1228 if(date.GetMonth() < 10)
1230 dateFormat.Append('0');
1232 dateFormat.Append(date.GetMonth());
1233 dateFormat.Append('-');
1234 if(date.GetDay() < 10)
1236 dateFormat.Append('0');
1238 dateFormat.Append(date.GetDay());
1239 dateFormat.Append(' ');
1240 if(date.GetHour() < 10)
1242 dateFormat.Append('0');
1244 dateFormat.Append(date.GetHour());
1245 dateFormat.Append(':');
1246 if(date.GetMinute() < 10)
1248 dateFormat.Append('0');
1250 dateFormat.Append(date.GetMinute());
1251 dateFormat.Append(':');
1252 if(date.GetSecond() < 10)
1254 dateFormat.Append('0');
1256 dateFormat.Append(date.GetSecond());