Task TT-75 Implement "Main page loading UI" view
[profile/tv/apps/web/browser.git] / services / BookmarkService / BookmarkService.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /*
18  *
19  * Created on: Dec, 2014
20  *     Author: m.kielak
21  */
22
23 #ifndef BOOKMARKSERVICE_H
24 #define BOOKMARKSERVICE_H
25
26 #include "browser_config.h"
27 #include <vector>
28 #include <boost/signals2/signal.hpp>
29 #include <Evas.h>
30
31 #include "AbstractService.h"
32 #include "service_macros.h"
33 #include "BookmarkItem.h"
34 #include "BrowserImage.h"
35 #include "Config/Config.h"
36 #include "AbstractFavoriteService.h"
37
38 namespace tizen_browser{
39 namespace services{
40
41 class BROWSER_EXPORT BookmarkService
42         : public tizen_browser::interfaces::AbstractFavoriteService
43 {
44 public:
45     BookmarkService();
46     virtual ~BookmarkService();
47     virtual std::string getName();
48
49     /**
50      * @brief Add page to bookmarks
51      *
52      * @param address Webpage url.
53      * @param tittle Title of bookmark.
54      * @param note Bookmark note, default is empty .
55      * @param dirId Directory numeric ID, default is 0.
56      * @param thumbnail Page thumbnail, default is empty image.
57      * @param favicon Page favicon image, default is empty image.
58      *
59      * @return BookmarkItem class
60      */
61     std::shared_ptr<BookmarkItem> addToBookmarks(const std::string & address,
62                                                  const std::string & tittle,
63                                                  const std::string & note = std::string(),
64                                                  std::shared_ptr<tizen_browser::tools::BrowserImage> thumbnail=std::shared_ptr<tizen_browser::tools::BrowserImage>(),
65                                                  std::shared_ptr<tizen_browser::tools::BrowserImage> favicon = std::shared_ptr<tizen_browser::tools::BrowserImage>(),
66                                                  unsigned int dirId = 0);
67     /**
68      * @brief Count bookmarks and subfolders
69      * @return Number of bookmarks and subfolders
70      */
71     int countBookmarksAndSubFolders();
72
73     /** \todo Need to change this callback function for finding stored bookmark, check getBookmarkId function
74      * @brief Check if bookmark exists
75      *
76      * @param url url to find
77      * @return true if exists, false if not
78      */
79      bool bookmarkExists(const std::string & url);
80
81     /**
82      * @brief Get bookmarks from platform service and store it in private m_bookmarksList
83      *
84      * @return list of bookmark items, bookmark items in a folder & bookmark folders
85      */
86     std::vector<std::shared_ptr<BookmarkItem> > getBookmarks(int folder_id = 0);
87     std::vector<std::shared_ptr<BookmarkItem> > getBookmarkFolders();
88
89    /**
90      * @brief Delete all bookmarks
91      *
92      * @return true if success, false on error
93      */
94     bool deleteAllBookmarks();
95
96     /**
97      * @brief Delete bookmark by given url
98      *
99      * @param url of bookmark to delete
100      * @return true if success, false on error of not found bookmark
101      */
102     bool deleteBookmark(const std::string & url);
103
104
105     void synchronizeBookmarks();
106
107     typedef struct _folder_info {
108         int folder_id;
109         char *folder_name;
110     } folder_info;
111
112     int get_root_folder_id(void);
113     int save_folder(const char *title, int *saved_bookmark_id, int parent_id=0,int by_operator = 0);
114     bool delete_by_id(int id);
115     bool delete_by_id_notify(int id);
116     bool delete_by_uri(const char *uri);
117     int update_bookmark(int id, const char *title, const char *uri, int parent_id, int order,
118                         bool is_duplicate_check_needed = false, bool is_URI_check_needed = false);
119     int update_bookmark_notify(int id, const char *title, const char *uri, int parent_id, int order,
120                                bool is_duplicate_check_needed = false, bool is_URI_check_needed = false);
121     bool delete_all(void);
122     bool get_item_by_id(int id, BookmarkItem *item);
123     std::vector<BookmarkItem *> get_list_by_folder(const int folder_id);
124     bool get_list_users_by_folder(const int folder_id, std::vector<BookmarkItem *> &list);
125     bool get_list_by_dividing(const int folder_id, std::vector<BookmarkItem *> &list, int *last_item, int genlist_block_size);
126     bool get_list_users_by_dividing(const int folder_id, std::vector<BookmarkItem *> &list, int *last_item, int genlist_block_size);
127     int _get_folder_count(const int folder_id);
128     int _get_bookmarks_count(const int folder_id);
129     int _get_total_contents_count(const int folder_id);
130     bool get_list_operators(const int folder_id, std::vector<BookmarkItem *> &list);
131     bool get_list_by_keyword(const char *keyword, std::vector<BookmarkItem *> &list);
132     void destroy_list(std::vector<BookmarkItem *> &list);
133     int get_count(void);
134     bool get_id(const char *uri, int *bookmark_id);
135     bool get_folder_id(const char *title, int parent_id, int *folder_id);
136     bool is_in_bookmark(const char *uri);
137     bool is_in_folder(int parent_folder, const char *title);
138     bool get_folder_depth_count(int *depth_count);
139     bool set_thumbnail(int id, Evas_Object *thumbnail);
140     Evas_Object *get_thumbnail(int id, Evas_Object *parent);
141     bool set_favicon(int id, Evas_Object *favicon);
142     Evas_Object *get_favicon(int id, Evas_Object *parent);
143     bool set_webicon(int id, Evas_Object *webicon);
144     Evas_Object *get_webicon(int id, Evas_Object *parent);
145     bool set_access_count(int id, int count);
146     bool get_access_count(int id, int *count);
147     bool increase_access_count(int id);
148     bool set_last_sequence(int id);
149     const char* get_path_info(void);
150     folder_info *get_path_by_index(unsigned int index);
151     int get_path_size(void);
152     void push_back_path(folder_info *item);
153     void pop_back_path(void);
154     void clear_path_history(void);
155     void free_path_history(void);
156     void change_path_lang(void);
157     void path_into_sub_folder(int folder_id, const char *folder_name);
158     bool path_to_upper_folder(int *curr_folder);
159
160     bool get_memory_full(void) { return m_memory_full; }
161     int get_current_folder_id(void) { return m_curr_folder; }
162
163 private:
164     bool _get_depth_count_recursive(int folder_id, int cur_depth, int *depth_count);
165
166     std::vector<BookmarkItem *> m_bookmark_list;
167     std::vector<folder_info *> m_path_history;
168     std::string m_path_string;
169     bool m_memory_full;
170     bool m_bookmark_adaptor_initialize;
171     int m_curr_folder;
172     std::shared_ptr<tizen_browser::services::StorageService> m_storageManager;
173     std::vector<std::shared_ptr<BookmarkItem> > m_bookmarks;
174
175 ///    \todo Need to change getBookmarkId function for finding stored bookmark - check getBookmarkExists function
176     int getBookmarkId(const std::string & url);
177     std::shared_ptr<tizen_browser::services::StorageService> getStorageManager();
178     config::DefaultConfig config;
179 };
180
181 }
182 }
183
184 #endif // FAVORITESERVICE_H