[epiphany/wip/sync: 6/14] sync: Show the time of last sync in preferences dialog
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync: 6/14] sync: Show the time of last sync in preferences dialog
- Date: Sun, 18 Jun 2017 10:56:19 +0000 (UTC)
commit d9f2cde26227ffe250586cd150cda8a8ea4a1482
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Thu Jun 8 18:17:45 2017 +0300
sync: Show the time of last sync in preferences dialog
data/org.gnome.epiphany.gschema.xml | 5 +++++
lib/ephy-prefs.h | 1 +
lib/ephy-sync-utils.c | 13 +++++++++++++
lib/ephy-sync-utils.h | 3 +++
lib/sync/ephy-sync-service.c | 3 +++
src/prefs-dialog.c | 28 ++++++++++++++++++++++++++++
src/resources/gtk/prefs-dialog.ui | 12 ++++++++++++
7 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index f0ccddd..e415d90 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -277,6 +277,11 @@
<summary>Currently signed in sync user</summary>
<description>The email linked to the Firefox Account used to sync data with Mozilla’s
servers.</description>
</key>
+ <key type="x" name="sync-time">
+ <default>0</default>
+ <summary>Last sync timestamp</summary>
+ <description>The UNIX time at which last sync was made in seconds.</description>
+ </key>
<key type="s" name="sync-device-id">
<default>''</default>
<summary>Sync device ID</summary>
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index 6736296..9fafee4 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -153,6 +153,7 @@ static const char * const ephy_prefs_web_schema[] = {
#define EPHY_PREFS_SYNC_SCHEMA "org.gnome.Epiphany.sync"
#define EPHY_PREFS_SYNC_USER "sync-user"
+#define EPHY_PREFS_SYNC_TIME "sync-time"
#define EPHY_PREFS_SYNC_DEVICE_ID "sync-device-id"
#define EPHY_PREFS_SYNC_DEVICE_NAME "sync-device-name"
#define EPHY_PREFS_SYNC_FREQUENCY "sync-frequency"
diff --git a/lib/ephy-sync-utils.c b/lib/ephy-sync-utils.c
index bc4ff58..894d4b8 100644
--- a/lib/ephy-sync-utils.c
+++ b/lib/ephy-sync-utils.c
@@ -305,6 +305,19 @@ ephy_sync_utils_user_is_signed_in (void)
return FALSE;
}
+void
+ephy_sync_utils_set_sync_time (gint64 time)
+{
+ time = time > 0 ? time : 0;
+ g_settings_set_int64 (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_TIME, time);
+}
+
+gint64
+ephy_sync_utils_get_sync_time (void)
+{
+ return g_settings_get_int64 (EPHY_SETTINGS_SYNC, EPHY_PREFS_SYNC_TIME);
+}
+
guint
ephy_sync_utils_get_sync_frequency (void)
{
diff --git a/lib/ephy-sync-utils.h b/lib/ephy-sync-utils.h
index f741a91..34deea0 100644
--- a/lib/ephy-sync-utils.h
+++ b/lib/ephy-sync-utils.h
@@ -60,6 +60,9 @@ void ephy_sync_utils_set_sync_user (const char *user);
char *ephy_sync_utils_get_sync_user (void);
gboolean ephy_sync_utils_user_is_signed_in (void);
+void ephy_sync_utils_set_sync_time (gint64 time);
+gint64 ephy_sync_utils_get_sync_time (void);
+
guint ephy_sync_utils_get_sync_frequency (void);
gboolean ephy_sync_utils_sync_with_firefox (void);
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index af6bfef..9279f04 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -1368,6 +1368,8 @@ ephy_sync_service_sync (gpointer user_data)
for (GSList *l = self->managers; l && l->data; l = l->next)
ephy_sync_service_sync_collection (self, l->data, ++index == num_managers);
+ ephy_sync_utils_set_sync_time (g_get_real_time () / 1000000);
+
return G_SOURCE_CONTINUE;
}
@@ -2309,6 +2311,7 @@ ephy_sync_service_do_sign_out (EphySyncService *self)
ephy_sync_utils_set_bookmarks_sync_is_initial (TRUE);
ephy_sync_utils_set_passwords_sync_is_initial (TRUE);
ephy_sync_utils_set_history_sync_is_initial (TRUE);
+ ephy_sync_utils_set_sync_time (0);
}
void
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 607eb04..49b7019 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -40,6 +40,7 @@
#include "ephy-string.h"
#include "ephy-sync-service.h"
#include "ephy-sync-utils.h"
+#include "ephy-time-helpers.h"
#include "ephy-uri-tester-shared.h"
#include "clear-data-dialog.h"
#include "cookies-dialog.h"
@@ -138,6 +139,8 @@ struct _PrefsDialog {
GtkWidget *sync_device_name_change_button;
GtkWidget *sync_device_name_save_button;
GtkWidget *sync_device_name_cancel_button;
+ GtkWidget *sync_last_sync_time_box;
+ GtkWidget *sync_last_sync_time_label;
gboolean sync_was_signed_in;
WebKitWebView *fxa_web_view;
@@ -227,6 +230,26 @@ sync_with_firefox_toggled_cb (GtkToggleButton *button,
}
static void
+sync_set_last_sync_time (PrefsDialog *dialog)
+{
+ gint64 sync_time = ephy_sync_utils_get_sync_time ();
+
+ if (sync_time) {
+ char *time = ephy_time_helpers_utf_friendly_time (sync_time);
+ /* Translators: the %s refers to the time at which the last sync was made.
+ * For example: Today 04:34 PM, Sun 11:25 AM, May 31 06:41 PM.
+ */
+ char *text = g_strdup_printf (_("Last synchronized: %s"), time);
+
+ gtk_label_set_text (GTK_LABEL (dialog->sync_last_sync_time_label), text);
+ gtk_widget_set_visible (dialog->sync_last_sync_time_box, TRUE);
+
+ g_free (text);
+ g_free (time);
+ }
+}
+
+static void
sync_finished_cb (EphySyncService *service,
PrefsDialog *dialog)
{
@@ -234,6 +257,7 @@ sync_finished_cb (EphySyncService *service,
g_assert (EPHY_IS_PREFS_DIALOG (dialog));
gtk_widget_set_sensitive (dialog->sync_now_button, TRUE);
+ sync_set_last_sync_time (dialog);
}
static void
@@ -548,6 +572,7 @@ on_sync_sign_out_button_clicked (GtkWidget *button,
gtk_box_pack_start (GTK_BOX (dialog->sync_page_box),
dialog->sync_firefox_iframe_box,
FALSE, FALSE, 0);
+ gtk_widget_set_visible (dialog->sync_last_sync_time_box, FALSE);
dialog->sync_was_signed_in = FALSE;
}
@@ -734,6 +759,8 @@ prefs_dialog_class_init (PrefsDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_device_name_change_button);
gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_device_name_save_button);
gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_device_name_cancel_button);
+ gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_last_sync_time_box);
+ gtk_widget_class_bind_template_child (widget_class, PrefsDialog, sync_last_sync_time_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);
@@ -1765,6 +1792,7 @@ setup_sync_page (PrefsDialog *dialog)
/* Translators: the %s refers to the email of the currently logged in user. */
char *text = g_strdup_printf (_("Logged in as %s"), email);
+ sync_set_last_sync_time (dialog);
gtk_label_set_markup (GTK_LABEL (dialog->sync_firefox_account_label), text);
gtk_container_remove (GTK_CONTAINER (dialog->sync_page_box),
dialog->sync_firefox_iframe_box);
diff --git a/src/resources/gtk/prefs-dialog.ui b/src/resources/gtk/prefs-dialog.ui
index 2dd7ed8..ad606ea 100644
--- a/src/resources/gtk/prefs-dialog.ui
+++ b/src/resources/gtk/prefs-dialog.ui
@@ -1023,6 +1023,18 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkBox" id="sync_last_sync_time_box">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="sync_last_sync_time_label">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]