summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DBus.py66
-rw-r--r--pylock.py14
2 files changed, 77 insertions, 3 deletions
diff --git a/DBus.py b/DBus.py
new file mode 100644
index 0000000..fd964d8
--- /dev/null
+++ b/DBus.py
@@ -0,0 +1,66 @@
+from gi.repository import GLib, Gio
+
+from ctypes import CDLL, POINTER, Structure, CFUNCTYPE, pointer
+from ctypes import c_void_p, c_char_p, c_bool
+from ctypes.util import find_library
+
+from functools import partial
+
+
+dbus_xml = '''
+<node>
+ <interface name="net.universe_factory.Pylock">
+ <method name="Lock"/>
+ </interface>
+</node>
+'''
+
+gio = CDLL(find_library('gio-2.0'))
+
+nodeInfo = Gio.DBusNodeInfo.new_for_xml(dbus_xml)
+interfaceInfo = nodeInfo.lookup_interface('net.universe_factory.Pylock')
+
+METHOD_CALL_FUNC = CFUNCTYPE(None, c_void_p, c_char_p, c_char_p, c_char_p, c_char_p, c_void_p, c_void_p, c_void_p)
+GET_PROPERTY_FUNC = CFUNCTYPE(c_void_p, c_void_p, c_char_p, c_char_p, c_char_p, c_char_p, c_void_p, c_void_p)
+SET_PROPERTY_FUNC = CFUNCTYPE(c_bool, c_void_p, c_char_p, c_char_p, c_char_p, c_char_p, c_void_p, c_void_p, c_void_p)
+
+def method_call(locker, connection, sender, object_path, interface_name, method_name, parameters, invocation, user_data):
+ assert str(method_name, 'ascii') == 'Lock'
+
+ locker.lock()
+ gio.g_dbus_method_invocation_return_value(invocation, hash(GLib.Variant.new_tuple()))
+
+@GET_PROPERTY_FUNC
+def get_property(connection, sender, object_path, interface_name, property_name, error, user_data):
+ assert False
+
+@SET_PROPERTY_FUNC
+def set_property(connection, sender, object_path, interface_name, property_name, value, error, user_data):
+ assert False
+
+class VTable(Structure):
+ _fields_ = [
+ ("method_call", METHOD_CALL_FUNC),
+ ("get_property", GET_PROPERTY_FUNC),
+ ("set_property", SET_PROPERTY_FUNC)
+ ]
+
+ def __init__(self, locker):
+ Structure.__init__(self)
+ self.method_call = METHOD_CALL_FUNC(partial(method_call, locker))
+ self.get_property = get_property
+ self.set_property = set_property
+
+gio.g_dbus_connection_register_object.argtypes = [c_void_p, c_char_p, c_void_p, POINTER(VTable), c_void_p, c_void_p, c_void_p]
+gio.g_dbus_method_invocation_return_value.argtypes = [c_void_p, c_void_p]
+
+
+class DBus(object):
+ def __init__(self, locker):
+ self.vtable = VTable(locker)
+
+ Gio.bus_own_name(Gio.BusType.SESSION, 'net.universe_factory.Pylock', Gio.BusNameOwnerFlags.NONE, self.bus_aquired, None, None)
+
+ def bus_aquired(self, connection, name):
+ b = lambda s: bytes(s, 'ascii')
+ gio.g_dbus_connection_register_object(c_void_p(hash(connection)), b('/net/universe_factory/Pylock'), c_void_p(hash(interfaceInfo)), pointer(self.vtable), None, None, None)
diff --git a/pylock.py b/pylock.py
index cad52fc..6903af5 100644
--- a/pylock.py
+++ b/pylock.py
@@ -6,8 +6,9 @@ import os
import pwd
import locale
-from gi.repository import Gtk, Gdk
+from gi.repository import Gtk, Gdk, Gio
+from DBus import DBus
from Locker import Locker
from LockWindow import LockWindow
import pam
@@ -18,7 +19,7 @@ def get_username():
theme = 'UzL-login'
-timeout = 5
+timeout = 500
logoutTimeout = 15
username = get_username()
@@ -39,8 +40,11 @@ locale.textdomain('pylock')
Gtk.Settings.get_default().set_property('gtk-theme-name', theme)
+
+
window = LockWindow()
+
def lock(timeLeft):
window.updateLockMessage(username, timeLeft)
window.lock()
@@ -51,9 +55,13 @@ def logout():
def updateTimeout(timeLeft):
window.updateLockMessage(username, timeLeft)
+
locker = Locker(timeout, lock, window.unlock, logoutTimeout, logout, updateTimeout)
-pamAuth = pam.pam()
+dbus = DBus(locker)
+
+
+pamAuth = pam.pam()
def tryUnlock(w, password):
if pamAuth.authenticate(username, password):