3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (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);
325 HistoryPresentationModel::SaveTempHistory(History& history)
327 AppLog("HistoryPresentationModel::saveHistory");
328 result r = E_FAILURE;
329 String historyTable(HISTORY_DATA_TABLE);
333 int resultCount = -1;
338 ArrayList* pMostVisitedSites = null;
339 bool isAlreadyExist = false;
340 bool isEligibleForMostVisitedSites = true;
342 String thumbnailPath;
346 SystemTime::GetCurrentTime(todayStart);
347 SystemTime::GetCurrentTime(todayEnd);
348 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
349 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
351 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
352 pTodaysList->Construct();
353 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
354 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
356 for(int count = 0; count < todaysCount; count++)
358 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
359 //AppLog("HistoryPresentationModel::saveHistory pHistoryItem id is %ls",pHistoryItem->GetHistoryId().GetPointer());
360 AppLog("SaveHistory pHistoryItem url is %ls",pHistoryItem->GetHistoryUrl().GetPointer());
361 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
363 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
365 history.SetHistoryId(pHistoryItem->GetHistoryId());
366 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
371 pMostVisitedSites = new(std::nothrow) ArrayList();
372 pMostVisitedSites->Construct();
373 String historyTitle = history.GetHistoryTitle();
374 historyTitle.Replace(L"'", L"''");
376 String historyUrl = history.GetHistoryUrl();
377 historyUrl.Replace(L"'", L"''");
379 PresentationModelBase::GetCurrentDateTime(date);
380 GetMostVisitedSites(*pMostVisitedSites);
381 GetUrlCount(historyUrl, urlCount);
382 for (i = 0; i < pMostVisitedSites->GetCount(); i++)
384 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
385 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
387 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
388 isAlreadyExist = true;
391 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
393 isEligibleForMostVisitedSites = true;
397 isEligibleForMostVisitedSites = false;
401 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
403 AppLog("HistoryPresentationModel::SaveHistory coming here");
405 thumbnailPath = GenerateFileName();
406 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
407 Image* pImage = new(std::nothrow) Image();
409 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
413 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
417 delete pMostVisitedSites;
418 pMostVisitedSites = NULL ;
420 if (history.GetHistoryId() == "")
422 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
424 columnNames.Append(L"ADDRESS, ");
425 columnNames.Append(L"TITLE, ");
426 columnNames.Append(L"VISITDATE, ");
427 columnNames.Append(L"FAVICON, ");
428 columnNames.Append(L"FAVICON_W, ");
429 columnNames.Append(L"FAVICON_H");
431 query.Append(L"INSERT INTO ");
432 query.Append(historyTable);
434 query.Append(columnNames);
436 query.Append("VALUES");
437 query.Append(" (?,?,?,?,?,?)");
441 query.Append(L"UPDATE ");
442 query.Append(historyTable);
443 query.Append(" SET ADDRESS = ");
445 query.Append(historyUrl);
447 query.Append(", TITLE = ");
449 query.Append(historyTitle);
451 query.Append(", VISITED_TIME = ");
452 query.Append("DateTime(");
454 query.Append(GetStringFromDate(date));
457 query.Append(" WHERE ID = ");
458 query.Append(history.GetHistoryId());
461 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
463 r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
466 AppLog("HistoryPresentationModel::SaveHistory result is success");
470 AppLog("HistoryPresentationModel::SaveHistory result is failure");
472 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
474 r = PresentationModelBase::CommitDb();
476 r = GetLastInsertedId(historyTable, rowId);
479 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
485 historyId.Append(rowId);
486 if (historyId.GetLength() < 0)
490 //Set the generated ID to History
491 history.SetHistoryId(historyId);
504 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
506 result r = E_FAILURE;
508 String historyTable = HISTORY_DATA_TABLE;
509 int resultCount = -1;
511 if (pHistoryIdList == null)
516 query.Append(L"DELETE FROM ");
517 query.Append(historyTable);
518 query.Append(" WHERE");
519 for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
521 query.Append(" ID = ");
522 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
523 query.Append(*hisId);
524 query.Append(" OR ");
526 query.Append(" ID = ");
527 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
532 query.Append(*hisId);
534 r = PresentationModelBase::ExecuteQuery(query, resultCount);
535 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
537 r = PresentationModelBase::CommitDb();
549 HistoryPresentationModel::DeleteHistory(const int historyId)
551 result r = E_FAILURE;
553 String historyTable = HISTORY_DATA_TABLE;
554 int resultCount = -1;
558 return E_INVALID_ARG;
561 query.Append(L"DELETE FROM ");
562 query.Append(historyTable);
563 query.Append(" WHERE ID = ");
564 query.Append(historyId);
566 r = PresentationModelBase::ExecuteQuery(query, resultCount);
567 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
569 r = PresentationModelBase::CommitDb();
581 HistoryPresentationModel::DeleteHistory(String& historyUrl)
583 result r = E_FAILURE;
585 String historyTable = HISTORY_DATA_TABLE;
586 int resultCount = -1;
588 query.Append(L"DELETE FROM ");
589 query.Append(historyTable);
590 query.Append(" WHERE ADDRESS = '");
591 query.Append(historyUrl);
594 r = PresentationModelBase::ExecuteQuery(query, resultCount);
595 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
597 r = PresentationModelBase::CommitDb();
609 HistoryPresentationModel::ClearHistory(void)
611 result r = E_FAILURE;
613 String historyTable = HISTORY_DATA_TABLE;
614 int resultCount = -1;
616 query.Append(L"DELETE FROM ");
617 query.Append(historyTable);
619 r = PresentationModelBase::ExecuteQuery(query, resultCount);
620 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
622 r = PresentationModelBase::CommitDb();
628 HistoryPresentationModel::GetHistoryCount(int& historyCount)
633 String historyTable(HISTORY_DATA_TABLE);
634 result r = E_FAILURE;
635 bool nextRowPresent = false;
637 query.Append(L"SELECT COUNT(ID) FROM ");
638 query.Append(historyTable);
640 r = PresentationModelBase::ExecuteQuery(query, count);
641 AppLog("the count is %d", count);
642 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
644 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
645 if (IsFailed(r) != null)
647 if (nextRowPresent == true)
649 r = PresentationModelBase::GetColumn(0, intVal);
650 if (IsFailed(r) != null)
652 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
656 historyCount = intVal;
662 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
665 result r = E_SUCCESS;
666 if(__pDataList == null)
668 __pDataList = new(std::nothrow) ArrayList();
669 __pDataList->Construct();
671 r = GetHistoryCount(count);
678 r = GetHistory(0, count, *__pDataList);
687 count = __pDataList->GetCount();
690 for (int counter = 0 ; counter < count; counter++)
692 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
693 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
702 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
707 String historyTable(HISTORY_DATA_TABLE);
708 result r = E_FAILURE;
710 query.Append(L"SELECT * from ");
711 query.Append(historyTable);
712 query.Append(" ORDER BY VISITDATE DESC");
718 query.Append(" LIMIT ");
724 query.Append(" OFFSET ");
725 query.Append(startIndex);
729 r = PresentationModelBase::ExecuteQuery(query, count);
730 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
732 r = CreateHistoryList(count, pHistoryList);
735 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
741 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
744 History* pHistory = null;
748 result r = E_FAILURE;
753 DateTime visitedTime;
755 String thumbnailPath;
756 bool nextRowPresent = false;
758 Bitmap* pThumnailBitmap = null;
759 ByteBuffer *pFavIconBuffer;
762 if (historyCount < 1)
767 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
769 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
774 if (nextRowPresent == true)
776 pHistory = new(std::nothrow) History;
779 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
785 r = PresentationModelBase::GetColumn(columnCount, intVal);
791 historyId.Append(intVal);
792 if (historyId.GetLength() > 0)
794 pHistory->SetHistoryId(historyId);
801 r = PresentationModelBase::GetColumn(columnCount, stringVal);
804 pHistory->SetHistoryUrl(stringVal);
808 r = PresentationModelBase::GetColumn(columnCount, stringVal);
811 pHistory->SetHistoryTitle(stringVal);
815 case HISTORY_VISITED_TIME:
816 r = PresentationModelBase::GetColumn(columnCount, dateVal);
819 visitedTime = dateVal;
820 pHistory->SetVisitedTime(visitedTime);
824 case HISTORY_FAVICON:
826 pFavIconBuffer = new ByteBuffer();
827 r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
830 pHistory->SetFavIconBuffer(*pFavIconBuffer);
834 case HISTORY_FAVICON_LENGTH:
839 case HISTORY_FAVICON_W:
841 r = PresentationModelBase::GetColumn(columnCount, intVal);
846 pHistory->SetFavIconWidth(intVal);
851 case HISTORY_FAVICON_H:
853 r = PresentationModelBase::GetColumn(columnCount, intVal);
858 pHistory->SetFavIconHeight(intVal);
864 case HISTORY_VISITED_COUNT:
865 r = PresentationModelBase::GetColumn(columnCount, intVal);
870 pHistory->SetVisitedCount(intVal);
881 r = historyList.Add(*pHistory);
895 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
897 text.Replace(L"'", L"''");
901 String historyTable(HISTORY_DATA_TABLE);
902 result r = E_FAILURE;
904 query.Append(L"SELECT ");
905 query.Append(historyTable);
906 query.Append(L".* ");
907 query.Append(L"FROM ");
908 query.Append(historyTable);
909 query.Append(L" WHERE (");
910 query.Append(historyTable);
911 query.Append(L".TITLE LIKE '%");
914 query.Append(" OR ");
916 query.Append(historyTable);
917 query.Append(L".ADDRESS LIKE '%");
920 query.Append(" ORDER BY VISITDATE DESC");
925 query.Append(" LIMIT ");
931 query.Append(" OFFSET ");
932 query.Append(startIndex);
936 r = HistoryPresentationModel::ExecuteQuery(query, count);
937 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
939 r = CreateHistoryList(count, pHistoryList);
942 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
948 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
953 String historyTable(HISTORY_DATA_TABLE);
954 result r = E_FAILURE;
955 bool nextRowPresent = false;
957 text.Replace(L"'", L"''");
958 query.Append(L"SELECT COUNT(ID) FROM ");
959 query.Append(historyTable);
960 query.Append(L" WHERE (TITLE LIKE '%");
963 query.Append(" OR ");
964 query.Append(L"(ADDRESS LIKE '%");
968 r = HistoryPresentationModel::ExecuteQuery(query, count);
969 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));
971 r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);
972 if (IsFailed(r) != null)
974 if (nextRowPresent == true)
976 r = HistoryPresentationModel::GetColumn(0, intVal);
977 if (IsFailed(r) != null)
979 AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));
983 historyCount = intVal;
989 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
992 result r = E_SUCCESS;
993 if(__pDataList == null)
995 __pDataList = new(std::nothrow) ArrayList();
996 __pDataList->Construct();
998 r = GetHistoryCount(count);
1005 r = GetHistory(0, count, *__pDataList);
1014 count = __pDataList->GetCount();
1016 int itemsFoundIndex = -1;
1017 for (int counter = 0 ; counter < count; counter++)
1019 History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
1020 if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
1023 if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
1025 pHistoryList.Add(*pHistory);
1027 else if(itemsFoundIndex > (limit + startIndex))
1037 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
1042 String historyTable(HISTORY_DATA_TABLE);
1043 result r = E_FAILURE;
1046 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
1047 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
1049 r = HistoryPresentationModel::ExecuteQuery(query, count);
1050 AppLog("the count is %d",count);
1051 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
1053 r = CreateHistoryList(count, pHistoryList, 9);
1056 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
1063 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
1068 String historyTable(HISTORY_DATA_TABLE);
1069 result r = E_FAILURE;
1070 bool nextRowPresent = false;
1072 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
1073 query.Append(historyTable);
1074 query.Append(L" WHERE ADDRESS = ");
1079 r = PresentationModelBase::ExecuteQuery(query, count);
1080 AppLog("the count is %d", count);
1081 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
1083 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
1086 if (nextRowPresent == true)
1088 r = PresentationModelBase::GetColumn(0, intVal);
1091 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
1095 historyCount = intVal;
1101 HistoryPresentationModel::GenerateFileName(void)
1103 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
1104 if ( pAppRegistry == NULL )
1108 String keyCount("ThumbnailCount");
1109 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
1110 result r = E_SUCCESS;
1112 r = pAppRegistry->Get(keyCount, keyValue);
1114 if (r == E_KEY_NOT_FOUND)
1117 pAppRegistry->Add(keyCount, keyValue);
1122 pAppRegistry->Set(keyCount, keyValue);
1125 fileName.Append(keyValue);
1126 fileName.Append(".jpg");
1127 pAppRegistry->Save();
1133 HistoryPresentationModel::GetStringFromDate(DateTime& date)
1135 String dateFormat = L"";
1136 dateFormat.Append(date.GetYear());
1137 dateFormat.Append('-');
1138 if(date.GetMonth() < 10)
1140 dateFormat.Append('0');
1142 dateFormat.Append(date.GetMonth());
1143 dateFormat.Append('-');
1144 if(date.GetDay() < 10)
1146 dateFormat.Append('0');
1148 dateFormat.Append(date.GetDay());
1149 dateFormat.Append(' ');
1150 if(date.GetHour() < 10)
1152 dateFormat.Append('0');
1154 dateFormat.Append(date.GetHour());
1155 dateFormat.Append(':');
1156 if(date.GetMinute() < 10)
1158 dateFormat.Append('0');
1160 dateFormat.Append(date.GetMinute());
1161 dateFormat.Append(':');
1162 if(date.GetSecond() < 10)
1164 dateFormat.Append('0');
1166 dateFormat.Append(date.GetSecond());