aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-12 16:28:34 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-12 16:28:34 -0300
commitd2e99cfb78dfcdad000faf9c1c7d4e5a40d53f95 (patch)
treee177d5cffa1cd97a82c294449f9eb676577b0dbf
parent48e027ef11b7b09c20a6362e1768f909ea250815 (diff)
downloadqmenumodel-d2e99cfb78dfcdad000faf9c1c7d4e5a40d53f95.tar.gz
qmenumodel-d2e99cfb78dfcdad000faf9c1c7d4e5a40d53f95.tar.bz2
qmenumodel-d2e99cfb78dfcdad000faf9c1c7d4e5a40d53f95.zip
Parse extra properties name to remove 'x-' and replace '-' to '_'.
-rw-r--r--src/common/qmenumodel.cpp13
-rw-r--r--src/common/qmenumodel.h1
-rw-r--r--tests/client/modeltest.cpp20
3 files changed, 23 insertions, 11 deletions
diff --git a/src/common/qmenumodel.cpp b/src/common/qmenumodel.cpp
index ffb3fb6..af29ded 100644
--- a/src/common/qmenumodel.cpp
+++ b/src/common/qmenumodel.cpp
@@ -179,6 +179,16 @@ QVariant QMenuModel::getLink(const QModelIndex &index,
}
/*! \internal */
+QString QMenuModel::parseExtraPropertyName(const QString &name) const
+{
+ QString newName(name);
+ if (name.startsWith("x-")) {
+ newName = name.right(name.length() - 2);
+ }
+ return newName.replace("-", "_");
+}
+
+/*! \internal */
QVariant QMenuModel::getExtraProperties(const QModelIndex &index) const
{
GMenuAttributeIter *iter = g_menu_model_iterate_item_attributes(m_menuModel, index.row());
@@ -191,7 +201,8 @@ QVariant QMenuModel::getExtraProperties(const QModelIndex &index) const
GVariant *value = NULL;
while (g_menu_attribute_iter_get_next (iter, &attrName, &value)) {
if (strncmp("x-", attrName, 2) == 0) {
- extra->setProperty(attrName, Converter::parseGVariant(value));
+
+ extra->setProperty(parseExtraPropertyName(attrName).toLatin1(), Converter::parseGVariant(value));
}
}
diff --git a/src/common/qmenumodel.h b/src/common/qmenumodel.h
index e102f72..ba5696d 100644
--- a/src/common/qmenumodel.h
+++ b/src/common/qmenumodel.h
@@ -56,6 +56,7 @@ private:
QVariant getStringAttribute(const QModelIndex &index, const QString &attribute) const;
QVariant getLink(const QModelIndex &index, const QString &linkName) const;
QVariant getExtraProperties(const QModelIndex &index) const;
+ QString parseExtraPropertyName(const QString &name) const;
static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data);
};
diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp
index 9c092f1..4cf7f54 100644
--- a/tests/client/modeltest.cpp
+++ b/tests/client/modeltest.cpp
@@ -147,52 +147,52 @@ private Q_SLOTS:
QObject *extra = e.value<QObject*>();
// Boolean
- QVariant v = extra->property("x-boolean");
+ QVariant v = extra->property("boolean");
QCOMPARE(v.type(), QVariant::Bool);
QCOMPARE(v.toBool(), true);
// Byte
- v = extra->property("x-byte");
+ v = extra->property("byte");
QCOMPARE(v.typeName(), "uchar");
QCOMPARE(v.value<uchar>(), (uchar)42);
// Int16
- v = extra->property("x-int16");
+ v = extra->property("int16");
QCOMPARE(v.typeName(), "short");
QCOMPARE(v.value<short>(), (short)-42);
// UInt16
- v = extra->property("x-uint16");
+ v = extra->property("uint16");
QCOMPARE(v.typeName(), "ushort");
QCOMPARE(v.value<ushort>(), (ushort)42);
// Int32
- v = extra->property("x-int32");
+ v = extra->property("int32");
QCOMPARE(v.type(), QVariant::Int);
QCOMPARE(v.toInt(), -42);
// UInt32
- v = extra->property("x-uint32");
+ v = extra->property("uint32");
QCOMPARE(v.type(), QVariant::UInt);
QCOMPARE(v.toUInt(), (uint) 42);
// Int64
- v = extra->property("x-int64");
+ v = extra->property("int64");
QCOMPARE(v.typeName(), "long");
QCOMPARE(v.value<long>(), (long) -42);
// UInt64
- v = extra->property("x-uint64");
+ v = extra->property("uint64");
QCOMPARE(v.typeName(), "ulong");
QCOMPARE(v.value<ulong>(), (ulong) 42);
// Double
- v = extra->property("x-double");
+ v = extra->property("double");
QCOMPARE(v.type(), QVariant::Double);
QCOMPARE(v.toDouble(), 42.42);
// String
- v = extra->property("x-string");
+ v = extra->property("string");
QCOMPARE(v.type(), QVariant::String);
QCOMPARE(v.toString(), QString("42"));
}