[epiphany/wip/ephy-sync: 77/116] Discard sync window and add a new tab in the preferences dialog



commit 5d6e88d145ea1ac0f9fd4085dcd8ed71086502be
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Thu Jun 23 18:39:05 2016 +0300

    Discard sync window and add a new tab in the preferences dialog

 src/Makefile.am                            |    2 -
 src/ephy-shell.c                           |   36 -----
 src/ephy-shell.h                           |    2 -
 src/ephy-sync-window.c                     |  216 ----------------------------
 src/ephy-sync-window.h                     |   36 -----
 src/epiphany.gresource.xml                 |    1 -
 src/prefs-dialog.c                         |  145 +++++++++++++++++++
 src/resources/epiphany-application-menu.ui |    5 -
 src/resources/prefs-dialog.ui              |  194 +++++++++++++++++++++++++
 src/resources/sync-dialog.ui               |  131 -----------------
 src/window-commands.c                      |   16 --
 src/window-commands.h                      |    2 -
 12 files changed, 339 insertions(+), 447 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a523cda..48f5f5f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -77,8 +77,6 @@ libephymain_la_SOURCES = \
        ephy-sync-service.h                     \
        ephy-sync-utils.c                       \
        ephy-sync-utils.h                       \
-       ephy-sync-window.c                      \
-       ephy-sync-window.h                      \
        ephy-title-box.c                        \
        ephy-title-box.h                        \
        ephy-toolbar.c                          \
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 5ee4be4..7b4f401 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -30,7 +30,6 @@
 #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"
@@ -58,7 +57,6 @@ struct _EphyShell {
   GNetworkMonitor *network_monitor;
   GtkWidget *bme;
   GtkWidget *history_window;
-  GtkWidget *sync_window;
   GObject *prefs_dialog;
   EphyShellStartupContext *local_startup_context;
   EphyShellStartupContext *remote_startup_context;
@@ -186,20 +184,6 @@ show_history (GSimpleAction *action,
 }
 
 static void
-show_sync (GSimpleAction *action,
-           GVariant      *parameter,
-           gpointer      user_data)
-{
-  GtkWindow *window;
-
-LOG ("%s:%d", __func__, __LINE__);
-
-  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)
@@ -260,7 +244,6 @@ 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 },
@@ -856,25 +839,6 @@ ephy_shell_get_history_window (EphyShell *shell)
   return shell->history_window;
 }
 
