[gnome-software] Move the install and check timeouts to GSettings schema
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Move the install and check timeouts to GSettings schema
- Date: Mon, 11 Nov 2013 10:27:24 +0000 (UTC)
commit a867c92a8203c20a572888e9cafadfbfd126a0ae
Author: Richard Hughes <richard hughsie com>
Date: Mon Nov 11 10:00:06 2013 +0000
Move the install and check timeouts to GSettings schema
I've done this for three reasons:
* We already documented how to force notifications for Fedora QA
* Sometimes g_ascii_strtoll() is failing for valid input
* It's not nice to write random files without some kind of schema
data/org.gnome.software.gschema.xml | 8 +++++
src/gs-offline-updates.c | 6 +++-
src/gs-update-monitor.c | 22 +++++++++++--
src/gs-utils.c | 54 -----------------------------------
src/gs-utils.h | 3 --
5 files changed, 31 insertions(+), 62 deletions(-)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index a017386..e182d99 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -10,5 +10,13 @@
<summary>Applications require AppData to be shown in the search results</summary>
<description>If enabled applications require a long description before they are shown to the user in
the search results.</description>
</key>
+ <key name="check-timestamp" type="x">
+ <default>0</default>
+ <summary>The last update check timestamp</summary>
+ </key>
+ <key name="install-timestamp" type="x">
+ <default>0</default>
+ <summary>The last update timestamp</summary>
+ </key>
</schema>
</schemalist>
diff --git a/src/gs-offline-updates.c b/src/gs-offline-updates.c
index bfbc763..0fa0dd8 100644
--- a/src/gs-offline-updates.c
+++ b/src/gs-offline-updates.c
@@ -63,6 +63,7 @@ gs_offline_updates_trigger (void)
GError *error = NULL;
const gchar *argv[3];
GDateTime *now;
+ GSettings *settings;
argv[0] = "pkexec";
argv[1] = LIBEXECDIR "/pk-trigger-offline-update";
@@ -80,8 +81,11 @@ gs_offline_updates_trigger (void)
}
now = g_date_time_new_now_local ();
- gs_save_timestamp_to_file ("install-timestamp", now);
+ settings = g_settings_new ("org.gnome.software");
+ g_settings_set (settings, "install-timestamp", "x",
+ g_date_time_to_unix (now));
g_date_time_unref (now);
+ g_object_unref (settings);
}
void
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index dad1cc0..4380b9b 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -46,6 +46,7 @@ struct _GsUpdateMonitor {
gchar **pending_downloads;
PkTask *task;
PkControl *control;
+ GSettings *settings;
GFile *offline_update_file;
GFileMonitor *offline_update_monitor;
@@ -203,11 +204,18 @@ no_updates_for_a_week (GsUpdateMonitor *monitor)
GDateTime *last_update;
GDateTime *now;
GTimeSpan d;
+ gint64 tmp;
- last_update = gs_read_timestamp_from_file ("install-timestamp");
- if (!last_update)
+ g_settings_get (monitor->settings, "install-timestamp", "x", &tmp);
+ if (tmp == 0)
return TRUE;
+ last_update = g_date_time_new_from_unix_local (tmp);
+ if (last_update == NULL) {
+ g_warning ("failed to set timestamp %" G_GINT64_FORMAT, tmp);
+ return TRUE;
+ }
+
now = g_date_time_new_now_local ();
d = g_date_time_difference (now, last_update);
g_date_time_unref (last_update);
@@ -443,7 +451,8 @@ check_hourly_cb (gpointer data)
g_debug ("Daily update check due");
monitor->check_timestamp = g_date_time_new_now_local ();
- gs_save_timestamp_to_file ("check-timestamp", monitor->check_timestamp);
+ g_settings_set (monitor->settings, "check-timestamp", "x",
+ g_date_time_to_unix (monitor->check_timestamp));
monitor->refresh_cache_due = TRUE;
monitor->get_updates_due = TRUE;
@@ -481,12 +490,16 @@ notify_network_state_cb (PkControl *control,
static void
gs_update_monitor_init (GsUpdateMonitor *monitor)
{
+ gint64 tmp;
+
monitor->check_offline_update_id =
g_timeout_add_seconds (15, check_offline_update_cb, monitor);
g_source_set_name_by_id (monitor->check_offline_update_id,
"[gnome-software] check_offline_update_cb");
- monitor->check_timestamp = gs_read_timestamp_from_file ("check-timestamp");
+ monitor->settings = g_settings_new ("org.gnome.software");
+ g_settings_get (monitor->settings, "check-timestamp", "x", &tmp);
+ monitor->check_timestamp = g_date_time_new_from_unix_local (tmp);
monitor->check_hourly_id =
g_timeout_add_seconds (3600, check_hourly_cb, monitor);
@@ -534,6 +547,7 @@ gs_update_monitor_finalize (GObject *object)
g_clear_object (&monitor->control);
g_clear_object (&monitor->offline_update_file);
g_clear_object (&monitor->offline_update_monitor);
+ g_clear_object (&monitor->settings);
g_application_release (monitor->application);
G_OBJECT_CLASS (gs_update_monitor_parent_class)->finalize (object);
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 6b9dc60..4b1af7e 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -340,58 +340,4 @@ gs_reboot (GCallback reboot_failed)
g_object_unref (bus);
}
-GDateTime *
-gs_read_timestamp_from_file (const gchar *name)
-{
- gchar *file;
- gchar *contents;
- GDateTime *result;
-
- result = NULL;
- file = g_build_filename (g_get_user_data_dir (),
- "gnome-software", name, NULL);
- if (g_file_get_contents (file, &contents, NULL, NULL)) {
- gint64 timestamp;
- gchar *endptr = NULL;
-
- timestamp = g_ascii_strtoll (contents, &endptr, 0);
- if (endptr) {
- g_warning ("Could not read %s timestamp: %s", name, contents);
- } else {
- result = g_date_time_new_from_unix_local (timestamp);
- }
- g_free (contents);
- }
- g_free (file);
-
- return result;
-}
-
-gboolean
-gs_save_timestamp_to_file (const gchar *name,
- GDateTime *date)
-{
- gchar *file;
- gchar *contents;
- gint64 timestamp;
- gboolean result;
- GError *error = NULL;
-
- result = TRUE;
- timestamp = g_date_time_to_unix (date);
- contents = g_strdup_printf ("%" G_GINT64_FORMAT, timestamp);
- file = g_build_filename (g_get_user_data_dir (),
- "gnome-software", name, NULL);
- if (!g_file_set_contents (file, contents, -1, &error)) {
- g_warning ("Could not save %s timestamp: %s",
- name, error->message);
- g_error_free (error);
- result = FALSE;
- }
- g_free (contents);
- g_free (file);
-
- return result;
-}
-
/* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 9fc36b8..ecfdd84 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -49,9 +49,6 @@ GdkPixbuf *gs_pixbuf_load (const gchar *icon_name,
guint icon_size,
GError **error);
void gs_reboot (GCallback reboot_failed);
-GDateTime *gs_read_timestamp_from_file (const gchar *name);
-gboolean gs_save_timestamp_to_file (const gchar *name,
- GDateTime *date);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]