From cf62534add74555531fbdc5da84f9a5bc29e76a2 Mon Sep 17 00:00:00 2001 From: Hyerim Bae Date: Tue, 4 Sep 2012 17:53:57 +0900 Subject: [Title] Fix issue that the most visited item can't be deleted. [Issue#] N_SE-8861 [Problem] The most visited item can't be deleted. [Cause] The most visited item index is wrong. [Solution] Delete the most visited item with url. [Team] Browser UI [Developer] Hyerim Bae [Request] N/A Change-Id: I4795a74b9dedb9a293bf61432b1b916acf03e7b0 --- src/database/most-visited-sites-db.cpp | 30 +++++++++++++++++++++++++++ src/database/most-visited-sites-db.h | 1 + src/most-visited-sites/most-visited-sites.cpp | 11 +++++++--- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/database/most-visited-sites-db.cpp b/src/database/most-visited-sites-db.cpp index a1a961aa..b491943b 100644 --- a/src/database/most-visited-sites-db.cpp +++ b/src/database/most-visited-sites-db.cpp @@ -94,6 +94,36 @@ Eina_Bool Most_Visited_Sites_DB::is_in_bookmark(const char* url, int *bookmark_i return (error == SQLITE_ROW); } +Eina_Bool Most_Visited_Sites_DB::delete_most_visited_sites_item(const char * url) +{ + int error = db_util_open(BROWSER_MOST_VISITED_SITES_DB_PATH, &m_db_descriptor, DB_UTIL_REGISTER_HOOK_METHOD); + if (error != SQLITE_OK) { + db_util_close(m_db_descriptor); + m_db_descriptor = NULL; + BROWSER_LOGD("check here"); + return EINA_FALSE; + } + + sqlite3_stmt *sqlite3_stmt = NULL; + error = sqlite3_prepare_v2(m_db_descriptor, "delete from mostvisited where address=?", + -1, &sqlite3_stmt, NULL); + if (error != SQLITE_OK) { + db_util_close(m_db_descriptor); + return EINA_FALSE; + } + + if (sqlite3_bind_text(sqlite3_stmt, 1, url, -1, NULL) != SQLITE_OK) + BROWSER_LOGE("sqlite3_bind_int is failed."); + + error = sqlite3_step(sqlite3_stmt); + if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK) + BROWSER_LOGE("sqlite3_finalize is failed."); + + db_util_close(m_db_descriptor); + + return (error == SQLITE_OK || error == SQLITE_DONE); +} + Eina_Bool Most_Visited_Sites_DB::delete_most_visited_sites_item(int index) { int error = db_util_open(BROWSER_MOST_VISITED_SITES_DB_PATH, &m_db_descriptor, DB_UTIL_REGISTER_HOOK_METHOD); diff --git a/src/database/most-visited-sites-db.h b/src/database/most-visited-sites-db.h index 08348392..882feb35 100644 --- a/src/database/most-visited-sites-db.h +++ b/src/database/most-visited-sites-db.h @@ -46,6 +46,7 @@ public: Eina_Bool save_most_visited_sites_item(int index, const char *url, const char *title, const char *screen_shot); Eina_Bool delete_most_visited_sites_item(int index); + Eina_Bool delete_most_visited_sites_item(const char *url); Eina_Bool delete_most_visited_sites_history_item(int history_id); std::string get_history_id_by_url(const char* url); std::string get_history_title_by_id(const char* id); diff --git a/src/most-visited-sites/most-visited-sites.cpp b/src/most-visited-sites/most-visited-sites.cpp index a431cba1..dc38d9e5 100644 --- a/src/most-visited-sites/most-visited-sites.cpp +++ b/src/most-visited-sites/most-visited-sites.cpp @@ -406,7 +406,7 @@ void Most_Visited_Sites::__context_popup_unpin_clicked_cb(void *data, Evas_Objec index++; } while (it = elm_gengrid_item_next_get(it)); - if (!most_visited_sites->m_most_visited_sites_db->delete_most_visited_sites_item(index)) { + if (!most_visited_sites->m_most_visited_sites_db->delete_most_visited_sites_item(most_visited_sites->m_selected_item->url)) { BROWSER_LOGE("delete_most_visited_sites_item failed"); return; } @@ -506,13 +506,17 @@ Eina_Bool Most_Visited_Sites::_delete_selected_item(void) index++; } while (it = elm_gengrid_item_next_get(it)); - if (!m_most_visited_sites_db->delete_most_visited_sites_item(index)) { + + BROWSER_LOGD("delete_most_visited_sites_item index = %d", m_selected_item->item); + if (!m_most_visited_sites_db->delete_most_visited_sites_item(m_selected_item->url)) { BROWSER_LOGE("delete_most_visited_sites_item failed"); return EINA_FALSE; } std::string history_id; history_id = m_most_visited_sites_db->get_history_id_by_url(m_selected_item->url); + + BROWSER_LOGD("delete_most_visited_sites_item history_id = %s, atoi(m_selected_item->history_id) = %d", history_id.c_str(), atoi(m_selected_item->history_id)); if (!m_most_visited_sites_db->delete_most_visited_sites_history_item(atoi(m_selected_item->history_id))) { BROWSER_LOGE("delete_most_visited_sites_history_item failed"); return EINA_FALSE; @@ -520,6 +524,7 @@ Eina_Bool Most_Visited_Sites::_delete_selected_item(void) is_ranked = EINA_TRUE; } else { + BROWSER_LOGD("delete_most_visited_sites_item atoi(m_selected_item->history_id) = %d", atoi(m_selected_item->history_id)); if (!m_most_visited_sites_db->delete_most_visited_sites_history_item(atoi(m_selected_item->history_id))) { BROWSER_LOGE("delete_most_visited_sites_history_item failed"); return EINA_FALSE; @@ -828,7 +833,7 @@ Eina_Bool Most_Visited_Sites::_item_moved(void) int index = 0; Elm_Object_Item *it = elm_gengrid_first_item_get(m_gengrid); do { - if (!m_most_visited_sites_db->delete_most_visited_sites_item(index)) + if (!m_most_visited_sites_db->delete_most_visited_sites_item(m_selected_item->url)) BROWSER_LOGE("fail to delete slot %d", index); most_visited_sites_item *item = (most_visited_sites_item *)elm_object_item_data_get(it); -- cgit v1.2.3