[epiphany/history-rewrite] ephy-history-service: add a method to clear the entire history



commit 09ef81ae93d631a6d58f37e23a552397a3a5fd06
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Fri Mar 2 21:24:58 2012 +0200

    ephy-history-service: add a method to clear the entire history

 lib/history/ephy-history-service.c |   43 ++++++++++++++++++++++++++++++++++++
 lib/history/ephy-history-service.h |    1 +
 2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c
index 1d5f06a..8d4e188 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,
+  CLEAR,
   /* QUIT */
   QUIT,
   /* READ */
@@ -287,6 +288,23 @@ ephy_history_service_close_database_connections (EphyHistoryService *self)
   priv->history_database = NULL;
 }
 
+static void
+ephy_history_service_clear_all (EphyHistoryService *self)
+{
+  EphyHistoryServicePrivate *priv = EPHY_HISTORY_SERVICE (self)->priv;
+  GError *error = NULL;
+
+  if (NULL == priv->history_database)
+    return;
+
+  ephy_sqlite_connection_execute (priv->history_database,
+                                  "DELETE FROM hosts;", &error);
+  if (error) {
+    g_error ("Couldn't clear history database: %s", error->message);
+    g_error_free(error);
+  }
+}
+
 static gboolean
 ephy_history_service_is_scheduled_to_quit (EphyHistoryService *self)
 {
@@ -688,6 +706,18 @@ ephy_history_service_execute_delete_urls (EphyHistoryService *self,
   return TRUE;
 }
 
+static gboolean
+ephy_history_service_execute_clear (EphyHistoryService *self,
+                                    gpointer pointer,
+                                    gpointer *result)
+{
+
+  ephy_history_service_clear_all (self);
+  ephy_history_service_schedule_commit (self);
+
+  return TRUE;
+}
+
 void
 ephy_history_service_delete_urls (EphyHistoryService *self,
                                   GList *urls,
@@ -701,6 +731,18 @@ ephy_history_service_delete_urls (EphyHistoryService *self,
   ephy_history_service_send_message (self, message);
 }
 
+void
+ephy_history_service_clear (EphyHistoryService *self,
+                            EphyHistoryJobCallback callback,
+                            gpointer user_data)
+{
+  EphyHistoryServiceMessage *message =
+    ephy_history_service_message_new (self, CLEAR,
+                                      NULL, NULL,
+                                      callback, user_data);
+  ephy_history_service_send_message (self, message);
+}
+
 static void
 ephy_history_service_quit (EphyHistoryService *self,
                            EphyHistoryJobCallback callback,
@@ -719,6 +761,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_clear,
   (EphyHistoryServiceMethod)ephy_history_service_execute_quit,
   (EphyHistoryServiceMethod)ephy_history_service_execute_get_url,
   (EphyHistoryServiceMethod)ephy_history_service_execute_get_host_for_url,
diff --git a/lib/history/ephy-history-service.h b/lib/history/ephy-history-service.h
index 50d79f3..64cab0c 100644
--- a/lib/history/ephy-history-service.h
+++ b/lib/history/ephy-history-service.h
@@ -70,6 +70,7 @@ void                     ephy_history_service_get_url                 (EphyHisto
 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, GList *substring_list, EphyHistoryJobCallback callback, gpointer user_data);
 void                     ephy_history_service_visit_url               (EphyHistoryService *self, const char *orig_url);
+void                     ephy_history_service_clear                   (EphyHistoryService *self, EphyHistoryJobCallback callback, gpointer user_data);
 
 G_END_DECLS
 



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