[epiphany/wip/ephy-sync] Add basic sync window



commit ca9ccf6c1d47cab317c6bc2d685253a2bf5f58dd
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Sun May 22 22:55:21 2016 +0300

    Add basic sync window

 src/Makefile.am                            |    3 +
 src/ephy-shell.c                           |   38 +++++++++
 src/ephy-shell.h                           |    2 +
 src/ephy-sync-window.c                     |   92 ++++++++++++++++++++++
 src/ephy-sync-window.h                     |   16 ++++
 src/epiphany.gresource.xml                 |    1 +
 src/resources/epiphany-application-menu.ui |    5 +
 src/resources/sync-dialog.ui               |  113 ++++++++++++++++++++++++++++
 src/window-commands.c                      |   16 ++++
 src/window-commands.h                      |    2 +
 10 files changed, 288 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 8136f13..6f3e42b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,6 +43,8 @@ libephymain_la_SOURCES = \
        ephy-home-action.h                      \
        ephy-history-window.c                   \
        ephy-history-window.h                   \
+       ephy-sync-window.c                      \
+       ephy-sync-window.h                      \
        ephy-link.c                             \
        ephy-link.h                             \
        ephy-link-action.c                      \
@@ -124,6 +126,7 @@ RESOURCE_FILES = \
        resources/passwords-dialog.ui             \
        resources/prefs-dialog.ui                 \
        resources/prefs-lang-dialog.ui            \
+       resources/sync-dialog.ui                  \
        $(NULL)
 
 epiphany-resources.c: epiphany.gresource.xml $(RESOURCE_FILES)
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index e050180..cceec58 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -30,6 +30,7 @@
 #include "ephy-file-helpers.h"
 #include "ephy-gui.h"
 #include "ephy-history-window.h"
+#include "ephy-sync-window.h"
 #include "ephy-home-action.h"
 #include "ephy-lockdown.h"
 #include "ephy-prefs.h"
