From a4353d08015354898b7c53c494d969875e28c23a Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 4 Nov 2010 23:29:34 -0400 Subject: [PATCH] UpHistory: Add method to set history dir Add up_history_set_directory() method to change the directory for history files. This is mainly useful for our test suite. --- src/up-history.c | 14 +++++++++++++- src/up-history.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/up-history.c b/src/up-history.c index eebbe44..24f9672 100644 --- a/src/up-history.c +++ b/src/up-history.c @@ -53,6 +53,7 @@ struct UpHistoryPrivate GPtrArray *data_time_empty; guint save_id; guint max_data_age; + gchar *dir; }; enum { @@ -394,11 +395,21 @@ up_history_get_filename (UpHistory *history, const gchar *type) gchar *filename; filename = g_strdup_printf ("history-%s-%s.dat", type, history->priv->id); - path = g_build_filename (PACKAGE_LOCALSTATE_DIR, "lib", "upower", filename, NULL); + path = g_build_filename (history->priv->dir, filename, NULL); g_free (filename); return path; } +/** + * up_history_set_directory: + **/ +void +up_history_set_directory (UpHistory *history, const gchar *dir) +{ + g_free (history->priv->dir); + history->priv->dir = g_strdup (dir); +} + /** * up_history_array_to_file: * @list: a valid #GPtrArray instance @@ -877,6 +888,7 @@ up_history_init (UpHistory *history) history->priv->data_time_empty = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); history->priv->save_id = 0; history->priv->max_data_age = UP_HISTORY_DEFAULT_MAX_DATA_AGE; + history->priv->dir = g_build_filename (PACKAGE_LOCALSTATE_DIR, "lib", "upower", NULL); } /** diff --git a/src/up-history.h b/src/up-history.h index 50b506d..87af5e3 100644 --- a/src/up-history.h +++ b/src/up-history.h @@ -84,6 +84,9 @@ void up_history_set_max_data_age (UpHistory *history, guint max_data_age); gboolean up_history_save_data (UpHistory *history); +void up_history_set_directory (UpHistory *history, + const gchar *dir); + G_END_DECLS #endif /* __UP_HISTORY_H */