[epiphany/wip/ephy-sync: 12/86] Add basic sync window



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

    Add basic sync window

 src/Makefile.am                            |    2 +
 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                      |    3 +
 10 files changed, 288 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 660ed41..183d77b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -55,6 +55,8 @@ libephymain_la_SOURCES = \
        ephy-encoding-row.h                     \
        ephy-history-window.c                   \
        ephy-history-window.h                   \
+       ephy-sync-window.c                      \
+       ephy-sync-window.h                      \
        ephy-link.c                             \
        ephy-link.h                             \
        ephy-location-controller.c              \
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 7c51744..6c837de 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-lockdown.h"
 #include "ephy-prefs.h"
 #include "ephy-private.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)
@@ -243,6 +259,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 },
   { "shortcuts", show_shortcuts, NULL, NULL, NULL },
   { "help", show_help, NULL, NULL, NULL },
@@ -822,6 +839,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 9ce4487..b0fe6fa 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -107,6 +107,8 @@ EphyBookmarksManager *ephy_shell_get_bookmarks_manager   (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 f8012c7..ee761b9 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" compressed="true">shortcuts-dialog.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">gtk/bookmark-properties-grid.ui</file>
diff --git a/src/resources/epiphany-application-menu.ui b/src/resources/epiphany-application-menu.ui
index bb0da59..c839232 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 6b14b7e..447d734 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1334,6 +1334,22 @@ window_cmd_zoom_in (GSimpleAction *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_zoom_out (GSimpleAction *action,
                      GVariant      *parameter,
                      gpointer       user_data)
diff --git a/src/window-commands.h b/src/window-commands.h
index deaaa4c..6a6930d 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -177,6 +177,9 @@ void window_cmd_tabs_detach                     (GSimpleAction *action,
 void window_cmd_tabs_close                      (GSimpleAction *action,
                                                  GVariant      *parameter,
                                                  gpointer       user_data);
+void window_cmd_edit_sync                 (GtkAction  *action,
+                                           EphyWindow *window);
+
 G_END_DECLS
 
 #endif


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