#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2008 # Pietro Montorfano # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 3 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. import elementary import dbus, e_dbus import time import evas import os TITLE = "Notifier" DIALER_ICON = "/usr/share/icons/shr/86x86/apps/openmoko-dialer.png" MESSAGES_ICON = "/usr/share/icons/shr/86x86/apps/openmoko-messages.png" MISSED_CALLS_PROGRAM = "/usr/bin/phonelog" MISSED_SMS_PROGRAM = "/usr/bin/openmoko-messages" SMS_1 = " unread message" SMS_2 = " unread messages" CALL_1 = " missed call" CALL_2 = " missed calls" USAGE_BUSNAME = 'org.freesmartphone.ousaged' USAGE_OBJECTPATH = '/org/freesmartphone/Usage' USAGE_INTERFACE = 'org.freesmartphone.Usage' GSM_BUSNAME = 'org.freesmartphone.ogsmd' GSM_OBJECTPATH = '/org/freesmartphone/GSM/Device' GSM_SIM_INTERFACE = 'org.freesmartphone.GSM.SIM' GSM_CALL_INTERFACE = 'org.freesmartphone.GSM.Call' SECONDS_FOR_RETRY = 5 system_bus = None gsm_bus = None gsm_message_iface = None gsm_sim_iface = None gsm_call_iface = None usage_bus = None usage_iface = None call_active = "" missed_calls = {} missed_sms = 0 ### UI functions def update_ui(): lost_call_count = 0 for (key, value) in missed_calls.iteritems(): lost_call_count += len(value) if (lost_call_count == 1): bt_calls.label_set(str(lost_call_count) + CALL_1) bt_calls.show() elif (lost_call_count > 1): bt_calls.label_set(str(lost_call_count) + CALL_2) bt_calls.show() else: bt_calls.hide() if (missed_sms == 1): bt_sms.label_set(str(missed_sms) + SMS_1) bt_sms.show() elif (missed_sms > 1): bt_sms.label_set(str(missed_sms) + SMS_2) bt_sms.show() else: bt_sms.hide() if ((missed_sms == 0) and ((lost_call_count == 0) or (missed_calls == {}))): win.hide() else: win.show() ## here's the main function, using args so that it doesn't crash even if new parameters will be added def call_signal_handler(sender = "", *args, **kwargs): global call_active call_status = str(args[0]) if (args[1].has_key("peer")): caller = str(args[1]["peer"]) else: caller = call_active if (call_status == "incoming"): call_active = caller elif ((call_status == "active") and (call_active != "")): call_active = "" elif ((call_status == "release") and (call_active != "")): if (missed_calls.has_key(call_active)): missed_calls[call_active].append(time.time()) else: missed_calls[call_active] = [time.time()] update_ui() def sms_signal_handler(*args, **kwargs): global missed_sms missed_sms += 1 update_ui() ## elementary standard signal def destroy(obj = None, event = None, data = ""): global missed_calls global missed_sms missed_calls.clear() missed_sms = 0 win.hide() def show_missed_calls(*args, **kwargs): global missed_calls missed_calls = {} update_ui() os.system(MISSED_CALLS_PROGRAM + " &") def show_missed_sms(*args, **kwargs): global missed_sms missed_sms = 0 update_ui() os.system(MISSED_SMS_PROGRAM + " &") if __name__ == "__main__": initialized = False while (not initialized): try: elementary.init() ### setting up the dbus and all the interfaces that we need dbus_loop = e_dbus.DBusEcoreMainLoop() system_bus = dbus.SystemBus(mainloop = dbus_loop) gsm_bus = system_bus.get_object(GSM_BUSNAME, GSM_OBJECTPATH) gsm_call_iface = dbus.Interface(gsm_bus, GSM_CALL_INTERFACE) gsm_sim_iface = dbus.Interface(gsm_bus, GSM_SIM_INTERFACE) ### Actually we only need to listen for incoming calls gsm_call_iface.connect_to_signal("CallStatus", call_signal_handler) gsm_sim_iface.connect_to_signal("IncomingStoredMessage", sms_signal_handler) initialized = True print "Let's go on" except: time.sleep(SECONDS_FOR_RETRY) initialized = False print "Retrying..." ### Now that dbus it's ok lets build the UI win = elementary.Window(TITLE, elementary.ELM_WIN_BASIC) win.title_set(TITLE) win.destroy = destroy bg = elementary.Background(win) win.resize_object_add(bg) bg.size_hint_weight_set(0.0, 0.0) bg.size_hint_align_set(-1.0, -1.0) bg.show() box_main = elementary.Box(win) box_main.size_hint_weight_set(0.0, 0.0) box_main.size_hint_align_set(-1.0, -1.0) win.resize_object_add(box_main) box_main.show() bt_calls = elementary.Button(win) bt_calls.label_set(CALL_1) bt_calls.size_hint_weight_set(0.0, 0.0) bt_calls.size_hint_align_set(-1.0, -1.0) bt_calls_icon = elementary.Icon(bt_calls) bt_calls_icon.file_set(DIALER_ICON) bt_calls_icon.size_hint_aspect_set(evas.EVAS_ASPECT_CONTROL_VERTICAL, 1, 1) bt_calls.icon_set(bt_calls_icon) box_main.pack_end(bt_calls) bt_calls.clicked = show_missed_calls bt_calls.show() bt_sms = elementary.Button(win) bt_sms.label_set(SMS_1) bt_sms.size_hint_weight_set(0.0, 0.0) bt_sms.size_hint_align_set(-1.0, -1.0) bt_sms_icon = elementary.Icon(bt_sms) bt_sms_icon.file_set(MESSAGES_ICON) bt_sms_icon.size_hint_aspect_set(evas.EVAS_ASPECT_CONTROL_VERTICAL, 1, 1) bt_sms.icon_set(bt_sms_icon) box_main.pack_end(bt_sms) bt_sms.clicked = show_missed_sms bt_sms.show() ### ok, let's go!! elementary.run() elementary.shutdown()