1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2014 Canonical
4
# This file is part of messaging-app.
6
# messaging-app is free software: you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License version 3, as published
8
# by the Free Software Foundation.
16
def receive_sms(sender, text):
17
"""Receive an SMS based on sender number and text
19
:parameter sender: phone number the message is from
20
:parameter text: text you want to send in the message
23
# prepare and send a Qt GUI script to phonesim, over its private D-BUS
24
# set up by ofono-phonesim-autostart
25
script_dir = tempfile.mkdtemp(prefix="phonesim_script")
26
os.chmod(script_dir, 0o755)
27
with open(os.path.join(script_dir, "sms.js"), "w") as f:
28
f.write("""tabSMS.gbMessage1.leMessageSender.text = "%s";
29
tabSMS.gbMessage1.leSMSClass.text = "1";
30
tabSMS.gbMessage1.teSMSText.setPlainText("%s");
31
tabSMS.gbMessage1.pbSendSMSMessage.click();
34
with open("/run/lock/ofono-phonesim-dbus.address") as f:
35
phonesim_bus = f.read().strip()
36
bus = dbus.bus.BusConnection(phonesim_bus)
37
script_proxy = bus.get_object("org.ofono.phonesim", "/")
38
script_proxy.SetPath(script_dir)
39
script_proxy.Run("sms.js")
40
shutil.rmtree(script_dir)