[gnome-software] Add a dummy history item to applications with no history



commit 3c0ecf4f4c5f9b99e5501b759e773913ca10e7ef
Author: Richard Hughes <richard hughsie com>
Date:   Thu Sep 12 11:43:07 2013 +0100

    Add a dummy history item to applications with no history
    
    If an application is installed but has no history, then we know the current
    version and should probably show something sensible in the UI.

 src/gs-shell-details.c                     |   10 ++++++++--
 src/plugins/gs-plugin-packagekit-history.c |   12 ++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 1f218b5..ef22f3e 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -337,6 +337,7 @@ gs_shell_details_app_history_button_cb (GtkWidget *widget, GsShellDetails *shell
        GsApp *app;
        GtkBox *box;
        GtkListBox *list_box;
+       guint64 timestamp;
        guint i;
 
        /* add each history package to the dialog */
@@ -382,8 +383,13 @@ gs_shell_details_app_history_button_cb (GtkWidget *widget, GsShellDetails *shell
                gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
 
                /* add the timestamp */
-               datetime = g_date_time_new_from_unix_utc (gs_app_get_install_date (app));
-               date_str = g_date_time_format (datetime, "%e %B %Y");
+               timestamp = gs_app_get_install_date (app);
+               datetime = g_date_time_new_from_unix_utc (timestamp);
+               if (timestamp == GS_APP_INSTALL_DATE_UNKNOWN) {
+                       date_str = g_strdup ("");
+               } else {
+                       date_str = g_date_time_format (datetime, "%e %B %Y");
+               }
                widget = gtk_label_new (date_str);
                g_object_set (widget,
                              "margin-left", 20,
diff --git a/src/plugins/gs-plugin-packagekit-history.c b/src/plugins/gs-plugin-packagekit-history.c
index 6c31a5e..164b629 100644
--- a/src/plugins/gs-plugin-packagekit-history.c
+++ b/src/plugins/gs-plugin-packagekit-history.c
@@ -145,6 +145,7 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
        GError *error_local = NULL;
        GList *l;
        GsApp *app;
+       GsApp *app_dummy;
        guint i = 0;
        GVariantIter iter;
        GVariant *result;
@@ -196,6 +197,17 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
                                        "@aa{sv}",
                                        &value);
                if (!ret) {
+                       /* make up a fake entry as we know this package was at
+                        * least installed at some point in time */
+                       if (gs_app_get_state (app) == GS_APP_STATE_INSTALLED) {
+                               app_dummy = gs_app_new (gs_app_get_id (app));
+                               gs_app_set_install_date (app_dummy, GS_APP_INSTALL_DATE_UNKNOWN);
+                               gs_app_set_kind (app_dummy, GS_APP_KIND_PACKAGE);
+                               gs_app_set_state (app_dummy, GS_APP_STATE_INSTALLED);
+                               gs_app_set_version (app_dummy, gs_app_get_version (app));
+                               gs_app_add_history (app, app_dummy);
+                               g_object_unref (app_dummy);
+                       }
                        g_debug ("no history for %s, setting timestamp nonzero",
                                 gs_app_get_source (app));
                        gs_app_set_install_date (app, GS_APP_INSTALL_DATE_UNKNOWN);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]