1 /* This file is part of Cinaest.
3 * Copyright (C) 2009 Philipp Zabel
5 * Cinaest is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Cinaest is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
19 public class Orientation : Object {
22 public signal void changed ();
23 private DBus.Connection conn;
24 private dynamic DBus.Object mce_request;
25 private dynamic DBus.Object mce_signal;
26 private dynamic DBus.Object hal_slide;
27 private const string MCE_SERVICE = "com.nokia.mce";
28 private const string MCE_REQUEST_PATH = "/com/nokia/mce/request";
29 private const string MCE_SIGNAL_PATH = "/com/nokia/mce/signal";
30 private const string MCE_REQUEST_IF = "com.nokia.mce.request";
31 private const string MCE_SIGNAL_IF = "com.nokia.mce.signal";
32 private const string HAL_SERVICE = "org.freedesktop.Hal";
33 private const string HAL_SLIDE_PATH = "/org/freedesktop/Hal/devices/platform_slide";
34 private const string HAL_DEVICE_IF = "org.freedesktop.Hal.Device";
39 conn = DBus.Bus.get (DBus.BusType.SYSTEM);
41 mce_request = conn.get_object (MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF);
42 mce_enable_accelerometer ();
44 mce_signal = conn.get_object (MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF);
45 mce_signal.sig_device_orientation_ind += on_mce_orientation_changed;
47 hal_slide = conn.get_object (HAL_SERVICE, HAL_SLIDE_PATH, HAL_DEVICE_IF);
48 hal_slide.Condition += on_hal_slide_condition;
49 bool closed = hal_slide.GetPropertyBoolean ("button.state.value");
52 stderr.printf ("Error: %s\n", e.message);
56 private void mce_enable_accelerometer () {
57 string orientation, stand, face;
60 mce_request.req_accelerometer_enable (out orientation, out stand, out face, out x, out y, out z);
61 on_mce_orientation_changed (mce_request, orientation, stand, face, x, y, z);
64 private void on_mce_orientation_changed (dynamic DBus.Object bluez, string orientation,
65 string stand, string face, int x, int y , int z) {
66 portrait = (orientation == "portrait" & !keyboard);
70 private void on_hal_slide_condition (dynamic DBus.Object slide, string cond_name, string cond_details) {
71 if (cond_name == "ButtonPressed" && cond_details == "cover") {
72 bool closed = hal_slide.GetPropertyBoolean ("button.state.value");