[epiphany/history-rewrite: 27/45] EphyHistoryService: add a generic method to set a URL property



commit eebabfa032a797cf1312fe9637e9710cfef00325
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Wed Jul 6 15:40:57 2011 +0300

    EphyHistoryService: add a generic method to set a URL property
    
    This is better than having individual setters and practical enough
    considering that the history service will be wrapped by higher-level
    API anyway.

 lib/history/ephy-history-service.c |   69 ++++++++++++++++++++++++++++++++++++
 lib/history/ephy-history-service.h |    2 +-
 lib/history/ephy-history-types.h   |    5 +++
 3 files changed, 75 insertions(+), 1 deletions(-)
---
diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c
index 5359cbb..78b0d3e 100644
--- a/lib/history/ephy-history-service.c
+++ b/lib/history/ephy-history-service.c
@@ -615,3 +615,72 @@ ephy_history_service_get_url (EphyHistoryService *self,
                                       ephy_history_service_execute_job_on_history_thread,
                                       details);
 }
+
+static gboolean
+ephy_history_service_execute_set_url_property (EphyHistoryService *self,
+                                               GVariant *variant,
+                                               gpointer *result)
+{
+  GVariant *value, *mvalue;
+  gchar *url_string;
+  EphyHistoryURL *url;
+  EphyHistoryURLProperty property;
+
+  g_variant_get (variant, "(s(iv))", &url_string, &property, &value);
+
+  url = ephy_history_url_new (url_string, NULL, 0, 0, 0, 1.0);
+  g_free (url_string);
+
+  if (NULL == ephy_history_service_get_url_row (self, NULL, url)) {
+    g_variant_unref (value);
+    ephy_history_url_free (url);
+
+    return FALSE;
+  }
+
+  switch (property) {
+  case EPHY_HISTORY_URL_TITLE:
+    if (url->title)
+      g_free (url->title);
+    mvalue = g_variant_get_maybe (value);
+    if (mvalue) {
+      url->title = g_variant_dup_string (mvalue, NULL);
+      g_variant_unref (mvalue);
+    } else {
+      url->title = NULL;
+    }
+    break;
+  case EPHY_HISTORY_URL_ZOOM_LEVEL:
+    url->zoom_level = g_variant_get_double (value);
+    break;
+  default:
+    g_assert_not_reached();
+  }
+  g_variant_unref (value);
+
+  ephy_history_service_update_url_row (self, url);
+  ephy_history_service_schedule_commit (self);
+
+  return TRUE;
+}
+
+void
+ephy_history_service_set_url_property (EphyHistoryService *self,
+                                       const char *url,
+                                       EphyHistoryURLProperty property,
+                                       GVariant *value,
+                                       EphyHistoryJobCallback callback,
+                                       gpointer user_data)
+{
+  GVariant *variant = g_variant_new ("(s(iv))", url, property, value);
+
+  EphyHistoryThreadJobDetails *details =
+    ephy_history_thread_job_details_new (self,
+                                         (EphyHistoryJobMethod) ephy_history_service_execute_set_url_property,
+                                         variant, (GDestroyNotify)g_variant_unref,
+                                         callback, user_data);
+
+  ephy_history_service_schedule_idle (self, G_PRIORITY_DEFAULT,
+                                      ephy_history_service_execute_job_on_history_thread,
+                                      details);
+}
diff --git a/lib/history/ephy-history-service.h b/lib/history/ephy-history-service.h
index 8f0b7f1..9d5d950 100644
--- a/lib/history/ephy-history-service.h
+++ b/lib/history/ephy-history-service.h
@@ -59,8 +59,8 @@ void                     ephy_history_service_add_visits              (EphyHisto
 void                     ephy_history_service_find_visits_in_time     (EphyHistoryService *self, gint64 from, gint64 to, EphyHistoryJobCallback callback, gpointer user_data);
 void                     ephy_history_service_set_url_title           (EphyHistoryService *self, const char *url, const char *title, EphyHistoryJobCallback callback, gpointer user_data);
 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_set_url_property        (EphyHistoryService *self, const char *url, EphyHistoryURLProperty property, GVariant *value, EphyHistoryJobCallback callback, gpointer user_data);
 void                     ephy_history_service_get_url                 (EphyHistoryService *self, const char *url, EphyHistoryJobCallback callback, gpointer user_data);
-
 G_END_DECLS
 
 #endif /* EPHY_HISTORY_SERVICE_H */
diff --git a/lib/history/ephy-history-types.h b/lib/history/ephy-history-types.h
index 3696866..b77fe77 100644
--- a/lib/history/ephy-history-types.h
+++ b/lib/history/ephy-history-types.h
@@ -37,6 +37,11 @@ typedef enum {
   EPHY_PAGE_VISIT_FORM_RELOAD,
 } EphyHistoryPageVisitType;
 
+typedef enum {
+  EPHY_HISTORY_URL_TITLE,
+  EPHY_HISTORY_URL_ZOOM_LEVEL
+} EphyHistoryURLProperty;
+
 typedef struct _EphyHistoryURL
 {
   int id;



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