![]() |
2011-06-17
, 13:21
|
|
Posts: 1,684 |
Thanked: 1,562 times |
Joined on Jun 2008
@ Austin, TX
|
#2
|
Ok, I'm working on my first Maemo5 project (QtCreator/C++) to get a feel for things, and the next stage is to query and preserve the status of all the accounts, disable them, then do stuff, and finally restore them.
Easy-peesy. DBus query to grab the state, DBus calls to disable them all, then DBus calls to restore the saved values.
Thing is, the version of Telepathy in the QtCreator SDK seems quite old, and doesn't have the convenience methods for getting and setting the DBus properties, so you have to use the generic DBus property methods.
My issue is that I've been mostly using Qt up to this point, with just a sprinkling of glib thrown in as required, so I have no idea if I'm missing something fundamental. The blocking calls (tp_cli_dbus_properties_run_get) are deprecated, and the async calls (tp_cli_dbus_properties_call_get) run from the event loop. Thus, the callbacks fire when the reply is received, but I've no idea what the correct way is to determine when this has completed.
It essentially becomes a bit more complicated due to the fact that there are two callbacks involved; the first to identify the accounts, and the second group are set up from that callback for each account to query the property values. I can (IMHO) bodge it by noting the number of accounts returned, and then waiting until I have that many property callbacks fired...but this seems a poor way of doing things, and I'm sure I must be missing something...
...any ideas?
The Following User Says Thank You to epage For This Useful Post: | ||
![]() |
2011-06-17
, 14:24
|
Posts: 249 |
Thanked: 277 times |
Joined on May 2010
@ Brighton, UK
|
#3
|
![]() |
2011-06-17
, 15:47
|
|
Posts: 1,684 |
Thanked: 1,562 times |
Joined on Jun 2008
@ Austin, TX
|
#4
|
Thanks for the reply. I appreciate your point with the thread title....changed
Python's next on my to-learn list...the python dbus examples I've stumbled across have all used nice blocking code in them, which makes me somewhat envious of the simplicity that comes from the blocking solutions.
The DBus values I'm querying are essentially a conversion of a snippet from the python found here, i.e. grab the "ValidAccounts" from "org.freedesktop.Telepathy.AccountManager", then for each object path in the resulting list of accounts, grab the "Enabled" property.
The mess of multiple callbacks however makes me sad, as it makes the flow very difficult to follow. It also took me several hours before I realised the reason I wasn't getting anything back was because I wasn't running the glib main loop.
For context, this is a tiny console app I'm using to develop this section of functionality before I move it across into the main GUI app. Hence my initial confusion at needing an event loop....(and because of the event loop I still haven't found a decent way of terminating the thing when it's finished executing....even before I realised I couldn't tell when all my callbacks were complete).
So I guess the tracking the manually tracking counts of things aka. book-keeping is the way forward. A shame, I was kinda hoping for another callback for "all done".
![]() |
2011-06-17
, 23:15
|
Posts: 249 |
Thanked: 277 times |
Joined on May 2010
@ Brighton, UK
|
#5
|
#include <QtDBus/QtDBus>
#include <QDebug>
#include <QtCore/QCoreApplication>
#include <telepathy-glib/interfaces.h>
const char * TP_PATH_ACCOUNT_MANAGER("/org/freedesktop/Telepathy/AccountManager");
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QDBusInterface tpAccountManagerApp(
TP_IFACE_ACCOUNT_MANAGER,
TP_PATH_ACCOUNT_MANAGER,
TP_IFACE_DBUS_PROPERTIES);
if (tpAccountManagerApp.isValid())
{
QDBusMessage accountList = tpAccountManagerApp.call(
"Get",
TP_IFACE_ACCOUNT_MANAGER,
"ValidAccounts");
foreach (QVariant arg, accountList.arguments())
{
QDBusArgument argument(qvariant_cast<QDBusVariant>(arg).variant().value<QDBusArgument>());
argument.beginArray();
while (!argument.atEnd())
{
// Grab the account path
QDBusObjectPath objectPath;
argument >> objectPath;
//Grab the enabled property of each account
QDBusInterface tpAccount(
TP_IFACE_ACCOUNT_MANAGER,
objectPath.path(),
TP_IFACE_DBUS_PROPERTIES);
if (tpAccount.isValid())
{
QDBusReply<QVariant> isEnabledProp = tpAccount.call(
"Get",
TP_IFACE_ACCOUNT,
"Enabled");
qDebug() << (isEnabledProp.value().toBool() ? "Enabled:\t\t" : "Not enabled:\t") << objectPath.path();
}
}
argument.endArray();
}
}
return a.exec();
}
Enabled: "/org/freedesktop/Telepathy/Account/ring/tel/ring" Not enabled: "/org/freedesktop/Telepathy/Account/gabble/jabber/jamierocks_40gmail_2ecom0" Enabled: "/org/freedesktop/Telepathy/Account/sofiasip/sip/_373023190" Not enabled: "/org/freedesktop/Telepathy/Account/sofiasip/sip/_33888389_40sipgate_2eco_2euk0" Not enabled: "/org/freedesktop/Telepathy/Account/gabble/jabber/jamie_40jabber_2ejamie_2dthompson_2eco_2euk0" Not enabled: "/org/freedesktop/Telepathy/Account/gabble/jabber/qwerki_40chat_2efacebook_2ecom0" QDBusArgument: write from a read-only object
Easy-peesy. DBus query to grab the state, DBus calls to disable them all, then DBus calls to restore the saved values.
Thing is, the version of Telepathy in the QtCreator SDK seems quite old, and doesn't have the convenience methods for getting and setting the DBus properties, so you have to use the generic DBus property methods.
My issue is that I've been mostly using Qt up to this point, with just a sprinkling of glib thrown in as required, so I have no idea if I'm missing something fundamental. The blocking calls (tp_cli_dbus_properties_run_get) are deprecated, and the async calls (tp_cli_dbus_properties_call_get) run from the event loop. Thus, the callbacks fire when the reply is received, but I've no idea what the correct way is to determine when this has completed.
It essentially becomes a bit more complicated due to the fact that there are two callbacks involved; the first to identify the accounts, and the second group are set up from that callback for each account to query the property values. I can (IMHO) bodge it by noting the number of accounts returned, and then waiting until I have that many property callbacks fired...but this seems a poor way of doing things, and I'm sure I must be missing something...
...any ideas?
Last edited by mr_jrt; 2011-06-17 at 13:25.