Test we can connect to udisks before connecting signals and reset the pointer of the interface. Thanks mail@holger-mense.de.

This commit is contained in:
David Sansome 2010-12-25 14:25:05 +00:00
parent 843cd92615
commit ced9a8b6e2

@ -47,20 +47,21 @@ void DeviceKitLister::Init() {
OrgFreedesktopUDisksInterface::staticInterfaceName(), OrgFreedesktopUDisksInterface::staticInterfaceName(),
"/org/freedesktop/UDisks", QDBusConnection::systemBus())); "/org/freedesktop/UDisks", QDBusConnection::systemBus()));
// Listen for changes
connect(interface_.get(), SIGNAL(DeviceAdded(QDBusObjectPath)), SLOT(DBusDeviceAdded(QDBusObjectPath)));
connect(interface_.get(), SIGNAL(DeviceRemoved(QDBusObjectPath)), SLOT(DBusDeviceRemoved(QDBusObjectPath)));
connect(interface_.get(), SIGNAL(DeviceChanged(QDBusObjectPath)), SLOT(DBusDeviceChanged(QDBusObjectPath)));
// Get all the devices currently attached // Get all the devices currently attached
QDBusPendingReply<QList<QDBusObjectPath> > reply = interface_->EnumerateDevices(); QDBusPendingReply<QList<QDBusObjectPath> > reply = interface_->EnumerateDevices();
reply.waitForFinished(); reply.waitForFinished();
if (!reply.isValid()) { if (!reply.isValid()) {
qWarning() << "Error enumerating DeviceKit-disks devices:" << reply.error().name() << reply.error().message(); qWarning() << "Error enumerating DeviceKit-disks devices:" << reply.error().name() << reply.error().message();
interface_.reset();
return; return;
} }
// Listen for changes
connect(interface_.get(), SIGNAL(DeviceAdded(QDBusObjectPath)), SLOT(DBusDeviceAdded(QDBusObjectPath)));
connect(interface_.get(), SIGNAL(DeviceRemoved(QDBusObjectPath)), SLOT(DBusDeviceRemoved(QDBusObjectPath)));
connect(interface_.get(), SIGNAL(DeviceChanged(QDBusObjectPath)), SLOT(DBusDeviceChanged(QDBusObjectPath)));
// Get information about each one // Get information about each one
QMap<QString, DeviceData> device_data; QMap<QString, DeviceData> device_data;
foreach (const QDBusObjectPath& path, reply.value()) { foreach (const QDBusObjectPath& path, reply.value()) {