[gnome-software] update dialog: Move the installed updates display here



commit e95fb5c68eb7941ecbe293f6a7bdc37d0b4cc4c3
Author: Kalev Lember <kalevlember gmail com>
Date:   Tue May 6 15:13:08 2014 +0200

    update dialog: Move the installed updates display here
    
    ... as per the design guidance.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727981

 src/gs-application.c    |    3 +-
 src/gs-shell.c          |   57 ++++++++++++++++++++++++++++++
 src/gs-shell.h          |    1 +
 src/gs-update-dialog.c  |   88 +++++++++++++++++++++++++++++++++++++++++-----
 src/gs-update-dialog.h  |    2 +
 src/gs-update-dialog.ui |   32 +++++++++++++++++
 6 files changed, 172 insertions(+), 11 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 2688326..a3e3216 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -300,7 +300,8 @@ set_mode_activated (GSimpleAction *action,
        } else if (g_strcmp0 (mode, "overview") == 0) {
                gs_shell_set_mode (app->shell, GS_SHELL_MODE_OVERVIEW);
        } else if (g_strcmp0 (mode, "updated") == 0) {
-               gs_shell_set_mode (app->shell, GS_SHELL_MODE_UPDATED);
+               gs_shell_set_mode (app->shell, GS_SHELL_MODE_UPDATES);
+               gs_shell_show_installed_updates (app->shell);
        } else {
                g_warning ("Mode '%s' not recognised", mode);
        }
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 5ab96b8..e179d49 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -34,6 +34,7 @@
 #include "gs-shell-updates.h"
 #include "gs-shell-category.h"
 #include "gs-sources-dialog.h"
+#include "gs-update-dialog.h"
 
 static const gchar *page_name[] = {
        "overview",
@@ -604,6 +605,62 @@ gs_shell_get_mode (GsShell *shell)
        return priv->mode;
 }
 
