Misc cleanup, test code, and debug help
authorEd Page <eopage@byu.net>
Mon, 26 Jul 2010 16:08:44 +0000 (11:08 -0500)
committerEd Page <eopage@byu.net>
Mon, 26 Jul 2010 16:09:22 +0000 (11:09 -0500)
src/autogv.py
src/debugger.py [new file with mode: 0755]
src/gvoice/__init__.py
src/gvoice/addressbook.py
src/gvoice/conversations.py

index fee55f4..0ebefea 100644 (file)
@@ -85,10 +85,11 @@ class NewGVConversations(object):
 class RefreshVoicemail(object):
 
        def __init__(self, connRef):
+               self._isStarted = False
                self._connRef = connRef
+
                self._newChannelSignaller = telepathy_utils.NewChannelSignaller(self._on_new_channel)
                self._outstandingRequests = []
-               self._isStarted = False
 
        def start(self):
                self._newChannelSignaller.start()
@@ -143,6 +144,78 @@ class RefreshVoicemail(object):
                self._outstandingRequests.remove(missDetection)
 
 
+class AutoAcceptGVCall(object):
+
+       def __init__(self, connRef):
+               self._connRef = connRef
+               self._isStarted = False
+               self._incomingCall = False
+               self._incomingChannel = False
+
+               self._newChannelSignaller = telepathy_utils.NewChannelSignaller(self._on_new_channel)
+
+               self._bus = dbus.SystemBus()
+               self._bus.add_signal_receiver(
+                       self._on_incoming,
+                       path='/com/nokia/csd/call',
+                       dbus_interface='com.nokia.csd.Call',
+                       signal_name='Coming'
+               )
+               self._callObject = self._bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
+               self._callInstance = dbus.Interface(self._callObject, 'com.nokia.csd.Call.Instance')
+
+       def start(self):
+               self._newChannelSignaller.start()
+               self._isStarted = True
+
+       def stop(self):
+               if not self._isStarted:
+                       _moduleLogger.info("auto-accept monitor stopped without starting")
+                       return
+               _moduleLogger.info("Stopping auto-accepting")
+               self._newChannelSignaller.stop()
+
+               self._incomingCall = False
+               self._incomingChannel = False
+               self._isStarted = False
+
+       @misc_utils.log_exception(_moduleLogger)
+       def _on_new_channel(self, bus, serviceName, connObjectPath, channelObjectPath, channelType):
+               if channelType != telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA:
+                       return
+
+               cmName = telepathy_utils.cm_from_path(connObjectPath)
+               if cmName == constants._telepathy_implementation_name_:
+                       _moduleLogger.debug("Ignoring channels from self to prevent deadlock")
+                       return
+
+               conn = telepathy.client.Connection(serviceName, connObjectPath)
+               try:
+                       chan = telepathy.client.Channel(serviceName, channelObjectPath)
+               except dbus.exceptions.UnknownMethodException:
+                       _moduleLogger.exception("Client might not have implemented a deprecated method")
+                       return
+
+               chan[telepathy.interfaces.CHANNEL].connect_to_signal(
+                       "Closed",
+                       self._on_closed,
+               )
+
+               self._incomingChannel = True
+               self._accept_if_ready()
+
+       @misc_utils.log_exception(_moduleLogger)
+       def _on_incoming(self, objPath, callerNumber):
+               if self._isStarted:
+                       self._incomingCall = True
+                       self._accept_if_ready()
+
+       @misc_utils.log_exception(_moduleLogger)
+       def _on_closed(self):
+               self._incomingCall = False
+               self._incomingChannel = False
+
+
 class TimedDisconnect(object):
 
        def __init__(self, connRef):
diff --git a/src/debugger.py b/src/debugger.py
new file mode 100755 (executable)
index 0000000..a5094dc
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+import gvoice
+
+
+def main(args):
+       if args[0] == "messages":
+               gvoice.conversations.print_conversations(args[1])
+       elif args[0] == "contacts":
+               gvoice.addressbook.print_addressbook(args[1])
+       else:
+               print "Huh?"
+
+
+if __name__ == "__main__":
+       import sys
+       main(sys.argv[1:])
index afabc11..2681021 100644 (file)
@@ -1,5 +1,4 @@
 #!/usr/bin/python
 
-import backend
 import addressbook
 import session
index 5d29a06..33f514a 100644 (file)
@@ -146,3 +146,16 @@ class Addressbook(object):
                                for (number, phoneType) in contactNumbers
                        )
                return numbers
+
+
+def print_addressbook(path):
+       import pprint
+
+       try:
+               with open(path, "rb") as f:
+                       fileVersion, fileBuild, contacts = pickle.load(f)
+       except (pickle.PickleError, IOError, EOFError, ValueError):
+               _moduleLogger.exception("")
+       else:
+               pprint.pprint((fileVersion, fileBuild))
+               pprint.pprint(contacts)
index d6edcb7..58b3c03 100644 (file)
@@ -286,3 +286,18 @@ class FilterOutReported(object):
                if filteredConversations and self._lastMessageTimestamp < filteredConversations[0].time:
                        self._lastMessageTimestamp = filteredConversations[0].time
                return filteredConversations
+
+
+def print_conversations(path):
+       import pprint
+
+       try:
+               with open(path, "rb") as f:
+                       fileVersion, fileBuild, convs = pickle.load(f)
+       except (pickle.PickleError, IOError, EOFError, ValueError):
+               _moduleLogger.exception("")
+       else:
+               for key, value in convs.iteritems():
+                       convs[key] = value.to_dict()
+               pprint.pprint((fileVersion, fileBuild))
+               pprint.pprint(convs)