-GtkWidget *
-ephy_shell_get_sync_window (EphyShell *shell)
-{
-  EphySyncService *sync_service;
-
-  if (shell->sync_window == NULL) {
-LOG ("%s:%d", __func__, __LINE__);
-    sync_service = ephy_shell_get_global_sync_service ();
-    shell->sync_window = ephy_sync_window_new (sync_service);
-    g_signal_connect (shell->sync_window,
-                      "destroy",
-                      G_CALLBACK (gtk_widget_destroyed),
-                      &shell->sync_window);
-  }
-
-LOG ("%s:%d", __func__, __LINE__);
-  return shell->sync_window;
-}
-
 /**
  * ephy_shell_get_prefs_dialog:
  *
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index 8485d87..77079ac 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -110,8 +110,6 @@ EphySyncService *ephy_shell_get_global_sync_service      (void);
 
 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/epiphany.gresource.xml b/src/epiphany.gresource.xml
index ee761b9..f8012c7 100644
--- a/src/epiphany.gresource.xml
+++ b/src/epiphany.gresource.xml
@@ -10,7 +10,6 @@
     <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/prefs-dialog.c b/src/prefs-dialog.c
index f4ab10e..c25455a 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -95,6 +95,20 @@ struct _PrefsDialog {
 
   GHashTable *iso_639_table;
   GHashTable *iso_3166_table;
+
+  /* sync */
+  GtkWidget *sync_top_box;
+  GtkWidget *sync_authenticate_box;
+  GtkWidget *sync_login_grid;
+  GtkWidget *sync_logout_box;
+  GtkWidget *sync_email_entry;
+  GtkWidget *sync_password_entry;
+  GtkWidget *sync_login_button;
+  GtkWidget *sync_logout_button;
+  GtkWidget *sync_logout_details_label;
+  GtkWidget *sync_email_details_label;
+  GtkWidget *sync_password_details_label;
+  GtkWidget *sync_extra_details_label;
 };
 
 enum {
@@ -152,6 +166,72 @@ on_manage_passwords_button_clicked (GtkWidget   *button,
 }
 
 static void
+on_sync_login_button_clicked (GtkWidget   *button,
+                              PrefsDialog *dialog)
+{
+  const gchar *emailUTF8;
+  const gchar *passwordUTF8;
+
+  gtk_label_set_markup (GTK_LABEL (dialog->sync_email_details_label), NULL);
+  gtk_label_set_markup (GTK_LABEL (dialog->sync_password_details_label), NULL);
+  gtk_label_set_markup (GTK_LABEL (dialog->sync_extra_details_label), NULL);
+
+  emailUTF8 = gtk_entry_get_text (GTK_ENTRY (dialog->sync_email_entry));
+  passwordUTF8 = gtk_entry_get_text (GTK_ENTRY (dialog->sync_password_entry));
+
+  if (emailUTF8 && !emailUTF8[0]) {
+    gtk_label_set_markup (GTK_LABEL (dialog->sync_email_details_label),
+                          _("<span fgcolor='#e6780b'>Please insert your email</span>"));
+LOG ("[%d] empty email field", __LINE__);
+    return;
+  }
+
+  if (passwordUTF8 && !passwordUTF8[0]) {
+    gtk_label_set_markup (GTK_LABEL (dialog->sync_password_details_label),
+                          _("<span fgcolor='#e6780b'>Please insert your password</span>"));
+LOG ("[%d] empty password field", __LINE__);
+    return;
+  }
+
+LOG ("[%d] email: %s", __LINE__, emailUTF8);
+LOG ("[%d] password: %s", __LINE__, passwordUTF8);
+
+  /* TODO: Call /account/login endpoint and handle server response */
+
+  g_settings_set_string (EPHY_SETTINGS_MAIN,
+                         EPHY_PREFS_SYNC_USER,
+                         emailUTF8);
+  /* Translators: the %s refers to the email of the currently logged in user. */
+  gtk_label_set_markup (GTK_LABEL (dialog->sync_logout_details_label),
+                        g_strdup_printf (_("Currently logged in as <b>%s</b>"), emailUTF8));
+  gtk_container_remove (GTK_CONTAINER (dialog->sync_authenticate_box),
+                        dialog->sync_login_grid);
+  gtk_box_pack_start (GTK_BOX (dialog->sync_authenticate_box),
+                      dialog->sync_logout_box,
+                      TRUE, TRUE, 0);
+}
+
+static void
+on_sync_logout_button_clicked (GtkWidget   *button,
+                               PrefsDialog *dialog)
+{
+  gtk_entry_set_text (GTK_ENTRY (dialog->sync_email_entry), "");
+  gtk_entry_set_text (GTK_ENTRY (dialog->sync_password_entry), "");
+
+  /* TODO: Call /session/destroy endpoint and forget tokens */
+
+  g_settings_set_string (EPHY_SETTINGS_MAIN,
+                         EPHY_PREFS_SYNC_USER,
+                         "");
+  gtk_container_remove (GTK_CONTAINER (dialog->sync_authenticate_box),
+                        dialog->sync_logout_box);
+  gtk_box_pack_start (GTK_BOX (dialog->sync_authenticate_box),
+                      dialog->sync_login_grid,
+                      TRUE, TRUE, 0);
+LOG ("[%d] logged out", __LINE__);
+}
+
+static void
 prefs_dialog_class_init (PrefsDialogClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -196,8 +276,24 @@ prefs_dialog_class_init (PrefsDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, lang_down_button);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, enable_spell_checking_checkbutton);
 
+  /* sync */
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_top_box);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_authenticate_box);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_login_grid);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_logout_box);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_email_entry);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_password_entry);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_login_button);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_logout_button);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_logout_details_label);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_email_details_label);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_password_details_label);
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_extra_details_label);
+
   gtk_widget_class_bind_template_callback (widget_class, on_manage_cookies_button_clicked);
   gtk_widget_class_bind_template_callback (widget_class, on_manage_passwords_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, on_sync_login_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, on_sync_logout_button_clicked);
 }
 
 static void
