diff options
author | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-10-30 11:56:37 +0000 |
---|---|---|
committer | Tarmac <> | 2012-10-30 11:56:37 +0000 |
commit | 035b6086485dcd3b42abc5d1fab2b155ccd16027 (patch) | |
tree | 43710ebf85e54277d0d084ac284781b4035a41c8 | |
parent | 4d47b26a31dc1c337b47ded055e5f6613972fc97 (diff) | |
parent | 307b793ca5deacfde7c787352f54f4f1aebc95e8 (diff) | |
download | qmenumodel-035b6086485dcd3b42abc5d1fab2b155ccd16027.tar.gz qmenumodel-035b6086485dcd3b42abc5d1fab2b155ccd16027.tar.bz2 qmenumodel-035b6086485dcd3b42abc5d1fab2b155ccd16027.zip |
Replaced gchar <-> QString convertion function, from Latin1 to Utf8.
Approved by PS Jenkins bot, Olivier Tilloy.
-rw-r--r-- | libqmenumodel/src/converter.cpp | 6 | ||||
-rw-r--r-- | libqmenumodel/src/qmenumodel.cpp | 6 | ||||
-rw-r--r-- | tests/client/modeltest.cpp | 8 | ||||
-rwxr-xr-x | tests/client/script_modeltest.py | 2 |
4 files changed, 15 insertions, 7 deletions
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp index c2b8fb1..75733ce 100644 --- a/libqmenumodel/src/converter.cpp +++ b/libqmenumodel/src/converter.cpp @@ -37,7 +37,7 @@ QVariant Converter::toQVariant(GVariant *value) } else if (g_variant_type_equal(type, G_VARIANT_TYPE_STRING)) { gsize size = 0; const gchar *v = g_variant_get_string(value, &size); - result.setValue(QString::fromLatin1(v, size)); + result.setValue(QString::fromUtf8(v, size)); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_VARDICT)) { GVariantIter iter; GVariant *vvalue; @@ -47,7 +47,7 @@ QVariant Converter::toQVariant(GVariant *value) g_variant_iter_init (&iter, value); while (g_variant_iter_loop (&iter, "{sv}", &key, &vvalue)) { - qmap.insert(QString::fromLatin1(key), toQVariant(vvalue)); + qmap.insert(QString::fromUtf8(key), toQVariant(vvalue)); } result.setValue(qmap); @@ -117,7 +117,7 @@ GVariant* Converter::toGVariant(const QVariant &value) result = g_variant_new_int32(value.toInt()); break; case QVariant::String: - result = g_variant_new_string(value.toString().toLatin1()); + result = g_variant_new_string(value.toString().toUtf8().data()); break; case QVariant::UInt: result = g_variant_new_uint32(value.toUInt()); diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index a45e5ff..f0c2274 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -156,10 +156,10 @@ QVariant QMenuModel::getStringAttribute(const QModelIndex &index, gchar* value = NULL; g_menu_model_get_item_attribute(m_menuModel, index.row(), - attribute.toLatin1(), + attribute.toUtf8().data(), "s", &value); if (value) { - result = QVariant(QString::fromLatin1(value)); + result = QVariant(QString::fromUtf8(value)); g_free(value); } return result; @@ -173,7 +173,7 @@ QVariant QMenuModel::getLink(const QModelIndex &index, link = g_menu_model_get_item_link(m_menuModel, index.row(), - linkName.toLatin1()); + linkName.toUtf8().data()); if (link) { QMenuModel *other = new QMenuModel(link, const_cast<QMenuModel*>(this)); diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp index 1c2eeca..93677db 100644 --- a/tests/client/modeltest.cpp +++ b/tests/client/modeltest.cpp @@ -212,7 +212,13 @@ private Q_SLOTS: QCOMPARE(v.type(), QVariant::Map); QCOMPARE(v.toMap(), map); - } + + // Utf8 + v = extra["utf8"]; + QCOMPARE(v.type(), QVariant::String); + QCOMPARE(v.toString(), QString("dança")); + + } /* * Test if model is destroyed without crash diff --git a/tests/client/script_modeltest.py b/tests/client/script_modeltest.py index 95df442..fdfbff4 100755 --- a/tests/client/script_modeltest.py +++ b/tests/client/script_modeltest.py @@ -1,4 +1,5 @@ #!/usr/bin/python2.7 +# -*- coding: utf-8 -*- import time from gi.repository import GLib @@ -21,6 +22,7 @@ al.appendItem("Menu0", "Menu0Act", None, None, {'x-boolean' : GLib.Variant('b', 'x-uint64' : GLib.Variant('t', 42), 'x-double' : GLib.Variant('d', 42.42), 'x-string' : GLib.Variant('s', u'42'), + 'x-utf8' : GLib.Variant('s', u'dança'), 'x-map' : GLib.Variant('a{sv}', pmap), }) al.appendItem("Menu1", "Menu1Act") |