1 /* This file is part of Beifahrer.
3 * Copyright (C) 2010 Philipp Zabel
5 * Beifahrer 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 * Beifahrer 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 Beifahrer. If not, see <http://www.gnu.org/licenses/>.
19 public class Orientation : Object {
20 private const string MCE_SERVICE = "com.nokia.mce";
21 private const string MCE_REQUEST_PATH = "/com/nokia/mce/request";
22 private const string MCE_SIGNAL_PATH = "/com/nokia/mce/signal";
23 private const string MCE_REQUEST_IF = "com.nokia.mce.request";
24 private const string MCE_SIGNAL_IF = "com.nokia.mce.signal";
26 private const string HAL_SERVICE = "org.freedesktop.Hal";
27 private const string HAL_SLIDE_PATH = "/org/freedesktop/Hal/devices/platform_slide";
28 private const string HAL_DEVICE_IF = "org.freedesktop.Hal.Device";
32 private DBus.Connection conn;
33 private dynamic DBus.Object mce_request;
34 private dynamic DBus.Object mce_signal;
35 private dynamic DBus.Object hal_slide;
37 public signal void changed ();
42 conn = DBus.Bus.get (DBus.BusType.SYSTEM);
44 mce_request = conn.get_object (MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF);
45 mce_enable_accelerometer ();
47 mce_signal = conn.get_object (MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF);
48 mce_signal.sig_device_orientation_ind += on_mce_orientation_changed;
50 hal_slide = conn.get_object (HAL_SERVICE, HAL_SLIDE_PATH, HAL_DEVICE_IF);
51 hal_slide.Condition += on_hal_slide_condition;
52 bool closed = hal_slide.GetPropertyBoolean ("button.state.value");
55 stderr.printf ("Error: %s\n", e.message);
59 private void mce_enable_accelerometer () {
60 string orientation, stand, face;
63 mce_request.req_accelerometer_enable (out orientation, out stand, out face, out x, out y, out z);
64 on_mce_orientation_changed (mce_request, orientation, stand, face, x, y, z);
67 private void on_mce_orientation_changed (dynamic DBus.Object mce, string orientation,
68 string stand, string face, int x, int y , int z) {
69 portrait = (orientation == "portrait" & !keyboard);
73 private void on_hal_slide_condition (dynamic DBus.Object slide, string cond_name, string cond_details) {
74 if (cond_name == "ButtonPressed" && cond_details == "cover") {
75 bool closed = hal_slide.GetPropertyBoolean ("button.state.value");