merge with master
[framework/osp/web.git] / src / FWeb_BookmarkItemImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FWeb_HistoryItemImplcpp
20  * @brief               The file contains the definition of _HistoryItemImpl class.
21  *
22  * This file contains the definition of _HistoryItemImpl class.
23  */
24 #include <favorites.h>
25 #include <unique_ptr.h>
26 #include <FBaseBoolean.h>
27 #include <FBaseInteger.h>
28 #include <FBaseSysLog.h>
29 #include <FGrpBitmap.h>
30 #include <FGrpDimension.h>
31 #include <FWebBookmarkItem.h>
32 #include "FWeb_BookmarkItemImpl.h"
33 #include "FWebCtrl_Utility.h"
34
35
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Web::Controls;
39
40
41 namespace Tizen { namespace Web
42 {
43
44
45 _BookmarkItemImpl::_BookmarkItemImpl(void)
46         : __isFolder(false)
47         , __id(0)
48         , __parentId(0)
49         , __url(L"")
50         , __title(L"")
51
52 {
53 }
54
55
56 _BookmarkItemImpl::~_BookmarkItemImpl(void)
57 {
58 }
59
60
61 void
62 _BookmarkItemImpl::SetBookmarkItem(RecordId id, const String& url, const String& title, RecordId parentId, bool isFolder)
63 {
64         __id = id;
65         __url = url;
66         __title = title;
67         __parentId = parentId;
68         __isFolder = isFolder;
69 }
70
71
72 String
73 _BookmarkItemImpl::GetTitle(void) const
74 {
75         return __title;
76 }
77
78
79 String
80 _BookmarkItemImpl::GetUrl(void) const
81 {
82         return __url;
83 }
84
85
86 Bitmap*
87 _BookmarkItemImpl::GetFaviconN(void) const
88 {
89         result r = E_SUCCESS;
90
91         Evas* pEvas = _Utility::GetEvasFromUiApp();
92         SysTryReturn(NID_WEB, pEvas, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
93
94         Evas_Object* pIcon = null;
95         int ret = favorites_bookmark_get_favicon(__id, pEvas, &pIcon);
96         SysTryReturn(NID_WEB, ret == FAVORITES_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] Propagating.");
97
98         BufferInfo bufferInfo;
99         r = _Utility::GetPixelBufferFromEvasObject(pIcon,  bufferInfo);
100         SysTryReturn(NID_WEB, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
101
102         const Dimension dimension(bufferInfo.width, bufferInfo.height);
103
104         ByteBuffer byteBuffer;
105         r = byteBuffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, dimension.height * dimension.width * 32, dimension.height * dimension.width * 32 );
106         SysTryReturn(NID_WEB, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
107
108         std::unique_ptr<Bitmap> pImage(new (std::nothrow) Bitmap());
109         SysTryReturn(NID_WEB, pImage.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
110
111         r = pImage->Construct(byteBuffer, dimension, BITMAP_PIXEL_FORMAT_ARGB8888);
112         SysTryReturn(NID_WEB, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
113
114         return pImage.release();
115 }
116
117
118 RecordId
119 _BookmarkItemImpl::GetParentFolderId(void) const
120 {
121         return __parentId;
122 }
123
124
125 bool
126 _BookmarkItemImpl::IsFolder(void) const
127 {
128         return __isFolder;
129 }
130
131
132 bool
133 _BookmarkItemImpl::Equals(const Object& obj) const
134 {
135         const _BookmarkItemImpl* pRhs = dynamic_cast< const _BookmarkItemImpl* >(&obj);
136         if (pRhs == null)
137         {
138                 return false;
139         }
140
141         return __id == pRhs->__id && __url == pRhs->__url && __title == pRhs->__title && __parentId == pRhs->__parentId
142                    && __isFolder == pRhs->__isFolder;
143 }
144
145
146 int
147 _BookmarkItemImpl::GetHashCode(void) const
148 {
149         return Integer(__id).GetHashCode() + __url.GetHashCode() + __title.GetHashCode()
150                 + Integer(__parentId).GetHashCode() + Boolean(__isFolder).GetHashCode();
151 }
152
153
154 _BookmarkItemImpl*
155 _BookmarkItemImpl::GetInstance(BookmarkItem* pBookmarkItem)
156 {
157         return pBookmarkItem->__pBookmarkItemImpl;
158 }
159
160
161 const _BookmarkItemImpl*
162 _BookmarkItemImpl::GetInstance(const BookmarkItem* pBookmarkItem)
163 {
164         return pBookmarkItem->__pBookmarkItemImpl;
165 }
166
167
168 }} // Tizen::Web