+static void
+gs_shell_get_installed_updates_cb (GsPluginLoader *plugin_loader,
+                                   GAsyncResult *res,
+                                   GsShell *shell)
+{
+       GsShellPrivate *priv = shell->priv;
+       GError *error = NULL;
+       GList *list;
+       GtkWidget *dialog;
+       GtkWidget *toplevel;
+
+       /* get the results */
+       list = gs_plugin_loader_get_updates_finish (plugin_loader, res, &error);
+       if (list == NULL) {
+               if (g_error_matches (error,
+                                    GS_PLUGIN_LOADER_ERROR,
+                                    GS_PLUGIN_LOADER_ERROR_NO_RESULTS)) {
+                       g_debug ("no updates to show");
+               } else {
+                       g_warning ("failed to get updates: %s", error->message);
+               }
+               g_error_free (error);
+               goto out;
+       }
+
+       dialog = gs_update_dialog_new ();
+       gs_update_dialog_show_installed_updates (GS_UPDATE_DIALOG (dialog), list);
+
+       toplevel = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
+       gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
+
+       gtk_window_present (GTK_WINDOW (dialog));
+
+out:
+       gs_plugin_list_free (list);
+}
+
+
+void
+gs_shell_show_installed_updates (GsShell *shell)
+{
+       GsShellPrivate *priv = shell->priv;
+       guint64 refine_flags;
+
+       refine_flags = GS_PLUGIN_REFINE_FLAGS_DEFAULT |
+                      GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS |
+                      GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
+                      GS_PLUGIN_REFINE_FLAGS_USE_HISTORY;
+
+       gs_plugin_loader_get_updates_async (priv->plugin_loader,
+                                           refine_flags,
+                                           priv->cancellable,
+                                           (GAsyncReadyCallback) gs_shell_get_installed_updates_cb,
+                                           shell);
+}
+
 void
 gs_shell_show_sources (GsShell *shell)
 {
diff --git a/src/gs-shell.h b/src/gs-shell.h
index e9d71ba..a7400c3 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -73,6 +73,7 @@ void           gs_shell_refresh               (GsShell        *shell,
 void            gs_shell_set_mode              (GsShell        *shell,
                                                 GsShellMode     mode);
 GsShellMode     gs_shell_get_mode              (GsShell        *shell);
+void            gs_shell_show_installed_updates(GsShell        *shell);
 void            gs_shell_show_sources          (GsShell        *shell);
 void            gs_shell_show_app              (GsShell        *shell,
                                                 GsApp          *app);
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 887d834..5174ce2 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -25,7 +25,9 @@
 #include <gtk/gtk.h>
 
 #include "gs-update-dialog.h"
+#include "gs-app-widget.h"
 #include "gs-markdown.h"
+#include "gs-offline-updates.h"
 #include "gs-utils.h"
 
 typedef struct {
@@ -37,7 +39,6 @@ typedef struct {
 struct _GsUpdateDialogPrivate
 {
        GQueue          *back_entry_stack;
-       GsApp           *app;
        GtkWidget       *box_header;
        GtkWidget       *button_back;
        GtkWidget       *image_icon;
@@ -45,6 +46,7 @@ struct _GsUpdateDialogPrivate
        GtkWidget       *label_name;
        GtkWidget       *label_summary;
        GtkWidget       *list_box;
+       GtkWidget       *list_box_installed_updates;
        GtkWidget       *scrolledwindow;
        GtkWidget       *scrolledwindow_details;
        GtkWidget       *stack;
@@ -125,8 +127,7 @@ row_activated_cb (GtkListBox *list_box,
                   GtkListBoxRow *row,
                   GsUpdateDialog *dialog)
 {
-       GsUpdateDialogPrivate *priv = gs_update_dialog_get_instance_private (dialog);
-       GsApp *app = NULL;
+       GsApp *app;
 
        app = GS_APP (g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (row))), "app"));
 
@@ -134,8 +135,68 @@ row_activated_cb (GtkListBox *list_box,
        save_back_entry (dialog);
 
        /* setup package view */
-       gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "package-details");
-       set_updates_description_ui (dialog, app);
+       gs_update_dialog_show_update_details (dialog, app);
+}
+
+static void
+installed_updates_row_activated_cb (GtkListBox *list_box,
+                                    GtkListBoxRow *row,
+                                    GsUpdateDialog *dialog)
+{
+       GsAppWidget *app_widget;
+       GsApp *app;
+
+       app_widget = GS_APP_WIDGET (gtk_bin_get_child (GTK_BIN (row)));
+       app = gs_app_widget_get_app (app_widget);
+
+       /* save the current stack state for the back button */
+       save_back_entry (dialog);
+
+       gs_update_dialog_show_update_details (dialog, app);
+}
+
+void
+gs_update_dialog_show_installed_updates (GsUpdateDialog *dialog, GList *installed_updates)
+{
+       GsUpdateDialogPrivate *priv = gs_update_dialog_get_instance_private (dialog);
+       GList *l;
+       GsApp *app;
+       GtkWidget *widget;
+       guint64 time_updates_installed;
+
+       /* TRANSLATORS: this is the title of the installed updates dialog window */
+       gtk_window_set_title (GTK_WINDOW (dialog), _("Installed Updates"));
+
+       if (gs_offline_updates_get_time_completed (&time_updates_installed)) {
+               GDateTime *date;
+               GtkWidget *header;
+               gchar *date_str;
+               gchar *subtitle;
+
+               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);
+               header = gtk_dialog_get_header_bar (GTK_DIALOG (dialog));
+               gtk_header_bar_set_subtitle (GTK_HEADER_BAR (header), subtitle);
+
+               g_free (date_str);
+       }
+
+       gtk_widget_set_visible (priv->button_back, !g_queue_is_empty (priv->back_entry_stack));
+       gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "installed-updates-list");
+
+       gs_container_remove_all (GTK_CONTAINER (priv->list_box_installed_updates));
+       for (l = installed_updates; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               widget = gs_app_widget_new ();
+               gs_app_widget_set_show_update (GS_APP_WIDGET (widget), TRUE);
+               gs_app_widget_set_app (GS_APP_WIDGET (widget), app);
+               gtk_container_add (GTK_CONTAINER (priv->list_box_installed_updates), widget);
+               gtk_widget_show (widget);
+       }
 }
 
 void
@@ -146,9 +207,6 @@ gs_update_dialog_show_update_details (GsUpdateDialog *dialog, GsApp *app)
        GsAppKind kind;
        const gchar *sort;
 
