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)
340 history.SetFavIconBitmap(favIconImage);
344 query.Append(L"UPDATE ");
345 query.Append(historyTable);
346 query.Append(" SET FAVICON = ");
348 query.Append(", FAVICON_W = ");
350 query.Append(", FAVICON_H = ");
352 query.Append(" WHERE ID = ");
355 AppLog("query is %ls", query.GetPointer());
357 r = PresentationModelBase::ExecuteUpdateHistoryFavIconQuery(query, resultCount, history);
360 AppLog("HistoryPresentationModel::SaveHistory result is success");
364 AppLog("HistoryPresentationModel::SaveHistory result is failure");
366 r = PresentationModelBase::CommitDb();
371 HistoryPresentationModel::SaveTempHistory(History& history)
373 AppLog("HistoryPresentationModel::saveHistory");
374 result r = E_FAILURE;
375 String historyTable(HISTORY_DATA_TABLE);
379 int resultCount = -1;
384 ArrayList* pMostVisitedSites = null;
385 bool isAlreadyExist = false;
386 bool isEligibleForMostVisitedSites = true;
388 String thumbnailPath;
392 SystemTime::GetCurrentTime(todayStart);
393 SystemTime::GetCurrentTime(todayEnd);
394 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
395 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
397 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
398 pTodaysList->Construct();
399 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
400 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
402 for(int count = 0; count < todaysCount; count++)
404 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
405 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
407 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
409 history.SetHistoryId(pHistoryItem->GetHistoryId());
410 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
415 pMostVisitedSites = new(std::nothrow) ArrayList();
416 pMostVisitedSites->Construct();
417 String historyTitle = history.GetHistoryTitle();
418 historyTitle.Replace(L"'", L"''");
420 String historyUrl = history.GetHistoryUrl();
421 historyUrl.Replace(L"'", L"''");
423 PresentationModelBase::GetCurrentDateTime(date);
424 GetMostVisitedSites(*pMostVisitedSites);
425 GetUrlCount(historyUrl, urlCount);
426 for (i = 0; i < pMostVisitedSites->GetCount(); i++)
428 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
429 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
431 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
432 isAlreadyExist = true;
435 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
437 isEligibleForMostVisitedSites = true;
441 isEligibleForMostVisitedSites = false;
445 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
447 AppLog("HistoryPresentationModel::SaveHistory coming here");
449 thumbnailPath = GenerateFileName();
450 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
451 Image* pImage = new(std::nothrow) Image();
453 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
457 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
461 delete pMostVisitedSites;
462 pMostVisitedSites = NULL ;
464 if (history.GetHistoryId() == "")
466 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
468 columnNames.Append(L"ADDRESS, ");
469 columnNames.Append(L"TITLE, ");
470 columnNames.Append(L"VISITDATE, ");
471 columnNames.Append(L"FAVICON, ");
472 columnNames.Append(L"FAVICON_W, ");
473 columnNames.Append(L"FAVICON_H");
475 query.Append(L"INSERT INTO ");
476 query.Append(historyTable);
478 query.Append(columnNames);
480 query.Append("VALUES");
481 query.Append(" (?,?,?,?,?,?)");
485 query.Append(L"UPDATE ");
486 query.Append(historyTable);
487 query.Append(" SET ADDRESS = ");
489 query.Append(historyUrl);
491 query.Append(", TITLE = ");
493 query.Append(historyTitle);
495 query.Append(", VISITED_TIME = ");
496 query.Append("DateTime(");
498 query.Append(GetStringFromDate(date));
501 query.Append(" WHERE ID = ");
502 query.Append(history.GetHistoryId());
505 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
507 r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
510 AppLog("HistoryPresentationModel::SaveHistory result is success");
514 AppLog("HistoryPresentationModel::SaveHistory result is failure");
516 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
518 r = PresentationModelBase::CommitDb();
520 r = GetLastInsertedId(historyTable, rowId);
523 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
529 historyId.Append(rowId);
530 if (historyId.GetLength() < 0)
534 //Set the generated ID to History
535 history.SetHistoryId(historyId);
548 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
550 result r = E_FAILURE;
552 String historyTable = HISTORY_DATA_TABLE;
553 int resultCount = -1;
555 if (pHistoryIdList == null)
560 query.Append(L"DELETE FROM ");
561 query.Append(historyTable);
562 query.Append(" WHERE");
563 for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
565 query.Append(" ID = ");
566 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
567 query.Append(*hisId);
568 query.Append(" OR ");
570 query.Append(" ID = ");
571 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
576 query.Append(*hisId);
578 r = PresentationModelBase::ExecuteQuery(query, resultCount);
579 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
581 r = PresentationModelBase::CommitDb();
593 HistoryPresentationModel::DeleteHistory(const int historyId)
595 result r = E_FAILURE;
597 String historyTable = HISTORY_DATA_TABLE;
598 int resultCount = -1;
602 return E_INVALID_ARG;
605 query.Append(L"DELETE FROM ");
606 query.Append(historyTable);
607 query.Append(" WHERE ID = ");
608 query.Append(historyId);
610 r = PresentationModelBase::ExecuteQuery(query, resultCount);
611 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
613 r = PresentationModelBase::CommitDb();
625 HistoryPresentationModel::DeleteHistory(String& historyUrl)
627 result r = E_FAILURE;
629 String historyTable = HISTORY_DATA_TABLE;
630 int resultCount = -1;
632 query.Append(L"DELETE FROM ");
633 query.Append(historyTable);
634 query.Append(" WHERE ADDRESS = '");
635 query.Append(historyUrl);
638 r = PresentationModelBase::ExecuteQuery(query, resultCount);
639 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
641 r = PresentationModelBase::CommitDb();
653 HistoryPresentationModel::ClearHistory(void)
655 result r = E_FAILURE;
657 String historyTable = HISTORY_DATA_TABLE;
658 int resultCount = -1;
660 query.Append(L"DELETE FROM ");
661 query.Append(historyTable);
663 r = PresentationModelBase::ExecuteQuery(query, resultCount);
664 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
666 r = PresentationModelBase::CommitDb();
672 HistoryPresentationModel::GetHistoryCount(int& historyCount)
677 String historyTable(HISTORY_DATA_TABLE);
678 result r = E_FAILURE;
679 bool nextRowPresent = false;
681 query.Append(L"SELECT COUNT(ID) FROM ");
682 query.Append(historyTable);
684 r = PresentationModelBase::ExecuteQuery(query, count);
685 AppLog("the count is %d", count);
686 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
688 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
689 if (IsFailed(r) != null)
691 if (nextRowPresent == true)
693 r = PresentationModelBase::GetColumn(0, intVal);
694 if (IsFailed(r) != null)
696 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
700 historyCount = intVal;
706 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
709 result r = E_SUCCESS;
711 if(__pDataList != null)
717 //if(__pDataList == null)
719 __pDataList = new(std::nothrow) ArrayList();
720 __pDataList->Construct();
722 r = GetHistoryCount(count);
729 r = GetHistory(0, count, *__pDataList);
740 count = __pDataList->GetCount();
743 for (int counter = 0 ; counter < count; counter++)
745 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
746 AppLog("vinayhistorytimecomparison %d, %d",pHistory->GetVisitedTime().CompareTo(startTime),pHistory->GetVisitedTime().CompareTo(endTime));
747 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
756 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
761 String historyTable(HISTORY_DATA_TABLE);
762 result r = E_FAILURE;
764 query.Append(L"SELECT * from ");
765 query.Append(historyTable);
766 query.Append(" ORDER BY VISITDATE DESC");
772 query.Append(" LIMIT ");
778 query.Append(" OFFSET ");
779 query.Append(startIndex);
783 r = PresentationModelBase::ExecuteQuery(query, count);
784 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
786 r = CreateHistoryList(count, pHistoryList);
789 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
795 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
798 History* pHistory = null;
802 result r = E_FAILURE;
807 DateTime visitedTime;
809 String thumbnailPath;
810 bool nextRowPresent = false;
812 Bitmap* pThumnailBitmap = null;
813 ByteBuffer *pFavIconBuffer;
816 if (historyCount < 1)
821 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
823 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
828 if (nextRowPresent == true)
830 pHistory = new(std::nothrow) History;
833 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
839 r = PresentationModelBase::GetColumn(columnCount, intVal);
845 historyId.Append(intVal);
846 if (historyId.GetLength() > 0)
848 pHistory->SetHistoryId(historyId);
855 r = PresentationModelBase::GetColumn(columnCount, stringVal);
858 pHistory->SetHistoryUrl(stringVal);
862 r = PresentationModelBase::GetColumn(columnCount, stringVal);
865 pHistory->SetHistoryTitle(stringVal);
869 case HISTORY_VISITED_TIME:
870 r = PresentationModelBase::GetColumn(columnCount, dateVal);
873 visitedTime = dateVal;
874 pHistory->SetVisitedTime(visitedTime);
878 case HISTORY_FAVICON:
880 pFavIconBuffer = new ByteBuffer();
881 r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
884 pHistory->SetFavIconBuffer(*pFavIconBuffer);
888 case HISTORY_FAVICON_LENGTH:
893 case HISTORY_FAVICON_W:
895 r = PresentationModelBase::GetColumn(columnCount, intVal);
900 pHistory->SetFavIconWidth(intVal);
905 case HISTORY_FAVICON_H:
907 r = PresentationModelBase::GetColumn(columnCount, intVal);
912 pHistory->SetFavIconHeight(intVal);
918 case HISTORY_VISITED_COUNT:
919 r = PresentationModelBase::GetColumn(columnCount, intVal);
924 pHistory->SetVisitedCount(intVal);
935 r = historyList.Add(*pHistory);
949 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
951 text.Replace(L"'", L"''");
955 String historyTable(HISTORY_DATA_TABLE);
956 result r = E_FAILURE;
958 query.Append(L"SELECT ");
959 query.Append(historyTable);
960 query.Append(L".* ");
961 query.Append(L"FROM ");
962 query.Append(historyTable);
963 query.Append(L" WHERE (");
964 query.Append(historyTable);
965 query.Append(L".TITLE LIKE '%");
968 query.Append(" OR ");
970 query.Append(historyTable);
971 query.Append(L".ADDRESS LIKE '%");
974 query.Append(" ORDER BY VISITDATE DESC");
979 query.Append(" LIMIT ");
985 query.Append(" OFFSET ");
986 query.Append(startIndex);
990 r = HistoryPresentationModel::ExecuteQuery(query, count);
991 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
993 r = CreateHistoryList(count, pHistoryList);
996 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1002 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
1007 String historyTable(HISTORY_DATA_TABLE);
1008 result r = E_FAILURE;
1009 bool nextRowPresent = false;
1011 text.Replace(L"'", L"''");
1012 query.Append(L"SELECT COUNT(ID) FROM ");
1013 query.Append(historyTable);
1014 query.Append(L" WHERE (TITLE LIKE '%");
1016 query.Append("%')");
1017 query.Append(" OR ");
1018 query.Append(L"(ADDRESS LIKE '%");
1020 query.Append("%')");
1022 r = HistoryPresentationModel::ExecuteQuery(query, count);
1023 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));
1025 r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);
1026 if (IsFailed(r) != null)
1028 if (nextRowPresent == true)
1030 r = HistoryPresentationModel::GetColumn(0, intVal);
1031 if (IsFailed(r) != null)
1033 AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));
1037 historyCount = intVal;
1043 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
1046 result r = E_SUCCESS;
1047 if(__pDataList == null)
1049 __pDataList = new(std::nothrow) ArrayList();
1050 __pDataList->Construct();
1052 r = GetHistoryCount(count);
1059 r = GetHistory(0, count, *__pDataList);
1070 count = __pDataList->GetCount();
1072 int itemsFoundIndex = -1;
1073 for (int counter = 0 ; counter < count; counter++)
1075 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
1076 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1079 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1081 pHistoryList.Add(*pHistory);
1083 else if(itemsFoundIndex > (limit + startIndex))
1093 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
1098 String historyTable(HISTORY_DATA_TABLE);
1099 result r = E_FAILURE;
1102 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
1103 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
1105 r = HistoryPresentationModel::ExecuteQuery(query, count);
1106 AppLog("the count is %d",count);
1107 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
1109 r = CreateHistoryList(count, pHistoryList, 9);
1112 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1119 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
1124 String historyTable(HISTORY_DATA_TABLE);
1125 result r = E_FAILURE;
1126 bool nextRowPresent = false;
1128 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
1129 query.Append(historyTable);
1130 query.Append(L" WHERE ADDRESS = ");
1135 r = PresentationModelBase::ExecuteQuery(query, count);
1136 AppLog("the count is %d", count);
1137 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
1139 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
1142 if (nextRowPresent == true)
1144 r = PresentationModelBase::GetColumn(0, intVal);
1147 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
1151 historyCount = intVal;
1157 HistoryPresentationModel::GenerateFileName(void)
1159 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
1160 if ( pAppRegistry == NULL )
1164 String keyCount("ThumbnailCount");
1165 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
1166 result r = E_SUCCESS;
1168 r = pAppRegistry->Get(keyCount, keyValue);
1170 if (r == E_KEY_NOT_FOUND)
1173 pAppRegistry->Add(keyCount, keyValue);
1178 pAppRegistry->Set(keyCount, keyValue);
1181 fileName.Append(keyValue);
1182 fileName.Append(".jpg");
1183 pAppRegistry->Save();
1189 HistoryPresentationModel::GetStringFromDate(DateTime& date)
1191 String dateFormat = L"";
1192 dateFormat.Append(date.GetYear());
1193 dateFormat.Append('-');
1194 if(date.GetMonth() < 10)
1196 dateFormat.Append('0');
1198 dateFormat.Append(date.GetMonth());
1199 dateFormat.Append('-');
1200 if(date.GetDay() < 10)
1202 dateFormat.Append('0');
1204 dateFormat.Append(date.GetDay());
1205 dateFormat.Append(' ');
1206 if(date.GetHour() < 10)
1208 dateFormat.Append('0');
1210 dateFormat.Append(date.GetHour());
1211 dateFormat.Append(':');
1212 if(date.GetMinute() < 10)
1214 dateFormat.Append('0');
1216 dateFormat.Append(date.GetMinute());
1217 dateFormat.Append(':');
1218 if(date.GetSecond() < 10)
1220 dateFormat.Append('0');
1222 dateFormat.Append(date.GetSecond());