[gnome-software] Do not refresh the screenshots twice when showing the details page
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Do not refresh the screenshots twice when showing the details page
- Date: Wed, 9 Oct 2013 16:32:28 +0000 (UTC)
commit 12891c9f75df11ef749b9c4451482b0f7df331da
Author: Richard Hughes <richard hughsie com>
Date: Wed Oct 9 17:31:56 2013 +0100
Do not refresh the screenshots twice when showing the details page
src/gs-screenshot-image.c | 72 ++++++++++++++++++++-----
src/gs-screenshot-image.h | 9 ++-
src/gs-shell-details.c | 125 ++++++++++++++++++++++++++------------------
3 files changed, 137 insertions(+), 69 deletions(-)
---
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index 0c6e88a..a29782a 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -40,7 +40,9 @@ struct _GsScreenshotImagePrivate
gchar *cachedir;
gchar *filename;
guint spinner_id;
- const gchar *current_image;
+ const gchar *current_image;
+ guint width;
+ guint height;
};
G_DEFINE_TYPE_WITH_PRIVATE (GsScreenshotImage, gs_screenshot_image, GTK_TYPE_BIN)
@@ -129,7 +131,9 @@ gs_screenshot_show_image (GsScreenshotImage *ssimg)
* gs_screenshot_image_complete_cb:
**/
static void
-gs_screenshot_image_complete_cb (SoupSession *session, SoupMessage *msg, gpointer user_data)
+gs_screenshot_image_complete_cb (SoupSession *session,
+ SoupMessage *msg,
+ gpointer user_data)
{
GsScreenshotImagePrivate *priv;
GsScreenshotImage *ssimg = GS_SCREENSHOT_IMAGE (user_data);
@@ -193,8 +197,47 @@ gs_screenshot_image_show_spinner (gpointer user_data)
**/
void
gs_screenshot_image_set_screenshot (GsScreenshotImage *ssimg,
- GsScreenshot *screenshot,
- guint width, guint height)
+ GsScreenshot *screenshot)
+{
+ GsScreenshotImagePrivate *priv;
+
+ g_return_if_fail (GS_IS_SCREENSHOT_IMAGE (ssimg));
+ g_return_if_fail (GS_IS_SCREENSHOT (screenshot));
+
+ priv = gs_screenshot_image_get_instance_private (ssimg);
+
+ if (priv->screenshot == screenshot)
+ return;
+ if (priv->screenshot)
+ g_object_unref (priv->screenshot);
+ priv->screenshot = g_object_ref (screenshot);
+}
+
+/**
+ * gs_screenshot_image_set_size:
+ **/
+void
+gs_screenshot_image_set_size (GsScreenshotImage *ssimg,
+ guint width, guint height)
+{
+ GsScreenshotImagePrivate *priv;
+
+ g_return_if_fail (GS_IS_SCREENSHOT_IMAGE (ssimg));
+ g_return_if_fail (width != 0);
+ g_return_if_fail (height != 0);
+
+ priv = gs_screenshot_image_get_instance_private (ssimg);
+ priv->width = width;
+ priv->height = height;
+ gtk_widget_set_size_request (priv->stack, width, height);
+}
+
+/**
+ * gs_screenshot_image_load_async:
+ **/
+void
+gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
+ GCancellable *cancellable)
{
GsScreenshotImagePrivate *priv;
SoupMessage *msg = NULL;
@@ -206,19 +249,17 @@ gs_screenshot_image_set_screenshot (GsScreenshotImage *ssimg,
gint rc;
g_return_if_fail (GS_IS_SCREENSHOT_IMAGE (ssimg));
- g_return_if_fail (GS_IS_SCREENSHOT (screenshot));
- g_return_if_fail (width != 0);
- g_return_if_fail (height != 0);
priv = gs_screenshot_image_get_instance_private (ssimg);
- g_object_ref (screenshot);
- if (priv->screenshot)
- g_object_unref (priv->screenshot);
- priv->screenshot = screenshot;
- gtk_widget_set_size_request (priv->stack, width, height);
+
+ g_return_if_fail (GS_IS_SCREENSHOT (priv->screenshot));
+ g_return_if_fail (priv->width != 0);
+ g_return_if_fail (priv->height != 0);
/* test if size specific cachdir exists */
- url = gs_screenshot_get_url (screenshot, width, height);
+ url = gs_screenshot_get_url (priv->screenshot,
+ priv->width,
+ priv->height);
if (url == NULL) {
/* TRANSLATORS: this is when we request a screenshot size that
* the generator did not create or the parser did not add */
@@ -226,7 +267,7 @@ gs_screenshot_image_set_screenshot (GsScreenshotImage *ssimg,
goto out;
}
basename = g_path_get_basename (url);
- sizedir = g_strdup_printf ("%ux%u", width, height);
+ sizedir = g_strdup_printf ("%ux%u", priv->width, priv->height);
cachedir = g_build_filename (priv->cachedir,
"gnome-software",
"screenshots",
@@ -265,7 +306,8 @@ gs_screenshot_image_set_screenshot (GsScreenshotImage *ssimg,
/* send async */
soup_session_queue_message (priv->session, msg,
- gs_screenshot_image_complete_cb, ssimg);
+ gs_screenshot_image_complete_cb,
+ ssimg);
if (priv->spinner_id != 0)
g_source_remove (priv->spinner_id);
priv->spinner_id = g_timeout_add (250, gs_screenshot_image_show_spinner, ssimg);
diff --git a/src/gs-screenshot-image.h b/src/gs-screenshot-image.h
index bd90a5c..d99bf17 100644
--- a/src/gs-screenshot-image.h
+++ b/src/gs-screenshot-image.h
@@ -57,12 +57,15 @@ GtkWidget *gs_screenshot_image_new (SoupSession *session);
GsScreenshot *gs_screenshot_image_get_screenshot (GsScreenshotImage *ssimg);
void gs_screenshot_image_set_screenshot (GsScreenshotImage *ssimg,
- GsScreenshot *screenshot,
- guint width,
- guint height);
+ GsScreenshot *screenshot);
const gchar *gs_screenshot_image_get_cachedir (GsScreenshotImage *ssimg);
void gs_screenshot_image_set_cachedir (GsScreenshotImage *ssimg,
const gchar *cachedir);
+void gs_screenshot_image_set_size (GsScreenshotImage *ssimg,
+ guint width,
+ guint height);
+void gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
+ GCancellable *cancellable);
G_END_DECLS
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 1f8fa77..9fc92c4 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -204,10 +204,77 @@ gs_shell_details_screenshot_selected_cb (GtkListBox *list,
ssthumb = GS_SCREENSHOT_IMAGE (gtk_bin_get_child (GTK_BIN (row)));
ss = gs_screenshot_image_get_screenshot (ssthumb);
- gs_screenshot_image_set_screenshot (ssmain,
- ss,
- GS_SCREENSHOT_SIZE_LARGE_WIDTH,
- GS_SCREENSHOT_SIZE_LARGE_HEIGHT);
+ gs_screenshot_image_set_screenshot (ssmain, ss);
+ gs_screenshot_image_load_async (ssmain, NULL);
+}
+
+/**
+ * gs_shell_details_refresh_screenshots:
+ **/
+static void
+gs_shell_details_refresh_screenshots (GsShellDetails *shell_details)
+{
+ GPtrArray *screenshots;
+ GsScreenshot *ss;
+ GsShellDetailsPrivate *priv = shell_details->priv;
+ GtkWidget *list;
+ GtkWidget *ssimg;
+ GtkWidget *widget;
+ guint i;
+
+ /* set screenshots */
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+ "box_details_screenshot_main"));
+ gs_container_remove_all (GTK_CONTAINER (widget));
+ screenshots = gs_app_get_screenshots (priv->app);
+ if (screenshots->len == 0)
+ return;
+
+ /* set the default image */
+ ss = g_ptr_array_index (screenshots, 0);
+ ssimg = gs_screenshot_image_new (priv->session);
+ gtk_widget_set_can_focus (gtk_bin_get_child (GTK_BIN (ssimg)), FALSE);
+ gs_screenshot_image_set_cachedir (GS_SCREENSHOT_IMAGE (ssimg),
+ g_get_user_cache_dir ());
+ gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg), ss);
+ gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg),
+ GS_SCREENSHOT_SIZE_LARGE_WIDTH,
+ GS_SCREENSHOT_SIZE_LARGE_HEIGHT);
+ gs_screenshot_image_load_async (GS_SCREENSHOT_IMAGE (ssimg), NULL);
+ gtk_box_pack_start (GTK_BOX (widget), ssimg, FALSE, FALSE, 0);
+ gtk_widget_set_visible (ssimg, TRUE);
+
+ /* set all the thumbnails */
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+ "box_details_screenshot_thumbnails"));
+ gs_container_remove_all (GTK_CONTAINER (widget));
+ if (screenshots->len < 2)
+ return;
+
+ list = gtk_list_box_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (list), "image-list");
+ gtk_widget_show (list);
+ gtk_box_pack_start (GTK_BOX (widget), list, FALSE, FALSE, 0);
+ for (i = 0; i < screenshots->len; i++) {
+ ss = g_ptr_array_index (screenshots, i);
+ ssimg = gs_screenshot_image_new (priv->session);
+ gs_screenshot_image_set_cachedir (GS_SCREENSHOT_IMAGE (ssimg),
+ g_get_user_cache_dir ());
+ gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg), ss);
+ gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg),
+ GS_SCREENSHOT_SIZE_SMALL_WIDTH,
+ GS_SCREENSHOT_SIZE_SMALL_HEIGHT);
+ gs_screenshot_image_load_async (GS_SCREENSHOT_IMAGE (ssimg), NULL);
+ gtk_list_box_insert (GTK_LIST_BOX (list), ssimg, -1);
+ gtk_widget_set_visible (ssimg, TRUE);
+ }
+
+ gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_BROWSE);
+ gtk_list_box_select_row (GTK_LIST_BOX (list),
+ gtk_list_box_get_row_at_index (GTK_LIST_BOX (list), 0));
+ g_signal_connect (list, "row-selected",
+ G_CALLBACK (gs_shell_details_screenshot_selected_cb),
+ shell_details);
}
/**
@@ -217,16 +284,12 @@ static void
gs_shell_details_refresh_all (GsShellDetails *shell_details)
{
GPtrArray *history;
- GPtrArray *screenshots;
GdkPixbuf *pixbuf;
- GsScreenshot *ss;
GsShellDetailsPrivate *priv = shell_details->priv;
- GtkWidget *ssimg;
GtkWidget *widget2;
GtkWidget *widget;
const gchar *tmp;
gchar *size;
- guint i;
/* change widgets */
tmp = gs_app_get_name (priv->app);
@@ -277,49 +340,6 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
gtk_widget_set_visible (widget, FALSE);
}
- /* set screenshots */
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "box_details_screenshot_main"));
- gs_container_remove_all (GTK_CONTAINER (widget));
- screenshots = gs_app_get_screenshots (priv->app);
- if (screenshots->len > 0) {
- ss = g_ptr_array_index (screenshots, 0);
- ssimg = gs_screenshot_image_new (priv->session);
- gtk_widget_set_can_focus (gtk_bin_get_child (GTK_BIN (ssimg)), FALSE);
- gs_screenshot_image_set_cachedir (GS_SCREENSHOT_IMAGE (ssimg), g_get_user_cache_dir ());
- gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg),
- ss,
- GS_SCREENSHOT_SIZE_LARGE_WIDTH,
- GS_SCREENSHOT_SIZE_LARGE_HEIGHT);
- gtk_box_pack_start (GTK_BOX (widget), ssimg, FALSE, FALSE, 0);
- gtk_widget_set_visible (ssimg, TRUE);
- }
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "box_details_screenshot_thumbnails"));
- gs_container_remove_all (GTK_CONTAINER (widget));
- if (screenshots->len > 1) {
- GtkWidget *list;
- list = gtk_list_box_new ();
- gtk_style_context_add_class (gtk_widget_get_style_context (list), "image-list");
- gtk_widget_show (list);
- gtk_box_pack_start (GTK_BOX (widget), list, FALSE, FALSE, 0);
- for (i = 0; i < screenshots->len; i++) {
- ss = g_ptr_array_index (screenshots, i);
- ssimg = gs_screenshot_image_new (priv->session);
- gs_screenshot_image_set_cachedir (GS_SCREENSHOT_IMAGE (ssimg), g_get_user_cache_dir
());
- gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg),
- ss,
- GS_SCREENSHOT_SIZE_SMALL_WIDTH,
- GS_SCREENSHOT_SIZE_SMALL_HEIGHT);
- gtk_list_box_insert (GTK_LIST_BOX (list), ssimg, -1);
- gtk_widget_set_visible (ssimg, TRUE);
- }
-
- gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_BROWSE);
- gtk_list_box_select_row (GTK_LIST_BOX (list),
- gtk_list_box_get_row_at_index (GTK_LIST_BOX (list), 0));
- g_signal_connect (list, "row-selected",
- G_CALLBACK (gs_shell_details_screenshot_selected_cb), shell_details);
- }
-
/* set the project group */
tmp = gs_app_get_project_group (priv->app);
if (tmp == NULL) {
@@ -452,6 +472,9 @@ gs_shell_details_set_app (GsShellDetails *shell_details, GsApp *app)
G_CALLBACK (gs_shell_details_app_state_changed_cb),
shell_details);
+ /* set screenshots */
+ gs_shell_details_refresh_screenshots (shell_details);
+
/* change widgets */
gs_shell_details_refresh_all (shell_details);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]