@@ -1227,6 +1323,54 @@ setup_language_page (PrefsDialog *dialog)
 }
 
 static void
+setup_sync_page (PrefsDialog *dialog)
+{
+  GtkWidget *sync_main_label;
+  GtkWidget *sync_secondary_label;
+  gchar *sync_user = NULL;
+  gboolean logged_in;
+
+  sync_main_label = gtk_label_new (NULL);
+  gtk_widget_set_visible (sync_main_label, TRUE);
+  gtk_widget_set_halign (sync_main_label, GTK_ALIGN_START);
+  gtk_label_set_markup (GTK_LABEL (sync_main_label),
+                        _("Log in with your "
+                          "<a href=\"https://www.mozilla.org/en-US/firefox/accounts/\"; "
+                          "title=\"Get a Firefox Account\">Firefox Account</a> "
+                          "and have your data synced across all your devices.\n"));
+
+  sync_secondary_label = gtk_label_new (NULL);
+  gtk_widget_set_visible (sync_secondary_label, TRUE);
+  gtk_widget_set_halign (sync_secondary_label, GTK_ALIGN_START);
+  gtk_label_set_markup (GTK_LABEL (sync_secondary_label),
+                        _("Note that you must own an <b>already verified account</b> "
+                          "to be able to login."));
+
+  gtk_box_pack_start (GTK_BOX (dialog->sync_top_box),
+                      sync_main_label,
+                      TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (dialog->sync_top_box),
+                      sync_secondary_label,
+                      TRUE, TRUE, 0);
+
+  sync_user = g_settings_get_string (EPHY_SETTINGS_MAIN, EPHY_PREFS_SYNC_USER);
+  logged_in = sync_user && sync_user[0];
+
+  if (logged_in) {
+LOG ("[%d] Setup sync page, already logged in as %s", __LINE__, sync_user);
+    gtk_container_remove (GTK_CONTAINER (dialog->sync_authenticate_box),
+                          dialog->sync_login_grid);
+    /* Translators: the %s refers to the email of the currently logged in user. */
+    gtk_label_set_markup (GTK_LABEL (dialog->sync_logout_details_label),
+                          g_strdup_printf (_("Currently logged in as <b>%s</b>"), sync_user));
+  } else {
+LOG ("[%d] Setup sync page, not logged in", __LINE__);
+    gtk_container_remove (GTK_CONTAINER (dialog->sync_authenticate_box),
+                          dialog->sync_logout_box);
+  }
+}
+
+static void
 prefs_dialog_init (PrefsDialog *dialog)
 {
   gtk_widget_init_template (GTK_WIDGET (dialog));
@@ -1235,6 +1379,7 @@ prefs_dialog_init (PrefsDialog *dialog)
   setup_fonts_page (dialog);
   setup_privacy_page (dialog);
   setup_language_page (dialog);
+  setup_sync_page (dialog);
 
   ephy_gui_ensure_window_group (GTK_WINDOW (dialog));
   g_signal_connect (dialog, "response",
diff --git a/src/resources/epiphany-application-menu.ui b/src/resources/epiphany-application-menu.ui
index c839232..bb0da59 100644
--- a/src/resources/epiphany-application-menu.ui
+++ b/src/resources/epiphany-application-menu.ui
@@ -29,11 +29,6 @@
         <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/prefs-dialog.ui b/src/resources/prefs-dialog.ui
index 710b983..b035cbf 100644
--- a/src/resources/prefs-dialog.ui
+++ b/src/resources/prefs-dialog.ui
@@ -732,6 +732,200 @@
                 <property name="tab_fill">False</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="border-width">12</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">18</property>
+                <child>
+                  <object class="GtkBox">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">18</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">True</property>
+                            <property name="halign">start</property>
+                            <property name="label" translatable="yes">Sync</property>
+                            <attributes>
+                              <attribute name="weight" value="bold"/>
+                            </attributes>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkBox" id="sync_top_box">
+                            <property name="visible">True</property>
+                            <property name="orientation">vertical</property>
+                            <property name="spacing">0</property>
+                            <property name="margin-start">12</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkBox">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">18</property>
+                    <child>
+                      <object class="GtkBox" id="sync_authenticate_box">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">True</property>
+                            <property name="halign">start</property>
+                            <property name="label" translatable="yes">Authenticate</property>
+                            <attributes>
+                              <attribute name="weight" value="bold"/>
+                            </attributes>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkGrid" id="sync_login_grid">
+                            <property name="visible">True</property>
+                            <property name="margin-start">12</property>
+                            <property name="row-spacing">6</property>
+                            <property name="column-spacing">12</property>
+                            <child>
+                              <object class="GtkEntry" id="sync_email_entry">
+                                <property name="visible">True</property>
+                                <property name="halign">start</property>
+                                <property name="max-length">80</property>
+                                <property name="width_request">230</property>
+                                <property name="activates-default">True</property>
+                                <property name="placeholder-text">Email</property>
+                              </object>
+                              <packing>
+                                <property name="left-attach">0</property>
+                                <property name="top-attach">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="sync_email_details_label">
+                                <property name="visible">True</property>
+                                <property name="halign">start</property>
+                                <property name="use-markup">True</property>
+                                <property name="label" translatable="yes"></property>
+                              </object>
+                              <packing>
+                                <property name="left-attach">1</property>
+                                <property name="top-attach">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkEntry" id="sync_password_entry">
+                                <property name="visible">True</property>
+                                <property name="halign">start</property>
+                                <property name="max-length">80</property>
+                                <property name="width_request">230</property>
+                                <property name="activates-default">True</property>
+                                <property name="visibility">False</property>
+                                <property name="caps-lock-warning">True</property>
+                                <property name="placeholder-text">Password</property>
+                              </object>
+                              <packing>
+                                <property name="left-attach">0</property>
+                                <property name="top-attach">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="sync_password_details_label">
+                                <property name="visible">True</property>
+                                <property name="halign">start</property>
+                                <property name="use-markup">True</property>
+                                <property name="label" translatable="yes"></property>
+                              </object>
+                              <packing>
+                                <property name="left-attach">1</property>
+                                <property name="top-attach">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="sync_login_button">
+                                <property name="label" translatable="yes">_Login</property>
+                                <property name="visible">True</property>
+                                <property name="use-underline">True</property>
+                                <property name="halign">start</property>
+                                <property name="width-request">100</property>
+                                <signal name="clicked" handler="on_sync_login_button_clicked"/>
+                                <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>
+                            <child>
+                              <object class="GtkLabel" id="sync_extra_details_label">
+                                <property name="visible">True</property>
+                                <property name="halign">start</property>
+                                <property name="use-markup">True</property>
+                                <property name="label" translatable="yes"></property>
+                              </object>
+                              <packing>
+                                <property name="left-attach">0</property>
+                                <property name="top-attach">3</property>
+                              </packing>
+                            </child>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkBox" id="sync_logout_box">
+                            <property name="visible">True</property>
+                            <property name="orientation">vertical</property>
+                            <property name="spacing">12</property>
+                            <property name="margin-start">12</property>
+                            <child>
+                              <object class="GtkLabel" id="sync_logout_details_label">
+                                <property name="visible">True</property>
+                                <property name="halign">start</property>
+                                <property name="label" translatable="yes"></property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="sync_logout_button">
+                                <property name="label" translatable="yes">Lo_gout</property>
+                                <property name="visible">True</property>
+                                <property name="use-underline">True</property>
+                                <property name="halign">start</property>
+                                <property name="width-request">100</property>
+                                <signal name="clicked" handler="on_sync_logout_button_clicked"/>
+                                <style>
+                                  <class name="destructive-action"/>
+                                  <class name="text-button"/>
+                                </style>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Sync</property>
+              </object>
+              <packing>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">True</property>
diff --git a/src/window-commands.c b/src/window-commands.c
index cf16fcc..6b14b7e 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1334,22 +1334,6 @@ window_cmd_zoom_in (GSimpleAction *action,
 }
 
 void
-window_cmd_edit_sync (GtkAction  *action,
-                      EphyWindow *window)
-{
-  GtkWidget *swindow;
-
-LOG ("%s:%d", __func__, __LINE__);
-
-  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 6a6930d..c4aaf64 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -177,8 +177,6 @@ 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
 


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