Fixed Nabi Issues 52332,54256,54601,54130,54264,54471
[apps/osp/Internet.git] / src / IntBookmarkPresentationModel.cpp
index 8460bb4..1311fbb 100644 (file)
@@ -2,7 +2,7 @@
 
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
@@ -91,6 +91,7 @@ void BookmarkPresentationModel::DestroyInstance(void)
 {
        if (__pBookmarkPresentationModel)
        {
+               __pBookmarkPresentationModel->UnInitialize();
                delete __pBookmarkPresentationModel;
                __pBookmarkPresentationModel = null;
        }
@@ -110,78 +111,9 @@ BookmarkPresentationModel::GetInstance(void)
 result
 BookmarkPresentationModel::SaveFolder(BookmarkData& bookmark)
 {
-       bookmark.SetParentId("-1");
-       SaveTempBookmark(bookmark);
-       /*
-       result r = E_FAILURE;
-       String bookmarkFolderTable(BOOKMARK_FOLDER_TABLE);
-       String query;
-       String columnNames;
-       int resultCount = -1;
-       int rowId = -1;
-       DateTime dt;
-       String bookmarkId;
-       String bookmarkTitle = bookmark.GetBookmarkTitle();
-       bookmarkTitle.Replace(L"'", L"''");
-
-       PresentationModelBase::GetCurrentDateTime(dt);
-       if (bookmark.GetBookmarkId() == "")
-       {
-               columnNames.Append(L"TITLE, ");
-               columnNames.Append(L"CREATED_TIME, ");
-               columnNames.Append(L"MODIFIED_TIME");
-
-               query.Append(L"INSERT INTO ");
-               query.Append(bookmarkFolderTable);
-               query.Append("(");
-               query.Append(columnNames);
-               query.Append(") ");
-               query.Append("VALUES(");
-               query.Append("'");
-               query.Append(bookmarkTitle);
-               query.Append("', ");
-               query.Append("'");
-               query.Append(dt.ToString());
-               query.Append("', ");
-               query.Append("'");
-               query.Append(dt.ToString());
-               query.Append("')");
-       }
-       else
-       {
-               query.Append(L"UPDATE ");
-               query.Append(bookmarkFolderTable);
-               query.Append(" SET TITLE = ");
-               query.Append("'");
-               query.Append(bookmarkTitle);
-               query.Append("'");
-               query.Append(", MODIFIED_TIME = ");
-               query.Append("'");
-               query.Append(dt.ToString());
-               query.Append("'");
-               query.Append(" WHERE ID = ");
-               query.Append(bookmark.GetBookmarkId());
-       }
-
-
-       r = PresentationModelBase::ExecuteQuery(query, resultCount);
-       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveFolder query failed  %s",GetErrorMessage(r));
-
-       r = PresentationModelBase::CommitDb();
-
-       r = GetLastInsertedId(bookmarkFolderTable, rowId);
-       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveFolder GetLastInsertedId failed %s",GetErrorMessage(r));
-
-       if (rowId < 0)
-               return E_FAILURE;
-
-       bookmarkId.Append(rowId);
-
-       //Set the generated ID to Bookmark
-       bookmark.SetBookmarkId(bookmarkId);
-
-    CATCH: return r;
-*/}
+       bookmark.SetParentId("0");
+       return SaveTempBookmark(bookmark);
+}
 
 result
 BookmarkPresentationModel::SaveBookmark(BookmarkData& bookmark)
@@ -196,9 +128,9 @@ BookmarkPresentationModel::SaveBookmark(BookmarkData& bookmark)
        DateTime dt;
        String bookmarkId;
        String bookmarkTitle = bookmark.GetBookmarkTitle();
-       bookmarkTitle.Replace(L"'", L"''");
+       bookmarkTitle.Replace(L"'", L"\'");
        String bookmarkUrl = bookmark.GetUrl();
-       bookmarkUrl.Replace(L"'", L"''");
+       bookmarkUrl.Replace(L"'", L"\'");
 
        AppLog("BookmarkPresentationModel::SaveBookmark");
 
@@ -704,6 +636,26 @@ BookmarkPresentationModel::GetBookmark(const String& parentID, int startIndex, i
        CATCH: return r;
 }
 
