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 (i = 0; i < pMostVisitedSites->GetCount(); i++)
170 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
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 ;
206 if (history.GetHistoryId() == "")
208 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
210 columnNames.Append(L"TITLE, ");
211 columnNames.Append(L"URL, ");
212 columnNames.Append(L"VISITED_TIME, ");
213 columnNames.Append(L"ICON_PATH, ");
214 columnNames.Append(L"FAVICON_ID, ");
215 columnNames.Append(L"THUMBNAIL_PATH");
217 query.Append(L"INSERT INTO ");
218 query.Append(historyTable);
220 query.Append(columnNames);
222 query.Append("VALUES(");
224 query.Append(historyTitle);
228 query.Append(historyUrl);
230 query.Append("DateTime(");
232 query.Append(GetStringFromDate(date));
233 query.Append("'), ");
235 query.Append(history.GetHistoryIconPath());
239 query.Append(history.GetFaviconId());
243 query.Append(thumbnailPath);
247 columnNames.Append(L"ADDRESS, ");
248 columnNames.Append(L"TITLE, ");
249 //columnNames.Append(L"COUNTER, ");
250 columnNames.Append(L"VISITDATE");
251 // columnNames.Append(L"FAVICON, ");
252 // columnNames.Append(L"FAVICON_LENGTH, ");
253 // columnNames.Append(L"FAVICON_W, ");
254 // columnNames.Append(L"FAVICON_H, ");
255 // columnNames.Append(L"SNAPSHOT, ");
256 // columnNames.Append(L"SNAPSHOT_STRIDE, ");
257 // columnNames.Append(L"SNAPSHOT_W, ");
258 // columnNames.Append(L"SNAPSHOT_H");
259 // columnNames.Append(L"ICON_PATH, ");
260 // columnNames.Append(L"FAVICON_ID, ");
261 // columnNames.Append(L"THUMBNAIL_PATH");
263 query.Append(L"INSERT INTO ");
264 query.Append(historyTable);
266 query.Append(columnNames);
268 query.Append("VALUES(");
270 query.Append(historyUrl);
274 query.Append(historyTitle);
276 query.Append("DateTime(");
278 query.Append(GetStringFromDate(date));
281 //query.Append("'), ");
283 //query.Append(history.GetHistoryIconPath());
285 //query.Append(", ");
287 //query.Append(history.GetFaviconId());
289 //query.Append(", ");
291 //query.Append(thumbnailPath);
297 /*query.Append(L"UPDATE ");
298 query.Append(historyTable);
299 query.Append(" SET TITLE = ");
301 query.Append(historyTitle);
303 query.Append(", URL = ");
305 query.Append(historyUrl);
307 query.Append(", VISITED_TIME = ");
308 query.Append("DateTime(");
310 query.Append(GetStringFromDate(date));
312 query.Append(", ICON_PATH = ");
314 query.Append(history.GetHistoryIconPath());
318 query.Append(history.GetFaviconId());
322 query.Append(thumbnailPath);
324 query.Append(" WHERE ID = ");
325 query.Append(history.GetHistoryId());*/
326 query.Append(L"UPDATE ");
327 query.Append(historyTable);
328 query.Append(" SET ADDRESS = ");
330 query.Append(historyUrl);
332 query.Append(", TITLE = ");
334 query.Append(historyTitle);
336 query.Append(", VISITED_TIME = ");
337 query.Append("DateTime(");
339 query.Append(GetStringFromDate(date));
341 /*query.Append(", ICON_PATH = ");
343 query.Append(history.GetHistoryIconPath());
347 query.Append(history.GetFaviconId());
351 query.Append(thumbnailPath);*/
353 query.Append(" WHERE ID = ");
354 query.Append(history.GetHistoryId());
358 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
360 r = PresentationModelBase::ExecuteQuery(query, resultCount);
363 AppLog("HistoryPresentationModel::SaveHistory result is success");
367 AppLog("HistoryPresentationModel::SaveHistory result is failure");
369 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
371 r = PresentationModelBase::CommitDb();
373 r = GetLastInsertedId(historyTable, rowId);
376 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
382 historyId.Append(rowId);
383 if (historyId.GetLength() < 0)
387 //Set the generated ID to History
388 history.SetHistoryId(historyId);
394 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
396 result r = E_FAILURE;
398 String historyTable = HISTORY_DATA_TABLE;
399 int resultCount = -1;
401 if (pHistoryIdList == null)
406 query.Append(L"DELETE FROM ");
407 query.Append(historyTable);
408 query.Append(" WHERE");
409 for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
411 query.Append(" ID = ");
412 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
413 query.Append(*hisId);
414 query.Append(" OR ");
416 query.Append(" ID = ");
417 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
422 query.Append(*hisId);
424 r = PresentationModelBase::ExecuteQuery(query, resultCount);
425 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
427 r = PresentationModelBase::CommitDb();
433 HistoryPresentationModel::DeleteHistory(const int historyId)
435 result r = E_FAILURE;
437 String historyTable = HISTORY_DATA_TABLE;
438 int resultCount = -1;
442 return E_INVALID_ARG;
445 query.Append(L"DELETE FROM ");
446 query.Append(historyTable);
447 query.Append(" WHERE ID = ");
448 query.Append(historyId);
450 r = PresentationModelBase::ExecuteQuery(query, resultCount);
451 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
453 r = PresentationModelBase::CommitDb();
459 HistoryPresentationModel::DeleteHistory(String& historyUrl)
461 result r = E_FAILURE;
463 String historyTable = HISTORY_DATA_TABLE;
464 int resultCount = -1;
466 query.Append(L"DELETE FROM ");
467 query.Append(historyTable);
468 query.Append(" WHERE ADDRESS = '");
469 query.Append(historyUrl);
472 r = PresentationModelBase::ExecuteQuery(query, resultCount);
473 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
475 r = PresentationModelBase::CommitDb();
481 HistoryPresentationModel::ClearHistory(void)
483 result r = E_FAILURE;
485 String historyTable = HISTORY_DATA_TABLE;
486 int resultCount = -1;
488 query.Append(L"DELETE FROM ");
489 query.Append(historyTable);
491 r = PresentationModelBase::ExecuteQuery(query, resultCount);
492 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
494 r = PresentationModelBase::CommitDb();
500 HistoryPresentationModel::GetHistoryCount(int& historyCount)
505 String historyTable(HISTORY_DATA_TABLE);
506 result r = E_FAILURE;
507 bool nextRowPresent = false;
509 query.Append(L"SELECT COUNT(ID) FROM ");
510 query.Append(historyTable);
512 r = PresentationModelBase::ExecuteQuery(query, count);
513 AppLog("the count is %d", count);
514 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
516 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
517 if (IsFailed(r) != null)
519 if (nextRowPresent == true)
521 r = PresentationModelBase::GetColumn(0, intVal);
522 if (IsFailed(r) != null)
524 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
528 historyCount = intVal;
534 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
540 String historyTable(HISTORY_DATA_TABLE);
541 result r = E_FAILURE;
542 bool nextRowPresent = false;
544 query.Append(L"SELECT COUNT(ID) FROM ");
545 query.Append(historyTable);
546 query.Append(" WHERE VISITDATE >= ");
547 query.Append("DateTime(");
549 query.Append(GetStringFromDate(startTime));
551 query.Append(" AND VISITDATE <= ");
552 query.Append("DateTime(");
554 query.Append(GetStringFromDate(endTime));
557 r = PresentationModelBase::ExecuteQuery(query, count);
558 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCountWithTimeRange query failed %s",GetErrorMessage(r));
560 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
563 if (nextRowPresent == true)
565 r = PresentationModelBase::GetColumn(0, intVal);
568 AppLogDebug("Error:PresentationModelBase::DbGetColumn:%s", GetErrorMessage(r));
572 historyCount = intVal;
578 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
583 String historyTable(HISTORY_DATA_TABLE);
584 result r = E_FAILURE;
586 query.Append(L"SELECT");
587 query.Append(historyTable);
588 query.Append(L".*, ");
589 query.Append(BOOKMARK_URL_TABLE);
590 query.Append(L".ID ");
591 query.Append(L"FROM ");
592 query.Append(historyTable);
594 query.Append(BOOKMARK_URL_TABLE);
595 query.Append(L" WHERE ");
596 query.Append(historyTable);
597 query.Append(L".ADDRESS ");
600 query.Append(L"SELECT");
601 query.Append(historyTable);
602 query.Append(L".ADDRESS ");
603 query.Append(L"FROM ");
604 query.Append(BOOKMARK_URL_TABLE);
605 query.Append(L" LEFT JOIN ");
606 query.Append(historyTable);
608 query.Append(BOOKMARK_URL_TABLE);
609 query.Append(L".ADDRESS = ");
610 query.Append(historyTable);
611 query.Append(L".ADDRESS ");
612 query.Append(" ORDER BY");
613 query.Append(historyTable);
614 query.Append(L".VISITDATE DESC");
616 query.Append(" GROUP BY ");
617 query.Append(historyTable);
618 query.Append(L".ADDRESS ");
619 query.Append(" ORDER BY");
620 query.Append(L"COUNT(");
621 query.Append(historyTable);
622 query.Append(L".ADDRESS) DESC ");
628 query.Append(" LIMIT ");
634 query.Append(" OFFSET ");
635 query.Append(startIndex);
639 r = PresentationModelBase::ExecuteQuery(query, count);
640 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
642 r = CreateHistoryList(count, pHistoryList);
645 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
651 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
654 History* pHistory = null;
658 result r = E_FAILURE;
663 DateTime visitedTime;
665 String thumbnailPath;
666 bool nextRowPresent = false;
668 Bitmap* pThumnailBitmap = null;
671 if (historyCount < 1)
676 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
678 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
683 if (nextRowPresent == true)
685 pHistory = new(std::nothrow) History;
688 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
694 r = PresentationModelBase::GetColumn(columnCount, intVal);
700 historyId.Append(intVal);
701 if (historyId.GetLength() > 0)
703 pHistory->SetHistoryId(historyId);
710 r = PresentationModelBase::GetColumn(columnCount, stringVal);
713 pHistory->SetHistoryUrl(stringVal);
717 r = PresentationModelBase::GetColumn(columnCount, stringVal);
720 pHistory->SetHistoryTitle(stringVal);
723 case HISTORY_VISITED_TIME:
724 r = PresentationModelBase::GetColumn(columnCount, dateVal);
727 visitedTime = dateVal;
728 pHistory->SetVisitedTime(visitedTime);
732 /*case HISTORY_ICON_PATH:
733 r = PresentationModelBase::GetColumn(columnCount, stringVal);
736 iconPath = stringVal;
737 pHistory->SetIconPath(iconPath);
741 case HISTORY_FAVICONID:
743 r = PresentationModelBase::GetColumn(columnCount, intVal);
749 faviconId.Append(intVal);
750 if (faviconId.GetLength() > 0)
752 pHistory->SetFaviconId(faviconId);
757 case HISTORY_THUMBNAIL:
758 r = PresentationModelBase::GetColumn(columnCount, stringVal);
762 thumbnailPath = stringVal;
763 pThumnailBitmap = image.DecodeN(thumbnailPath, BITMAP_PIXEL_FORMAT_RGB565);
764 if (pThumnailBitmap != null)
766 pHistory->SetThumbnail(pThumnailBitmap);
767 pHistory->SetThumbnailPath(thumbnailPath);
771 /* case HISTORY_BOOKMARK_ID:
772 r = PresentationModelBase::GetColumn(columnCount, intVal);
778 bookmarkId.Append(intVal);
779 if (bookmarkId.GetLength() > 0)
781 pHistory->SetBookmarkId(bookmarkId);
788 case HISTORY_VISITED_COUNT:
789 r = PresentationModelBase::GetColumn(columnCount, intVal);
794 pHistory->SetVisitedCount(intVal);
806 r = historyList.Add(*pHistory);
820 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
822 text.Replace(L"'", L"''");
826 String historyTable(HISTORY_DATA_TABLE);
827 result r = E_FAILURE;
829 query.Append(L"SELECT ");
830 query.Append(historyTable);
831 query.Append(L".* ");
832 query.Append(L"FROM ");
833 query.Append(historyTable);
834 query.Append(L" WHERE (");
835 query.Append(historyTable);
836 query.Append(L".TITLE LIKE '%");
839 query.Append(" OR ");
841 query.Append(historyTable);
842 query.Append(L".ADDRESS LIKE '%");
845 query.Append(" ORDER BY VISITDATE DESC");
850 query.Append(" LIMIT ");
856 query.Append(" OFFSET ");
857 query.Append(startIndex);
861 r = HistoryPresentationModel::ExecuteQuery(query, count);
862 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
864 r = CreateHistoryList(count, pHistoryList);
867 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
873 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
878 String historyTable(HISTORY_DATA_TABLE);
879 result r = E_FAILURE;
880 bool nextRowPresent = false;
882 text.Replace(L"'", L"''");
883 query.Append(L"SELECT COUNT(ID) FROM ");
884 query.Append(historyTable);
885 query.Append(L" WHERE (TITLE LIKE '%");
888 query.Append(" OR ");
889 query.Append(L"(ADDRESS LIKE '%");
893 r = HistoryPresentationModel::ExecuteQuery(query, count);
894 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));
896 r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);
897 if (IsFailed(r) != null)
899 if (nextRowPresent == true)
901 r = HistoryPresentationModel::GetColumn(0, intVal);
902 if (IsFailed(r) != null)
904 AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));
908 historyCount = intVal;
914 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
918 String historyTable(HISTORY_DATA_TABLE);
919 result r = E_FAILURE;
921 query.Append(L"SELECT ");
922 //query.Append(historyTable);
924 query.Append(L"FROM ");
925 query.Append(historyTable);
926 query.Append(" WHERE ");
927 //query.Append(historyTable);
928 query.Append(L"VISITDATE >= ");
929 query.Append("DateTime(");
931 query.Append(GetStringFromDate(startTime));
933 query.Append(" AND ");
934 //query.Append(historyTable);
935 query.Append(L"VISITDATE <= ");
936 query.Append("DateTime(");
938 query.Append(GetStringFromDate(endTime));
940 query.Append(" ORDER BY VISITDATE DESC");
945 query.Append(" LIMIT ");
951 query.Append(" OFFSET ");
952 query.Append(startIndex);
956 r = HistoryPresentationModel::ExecuteQuery(query, count);
957 AppLog("the count is %d",count);
958 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
960 r = CreateHistoryList(count, pHistoryList);
963 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
970 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
975 String historyTable(HISTORY_DATA_TABLE);
976 result r = E_FAILURE;
979 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
980 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
982 r = HistoryPresentationModel::ExecuteQuery(query, count);
983 AppLog("the count is %d",count);
984 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
986 r = CreateHistoryList(count, pHistoryList, 9);
989 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
996 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
1001 String historyTable(HISTORY_DATA_TABLE);
1002 result r = E_FAILURE;
1003 bool nextRowPresent = false;
1005 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
1006 query.Append(historyTable);
1007 query.Append(L" WHERE ADDRESS = ");
1012 r = PresentationModelBase::ExecuteQuery(query, count);
1013 AppLog("the count is %d", count);
1014 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
1016 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
1019 if (nextRowPresent == true)
1021 r = PresentationModelBase::GetColumn(0, intVal);
1024 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
1028 historyCount = intVal;
1034 HistoryPresentationModel::GenerateFileName(void)
1036 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
1037 if ( pAppRegistry == NULL )
1041 String keyCount("ThumbnailCount");
1042 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
1043 result r = E_SUCCESS;
1045 r = pAppRegistry->Get(keyCount, keyValue);
1047 if (r == E_KEY_NOT_FOUND)
1050 pAppRegistry->Add(keyCount, keyValue);
1055 pAppRegistry->Set(keyCount, keyValue);
1058 fileName.Append(keyValue);
1059 fileName.Append(".jpg");
1060 pAppRegistry->Save();
1066 HistoryPresentationModel::GetStringFromDate(DateTime& date)
1068 String dateFormat = L"";
1069 dateFormat.Append(date.GetYear());
1070 dateFormat.Append('-');
1071 if(date.GetMonth() < 10)
1073 dateFormat.Append('0');
1075 dateFormat.Append(date.GetMonth());
1076 dateFormat.Append('-');
1077 if(date.GetDay() < 10)
1079 dateFormat.Append('0');
1081 dateFormat.Append(date.GetDay());
1082 dateFormat.Append(' ');
1083 if(date.GetHour() < 10)
1085 dateFormat.Append('0');
1087 dateFormat.Append(date.GetHour());
1088 dateFormat.Append(':');
1089 if(date.GetMinute() < 10)
1091 dateFormat.Append('0');
1093 dateFormat.Append(date.GetMinute());
1094 dateFormat.Append(':');
1095 if(date.GetSecond() < 10)
1097 dateFormat.Append('0');
1099 dateFormat.Append(date.GetSecond());