[epiphany/wip/history-rewrite] ephy-history-service: add a method to remove a host from the history



commit 4434c5079f608b86bbd9c4fef94686348b1247fc
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Tue Mar 6 17:08:50 2012 +0200

    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(+), 0 deletions(-)
---
diff --git a/lib/history/ephy-history-service-hosts-table.c b/lib/history/ephy-history-service-hosts-table.c
index 0327644..9691545 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 4cf88d4..b585d40 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 53363bc..4c9e441 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,
@@ -756,6 +757,18 @@ ephy_history_service_execute_delete_urls (EphyHistoryService *self,
 }
 
 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,
                                     gpointer *result)
@@ -781,6 +794,19 @@ ephy_history_service_delete_urls (EphyHistoryService *self,
 }
 
 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,
                             gpointer user_data)
@@ -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 c9632f8..e6c522d 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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]