[PATCH 1/2] Add a checkmark on a DiskOverview when it is selected.

Samantha N. Bueno sbueno+anaconda at redhat.com
Thu Apr 18 17:47:01 UTC 2013


Ack to both of these. Looks nice, btw.

On Thu, Apr 18, 2013 at 01:17:52PM -0400, Chris Lumens wrote:
> This is to help make it a little more obvious when a disk is selected,
> especially when there is only one disk available and we select it by
> default.  It can be hard to tell what the blue background means then.
> ---
>  data/pixmaps/Makefile.am                |   2 +-
>  data/pixmaps/anaconda-selected-icon.svg | 136 ++++++++++++++++++++++++++++++++
>  widgets/src/DiskOverview.c              |  82 +++++++++++++++----
>  3 files changed, 205 insertions(+), 15 deletions(-)
>  create mode 100644 data/pixmaps/anaconda-selected-icon.svg
> 
> diff --git a/data/pixmaps/Makefile.am b/data/pixmaps/Makefile.am
> index 00320b0..26d1f77 100644
> --- a/data/pixmaps/Makefile.am
> +++ b/data/pixmaps/Makefile.am
> @@ -18,6 +18,6 @@
>  # Author: David Cantrell <dcantrell at redhat.com>
>  
>  pixmapsdir        = $(datadir)/$(PACKAGE_NAME)/pixmaps
> -dist_pixmaps_DATA = *.png
> +dist_pixmaps_DATA = *.png *.svg
>  
>  MAINTAINERCLEANFILES = Makefile.in
> diff --git a/data/pixmaps/anaconda-selected-icon.svg b/data/pixmaps/anaconda-selected-icon.svg
> new file mode 100644
> index 0000000..32c90fd
> --- /dev/null
> +++ b/data/pixmaps/anaconda-selected-icon.svg
> @@ -0,0 +1,136 @@
> +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
> +<!-- Created with Inkscape (http://www.inkscape.org/) -->
> +
> +<svg
> +   xmlns:dc="http://purl.org/dc/elements/1.1/"
> +   xmlns:cc="http://creativecommons.org/ns#"
> +   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
> +   xmlns:svg="http://www.w3.org/2000/svg"
> +   xmlns="http://www.w3.org/2000/svg"
> +   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
> +   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
> +   id="svg7384"
> +   sodipodi:docname="anaconda-selected-icon.svg"
> +   version="1.1"
> +   inkscape:version="0.48+devel r11963"
> +   height="16"
> +   width="16">
> +  <metadata
> +     id="metadata90">
> +    <rdf:RDF>
> +      <cc:Work
> +         rdf:about="">
> +        <dc:format>image/svg+xml</dc:format>
> +        <dc:type
> +           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
> +        <dc:title>Gnome Symbolic Icon Theme</dc:title>
> +      </cc:Work>
> +    </rdf:RDF>
> +  </metadata>
> +  <sodipodi:namedview
> +     inkscape:cy="6.5413406"
> +     pagecolor="#ffffff"
> +     borderopacity="1"
> +     showborder="true"
> +     inkscape:bbox-paths="false"
> +     guidetolerance="10"
> +     inkscape:object-paths="true"
> +     inkscape:window-width="1145"
> +     showguides="true"
> +     inkscape:object-nodes="true"
> +     inkscape:snap-bbox="true"
> +     inkscape:pageshadow="2"
> +     inkscape:guide-bbox="true"
> +     inkscape:snap-nodes="false"
> +     bordercolor="#666666"
> +     objecttolerance="10"
> +     id="namedview88"
> +     showgrid="false"
> +     inkscape:window-maximized="0"
> +     inkscape:window-x="201"
> +     inkscape:snap-global="true"
> +     inkscape:window-y="27"
> +     gridtolerance="10"
> +     inkscape:window-height="709"
> +     inkscape:snap-to-guides="true"
> +     inkscape:current-layer="layer15"
> +     inkscape:snap-bbox-midpoints="false"
> +     inkscape:zoom="16"
> +     inkscape:cx="6.9516857"
> +     inkscape:snap-grids="true"
> +     inkscape:pageopacity="0"
> +     borderlayer="true">
> +    <inkscape:grid
> +       spacingx="1px"
> +       spacingy="1px"
> +       id="grid4866"
> +       empspacing="2"
> +       enabled="true"
> +       type="xygrid"
> +       snapvisiblegridlinesonly="true"
> +       visible="true" />
> +  </sodipodi:namedview>
> +  <title
> +     id="title9167">Gnome Symbolic Icon Theme</title>
> +  <defs
> +     id="defs7386" />
> +  <g
> +     inkscape:label="status"
> +     transform="translate(-482,-381.99998)"
> +     inkscape:groupmode="layer"
> +     id="layer9"
> +     style="display:inline" />
> +  <g
> +     inkscape:label="devices"
> +     transform="translate(-482,-381.99998)"
> +     inkscape:groupmode="layer"
> +     id="layer10" />
> +  <g
> +     inkscape:label="apps"
> +     transform="translate(-482,-381.99998)"
> +     inkscape:groupmode="layer"
> +     id="layer11" />
> +  <g
> +     inkscape:label="actions"
> +     transform="translate(-482,-381.99998)"
> +     inkscape:groupmode="layer"
> +     id="layer12" />
> +  <g
> +     inkscape:label="places"
> +     transform="translate(-482,-381.99998)"
> +     inkscape:groupmode="layer"
> +     id="layer13" />
> +  <g
> +     inkscape:label="mimetypes"
> +     transform="translate(-482,-381.99998)"
> +     inkscape:groupmode="layer"
> +     id="layer14" />
> +  <g
> +     inkscape:label="emblems"
> +     transform="translate(-482,-381.99998)"
> +     inkscape:groupmode="layer"
> +     id="layer15"
> +     style="display:inline">
> +    <g
> +       inkscape:label="emblem-important"
> +       transform="translate(135.8093,-581.17812)"
> +       id="g17779" />
> +    <path
> +       style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.5;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
> +       d="M 11.53125 4.3125 C 11.784964 4.3148534 12.043986 4.3496993 12.28125 4.40625 C 12.035802 4.3478581 11.794428 4.3125 11.53125 4.3125 z M 12.28125 4.40625 C 12.505761 4.4597611 12.733193 4.5282014 12.9375 4.625 C 12.73111 4.5265635 12.508413 4.460292 12.28125 4.40625 z M 13.6875 5.125 C 13.850992 5.2667533 13.991932 5.4225624 14.125 5.59375 C 13.993811 5.4260074 13.847799 5.2645304 13.6875 5.125 z M 14.125 5.59375 L 11.71875 7.90625 L 10.8125 6.90625 L 9.78125 7.90625 L 11.71875 9.84375 L 14.78125 7.09375 C 14.688509 6.5295894 14.461839 6.0244437 14.125 5.59375 z M 14.84375 7.625 C 14.84375 8.544865 14.444846 9.3969938 13.84375 10 C 14.452893 9.395735 14.84375 8.5537662 14.84375 7.625 z "
> +       transform="translate(482,381.99998)"
> +       id="path1012" />
> +    <path
> +       inkscape:connector-curvature="0"
> +       d="m 493.51417,386.30805 c -1.82723,0 -3.30412,1.49216 -3.30412,3.33188 0,1.83973 1.47689,3.33189 3.30412,3.33189 1.82723,0 3.318,-1.49216 3.318,-3.33189 0,-0.18508 -0.0267,-0.36456 -0.0555,-0.54143 l -3.06223,2.74335 -1.92929,-1.93014 1.01176,-0.99284 0.91795,0.98022 2.40931,-2.31382 C 495.51856,386.80617 494.57294,386.30805 493.51417,386.30805 Z"
> +       id="path74"
> +       sodipodi:nodetypes="ssssccccccs"
> +       style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;display:inline" />
> +  </g>
> +  <g
> +     inkscape:label="categories"
> +     transform="translate(-482,-381.99998)"
> +     inkscape:groupmode="layer"
> +     id="g4953"
> +     style="display:inline" />
> +</svg>
> diff --git a/widgets/src/DiskOverview.c b/widgets/src/DiskOverview.c
> index e3c39f4..2dcade1 100644
> --- a/widgets/src/DiskOverview.c
> +++ b/widgets/src/DiskOverview.c
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (C) 2011-2012  Red Hat, Inc.
> + * Copyright (C) 2011-2013  Red Hat, Inc.
>   *
>   * This program is free software; you can redistribute it and/or modify
>   * it under the terms of the GNU General Public License as published by
> @@ -18,6 +18,7 @@
>   */
>  
>  #include <gdk/gdk.h>
> +#include <gio/gio.h>
>  #include <string.h>
>  
>  #include "DiskOverview.h"
> @@ -53,11 +54,11 @@ enum {
>  #define DEFAULT_NAME          ""
>  #define DEFAULT_POPUP_INFO    ""
>  
> -#define ICON_SIZE             125
> +#define ICON_SIZE             128
>  
>  struct _AnacondaDiskOverviewPrivate {
>      GtkWidget *vbox;
> -    GtkWidget *kind;
> +    GtkWidget *kind_icon;
>      GtkWidget *description_label;
>      GtkWidget *capacity_label;
>      GtkWidget *name_label;
> @@ -65,6 +66,7 @@ struct _AnacondaDiskOverviewPrivate {
>  
>      GdkCursor *cursor;
>  
> +    gchar *kind;
>      gboolean chosen;
>  };
>  
> @@ -186,6 +188,50 @@ GtkWidget *anaconda_disk_overview_new() {
>      return g_object_new(ANACONDA_TYPE_DISK_OVERVIEW, NULL);
>  }
>  
> +static void set_icon(AnacondaDiskOverview *widget, const char *icon_name) {
> +    GError *err = NULL;
> +    GIcon *base_icon, *emblem_icon, *icon;
> +    GEmblem *emblem = NULL;
> +
> +    if (!icon_name)
> +        return;
> +
> +    if (widget->priv->kind_icon)
> +        gtk_widget_destroy(widget->priv->kind_icon);
> +
> +    if (widget->priv->chosen) {
> +        base_icon = g_icon_new_for_string(icon_name, &err);
> +        if (!base_icon) {
> +            fprintf(stderr, "could not create icon: %s\n", err->message);
> +            g_error_free(err);
> +            return;
> +        }
> +
> +        emblem_icon = g_icon_new_for_string("/usr/share/anaconda/pixmaps/anaconda-selected-icon.svg", &err);
> +        if (!emblem_icon) {
> +            fprintf(stderr, "could not create emblem: %s\n", err->message);
> +            g_error_free(err);
> +        }
> +        else {
> +            emblem = g_emblem_new(emblem_icon);
> +        }
> +
> +        icon = g_emblemed_icon_new(base_icon, emblem);
> +        g_object_unref(base_icon);
> +    }
> +    else {
> +        icon = g_icon_new_for_string(icon_name, &err);
> +        if (!icon) {
> +            fprintf(stderr, "could not create icon: %s\n", err->message);
> +            g_error_free(err);
> +            return;
> +        }
> +    }
> +
> +    widget->priv->kind_icon = gtk_image_new_from_gicon(icon, GTK_ICON_SIZE_DIALOG);
> +    gtk_image_set_pixel_size(GTK_IMAGE(widget->priv->kind_icon), ICON_SIZE);
> +}
> +
>  /* Initialize the widgets in a newly allocated DiskOverview. */
>  static void anaconda_disk_overview_init(AnacondaDiskOverview *widget) {
>      char *markup;
> @@ -219,8 +265,7 @@ static void anaconda_disk_overview_init(AnacondaDiskOverview *widget) {
>      g_free(markup);
>  
>      /* Create the spoke's icon. */
> -    widget->priv->kind = gtk_image_new_from_icon_name(DEFAULT_KIND, GTK_ICON_SIZE_DIALOG);
> -    gtk_image_set_pixel_size(GTK_IMAGE(widget->priv->kind), ICON_SIZE);
> +    set_icon(widget, DEFAULT_KIND);
>  
>      /* Create the description label. */
>      widget->priv->description_label = gtk_label_new(NULL);
> @@ -233,7 +278,7 @@ static void anaconda_disk_overview_init(AnacondaDiskOverview *widget) {
>  
>      /* Add everything to the vbox, add the vbox to the widget. */
>      gtk_container_add(GTK_CONTAINER(widget->priv->vbox), widget->priv->capacity_label);
> -    gtk_container_add(GTK_CONTAINER(widget->priv->vbox), widget->priv->kind);
> +    gtk_container_add(GTK_CONTAINER(widget->priv->vbox), widget->priv->kind_icon);
>      gtk_container_add(GTK_CONTAINER(widget->priv->vbox), widget->priv->description_label);
>      gtk_container_add(GTK_CONTAINER(widget->priv->vbox), widget->priv->name_label);
>  
> @@ -264,11 +309,15 @@ gboolean anaconda_disk_overview_clicked(AnacondaDiskOverview *widget, GdkEvent *
>  }
>  
>  static void anaconda_disk_overview_toggle_background(AnacondaDiskOverview *widget) {
> -    if (widget->priv->chosen) {
> -	gtk_widget_set_state_flags(GTK_WIDGET(widget), GTK_STATE_FLAG_SELECTED, FALSE);
> -    }
> +    if (widget->priv->chosen)
> +        gtk_widget_set_state_flags(GTK_WIDGET(widget), GTK_STATE_FLAG_SELECTED, FALSE);
>      else
> -	gtk_widget_unset_state_flags(GTK_WIDGET(widget), GTK_STATE_FLAG_SELECTED);
> +        gtk_widget_unset_state_flags(GTK_WIDGET(widget), GTK_STATE_FLAG_SELECTED);
> +
> +    set_icon(widget, widget->priv->kind);
> +    gtk_container_add(GTK_CONTAINER(widget->priv->vbox), widget->priv->kind_icon);
> +    gtk_box_reorder_child(GTK_BOX(widget->priv->vbox), widget->priv->kind_icon, 1);
> +    gtk_widget_show(widget->priv->kind_icon);
>  }
>  
>  static void anaconda_disk_overview_finalize(AnacondaDiskOverview *widget) {
> @@ -291,7 +340,7 @@ static void anaconda_disk_overview_get_property(GObject *object, guint prop_id,
>              break;
>  
>          case PROP_KIND:
> -            g_value_set_object (value, (GObject *)priv->kind);
> +            g_value_set_object (value, (GObject *)priv->kind_icon);
>              break;
>  
>          case PROP_CAPACITY:
> @@ -315,14 +364,19 @@ static void anaconda_disk_overview_set_property(GObject *object, guint prop_id,
>      switch(prop_id) {
>          case PROP_DESCRIPTION: {
>              char *markup = g_markup_printf_escaped("<span weight='bold' size='large'>%s</span>", g_value_get_string(value));
> -	    gtk_label_set_markup(GTK_LABEL(priv->description_label), markup);
> +            gtk_label_set_markup(GTK_LABEL(priv->description_label), markup);
>              g_free(markup);
>              break;
>          }
>  
>          case PROP_KIND:
> -            gtk_image_set_from_icon_name(GTK_IMAGE(priv->kind), g_value_get_string(value), GTK_ICON_SIZE_DIALOG);
> -            gtk_image_set_pixel_size(GTK_IMAGE(priv->kind), ICON_SIZE);
> +            if (widget->priv->kind)
> +                g_free(widget->priv->kind);
> +
> +            widget->priv->kind = g_strdup(g_value_get_string(value));
> +            set_icon(widget, widget->priv->kind);
> +            gtk_container_add(GTK_CONTAINER(widget->priv->vbox), widget->priv->kind_icon);
> +            gtk_box_reorder_child(GTK_BOX(widget->priv->vbox), widget->priv->kind_icon, 1);
>              break;
>  
>          case PROP_CAPACITY: {
> -- 
> 1.8.1.2
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches


More information about the anaconda-patches mailing list