~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): Artur Rona
  • Date: 2011-02-01 20:27:20 UTC
  • mfrom: (1.1.14 upstream) (3.3.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110201202720-xobt459otz1m6sas
Tags: 0.3.0-1.1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/control, debian/rules:
    + Change build-depends from libwebkit-dev to libwebkitgtk-dev.
* debian/patches/desktop-scheme-handler-types:
  - Dropped, fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    #define gtk_widget_get_allocation(wdgt, alloc) *alloc = wdgt->allocation
39
39
#endif
40
40
 
 
41
#define I_ g_intern_static_string
 
42
 
41
43
static void
42
44
proxy_toggle_button_toggled_cb (GtkToggleButton* button,
43
45
                                GObject*         object)
104
106
    #endif
105
107
    if (!exe)
106
108
        exe = g_app_info_get_executable (info);
 
109
    if (!exe)
 
110
        exe = g_app_info_get_name (info);
107
111
    return exe;
108
112
}
109
113
 
247
251
        }
248
252
        else if (value != custom_value && GTK_IS_ENTRY (child))
249
253
        {
 
254
            g_signal_handlers_block_by_func (
 
255
                button, proxy_combo_box_changed_cb, object);
250
256
            /* Force the combo to change the item again */
251
257
            gtk_widget_destroy (child);
252
258
            gtk_combo_box_set_active (button, value + 1);
253
259
            gtk_combo_box_set_active (button, value);
 
260
            g_signal_handlers_unblock_by_func (
 
261
                button, proxy_combo_box_changed_cb, object);
254
262
        }
255
263
    }
256
264
 
466
474
 *     "custom-PROPERTY": the last value of an enumeration will be the "custom"
467
475
 *         value, where the user may enter text freely, which then updates
468
476
 *         the property PROPERTY instead. This applies only to enumerations.
 
477
 *     Since 0.2.9 the following hints are also supported:
 
478
 *     "languages": the widget will be particularly suitable for choosing
 
479
 *         multiple language codes, ie. "de,en_GB".
469
480
 *
470
481
 * Any other values for @hint are silently ignored.
471
482
 *
504
515
    type = G_PARAM_SPEC_TYPE (pspec);
505
516
    nick = g_param_spec_get_nick (pspec);
506
517
    _hint = g_intern_string (hint);
507
 
    if (_hint == g_intern_string ("blurb"))
 
518
    if (_hint == I_("blurb"))
508
519
        nick = g_param_spec_get_blurb (pspec);
509
520
    string = NULL;
510
521
    if (type == G_TYPE_PARAM_BOOLEAN)
513
524
        gboolean toggled = katze_object_get_boolean (object, property);
514
525
 
515
526
        #ifdef HAVE_HILDON_2_2
516
 
        if (_hint != g_intern_string ("toggle"))
 
527
        if (_hint != I_("toggle"))
517
528
        {
518
529
            widget = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
519
530
            gtk_button_set_label (GTK_BUTTON (widget), gettext (nick));
523
534
        #endif
524
535
        {
525
536
            widget = gtk_check_button_new ();
526
 
            if (_hint == g_intern_string ("toggle"))
 
537
            if (_hint == I_("toggle"))
527
538
                gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (widget), FALSE);
528
539
            else
529
540
                gtk_button_set_label (GTK_BUTTON (widget), gettext (nick));
538
549
            G_CALLBACK (proxy_widget_boolean_destroy_cb), object);
539
550
        g_free (notify_property);
540
551
    }
541
 
    else if (type == G_TYPE_PARAM_STRING && _hint == g_intern_string ("file"))
 
552
    else if (type == G_TYPE_PARAM_STRING && _hint == I_("file"))
542
553
    {
543
554
        string = katze_object_get_string (object, property);
544
555
 
553
564
            g_signal_connect (widget, "selection-changed",
554
565
                              G_CALLBACK (proxy_file_file_set_cb), object);
555
566
    }
556
 
    else if (type == G_TYPE_PARAM_STRING && _hint == g_intern_string ("folder"))
 
567
    else if (type == G_TYPE_PARAM_STRING && _hint == I_("folder"))
557
568
    {
558
569
        string = katze_object_get_string (object, property);
559
570
 
567
578
            g_signal_connect (widget, "selection-changed",
568
579
                              G_CALLBACK (proxy_folder_file_set_cb), object);
569
580
    }
