Package updated to version mafw-gst-renderer-0.2.2010.07-2+0m5-1.
[mafwsubrenderer] / libmafw-gst-renderer / keypad.c
1 /*
2  * This file is a part of MAFW
3  *
4  * Copyright (C) 2007, 2008, 2009 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Visa Smolander <visa.smolander@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24  
25 #include <glib.h>
26 #include <mce/dbus-names.h>
27 #include <dbus/dbus.h>
28 #include "keypad.h"
29
30
31 #define KEYPAD_TIMER_INTERVAL 50
32
33 static guint toutid;
34
35 void keypadlocking_allow(void)
36 {
37         if (toutid)
38         {
39                 g_source_remove(toutid);
40                 toutid = 0;
41         }
42 }
43
44 static gboolean no_keylock_timeout(gpointer udata)
45 {
46         static DBusMessage *msg = NULL;
47         static DBusConnection *sysbus = NULL;
48
49         if (!sysbus)
50         {
51                 DBusError err;
52
53                 dbus_error_init(&err);
54                 sysbus = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
55                 g_assert(sysbus);
56                 g_assert(!dbus_error_is_set(&err));
57         }
58         if (!msg)
59         {
60                 msg = dbus_message_new_method_call(MCE_SERVICE,
61                                 MCE_REQUEST_PATH, MCE_REQUEST_IF,
62                                 MCE_PREVENT_KEYPAD_OFF_REQ);
63                 g_assert(msg);
64         }
65         g_assert(dbus_connection_send(sysbus, msg,NULL));
66         dbus_connection_flush(sysbus);
67         return TRUE;
68 }
69
70 void keypadlocking_prohibit(void)
71 {
72         if (!toutid)
73         {
74                 toutid = g_timeout_add_seconds(KEYPAD_TIMER_INTERVAL,
75                                               no_keylock_timeout,
76                                               NULL);
77                 no_keylock_timeout(NULL);
78         }
79 }