2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * Created on: Apr, 2014
23 #include "browser_config.h"
24 #include "BookmarkService.h"
25 #include <Elementary.h>
27 #include <boost/any.hpp>
28 #include <BrowserAssert.h>
30 #include "ServiceManager.h"
31 #include "service_macros.h"
32 #include "BrowserLogger.h"
33 #include "AbstractWebEngine.h"
34 #include "AbstractMainWindow.h"
36 #include "GeneralTools.h"
38 #include <web/web_bookmark.h>
42 namespace tizen_browser{
45 EXPORT_SERVICE(BookmarkService, "org.tizen.browser.favoriteservice")
47 BookmarkService::BookmarkService()
49 int ret = bp_bookmark_adaptor_initialize();
51 BROWSER_LOGE("Error! Could not initialize bookmark service!");
56 BookmarkService::~BookmarkService()
58 bp_bookmark_adaptor_deinitialize();
62 /*private*/ std::shared_ptr<tizen_browser::services::StorageService> BookmarkService::getStorageManager() {
63 return m_storageManager;
66 void BookmarkService::synchronizeBookmarks()
71 std::shared_ptr<BookmarkItem> BookmarkService::addToBookmarks(
72 const std::string & address,
73 const std::string & tittle,
74 const std::string & note,
75 std::shared_ptr<tizen_browser::tools::BrowserImage> thumbnail,
76 std::shared_ptr<tizen_browser::tools::BrowserImage> favicon,
79 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
80 bp_bookmark_property_cond_fmt properties;
81 properties.parent = -1;
83 properties.is_operator = -1;
84 properties.is_editable = -1;
85 //conditions for querying
86 bp_bookmark_rows_cond_fmt conds;
89 conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
91 conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
92 conds.period_type = BP_BOOKMARK_DATE_ALL;
97 int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, address.c_str(), 0);
100 BROWSER_LOGE("Error! Could not get ids!");
101 return std::make_shared<BookmarkItem>();
104 bp_bookmark_info_fmt info;
108 info.access_count = -1;
111 if (!address.empty()) {
112 info.url = (char*) address.c_str();
115 info.title = (char*) tittle.c_str();
117 ret = bp_bookmark_adaptor_easy_create(&id, &info);
119 BROWSER_LOGE("Error! Could not create new bookmark!");
120 return std::make_shared<BookmarkItem>();
124 ret = bp_bookmark_adaptor_set_sequence(id, -1);
128 std::unique_ptr<tizen_browser::tools::Blob> thumb_blob = tizen_browser::tools::EflTools::getBlobPNG(thumbnail);
129 unsigned char * thumb = std::move((unsigned char*)thumb_blob->getData());
130 bp_bookmark_adaptor_set_snapshot(id, thumbnail->width, thumbnail->height, thumb, thumb_blob->getLength());
134 std::unique_ptr<tizen_browser::tools::Blob> favicon_blob = tizen_browser::tools::EflTools::getBlobPNG(favicon);
135 unsigned char * fav = std::move((unsigned char*)favicon_blob->getData());
136 bp_bookmark_adaptor_set_icon(id, favicon->width, favicon->height, fav, favicon_blob->getLength());
138 std::shared_ptr<BookmarkItem> bookmark = std::make_shared<BookmarkItem>(address, tittle, note, dirId, id);
139 bookmark->setThumbnail(thumbnail);
140 bookmark->setFavicon(favicon);
141 m_bookmarks.push_back(bookmark);
142 bookmarkAdded(bookmark);
146 bool BookmarkService::deleteBookmark(const std::string & url)
148 int id = getBookmarkId(url);
150 bp_bookmark_adaptor_delete(id);
151 bookmarkDeleted(url);
155 int BookmarkService::countBookmarksAndSubFolders()
157 return m_bookmarks.size();
160 bool BookmarkService::bookmarkExists(const std::string & url)
162 return 0 != getBookmarkId(url);
165 int BookmarkService::getBookmarkId(const std::string & url)
167 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
168 bp_bookmark_property_cond_fmt properties;
169 properties.parent = -1;
171 properties.is_operator = 0;
172 properties.is_editable = -1;
173 bp_bookmark_rows_cond_fmt conds;
176 conds.order_offset = BP_BOOKMARK_O_DATE_CREATED;
178 conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
179 conds.period_type = BP_BOOKMARK_DATE_ALL;
183 int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, url.c_str(), 0);
191 std::vector<std::shared_ptr<BookmarkItem> > BookmarkService::getBookmarks(int folder_id)
193 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
196 int ret = bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, 0, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
198 BROWSER_LOGE("Error! Could not get ids!");
199 return std::vector<std::shared_ptr<BookmarkItem>>();
204 BROWSER_LOGD("Bookmark items: %d", ids_count);
206 for(int i = 0; i<ids_count; i++)
208 bp_bookmark_info_fmt bookmark_info;
209 bp_bookmark_adaptor_get_easy_all(ids[i], &bookmark_info);
211 std::shared_ptr<BookmarkItem> bookmark = std::make_shared<BookmarkItem>(std::string(bookmark_info.url),std::string(bookmark_info.title), std::string(""),(int) bookmark_info.parent, ids[i]);
213 std::shared_ptr<tizen_browser::tools::BrowserImage> bi = std::make_shared<tizen_browser::tools::BrowserImage>();
214 bi->imageType = tizen_browser::tools::BrowserImage::ImageType::ImageTypePNG;
215 bi->width = bookmark_info.thumbnail_width;
216 bi->height = bookmark_info.thumbnail_height;
217 bi->dataSize = bookmark_info.thumbnail_length;
218 bi->imageData = (void*)malloc(bookmark_info.thumbnail_length);
219 memcpy(bi->imageData, (void*)bookmark_info.thumbnail, bookmark_info.thumbnail_length);
220 bookmark->setThumbnail(bi);
222 std::shared_ptr<tizen_browser::tools::BrowserImage> fav = std::make_shared<tizen_browser::tools::BrowserImage>();
223 unsigned char *image_bytes;
224 bp_bookmark_adaptor_get_icon(ids[i], &fav->width, &fav->height, &image_bytes, &fav->dataSize);
225 fav->imageType = tizen_browser::tools::BrowserImage::ImageType::ImageTypePNG;
227 fav->imageData = (void*)malloc(bookmark_info.favicon_length);
228 memcpy(fav->imageData, (void*)image_bytes, bookmark_info.favicon_length);
229 bookmark->setFavicon(fav);
231 m_bookmarks.push_back(bookmark);
237 std::vector<std::shared_ptr<BookmarkItem> > BookmarkService::getBookmarkFolders()
239 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
242 int ret = bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, -1, 1, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
244 BROWSER_LOGE("Error! Could not get ids!");
245 return std::vector<std::shared_ptr<BookmarkItem>>();
250 BROWSER_LOGD("Bookmark items: %d", ids_count);
252 for(int i = 0; i<ids_count; i++)
254 bp_bookmark_info_fmt bookmark_info;
255 bp_bookmark_adaptor_get_easy_all(ids[i], &bookmark_info);
257 std::shared_ptr<BookmarkItem> bookmark = std::make_shared<BookmarkItem>(std::string(bookmark_info.url ? bookmark_info.url : ""),std::string(bookmark_info.title ? bookmark_info.title : ""), std::string(""),(int) bookmark_info.parent, ids[i]);
258 std::shared_ptr<tizen_browser::tools::BrowserImage> bi = std::make_shared<tizen_browser::tools::BrowserImage>();
259 bi->imageType = tizen_browser::tools::BrowserImage::ImageType::ImageTypePNG;
260 bi->width = bookmark_info.thumbnail_width;
261 bi->height = bookmark_info.thumbnail_height;
262 bi->dataSize = bookmark_info.thumbnail_length;
263 bi->imageData = (void*)malloc(bookmark_info.thumbnail_length);
264 memcpy(bi->imageData, (void*)bookmark_info.thumbnail, bookmark_info.thumbnail_length);
265 bookmark->setThumbnail(bi);
267 std::shared_ptr<tizen_browser::tools::BrowserImage> fav = std::make_shared<tizen_browser::tools::BrowserImage>();
268 unsigned char *image_bytes;
269 bp_bookmark_adaptor_get_icon(ids[i], &fav->width, &fav->height, &image_bytes, &fav->dataSize);
270 fav->imageType = tizen_browser::tools::BrowserImage::ImageType::ImageTypePNG;
272 fav->imageData = (void*)malloc(bookmark_info.favicon_length);
273 memcpy(fav->imageData, (void*)image_bytes, bookmark_info.favicon_length);
274 bookmark->setFavicon(fav);
275 if(!bookmark_info.is_operator)
276 m_bookmarks.push_back(bookmark);
278 m_bookmarks.insert(m_bookmarks.begin(),bookmark);
285 bool BookmarkService::deleteAllBookmarks()
287 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
288 bp_bookmark_adaptor_reset();
294 int BookmarkService::get_root_folder_id(void)
296 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
298 bp_bookmark_adaptor_get_root(&root_id);
302 int BookmarkService::save_folder(const char *title, int *saved_folder_id, int parent_id, int by_operator)
304 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
306 bp_bookmark_property_cond_fmt properties;
307 properties.parent = parent_id;
309 properties.is_operator = -1;
310 properties.is_editable = -1;
311 //conditions for querying
312 bp_bookmark_rows_cond_fmt conds;
315 conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
317 conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
318 conds.period_type = BP_BOOKMARK_DATE_ALL;
322 int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_TITLE, title, 0);
332 bp_bookmark_info_fmt info;
334 info.parent = parent_id;
336 info.is_operator = by_operator;
337 info.access_count = -1;
339 if (title != nullptr && strlen(title) > 0)
341 info.title = (char *)title;
343 ret = bp_bookmark_adaptor_easy_create(&id, &info);
346 ret = bp_bookmark_adaptor_set_sequence(id, -1); // max sequence
348 *saved_folder_id = id;
349 BROWSER_LOGD("bmsvc_add_bookmark is success(id:%d)", *saved_folder_id);
350 bp_bookmark_adaptor_publish_notification();
354 BROWSER_LOGD("bmsvc_add_bookmark is failed");
358 bool BookmarkService::delete_by_id(int id)
360 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
361 BROWSER_LOGD("id[%d]", id);
362 if (bp_bookmark_adaptor_delete(id) < 0)
365 bp_bookmark_adaptor_publish_notification();
370 bool BookmarkService::delete_by_id_notify(int id)
372 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
373 BROWSER_LOGD("id[%d]", id);
376 get_item_by_id(id, &item);
377 return delete_by_id(id);
380 bool BookmarkService::delete_by_uri(const char *uri)
382 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
383 BROWSER_LOGD("uri[%s]", uri);
384 bp_bookmark_property_cond_fmt properties;
385 properties.parent = -1;
387 properties.is_operator = -1;
388 properties.is_editable = -1;
389 //conditions for querying
390 bp_bookmark_rows_cond_fmt conds;
393 conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
395 conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
396 conds.period_type = BP_BOOKMARK_DATE_ALL;
400 int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, uri, 0);
402 if (ret >= 0 && ids_count > 0)
404 delete_by_id_notify(ids[0]);
411 int BookmarkService::update_bookmark(int id, const char *title, const char *uri, int parent_id, int order,
412 bool is_duplicate_check_needed, bool is_URI_check_needed)
414 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
416 bool is_URI_exist = (uri != nullptr && strlen(uri) > 0);
417 bool is_title_exist = (title != nullptr && strlen(title) > 0);
419 if (is_duplicate_check_needed) {
420 bp_bookmark_property_cond_fmt properties;
421 properties.parent = -1;
423 properties.is_operator = -1;
424 properties.is_editable = -1;
425 //conditions for querying
426 bp_bookmark_rows_cond_fmt conds;
429 conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
431 conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
432 conds.period_type = BP_BOOKMARK_DATE_ALL;
435 //This is a bookmark item so check for any such URL already exists
436 if (is_URI_exist && is_URI_check_needed) {
437 ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, uri, 0);
442 //This is a bookmark folder so check for any such folder with same title already exists
443 else if (is_title_exist) {
444 ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_TITLE, title, 0);
451 BROWSER_LOGD("same bookmark already exist");
455 bp_bookmark_info_fmt info;
457 info.parent = parent_id;
458 info.sequence = order;
461 info.url = (char *)uri;
463 info.title = (char *)title;
465 ret = bp_bookmark_adaptor_easy_create(&id, &info);
467 BROWSER_LOGD("bp_bookmark_adaptor_easy_create is success");
468 bp_bookmark_adaptor_publish_notification();
471 int errcode = bp_bookmark_adaptor_get_errorcode();
472 BROWSER_LOGD("bp_bookmark_adaptor_easy_create is failed[%d]", errcode);
476 int BookmarkService::update_bookmark_notify(int id, const char *title, const char *uri, int parent_id, int order,
477 bool is_duplicate_check_needed, bool is_URI_check_needed)
479 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
481 int ret = update_bookmark(id, title, uri, parent_id, order, is_duplicate_check_needed, is_URI_check_needed);
485 bool BookmarkService::is_in_bookmark(const char *uri)
487 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
488 BROWSER_LOGD("uri[%s]", uri);
491 return get_id(uri, &id);
494 bool BookmarkService::is_in_folder(int parent_folder, const char *title)
496 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
499 bp_bookmark_property_cond_fmt properties;
500 properties.parent = parent_folder;
502 properties.is_operator = -1;
503 properties.is_editable = -1;
504 //conditions for querying
505 bp_bookmark_rows_cond_fmt conds;
508 conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
510 conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
511 conds.period_type = BP_BOOKMARK_DATE_ALL;
515 int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_TITLE, title, 0);
517 return ((ret >= 0) && (ids_count > 0));
520 bool BookmarkService::get_id(const char *uri, int *bookmark_id)
522 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
523 bp_bookmark_property_cond_fmt properties;
524 properties.parent = -1;
526 properties.is_operator = -1;
527 properties.is_editable = -1;
528 //conditions for querying
529 bp_bookmark_rows_cond_fmt conds;
532 conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
534 conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
535 conds.period_type = BP_BOOKMARK_DATE_ALL;
539 int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, uri, 0);
541 bool result = ((ret >= 0) && (ids_count > 0));
543 *bookmark_id = ids[0];
548 bool BookmarkService::get_folder_id(const char *title, int parent_id, int *folder_id)
550 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
552 bp_bookmark_property_cond_fmt properties;
553 properties.parent = parent_id;
555 properties.is_operator = -1;
556 properties.is_editable = -1;
557 //conditions for querying
558 bp_bookmark_rows_cond_fmt conds;
561 conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
563 conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
564 conds.period_type = BP_BOOKMARK_DATE_ALL;
568 int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_TITLE, title, 0);
570 bool result = ((ret >= 0) && (ids_count > 0));
577 bool BookmarkService::get_item_by_id(int id, BookmarkItem *item)
579 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
580 BROWSER_LOGD("ID: %d", id);
582 BROWSER_LOGE("item is nullptr");
586 if (id == get_root_folder_id()) {
587 item->setTittle("Bookmarks");
588 item->setAddress("");
590 item->set_folder_flag(1);
591 item->set_editable_flag(1);
595 bp_bookmark_info_fmt info;
596 if (bp_bookmark_adaptor_get_info(id, (BP_BOOKMARK_O_TYPE | BP_BOOKMARK_O_PARENT | BP_BOOKMARK_O_SEQUENCE |
597 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |BP_BOOKMARK_O_TITLE), &info) == 0) {
599 item->set_folder_flag(static_cast<bool>(info.type));
600 item->setDir(info.parent);
601 item->set_editable_flag(static_cast<bool>(info.editable));
603 if (info.url != nullptr && strlen(info.url) > 0)
604 item->setAddress(info.url);
606 if (info.title != nullptr && strlen(info.title) > 0)
607 item->setTittle(info.title);
609 bp_bookmark_adaptor_easy_free(&info);
612 BROWSER_LOGD("bp_bookmark_adaptor_get_easy_all is failed");
616 std::vector<BookmarkItem *> BookmarkService::get_list_by_folder(const int folder_id)
618 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
619 std::vector<BookmarkItem *> list;
620 BROWSER_LOGD("folder ID: %d", folder_id);
624 if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, -1, -1, -1, BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
625 BROWSER_LOGD("bp_bookmark_adaptor_get_sequence_child_ids_p is failed");
629 if (ids_count <= 0) {
630 BROWSER_LOGD("bookmark list is empty");
635 bp_bookmark_info_fmt info;
636 for(int i = 0; i < ids_count; i++) {
637 if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
638 BP_BOOKMARK_O_SEQUENCE |
639 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
640 BP_BOOKMARK_O_TITLE | BP_BOOKMARK_O_IS_OPERATOR), &info) == 0) {
641 BookmarkItem *item = new BookmarkItem();
644 item->set_folder_flag(static_cast<bool>(info.type));
645 item->setDir(folder_id);
646 item->set_editable_flag(static_cast<bool>(info.editable));
648 if (info.url != nullptr && strlen(info.url) > 0)
649 item->setAddress(info.url);
651 if (info.title != nullptr && strlen(info.title) > 0)
652 item->setTittle(info.title);
654 list.push_back(item);
655 bp_bookmark_adaptor_easy_free(&info);
662 bool BookmarkService::get_list_users_by_folder(const int folder_id, std::vector<BookmarkItem *> &list)
664 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
665 BROWSER_LOGD("folder ID: %d", folder_id);
668 if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, -1, 0, -1, BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
669 BROWSER_LOGD("bp_bookmark_adaptor_get_ids_p is failed");
673 if (ids_count <= 0) {
674 BROWSER_LOGD("bookmark list is empty");
679 bp_bookmark_info_fmt info;
680 for(int i = 0; i < ids_count; i++) {
681 if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
682 BP_BOOKMARK_O_SEQUENCE |
683 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
684 BP_BOOKMARK_O_TITLE |
685 BP_BOOKMARK_O_IS_OPERATOR), &info) == 0) {
686 BookmarkItem *item = new BookmarkItem();
688 item->set_folder_flag(static_cast<bool>(info.type));
689 item->setDir(folder_id);
690 item->set_editable_flag(static_cast<bool>(info.editable));
692 if (info.url != nullptr && strlen(info.url) > 0)
693 item->setAddress(info.url);
695 if (info.title != nullptr && strlen(info.title) > 0)
696 item->setTittle(info.title);
698 if (info.is_operator > 0) {
701 list.push_back(item);
703 bp_bookmark_adaptor_easy_free(&info);
707 return (list.empty() == false);
710 bool BookmarkService::get_list_by_dividing(const int folder_id, std::vector<BookmarkItem *> &list, int *list_item_count, int genlist_block_size)
712 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
713 BROWSER_LOGD("folder ID: %d", folder_id);
717 if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, genlist_block_size, *list_item_count, folder_id, -1, -1, -1,
718 BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
719 BROWSER_LOGD("bp_bookmark_adaptor_get_ids_p is failed");
723 if (ids_count <= 0) {
724 BROWSER_LOGD("bookmark list is empty");
729 bp_bookmark_info_fmt info;
730 for(int i = 0; i < ids_count; i++) {
731 if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
732 BP_BOOKMARK_O_SEQUENCE |
733 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
734 BP_BOOKMARK_O_TITLE | BP_BOOKMARK_O_IS_OPERATOR), &info) == 0) {
735 BookmarkItem *item = new BookmarkItem();
737 item->set_folder_flag(static_cast<bool>(info.type));
738 item->setDir(folder_id);
739 item->set_editable_flag(static_cast<bool>(info.editable));
741 if (info.url != nullptr && strlen(info.url) > 0)
742 item->setAddress(info.url);
744 if (info.title != nullptr && strlen(info.title) > 0)
745 item->setTittle(info.title);
747 list.push_back(item);
748 bp_bookmark_adaptor_easy_free(&info);
755 bool BookmarkService::get_list_users_by_dividing(const int folder_id, std::vector<BookmarkItem *> &list, int *list_item_count, int genlist_block_size)
757 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
758 BROWSER_LOGD("folder ID: %d", folder_id);
761 if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, genlist_block_size, *list_item_count, folder_id, -1, 0, 1,
762 BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
763 BROWSER_LOGD("bp_bookmark_adaptor_get_ids_p is failed");
767 if (ids_count <= 0) {
768 BROWSER_LOGD("bookmark list is empty");
773 bp_bookmark_info_fmt info;
774 BROWSER_LOGD("list.size() before : %d", list.size());
775 BROWSER_LOGD("ids_count: %d", ids_count);
776 for(int i = 0; i < ids_count; i++) {
777 BROWSER_LOGD("list.size(): %d", list.size());
778 BROWSER_LOGD("index : %d", i);
779 if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
780 BP_BOOKMARK_O_SEQUENCE |
781 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
782 BP_BOOKMARK_O_TITLE |
783 BP_BOOKMARK_O_IS_OPERATOR), &info) == 0) {
784 BookmarkItem *item = new BookmarkItem();
786 item->set_folder_flag(static_cast<bool>(info.type));
787 item->setDir(folder_id);
788 item->set_editable_flag(static_cast<bool>(info.editable));
790 if (info.url != nullptr && strlen(info.url) > 0)
791 item->setAddress(info.url);
793 if (info.title != nullptr && strlen(info.title) > 0)
794 item->setTittle(info.title);
796 if (info.is_operator > 0) {
797 BROWSER_LOGD("this is operator bookmark");
800 BROWSER_LOGD("item is pushed");
801 list.push_back(item);
803 bp_bookmark_adaptor_easy_free(&info);
806 BROWSER_LOGD("list.size() after: %d", list.size());
808 return (list.empty() == false);
811 int BookmarkService::_get_folder_count(const int folder_id)
813 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
814 BROWSER_LOGD("folder ID: %d", folder_id);
818 bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, 1, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
824 int BookmarkService::_get_bookmarks_count(const int folder_id)
826 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
827 BROWSER_LOGD("folder ID: %d", folder_id);
831 bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, 0, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
837 int BookmarkService::_get_total_contents_count(const int folder_id)
839 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
840 BROWSER_LOGD("folder ID: %d", folder_id);
844 bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, 0, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
849 bool BookmarkService::get_list_operators(const int folder_id, std::vector<BookmarkItem *> &list)
851 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
852 BROWSER_LOGD("folder ID: %d", folder_id);
856 if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, -1, 1, -1, BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
857 BROWSER_LOGD("bp_bookmark_adaptor_get_ids_p is failed");
861 if (ids_count <= 0) {
862 BROWSER_LOGD("bookmark list is empty");
867 bp_bookmark_info_fmt info;
868 for(int i = 0; i < ids_count; i++) {
869 if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
870 BP_BOOKMARK_O_SEQUENCE |
871 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
872 BP_BOOKMARK_O_TITLE), &info) == 0) {
873 BookmarkItem *item = new BookmarkItem();
875 item->set_folder_flag(static_cast<bool>(info.type));
876 item->setDir(folder_id);
877 item->set_editable_flag(static_cast<bool>(info.editable));
879 if (info.url != nullptr && strlen(info.url) > 0)
880 item->setAddress(info.url);
882 if (info.title != nullptr && strlen(info.title) > 0)
883 item->setTittle(info.title);
885 list.push_back(item);
886 bp_bookmark_adaptor_easy_free(&info);
890 return (list.empty() == false);
893 bool BookmarkService::get_list_by_keyword(const char *keyword, std::vector<BookmarkItem *> &list)
895 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
898 if (!keyword || (strlen(keyword) == 0)) {
899 BROWSER_LOGD("keyword is nullptr");
903 std::string buf_str(keyword);
904 buf_str = "%" + buf_str + "%";
906 bp_bookmark_property_cond_fmt properties;
907 properties.parent = -1;
909 properties.is_operator = -1;
910 properties.is_editable = -1;
911 //conditions for querying
912 bp_bookmark_rows_cond_fmt conds;
915 conds.order_offset = BP_BOOKMARK_O_TITLE;
917 conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
918 conds.period_type = BP_BOOKMARK_DATE_ALL;
922 if (bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds,
923 (BP_BOOKMARK_O_TITLE | BP_BOOKMARK_O_URL), buf_str.c_str(), 1) < 0) {
924 BROWSER_LOGE("bp_bookmark_adaptor_get_cond_ids_p is failed");
928 if (ids_count <= 0) {
929 BROWSER_LOGD("bookmark list is empty");
934 bp_bookmark_info_fmt info;
935 for(int i = 0; i < ids_count; i++) {
936 if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
937 BP_BOOKMARK_O_PARENT | BP_BOOKMARK_O_SEQUENCE |
938 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
939 BP_BOOKMARK_O_TITLE), &info) == 0) {
940 BookmarkItem *item = new BookmarkItem();
942 item->set_folder_flag(static_cast<bool>(info.type));
943 item->setDir(info.parent);
944 item->set_editable_flag(static_cast<bool>(info.editable));
946 if (info.url != nullptr && strlen(info.url) > 0)
947 item->setAddress(info.url);
949 if (info.title != nullptr && strlen(info.title) > 0)
950 item->setTittle(info.title);
952 list.push_back(item);
953 bp_bookmark_adaptor_easy_free(&info);
960 void BookmarkService::destroy_list(std::vector<BookmarkItem *> &list)
962 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
965 for(unsigned int i = 0 ; i < list.size() ; i++) {
971 bool BookmarkService::get_folder_depth_count(int *depth_count)
973 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
974 BROWSER_LOGD("depth_count: %d", *depth_count);
975 return _get_depth_count_recursive(get_root_folder_id(), 0, depth_count);
978 bool BookmarkService::_get_depth_count_recursive(int folder_id, int cur_depth, int *depth_count)
980 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
981 BROWSER_LOGD("current_depth: %d, depth_count:%d", cur_depth, *depth_count);
983 std::vector<BookmarkItem *> bookmark_list = get_list_by_folder(folder_id);
984 if (!bookmark_list.empty()) {
985 BROWSER_LOGE("get_list_by_folder is failed(folder id:%d)",folder_id);
989 for(unsigned int j = 0 ; j < bookmark_list.size() ; j++) {
990 if (bookmark_list[j]->is_folder()) {
991 /* Folder item is found. get sub list */
992 if ((cur_depth+1) > *depth_count)
993 *depth_count = cur_depth+1;
995 _get_depth_count_recursive(bookmark_list[j]->getId(), cur_depth+1, depth_count);
998 destroy_list(bookmark_list);
1002 bool BookmarkService::set_thumbnail(int id, Evas_Object *thumbnail)
1004 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1005 BROWSER_LOGD("id : %d", id);
1012 //platform_Service ps.
1013 //ps.evas_image_size_get(thumbnail, &w, &h, &stride);
1015 BROWSER_LOGD("thumbnail w=[%d], h=[%d], stride=[%d], len=[%d]", w, h, stride, len);
1020 void *thumbnail_data = evas_object_image_data_get(thumbnail, true);
1021 int ret = bp_bookmark_adaptor_set_snapshot(id, w, h, (const unsigned char *)thumbnail_data, len);
1023 BROWSER_LOGE("bp_bookmark_adaptor_set_thumbnail is failed");
1029 Evas_Object *BookmarkService::get_thumbnail(int id, Evas_Object *parent)
1031 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1032 BROWSER_LOGD("id : %d", id);
1033 void *thumbnail_data = nullptr;
1037 Evas_Object *icon = nullptr;
1039 int ret = bp_bookmark_adaptor_get_snapshot(id, &w, &h, (unsigned char **)&thumbnail_data, &len);
1040 BROWSER_LOGE("len: %d, w:%d, h:%d", len, w, h);
1042 /* gengrid event area has scaled with original image if it is evas image.
1043 therefore use elm_image*/
1044 icon = elm_image_add(parent);
1045 Evas_Object *icon_object = elm_image_object_get(icon);
1046 evas_object_image_colorspace_set(icon_object, EVAS_COLORSPACE_ARGB8888);
1047 evas_object_image_size_set(icon_object, w, h);
1048 evas_object_image_fill_set(icon_object, 0, 0, w, h);
1049 evas_object_image_filled_set(icon_object, true);
1050 evas_object_image_alpha_set(icon_object,true);
1052 void *target_image_data = evas_object_image_data_get(icon_object, true);
1053 memcpy(target_image_data, thumbnail_data, len);
1054 evas_object_image_data_set(icon_object, target_image_data);
1060 bool BookmarkService::set_favicon(int id, Evas_Object *favicon)
1062 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1063 BROWSER_LOGD("id : %d", id);
1070 //platform_Service ps.
1071 //ps.evas_image_size_get(favicon, &w, &h, &stride);
1073 BROWSER_LOGD("favicon w=[%d], h=[%d], stride=[%d], len=[%d]", w, h, stride, len);
1078 void *favicon_data = evas_object_image_data_get(favicon, true);
1079 int ret = bp_bookmark_adaptor_set_icon(id, w, h, (const unsigned char *)favicon_data, len);
1081 BROWSER_LOGE("bp_bookmark_adaptor_set_favicon is failed");
1087 Evas_Object *BookmarkService::get_favicon(int id, Evas_Object *parent)
1089 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1090 BROWSER_LOGD("id : %d", id);
1091 void *favicon_data = nullptr;
1097 e = evas_object_evas_get(parent);
1099 BROWSER_LOGE("canvas is nullptr");
1102 int ret = bp_bookmark_adaptor_get_icon(id, &w, &h, (unsigned char **)&favicon_data, &len);
1104 BROWSER_LOGE("bp_bookmark_adaptor_set_favicon is failed");
1108 Evas_Object *icon = nullptr;
1109 BROWSER_LOGE("len: %d, w:%d, h:%d", len, w, h);
1111 icon = evas_object_image_filled_add(e);
1112 if (w == 0 || h == 0) {
1113 // Android bookmark.
1114 evas_object_image_memfile_set(icon, favicon_data, len, nullptr, nullptr);
1117 evas_object_image_colorspace_set(icon, EVAS_COLORSPACE_ARGB8888);
1118 evas_object_image_size_set(icon, w, h);
1119 evas_object_image_fill_set(icon, 0, 0, w, h);
1120 evas_object_image_filled_set(icon, true);
1121 evas_object_image_alpha_set(icon,true);
1123 void *target_image_data = evas_object_image_data_get(icon, true);
1124 memcpy(target_image_data, favicon_data, len);
1125 evas_object_image_data_set(icon, target_image_data);
1131 bool BookmarkService::set_webicon(int id, Evas_Object *webicon)
1133 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1134 BROWSER_LOGD("id : %d", id);
1141 //platform_Service ps;
1142 //ps.evas_image_size_get(webicon, &w, &h, &stride);
1144 BROWSER_LOGD("webicon w=[%d], h=[%d], stride=[%d], len=[%d]", w, h, stride, len);
1149 void *webicon_data = evas_object_image_data_get(webicon, true);
1150 int ret = bp_bookmark_adaptor_set_webicon(id, w, h, (const unsigned char *)webicon_data, len);
1152 BROWSER_LOGE("set webicon is failed");
1156 Evas_Object *BookmarkService::get_webicon(int id, Evas_Object *parent)
1158 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1159 BROWSER_LOGD("id : %d", id);
1160 void *webicon_data = nullptr;
1165 int ret = bp_bookmark_adaptor_get_webicon(id, &w, &h, (unsigned char **)&webicon_data, &len);
1167 BROWSER_LOGE("bp_bookmark_adaptor_set_webicon is failed");
1171 Evas_Object *icon = nullptr;
1172 BROWSER_LOGE("len: %d, w:%d, h:%d", len, w, h);
1174 Evas *e = evas_object_evas_get(parent);
1175 icon = evas_object_image_filled_add(e);
1177 evas_object_image_colorspace_set(icon, EVAS_COLORSPACE_ARGB8888);
1178 evas_object_image_size_set(icon, w, h);
1179 evas_object_image_fill_set(icon, 0, 0, w, h);
1180 evas_object_image_filled_set(icon, true);
1181 evas_object_image_alpha_set(icon,true);
1183 void *target_image_data = evas_object_image_data_get(icon, true);
1184 memcpy(target_image_data, webicon_data, len);
1185 evas_object_image_data_set(icon, target_image_data);
1191 bool BookmarkService::set_access_count(int id, int count)
1193 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1195 return !bp_bookmark_adaptor_set_access_count(id, count);
1198 bool BookmarkService::get_access_count(int id, int *count)
1200 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1202 return !bp_bookmark_adaptor_get_access_count(id, count);
1205 bool BookmarkService::increase_access_count(int id)
1207 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1210 if(get_access_count(id, &count) == false) {
1211 BROWSER_LOGD("get_access_count is failed");
1215 if(set_access_count(id, count + 1) == false) {
1216 BROWSER_LOGD("set_access_count is failed");
1223 bool BookmarkService::set_last_sequence(int id)
1225 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1227 return (bp_bookmark_adaptor_set_sequence(id, -1) == -1);
1230 const char* BookmarkService::get_path_info(void)
1232 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1233 BROWSER_LOGD("%s", m_path_string.c_str());
1234 return m_path_string.c_str();
1237 BookmarkService::folder_info *BookmarkService::get_path_by_index(unsigned int index)
1239 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1240 BROWSER_LOGD("%s", m_path_history[index]->folder_name);
1241 return m_path_history[index];
1244 int BookmarkService::get_path_size(void)
1246 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1247 BROWSER_LOGD("%d", m_path_history.size());
1248 return m_path_history.size();
1251 void BookmarkService::push_back_path(folder_info *item)
1253 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1254 BROWSER_LOGD("path size before push: %d", m_path_history.size());
1255 m_path_history.push_back(item);
1258 void BookmarkService::pop_back_path(void)
1260 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1261 BROWSER_LOGD("path size before pop: %d", m_path_history.size());
1262 m_path_history.pop_back();
1265 void BookmarkService::clear_path_history(void)
1267 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1269 free_path_history();
1270 m_path_history.clear();
1273 void BookmarkService::free_path_history(void)
1275 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1277 for(unsigned int i = 0 ; i < m_path_history.size() ; i++) {
1278 if (m_path_history[i]) {
1279 if (m_path_history[i]->folder_name)
1280 free(m_path_history[i]->folder_name);
1282 free(m_path_history[i]);
1287 void BookmarkService::change_path_lang(void)
1289 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1291 m_path_string.clear();
1293 char *old_str = m_path_history[0]->folder_name;
1294 m_path_history[0]->folder_name = strdup("Bookmarks");
1297 for(int i = 0 ; i < get_path_size(); i++) {
1298 if (get_path_by_index(i)) {
1299 if (m_path_string.empty()) {
1300 m_path_string = m_path_history[0]->folder_name;
1302 m_path_string += "/";
1303 m_path_string += get_path_by_index(i)->folder_name;
1307 BROWSER_LOGD("str: %s", m_path_string.c_str());
1310 void BookmarkService::path_into_sub_folder(int folder_id, const char *folder_name)
1312 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1315 folder_info *item = (folder_info *)calloc(1, sizeof(folder_info));
1317 item->folder_id = folder_id;
1318 if (folder_id == get_root_folder_id()) {
1319 item->folder_name = strdup("Bookmarks");
1321 item->folder_name = strdup(folder_name);
1322 push_back_path(item);
1324 m_path_string.clear();
1325 for(int i = 0 ; i < get_path_size() ; i++) {
1326 if (get_path_by_index(i)) {
1327 if (m_path_string.empty()) {
1328 m_path_string = get_path_by_index(i)->folder_name;
1330 m_path_string += "/";
1331 m_path_string += get_path_by_index(i)->folder_name;
1335 char *path_string = (elm_entry_utf8_to_markup(m_path_string.c_str()));
1336 m_path_string = path_string;
1338 BROWSER_LOGD("m_path_string: %s", m_path_string.c_str());
1340 m_curr_folder = folder_id;
1343 bool BookmarkService::path_to_upper_folder(int *curr_folder)
1345 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1348 int current_depth = get_path_size();
1349 BROWSER_LOGD("current_depth: %d", current_depth);
1351 if (current_depth <= 0) {
1352 BROWSER_LOGE("[ERROR] top folder is not valid");
1356 int curr_depth = current_depth - 1;
1357 if (curr_depth > 0) {
1358 *curr_folder = get_path_by_index(curr_depth - 1)->folder_id;
1359 if (get_path_by_index(curr_depth) && get_path_by_index(curr_depth)->folder_name) {
1360 free(get_path_by_index(curr_depth)->folder_name);
1361 free(get_path_by_index(curr_depth));
1365 /* Current folder is root folder */
1366 if (*curr_folder != get_root_folder_id()) {
1367 BROWSER_LOGE("[ERROR] top folder is not root folder");
1370 if (get_path_by_index(curr_depth) && get_path_by_index(curr_depth)->folder_name) {
1371 free(get_path_by_index(curr_depth)->folder_name);
1372 free(get_path_by_index(curr_depth));
1375 m_path_string.clear();
1379 m_path_string.clear();
1380 for(int i = 0 ; i < get_path_size() ; i++) {
1381 if (get_path_by_index(i)) {
1382 if (m_path_string.empty()) {
1383 m_path_string = get_path_by_index(i)->folder_name;
1385 m_path_string += "/";
1386 m_path_string += get_path_by_index(i)->folder_name;
1390 BROWSER_LOGD("m_path_string: %s", m_path_string.c_str());
1392 m_curr_folder = *curr_folder;
1396 } /* end of namespace services*/
1397 } /* end of namespace tizen_browser */