aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/converter.cpp30
-rw-r--r--libqmenumodel/src/converter.h2
-rw-r--r--libqmenumodel/src/qdbusobject.cpp1
-rw-r--r--libqmenumodel/src/qstateaction.cpp20
-rw-r--r--libqmenumodel/src/qstateaction.h2
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp18
-rw-r--r--libqmenumodel/src/unitymenumodel.h2
7 files changed, 72 insertions, 3 deletions
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp
index 69e6629..527ae85 100644
--- a/libqmenumodel/src/converter.cpp
+++ b/libqmenumodel/src/converter.cpp
@@ -24,6 +24,7 @@ extern "C" {
#include "converter.h"
#include <QDebug>
+#include <QString>
#include <QVariant>
/*! \internal */
@@ -137,6 +138,29 @@ static GVariant* toGVariant(const QString &typeName, const QVariant &value)
return NULL;
}
+QVariant Converter::toQVariantFromVariantString(const QString &variantString)
+{
+ GVariant *gvariant;
+ GError *error = NULL;
+
+ if (variantString.isEmpty()) {
+ return QVariant();
+ }
+
+ gvariant = g_variant_parse (NULL, variantString.toUtf8().data(), NULL, NULL, &error);
+
+ if (error) {
+ qWarning() << "Impossible to parse" << variantString << "as variant string:"<< error->message;
+ g_error_free (error);
+ return QVariant();
+ }
+
+ const QVariant& qvariant = Converter::toQVariant(gvariant);
+ g_variant_unref (gvariant);
+
+ return qvariant;
+}
+
GVariant* Converter::toGVariant(const QVariant &value)
{
GVariant *result = NULL;
@@ -156,12 +180,18 @@ GVariant* Converter::toGVariant(const QVariant &value)
case QVariant::Int:
result = g_variant_new_int32(value.toInt());
break;
+ case QVariant::LongLong:
+ result = g_variant_new_int64(value.toLongLong());
+ break;
case QVariant::String:
result = g_variant_new_string(value.toString().toUtf8().data());
break;
case QVariant::UInt:
result = g_variant_new_uint32(value.toUInt());
break;
+ case QVariant::ULongLong:
+ result = g_variant_new_uint64(value.toULongLong());
+ break;
case QVariant::Map:
{
GVariantBuilder *b;
diff --git a/libqmenumodel/src/converter.h b/libqmenumodel/src/converter.h
index f47c09e..27cdcae 100644
--- a/libqmenumodel/src/converter.h
+++ b/libqmenumodel/src/converter.h
@@ -21,12 +21,14 @@
#define CONVERTER_H
typedef struct _GVariant GVariant;
+class QString;
class QVariant;
class Converter
{
public:
static QVariant toQVariant(GVariant *value);
+ static QVariant toQVariantFromVariantString(const QString &variantString);
static GVariant* toGVariant(const QVariant &value);
// This converts a QVariant to a GVariant using a provided gvariant schema as
diff --git a/libqmenumodel/src/qdbusobject.cpp b/libqmenumodel/src/qdbusobject.cpp
index be9fb93..fab2df7 100644
--- a/libqmenumodel/src/qdbusobject.cpp
+++ b/libqmenumodel/src/qdbusobject.cpp
@@ -81,7 +81,6 @@ QDBusObject::QDBusObject(QObject* listener)
m_busType(DBusEnums::None),
m_status(DBusEnums::Disconnected)
{
- g_type_init();
qRegisterMetaType<DBusEnums::ConnectionStatus>("DBusEnums::ConnectionStatus");
}
diff --git a/libqmenumodel/src/qstateaction.cpp b/libqmenumodel/src/qstateaction.cpp
index 983064a..fcffa44 100644
--- a/libqmenumodel/src/qstateaction.cpp
+++ b/libqmenumodel/src/qstateaction.cpp
@@ -19,6 +19,7 @@
#include "qstateaction.h"
+#include "converter.h"
#include "qdbusactiongroup.h"
/*!
@@ -99,6 +100,15 @@ void QStateAction::updateState(const QVariant &state)
}
/*!
+ Request for the state of action to be changed to \a paramenter.
+ This call merely requests a change. The action may refuse to change its state or may change its state to something other than \a paramenter.
+*/
+void QStateAction::updateStateByVariantString(const QString &state)
+{
+ updateState(Converter::toQVariantFromVariantString(state));
+}
+
+/*!
Activates the action passing \a parameter.
\a parameter must be the correct type of parameter for the action
*/
@@ -107,6 +117,16 @@ void QStateAction::activate(const QVariant &parameter)
m_group->activateAction(m_name, parameter);
}
+/*!
+ Activates the action passing \a parameter using GLib Variant String format.
+ \a parameter must be the correct type of parameter for the action
+*/
+void QStateAction::activateByVariantString(const QString &parameter)
+{
+ activate(Converter::toQVariantFromVariantString(parameter));
+}
+
+
/*! \internal */
QString QStateAction::name() const
{
diff --git a/libqmenumodel/src/qstateaction.h b/libqmenumodel/src/qstateaction.h
index 0fc68c2..4d05a7a 100644
--- a/libqmenumodel/src/qstateaction.h
+++ b/libqmenumodel/src/qstateaction.h
@@ -36,7 +36,9 @@ public:
bool isValid() const;
Q_INVOKABLE void activate(const QVariant &parameter = QVariant());
+ Q_INVOKABLE void activateByVariantString(const QString &parameter = QString());
Q_INVOKABLE void updateState(const QVariant &parameter);
+ Q_INVOKABLE void updateStateByVariantString(const QString &parameter);
Q_SIGNALS:
void stateChanged(QVariant state);
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp
index 70412a4..aac1d92 100644
--- a/libqmenumodel/src/unitymenumodel.cpp
+++ b/libqmenumodel/src/unitymenumodel.cpp
@@ -661,7 +661,7 @@ bool UnityMenuModel::loadExtendedAttributes(int position, const QVariantMap &sch
continue;
}
- QVariant qvalue = attributeToQVariant(value, type);
+ const QVariant &qvalue = attributeToQVariant(value, type);
if (qvalue.isValid())
extendedAttrs->insert(qtify_name (name.toUtf8()), qvalue);
else
@@ -692,6 +692,8 @@ void UnityMenuModel::activate(int index, const QVariant& parameter)
{
GSequenceIter *it;
GtkMenuTrackerItem *item;
+ GVariant *value;
+ const GVariantType *parameter_type;
it = g_sequence_get_iter_at_pos (priv->items, index);
if (g_sequence_iter_is_end (it)) {
@@ -707,7 +709,9 @@ void UnityMenuModel::activate(int index, const QVariant& parameter)
gchar *action;
action = gtk_menu_tracker_item_get_action_name (item);
- g_action_group_activate_action (G_ACTION_GROUP (priv->muxer), action, Converter::toGVariant(parameter));
+ parameter_type = g_action_group_get_action_parameter_type (G_ACTION_GROUP (priv->muxer), action);
+ value = Converter::toGVariantWithSchema(parameter, g_variant_type_peek_string (parameter_type));
+ g_action_group_activate_action (G_ACTION_GROUP (priv->muxer), action, value);
g_free (action);
} else {
@@ -715,6 +719,16 @@ void UnityMenuModel::activate(int index, const QVariant& parameter)
}
}
+void UnityMenuModel::activateByVariantString(int index, const QString& parameter)
+{
+ activate(index, Converter::toQVariantFromVariantString(parameter));
+}
+
+void UnityMenuModel::changeStateByVariantString(int index, const QString& parameter)
+{
+ changeState(index, Converter::toQVariantFromVariantString(parameter));
+}
+
void UnityMenuModel::changeState(int index, const QVariant& parameter)
{
GSequenceIter *it;
diff --git a/libqmenumodel/src/unitymenumodel.h b/libqmenumodel/src/unitymenumodel.h
index 8816d22..ed3bcd7 100644
--- a/libqmenumodel/src/unitymenumodel.h
+++ b/libqmenumodel/src/unitymenumodel.h
@@ -63,7 +63,9 @@ public:
Q_INVOKABLE QVariant get(int row, const QByteArray &role);
Q_INVOKABLE void activate(int index, const QVariant& parameter = QVariant());
+ Q_INVOKABLE void activateByVariantString(int index, const QString& parameter = QString());
Q_INVOKABLE void changeState(int index, const QVariant& parameter);
+ Q_INVOKABLE void changeStateByVariantString(int index, const QString& parameter);
void registerAction(UnityMenuAction* action);
void unregisterAction(UnityMenuAction* action);