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 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
755 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
760 String historyTable(HISTORY_DATA_TABLE);
761 result r = E_FAILURE;
763 query.Append(L"SELECT * from ");
764 query.Append(historyTable);
765 query.Append(" ORDER BY VISITDATE DESC");
771 query.Append(" LIMIT ");
777 query.Append(" OFFSET ");
778 query.Append(startIndex);
782 r = PresentationModelBase::ExecuteQuery(query, count);
783 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
785 r = CreateHistoryList(count, pHistoryList);
788 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
794 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
797 History* pHistory = null;
801 result r = E_FAILURE;
806 DateTime visitedTime;
808 String thumbnailPath;
809 bool nextRowPresent = false;
811 Bitmap* pThumnailBitmap = null;
812 ByteBuffer *pFavIconBuffer;
815 if (historyCount < 1)
820 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
822 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
827 if (nextRowPresent == true)
829 pHistory = new(std::nothrow) History;
832 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
838 r = PresentationModelBase::GetColumn(columnCount, intVal);
844 historyId.Append(intVal);
845 if (historyId.GetLength() > 0)
847 pHistory->SetHistoryId(historyId);
854 r = PresentationModelBase::GetColumn(columnCount, stringVal);
857 pHistory->SetHistoryUrl(stringVal);
861 r = PresentationModelBase::GetColumn(columnCount, stringVal);
864 pHistory->SetHistoryTitle(stringVal);
868 case HISTORY_VISITED_TIME:
869 r = PresentationModelBase::GetColumn(columnCount, dateVal);
872 visitedTime = dateVal;
873 pHistory->SetVisitedTime(visitedTime);
877 case HISTORY_FAVICON:
879 pFavIconBuffer = new ByteBuffer();
880 r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
883 pHistory->SetFavIconBuffer(*pFavIconBuffer);
887 case HISTORY_FAVICON_LENGTH:
892 case HISTORY_FAVICON_W:
894 r = PresentationModelBase::GetColumn(columnCount, intVal);
899 pHistory->SetFavIconWidth(intVal);
904 case HISTORY_FAVICON_H:
906 r = PresentationModelBase::GetColumn(columnCount, intVal);
911 pHistory->SetFavIconHeight(intVal);
917 case HISTORY_VISITED_COUNT:
918 r = PresentationModelBase::GetColumn(columnCount, intVal);
923 pHistory->SetVisitedCount(intVal);
934 r = historyList.Add(*pHistory);
948 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
950 text.Replace(L"'", L"''");
954 String historyTable(HISTORY_DATA_TABLE);
955 result r = E_FAILURE;
957 query.Append(L"SELECT ");
958 query.Append(historyTable);
959 query.Append(L".* ");
960 query.Append(L"FROM ");
961 query.Append(historyTable);
962 query.Append(L" WHERE (");
963 query.Append(historyTable);
964 query.Append(L".TITLE LIKE '%");
967 query.Append(" OR ");
969 query.Append(historyTable);
970 query.Append(L".ADDRESS LIKE '%");
973 query.Append(" ORDER BY VISITDATE DESC");
978 query.Append(" LIMIT ");
984 query.Append(" OFFSET ");
985 query.Append(startIndex);
989 r = HistoryPresentationModel::ExecuteQuery(query, count);
990 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
992 r = CreateHistoryList(count, pHistoryList);
995 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1001 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
1006 String historyTable(HISTORY_DATA_TABLE);
1007 result r = E_FAILURE;
1008 bool nextRowPresent = false;
1010 text.Replace(L"'", L"''");
1011 query.Append(L"SELECT COUNT(ID) FROM ");
1012 query.Append(historyTable);
1013 query.Append(L" WHERE (TITLE LIKE '%");
1015 query.Append("%')");
1016 query.Append(" OR ");
1017 query.Append(L"(ADDRESS LIKE '%");
1019 query.Append("%')");
1021 r = HistoryPresentationModel::ExecuteQuery(query, count);
1022 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));
1024 r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);
1025 if (IsFailed(r) != null)
1027 if (nextRowPresent == true)
1029 r = HistoryPresentationModel::GetColumn(0, intVal);
1030 if (IsFailed(r) != null)
1032 AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));
1036 historyCount = intVal;
1042 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
1045 result r = E_SUCCESS;
1046 if(__pDataList == null)
1048 __pDataList = new(std::nothrow) ArrayList();
1049 __pDataList->Construct();
1051 r = GetHistoryCount(count);
1058 r = GetHistory(0, count, *__pDataList);
1069 count = __pDataList->GetCount();
1071 int itemsFoundIndex = -1;
1072 for (int counter = 0 ; counter < count; counter++)
1074 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
1075 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1078 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1080 pHistoryList.Add(*pHistory);
1082 else if(itemsFoundIndex > (limit + startIndex))
1092 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
1097 String historyTable(HISTORY_DATA_TABLE);
1098 result r = E_FAILURE;
1101 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
1102 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
1104 r = HistoryPresentationModel::ExecuteQuery(query, count);
1105 AppLog("the count is %d",count);
1106 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
1108 r = CreateHistoryList(count, pHistoryList, 9);
1111 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1118 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
1123 String historyTable(HISTORY_DATA_TABLE);
1124 result r = E_FAILURE;
1125 bool nextRowPresent = false;
1127 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
1128 query.Append(historyTable);
1129 query.Append(L" WHERE ADDRESS = ");
1134 r = PresentationModelBase::ExecuteQuery(query, count);
1135 AppLog("the count is %d", count);
1136 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
1138 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
1141 if (nextRowPresent == true)
1143 r = PresentationModelBase::GetColumn(0, intVal);
1146 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
1150 historyCount = intVal;
1156 HistoryPresentationModel::GenerateFileName(void)
1158 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
1159 if ( pAppRegistry == NULL )
1163 String keyCount("ThumbnailCount");
1164 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
1165 result r = E_SUCCESS;
1167 r = pAppRegistry->Get(keyCount, keyValue);
1169 if (r == E_KEY_NOT_FOUND)
1172 pAppRegistry->Add(keyCount, keyValue);
1177 pAppRegistry->Set(keyCount, keyValue);
1180 fileName.Append(keyValue);
1181 fileName.Append(".jpg");
1182 pAppRegistry->Save();
1188 HistoryPresentationModel::GetStringFromDate(DateTime& date)
1190 String dateFormat = L"";
1191 dateFormat.Append(date.GetYear());
1192 dateFormat.Append('-');
1193 if(date.GetMonth() < 10)
1195 dateFormat.Append('0');
1197 dateFormat.Append(date.GetMonth());
1198 dateFormat.Append('-');
1199 if(date.GetDay() < 10)
1201 dateFormat.Append('0');
1203 dateFormat.Append(date.GetDay());
1204 dateFormat.Append(' ');
1205 if(date.GetHour() < 10)
1207 dateFormat.Append('0');
1209 dateFormat.Append(date.GetHour());
1210 dateFormat.Append(':');
1211 if(date.GetMinute() < 10)
1213 dateFormat.Append('0');
1215 dateFormat.Append(date.GetMinute());
1216 dateFormat.Append(':');
1217 if(date.GetSecond() < 10)
1219 dateFormat.Append('0');
1221 dateFormat.Append(date.GetSecond());