-       g_clear_object (&priv->app);
-       priv->app = g_object_ref (app);
-
        kind = gs_app_get_kind (app);
 
        /* set update header */
@@ -228,7 +286,6 @@ os_updates_sort_func (GtkListBoxRow *a,
        return g_strcmp0 (key1, key2);
 }
 
-
 static void
 button_back_cb (GtkWidget *widget, GsUpdateDialog *dialog)
 {
@@ -274,7 +331,6 @@ gs_update_dialog_finalize (GObject *object)
                g_queue_free_full (priv->back_entry_stack, (GDestroyNotify) back_entry_free);
                priv->back_entry_stack = NULL;
        }
-       g_clear_object (&priv->app);
 
        G_OBJECT_CLASS (gs_update_dialog_parent_class)->finalize (object);
 }
@@ -298,6 +354,17 @@ gs_update_dialog_init (GsUpdateDialog *dialog)
                                    os_updates_sort_func,
                                    dialog, NULL);
 
+       g_signal_connect (GTK_LIST_BOX (priv->list_box_installed_updates), "row-activated",
+                         G_CALLBACK (installed_updates_row_activated_cb), dialog);
+       gtk_list_box_set_header_func (GTK_LIST_BOX (priv->list_box_installed_updates),
+                                     list_header_func,
+                                     dialog, NULL);
+#if 0
+       gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->list_box_updates),
+                                   installed_updates_sort_func,
+                                   dialog, NULL);
+#endif
+
        g_signal_connect (priv->button_back, "clicked",
                          G_CALLBACK (button_back_cb),
                          dialog);
@@ -328,6 +395,7 @@ gs_update_dialog_class_init (GsUpdateDialogClass *klass)
        gtk_widget_class_bind_template_child_private (widget_class, GsUpdateDialog, label_name);
        gtk_widget_class_bind_template_child_private (widget_class, GsUpdateDialog, label_summary);
        gtk_widget_class_bind_template_child_private (widget_class, GsUpdateDialog, list_box);
+       gtk_widget_class_bind_template_child_private (widget_class, GsUpdateDialog, 
list_box_installed_updates);
        gtk_widget_class_bind_template_child_private (widget_class, GsUpdateDialog, scrolledwindow);
        gtk_widget_class_bind_template_child_private (widget_class, GsUpdateDialog, scrolledwindow_details);
        gtk_widget_class_bind_template_child_private (widget_class, GsUpdateDialog, stack);
diff --git a/src/gs-update-dialog.h b/src/gs-update-dialog.h
index 9009867..d6ffd44 100644
--- a/src/gs-update-dialog.h
+++ b/src/gs-update-dialog.h
@@ -51,6 +51,8 @@ struct _GsUpdateDialogClass
 
 GType           gs_update_dialog_get_type                      (void);
 GtkWidget      *gs_update_dialog_new                           (void);
+void            gs_update_dialog_show_installed_updates        (GsUpdateDialog         *dialog,
+                                                                GList                  *installed_updates);
 void            gs_update_dialog_show_update_details           (GsUpdateDialog         *dialog,
                                                                 GsApp                  *app);
 
diff --git a/src/gs-update-dialog.ui b/src/gs-update-dialog.ui
index 9076ceb..4d781db 100644
--- a/src/gs-update-dialog.ui
+++ b/src/gs-update-dialog.ui
@@ -198,6 +198,38 @@
                 <property name="name">os-update-list</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkScrolledWindow" id="scrolledwindow_installed_updates">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="vexpand">True</property>
+                <property name="hscrollbar_policy">never</property>
+                <property name="vscrollbar_policy">automatic</property>
+                <property name="shadow_type">none</property>
+                <property name="kinetic_scrolling">False</property>
+                <child>
+                  <object class="GtkFrame" id="frame_installed_updates">
+                    <property name="visible">True</property>
+                    <property name="shadow_type">in</property>
+                    <property name="halign">fill</property>
+                    <property name="valign">start</property>
+                    <style>
+                      <class name="view"/>
+                    </style>
+                    <child>
+                      <object class="GtkListBox" id="list_box_installed_updates">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="selection_mode">none</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="name">installed-updates-list</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>


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