~ubuntu-branches/ubuntu/oneiric/midori/oneiric-updates

« back to all changes in this revision

Viewing changes to katze/katze-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Micah Gersten
  • Date: 2011-05-18 21:07:34 UTC
  • mfrom: (1.1.16 upstream) (3.3.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110518210734-232wzq1tc88gtz2p
Tags: 0.3.6-1ubuntu1
* Merge from debian unstable. (LP: #784944) Remaining changes:
  - debian/control:
    + Change build-depends from libwebkit-dev to libwebkitgtk-dev
  - debian/rules:
    + Change package query from libwebkit-dev to libwebkitgtk-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
477
477
 *     Since 0.2.9 the following hints are also supported:
478
478
 *     "languages": the widget will be particularly suitable for choosing
479
479
 *         multiple language codes, ie. "de,en_GB".
 
480
 *     Since 0.3.6 the following hints are also supported:
 
481
 *     "address": the widget will be particularly suitable for typing
 
482
 *         a valid URI or IP address and highlight errors.
480
483
 *
481
484
 * Any other values for @hint are silently ignored.
482
485
 *
741
744
    {
742
745
        gchar* notify_property;
743
746
 
744
 
        widget = gtk_entry_new ();
 
747
        if (_hint == I_("address"))
 
748
            widget = katze_uri_entry_new (NULL);
 
749
        else
 
750
            widget = gtk_entry_new ();
745
751
        g_object_get (object, property, &string, NULL);
746
752
        if (!string)
747
753
            string = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
1559
1565
        GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
1560
1566
}
1561
1567
 
 
1568
static void
 
1569
katze_uri_entry_changed_cb (GtkWidget* entry,
 
1570
                            GtkWidget* other_widget)
 
1571
{
 
1572
    const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry));
 
1573
    gboolean valid = g_str_has_prefix (uri, "http://")
 
1574
                  || g_str_has_prefix (uri, "https://")
 
1575
                  || g_str_has_prefix (uri, "file://")
 
1576
                  || g_str_has_prefix (uri, "data:")
 
1577
                  || g_str_has_prefix (uri, "about:")
 
1578
                  || g_str_has_prefix (uri, "javascript:");
 
1579
    if (*uri && !valid)
 
1580
    {
 
1581
        GdkColor bg_color = { 0 };
 
1582
        GdkColor fg_color = { 0 };
 
1583
        gdk_color_parse ("#ef7070", &bg_color);
 
1584
        gdk_color_parse ("#000", &fg_color);
 
1585
        gtk_widget_modify_base (entry, GTK_STATE_NORMAL, &bg_color);
 
1586
        gtk_widget_modify_text (entry, GTK_STATE_NORMAL, &fg_color);
 
1587
    }
 
1588
    else
 
1589
    {
 
1590
        gtk_widget_modify_base (entry, GTK_STATE_NORMAL, NULL);
 
1591
        gtk_widget_modify_text (entry, GTK_STATE_NORMAL, NULL);
 
1592
    }
 
1593
 
 
1594
    if (other_widget != NULL)
 
1595
        gtk_widget_set_sensitive (other_widget, *uri && valid);
 
1596
}
 
1597
 
 
1598
/**
 
1599
 * katze_uri_entry_new:
 
1600
 * @other_widget: a #GtkWidget, or %NULL
 
1601
 *
 
1602
 * Creates an entry that validates the typed URI.
 
1603
 *
 
1604
 * If @other_widget is given, it will become insensitive if
 
1605
 * the input is not a valid URI.
 
1606
 *
 
1607
 * Returns: a #GtkEntry
 
1608
 *
 
1609
 * Since: 0.3.6
 
1610
 */
 
1611
GtkWidget*
 
1612
katze_uri_entry_new (GtkWidget* other_widget)
 
1613
{
 
1614
    GtkWidget* entry = gtk_entry_new ();
 
1615
    g_signal_connect (entry, "changed",
 
1616
        G_CALLBACK (katze_uri_entry_changed_cb), other_widget);
 
1617
    return entry;
 
1618
}
 
1619