[rhel7 1/3] Allow markup and links in the info bar.

David Shea dshea at redhat.com
Thu Jun 4 20:28:30 UTC 2015


This changes the behavior of
anaconda_base_window_set_{error,info_warning}, in that the message
parameter is now treated as markup. Encourage the use of links in the
message in order to add something activatable to the tab order. The
actual link URI will be ignored.

Change the info-bar-clicked event to activate on button-pressed instead
of button-released, which keeps us from receiving both a button event
and a link event if someone clicks on a link.

(cherry picked from commit 873f816bce6f4ed4611dd98765ba276ed56279ee)

Related: rhbz#1125145
---
 widgets/src/BaseWindow.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/widgets/src/BaseWindow.c b/widgets/src/BaseWindow.c
index 4009ddc..7a1528a 100644
--- a/widgets/src/BaseWindow.c
+++ b/widgets/src/BaseWindow.c
@@ -129,6 +129,7 @@ static void anaconda_base_window_get_property(GObject *object, guint prop_id, GV
 static void anaconda_base_window_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 static void anaconda_base_window_buildable_init(GtkBuildableIface *iface);
 static void format_beta_label(AnacondaBaseWindow *window, const char *markup);
+static gboolean anaconda_base_window_info_activate_link(GtkLabel *label, gchar *uri, gpointer user_data);
 
 static gboolean anaconda_base_window_info_bar_clicked(GtkWidget *widget, GdkEvent *event, AnacondaBaseWindow *win);
 static void anaconda_base_window_help_button_clicked(GtkButton *button, AnacondaBaseWindow *win);
@@ -187,6 +188,11 @@ static void anaconda_base_window_class_init(AnacondaBaseWindowClass *klass) {
      * (pressed and released).  This allows, for instance, popping up a dialog with
      * more detailed information.
      *
+     * Activatable info bars are encouraged to include a link in the message for the
+     * purpose of keyboard navigation.  Clicking the link will emit the
+     * info-bar-clicked signal. See anaconda_base_window_set_error() for more
+     * information.
+     *
      * Since: 1.0
      */
     window_signals[SIGNAL_INFO_BAR_CLICKED] = g_signal_new("info-bar-clicked",
@@ -560,8 +566,16 @@ static void anaconda_base_window_set_info_bar(AnacondaBaseWindow *win, GtkMessag
     label = gtk_label_new(_(msg));
     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
     gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD);
+    gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
+    gtk_label_set_track_visited_links(GTK_LABEL(label), FALSE);
     gtk_widget_show(label);
 
+    /* Connect the activate-link signal to ignore actual link clicks. The part
+     * of the click we care about will be handled by the event box
+     */
+    g_signal_connect(label, "activate-link",
+            G_CALLBACK(anaconda_base_window_info_activate_link), win);
+
     win->priv->info_bar = gtk_info_bar_new();
     gtk_widget_set_no_show_all(win->priv->info_bar, TRUE);
 
@@ -575,8 +589,8 @@ static void anaconda_base_window_set_info_bar(AnacondaBaseWindow *win, GtkMessag
      * custom signal for the whole window.  It will be disconnected when the info
      * bar is hidden.
      */
-    gtk_widget_add_events(GTK_WIDGET(win->priv->event_box), GDK_BUTTON_RELEASE_MASK);
-    g_signal_connect(win->priv->event_box, "button-release-event",
+    gtk_widget_add_events(GTK_WIDGET(win->priv->event_box), GDK_BUTTON_PRESS_MASK);
+    g_signal_connect(win->priv->event_box, "button-press-event",
                      G_CALLBACK(anaconda_base_window_info_bar_clicked), win);
 
     content_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(win->priv->info_bar));
@@ -592,6 +606,12 @@ static void anaconda_base_window_set_info_bar(AnacondaBaseWindow *win, GtkMessag
     win->priv->info_shown = TRUE;
 }
 
+static gboolean anaconda_base_window_info_activate_link(GtkLabel *label, gchar *uri, gpointer win) {
+    /* Ignore the actual URI and emit info-bar-clicked on the window */
+    g_signal_emit(win, window_signals[SIGNAL_INFO_BAR_CLICKED], 0);
+    return TRUE;
+}
+
 /**
  * anaconda_base_window_set_error:
  * @win: a #AnacondaBaseWindow
@@ -601,6 +621,12 @@ static void anaconda_base_window_set_info_bar(AnacondaBaseWindow *win, GtkMessag
  * message.  Only one message may be shown at a time.  In order to show
  * a second message, anaconda_base_window_clear_info must first be called.
  *
+ * The message will be interpreted as Pango markup. Clickable messages are
+ * encouraged to include a clickable link using the #GtkLabel syntax in order
+ * to make the info bar accessible via the keyboard. The link URI will be
+ * ignored, and all link clicks will emit the
+ * #AnacondaBaseWindow::info-bar-clicked signal on @win.
+ *
  * Since: 1.0
  */
 void anaconda_base_window_set_error(AnacondaBaseWindow *win, const char *msg) {
@@ -616,6 +642,12 @@ void anaconda_base_window_set_error(AnacondaBaseWindow *win, const char *msg) {
  * message.  Only one message may be shown at a time.  In order to show
  * a second message, anaconda_base_window_clear_info must first be called.
  *
+ * The message will be interpreted as Pango markup. Clickable messages are
+ * encouraged to include a clickable link using the #GtkLabel syntax in order
+ * to make the info bar accessible via the keyboard. The link URI will be
+ * ignored, and all link clicks will emit the
+ * #AnacondaBaseWindow::info-bar-clicked signal on @win.
+ *
  * Since: 1.0
  */
 void anaconda_base_window_set_info(AnacondaBaseWindow *win, const char *msg) {
@@ -631,6 +663,12 @@ void anaconda_base_window_set_info(AnacondaBaseWindow *win, const char *msg) {
  * message.  Only one message may be shown at a time.  In order to show
  * a second message, anaconda_base_window_clear_info must first be called.
  *
+ * The message will be interpreted as Pango markup. Clickable messages are
+ * encouraged to include a clickable link using the #GtkLabel syntax in order
+ * to make the info bar accessible via the keyboard. The link URI will be
+ * ignored, and all link clicks will emit the
+ * #AnacondaBaseWindow::info-bar-clicked signal on @win.
+ *
  * Since: 1.0
  */
 void anaconda_base_window_set_warning(AnacondaBaseWindow *win, const char *msg) {
-- 
2.1.0



More information about the anaconda-patches mailing list