[gnome-software] updates: Show the time we last checked for updates
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] updates: Show the time we last checked for updates
- Date: Tue, 11 Mar 2014 07:53:13 +0000 (UTC)
commit 4f4d04df3cf7cbceb31ce45e297930ee2e09d74e
Author: Kalev Lember <kalevlember gmail com>
Date: Mon Mar 3 13:17:54 2014 +0100
updates: Show the time we last checked for updates
This adds a label with 'Last checked: HH:MM' towards the bottom of the
"has no updates" page.
https://bugzilla.gnome.org/show_bug.cgi?id=725165
configure.ac | 1 +
src/Makefile.am | 1 +
src/gnome-software.ui | 42 +++++++++++++++-------
src/gs-shell-updates.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 122 insertions(+), 13 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a4cc64f..c62e81d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -78,6 +78,7 @@ PKG_CHECK_MODULES(SQLITE, sqlite3)
PKG_CHECK_MODULES(NOTIFY, libnotify)
PKG_CHECK_MODULES(SOUP, libsoup-2.4)
PKG_CHECK_MODULES(GSETTINGS_DESKTOP_SCHEMAS, gsettings-desktop-schemas >= 3.11.5)
+PKG_CHECK_MODULES(GNOME_DESKTOP, gnome-desktop-3.0)
AC_ARG_ENABLE(man,
[AS_HELP_STRING([--enable-man],
[generate man pages [default=auto]])],,
diff --git a/src/Makefile.am b/src/Makefile.am
index 258d59d..42ec26f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,7 @@ AM_CPPFLAGS = \
$(SOUP_CFLAGS) \
$(PACKAGEKIT_CFLAGS) \
$(NOTIFY_CFLAGS) \
+ $(GNOME_DESKTOP_CFLAGS) \
-DG_LOG_DOMAIN=\"Gs\" \
-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE \
-DGS_MODULESETDIR=\"$(datadir)/gnome-software/modulesets.d\" \
diff --git a/src/gnome-software.ui b/src/gnome-software.ui
index 1d58367..4fc826f 100644
--- a/src/gnome-software.ui
+++ b/src/gnome-software.ui
@@ -917,31 +917,47 @@
<object class="GtkBox" id="updates_uptodate_box">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="spacing">12</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
+ <property name="spacing">48</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<style>
<class name="dim-label"/>
</style>
- <child>
- <object class="GtkImage" id="image_updates">
+ <child type="center">
+ <object class="GtkBox" id="updates_uptodate_centerbox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="pixel_size">128</property>
- <property name="icon_name">object-select-symbolic</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkImage" id="image_updates">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="pixel_size">128</property>
+ <property name="icon_name">object-select-symbolic</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label10">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Software is up to date</property>
+ <attributes>
+ <attribute name="scale" value="1.4"/>
+ </attributes>
+ </object>
+ </child>
</object>
</child>
<child>
- <object class="GtkLabel" id="label10">
+ <object class="GtkLabel" id="label_updates_last_checked">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label" translatable="yes">Software is up to date</property>
- <attributes>
- <attribute name="scale" value="1.4"/>
- </attributes>
+ <property name="margin_bottom">32</property>
+ <property name="label">Last checked: HH:MM</property>
</object>
+ <packing>
+ <property name="pack_type">end</property>
+ </packing>
</child>
</object>
<packing>
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 2c596ae..c011a47 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -32,6 +32,8 @@
#include "gs-markdown.h"
#include "gs-update-dialog.h"
+#include <gdesktop-enums.h>
+#include <langinfo.h>
/* this isn't ideal, as PK should be abstracted away in a plugin, but
* GNetworkMonitor doesn't provide us with a connection type */
#include <packagekit-glib2/packagekit.h>
@@ -57,6 +59,8 @@ struct GsShellUpdatesPrivate
GtkBuilder *builder;
GCancellable *cancellable;
GCancellable *cancellable_refresh;
+ GSettings *settings;
+ GSettings *desktop_settings;
GtkListBox *list_box_updates;
gboolean cache_valid;
GsShell *shell;
@@ -64,6 +68,7 @@ struct GsShellUpdatesPrivate
PkControl *control;
GsShellUpdatesState state;
gboolean has_agreed_to_mobile_data;
+ gboolean ampm_available;
};
enum {
@@ -84,6 +89,68 @@ gs_shell_updates_invalidate (GsShellUpdates *shell_updates)
shell_updates->priv->cache_valid = FALSE;
}
+static GDateTime *
+time_next_midnight (void)
+{
+ GDateTime *now;
+ GDateTime *next_midnight;
+ GTimeSpan since_midnight;
+
+ now = g_date_time_new_now_local ();
+ since_midnight = g_date_time_get_hour (now) * G_TIME_SPAN_HOUR +
+ g_date_time_get_minute (now) * G_TIME_SPAN_MINUTE +
+ g_date_time_get_second (now) * G_TIME_SPAN_SECOND +
+ g_date_time_get_microsecond (now);
+ next_midnight = g_date_time_add (now, G_TIME_SPAN_DAY - since_midnight);
+ g_date_time_unref (now);
+
+ return next_midnight;
+}
+
+static gchar *
+gs_shell_updates_last_checked_time_string (GsShellUpdates *shell_updates)
+{
+ GsShellUpdatesPrivate *priv = shell_updates->priv;
+ GDesktopClockFormat clock_format;
+ GDateTime *last_checked;
+ GDateTime *midnight;
+ const gchar *format_string;
+ gchar *time_string;
+ gboolean use_24h_time;
+ gint64 tmp;
+ gint days_ago;
+
+ g_settings_get (priv->settings, "check-timestamp", "x", &tmp);
+ last_checked = g_date_time_new_from_unix_local (tmp);
+
+ midnight = time_next_midnight ();
+ days_ago = g_date_time_difference (midnight, last_checked) / G_TIME_SPAN_DAY;
+
+ clock_format = g_settings_get_enum (priv->desktop_settings, "clock-format");
+ use_24h_time = (clock_format == G_DESKTOP_CLOCK_FORMAT_24H || priv->ampm_available == FALSE);
+
+ if (days_ago < 1) { // today
+ if (use_24h_time) {
+ /* TRANSLATORS: Time in 24h format */
+ format_string = _("%R");
+ } else {
+ /* TRANSLATORS: Time in 12h format */
+ format_string = _("%l:%M %p");
+ }
+ } else {
+ /* TRANSLATORS: This is the date string with: day number, month name, year.
+ i.e. "25 May 2012" */
+ format_string = _("%e %B %Y");
+ }
+
+ time_string = g_date_time_format (last_checked, format_string);
+
+ g_date_time_unref (last_checked);
+ g_date_time_unref (midnight);
+
+ return time_string;
+}
+
/**
* gs_shell_updates_update_ui_state:
**/
@@ -256,6 +323,20 @@ gs_shell_updates_update_ui_state (GsShellUpdates *shell_updates)
g_assert_not_reached ();
break;
}
+
+ /* last checked label */
+ if (g_strcmp0 (gtk_stack_get_visible_child_name (GTK_STACK (widget)), "uptodate") == 0) {
+ gchar *last_checked;
+
+ tmp = gs_shell_updates_last_checked_time_string (shell_updates);
+ /* TRANSLATORS: This is the time when we last checked for updates */
+ last_checked = g_strdup_printf (_("Last checked: %s"), tmp);
+ g_free (tmp);
+
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_updates_last_checked"));
+ gtk_label_set_label (GTK_LABEL (widget), last_checked);
+ g_free (last_checked);
+ }
}
/**
@@ -932,10 +1013,18 @@ gs_shell_updates_class_init (GsShellUpdatesClass *klass)
static void
gs_shell_updates_init (GsShellUpdates *shell_updates)
{
+ const char *ampm;
+
shell_updates->priv = GS_SHELL_UPDATES_GET_PRIVATE (shell_updates);
shell_updates->priv->control = pk_control_new ();
shell_updates->priv->cancellable_refresh = g_cancellable_new ();
shell_updates->priv->state = GS_SHELL_UPDATES_STATE_STARTUP;
+ shell_updates->priv->settings = g_settings_new ("org.gnome.software");
+ shell_updates->priv->desktop_settings = g_settings_new ("org.gnome.desktop.interface");
+
+ ampm = nl_langinfo (AM_STR);
+ if (ampm != NULL && *ampm != '\0')
+ shell_updates->priv->ampm_available = TRUE;
}
/**
@@ -954,6 +1043,8 @@ gs_shell_updates_finalize (GObject *object)
g_object_unref (priv->plugin_loader);
g_object_unref (priv->cancellable);
g_object_unref (priv->control);
+ g_object_unref (priv->settings);
+ g_object_unref (priv->desktop_settings);
G_OBJECT_CLASS (gs_shell_updates_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]