static void background_loaded_cb (GObject *source, GAsyncResult *res, gpointer data) { BackgroundData *bd = data; GtkWidget *child; GdkPixbuf *pixbuf; GError *error = NULL; pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (error) { g_warning ("Error loading '%s': %s", bd->filename, error->message); g_error_free (error); return; } child = gtk_image_new_from_pixbuf (pixbuf); gtk_widget_show (child); gtk_flow_box_insert (GTK_FLOW_BOX (bd->flowbox), child, -1); child = gtk_widget_get_parent (child); g_object_set_data_full (G_OBJECT (child), "filename", bd->filename, g_free); g_free (bd); }
static void populate_flowbox (GtkWidget *button, GtkWidget *flowbox) { const gchar *location; GDir *dir; GError *error = NULL; const gchar *name; gchar *filename; GFile *file; GInputStream *stream; BackgroundData *bd; GdkPixbuf *pixbuf; GtkWidget *child; g_signal_handlers_disconnect_by_func (button, populate_flowbox, flowbox); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 110, 70); gdk_pixbuf_fill (pixbuf, 0xffffffff); child = gtk_image_new_from_pixbuf (pixbuf); gtk_widget_show (child); gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), child, -1); location = "/usr/share/backgrounds/gnome"; dir = g_dir_open (location, 0, &error); if (error) { g_warning ("%s", error->message); g_error_free (error); return; } while ((name = g_dir_read_name (dir)) != NULL) { filename = g_build_filename (location, name, NULL); file = g_file_new_for_path (filename); stream = G_INPUT_STREAM (g_file_read (file, NULL, &error)); if (error) { g_warning ("%s", error->message); g_clear_error (&error); g_free (filename); } else { bd = g_new (BackgroundData, 1); bd->flowbox = flowbox; bd->filename = filename; gdk_pixbuf_new_from_stream_at_scale_async (stream, 110, 110, TRUE, NULL, background_loaded_cb, bd); } g_object_unref (file); g_object_unref (stream); } g_dir_close (dir); }
/** * gs_shell_overview_get_categories_cb: **/ static void gs_shell_overview_get_categories_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GsShellOverview *self = GS_SHELL_OVERVIEW (user_data); GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self); GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object); GList *l; GsCategory *cat; GtkWidget *tile; gboolean has_category = FALSE; g_autoptr(GError) error = NULL; g_autoptr(GsAppList) list = NULL; list = gs_plugin_loader_get_categories_finish (plugin_loader, res, &error); if (list == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("failed to get categories: %s", error->message); goto out; } gs_container_remove_all (GTK_CONTAINER (priv->flowbox_categories)); for (l = list; l; l = l->next) { cat = GS_CATEGORY (l->data); if (gs_category_get_size (cat) == 0) continue; tile = gs_category_tile_new (cat); g_signal_connect (tile, "clicked", G_CALLBACK (category_tile_clicked), self); gtk_flow_box_insert (GTK_FLOW_BOX (priv->flowbox_categories), tile, -1); gtk_widget_set_can_focus (gtk_widget_get_parent (tile), FALSE); has_category = TRUE; } out: if (has_category) { priv->empty = FALSE; } gtk_widget_set_visible (priv->category_heading, has_category); priv->loading_categories = FALSE; priv->refresh_count--; if (priv->refresh_count == 0) { priv->cache_valid = TRUE; g_signal_emit (self, signals[SIGNAL_REFRESHED], 0); } }