570
 
    else if (type == G_TYPE_PARAM_STRING && _hint == g_intern_string ("uri"))
 
581
    else if (type == G_TYPE_PARAM_STRING && _hint == I_("uri"))
571
582
    {
572
583
        string = katze_object_get_string (object, property);
573
584
 
586
597
                              G_CALLBACK (proxy_uri_file_set_cb), object);
587
598
        #endif
588
599
    }
589
 
    else if (type == G_TYPE_PARAM_STRING && (_hint == g_intern_string ("font")
590
 
        || _hint == g_intern_string ("font-monospace")))
 
600
    else if (type == G_TYPE_PARAM_STRING && (_hint == I_("font")
 
601
        || _hint == I_("font-monospace")))
591
602
    {
592
603
        GtkComboBox* combo;
593
604
        gint n_families, i;
594
605
        PangoContext* context;
595
606
        PangoFontFamily** families;
596
 
        gboolean monospace = _hint == g_intern_string ("font-monospace");
 
607
        gboolean monospace = _hint == I_("font-monospace");
597
608
        string = katze_object_get_string (object, property);
598
609
 
599
610
        widget = gtk_combo_box_new_text ();
634
645
        const gchar* app_type = &hint[12];
635
646
        GtkSettings* settings;
636
647
        gint icon_width = 16;
 
648
        GtkTreeIter iter_none;
 
649
        GAppInfo* info;
637
650
 
638
651
        settings = gtk_settings_get_for_screen (gdk_screen_get_default ());
639
652
        gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
658
671
        if (!g_strcmp0 (string, ""))
659
672
            katze_assign (string, NULL);
660
673
 
661
 
        if (apps)
 
674
        gtk_list_store_insert_with_values (model, &iter_none, 0,
 
675
            0, NULL, 1, NULL, 2, _("None"), 3, icon_width, -1);
 
676
 
 
677
        if (apps != NULL)
662
678
        {
663
 
            GtkTreeIter iter_none;
664
679
            gint i = 0;
665
 
            GAppInfo* info;
666
 
 
667
 
            gtk_list_store_insert_with_values (model, &iter_none, 0,
668
 
                0, NULL, 1, NULL, 2, _("None"), 3, icon_width, -1);
669
680
 
670
681
            while ((info = g_list_nth_data (apps, i++)))
671
682
            {
685
696
 
686
697
                g_free (icon_name);
687
698
            }
 
699
            g_list_free (apps);
 
700
        }
688
701
 
 
702
        {
689
703
            info = g_app_info_create_from_commandline ("",
690
704
                "", G_APP_INFO_CREATE_NONE, NULL);
691
705
            gtk_list_store_insert_with_values (model, NULL, G_MAXINT,
720
734
                    gtk_combo_box_set_active_iter (combo, &iter_none);
721
735
            }
722
736
        }
723
 
        g_list_free (apps);
724
737
        g_signal_connect (widget, "changed",
725
738
                          G_CALLBACK (proxy_combo_box_apps_changed_cb), object);
726
739
    }
732
745
        g_object_get (object, property, &string, NULL);
733
746
        if (!string)
734
747
            string = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
 
748
        if (!(string && *string) && _hint == I_("languages"))
 
749
        {
 
750
            gchar* lang = g_strjoinv (",", (gchar**)g_get_language_names ());
 
751
            if (g_str_has_suffix (lang, ",C"))
 
752
            {
 
753
                string = g_strndup (lang, strlen (lang) - 2);
 
754
                g_free (lang);
 
755
            }
 
756
            else
 
757
                string = lang;
 
758
        }
735
759
        gtk_entry_set_text (GTK_ENTRY (widget), string ? string : "");
736
760
        g_signal_connect (widget, "activate",
737
761
                          G_CALLBACK (proxy_entry_activate_cb), object);
1132
1156
    KatzeItem* child;
1133
1157
    GtkTreeIter iter;
1134
1158
    GtkTreeIter root_iter;
1135
 
    guint i = 0;
1136
1159
 
1137
 
    while ((child = katze_array_get_nth_item (KATZE_ARRAY (array), i)))
 
1160
    KATZE_ARRAY_FOREACH_ITEM (child, array)
1138
1161
    {
1139
1162
        if (KATZE_ITEM_IS_BOOKMARK (child))
1140
1163
        {
1151
1174
            gtk_tree_store_insert_with_values (model, &iter, &root_iter,
1152
1175
                                               0, 0, NULL, -1);
1153
1176
        }
1154
 
        i++;
1155
1177
    }
