View Single Post
Posts: 44 | Thanked: 186 times | Joined on Apr 2010 @ Worthing, West Sussex, England
#2
Bear with me, this may be long. Most of this information I've found from searching this forum or others. Qt provides methods to help you with this but you do need to setup a few things before you can handle the button.

Start by declaring a couple of slots in your class to handle the half and full button presses:

Code:
public slots:
	void shutter_property_modified(int num_updates, QList<Property> updates);
	void focus_property_modified(int num_updates, QList<Property> updates);
Next you need to define the "Property" type used as a paramter to the slots above:

Code:
struct Property
{
	QString name;
	bool added;
	bool removed;
};
You have to tell Qt about the new Property type and define code to stream it in and out:

Code:
Q_DECLARE_METATYPE(Property)
Q_DECLARE_METATYPE(QList<Property>)

const QDBusArgument & operator<<(QDBusArgument &arg, const Property &change)
{
	arg.beginStructure();
	arg << change.name << change.added << change.removed;
	arg.endStructure();
	return arg;
} 
const QDBusArgument & operator>>(const QDBusArgument &arg, Property &change)
{
	arg.beginStructure();
	arg >> change.name >> change.added >> change.removed;
	arg.endStructure();
	return arg;
}
Register the Property type with Qt. You need to call these functions somewhere in your code.

Code:
	qDBusRegisterMetaType< Property >();
	qDBusRegisterMetaType< QList<Property> >();
Connect the DBus events to our slots:

Code:
#define DBUS_SHUTTER_RELEASE_BUTTON "/org/freedesktop/Hal/devices/platform_cam_launch"
#define DBUS_FOCUS_BUTTON "/org/freedesktop/Hal/devices/platform_cam_focus"

 	QDBusConnection::systemBus().connect(
					QString(),
					DBUS_SHUTTER_RELEASE_BUTTON,
	 				"org.freedesktop.Hal.Device",
                    "PropertyModified",
                    this,
                    SLOT(shutter_property_modified(int, QList<Property>)));
 	QDBusConnection::systemBus().connect(
					QString(),
					DBUS_FOCUS_BUTTON,
	 				"org.freedesktop.Hal.Device",
                    "PropertyModified",
                    this,
                    SLOT(focus_property_modified(int, QList<Property>)));
Then you can define your slot functions:

Code:
void Camera::shutter_property_modified(int num_updates, QList<Property> updates) {
    QDBusInterface propertyInterface("org.freedesktop.Hal",
		DBUS_SHUTTER_RELEASE_BUTTON,
		"org.freedesktop.Hal.Device",
		QDBusConnection::systemBus());
    bool pressed = propertyInterface.call("GetProperty", "button.state.value").arguments().at(0).toBool();
    if (pressed) {
		capture_image();
    }
}

void Camera::focus_property_modified(int num_updates, QList<Property> updates) {
    QDBusInterface propertyInterface("org.freedesktop.Hal",
		DBUS_FOCUS_BUTTON,
		"org.freedesktop.Hal.Device",
		QDBusConnection::systemBus());
    bool pressed = propertyInterface.call("GetProperty", "button.state.value").arguments().at(0).toBool();
    if (pressed) {
		focus();
    }
}
I think that's all!
 

The Following 9 Users Say Thank You to fieldofcows For This Useful Post: