From e9463a9dc1fd77f741d3cc6a6c335db9733ebdf1 Mon Sep 17 00:00:00 2001 From: Claudio Saavedra Date: Tue, 6 Mar 2012 17:08:50 +0200 Subject: ephy-history-service: add a method to remove a host from the history This method will remove all the history related to that host. --- lib/history/ephy-history-service-hosts-table.c | 50 ++++++++++++++++++++++++++ lib/history/ephy-history-service-private.h | 1 + lib/history/ephy-history-service.c | 27 ++++++++++++++ lib/history/ephy-history-service.h | 1 + 4 files changed, 79 insertions(+) (limited to 'lib/history') diff --git a/lib/history/ephy-history-service-hosts-table.c b/lib/history/ephy-history-service-hosts-table.c index 032764457..969154501 100644 --- a/lib/history/ephy-history-service-hosts-table.c +++ b/lib/history/ephy-history-service-hosts-table.c @@ -318,3 +318,53 @@ ephy_history_service_get_host_row_from_url (EphyHistoryService *self, return host; } + +void +ephy_history_service_delete_host_row (EphyHistoryService *self, + EphyHistoryHost *host) +{ + EphyHistoryServicePrivate *priv = EPHY_HISTORY_SERVICE (self)->priv; + EphySQLiteStatement *statement = NULL; + gchar *sql_statement; + GError *error = NULL; + + g_assert (priv->history_thread == g_thread_self ()); + g_assert (priv->history_database != NULL); + + g_assert (host->id != -1 || host->url); + + if (host->id != -1) + sql_statement = g_strdup ("DELETE FROM hosts WHERE id=?"); + else + sql_statement = g_strdup ("DELETE FROM hosts WHERE url=?"); + + statement = ephy_sqlite_connection_create_statement (priv->history_database, + sql_statement, &error); + g_free (sql_statement); + + if (error) { + g_error ("Could not build urls table query statement: %s", error->message); + g_error_free (error); + g_object_unref (statement); + return; + } + + if (host->id != -1) + ephy_sqlite_statement_bind_int (statement, 0, host->id, &error); + else + ephy_sqlite_statement_bind_string (statement, 0, host->url, &error); + + if (error) { + g_error ("Could not build hosts table query statement: %s", error->message); + g_error_free (error); + g_object_unref (statement); + return; + } + + ephy_sqlite_statement_step (statement, &error); + if (error) { + g_error ("Could not modify host in hosts table: %s", error->message); + g_error_free (error); + } + g_object_unref (statement); +} diff --git a/lib/history/ephy-history-service-private.h b/lib/history/ephy-history-service-private.h index 4cf88d4c0..b585d403d 100644 --- a/lib/history/ephy-history-service-private.h +++ b/lib/history/ephy-history-service-private.h @@ -51,5 +51,6 @@ void ephy_history_service_update_host_row (EphyHisto EphyHistoryHost * ephy_history_service_get_host_row (EphyHistoryService *self, const gchar *url_string, EphyHistoryHost *host); GList * ephy_history_service_get_all_hosts (EphyHistoryService *self); EphyHistoryHost * ephy_history_service_get_host_row_from_url (EphyHistoryService *self, const gchar *url); +void ephy_history_service_delete_host_row (EphyHistoryService *self, EphyHistoryHost *host); #endif /* EPHY_HISTORY_SERVICE_PRIVATE_H */ diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c index 53363bc56..4c9e44179 100644 --- a/lib/history/ephy-history-service.c +++ b/lib/history/ephy-history-service.c @@ -32,6 +32,7 @@ typedef enum { ADD_VISIT, ADD_VISITS, DELETE_URLS, + DELETE_HOST, CLEAR, /* QUIT */ QUIT, @@ -755,6 +756,18 @@ ephy_history_service_execute_delete_urls (EphyHistoryService *self, return TRUE; } +static gboolean +ephy_history_service_execute_delete_host (EphyHistoryService *self, + EphyHistoryHost *host, + EphyHistoryJobCallback callback, + gpointer user_data) +{ + ephy_history_service_delete_host_row (self, host); + ephy_history_service_schedule_commit (self); + + return TRUE; +} + static gboolean ephy_history_service_execute_clear (EphyHistoryService *self, gpointer pointer, @@ -780,6 +793,19 @@ ephy_history_service_delete_urls (EphyHistoryService *self, ephy_history_service_send_message (self, message); } +void +ephy_history_service_delete_host (EphyHistoryService *self, + EphyHistoryHost *host, + EphyHistoryJobCallback callback, + gpointer user_data) +{ + EphyHistoryServiceMessage *message = + ephy_history_service_message_new (self, DELETE_HOST, + ephy_history_host_copy (host), (GDestroyNotify)ephy_history_host_free, + callback, user_data); + ephy_history_service_send_message (self, message); +} + void ephy_history_service_clear (EphyHistoryService *self, EphyHistoryJobCallback callback, @@ -810,6 +836,7 @@ static EphyHistoryServiceMethod methods[] = { (EphyHistoryServiceMethod)ephy_history_service_execute_add_visit, (EphyHistoryServiceMethod)ephy_history_service_execute_add_visits, (EphyHistoryServiceMethod)ephy_history_service_execute_delete_urls, + (EphyHistoryServiceMethod)ephy_history_service_execute_delete_host, (EphyHistoryServiceMethod)ephy_history_service_execute_clear, (EphyHistoryServiceMethod)ephy_history_service_execute_quit, (EphyHistoryServiceMethod)ephy_history_service_execute_get_url, diff --git a/lib/history/ephy-history-service.h b/lib/history/ephy-history-service.h index c9632f86b..e6c522d11 100644 --- a/lib/history/ephy-history-service.h +++ b/lib/history/ephy-history-service.h @@ -67,6 +67,7 @@ void ephy_history_service_set_url_title (EphyHisto void ephy_history_service_set_url_zoom_level (EphyHistoryService *self, const char *url, const double zoom_level, EphyHistoryJobCallback callback, gpointer user_data); void ephy_history_service_get_host_for_url (EphyHistoryService *self, const char *url, EphyHistoryJobCallback callback, gpointer user_data); void ephy_history_service_get_hosts (EphyHistoryService *self, EphyHistoryJobCallback callback, gpointer user_data); +void ephy_history_service_delete_host (EphyHistoryService *self, EphyHistoryHost *host, EphyHistoryJobCallback callback, gpointer user_data); void ephy_history_service_get_url (EphyHistoryService *self, const char *url, EphyHistoryJobCallback callback, gpointer user_data); void ephy_history_service_delete_urls (EphyHistoryService *self, GList *urls, EphyHistoryJobCallback callback, gpointer user_data); void ephy_history_service_find_urls (EphyHistoryService *self, gint64 from, gint64 to, guint limit, gint host, GList *substring_list, EphyHistoryJobCallback callback, gpointer user_data); -- cgit v1.2.3