Bump to 1.3.6
[gc-dialer] / src / session.py
index 8a97f4e..dbdc3e4 100644 (file)
@@ -12,7 +12,8 @@ try:
 except ImportError:
        import pickle
 
-from PyQt4 import QtCore
+import util.qt_compat as qt_compat
+QtCore = qt_compat.QtCore
 
 from util import qore_utils
 from util import qui_utils
@@ -37,21 +38,21 @@ class _DraftContact(object):
 
 class Draft(QtCore.QObject):
 
-       sendingMessage = QtCore.pyqtSignal()
-       sentMessage = QtCore.pyqtSignal()
-       calling = QtCore.pyqtSignal()
-       called = QtCore.pyqtSignal()
-       cancelling = QtCore.pyqtSignal()
-       cancelled = QtCore.pyqtSignal()
-       error = QtCore.pyqtSignal(str)
+       sendingMessage = qt_compat.Signal()
+       sentMessage = qt_compat.Signal()
+       calling = qt_compat.Signal()
+       called = qt_compat.Signal()
+       cancelling = qt_compat.Signal()
+       cancelled = qt_compat.Signal()
+       error = qt_compat.Signal(str)
 
-       recipientsChanged = QtCore.pyqtSignal()
+       recipientsChanged = qt_compat.Signal()
 
-       def __init__(self, pool, backend, errorLog):
+       def __init__(self, asyncQueue, backend, errorLog):
                QtCore.QObject.__init__(self)
                self._errorLog = errorLog
                self._contacts = {}
-               self._pool = pool
+               self._asyncQueue = asyncQueue
                self._backend = backend
                self._busyReason = None
                self._message = ""
@@ -60,7 +61,7 @@ class Draft(QtCore.QObject):
                assert 0 < len(self._contacts), "No contacts selected"
                assert 0 < len(self._message), "No message to send"
                numbers = [misc_utils.make_ugly(contact.selectedNumber) for contact in self._contacts.itervalues()]
-               le = concurrent.AsyncLinearExecution(self._pool, self._send)
+               le = self._asyncQueue.add_async(self._send)
                le.start(numbers, self._message)
 
        def call(self):
@@ -68,11 +69,11 @@ class Draft(QtCore.QObject):
                assert len(self._message) == 0, "Cannot send message with call"
                (contact, ) = self._contacts.itervalues()
                number = misc_utils.make_ugly(contact.selectedNumber)
-               le = concurrent.AsyncLinearExecution(self._pool, self._call)
+               le = self._asyncQueue.add_async(self._call)
                le.start(number)
 
        def cancel(self):
-               le = concurrent.AsyncLinearExecution(self._pool, self._cancel)
+               le = self._asyncQueue.add_async(self._cancel)
                le.start()
 
        def _get_message(self):
@@ -197,20 +198,21 @@ class Draft(QtCore.QObject):
 class Session(QtCore.QObject):
 
        # @todo Somehow add support for csv contacts
+       # @BUG When loading without caches, downloads messages twice
 
-       stateChange = QtCore.pyqtSignal(str)
-       loggedOut = QtCore.pyqtSignal()
-       loggedIn = QtCore.pyqtSignal()
-       callbackNumberChanged = QtCore.pyqtSignal(str)
+       stateChange = qt_compat.Signal(str)
+       loggedOut = qt_compat.Signal()
+       loggedIn = qt_compat.Signal()
+       callbackNumberChanged = qt_compat.Signal(str)
 
-       accountUpdated = QtCore.pyqtSignal()
-       messagesUpdated = QtCore.pyqtSignal()
-       newMessages = QtCore.pyqtSignal()
-       historyUpdated = QtCore.pyqtSignal()
-       dndStateChange = QtCore.pyqtSignal(bool)
-       voicemailAvailable = QtCore.pyqtSignal(str, str)
+       accountUpdated = qt_compat.Signal()
+       messagesUpdated = qt_compat.Signal()
+       newMessages = qt_compat.Signal()
+       historyUpdated = qt_compat.Signal()
+       dndStateChange = qt_compat.Signal(bool)
+       voicemailAvailable = qt_compat.Signal(str, str)
 
-       error = QtCore.pyqtSignal(str)
+       error = qt_compat.Signal(str)
 
        LOGGEDOUT_STATE = "logged out"
        LOGGINGIN_STATE = "logging in"
@@ -220,15 +222,21 @@ class Session(QtCore.QObject):
        MESSAGE_VOICEMAILS = "Voicemail"
        MESSAGE_ALL = "All"
 
+       HISTORY_RECEIVED = "Received"
+       HISTORY_MISSED = "Missed"
+       HISTORY_PLACED = "Placed"
+       HISTORY_ALL = "All"
+
        _OLDEST_COMPATIBLE_FORMAT_VERSION = misc_utils.parse_version("1.3.0")
 
        _LOGGEDOUT_TIME = -1
        _LOGGINGIN_TIME = 0
 
