[gnome-software] Define and use a cleanup function for GDateTime
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Define and use a cleanup function for GDateTime
- Date: Sun, 15 Mar 2015 21:46:41 +0000 (UTC)
commit 5c8a68c05ee3ddb3e4945772648a927001c5a8bb
Author: Kalev Lember <kalevlember gmail com>
Date: Sun Mar 15 22:30:19 2015 +0100
Define and use a cleanup function for GDateTime
src/gs-cleanup.h | 2 ++
src/gs-history-dialog.c | 3 +--
src/gs-plugin.c | 3 +--
src/gs-shell-details.c | 3 +--
src/gs-shell-overview.c | 3 +--
src/gs-shell-updates.c | 13 ++++---------
src/gs-update-dialog.c | 3 +--
src/gs-update-monitor.c | 9 +++------
8 files changed, 14 insertions(+), 25 deletions(-)
---
diff --git a/src/gs-cleanup.h b/src/gs-cleanup.h
index 8c5f05b..461c871 100644
--- a/src/gs-cleanup.h
+++ b/src/gs-cleanup.h
@@ -50,6 +50,7 @@ G_BEGIN_DECLS
GS_DEFINE_CLEANUP_FUNCTION0(GArray*, gs_local_array_unref, g_array_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GBytes*, gs_local_bytes_unref, g_bytes_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GChecksum*, gs_local_checksum_free, g_checksum_free)
+GS_DEFINE_CLEANUP_FUNCTION0(GDateTime*, gs_local_date_time_unref, g_date_time_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GDir*, gs_local_dir_close, g_dir_close)
GS_DEFINE_CLEANUP_FUNCTION0(GError*, gs_local_free_error, g_error_free)
GS_DEFINE_CLEANUP_FUNCTION0(GHashTable*, gs_local_hashtable_unref, g_hash_table_unref)
@@ -73,6 +74,7 @@ GS_DEFINE_CLEANUP_FUNCTION(void*, gs_local_free, g_free)
#define _cleanup_timer_destroy_ __attribute__ ((cleanup(gs_local_destroy_timer)))
#define _cleanup_free_ __attribute__ ((cleanup(gs_local_free)))
#define _cleanup_checksum_free_ __attribute__ ((cleanup(gs_local_checksum_free)))
+#define _cleanup_date_time_unref_ __attribute__ ((cleanup(gs_local_date_time_unref)))
#define _cleanup_error_free_ __attribute__ ((cleanup(gs_local_free_error)))
#define _cleanup_list_free_ __attribute__ ((cleanup(gs_local_free_list)))
#define _cleanup_plugin_list_free_ __attribute__ ((cleanup(gs_local_free_plugin_list)))
diff --git a/src/gs-history-dialog.c b/src/gs-history-dialog.c
index e66c5ab..bdd9e9d 100644
--- a/src/gs-history-dialog.c
+++ b/src/gs-history-dialog.c
@@ -58,7 +58,6 @@ gs_history_dialog_set_app (GsHistoryDialog *dialog, GsApp *app)
{
GsHistoryDialogPrivate *priv = gs_history_dialog_get_instance_private (dialog);
const gchar *tmp;
- GDateTime *datetime;
GPtrArray *history;
GtkBox *box;
GtkWidget *widget;
@@ -70,6 +69,7 @@ gs_history_dialog_set_app (GsHistoryDialog *dialog, GsApp *app)
history = gs_app_get_history (app);
g_ptr_array_sort (history, history_sort_cb);
for (i = 0; i < history->len; i++) {
+ _cleanup_date_time_unref_ GDateTime *datetime = NULL;
_cleanup_free_ gchar *date_str = NULL;
app = g_ptr_array_index (history, i);
box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
@@ -129,7 +129,6 @@ gs_history_dialog_set_app (GsHistoryDialog *dialog, GsApp *app)
NULL);
gtk_size_group_add_widget (priv->sizegroup_timestamp, widget);
gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
- g_date_time_unref (datetime);
/* add the version */
widget = gtk_label_new (gs_app_get_version (app));
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 5738e99..2448657 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -154,11 +154,11 @@ gs_plugin_list_randomize_cb (gconstpointer a, gconstpointer b, gpointer user_dat
void
gs_plugin_list_randomize (GList **list)
{
- GDateTime *date;
GList *l;
GRand *rand;
GsApp *app;
gchar sort_key[] = { '\0', '\0', '\0', '\0' };
+ _cleanup_date_time_unref_ GDateTime *date = NULL;
_cleanup_free_ gchar *key = NULL;
key = g_strdup_printf ("Plugin::sort-key[%p]", list);
@@ -178,7 +178,6 @@ gs_plugin_list_randomize (GList **list)
gs_app_set_metadata (app, key, NULL);
}
g_rand_free (rand);
- g_date_time_unref (date);
}
/**
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 6e58097..9a0c9ac 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -611,11 +611,10 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
/* TRANSLATORS: this is where the updated date is not known */
gtk_label_set_label (GTK_LABEL (priv->label_details_updated_value), C_("updated", "Never"));
} else {
- GDateTime *dt;
+ _cleanup_date_time_unref_ GDateTime *dt = NULL;
_cleanup_free_ gchar *updated_str = NULL;
dt = g_date_time_new_from_unix_utc (updated);
updated_str = g_date_time_format (dt, "%x");
- g_date_time_unref (dt);
gtk_label_set_label (GTK_LABEL (priv->label_details_updated_value), updated_str);
}
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index 12e95ad..edc5889 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -317,9 +317,9 @@ out:
static void
gs_shell_overview_load (GsShellOverview *shell_overview)
{
- GDateTime *date;
GsShellOverviewPrivate *priv = shell_overview->priv;
const gchar *category_of_day;
+ _cleanup_date_time_unref_ GDateTime *date = NULL;
priv->empty = TRUE;
@@ -349,7 +349,6 @@ gs_shell_overview_load (GsShellOverview *shell_overview)
g_assert_not_reached ();
break;
}
- g_date_time_unref (date);
if (!priv->loading_featured) {
priv->loading_featured = TRUE;
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 51407b1..fbd1e36 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -100,9 +100,9 @@ gs_shell_updates_invalidate (GsShellUpdates *shell_updates)
static GDateTime *
time_next_midnight (void)
{
- GDateTime *now;
GDateTime *next_midnight;
GTimeSpan since_midnight;
+ _cleanup_date_time_unref_ GDateTime *now = NULL;
now = g_date_time_new_now_local ();
since_midnight = g_date_time_get_hour (now) * G_TIME_SPAN_HOUR +
@@ -110,7 +110,6 @@ time_next_midnight (void)
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;
}
@@ -120,13 +119,13 @@ 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;
+ _cleanup_date_time_unref_ GDateTime *last_checked = NULL;
+ _cleanup_date_time_unref_ GDateTime *midnight = NULL;
g_settings_get (priv->settings, "check-timestamp", "x", &tmp);
if (tmp == 0)
@@ -179,9 +178,6 @@ gs_shell_updates_last_checked_time_string (GsShellUpdates *shell_updates)
time_string = g_date_time_format (last_checked, format_string);
- g_date_time_unref (last_checked);
- g_date_time_unref (midnight);
-
return time_string;
}
@@ -604,8 +600,8 @@ gs_shell_updates_refresh_cb (GsPluginLoader *plugin_loader,
GsShellUpdates *shell_updates)
{
gboolean ret;
- GDateTime *now;
GsShellUpdatesPrivate *priv = shell_updates->priv;
+ _cleanup_date_time_unref_ GDateTime *now = NULL;
_cleanup_error_free_ GError *error = NULL;
/* get the results */
@@ -642,7 +638,6 @@ gs_shell_updates_refresh_cb (GsPluginLoader *plugin_loader,
now = g_date_time_new_now_local ();
g_settings_set (priv->settings, "check-timestamp", "x",
g_date_time_to_unix (now));
- g_date_time_unref (now);
/* get the new list */
gs_shell_updates_invalidate (shell_updates);
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index ab6f08f..f13f97b 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -174,14 +174,13 @@ gs_update_dialog_show_installed_updates (GsUpdateDialog *dialog, GList *installe
time_updates_installed = pk_offline_get_results_mtime (NULL);
if (time_updates_installed > 0) {
- GDateTime *date;
GtkWidget *header;
+ _cleanup_date_time_unref_ GDateTime *date = NULL;
_cleanup_free_ gchar *date_str = NULL;
_cleanup_free_ gchar *subtitle = NULL;
date = g_date_time_new_from_unix_utc (time_updates_installed);
date_str = g_date_time_format (date, "%x");
- g_date_time_unref (date);
/* TRANSLATORS: this is the subtitle of the installed updates dialog window */
subtitle = g_strdup_printf (_("Installed on %s"), date_str);
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index 6c92620..d8eb763 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -214,10 +214,10 @@ has_important_updates (GPtrArray *packages)
static gboolean
no_updates_for_a_week (GsUpdateMonitor *monitor)
{
- GDateTime *last_update;
- GDateTime *now;
GTimeSpan d;
gint64 tmp;
+ _cleanup_date_time_unref_ GDateTime *last_update = NULL;
+ _cleanup_date_time_unref_ GDateTime *now = NULL;
g_settings_get (monitor->settings, "install-timestamp", "x", &tmp);
if (tmp == 0)
@@ -231,8 +231,6 @@ no_updates_for_a_week (GsUpdateMonitor *monitor)
now = g_date_time_new_now_local ();
d = g_date_time_difference (now, last_update);
- g_date_time_unref (last_update);
- g_date_time_unref (now);
if (d >= 7 * G_TIME_SPAN_DAY)
return TRUE;
@@ -412,15 +410,14 @@ check_updates (GsUpdateMonitor *monitor)
return;
if (monitor->check_timestamp != NULL) {
- GDateTime *now;
gint now_year, now_month, now_day, now_hour;
gint year, month, day;
+ _cleanup_date_time_unref_ GDateTime *now = NULL;
now = g_date_time_new_now_local ();
g_date_time_get_ymd (now, &now_year, &now_month, &now_day);
now_hour = g_date_time_get_hour (now);
- g_date_time_unref (now);
g_date_time_get_ymd (monitor->check_timestamp, &year, &month, &day);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]