[epiphany] Create the EphyCompletionModel with a history service and bookmarks objects



commit 7c7c8fb8432ea04c14d70138a4de12675fa2fa0f
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Mon Dec 9 19:46:23 2013 +0100

    Create the EphyCompletionModel with a history service and bookmarks objects
    
    Instead of getting them from the global shell.

 src/ephy-completion-model.c        |   59 +++++++++++++++++++++++++++++-------
 src/ephy-completion-model.h        |    4 ++-
 src/ephy-location-controller.c     |    6 +++-
 src/ephy-search-provider.c         |    3 +-
 tests/ephy-completion-model-test.c |    6 ++-
 5 files changed, 62 insertions(+), 16 deletions(-)
---
diff --git a/src/ephy-completion-model.c b/src/ephy-completion-model.c
index 35bd43e..5bf408b 100644
--- a/src/ephy-completion-model.c
+++ b/src/ephy-completion-model.c
@@ -29,6 +29,12 @@
 
 #include <string.h>
 
+enum {
+  PROP_0,
+  PROP_HISTORY_SERVICE,
+  PROP_BOOKMARKS
+};
+
 G_DEFINE_TYPE (EphyCompletionModel, ephy_completion_model, GTK_TYPE_LIST_STORE)
 
 #define EPHY_COMPLETION_MODEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), 
EPHY_TYPE_COMPLETION_MODEL, EphyCompletionModelPrivate))
@@ -65,6 +71,24 @@ free_search_terms (GSList *search_terms)
 }
 
 static void
+ephy_completion_model_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec 
*pspec)
+{
+  EphyCompletionModel *self = EPHY_COMPLETION_MODEL (object);
+
+  switch (property_id) {
+  case PROP_HISTORY_SERVICE:
+    self->priv->history_service = EPHY_HISTORY_SERVICE (g_value_get_pointer (value));
+    break;
+  case PROP_BOOKMARKS:
+    self->priv->bookmarks = ephy_bookmarks_get_bookmarks (EPHY_BOOKMARKS (g_value_get_pointer (value)));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec);
+    break;
+  }
+}
+
+static void
 ephy_completion_model_finalize (GObject *object)
 {
   EphyCompletionModelPrivate *priv = EPHY_COMPLETION_MODEL (object)->priv;
@@ -87,24 +111,30 @@ ephy_completion_model_class_init (EphyCompletionModelClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->set_property = ephy_completion_model_set_property;
   object_class->constructed = ephy_completion_model_constructed;
   object_class->finalize = ephy_completion_model_finalize;
 
+  g_object_class_install_property (object_class,
+                                   PROP_HISTORY_SERVICE,
+                                   g_param_spec_pointer ("history-service",
+                                                         "History Service",
+                                                         "The history service",
+                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | 
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+  g_object_class_install_property (object_class,
+                                   PROP_BOOKMARKS,
+                                   g_param_spec_pointer ("bookmarks",
+                                                         "Bookmarks",
+                                                         "The bookmarks",
+                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | 
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
   g_type_class_add_private (object_class, sizeof (EphyCompletionModelPrivate));
 }
 
 static void
 ephy_completion_model_init (EphyCompletionModel *model)
 {
-  EphyCompletionModelPrivate *priv;
-  EphyBookmarks *bookmarks_service;
-
-  model->priv = priv = EPHY_COMPLETION_MODEL_GET_PRIVATE (model);
-
-  priv->history_service = EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service 
(ephy_embed_shell_get_default ()));
-
-  bookmarks_service = ephy_shell_get_bookmarks (ephy_shell_get_default ());
-  priv->bookmarks = ephy_bookmarks_get_bookmarks (bookmarks_service);
+  model->priv = EPHY_COMPLETION_MODEL_GET_PRIVATE (model);
 }
 
 static gboolean
@@ -553,7 +583,14 @@ ephy_completion_model_update_for_string (EphyCompletionModel *model,
 }
 
 EphyCompletionModel *
-ephy_completion_model_new (void)
+ephy_completion_model_new (EphyHistoryService *history_service,
+                           EphyBookmarks      *bookmarks)
 {
-  return g_object_new (EPHY_TYPE_COMPLETION_MODEL, NULL);
+  g_return_val_if_fail (EPHY_IS_HISTORY_SERVICE (history_service), NULL);
+  g_return_val_if_fail (EPHY_IS_BOOKMARKS (bookmarks), NULL);
+
+  return g_object_new (EPHY_TYPE_COMPLETION_MODEL,
+                       "history-service", history_service,
+                       "bookmarks", bookmarks,
+                       NULL);
 }
diff --git a/src/ephy-completion-model.h b/src/ephy-completion-model.h
index f02f812..4fb7afe 100644
--- a/src/ephy-completion-model.h
+++ b/src/ephy-completion-model.h
@@ -24,6 +24,7 @@
 #ifndef EPHY_COMPLETION_MODEL_H
 #define EPHY_COMPLETION_MODEL_H
 
+#include "ephy-bookmarks.h"
 #include "ephy-history-service.h"
 
 #include <gtk/gtk.h>
@@ -66,7 +67,8 @@ typedef struct
 
 GType                ephy_completion_model_get_type         (void);
 
-EphyCompletionModel *ephy_completion_model_new              (void);
+EphyCompletionModel *ephy_completion_model_new              (EphyHistoryService *history_service,
+                                                              EphyBookmarks *bookmarks);
 
 void                 ephy_completion_model_update_for_string (EphyCompletionModel *model,
                                                               const char *string,
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index 0ff9e4d..a1884c4 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -342,6 +342,8 @@ ephy_location_controller_constructed (GObject *object)
 {
        EphyLocationController *controller = EPHY_LOCATION_CONTROLLER (object);
        EphyLocationControllerPrivate *priv = controller->priv;
+       EphyHistoryService *history_service;
+       EphyBookmarks *bookmarks;
        EphyCompletionModel *model;
        GtkWidget *notebook, *widget;
 
@@ -353,7 +355,9 @@ ephy_location_controller_constructed (GObject *object)
        g_signal_connect (notebook, "switch-page",
                          G_CALLBACK (switch_page_cb), controller);
 
-       model = ephy_completion_model_new ();
+       history_service = EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service 
(ephy_embed_shell_get_default ()));
+       bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ());
+       model = ephy_completion_model_new (history_service, bookmarks);
        ephy_location_entry_set_completion (priv->location_entry,
                                            GTK_TREE_MODEL (model),
                                            EPHY_COMPLETION_TEXT_COL,
diff --git a/src/ephy-search-provider.c b/src/ephy-search-provider.c
index cbdba11..5d69467 100644
--- a/src/ephy-search-provider.c
+++ b/src/ephy-search-provider.c
@@ -361,7 +361,8 @@ ephy_search_provider_init (EphySearchProvider *self)
 
   self->settings = g_settings_new (EPHY_PREFS_SCHEMA);
 
-  self->model = ephy_completion_model_new ();
+  self->model = ephy_completion_model_new (EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service 
(ephy_embed_shell_get_default ())),
+                                           ephy_shell_get_bookmarks (ephy_shell_get_default ()));
   self->cancellable = g_cancellable_new ();
 }
 
diff --git a/tests/ephy-completion-model-test.c b/tests/ephy-completion-model-test.c
index b20ecb5..c717210 100644
--- a/tests/ephy-completion-model-test.c
+++ b/tests/ephy-completion-model-test.c
@@ -31,7 +31,8 @@ static void
 test_ephy_completion_model_create (void)
 {
     EphyCompletionModel *model;
-    model = ephy_completion_model_new ();
+    model = ephy_completion_model_new (EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service 
(ephy_embed_shell_get_default ())),
+                                       ephy_shell_get_bookmarks (ephy_shell_get_default ()));
     g_assert (model);
     g_object_unref (model);
 }
@@ -56,7 +57,8 @@ test_ephy_completion_model_update_empty (void)
     EphyCompletionModel *model;
     GMainLoop *loop = NULL;
 
-    model = ephy_completion_model_new ();
+    model = ephy_completion_model_new (EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service 
(ephy_embed_shell_get_default ())),
+                                       ephy_shell_get_bookmarks (ephy_shell_get_default ()));
     g_assert (model);
 
     loop = g_main_loop_new (NULL, FALSE);


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