From 6096697e8607c2330f955d3a74e4d0fa87e47310 Mon Sep 17 00:00:00 2001
From: Jose Luis Perez Diez <jluis@escomposlinux.org>
Date: Fri, 2 Oct 2009 12:40:48 +0200
Subject: [PATCH] Added support to opimd contacts
---
src/zhone | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 103 insertions(+), 5 deletions(-)
diff --git a/src/zhone b/src/zhone
index 992e1fb..04d4f23 100755
|
a
|
b
|
class pyphone_contacts(edje_group): |
| 667 | 667 | self.selected = None |
| 668 | 668 | |
| 669 | 669 | self.part_text_set( "label_action_dial", _("dial") ) |
| | 670 | |
| | 671 | def Opim( self, reference ): |
| | 672 | return Interface( |
| | 673 | dbus_object.bus.get_object( |
| | 674 | 'org.freesmartphone.opimd', |
| | 675 | '/org/freesmartphone/PIM/Contacts'+reference |
| | 676 | ), |
| | 677 | 'org.freesmartphone.PIM.Contact' |
| | 678 | ) |
| 670 | 679 | |
| 671 | 680 | def cbNameEdit( self, name, reference ): |
| 672 | 681 | for i in range( len( self.phonebook ) ): |
| 673 | 682 | if self.phonebook[i][0] == reference: |
| 674 | 683 | self.phonebook[i] = ( reference, name, self.phonebook[i][2] ) |
| 675 | | if dbus_object.gsm_device_obj: |
| | 684 | if dbus_object.contacts_iface: |
| | 685 | self.Opim(reference).Update({"Name": name}) |
| | 686 | logger.debug('opimd Name changed') |
| | 687 | elif dbus_object.gsm_device_obj: |
| | 688 | logger.debug("Name changed"); |
| 676 | 689 | dbus_object.gsm_sim_iface.StoreEntry( |
| 677 | 690 | "contacts", |
| 678 | 691 | reference, |
| … |
… |
class pyphone_contacts(edje_group): |
| 687 | 700 | for i in range( len( self.phonebook ) ): |
| 688 | 701 | if self.phonebook[i][0] == reference: |
| 689 | 702 | self.phonebook[i] = ( reference, self.phonebook[i][1], number ) |
| 690 | | if dbus_object.gsm_device_obj: |
| | 703 | if dbus_object.contacts_iface: |
| | 704 | self.Opim(reference).Update({"Phone": "tel:"+number}) |
| | 705 | logger.debug("opimd Number changed"); |
| | 706 | elif dbus_object.gsm_device_obj: |
| | 707 | logger.debug("Number changed"); |
| 691 | 708 | dbus_object.gsm_sim_iface.StoreEntry( |
| 692 | 709 | "contacts", |
| 693 | 710 | reference, |
| … |
… |
class pyphone_contacts(edje_group): |
| 716 | 733 | break |
| 717 | 734 | if reference is None: |
| 718 | 735 | return # no space? |
| 719 | | if dbus_object.gsm_device_obj: |
| | 736 | if dbus_object.contacts_iface: |
| | 737 | logger.debug("opimd New contact"); |
| | 738 | reference = dbus_object.contacts_iface.Add( |
| | 739 | {"Name" : name,"Phone" : "tel:"+number} |
| | 740 | ) |
| | 741 | reference = reference[reference.rfind("/"):] |
| | 742 | elif dbus_object.gsm_device_obj: |
| | 743 | lgogger.debug("New contact"); |
| 720 | 744 | dbus_object.gsm_sim_iface.StoreEntry( |
| 721 | 745 | "contacts", |
| 722 | 746 | reference, |
| … |
… |
class pyphone_contacts(edje_group): |
| 730 | 754 | def cbDelete( self, result, reference ): |
| 731 | 755 | if result == "abort": |
| 732 | 756 | return |
| 733 | | if dbus_object.gsm_device_obj: |
| | 757 | if dbus_object.contacts_iface: |
| | 758 | self.Opim(reference).Delete() |
| | 759 | logger.debug("opimd Deleting contact"); |
| | 760 | elif dbus_object.gsm_device_obj: |
| | 761 | logger.debug("Deleting contact SIM"); |
| 734 | 762 | dbus_object.gsm_sim_iface.DeleteEntry( |
| 735 | 763 | "contacts", |
| 736 | 764 | reference |
| … |
… |
class pyphone_contacts(edje_group): |
| 788 | 816 | logger.error( "error while retrieving phonebook %s" % e ) |
| 789 | 817 | self.busy = False |
| 790 | 818 | |
| | 819 | def cbOpimdReplies(self,result): |
| | 820 | if str(result) == result: |
| | 821 | logger.debug("opimd query %s" % result) |
| | 822 | self.query_iface = Interface( |
| | 823 | dbus_object.bus.get_object('org.freesmartphone.opimd',result), |
| | 824 | 'org.freesmartphone.PIM.ContactQuery' |
| | 825 | ) |
| | 826 | self.query_iface.GetResultCount( |
| | 827 | reply_handler= self.cbOpimdReplies, |
| | 828 | error_handler = self.cbPhonebookError |
| | 829 | ) |
| | 830 | elif isinstance(result,int): |
| | 831 | logger.debug("procesing %s opimd contacts" % result) |
| | 832 | self.query_iface.GetMultipleResults( |
| | 833 | result, |
| | 834 | reply_handler = self.cbOpimdReplies, |
| | 835 | error_handler = self.cbPhonebookError |
| | 836 | ) |
| | 837 | else: |
| | 838 | for contact in result: |
| | 839 | try: |
| | 840 | phonenum = contact["Phone"][4:] |
| | 841 | except KeyError: |
| | 842 | phonenum = contact["Cell phone"][4:] |
| | 843 | try: |
| | 844 | name = contact["Name"] |
| | 845 | except KeyError: |
| | 846 | name = "N/A %s" % i |
| | 847 | self.phonebook.append( ( |
| | 848 | str(contact["Path"][contact["Path"].rfind("/"):]), |
| | 849 | str(name), |
| | 850 | str(phonenum) |
| | 851 | )) |
| | 852 | self.query_iface.Dispose() |
| | 853 | self.quier_iface = None |
| | 854 | self.busy = False |
| | 855 | self.phonebook.sort( key = lambda x: x[1].lower() ) |
| | 856 | logger.info( "retrieved phonebook: %s" % self.phonebook ) |
| | 857 | self.ready = True |
| | 858 | self.updateList() |
| | 859 | self.main.groups["main"].targets["contacts"] = True |
| | 860 | self.main.groups["main"].update() |
| | 861 | |
| | 862 | |
| 791 | 863 | def prepare( self ): |
| 792 | 864 | if not self.ready and not self.busy: |
| 793 | | if dbus_object.gsm_device_obj: |
| | 865 | if dbus_object.contacts_iface: |
| | 866 | self.busy = True |
| | 867 | dbus_object.contacts_iface.Query( |
| | 868 | {}, |
| | 869 | reply_handler = self.cbOpimdReplies, |
| | 870 | error_handler=self.cbPhonebookError |
| | 871 | ) |
| | 872 | elif dbus_object.gsm_device_obj: |
| 794 | 873 | logger.info( "retrieving phonebook..." ) |
| 795 | 874 | dbus_object.gsm_sim_iface.RetrievePhonebook( |
| 796 | 875 | "contacts", |
| … |
… |
class DBusObject( object ): |
| 2559 | 2638 | self.gsm_server_obj = None |
| 2560 | 2639 | self.gsm_data_iface = None |
| 2561 | 2640 | |
| | 2641 | self.contacts_iface = None |
| | 2642 | |
| 2562 | 2643 | self.fullinit = False |
| 2563 | 2644 | |
| 2564 | 2645 | def tryGetProxy( self, busname, objname ): |
| … |
… |
class DBusObject( object ): |
| 2674 | 2755 | self.prefs_obj = self.tryGetProxy( 'org.freesmartphone.opreferencesd', '/org/freesmartphone/Preferences' ) |
| 2675 | 2756 | self.prefs_iface = Interface( self.prefs_obj, 'org.freesmartphone.Preferences' ) |
| 2676 | 2757 | logger.debug( "preferences ok: %s" % self.prefs_iface ) |
| | 2758 | |
| | 2759 | #Starting with Contacts |
| | 2760 | #opimd contacts |
| | 2761 | contacts_obj = self.tryGetProxy( |
| | 2762 | 'org.freesmartphone.opimd', |
| | 2763 | '/org/freesmartphone/PIM/Contacts' |
| | 2764 | ) |
| | 2765 | if contacts_obj: |
| | 2766 | self.contacts_iface = Interface( |
| | 2767 | contacts_obj, |
| | 2768 | 'org.freesmartphone.PIM.Contacts' |
| | 2769 | ) |
| | 2770 | logger.info ( 'Using contacts from org.freesmartphone.opimd') |
| | 2771 | elif self.gsm_device_object: |
| | 2772 | logger.info ( 'Using contacts from memory in SIM card' ) |
| | 2773 | else: |
| | 2774 | logger.info ( 'Using contacts harcoded on Zhone') |
| 2677 | 2775 | |
| 2678 | 2776 | logger.debug( "failcount = %d" % failcount ) |
| 2679 | 2777 | if failcount == 0: |