+result BookmarkPresentationModel::GetBookmarkForHistory(int startIndex, Tizen::Base::Collection::ArrayList& pBookmarkList)
+{
+       int count = -1;
+       String query;
+       String bookmarkTable(BOOKMARK_URL_TABLE);
+       result r = E_FAILURE;
+
+       query.Append(L"SELECT * FROM ");
+       query.Append(bookmarkTable);
+       query.Append(" WHERE ADDRESS != ''");
+
+       r = PresentationModelBase::ExecuteQuery(query, count);
+       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetBookmark query failed  %s",GetErrorMessage(r));
+
+       r = CreateBookmarkList(count, pBookmarkList);
+       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::CreateBookmarkList failed  %s",GetErrorMessage(r));
+
+       CATCH: return r;
+}
+
 result
 BookmarkPresentationModel::GetFolder(const String& parentID, int startIndex, int limit, ArrayList& folderList)
 {
@@ -764,7 +716,7 @@ BookmarkPresentationModel::GetSearchBookmarkCount(int& searchBookmarkCount, Stri
        String bookmarkTable(BOOKMARK_URL_TABLE);
        result r = E_FAILURE;
        bool nextRowPresent = false;
-       text.Replace(L"'", L"''");
+       text.Replace(L"'", L"\'");
 
        query.Append(L"SELECT COUNT(ID) FROM ");
        query.Append(bookmarkTable);
@@ -774,7 +726,8 @@ BookmarkPresentationModel::GetSearchBookmarkCount(int& searchBookmarkCount, Stri
        query.Append(" OR ");
        query.Append(L"ADDRESS LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%'");
+       query.Append(" ESCAPE '/')");
        query.Append(" AND ADDRESS != ''");
 
        r = BookmarkPresentationModel::ExecuteQuery(query, count);
@@ -789,7 +742,10 @@ BookmarkPresentationModel::GetSearchBookmarkCount(int& searchBookmarkCount, Stri
        }
        searchBookmarkCount = intVal;
 
-       CATCH: return r;
+       CATCH:
+//     text.Replace(L"''", L"'");
+       return r;
+
 }
 
 
@@ -803,13 +759,14 @@ BookmarkPresentationModel::GetSearchFolderCount(int& searchFolderCount, String&
        String bookmarkTable(BOOKMARK_URL_TABLE);
        result r = E_FAILURE;
        bool nextRowPresent = false;
-       text.Replace(L"'", L"''");
+       text.Replace(L"'", L"\'");
 
        query.Append(L"SELECT COUNT(ID) FROM ");
        query.Append(bookmarkTable);
        query.Append(L" WHERE TITLE LIKE '%");
        query.Append(text);
        query.Append("%'");
+       query.Append(" ESCAPE '/'");
        query.Append(" AND ADDRESS = ''");
 
        r = BookmarkPresentationModel::ExecuteQuery(query, count);
@@ -824,7 +781,9 @@ BookmarkPresentationModel::GetSearchFolderCount(int& searchFolderCount, String&
        }
        searchFolderCount = intVal;
 
-       CATCH: return r;
+       CATCH:
+//     text.Replace(L"''", L"'");
+       return r;
 }
 
 
@@ -855,17 +814,17 @@ BookmarkPresentationModel::GetSearchBookmark(int startIndex, int limit, ArrayLis
        String bookmarkTable(BOOKMARK_URL_TABLE);
        result r = E_FAILURE;
 
-       text.Replace(L"'", L"''");
+       text.Replace(L"'", L"\'");
        query.Append(L"SELECT * FROM ");
        query.Append(bookmarkTable);
-       query.Append(L" WHERE (TITLE LIKE '%");
+       query.Append(L" WHERE ((TITLE LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%' ESCAPE '/')");
        query.Append(" OR ");
        query.Append(L"(ADDRESS LIKE '%");
        query.Append(text);
-       query.Append("%')");
-       query.Append(" AND ADDRESS != ''");
+       query.Append("%' ESCAPE '/') )");
+       query.Append(" AND (ADDRESS != '')");
        //Append LIMIT
        if (limit > 0)
        {
@@ -879,14 +838,16 @@ BookmarkPresentationModel::GetSearchBookmark(int startIndex, int limit, ArrayLis
                        query.Append(startIndex);
                }
        }
-
+       AppLog("Query is %ls", query.GetPointer());
        r = BookmarkPresentationModel::ExecuteQuery(query, count);
        TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchBookmark query failed  %s",GetErrorMessage(r));
 
        r = CreateBookmarkList(count, pBookmarkList);
        TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::CreateBookmarkList failed  %s",GetErrorMessage(r));
 
-       CATCH: return r;
+       CATCH:
+//     text.Replace(L"''", L"'");
+       return r;
 }
 
 result
@@ -896,7 +857,7 @@ BookmarkPresentationModel::GetSearchFolder(int startIndex, int limit, ArrayList&
        String query;
        String bookmarkTable(BOOKMARK_URL_TABLE);
        result r = E_FAILURE;
-       text.Replace(L"'", L"''");
+       text.Replace(L"'", L"\'");
 
        query.Append(L"SELECT * FROM ");
        query.Append(bookmarkTable);
@@ -904,6 +865,7 @@ BookmarkPresentationModel::GetSearchFolder(int startIndex, int limit, ArrayList&
        query.Append(text);
        //query.Append("%')");
        query.Append("%'");
+       query.Append(" ESCAPE '/'");
        query.Append(" AND ADDRESS = ''");
 
        //Append LIMIT
@@ -926,7 +888,9 @@ BookmarkPresentationModel::GetSearchFolder(int startIndex, int limit, ArrayList&
        r = CreateFolderList(count, pFolderList);
        TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::CreateBookmarkList failed  %s",GetErrorMessage(r));
 
-       CATCH: return r;
+       CATCH:
+//     text.Replace(L"''", L"'");
+       return r;
 }
 
 result
@@ -1289,11 +1253,29 @@ BookmarkPresentationModel::DoesBookmarkExist(const Tizen::Base::String& Url, boo
        result r = E_FAILURE;
        bool nextRowPresent = false;
        int count = 0;
+       String tempURL = Url;
+       tempURL.Replace(L"'", L"''");
 
        query.Append(L"SELECT COUNT(ID) FROM ");
        query.Append(bookmarkTable);
        query.Append(" WHERE ADDRESS = '");
-       query.Append(Url);
+       query.Append(tempURL);
+       if(tempURL.EndsWith(L"/"))
+       {
+               query.Append("' OR ADDRESS = '");
+               String newUrl = L"";
+               tempURL.SubString(0,tempURL.GetLength()-1 ,newUrl);
+               query.Append(newUrl);
+       }
+       else
+       {
+               query.Append("' OR ADDRESS = '");
+               String newUrl = tempURL;
+//             Url.SubString(0,Url.GetLength()-1 ,newUrl);
+               newUrl.Append(L"/");
+               query.Append(newUrl);
+       }
+
        if(checkParentId == true)
        {
                query.Append(L"' AND PARENT = '");
@@ -1322,7 +1304,7 @@ BookmarkPresentationModel::DoesBookmarkExist(const Tizen::Base::String& Url, boo
        {
                exist = true ;
        }
-
+       tempURL.Replace(L"''",L"'");
        CATCH: return r;
 }
 
@@ -1338,6 +1320,24 @@ BookmarkPresentationModel::DeleteBookmark(const Tizen::Base::String& url)
        query.Append(bookmarkTable);
        query.Append(" WHERE ADDRESS = '");
        query.Append(url);
+
+       if(url.EndsWith(L"/"))
+       {
+               query.Append("' OR ADDRESS = '");
+               String newUrl = L"";
+               url.SubString(0,url.GetLength()-1 ,newUrl);
+               query.Append(newUrl);
+       }
+       else
+       {
+               query.Append("' OR ADDRESS = '");
+               String newUrl = url;
+//             Url.SubString(0,Url.GetLength()-1 ,newUrl);
+               newUrl.Append(L"/");
+               query.Append(newUrl);
+
+       }
+
        query.Append(L"'");
 
        r = BookmarkPresentationModel::ExecuteQuery(query, resultCount);