@@ -56,6 +57,7 @@ struct _EphyShell {
   GNetworkMonitor *network_monitor;
   GtkWidget *bme;
   GtkWidget *history_window;
+  GtkWidget *sync_window;
   GObject *prefs_dialog;
   EphyShellStartupContext *local_startup_context;
   EphyShellStartupContext *remote_startup_context;
@@ -183,6 +185,20 @@ show_history (GSimpleAction *action,
 }
 
 static void
+show_sync (GSimpleAction *action,
+           GVariant      *parameter,
+           gpointer      user_data)
+{
+  GtkWindow *window;
+
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+
+  window = gtk_application_get_active_window (GTK_APPLICATION (ephy_shell));
+
+  window_cmd_edit_sync (NULL, EPHY_WINDOW (window));
+}
+
+static void
 show_preferences (GSimpleAction *action,
                   GVariant      *parameter,
                   gpointer       user_data)
@@ -231,6 +247,7 @@ static GActionEntry app_entries[] = {
   { "new-incognito", new_incognito_window, NULL, NULL, NULL },
   { "bookmarks", show_bookmarks, NULL, NULL, NULL },
   { "history", show_history, NULL, NULL, NULL },
+  { "sync", show_sync, NULL, NULL, NULL },
   { "preferences", show_preferences, NULL, NULL, NULL },
   { "help", show_help, NULL, NULL, NULL },
   { "about", show_about, NULL, NULL, NULL },
@@ -790,6 +807,27 @@ ephy_shell_get_history_window (EphyShell *shell)
   return shell->history_window;
 }
 
+GtkWidget *
+ephy_shell_get_sync_window (EphyShell *shell)
+{
+  EphyEmbedShell *embed_shell;
+
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+
+  embed_shell = ephy_embed_shell_get_default ();
+  embed_shell = embed_shell; // suppress warnings
+
+  if (shell->sync_window == NULL) {
+    shell->sync_window = ephy_sync_window_new ();
+    g_signal_connect (shell->sync_window,
+                      "destroy",
+                      G_CALLBACK (gtk_widget_destroyed),
+                      &shell->sync_window);
+  }
+
+  return shell->sync_window;
+}
+
 /**
  * ephy_shell_get_prefs_dialog:
  *
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index f06bbdc..1e1f139 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -104,6 +104,8 @@ GtkWidget       *ephy_shell_get_bookmarks_editor         (EphyShell *shell);
 
 GtkWidget       *ephy_shell_get_history_window           (EphyShell *shell);
 
+GtkWidget       *ephy_shell_get_sync_window              (EphyShell *shell);
+
 GObject         *ephy_shell_get_prefs_dialog             (EphyShell *shell);
 
 guint           ephy_shell_get_n_windows                (EphyShell *shell);
diff --git a/src/ephy-sync-window.c b/src/ephy-sync-window.c
new file mode 100644
index 0000000..b7f76b9
--- /dev/null
+++ b/src/ephy-sync-window.c
@@ -0,0 +1,92 @@
+#include "ephy-sync-window.h"
+#include "ephy-gui.h"
+
+#include <gtk/gtk.h>
+
+struct _EphySyncWindow {
+  GtkDialog parent_instance;
+
+  GCancellable *cancellable;
+
+  GtkWidget *entry_email;
+  GtkWidget *entry_password;
+  GtkButton *btn_submit;
+
+  GActionGroup *action_group;
+
+  // TODO: Add sync service instance
+};
+
+G_DEFINE_TYPE (EphySyncWindow, ephy_sync_window, GTK_TYPE_DIALOG)
+
+static void
+quickstretch (GSimpleAction *action,
+              GVariant      *parameter,
+              gpointer       user_data)
+{
+  EphySyncWindow *self = EPHY_SYNC_WINDOW (user_data);
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+
+  printf("email:%s\n", gtk_entry_get_text (GTK_ENTRY (self->entry_email)));
+  printf("password:%s\n", gtk_entry_get_text (GTK_ENTRY (self->entry_password)));
+}
+
+static GActionGroup *
+create_action_group (EphySyncWindow *self)
+{
+  GSimpleActionGroup *group;
+
+  const GActionEntry entries[] = {
+    { "quickstretch", quickstretch }
+  };
+
+  group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (group), entries, G_N_ELEMENTS (entries), self);
+
+  return G_ACTION_GROUP (group);
+}
+
+static void
+ephy_sync_window_class_init (EphySyncWindowClass *klass)
+{
+  // GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+
+  gtk_widget_class_set_template_from_resource (widget_class,
+                                               "/org/gnome/epiphany/sync-dialog.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, EphySyncWindow, entry_email);
+  gtk_widget_class_bind_template_child (widget_class, EphySyncWindow, entry_password);
+  gtk_widget_class_bind_template_child (widget_class, EphySyncWindow, btn_submit);
+}
+
+static void
+ephy_sync_window_init (EphySyncWindow *self)
+{
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  self->cancellable = g_cancellable_new ();
+
+  ephy_gui_ensure_window_group (GTK_WINDOW (self));
+
+  self->action_group = create_action_group (self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "sync", self->action_group);
+}
+
+GtkWidget *
+ephy_sync_window_new (void)
+{
+  EphySyncWindow *self;
+
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+
+  self = g_object_new (EPHY_TYPE_SYNC_WINDOW,
+                       "use-header-bar", TRUE,
+                       NULL);
+
+  return GTK_WIDGET (self);
+}
diff --git a/src/ephy-sync-window.h b/src/ephy-sync-window.h
new file mode 100644
index 0000000..df72f91
--- /dev/null
+++ b/src/ephy-sync-window.h
@@ -0,0 +1,16 @@
+#ifndef EPHY_SYNC_WINDOW_H
+#define EPHY_SYNC_WINDOW_H
+
+#include <gtk/gtk.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);
+
+G_END_DECLS
+
+#endif
diff --git a/src/epiphany.gresource.xml b/src/epiphany.gresource.xml
index ca2086e..87d4f54 100644
--- a/src/epiphany.gresource.xml
+++ b/src/epiphany.gresource.xml
@@ -10,6 +10,7 @@
     <file preprocess="xml-stripblanks" compressed="true">clear-data-dialog.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">cookies-dialog.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">history-dialog.ui</file>
+    <file preprocess="xml-stripblanks" compressed="true">sync-dialog.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">passwords-dialog.ui</file>
     <file preprocess="xml-stripblanks">epiphany-application-menu.ui</file>
     <file preprocess="xml-stripblanks">epiphany-ui.xml</file>
diff --git a/src/resources/epiphany-application-menu.ui b/src/resources/epiphany-application-menu.ui
index e554ce0..e2154ac 100644
--- a/src/resources/epiphany-application-menu.ui
+++ b/src/resources/epiphany-application-menu.ui
@@ -29,6 +29,11 @@
         <attribute name="action">app.history</attribute>
         <attribute name="accel">&lt;Primary&gt;h</attribute>
       </item>
+      <item>
+        <attribute name="label" translatable="yes">_Sync</attribute>
+        <attribute name="action">app.sync</attribute>
+        <attribute name="accel">&lt;Primary&gt;s</attribute>
+      </item>
     </section>
     <section>
       <item>
diff --git a/src/resources/sync-dialog.ui b/src/resources/sync-dialog.ui
new file mode 100644
index 0000000..2e95416
--- /dev/null
+++ b/src/resources/sync-dialog.ui
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.10"/>
+
+  <template class="EphySyncWindow" parent="GtkDialog">
+    <property name="height_request">400</property>
+    <property name="modal">True</property>
+    <property name="window_position">center</property>
+    <property name="default_width">600</property>
+    <property name="default_height">400</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="headerbar">
+      <object class="GtkHeaderBar">
+        <property name="title" translatable="yes">Sync</property>
+        <property name="show-close-button">True</property>
+      </object>
+    </child>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog_vbox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkGrid" id="grid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">10</property>
+            <property name="row-spacing">6</property>
+            <property name="column-spacing">12</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="label" translatable="yes">Email</property>
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0.5</property>
+                <property name="yalign">0.5</property>
+                <property name="halign">start</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry_email">
+                <property name="visible">True</property>
+                <property name="max-length">64</property>
+                <property name="width_request">200</property>
+              </object>
+              <packing>
+                <property name="left-attach">1</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="label" translatable="yes">Password</property>
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0.5</property>
+                <property name="yalign">0.5</property>
+                <property name="halign">start</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry_password">
+                <property name="visible">True</property>
+                <property name="max-length">64</property>
+                <property name="width_request">200</property>
+                <property name="visibility">False</property>
+                <property name="caps-lock-warning">True</property>
+              </object>
+              <packing>
+                <property name="left-attach">1</property>
+                <property name="top-attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="btn_submit">
+                <property name="label" translatable="yes">_Stretch</property>
+                <property name="visible">True</property>
+                <property name="use-underline">True</property>
+                <property name="sensitive">True</property>
+                <property name="valign">center</property>
+                <property name="action-name">sync.quickstretch</property>
+                <style>
+                  <class name="suggested-action"/>
+                  <class name="text-button"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">2</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/window-commands.c b/src/window-commands.c
index be9744c..78bebf2 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1083,6 +1083,22 @@ window_cmd_edit_history (GtkAction  *action,
 }
 
 void
+window_cmd_edit_sync (GtkAction  *action,
+                      EphyWindow *window)
+{
+  GtkWidget *swindow;
+
+  printf ("[%s:%d, %s]\n", __FILE__, __LINE__, __func__);
+
+  swindow = ephy_shell_get_sync_window (ephy_shell_get_default ());
+
+  if (GTK_WINDOW (window) != gtk_window_get_transient_for (GTK_WINDOW (swindow)))
+    gtk_window_set_transient_for (GTK_WINDOW (swindow),
+                                  GTK_WINDOW (window));
+  gtk_window_present (GTK_WINDOW (swindow));
+}
+
+void
 window_cmd_edit_preferences (GtkAction  *action,
                              EphyWindow *window)
 {
diff --git a/src/window-commands.h b/src/window-commands.h
index 1db5a47..c7e2964 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -104,6 +104,8 @@ void window_cmd_edit_bookmarks            (GtkAction  *action,
                                            EphyWindow *window);
 void window_cmd_edit_history              (GtkAction  *action,
                                            EphyWindow *window);
+void window_cmd_edit_sync                 (GtkAction  *action,
+                                           EphyWindow *window);
 void window_cmd_file_new_window           (GtkAction  *action,
                                            EphyWindow *window);
 void window_cmd_file_new_incognito_window (GtkAction  *action,


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