Reply
Thread Tools
Posts: 38 | Thanked: 2 times | Joined on Apr 2010 @ Novosibirsk, Russia
#1
Hello, all!
Somebody knows how to work with camera button in my Qt application? My first thought is to somehow use DBus, I started investigate this solution but by this time no result had received.
Actually I have to know when button is half-pressed and full-pressed. I think it is implemented by some signal`s mechanism, but which one?

ADD:

Looked at DBus by
Code:
dbus-monitor --profile --system
and that what I found in output:
Code:
sig	1273651715	193296	2	/org/freedesktop/DBus	org.freedesktop.DBus	NameAcquired
sig	1273651718	482511	4648	/org/freedesktop/Hal/devices/platform_cam_focus	org.freedesktop.Hal.Device	PropertyModified
sig	1273651718	486661	4649	/org/freedesktop/Hal/devices/platform_cam_focus	org.freedesktop.Hal.Device	Condition
sig	1273651723	712461	4651	/org/freedesktop/Hal/devices/platform_cam_launch	org.freedesktop.Hal.Device	PropertyModified
sig	1273651723	716703	4652	/org/freedesktop/Hal/devices/platform_cam_launch	org.freedesktop.Hal.Device	Condition
sig	1273651726	730558	4654	/org/freedesktop/Hal/devices/platform_cam_launch	org.freedesktop.Hal.Device	PropertyModified
sig	1273651726	735532	4655	/org/freedesktop/Hal/devices/platform_cam_launch	org.freedesktop.Hal.Device	Condition
sig	1273651726	792295	4656	/org/freedesktop/Hal/devices/platform_cam_focus	org.freedesktop.Hal.Device	PropertyModified
sig	1273651726	797788	4657	/org/freedesktop/Hal/devices/platform_cam_focus	org.freedesktop.Hal.Device	Condition
sig	1273651728	600766	722	/org/freedesktop/DBus	org.freedesktop.DBus	NameOwnerChanged
As I understand, this is the answer on the question 'which mechanism is using to send/receive signal from button'?

Last edited by Grinchman; 2010-05-12 at 08:15. Reason: Some features are found
 
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:
Posts: 38 | Thanked: 2 times | Joined on Apr 2010 @ Novosibirsk, Russia
#3
fieldofcows, I want to say 'Thanks' you 1 billion time! =) It was really awesome! I did not expect such complete solution, I was tuned in for a long brainstorming, but You have saved my brains! Thanks, thanks, thanks!!! =)
 
Posts: 44 | Thanked: 186 times | Joined on Apr 2010 @ Worthing, West Sussex, England
#4
Originally Posted by Grinchman View Post
fieldofcows, I want to say 'Thanks' you 1 billion time! =) It was really awesome! I did not expect such complete solution, I was tuned in for a long brainstorming, but You have saved my brains! Thanks, thanks, thanks!!! =)
You're very welcome!

There's one more problem you are going to encounter though which is that when you press the shutter button it will launch the standard camera app. I have found a solution to this but it's not the most elegant. If anyone knows a better way to solve this then I'd love to hear how.

My way involves stopping the camera-ui process when launching the app and restarting it on exit. The problem is that if your app crashes, camera-ui will not be restarted. Of course, your app (and mine) will not crash though...

To disable the default camera app:

Code:
QProcess process;
process.execute("/usr/sbin/dsmetool -k /usr/bin/camera-ui");
And to start it again:
Code:
process.execute("/usr/sbin/dsmetool -t /usr/bin/camera-ui");
 

The Following 3 Users Say Thank You to fieldofcows For This Useful Post:
Posts: 38 | Thanked: 2 times | Joined on Apr 2010 @ Novosibirsk, Russia
#5
Yes, you right! I had already prepared for this problem! =) Standard camera app did not export nothing into DBus, so if no more interface is available, then we have no choice but to stop it as you explained above...
 
Posts: 23 | Thanked: 0 times | Joined on Mar 2010
#6
I have a problem, my camera button is too sensible, and when i shake the phone or when im writing a SMS and i press the buton by mistake the camera pops up. Theres any way to disable the camera button permanently?

/usr/sbin/dsmetool -k /usr/bin/camera-ui

Its works, but not permanently.. I want to use the button only when the camera is ON! Can anyone help me?
 
Posts: 26 | Thanked: 3 times | Joined on Aug 2010 @ Nigeria
#7
Originally Posted by fifthelement89 View Post
I have a problem, my camera button is too sensible, the camera is ON! Can anyone help me?
Hi Fifthelement,

Does this happen when the led of your camera is closed?

Cheers
 
Posts: 23 | Thanked: 0 times | Joined on Mar 2010
#8
Originally Posted by Jude View Post
Hi Fifthelement,

Does this happen when the led of your camera is closed?

Cheers
Yes. Its always happening.. Its so annoying! I just want to use the camera when i have my lens open and ready to shoot.

So i just need something to disable the button for the function of start the camera app. Understand? Because when i want to start the camera i just go to the icon and i open the lens.
 
Posts: 23 | Thanked: 0 times | Joined on Mar 2010
#9
someone help me with this?
 
Posts: 23 | Thanked: 0 times | Joined on Mar 2010
#10
People, please does anyone know how to do this? My camera button is so anoying! Everythime i click it, even when i put the phone on my pocket, the camera starts.. I want to turn off that option.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 02:11.