[epiphany/wip/ephy-sync: 13/86] Provide stub implementation of EphySyncService class



commit 25deff28f4deedb373f384f01e6fd6c45e96f676
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Tue May 24 00:53:36 2016 +0300

    Provide stub implementation of EphySyncService class

 src/Makefile.am         |    2 +
 src/ephy-shell.c        |    4 ++-
 src/ephy-sync-service.c |   41 +++++++++++++++++++++++
 src/ephy-sync-service.h |   17 +++++++++
 src/ephy-sync-window.c  |   83 ++++++++++++++++++++++++++++++++++++++++++++--
 src/ephy-sync-window.h  |    4 ++-
 6 files changed, 145 insertions(+), 6 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 183d77b..d2595bd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -57,6 +57,8 @@ libephymain_la_SOURCES = \
        ephy-history-window.h                   \
        ephy-sync-window.c                      \
        ephy-sync-window.h                      \
+       ephy-sync-service.c                     \
+       ephy-sync-service.h                     \
        ephy-link.c                             \
        ephy-link.h                             \
        ephy-location-controller.c              \
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 6c837de..1ff420f 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -843,6 +843,7 @@ GtkWidget *
 ephy_shell_get_sync_window (EphyShell *shell)
 {
   EphyEmbedShell *embed_shell;
+  EphySyncService *sync_service;
 
   printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
 
@@ -850,7 +851,8 @@ ephy_shell_get_sync_window (EphyShell *shell)
   embed_shell = embed_shell; // suppress warnings
 
   if (shell->sync_window == NULL) {
-    shell->sync_window = ephy_sync_window_new ();
+    sync_service = ephy_sync_service_new ();
+    shell->sync_window = ephy_sync_window_new (sync_service);
     g_signal_connect (shell->sync_window,
                       "destroy",
                       G_CALLBACK (gtk_widget_destroyed),
diff --git a/src/ephy-sync-service.c b/src/ephy-sync-service.c
new file mode 100644
index 0000000..0fda189
--- /dev/null
+++ b/src/ephy-sync-service.c
@@ -0,0 +1,41 @@
+#include "ephy-sync-service.h"
+
+#include <stdio.h>
+
+struct _EphySyncService {
+  GObject parent_instance;
+};
+
+G_DEFINE_TYPE (EphySyncService, ephy_sync_service, G_TYPE_OBJECT);
+
+static void
+ephy_sync_service_class_init (EphySyncServiceClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  object_class = object_class; // suppress warnings
+
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+
+  // TODO: Set finalize, dispose, set/get property methods
+}
+
+static void
+ephy_sync_service_init (EphySyncService *self)
+{
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+}
+
+EphySyncService *
+ephy_sync_service_new (void)
+{
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+
+  return EPHY_SYNC_SERVICE (g_object_new (EPHY_TYPE_SYNC_SERVICE,
+                                          NULL));
+}
+
+void
+ephy_sync_service_stretch (void)
+{
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+}
diff --git a/src/ephy-sync-service.h b/src/ephy-sync-service.h
new file mode 100644
index 0000000..d685963
--- /dev/null
+++ b/src/ephy-sync-service.h
@@ -0,0 +1,17 @@
+#ifndef EPHY_SYNC_SERVICE_H
+#define EPHY_SYNC_SERVICE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_SYNC_SERVICE (ephy_sync_service_get_type())
+
+G_DECLARE_FINAL_TYPE (EphySyncService, ephy_sync_service, EPHY, SYNC_SERVICE, GObject)
+
+EphySyncService        *ephy_sync_service_new           (void);
+void                    ephy_sync_service_stretch       (void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/ephy-sync-window.c b/src/ephy-sync-window.c
index b7f76b9..8d23b6e 100644
--- a/src/ephy-sync-window.c
+++ b/src/ephy-sync-window.c
@@ -6,6 +6,7 @@
 struct _EphySyncWindow {
   GtkDialog parent_instance;
 
+  EphySyncService *sync_service;
   GCancellable *cancellable;
 
   GtkWidget *entry_email;
@@ -13,12 +14,18 @@ struct _EphySyncWindow {
   GtkButton *btn_submit;
 
   GActionGroup *action_group;
-
-  // TODO: Add sync service instance
 };
 
 G_DEFINE_TYPE (EphySyncWindow, ephy_sync_window, GTK_TYPE_DIALOG)
 
+enum {
+  PROP_0,
+  PROP_SYNC_SERVICE,
+  PROP_LAST
+};
+
+static GParamSpec *obj_properties[PROP_LAST];
+
 static void
 quickstretch (GSimpleAction *action,
               GVariant      *parameter,
@@ -31,6 +38,60 @@ quickstretch (GSimpleAction *action,
   printf("password:%s\n", gtk_entry_get_text (GTK_ENTRY (self->entry_password)));
 }
 
+static void
+set_sync_service (EphySyncWindow  *self,
+                  EphySyncService *sync_service)
+{
+  if (sync_service == self->sync_service)
+    return;
+
+  if (self->sync_service != NULL) {
+    // TODO: Disconnect signal handlers, if any
+    g_clear_object (&self->sync_service);
+  }
+
+  if (sync_service != NULL) {
+    self->sync_service = g_object_ref (sync_service);
+    // TODO: Connect signal handlers, if any
+  }
+}
+
+static void
+ephy_sync_window_set_property (GObject      *object,
+                               guint         prop_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  EphySyncWindow *self = EPHY_SYNC_WINDOW (object);
+
+  switch (prop_id) {
+    case PROP_SYNC_SERVICE:
+      set_sync_service (self, g_value_get_object (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+ephy_sync_window_get_property (GObject    *object,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  EphySyncWindow *self = EPHY_SYNC_WINDOW (object);
+
+  switch (prop_id) {
+    case PROP_SYNC_SERVICE:
+      g_value_set_object (value, self->sync_service);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
 static GActionGroup *
 create_action_group (EphySyncWindow *self)
 {
@@ -49,11 +110,24 @@ create_action_group (EphySyncWindow *self)
 static void
 ephy_sync_window_class_init (EphySyncWindowClass *klass)
 {
-  // GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
 
+  object_class->set_property = ephy_sync_window_set_property;
+  object_class->get_property = ephy_sync_window_get_property;
+  // TODO: Set dispose method
+
+  obj_properties[PROP_SYNC_SERVICE] =
+    g_param_spec_object ("sync-service",
+                         "Sync service",
+                         "Sync Service",
+                         EPHY_TYPE_SYNC_SERVICE,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+
+  g_object_class_install_properties (object_class, PROP_LAST, obj_properties);
+
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/org/gnome/epiphany/sync-dialog.ui");
 
@@ -78,7 +152,7 @@ ephy_sync_window_init (EphySyncWindow *self)
 }
 
 GtkWidget *
-ephy_sync_window_new (void)
+ephy_sync_window_new (EphySyncService *sync_service)
 {
   EphySyncWindow *self;
 
@@ -86,6 +160,7 @@ ephy_sync_window_new (void)
 
   self = g_object_new (EPHY_TYPE_SYNC_WINDOW,
                        "use-header-bar", TRUE,
+                       "sync-service", sync_service,
                        NULL);
 
   return GTK_WIDGET (self);
diff --git a/src/ephy-sync-window.h b/src/ephy-sync-window.h
index df72f91..dc747e8 100644
--- a/src/ephy-sync-window.h
+++ b/src/ephy-sync-window.h
@@ -3,13 +3,15 @@
 
 #include <gtk/gtk.h>
 
+#include "ephy-sync-service.h"
+
 G_BEGIN_DECLS
 
 #define EPHY_TYPE_SYNC_WINDOW (ephy_sync_window_get_type ())
 
 G_DECLARE_FINAL_TYPE (EphySyncWindow, ephy_sync_window, EPHY, SYNC_WINDOW, GtkDialog)
 
-GtkWidget       *ephy_sync_window_new        (void);
+GtkWidget       *ephy_sync_window_new        (EphySyncService *sync_service);
 
 G_END_DECLS
 


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