-       def __init__(self, errorLog, cachePath = None):
+       def __init__(self, errorLog, cachePath):
                QtCore.QObject.__init__(self)
                self._errorLog = errorLog
-               self._pool = qore_utils.AsyncPool()
+               self._pool = qore_utils.FutureThread()
+               self._asyncQueue = concurrent.AsyncTaskQueue(self._pool)
                self._backend = []
                self._loggedInTime = self._LOGGEDOUT_TIME
                self._loginOps = []
@@ -236,7 +244,7 @@ class Session(QtCore.QObject):
                self._voicemailCachePath = None
                self._username = None
                self._password = None
-               self._draft = Draft(self._pool, self._backend, self._errorLog)
+               self._draft = Draft(self._asyncQueue, self._backend, self._errorLog)
                self._delayedRelogin = QtCore.QTimer()
                self._delayedRelogin.setInterval(0)
                self._delayedRelogin.setSingleShot(True)
@@ -277,7 +285,7 @@ class Session(QtCore.QObject):
                        self._backend[0:0] = [gv_backend.GVDialer(cookiePath)]
 
                self._pool.start()
-               le = concurrent.AsyncLinearExecution(self._pool, self._login)
+               le = self._asyncQueue.add_async(self._login)
                le.start(username, password)
 
        def logout(self):
@@ -310,11 +318,11 @@ class Session(QtCore.QObject):
        def update_account(self, force = True):
                if not force and self._contacts:
                        return
-               le = concurrent.AsyncLinearExecution(self._pool, self._update_account), (), {}
+               le = self._asyncQueue.add_async(self._update_account), (), {}
                self._perform_op_while_loggedin(le)
 
        def refresh_connection(self):
-               le = concurrent.AsyncLinearExecution(self._pool, self._refresh_authentication)
+               le = self._asyncQueue.add_async(self._refresh_authentication)
                le.start()
 
        def get_contacts(self):
@@ -326,7 +334,7 @@ class Session(QtCore.QObject):
        def update_messages(self, messageType, force = True):
                if not force and self._messages:
                        return
-               le = concurrent.AsyncLinearExecution(self._pool, self._update_messages), (messageType, ), {}
+               le = self._asyncQueue.add_async(self._update_messages), (messageType, ), {}
                self._perform_op_while_loggedin(le)
 
        def get_messages(self):
@@ -335,10 +343,10 @@ class Session(QtCore.QObject):
        def get_when_messages_updated(self):
                return self._messageUpdateTime
 
-       def update_history(self, force = True):
+       def update_history(self, historyType, force = True):
                if not force and self._history:
                        return
-               le = concurrent.AsyncLinearExecution(self._pool, self._update_history), (), {}
+               le = self._asyncQueue.add_async(self._update_history), (historyType, ), {}
                self._perform_op_while_loggedin(le)
 
        def get_history(self):
@@ -348,11 +356,11 @@ class Session(QtCore.QObject):
                return self._historyUpdateTime
 
        def update_dnd(self):
-               le = concurrent.AsyncLinearExecution(self._pool, self._update_dnd), (), {}
+               le = self._asyncQueue.add_async(self._update_dnd), (), {}
                self._perform_op_while_loggedin(le)
 
        def set_dnd(self, dnd):
-               le = concurrent.AsyncLinearExecution(self._pool, self._set_dnd)
+               le = self._asyncQueue.add_async(self._set_dnd)
                le.start(dnd)
 
        def is_available(self, messageId):
@@ -366,7 +374,7 @@ class Session(QtCore.QObject):
                return actualPath
 
        def download_voicemail(self, messageId):
-               le = concurrent.AsyncLinearExecution(self._pool, self._download_voicemail)
+               le = self._asyncQueue.add_async(self._download_voicemail)
                le.start(messageId)
 
        def _set_dnd(self, dnd):
@@ -404,7 +412,7 @@ class Session(QtCore.QObject):
                return self._callback
 
        def set_callback_number(self, callback):
-               le = concurrent.AsyncLinearExecution(self._pool, self._set_callback_number)
+               le = self._asyncQueue.add_async(self._set_callback_number)
                le.start(callback)
 
        def _set_callback_number(self, callback):
@@ -689,13 +697,13 @@ class Session(QtCore.QObject):
                self.messagesUpdated.emit()
                self._alert_on_messages(self._messages)
 
-       def _update_history(self):
+       def _update_history(self, historyType):
                try:
                        assert self.state == self.LOGGEDIN_STATE, "History requires being logged in (currently %s" % self.state
-                       with qui_utils.notify_busy(self._errorLog, "Updating History"):
+                       with qui_utils.notify_busy(self._errorLog, "Updating '%s' History" % historyType):
                                self._history = yield (
-                                       self._backend[0].get_recent,
-                                       (),
+                                       self._backend[0].get_call_history,
+                                       (historyType, ),
                                        {},
                                )
                except Exception, e: