diff options
author | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-16 01:11:50 +0900 |
---|---|---|
committer | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-16 01:11:50 +0900 |
commit | 598161ada3a89d1b4c8dbd3ae10cf056f12e31f8 (patch) | |
tree | 7ac422c1a473dc2334ed46c7ed4b1c5577e360b8 | |
parent | c7e968ac93a332d19d17ae8202b38298728e0c8f (diff) | |
download | favorites-598161ada3a89d1b4c8dbd3ae10cf056f12e31f8.tar.gz favorites-598161ada3a89d1b4c8dbd3ae10cf056f12e31f8.tar.bz2 favorites-598161ada3a89d1b4c8dbd3ae10cf056f12e31f8.zip |
merge with master
-rwxr-xr-x | CMakeLists.txt | 6 | ||||
-rw-r--r-- | include/favorites.h | 63 | ||||
-rw-r--r-- | include/favorites_private.h | 11 | ||||
-rwxr-xr-x | packaging/capi-web-favorites.spec | 63 | ||||
-rw-r--r-- | src/favorites_bookmark.c | 603 | ||||
-rw-r--r-- | src/favorites_history.c | 2 |
6 files changed, 617 insertions, 131 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c93fe5..bc7806d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,14 +38,14 @@ ADD_DEFINITIONS( -DLOG_TAG=\"favorites\" ) -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") aux_source_directory(src SOURCES) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) -INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR}) INSTALL( DIRECTORY ${INC_DIR}/ DESTINATION include/web FILES_MATCHING @@ -63,7 +63,7 @@ CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc @ONLY ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) IF(UNIX) diff --git a/include/favorites.h b/include/favorites.h index b16122b..0a07bc3 100644 --- a/include/favorites.h +++ b/include/favorites.h @@ -37,7 +37,9 @@ typedef enum favorites_error{ FAVORITES_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
FAVORITES_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */
FAVORITES_ERROR_DB_FAILED = TIZEN_ERROR_WEB_CLASS | 0x62, /**< Database operation failure */
- FAVORITES_ERROR_ITEM_ALREADY_EXIST = TIZEN_ERROR_WEB_CLASS | 0x63 /**< Requested data already exists */
+ FAVORITES_ERROR_ITEM_ALREADY_EXIST = TIZEN_ERROR_WEB_CLASS | 0x63, /**< Requested data already exists */
+ FAVORITES_ERROR_NO_SUCH_FILE = TIZEN_ERROR_NO_SUCH_FILE, /**< No such file or directory */
+ FAVORITES_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN /**< Unknown error */
} favorites_error_e;
/**
@@ -76,14 +78,45 @@ typedef struct { typedef bool (*favorites_bookmark_foreach_cb)(favorites_bookmark_entry_s *item, void *user_data);
/**
- * @brief Adds an entry to bookmark list.
+ * @brief Gets the id of the root folder.
*
- * @remarks If a folder named @a "foldername" doesn't exist, it will be created.
- * @remarks The folder named "Bookmarks" is reserved for the root folder.
- * @param[in] url Book URL
+ * @param[out] root_folder_id The id of the root folder.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ */
+int favorites_bookmark_get_root_folder_id(int *root_id);
+
+/**
+ * @brief Adds a bookmark to bookmark database.
+ *
+ * @remarks If a folder named @a "foldername" doesn't exist, it will be created in the root folder.
+ * @param[in] url Bookmark URL
* @param[in] title The title of the bookmark
- * @param[in] folder_name The name of parent folder
- * @param[out] bookmark_id: The unique id of the added bookmark
+ * @param[in] folder_name The name of parent folder in the root folder
+ * @param[out] saved_id The unique id of the added bookmark
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_ITEM_ALREADY_EXIST Requested data already exists
+ *
+ */
+int favorites_bookmark_add_bookmark(const char *url, const char *title, const char *folder_name, int *saved_id);
+
+/**
+ * @brief Adds a bookmark or folder item to bookmark database.
+ *
+ * @remarks If the parent_id is not valid folder id, this API will return error.
+ * @param[in] title The title of the bookmark or folder
+ * @param[in] url The bookmark URL. if the type is folder, this param will be ignored.
+ * @param[in] parent_id The unique id of folder which added item belong to.
+ * @param[in] type The type of item ( 0 : bookmark, 1 : folder )
+ * @param[out] saved_id The unique id of the added item
*
* @return 0 on success, otherwise a negative error value.
* @retval #FAVORITES_ERROR_NONE Successful
@@ -92,7 +125,7 @@ typedef bool (*favorites_bookmark_foreach_cb)(favorites_bookmark_entry_s *item, * @retval #FAVORITES_ERROR_ITEM_ALREADY_EXIST Requested data already exists
*
*/
-int favorites_bookmark_add_bookmark(const char *url, const char *title, const char *folder_name, int *bookmark_id);
+int favorites_bookmark_add(const char *title, const char *url, int parent_id, int type, int *saved_id);
/**
* @brief Deletes the bookmark item of given bookmark id.
@@ -178,6 +211,20 @@ int favorites_bookmark_export_list(const char *file_path); int favorites_bookmark_get_favicon(int bookmark_id, Evas *evas, Evas_Object **icon);
/**
+ * @brief Sets the bookmark's favicon
+ *
+ * @param[in] bookmark_id The unique ID of bookmark
+ * @param[in] icon The favicon object to save
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_bookmark_set_favicon(int bookmark_id, Evas_Object *icon);
+
+/**
* @brief The structure of history entry in search results.
*
* @details This structure is passed to callback function in all history related
diff --git a/include/favorites_private.h b/include/favorites_private.h index 0f624de..b00f6ef 100644 --- a/include/favorites_private.h +++ b/include/favorites_private.h @@ -110,15 +110,20 @@ void _favorites_free_bookmark_list(bookmark_list_h m_list); int _favorites_free_bookmark_entry(favorites_bookmark_entry_s *entry);
int _favorites_get_bookmark_lastindex(int locationId);
int _favorites_bookmark_get_folderID(const char *foldername);
-int _favorites_bookmark_is_folder_exist(const char *foldername);
int _favorites_bookmark_create_folder(const char *foldername);
-int _favorites_bookmark_is_bookmark_exist(const char *url, const char *title, const int folderId);
int _favorites_get_bookmark_count_at_folder(int folderId);
int _favorites_bookmark_get_folder_count(void);
bookmark_list_h _favorites_get_bookmark_list_at_folder(int folderId);
bookmark_list_h _favorites_bookmark_get_folder_list(void);
int _favorites_get_unixtime_from_datetime(char *datetime);
-int _favorites_bookmark_get_bookmark_id(const char *url, const char *title, const int folder_id);
+int _add_bookmark(const char *title, const char *address, int parent_id, int *saved_bookmark_id);
+int _add_folder(const char *title, int parent_id, int *saved_folder_id);
+int _get_root_folder_id(void);
+int _get_exists_id(int id, int type);
+int _get_exists_bookmark(const char *address);
+int _get_exists_folder(const char *title, int parent_id);
+int _get_bookmark_id(const char *address);
+int _get_folder_id(const char *title, const int parent);
/* history internal API */
void _favorites_history_db_close(void);
diff --git a/packaging/capi-web-favorites.spec b/packaging/capi-web-favorites.spec index c495e2e..7c1d112 100755 --- a/packaging/capi-web-favorites.spec +++ b/packaging/capi-web-favorites.spec @@ -1,6 +1,6 @@ Name: capi-web-favorites Summary: Internet bookmark and history API -Version: 0.0.7 +Version: 0.0.11 Release: 1 Group: TO_BE/FILLED_IN License: Apache License, Version 2.0 @@ -30,13 +30,10 @@ Requires: %{name} = %{version}-%{release} %build -cmake . -DCMAKE_INSTALL_PREFIX=/usr - - +%cmake . make %{?jobs:-j%jobs} %install -rm -rf %{buildroot} %make_install %post @@ -46,19 +43,65 @@ mkdir -p /opt/usr/dbspace/ if [ ! -f /opt/usr/dbspace/.browser-history.db ]; then sqlite3 /opt/usr/dbspace/.browser-history.db 'PRAGMA journal_mode=PERSIST; - CREATE TABLE history(id INTEGER PRIMARY KEY AUTOINCREMENT, address, title, counter INTEGER, visitdate DATETIME, favicon BLOB, favicon_length INTEGER, favicon_w INTEGER, favicon_h INTEGER);' + CREATE TABLE history( + id INTEGER PRIMARY KEY AUTOINCREMENT + , address + , title + , counter INTEGER + , visitdate DATETIME + , favicon BLOB + , favicon_length INTEGER + , favicon_w INTEGER + , favicon_h INTEGER + , snapshot BLOB + , snapshot_stride INTEGER + , snapshot_w INTEGER + , snapshot_h INTEGER);' fi ### Bookmark ### if [ ! -f /opt/usr/dbspace/.internet_bookmark.db ]; then sqlite3 /opt/usr/dbspace/.internet_bookmark.db 'PRAGMA journal_mode=PERSIST; - CREATE TABLE bookmarks(id INTEGER PRIMARY KEY AUTOINCREMENT, type INTEGER, parent INTEGER, address, title, creationdate, sequence INTEGER, updatedate, visitdate, editable INTEGER, accesscount INTEGER, favicon BLOB, favicon_length INTEGER, favicon_w INTEGER, favicon_h INTEGER); + CREATE TABLE bookmarks( + id INTEGER PRIMARY KEY AUTOINCREMENT + ,type INTEGER + ,parent INTEGER + ,address + ,title + ,creationdate + ,sequence INTEGER + ,updatedate + ,visitdate + ,editable INTEGER + ,accesscount INTEGER + ,favicon BLOB + ,favicon_length INTEGER + ,favicon_w INTEGER + ,favicon_h INTEGER + ,created_date + ,account_name + ,account_type + ,thumbnail BLOB + ,thumbnail_length INTEGER + ,thumbnail_w INTEGER + ,thumbnail_h INTEGER + ,version INTEGER + ,sync + ,tag1 + ,tag2 + ,tag3 + ,tag4 + ); create index idx_bookmarks_on_parent_type on bookmarks(parent, type); - insert into bookmarks (type, parent, title, creationdate, editable, sequence, accesscount) values(1, 0, "Bookmarks", DATETIME("now"), 0, 1, 0);' -fi + INSERT INTO bookmarks (type, parent, title, creationdate, editable, sequence, accesscount, created_date) + VALUES(1, 0, "Bookmarks", DATETIME("now"), 0, 1, 0, strftime("%s","now")*1000); + CREATE TABLE tags( + tag + );' +fi # Change db file owner & permission chown :5000 /opt/usr/dbspace/.browser-history.db chown :5000 /opt/usr/dbspace/.browser-history.db-journal @@ -93,5 +136,3 @@ vconftool set -t string db/browser/user_agent "Mozilla/5.0 (Linux; U; Tizen 2.0; %files devel %{_includedir}/web/*.h %{_libdir}/pkgconfig/*.pc - - diff --git a/src/favorites_bookmark.c b/src/favorites_bookmark.c index 6ab46dd..b80cee4 100644 --- a/src/favorites_bookmark.c +++ b/src/favorites_bookmark.c @@ -20,7 +20,7 @@ #include <favorites.h>
#include <favorites_private.h>
-__thread sqlite3 *gl_internet_bookmark_db = 0;
+sqlite3 *gl_internet_bookmark_db = 0;
/* Private Functions */
void _favorites_close_bookmark_db(void)
@@ -143,7 +143,7 @@ int _favorites_bookmark_get_folderID(const char *foldername) memset(&query, 0x00, sizeof(char)*1024);
/* If there is no identical folder name, create new folder */
- if (_favorites_bookmark_is_folder_exist(foldername)==0){
+ if (_get_exists_folder(foldername, _get_root_folder_id())==0){
if(_favorites_bookmark_create_folder(foldername)!=1){
FAVORITES_LOGE("folder creating is failed.");
return -1;
@@ -178,49 +178,6 @@ int _favorites_bookmark_get_folderID(const char *foldername) return 1;
}
-int _favorites_bookmark_is_folder_exist(const char *foldername)
-{
- FAVORITES_LOGE("\n");
- int nError;
- sqlite3_stmt *stmt;
- char query[1024];
-
- memset(&query, 0x00, sizeof(char)*1024);
-
- if (!foldername || (strlen(foldername) <= 0)) {
- FAVORITES_LOGE("foldername is empty\n");
- return -1;
- }
- FAVORITES_LOGE("foldername: %s", foldername);
-
- if (_favorites_open_bookmark_db() < 0) {
- FAVORITES_LOGE("db_util_open is failed\n");
- return -1;
- }
-
- sprintf(query, "select id from bookmarks where type=1 AND title='%s'"
- , foldername);
-
- /* check foldername in the bookmark table */
- nError = sqlite3_prepare_v2(gl_internet_bookmark_db,query
- ,-1, &stmt, NULL);
-
- if (nError != SQLITE_OK) {
- FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
- _favorites_finalize_bookmark_db(stmt);
- return -1;
- }
-
- nError = sqlite3_step(stmt);
- if (nError == SQLITE_ROW) {
- /* The given foldername is exist on the bookmark table */
- _favorites_finalize_bookmark_db(stmt);
- return 1;
- }
- _favorites_close_bookmark_db();
- return 0;
-}
-
int _favorites_bookmark_create_folder(const char *foldername)
{
FAVORITES_LOGE("\n");
@@ -273,49 +230,6 @@ int _favorites_bookmark_create_folder(const char *foldername) return 0;
}
-int _favorites_bookmark_is_bookmark_exist
- (const char *url, const char *title, const int folderId)
-{
- FAVORITES_LOGE("folderId: %d", folderId);
- int nError;
- sqlite3_stmt *stmt;
- char query[1024];
-
- memset(&query, 0x00, sizeof(char)*1024);
-
- if (_favorites_open_bookmark_db() < 0) {
- FAVORITES_LOGE("db_util_open is failed\n");
- return -1;
- }
-
- sprintf(query, "select id from bookmarks where \
- type=0 AND address='%s' AND title='%s' AND parent=%d"
- , url, title, folderId);
- FAVORITES_LOGE("query: %s", query);
-
- /* check bookmark in the bookmark table */
- nError = sqlite3_prepare_v2(gl_internet_bookmark_db,query
- ,-1, &stmt, NULL);
-
- if (nError != SQLITE_OK) {
- FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
- _favorites_finalize_bookmark_db(stmt);
- return -1;
- }
-
- nError = sqlite3_step(stmt);
- if (nError == SQLITE_ROW) {
- /* There is same bookmark exist. */
- _favorites_finalize_bookmark_db(stmt);
- return 1;
- }
-
- FAVORITES_LOGE("there is no identical bookmark\n");
- _favorites_close_bookmark_db();
- /* there is no identical bookmark*/
- return 0;
-}
-
int _favorites_get_bookmark_count_at_folder(int folderId)
{
int nError;
@@ -671,39 +585,399 @@ int _favorites_get_unixtime_from_datetime(char *datetime) return 1;
}
-/* search last of sequence(order's index) */
-int _favorites_bookmark_get_bookmark_id(const char *url, const char *title, const int folder_id)
+int _add_bookmark(const char *title, const char *address, int parent_id, int *saved_bookmark_id)
{
+ FAVORITES_LOGD("");
+ if (title == NULL || strlen(title) <= 0) {
+ FAVORITES_LOGD("Invalid param: Title is empty");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+ if (address == NULL || strlen(address) <= 0) {
+ FAVORITES_LOGD("Invalid param: Address is empty");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+ if (memcmp(address, "file://", 7) == 0) {
+ FAVORITES_LOGD("Not Allow file://");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+
+ if (parent_id > 0) {
+ /* check whether folder is exist or not. */
+ if (_get_exists_id(parent_id, 1) <= 0) {
+ FAVORITES_LOGE("Not found parent folder (%d)\n", parent_id);
+ return FAVORITES_ERROR_NO_SUCH_FILE;
+ }
+ } else {
+ parent_id = _get_root_folder_id();
+ }
+ FAVORITES_LOGD("[%s][%s][%d]", title, address, parent_id);
+
+ int uid = _get_exists_bookmark(address);
+ /* ignore this call.. already exist. */
+ if (uid > 0) {
+ FAVORITES_LOGE("Bookmark is already exist. cancel the add operation.");
+ return FAVORITES_ERROR_ITEM_ALREADY_EXIST;
+ }
+
+ int lastIndex = _favorites_get_bookmark_lastindex(parent_id);
+ if (lastIndex < 0) {
+ FAVORITES_LOGE("Database::getLastIndex() is failed.\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
int nError;
sqlite3_stmt *stmt;
- char query[1024];
- /* Get the id of bookmark */
- sprintf(query, "select id from bookmarks where \
- type=0 AND address='%s' AND title='%s' AND parent=%d"
- , url, title, folder_id);
- FAVORITES_LOGE("query: %s", query);
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "INSERT INTO bookmarks (type, parent, address, title, creationdate,\
+ updatedate, editable, sequence)\
+ VALUES (0, ?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?)",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ /*parent */
+ if (sqlite3_bind_int(stmt, 1, parent_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /*address */
+ if (sqlite3_bind_text(stmt, 2, address, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /*title */
+ if (sqlite3_bind_text(stmt, 3, title, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /* order */
+ if (lastIndex >= 0) {
+ if (sqlite3_bind_int(stmt, 4, (lastIndex + 1)) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ }
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_OK || nError == SQLITE_DONE) {
+ _favorites_close_bookmark_db();
+ int id = _get_bookmark_id(address);
+ if (id > 0)
+ *saved_bookmark_id = id;
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
+int _add_folder(const char *title, int parent_id, int *saved_folder_id)
+{
+ FAVORITES_LOGD("");
+ if (title == NULL || strlen(title) <= 0) {
+ FAVORITES_LOGD("Invalid param: Title is empty");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+ if (parent_id > 0) {
+ /* check whether folder is exist or not. */
+ if (_get_exists_id(parent_id, 1) <= 0) {
+ FAVORITES_LOGE("Not found parent folder (%d)\n", parent_id);
+ return FAVORITES_ERROR_NO_SUCH_FILE;
+ }
+ } else {
+ parent_id = _get_root_folder_id();
+ }
+ FAVORITES_LOGD("[%s][%d]", title, parent_id);
+
+ int uid = _get_exists_folder(title, parent_id);
+ /* ignore this call.. already exist. */
+ if (uid > 0) {
+ FAVORITES_LOGE("Bookmark is already exist. cancel the add operation.");
+ return FAVORITES_ERROR_ITEM_ALREADY_EXIST;
+ }
+
+ int lastIndex = _favorites_get_bookmark_lastindex(parent_id);
+ if (lastIndex < 0) {
+ FAVORITES_LOGE("Database::getLastIndex() is failed.\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ int nError;
+ sqlite3_stmt *stmt;
+
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "INSERT INTO bookmarks (type, parent, title, creationdate,\
+ updatedate, sequence, editable)\
+ VALUES (1, ?, ?, DATETIME('now'), DATETIME('now'), ?, 1)",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ /*parent */
+ if (sqlite3_bind_int(stmt, 1, parent_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /*title */
+ if (sqlite3_bind_text(stmt, 2, title, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /* order */
+ if (lastIndex >= 0) {
+ if (sqlite3_bind_int(stmt, 3, (lastIndex + 1)) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_OK || nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ int id = _get_folder_id(title, parent_id);
+ if (id > 0)
+ *saved_folder_id = id;
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
+
+int _get_root_folder_id(void)
+{
+ return 1;
+}
+
+int _get_exists_id(int id, int type)
+{
+ FAVORITES_LOGE("\n");
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (id < 0)
+ return -1;
if (_favorites_open_bookmark_db() < 0) {
FAVORITES_LOGE("db_util_open is failed\n");
return -1;
}
- nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
- query, -1, &stmt, NULL);
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select * from bookmarks where id=? and type=?",
+ -1, &stmt, NULL);
if (nError != SQLITE_OK) {
- FAVORITES_LOGE("sqlite3_prepare_v2 is failed");
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
_favorites_finalize_bookmark_db(stmt);
return -1;
}
+ if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+ if (sqlite3_bind_int(stmt, 2, type) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ /* The given foldername is exist on the bookmark table */
+ _favorites_finalize_bookmark_db(stmt);
+ return 1;
+ }
- if ((nError = sqlite3_step(stmt)) == SQLITE_ROW) {
- int bookmark_id = sqlite3_column_int(stmt, 0);
+ _favorites_close_bookmark_db();
+ return 0;
+}
+
+int _get_exists_bookmark(const char *address)
+{
+ FAVORITES_LOGD("");
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select * from bookmarks where address=? and type=0",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_text(stmt, 1, address, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ _favorites_finalize_bookmark_db(stmt);
+ return 1;
+ }
+ _favorites_close_bookmark_db();
+ return 0;
+}
+
+int _get_exists_folder(const char *title, int parent_id)
+{
+ FAVORITES_LOGD("");
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select * from bookmarks where title=? and parent=? and type=1",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_text(stmt, 1, title, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_int(stmt, 2, parent_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ _favorites_finalize_bookmark_db(stmt);
+ return 1;
+ }
+ _favorites_close_bookmark_db();
+ return 0;
+}
+
+int _get_bookmark_id(const char *address)
+{
+ FAVORITES_LOGE("");
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select id from bookmarks where address=? and type=0",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_text(stmt, 1, address, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ int id = sqlite3_column_int(stmt, 0);
_favorites_finalize_bookmark_db(stmt);
- return bookmark_id;
+ return id;
+ }
+ _favorites_close_bookmark_db();
+ return 0;
+}
+
+int _get_folder_id(const char *title, const int parent)
+{
+
+ FAVORITES_LOGE("");
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "SELECT id FROM bookmarks WHERE title=? AND parent=? AND type=1",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_text(stmt, 1, title, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+ if (sqlite3_bind_int(stmt, 2, parent) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ int id = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ return id;
}
- FAVORITES_LOGE("No match with given url");
_favorites_close_bookmark_db();
return 0;
}
@@ -711,9 +985,38 @@ int _favorites_bookmark_get_bookmark_id(const char *url, const char *title, cons /*************************************************************
* APIs for Internet favorites
*************************************************************/
+int favorites_bookmark_get_root_folder_id(int *root_id)
+{
+ if (!root_id)
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+
+ *root_id = _get_root_folder_id();
+ return FAVORITES_ERROR_NONE;
+}
+
int favorites_bookmark_add_bookmark(const char *url, const char *title, const char *foldername, int *bookmark_id)
{
FAVORITES_LOGE("");
+#if 1
+ int ret = 0;
+ int root_id = 1;
+ int folder_id = 1;
+
+ if (!foldername || (strlen(foldername) <= 0)) {
+ FAVORITES_LOGE("foldername is empty. id is now root.\n");
+ folder_id = _get_root_folder_id();
+ } else {
+ FAVORITES_LOGE("adding folder\n");
+ ret = favorites_bookmark_add(foldername, url, root_id, 1, &folder_id);
+ if (ret != FAVORITES_ERROR_NONE) {
+ if (ret == FAVORITES_ERROR_ITEM_ALREADY_EXIST) {
+ folder_id = _get_folder_id(foldername, _get_root_folder_id());
+ } else
+ return ret;
+ }
+ }
+ return favorites_bookmark_add(title, url, folder_id, 0, bookmark_id);
+#else
int nError;
sqlite3_stmt *stmt;
int folderId = 1;
@@ -746,7 +1049,7 @@ int favorites_bookmark_add_bookmark(const char *url, const char *title, const ch }
/* Check the bookmarks is already exist*/
- if(_favorites_bookmark_is_bookmark_exist(url, title, folderId)!=0){
+ if(_get_exists_bookmark(url)!=0){
FAVORITES_LOGE("The bookmark is already exist.\n");
return FAVORITES_ERROR_ITEM_ALREADY_EXIST;
}
@@ -781,7 +1084,7 @@ int favorites_bookmark_add_bookmark(const char *url, const char *title, const ch if (nError == SQLITE_ROW || nError == SQLITE_DONE) {
_favorites_finalize_bookmark_db(stmt);
if (bookmark_id != NULL) {
- *bookmark_id = _favorites_bookmark_get_bookmark_id(url, title, folderId);
+ *bookmark_id = _get_bookmark_id(url);
}
return FAVORITES_ERROR_NONE;
}
@@ -789,6 +1092,22 @@ int favorites_bookmark_add_bookmark(const char *url, const char *title, const ch _favorites_close_bookmark_db();
return FAVORITES_ERROR_DB_FAILED;
+#endif
+}
+
+int favorites_bookmark_add(const char *title, const char *url, int parent_id, int type, int *saved_id)
+{
+ FAVORITES_LOGD("");
+ int ret = 0;
+ if (type == 0) {
+ FAVORITES_LOGD("type is bookmark");
+ ret = _add_bookmark(title, url, parent_id, saved_id);
+ } else {
+ FAVORITES_LOGD("type is folder");
+ ret = _add_folder(title, parent_id, saved_id);
+ }
+
+ return ret;
}
int favorites_bookmark_get_count(int *count)
@@ -1020,6 +1339,8 @@ int favorites_bookmark_export_list(const char * file_path) }
fputs("</DL><p>\n", fp);
fclose(fp);
+ _favorites_free_bookmark_list(bookmarks_list);
+ _favorites_free_bookmark_list(folders_list);
return FAVORITES_ERROR_NONE;
}
@@ -1079,6 +1400,7 @@ int favorites_bookmark_get_favicon(int id, Evas *evas, Evas_Object **icon) evas_object_image_alpha_set(*icon,EINA_TRUE);
evas_object_image_data_set(*icon, favicon->data);
}
+ free(favicon);
_favorites_finalize_bookmark_db(stmt);
return FAVORITES_ERROR_NONE;
}
@@ -1087,6 +1409,77 @@ int favorites_bookmark_get_favicon(int id, Evas *evas, Evas_Object **icon) return FAVORITES_ERROR_NONE;
}
+int favorites_bookmark_set_favicon(int bookmark_id, Evas_Object *icon)
+{
+ FAVORITES_INVALID_ARG_CHECK(bookmark_id<0);
+ FAVORITES_NULL_ARG_CHECK(icon);
+
+ int nError;
+ sqlite3_stmt *stmt;
+ int icon_w = 0;
+ int icon_h = 0;
+ int stride = 0;
+ int icon_length = 0;
+ void *icon_data = (void *)evas_object_image_data_get(icon, EINA_TRUE);
+ evas_object_image_size_get(icon, &icon_w, &icon_h);
+ stride = evas_object_image_stride_get(icon);
+ icon_length = icon_h * stride;
+ FAVORITES_LOGD("favicon size w:%d, h:%d, stride: %d", icon_w, icon_h, stride);
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "UPDATE bookmarks SET favicon=?,\
+ favicon_length=?, favicon_w=?, favicon_h=? \
+ WHERE id=?", -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ // bind
+ if (sqlite3_bind_blob(stmt, 1, icon_data , icon_length, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_blob(icon_data) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (sqlite3_bind_int(stmt, 2, icon_length) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int(icon_length) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (sqlite3_bind_int(stmt, 3, icon_w) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int(icon_w) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (sqlite3_bind_int(stmt, 4, icon_h) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int(icon_h) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (sqlite3_bind_int(stmt, 5, bookmark_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int(bookmark_id) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW || nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
int favorites_bookmark_delete_bookmark(int id)
{
FAVORITES_INVALID_ARG_CHECK(id<0);
diff --git a/src/favorites_history.c b/src/favorites_history.c index 6a6f4ef..456c8b3 100644 --- a/src/favorites_history.c +++ b/src/favorites_history.c @@ -20,7 +20,7 @@ #include <favorites.h>
#include <favorites_private.h>
-__thread sqlite3 *gl_internet_history_db = 0;
+sqlite3 *gl_internet_history_db = 0;
#define INTERNET_HISTORY_DB_NAME "/opt/usr/dbspace/.browser-history.db"
|