diff options
author | 2012-03-01 22:01:25 +0000 | |
---|---|---|
committer | 2012-03-01 22:01:25 +0000 | |
commit | b913f788267327228cb27ef1a1de7aa556b789c3 (patch) | |
tree | 8b678e4b011f163ce2d0c5b3673dc4e5901ae90b | |
parent | a8fed4cb21f81bc1ce539d679da42d03a912469f (diff) |
fix memory leak and improvement on the url comment patch, and add a completed at item to the general panel.
-rw-r--r-- | src/trg-cell-renderer-epoch.c | 14 | ||||
-rw-r--r-- | src/trg-general-panel.c | 33 | ||||
-rw-r--r-- | src/util.c | 16 | ||||
-rw-r--r-- | src/util.h | 1 |
4 files changed, 45 insertions, 19 deletions
diff --git a/src/trg-cell-renderer-epoch.c b/src/trg-cell-renderer-epoch.c index 5ed62c2..e16dd33 100644 --- a/src/trg-cell-renderer-epoch.c +++ b/src/trg-cell-renderer-epoch.c @@ -68,19 +68,9 @@ trg_cell_renderer_epoch_set_property(GObject * object, guint property_id, gint64 new_value = g_value_get_int64(value); if (priv->epoch_value != new_value) { if (new_value > 0) { -#if GLIB_CHECK_VERSION(2, 26, 00) - GDateTime *dt = g_date_time_new_from_unix_local(new_value); - gchar *timestring = g_date_time_format(dt, "%F %H:%M:%S"); - g_object_set(object, "text", timestring, NULL); + gchar *timestring = epoch_to_string(new_value); + g_object_set(object, "text", "", NULL); g_free(timestring); - g_date_time_unref(dt); -#else - time_t time_val = new_value; - char buf[64]; - struct tm *ts = localtime(&time_val); - strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); - g_object_set(object, "text", buf, NULL); -#endif } else { g_object_set(object, "text", "", NULL); } diff --git a/src/trg-general-panel.c b/src/trg-general-panel.c index 87ac72a..88c0545 100644 --- a/src/trg-general-panel.c +++ b/src/trg-general-panel.c @@ -59,6 +59,7 @@ struct _TrgGeneralPanelPrivate { GtkLabel *gen_down_rate_label; GtkLabel *gen_up_rate_label; GtkLabel *gen_ratio_label; + GtkLabel *gen_completedat_label; GtkLabel *gen_downloaddir_label; GtkLabel *gen_comment_label; GtkLabel *gen_error_label; @@ -82,6 +83,7 @@ void trg_general_panel_clear(TrgGeneralPanel * panel) gtk_label_clear(priv->gen_down_rate_label); gtk_label_clear(priv->gen_up_rate_label); gtk_label_clear(priv->gen_ratio_label); + gtk_label_clear(priv->gen_completedat_label); gtk_label_clear(priv->gen_downloaddir_label); gtk_label_clear(priv->gen_comment_label); gtk_label_clear(priv->gen_error_label); @@ -111,10 +113,10 @@ trg_general_panel_update(TrgGeneralPanel * panel, JsonObject * t, TrgGeneralPanelPrivate *priv; gchar buf[32]; gint sizeOfBuf; - gchar *statusString, *fullStatusString; + gchar *statusString, *fullStatusString, *completedAtString; const gchar *comment; const gchar *errorStr; - gint64 eta, uploaded, downloaded; + gint64 eta, uploaded, downloaded, completedAt; GtkLabel *keyLabel; gint64 seeders = 0, leechers = 0; @@ -151,6 +153,16 @@ trg_general_panel_update(TrgGeneralPanel * panel, JsonObject * t, gtk_label_set_text(GTK_LABEL(priv->gen_ratio_label), _("N/A")); } + completedAt = torrent_get_done_date(t); + if (completedAt > 0) + { + completedAtString = epoch_to_string(completedAt); + gtk_label_set_text(GTK_LABEL(priv->gen_completedat_label), completedAtString); + g_free(completedAtString); + } else { + gtk_label_set_text(GTK_LABEL(priv->gen_completedat_label), ""); + } + fullStatusString = g_strdup_printf("%s %s", statusString, torrent_get_is_private(t) ? _("(Private)") : _("(Public)")); @@ -169,12 +181,15 @@ trg_general_panel_update(TrgGeneralPanel * panel, JsonObject * t, torrent_get_download_dir(t)); comment = torrent_get_comment(t); - if(comment == strstr(comment, "http://")) { + if(g_str_has_prefix(comment, "http")) { /* starts with http -> url, converting to markup */ - comment = g_markup_printf_escaped("<a href='%s'>%s</a>", + gchar *commentMarkup = g_markup_printf_escaped("<a href='%s'>%s</a>", comment, comment); - }; - gtk_label_set_markup(GTK_LABEL(priv->gen_comment_label), comment); + gtk_label_set_markup(GTK_LABEL(priv->gen_comment_label), commentMarkup); + g_free(commentMarkup); + } else { + gtk_label_set_markup(GTK_LABEL(priv->gen_comment_label), comment); + } errorStr = torrent_get_errorstr(t); keyLabel = @@ -296,8 +311,12 @@ static void trg_general_panel_init(TrgGeneralPanel * self) priv->gen_comment_label = trg_general_panel_add_label(self, _("Comment"), 2, 4); + priv->gen_completedat_label = + trg_general_panel_add_label_with_width(self, _("Completed At"), 0, 5, + -1); + priv->gen_downloaddir_label = - trg_general_panel_add_label_with_width(self, _("Location"), 0, 5, + trg_general_panel_add_label_with_width(self, _("Location"), 1, 5, -1); priv->gen_error_label = @@ -490,6 +490,22 @@ int tr_snprintf(char *buf, size_t buflen, const char *fmt, ...) return len; } +gchar *epoch_to_string(gint64 epoch) +{ +#if GLIB_CHECK_VERSION(2, 26, 00) + GDateTime *dt = g_date_time_new_from_unix_local(epoch); + gchar *timestring = g_date_time_format(dt, "%F %H:%M:%S"); + g_date_time_unref(dt); + return timestring; +#else + char buf[64]; + time_t time_val = epoch; + struct tm *ts = localtime(&time_val); + int wrote = strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); + return g_strndup(buf, wrote); +#endif +} + size_t tr_strlcpy(char *dst, const void *src, size_t siz) { #ifdef HAVE_STRLCPY @@ -69,6 +69,7 @@ tr_formatter_speed_init(unsigned int kilo, char *tr_formatter_speed_KBps(char *buf, double KBps, size_t buflen); char *tr_strltime_long(char *buf, long seconds, size_t buflen); +gchar *epoch_to_string(gint64 epoch); char *tr_strltime_short(char *buf, long seconds, size_t buflen); char *tr_strpercent(char *buf, double x, size_t buflen); char *tr_strlpercent(char *buf, double x, size_t buflen); |