[epiphany/history-rewrite: 4/28] Allow adding visits with URL data.



commit 31390e72819da75000340ad0bea5db310490f89d
Author: Martin Robinson <mrobinson igalia com>
Date:   Sat Apr 23 14:02:03 2011 -0700

    Allow adding visits with URL data.
    
    Make EphyHistoryURL a member of EphyHistoryPageVisit. Allow
    instantiating an EphyHistoryPageVisit with a const char* url
    or an actual EphyHistoryURL.

 embed/history/ephy-history-service-visits-table.c |    2 +-
 embed/history/ephy-history-service.c              |   14 ++++---
 embed/history/ephy-history-types.c                |   38 +++++++++++++++------
 embed/history/ephy-history-types.h                |   18 +++++-----
 4 files changed, 45 insertions(+), 27 deletions(-)
---
diff --git a/embed/history/ephy-history-service-visits-table.c b/embed/history/ephy-history-service-visits-table.c
index f2a9e27..a55fd6b 100644
--- a/embed/history/ephy-history-service-visits-table.c
+++ b/embed/history/ephy-history-service-visits-table.c
@@ -69,7 +69,7 @@ ephy_history_service_add_visit_row (EphyHistoryService *self, EphyHistoryPageVis
     return;
   }
 
-  if (FALSE == ephy_sqlite_statement_bind_int (statement, 0, visit->url_id, &error) ||
+  if (FALSE == ephy_sqlite_statement_bind_int (statement, 0, visit->url->id, &error) ||
       FALSE == ephy_sqlite_statement_bind_int (statement, 1, visit->visit_time, &error) ||
       FALSE == ephy_sqlite_statement_bind_int (statement, 2, visit->visit_type, &error)) {
     g_error ("Could not build visits table addition statement: %s", error->message);
diff --git a/embed/history/ephy-history-service.c b/embed/history/ephy-history-service.c
index 2cc7c59..4b85c71 100644
--- a/embed/history/ephy-history-service.c
+++ b/embed/history/ephy-history-service.c
@@ -385,28 +385,30 @@ ephy_history_service_execute_job_on_history_thread (gpointer data)
 static gboolean
 ephy_history_service_execute_add_visit_helper (EphyHistoryService *self, EphyHistoryPageVisit *visit)
 {
-  EphyHistoryURL *url = ephy_history_service_get_url_row (self, visit->url);
+  EphyHistoryURL *url = ephy_history_service_get_url_row (self, visit->url->url);
 
   if (NULL == url) { /* This URL does not yet exist in the history table */
-    url = ephy_history_url_new (visit->url, "", 1, 0, visit->visit_time);
-    ephy_history_service_add_url_row (self, url);
+    visit->url->last_visit_time = visit->visit_time;
+    ephy_history_service_add_url_row (self, visit->url);
 
-    if (url->id == -1) {
+    if (visit->url->id == -1) {
       g_error ("Adding visit failed after failed URL addition.");
       return FALSE;
     }
+
   } else {
     url->visit_count++;
     if (visit->visit_time > url->last_visit_time) {
       url->last_visit_time = visit->visit_time;
     }
     ephy_history_service_update_url_row (self, url);
+
+    visit->url->id = url->id;
+    ephy_history_url_free (url);
   }
 
-  visit->url_id = url->id;
 
   ephy_history_service_add_visit_row (self, visit);
-  ephy_history_url_free (url);
   return visit->id != -1;
 }
 
diff --git a/embed/history/ephy-history-types.c b/embed/history/ephy-history-types.c
index 21c0ec4..2a8ce38 100644
--- a/embed/history/ephy-history-types.c
+++ b/embed/history/ephy-history-types.c
@@ -23,30 +23,39 @@
 #include "ephy-history-types.h"
 
 EphyHistoryPageVisit *
-ephy_history_page_visit_new (const char *url, gint64 visit_time, EphyHistoryPageVisitType visit_type)
+ephy_history_page_visit_new_with_url (EphyHistoryURL *url, gint64 visit_time, EphyHistoryPageVisitType visit_type)
 {
   EphyHistoryPageVisit *visit = g_slice_alloc0 (sizeof (EphyHistoryPageVisit));
   visit->id = -1;
-  visit->url = g_strdup (url);
-  visit->url_id = -1;
+  visit->url = url;
   visit->visit_time = visit_time;
   visit->visit_type = visit_type;
   return visit;
 }
 
+EphyHistoryPageVisit *
+ephy_history_page_visit_new (const char *url, gint64 visit_time, EphyHistoryPageVisitType visit_type)
+{
+  return ephy_history_page_visit_new_with_url (ephy_history_url_new (url, "", 0, 0, 0),
+                                               visit_time, visit_type);
+}
+
 void
 ephy_history_page_visit_free (EphyHistoryPageVisit *visit)
 {
-  g_free (visit->url);
+  if (visit == NULL)
+    return;
+
+  ephy_history_url_free (visit->url);
   g_slice_free1 (sizeof (EphyHistoryPageVisit), visit);
 }
 
 EphyHistoryPageVisit *
 ephy_history_page_visit_copy (EphyHistoryPageVisit *visit)
 {
-  EphyHistoryPageVisit *copy = ephy_history_page_visit_new (visit->url, visit->visit_time, visit->visit_type);
+  EphyHistoryPageVisit *copy = ephy_history_page_visit_new_with_url (0, visit->visit_time, visit->visit_type);
   copy->id = visit->id;
-  copy->url_id = visit->url_id;
+  copy->url = ephy_history_url_copy (visit->url);
   return copy;
 }
 
@@ -84,11 +93,15 @@ ephy_history_url_new (const char *url, const char *title, int visit_count, int t
 EphyHistoryURL *
 ephy_history_url_copy (EphyHistoryURL *url)
 {
-  EphyHistoryURL *copy = ephy_history_url_new (url->url,
-                                               url->title,
-                                               url->visit_count,
-                                               url->typed_count,
-                                               url->last_visit_time);
+  EphyHistoryURL *copy;
+  if (url == NULL)
+    return NULL;
+
+  copy = ephy_history_url_new (url->url,
+                               url->title,
+                               url->visit_count,
+                               url->typed_count,
+                               url->last_visit_time);
   copy->id = url->id;
   return copy;
 }
@@ -96,6 +109,9 @@ ephy_history_url_copy (EphyHistoryURL *url)
 void
 ephy_history_url_free (EphyHistoryURL *url)
 {
+  if (url == NULL)
+    return;
+
   g_free (url->url);
   g_free (url->title);
   g_slice_free1 (sizeof (EphyHistoryURL), url);
diff --git a/embed/history/ephy-history-types.h b/embed/history/ephy-history-types.h
index 4d8284d..3e77bd7 100644
--- a/embed/history/ephy-history-types.h
+++ b/embed/history/ephy-history-types.h
@@ -37,15 +37,6 @@ typedef enum {
   EphyPageVisitTypeFormReload,
 } EphyHistoryPageVisitType;
 
-typedef struct _EphyHistoryPageVisit
-{
-  int id;
-  char* url;
-  int url_id;
-  gint64 visit_time;
-  EphyHistoryPageVisitType visit_type;
-} EphyHistoryPageVisit;
-
 typedef struct _EphyHistoryURL
 {
   int id;
@@ -56,7 +47,16 @@ typedef struct _EphyHistoryURL
   int last_visit_time;
 } EphyHistoryURL;
 
+typedef struct _EphyHistoryPageVisit
+{
+  EphyHistoryURL* url;
+  int id;
+  gint64 visit_time;
+  EphyHistoryPageVisitType visit_type;
+} EphyHistoryPageVisit;
+
 EphyHistoryPageVisit *          ephy_history_page_visit_new (const char *url, gint64 visit_time, EphyHistoryPageVisitType visit_type);
+EphyHistoryPageVisit *          ephy_history_page_visit_new_with_url (EphyHistoryURL *url, gint64 visit_time, EphyHistoryPageVisitType visit_type);
 EphyHistoryPageVisit *          ephy_history_page_visit_copy (EphyHistoryPageVisit *visit);
 void                            ephy_history_page_visit_free (EphyHistoryPageVisit *visit);
 



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