Tizen 2.2.1
[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 <FUiCtrlFrame.h>
32 #include <FWebBookmarkItem.h>
33 #include "FWeb_BookmarkItemImpl.h"
34 #include "FWebCtrl_Utility.h"
35
36
37 using namespace Tizen::Base;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Web::Controls;
41
42
43 namespace Tizen { namespace Web
44 {
45
46
47 _BookmarkItemImpl::_BookmarkItemImpl(void)
48         : __isFolder(false)
49         , __id(0)
50         , __parentId(0)
51         , __url(L"")
52         , __title(L"")
53
54 {
55 }
56
57
58 _BookmarkItemImpl::~_BookmarkItemImpl(void)
59 {
60 }
61
62
63 void
64 _BookmarkItemImpl::SetBookmarkItem(RecordId id, const String& url, const String& title, RecordId parentId, bool isFolder)
65 {
66         __id = id;
67         __url = url;
68         __title = title;
69         __parentId = parentId;
70         __isFolder = isFolder;
71 }
72
73
74 String
75 _BookmarkItemImpl::GetTitle(void) const
76 {
77         return __title;
78 }
79
80
81 String
82 _BookmarkItemImpl::GetUrl(void) const
83 {
84         return __url;
85 }
86
87
88 Bitmap*
89 _BookmarkItemImpl::GetFaviconN(void) const
90 {
91         result r = E_SUCCESS;
92         Frame* pFrame = null;
93         Evas* pEvas = null;
94         Evas_Object* pIcon = null;
95
96         BufferInfo bufferInfo;
97         ByteBuffer byteBuffer;
98
99         std::unique_ptr<Bitmap> pImage;
100         Dimension dimension;
101         int ret = 0;
102
103         pEvas = _Utility::GetEvasFromUiApp(pFrame);
104         SysTryCatch(NID_WEB, pEvas, , E_SYSTEM, "[E_SYSTEM] Propagating.");
105
106         ret = favorites_bookmark_get_favicon(__id, pEvas, &pIcon);
107         SysTryCatch(NID_WEB, ret == FAVORITES_ERROR_NONE, , E_SYSTEM, "[E_SYSTEM] Propagating.");
108
109         if (!pIcon)
110         {
111                 return null;
112         }
113
114         r = _Utility::GetPixelBufferFromEvasObject(pIcon,  bufferInfo);
115         SysTryCatch(NID_WEB, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
116
117         dimension.width = bufferInfo.width;
118         dimension.height = bufferInfo.height;
119
120         r = byteBuffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, dimension.height * dimension.width * 32, dimension.height * dimension.width * 32 );
121         SysTryCatch(NID_WEB, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
122
123         pImage = std::unique_ptr<Bitmap>(new (std::nothrow) Bitmap());
124         SysTryCatch(NID_WEB, pImage.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
125
126         r = pImage->Construct(byteBuffer, dimension, BITMAP_PIXEL_FORMAT_ARGB8888);
127         SysTryCatch(NID_WEB, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
128
129         delete pFrame;
130
131         return pImage.release();
132
133 CATCH:
134         delete pFrame;
135
136         return null;
137 }
138
139
140 RecordId
141 _BookmarkItemImpl::GetParentFolderId(void) const
142 {
143         return __parentId;
144 }
145
146
147 bool
148 _BookmarkItemImpl::IsFolder(void) const
149 {
150         return __isFolder;
151 }
152
153
154 bool
155 _BookmarkItemImpl::Equals(const Object& obj) const
156 {
157         const _BookmarkItemImpl* pRhs = dynamic_cast< const _BookmarkItemImpl* >(&obj);
158         if (pRhs == null)
159         {
160                 return false;
161         }
162
163         return __id == pRhs->__id && __url == pRhs->__url && __title == pRhs->__title && __parentId == pRhs->__parentId
164                    && __isFolder == pRhs->__isFolder;
165 }
166
167
168 int
169 _BookmarkItemImpl::GetHashCode(void) const
170 {
171         return Integer(__id).GetHashCode() + __url.GetHashCode() + __title.GetHashCode()
172                 + Integer(__parentId).GetHashCode() + Boolean(__isFolder).GetHashCode();
173 }
174
175
176 _BookmarkItemImpl*
177 _BookmarkItemImpl::GetInstance(BookmarkItem* pBookmarkItem)
178 {
179         return pBookmarkItem->__pBookmarkItemImpl;
180 }
181
182
183 const _BookmarkItemImpl*
184 _BookmarkItemImpl::GetInstance(const BookmarkItem* pBookmarkItem)
185 {
186         return pBookmarkItem->__pBookmarkItemImpl;
187 }
188
189
190 }} // Tizen::Web