3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
5 // Licensed under the Flora License, Version 1.0 (the License);
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://floralicense.org/license/
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an AS IS BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
20 /*@file: IntHistoryPresentationModel.cpp
\r
21 *@brief: Provides functionalities to handle/maintain Browser History.
\r
25 #include "IntHistoryData.h"
\r
26 #include "IntHistoryPresentationModel.h"
\r
27 #include "IntTypes.h"
\r
29 using namespace Tizen::App;
\r
30 using namespace Tizen::Base;
\r
31 using namespace Tizen::Base::Collection;
\r
32 using namespace Tizen::Base::Utility;
\r
33 using namespace Tizen::Graphics;
\r
34 using namespace Tizen::Io;
\r
35 using namespace Tizen::Locales;
\r
36 using namespace Tizen::Media;
\r
37 using namespace Tizen::System;
\r
39 extern const wchar_t* HISTORY_DATA_TABLE;
\r
40 extern const wchar_t* BOOKMARK_URL_TABLE;
\r
42 HistoryPresentationModel* HistoryPresentationModel::__pHistoryPresentationModel = null;
\r
44 void HistoryPresentationModel::CreateInstance(void)
\r
46 if (__pHistoryPresentationModel == null)
\r
47 __pHistoryPresentationModel = new(std::nothrow) HistoryPresentationModel();
\r
48 result r = __pHistoryPresentationModel->Construct();
\r
51 delete __pHistoryPresentationModel;
\r
52 __pHistoryPresentationModel = null;
\r
55 std::atexit(DestroyInstance);
\r
59 HistoryPresentationModel* HistoryPresentationModel::GetInstance(void)
\r
61 if (__pHistoryPresentationModel == null)
\r
65 return __pHistoryPresentationModel;
\r
69 void HistoryPresentationModel::DestroyInstance(void)
\r
71 if (__pHistoryPresentationModel)
\r
73 delete __pHistoryPresentationModel;
\r
74 __pHistoryPresentationModel = null;
\r
78 HistoryPresentationModel::HistoryPresentationModel(void)
\r
83 HistoryPresentationModel::~HistoryPresentationModel(void)
\r
88 HistoryPresentationModel::HistoryPresentationModel(const HistoryPresentationModel& historyModelObj)
\r
93 HistoryPresentationModel& HistoryPresentationModel::operator=(const HistoryPresentationModel& historyModelObj)
\r
99 HistoryPresentationModel::Construct(void)
\r
101 result r = E_SUCCESS;
\r
102 DB_FILE_PATH = L"/opt/usr/dbspace/.browser-history.db";
\r
103 r = PresentationModelBase::Initialize();
\r
104 TryCatch( !IsFailed(r),,"Failed to initialize HistoryPresentationModel Model %s",GetErrorMessage(r));
\r
111 HistoryPresentationModel::SaveHistory(History& history)
\r
113 AppLog("HistoryPresentationModel::saveHistory");
\r
114 result r = E_FAILURE;
\r
115 String historyTable(HISTORY_DATA_TABLE);
\r
117 String columnNames;
\r
119 int resultCount = -1;
\r
124 ArrayList* pMostVisitedSites = null;
\r
125 bool isAlreadyExist = false;
\r
126 bool isEligibleForMostVisitedSites = true;
\r
128 String thumbnailPath;
\r
129 int todaysCount = 0;
\r
130 DateTime todayStart;
\r
132 SystemTime::GetCurrentTime(todayStart);
\r
133 SystemTime::GetCurrentTime(todayEnd);
\r
134 todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
\r
135 todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
\r
137 ArrayList* pTodaysList = new(std::nothrow) ArrayList();
\r
138 pTodaysList->Construct();
\r
139 GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
\r
140 GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
\r
142 for(int count = 0; count < todaysCount; count++)
\r
144 History *pHistoryItem = dynamic_cast<History*>(pTodaysList->GetAt(count));
\r
145 //AppLog("HistoryPresentationModel::saveHistory pHistoryItem id is %ls",pHistoryItem->GetHistoryId().GetPointer());
\r
146 AppLog("SaveHistory pHistoryItem url is %ls",pHistoryItem->GetHistoryUrl().GetPointer());
\r
147 AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
\r
149 if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
\r
151 history.SetHistoryId(pHistoryItem->GetHistoryId());
\r
152 AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
\r
157 pMostVisitedSites = new(std::nothrow) ArrayList();
\r
158 pMostVisitedSites->Construct();
\r
159 String historyTitle = history.GetHistoryTitle();
\r
160 historyTitle.Replace(L"'", L"''");
\r
162 String historyUrl = history.GetHistoryUrl();
\r
163 historyUrl.Replace(L"'", L"''");
\r
165 PresentationModelBase::GetCurrentDateTime(date);
\r
166 GetMostVisitedSites(*pMostVisitedSites);
\r
167 GetUrlCount(historyUrl, urlCount);
\r
168 for (i = 0; i < pMostVisitedSites->GetCount(); i++)
\r
170 History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
\r
171 if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
\r
173 AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
\r
174 isAlreadyExist = true;
\r
177 if ( pHistory != null && urlCount >= pHistory->GetVisitedCount())
\r
179 isEligibleForMostVisitedSites = true;
\r
183 isEligibleForMostVisitedSites = false;
\r
187 if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
\r
189 AppLog("HistoryPresentationModel::SaveHistory coming here");
\r
191 thumbnailPath = GenerateFileName();
\r
192 AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
\r
193 Image* pImage = new(std::nothrow) Image();
\r
194 pImage->Construct();
\r
195 result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
\r
199 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
\r
203 delete pMostVisitedSites;
\r
204 pMostVisitedSites = NULL ;
\r
206 if (history.GetHistoryId() == "")
\r
208 AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
\r
210 columnNames.Append(L"TITLE, ");
\r
211 columnNames.Append(L"URL, ");
\r
212 columnNames.Append(L"VISITED_TIME, ");
\r
213 columnNames.Append(L"ICON_PATH, ");
\r
214 columnNames.Append(L"FAVICON_ID, ");
\r
215 columnNames.Append(L"THUMBNAIL_PATH");
\r
217 query.Append(L"INSERT INTO ");
\r
218 query.Append(historyTable);
\r
220 query.Append(columnNames);
\r
221 query.Append(") ");
\r
222 query.Append("VALUES(");
\r
224 query.Append(historyTitle);
\r
226 query.Append(", ");
\r
228 query.Append(historyUrl);
\r
229 query.Append("', ");
\r
230 query.Append("DateTime(");
\r
232 query.Append(GetStringFromDate(date));
\r
233 query.Append("'), ");
\r
235 query.Append(history.GetHistoryIconPath());
\r
237 query.Append(", ");
\r
239 query.Append(history.GetFaviconId());
\r
241 query.Append(", ");
\r
243 query.Append(thumbnailPath);
\r
247 columnNames.Append(L"ADDRESS, ");
\r
248 columnNames.Append(L"TITLE, ");
\r
249 //columnNames.Append(L"COUNTER, ");
\r
250 columnNames.Append(L"VISITDATE");
\r
251 // columnNames.Append(L"FAVICON, ");
\r
252 // columnNames.Append(L"FAVICON_LENGTH, ");
\r
253 // columnNames.Append(L"FAVICON_W, ");
\r
254 // columnNames.Append(L"FAVICON_H, ");
\r
255 // columnNames.Append(L"SNAPSHOT, ");
\r
256 // columnNames.Append(L"SNAPSHOT_STRIDE, ");
\r
257 // columnNames.Append(L"SNAPSHOT_W, ");
\r
258 // columnNames.Append(L"SNAPSHOT_H");
\r
259 // columnNames.Append(L"ICON_PATH, ");
\r
260 // columnNames.Append(L"FAVICON_ID, ");
\r
261 // columnNames.Append(L"THUMBNAIL_PATH");
\r
263 query.Append(L"INSERT INTO ");
\r
264 query.Append(historyTable);
\r
266 query.Append(columnNames);
\r
267 query.Append(") ");
\r
268 query.Append("VALUES(");
\r
270 query.Append(historyUrl);
\r
272 query.Append(", ");
\r
274 query.Append(historyTitle);
\r
275 query.Append("', ");
\r
276 query.Append("DateTime(");
\r
278 query.Append(GetStringFromDate(date));
\r
279 query.Append("'))");
\r
281 //query.Append("'), ");
\r
282 //query.Append("'");
\r
283 //query.Append(history.GetHistoryIconPath());
\r
284 //query.Append("'");
\r
285 //query.Append(", ");
\r
286 //query.Append("'");
\r
287 //query.Append(history.GetFaviconId());
\r
288 //query.Append("'");
\r
289 //query.Append(", ");
\r
290 //query.Append("'");
\r
291 //query.Append(thumbnailPath);
\r
292 //query.Append("'");
\r
293 //query.Append(")");
\r
297 /*query.Append(L"UPDATE ");
\r
298 query.Append(historyTable);
\r
299 query.Append(" SET TITLE = ");
\r
301 query.Append(historyTitle);
\r
303 query.Append(", URL = ");
\r
305 query.Append(historyUrl);
\r
307 query.Append(", VISITED_TIME = ");
\r
308 query.Append("DateTime(");
\r
310 query.Append(GetStringFromDate(date));
\r
311 query.Append("')");
\r
312 query.Append(", ICON_PATH = ");
\r
314 query.Append(history.GetHistoryIconPath());
\r
316 query.Append(", ");
\r
318 query.Append(history.GetFaviconId());
\r
320 query.Append(", ");
\r
322 query.Append(thumbnailPath);
\r
324 query.Append(" WHERE ID = ");
\r
325 query.Append(history.GetHistoryId());*/
\r
326 query.Append(L"UPDATE ");
\r
327 query.Append(historyTable);
\r
328 query.Append(" SET ADDRESS = ");
\r
330 query.Append(historyUrl);
\r
332 query.Append(", TITLE = ");
\r
334 query.Append(historyTitle);
\r
336 query.Append(", VISITED_TIME = ");
\r
337 query.Append("DateTime(");
\r
339 query.Append(GetStringFromDate(date));
\r
340 query.Append("')");
\r
341 /*query.Append(", ICON_PATH = ");
\r
343 query.Append(history.GetHistoryIconPath());
\r
345 query.Append(", ");
\r
347 query.Append(history.GetFaviconId());
\r
349 query.Append(", ");
\r
351 query.Append(thumbnailPath);*/
\r
353 query.Append(" WHERE ID = ");
\r
354 query.Append(history.GetHistoryId());
\r
358 AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
\r
360 r = PresentationModelBase::ExecuteQuery(query, resultCount);
\r
361 if (r == E_SUCCESS)
\r
363 AppLog("HistoryPresentationModel::SaveHistory result is success");
\r
367 AppLog("HistoryPresentationModel::SaveHistory result is failure");
\r
369 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed %s",GetErrorMessage(r));
\r
371 r = PresentationModelBase::CommitDb();
\r
373 r = GetLastInsertedId(historyTable, rowId);
\r
376 AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
\r
382 historyId.Append(rowId);
\r
383 if (historyId.GetLength() < 0)
\r
387 //Set the generated ID to History
\r
388 history.SetHistoryId(historyId);
\r
394 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
\r
396 result r = E_FAILURE;
\r
398 String historyTable = HISTORY_DATA_TABLE;
\r
399 int resultCount = -1;
\r
401 if (pHistoryIdList == null)
\r
406 query.Append(L"DELETE FROM ");
\r
407 query.Append(historyTable);
\r
408 query.Append(" WHERE");
\r
409 for(int index = 0; index <= pHistoryIdList->GetCount()-2; index++)
\r
411 query.Append(" ID = ");
\r
412 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(index));
\r
413 query.Append(*hisId);
\r
414 query.Append(" OR ");
\r
416 query.Append(" ID = ");
\r
417 String* hisId = static_cast<String*>(pHistoryIdList->GetAt(pHistoryIdList->GetCount()-1));
\r
422 query.Append(*hisId);
\r
424 r = PresentationModelBase::ExecuteQuery(query, resultCount);
\r
425 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
\r
427 r = PresentationModelBase::CommitDb();
\r
433 HistoryPresentationModel::DeleteHistory(const int historyId)
\r
435 result r = E_FAILURE;
\r
437 String historyTable = HISTORY_DATA_TABLE;
\r
438 int resultCount = -1;
\r
442 return E_INVALID_ARG;
\r
445 query.Append(L"DELETE FROM ");
\r
446 query.Append(historyTable);
\r
447 query.Append(" WHERE ID = ");
\r
448 query.Append(historyId);
\r
450 r = PresentationModelBase::ExecuteQuery(query, resultCount);
\r
451 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
\r
453 r = PresentationModelBase::CommitDb();
\r
459 HistoryPresentationModel::DeleteHistory(String& historyUrl)
\r
461 result r = E_FAILURE;
\r
463 String historyTable = HISTORY_DATA_TABLE;
\r
464 int resultCount = -1;
\r
466 query.Append(L"DELETE FROM ");
\r
467 query.Append(historyTable);
\r
468 query.Append(" WHERE URL = '");
\r
469 query.Append(historyUrl);
\r
472 r = PresentationModelBase::ExecuteQuery(query, resultCount);
\r
473 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::DeleteHistory GetLastInsertedId failed %s",GetErrorMessage(r));
\r
475 r = PresentationModelBase::CommitDb();
\r
481 HistoryPresentationModel::ClearHistory(void)
\r
483 result r = E_FAILURE;
\r
485 String historyTable = HISTORY_DATA_TABLE;
\r
486 int resultCount = -1;
\r
488 query.Append(L"DELETE FROM ");
\r
489 query.Append(historyTable);
\r
491 r = PresentationModelBase::ExecuteQuery(query, resultCount);
\r
492 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::ClearHistory GetLastInsertedId failed %s",GetErrorMessage(r));
\r
494 r = PresentationModelBase::CommitDb();
\r
500 HistoryPresentationModel::GetHistoryCount(int& historyCount)
\r
505 String historyTable(HISTORY_DATA_TABLE);
\r
506 result r = E_FAILURE;
\r
507 bool nextRowPresent = false;
\r
509 query.Append(L"SELECT COUNT(ID) FROM ");
\r
510 query.Append(historyTable);
\r
512 r = PresentationModelBase::ExecuteQuery(query, count);
\r
513 AppLog("the count is %d", count);
\r
514 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
\r
516 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
\r
517 if (IsFailed(r) != null)
\r
519 if (nextRowPresent == true)
\r
521 r = PresentationModelBase::GetColumn(0, intVal);
\r
522 if (IsFailed(r) != null)
\r
524 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
\r
528 historyCount = intVal;
\r
534 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
\r
540 String historyTable(HISTORY_DATA_TABLE);
\r
541 result r = E_FAILURE;
\r
542 bool nextRowPresent = false;
\r
544 query.Append(L"SELECT COUNT(ID) FROM ");
\r
545 query.Append(historyTable);
\r
546 query.Append(" WHERE VISITDATE >= ");
\r
547 query.Append("DateTime(");
\r
549 query.Append(GetStringFromDate(startTime));
\r
550 query.Append("')");
\r
551 query.Append(" AND VISITDATE <= ");
\r
552 query.Append("DateTime(");
\r
554 query.Append(GetStringFromDate(endTime));
\r
555 query.Append("')");
\r
557 r = PresentationModelBase::ExecuteQuery(query, count);
\r
558 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCountWithTimeRange query failed %s",GetErrorMessage(r));
\r
560 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
\r
563 if (nextRowPresent == true)
\r
565 r = PresentationModelBase::GetColumn(0, intVal);
\r
568 AppLogDebug("Error:PresentationModelBase::DbGetColumn:%s", GetErrorMessage(r));
\r
572 historyCount = intVal;
\r
578 HistoryPresentationModel::GetHistory(const int startIndex,const int limit, ArrayList& pHistoryList)
\r
583 String historyTable(HISTORY_DATA_TABLE);
\r
584 result r = E_FAILURE;
\r
586 query.Append(L"SELECT");
\r
587 query.Append(historyTable);
\r
588 query.Append(L".*, ");
\r
589 query.Append(BOOKMARK_URL_TABLE);
\r
590 query.Append(L".ID ");
\r
591 query.Append(L"FROM ");
\r
592 query.Append(historyTable);
\r
593 query.Append(L", ");
\r
594 query.Append(BOOKMARK_URL_TABLE);
\r
595 query.Append(L" WHERE ");
\r
596 query.Append(historyTable);
\r
597 query.Append(L".ADDRESS ");
\r
598 query.Append(L"IN");
\r
599 query.Append(L"(");
\r
600 query.Append(L"SELECT");
\r
601 query.Append(historyTable);
\r
602 query.Append(L".ADDRESS ");
\r
603 query.Append(L"FROM ");
\r
604 query.Append(BOOKMARK_URL_TABLE);
\r
605 query.Append(L" LEFT JOIN ");
\r
606 query.Append(historyTable);
\r
607 query.Append(L"ON");
\r
608 query.Append(BOOKMARK_URL_TABLE);
\r
609 query.Append(L".ADDRESS = ");
\r
610 query.Append(historyTable);
\r
611 query.Append(L".ADDRESS ");
\r
612 query.Append(" ORDER BY");
\r
613 query.Append(historyTable);
\r
614 query.Append(L".VISITDATE DESC");
\r
616 query.Append(" GROUP BY ");
\r
617 query.Append(historyTable);
\r
618 query.Append(L".ADDRESS ");
\r
619 query.Append(" ORDER BY");
\r
620 query.Append(L"COUNT(");
\r
621 query.Append(historyTable);
\r
622 query.Append(L".ADDRESS) DESC ");
\r
628 query.Append(" LIMIT ");
\r
629 query.Append(limit);
\r
632 if (startIndex >= 0)
\r
634 query.Append(" OFFSET ");
\r
635 query.Append(startIndex);
\r
639 r = PresentationModelBase::ExecuteQuery(query, count);
\r
640 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistory query failed %s",GetErrorMessage(r));
\r
642 r = CreateHistoryList(count, pHistoryList);
\r
645 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
\r
651 HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& historyList, int maxCount)
\r
654 History* pHistory = null;
\r
658 result r = E_FAILURE;
\r
663 DateTime visitedTime;
\r
665 String thumbnailPath;
\r
666 bool nextRowPresent = false;
\r
668 Bitmap* pThumnailBitmap = null;
\r
671 if (historyCount < 1)
\r
676 for (int Count = 0; (maxCount == -1 && Count < historyCount ) || (maxCount != -1 && Count < maxCount && Count < historyCount); Count++)
\r
678 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
\r
683 if (nextRowPresent == true)
\r
685 pHistory = new(std::nothrow) History;
\r
688 for (int columnCount = 0; columnCount < MAX_NOTE_TABLE_COLUMN; columnCount++)
\r
691 switch (columnCount)
\r
694 r = PresentationModelBase::GetColumn(columnCount, intVal);
\r
700 historyId.Append(intVal);
\r
701 if (historyId.GetLength() > 0)
\r
703 pHistory->SetHistoryId(historyId);
\r
710 r = PresentationModelBase::GetColumn(columnCount, stringVal);
\r
713 pHistory->SetHistoryUrl(stringVal);
\r
716 case HISTORY_TITLE:
\r
717 r = PresentationModelBase::GetColumn(columnCount, stringVal);
\r
720 pHistory->SetHistoryTitle(stringVal);
\r
723 case HISTORY_VISITED_TIME:
\r
724 r = PresentationModelBase::GetColumn(columnCount, dateVal);
\r
727 visitedTime = dateVal;
\r
728 pHistory->SetVisitedTime(visitedTime);
\r
732 /*case HISTORY_ICON_PATH:
\r
733 r = PresentationModelBase::GetColumn(columnCount, stringVal);
\r
736 iconPath = stringVal;
\r
737 pHistory->SetIconPath(iconPath);
\r
741 case HISTORY_FAVICONID:
\r
743 r = PresentationModelBase::GetColumn(columnCount, intVal);
\r
749 faviconId.Append(intVal);
\r
750 if (faviconId.GetLength() > 0)
\r
752 pHistory->SetFaviconId(faviconId);
\r
757 case HISTORY_THUMBNAIL:
\r
758 r = PresentationModelBase::GetColumn(columnCount, stringVal);
\r
762 thumbnailPath = stringVal;
\r
763 pThumnailBitmap = image.DecodeN(thumbnailPath, BITMAP_PIXEL_FORMAT_RGB565);
\r
764 if (pThumnailBitmap != null)
\r
766 pHistory->SetThumbnail(pThumnailBitmap);
\r
767 pHistory->SetThumbnailPath(thumbnailPath);
\r
771 /* case HISTORY_BOOKMARK_ID:
\r
772 r = PresentationModelBase::GetColumn(columnCount, intVal);
\r
777 bookmarkId.Clear();
\r
778 bookmarkId.Append(intVal);
\r
779 if (bookmarkId.GetLength() > 0)
\r
781 pHistory->SetBookmarkId(bookmarkId);
\r
788 case HISTORY_VISITED_COUNT:
\r
789 r = PresentationModelBase::GetColumn(columnCount, intVal);
\r
794 pHistory->SetVisitedCount(intVal);
\r
806 r = historyList.Add(*pHistory);
\r
820 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
\r
822 text.Replace(L"'", L"''");
\r
826 String historyTable(HISTORY_DATA_TABLE);
\r
827 result r = E_FAILURE;
\r
829 query.Append(L"SELECT ");
\r
830 query.Append(historyTable);
\r
831 query.Append(L".* ");
\r
832 query.Append(L"FROM ");
\r
833 query.Append(historyTable);
\r
834 query.Append(L" WHERE (");
\r
835 query.Append(historyTable);
\r
836 query.Append(L".TITLE LIKE '%");
\r
837 query.Append(text);
\r
838 query.Append("%')");
\r
839 query.Append(" OR ");
\r
840 query.Append(L"(");
\r
841 query.Append(historyTable);
\r
842 query.Append(L".ADDRESS LIKE '%");
\r
843 query.Append(text);
\r
844 query.Append("%')");
\r
845 query.Append(" ORDER BY VISITDATE DESC");
\r
850 query.Append(" LIMIT ");
\r
851 query.Append(limit);
\r
854 if (startIndex >= 0)
\r
856 query.Append(" OFFSET ");
\r
857 query.Append(startIndex);
\r
861 r = HistoryPresentationModel::ExecuteQuery(query, count);
\r
862 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
\r
864 r = CreateHistoryList(count, pHistoryList);
\r
867 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
\r
873 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
\r
878 String historyTable(HISTORY_DATA_TABLE);
\r
879 result r = E_FAILURE;
\r
880 bool nextRowPresent = false;
\r
882 text.Replace(L"'", L"''");
\r
883 query.Append(L"SELECT COUNT(ID) FROM ");
\r
884 query.Append(historyTable);
\r
885 query.Append(L" WHERE (TITLE LIKE '%");
\r
886 query.Append(text);
\r
887 query.Append("%')");
\r
888 query.Append(" OR ");
\r
889 query.Append(L"(ADDRESS LIKE '%");
\r
890 query.Append(text);
\r
891 query.Append("%')");
\r
893 r = HistoryPresentationModel::ExecuteQuery(query, count);
\r
894 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));
\r
896 r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);
\r
897 if (IsFailed(r) != null)
\r
899 if (nextRowPresent == true)
\r
901 r = HistoryPresentationModel::GetColumn(0, intVal);
\r
902 if (IsFailed(r) != null)
\r
904 AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));
\r
908 historyCount = intVal;
\r
914 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
\r
918 String historyTable(HISTORY_DATA_TABLE);
\r
919 result r = E_FAILURE;
\r
921 query.Append(L"SELECT ");
\r
922 //query.Append(historyTable);
\r
923 query.Append(L"* ");
\r
924 query.Append(L"FROM ");
\r
925 query.Append(historyTable);
\r
926 query.Append(" WHERE ");
\r
927 //query.Append(historyTable);
\r
928 query.Append(L"VISITDATE >= ");
\r
929 query.Append("DateTime(");
\r
931 query.Append(GetStringFromDate(startTime));
\r
932 query.Append("')");
\r
933 query.Append(" AND ");
\r
934 //query.Append(historyTable);
\r
935 query.Append(L"VISITDATE <= ");
\r
936 query.Append("DateTime(");
\r
938 query.Append(GetStringFromDate(endTime));
\r
939 query.Append("')");
\r
940 query.Append(" ORDER BY VISITDATE DESC");
\r
945 query.Append(" LIMIT ");
\r
946 query.Append(limit);
\r
949 if (startIndex >= 0)
\r
951 query.Append(" OFFSET ");
\r
952 query.Append(startIndex);
\r
956 r = HistoryPresentationModel::ExecuteQuery(query, count);
\r
957 AppLog("the count is %d",count);
\r
958 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
\r
960 r = CreateHistoryList(count, pHistoryList);
\r
963 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
\r
970 HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
\r
975 String historyTable(HISTORY_DATA_TABLE);
\r
976 result r = E_FAILURE;
\r
979 //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
\r
980 query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
\r
982 r = HistoryPresentationModel::ExecuteQuery(query, count);
\r
983 AppLog("the count is %d",count);
\r
984 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
\r
986 r = CreateHistoryList(count, pHistoryList, 9);
\r
989 AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
\r
996 HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
\r
1001 String historyTable(HISTORY_DATA_TABLE);
\r
1002 result r = E_FAILURE;
\r
1003 bool nextRowPresent = false;
\r
1005 query.Append(L"SELECT COUNT(ADDRESS) FROM ");
\r
1006 query.Append(historyTable);
\r
1007 query.Append(L" WHERE ADDRESS = ");
\r
1008 query.Append("'");
\r
1009 query.Append(Url);
\r
1010 query.Append("'");
\r
1012 r = PresentationModelBase::ExecuteQuery(query, count);
\r
1013 AppLog("the count is %d", count);
\r
1014 TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCount query failed %s",GetErrorMessage(r));
\r
1016 r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
\r
1019 if (nextRowPresent == true)
\r
1021 r = PresentationModelBase::GetColumn(0, intVal);
\r
1024 AppLogDebug("Error:PresentationModelBase::GetColumn:%s", GetErrorMessage(r));
\r
1028 historyCount = intVal;
\r
1034 HistoryPresentationModel::GenerateFileName(void)
\r
1036 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
\r
1037 if ( pAppRegistry == NULL )
\r
1041 String keyCount("ThumbnailCount");
\r
1042 String fileName = UiApp::GetInstance()->GetAppRootPath() + "/data/Thumbnail/thumbnails";
\r
1043 result r = E_SUCCESS;
\r
1045 r = pAppRegistry->Get(keyCount, keyValue);
\r
1047 if (r == E_KEY_NOT_FOUND)
\r
1050 pAppRegistry->Add(keyCount, keyValue);
\r
1055 pAppRegistry->Set(keyCount, keyValue);
\r
1058 fileName.Append(keyValue);
\r
1059 fileName.Append(".jpg");
\r
1060 pAppRegistry->Save();
\r
1066 HistoryPresentationModel::GetStringFromDate(DateTime& date)
\r
1068 String dateFormat = L"";
\r
1069 dateFormat.Append(date.GetYear());
\r
1070 dateFormat.Append('-');
\r
1071 if(date.GetMonth() < 10)
\r
1073 dateFormat.Append('0');
\r
1075 dateFormat.Append(date.GetMonth());
\r
1076 dateFormat.Append('-');
\r
1077 if(date.GetDay() < 10)
\r
1079 dateFormat.Append('0');
\r
1081 dateFormat.Append(date.GetDay());
\r
1082 dateFormat.Append(' ');
\r
1083 if(date.GetHour() < 10)
\r
1085 dateFormat.Append('0');
\r
1087 dateFormat.Append(date.GetHour());
\r
1088 dateFormat.Append(':');
\r
1089 if(date.GetMinute() < 10)
\r
1091 dateFormat.Append('0');
\r
1093 dateFormat.Append(date.GetMinute());
\r
1094 dateFormat.Append(':');
\r
1095 if(date.GetSecond() < 10)
\r
1097 dateFormat.Append('0');
\r
1099 dateFormat.Append(date.GetSecond());
\r
1100 return dateFormat;
\r