1156
1178
}
1157
1179
 
1493
1515
{
1494
1516
    GdkPixbuf* icon = NULL;
1495
1517
 
 
1518
    g_return_val_if_fail (uri != NULL, NULL);
 
1519
 
1496
1520
    if (g_str_has_prefix (uri, "http://") || g_str_has_prefix (uri,"https://"))
1497
1521
    {
1498
1522
        guint i;
1522
1546
        g_free (checksum);
1523
1547
        path = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
1524
1548
                                 "icons", filename, NULL);
 
1549
        g_free (filename);
1525
1550
        if ((icon = gdk_pixbuf_new_from_file_at_size (path, 16, 16, NULL)))
1526
1551
        {
1527
1552
            g_free (path);
1534
1559
        GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
1535
1560
}
1536
1561
 
1537
 
/**
1538
 
 * katze_collfold:
1539
 
 * @str: a non-NULL UTF-8 string
1540
 
 *
1541
 
 * Computes a string without case and decomposited so
1542
 
 * it can be used for comparison.
1543
 
 *
1544
 
 * Return value: a normalized string
1545
 
 *
1546
 
 * Since: 0.2.3
1547
 
 **/
1548
 
gchar*
1549
 
katze_collfold (const gchar* str)
1550
 
{
1551
 
    GString* result = g_string_new (NULL);
1552
 
    const gchar* p = str;
1553
 
 
1554
 
    while (*p)
1555
 
    {
1556
 
        gunichar ch = g_unichar_tolower (g_utf8_get_char (p));
1557
 
        gsize len;
1558
 
        gunichar* sch = g_unicode_canonical_decomposition (ch, &len);
1559
 
        guint i = 0;
1560
 
        while (i < len)
1561
 
            g_string_append_unichar (result, sch[i++]);
1562
 
 
1563
 
        p = g_utf8_next_char (p);
1564
 
    }
1565
 
 
1566
 
    return g_string_free (result, FALSE);
1567
 
}
1568
 
 
1569
 
/**
1570
 
 * katze_utf8_stristr:
1571
 
 * @haystack: a non-NULL UTF-8 string
1572
 
 * @needle: a normalized non-NULL UTF-8 string
1573
 
 *
1574
 
 * Determines whether @needle is in @haystack, disregarding
1575
 
 * differences in case.
1576
 
 *
1577
 
 * Return value: %TRUE if @needle is found in @haystack
1578
 
 *
1579
 
 * Since: 0.2.3
1580
 
 **/
1581
 
gboolean
1582
 
katze_utf8_stristr (const gchar* haystack,
1583
 
                    const gchar* needle)
1584
 
{
1585
 
    #if 0 /* 0,000159 seconds */
1586
 
    /* Too slow for use in completion */
1587
 
    gchar* nhaystack = g_utf8_normalize (haystack, -1, G_NORMALIZE_DEFAULT);
1588
 
    const gchar *p = nhaystack;
1589
 
    gsize len = strlen (needle);
1590
 
    gsize i;
1591
 
 
1592
 
    while (*p)
1593
 
    {
1594
 
        for (i = 0; i < len; i++)
1595
 
            if (g_unichar_tolower (g_utf8_get_char (p + i))
1596
 
             != g_unichar_tolower (g_utf8_get_char (needle + i)))
1597
 
                goto next;
1598
 
 
1599
 
        g_free (nhaystack);
1600
 
        return TRUE;
1601
 
 
1602
 
        next:
1603
 
            p = g_utf8_next_char (p);
1604
 
    }
1605
 
 
1606
 
    g_free (nhaystack);
1607
 
    return FALSE;
1608
 
    #else /* 0,000044 seconds */
1609
 
    /* No unicode matching */
1610
 
    const gchar *p = haystack;
1611
 
    gsize len = strlen (needle);
1612
 
    gsize i;
1613
 
 
1614
 
    while (*p)
1615
 
    {
1616
 
        for (i = 0; i < len; i++)
1617
 
            if (g_ascii_tolower (p[i]) != g_ascii_tolower (needle[i]))
1618
 
                goto next;
1619
 
 
1620
 
        return TRUE;
1621
 
 
1622
 
        next:
1623
 
            p++;
1624
 
    }
1625
 
 
1626
 
    return FALSE;
1627
 
    #endif
1628
 
}