PySide Bug Reproduction: Bringing code inline with how DC does things
[gc-dialer] / src / dialcentral_qt.py
index d625fb3..4bf128a 100755 (executable)
@@ -10,12 +10,12 @@ import functools
 import logging
 import logging.handlers
 
-from PyQt4 import QtGui
-from PyQt4 import QtCore
+import util.qt_compat as qt_compat
+QtCore = qt_compat.QtCore
+QtGui = qt_compat.import_module("QtGui")
 
 import constants
 import alarm_handler
-import call_handler
 from util import qtpie
 from util import qwrappers
 from util import qui_utils
@@ -127,8 +127,8 @@ class Dialcentral(qwrappers.ApplicationWrapper):
        def _new_main_window(self):
                return MainWindow(None, self)
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_about(self, checked = True):
                with qui_utils.notify_error(self._errorLog):
@@ -269,8 +269,8 @@ class MainWindow(qwrappers.WindowWrapper):
                self._voicemailRefreshDelay.setInterval(30 * 1000)
                self._voicemailRefreshDelay.timeout.connect(self._on_call_missed)
                self._voicemailRefreshDelay.setSingleShot(True)
-               self._callHandler = call_handler.MissedCallWatcher()
-               self._callHandler.callMissed.connect(self._voicemailRefreshDelay.start)
+               self._callHandler = None
+               self._updateVoicemailOnMissedCall = False
 
                self._defaultCredentials = "", ""
                self._curentCredentials = "", ""
@@ -433,6 +433,7 @@ class MainWindow(qwrappers.WindowWrapper):
                        self._app.notifyOnMissed = config.getboolean("2 - Account Info", "notifyOnMissed")
                        self._app.notifyOnVoicemail = config.getboolean("2 - Account Info", "notifyOnVoicemail")
                        self._app.notifyOnSms = config.getboolean("2 - Account Info", "notifyOnSms")
+                       self._updateVoicemailOnMissedCall = config.getboolean("2 - Account Info", "updateVoicemailOnMissedCall")
                except ConfigParser.NoOptionError, e:
                        _moduleLogger.info(
                                "Settings file %s is missing option %s" % (
@@ -503,6 +504,7 @@ class MainWindow(qwrappers.WindowWrapper):
                config.set("2 - Account Info", "notifyOnMissed", repr(self._app.notifyOnMissed))
                config.set("2 - Account Info", "notifyOnVoicemail", repr(self._app.notifyOnVoicemail))
                config.set("2 - Account Info", "notifyOnSms", repr(self._app.notifyOnSms))
+               config.set("2 - Account Info", "updateVoicemailOnMissedCall", repr(self._updateVoicemailOnMissedCall))
 
                backendId = 2 # For backwards compatibility
                for tabIndex, tabTitle in enumerate(self._TAB_TITLES):
@@ -544,6 +546,13 @@ class MainWindow(qwrappers.WindowWrapper):
                        import dialogs
                        self._accountDialog = dialogs.AccountDialog(self._app)
                        self._accountDialog.setIfNotificationsSupported(self._app.alarmHandler.backgroundNotificationsSupported)
+
+               if self._callHandler is None or not self._callHandler.isSupported:
+                       self._accountDialog.updateVMOnMissedCall = self._accountDialog.VOICEMAIL_CHECK_NOT_SUPPORTED
+               elif self._updateVoicemailOnMissedCall:
+                       self._accountDialog.updateVMOnMissedCall = self._accountDialog.VOICEMAIL_CHECK_ENABLED
+               else:
+                       self._accountDialog.updateVMOnMissedCall = self._accountDialog.VOICEMAIL_CHECK_DISABLED
                self._accountDialog.notifications = self._app.alarmHandler.alarmType
                self._accountDialog.notificationTime = self._app.alarmHandler.recurrence
                self._accountDialog.notifyOnMissed = self._app.notifyOnMissed
@@ -568,6 +577,14 @@ class MainWindow(qwrappers.WindowWrapper):
                                callbackNumber = self._accountDialog.selectedCallback
                                self._session.set_callback_number(callbackNumber)
 
+                       if self._callHandler is None or self._accountDialog.updateVMOnMissedCall == self._accountDialog.VOICEMAIL_CHECK_DISABLEDD:
+                               pass
+                       elif self._accountDialog.updateVMOnMissedCall == self._accountDialog.VOICEMAIL_CHECK_ENABLED:
+                               self._updateVoicemailOnMissedCall = True
+                               self._callHandler.start()
+                       else:
+                               self._updateVoicemailOnMissedCall = False
+                               self._callHandler.stop()
                        if (
                                self._accountDialog.notifyOnMissed or
                                self._accountDialog.notifyOnVoicemail or
@@ -587,7 +604,7 @@ class MainWindow(qwrappers.WindowWrapper):
                else:
                        _moduleLogger.info("Unknown response")
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_new_message_alert(self):
                with qui_utils.notify_error(self._errorLog):
@@ -597,19 +614,19 @@ class MainWindow(qwrappers.WindowWrapper):
                                else:
                                        self._app.ledHandler.on()
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_call_missed(self):
                with qui_utils.notify_error(self._errorLog):
                        self._session.update_messages(self._session.MESSAGE_VOICEMAILS, force=True)
 
-       @QtCore.pyqtSlot(str)
+       @qt_compat.Slot(str)
        @misc_utils.log_exception(_moduleLogger)
        def _on_session_error(self, message):
                with qui_utils.notify_error(self._errorLog):
                        self._errorLog.push_error(message)
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_login(self):
                with qui_utils.notify_error(self._errorLog):
@@ -623,17 +640,23 @@ class MainWindow(qwrappers.WindowWrapper):
                        for tab in self._tabsContents:
                                tab.enable()
                        self._initialize_tab(self._currentTab)
-                       self._callHandler.start()
-
-       @QtCore.pyqtSlot()
+                       if self._updateVoicemailOnMissedCall:
+                               if self._callHandler is None:
+                                       import call_handler
+                                       self._callHandler = call_handler.MissedCallWatcher()
+                                       self._callHandler.callMissed.connect(self._voicemailRefreshDelay.start)
+                               self._callHandler.start()
+
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_logout(self):
                with qui_utils.notify_error(self._errorLog):
                        for tab in self._tabsContents:
                                tab.disable()
-                       self._callHandler.stop()
+                       if self._callHandler is not None:
+                               self._callHandler.stop()
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_app_alert(self):
                with qui_utils.notify_error(self._errorLog):
@@ -645,7 +668,7 @@ class MainWindow(qwrappers.WindowWrapper):
                                }[(self._app.notifyOnSms, self._app.notifyOnVoicemail)]
                                self._session.update_messages(messageType, force=True)
 
-       @QtCore.pyqtSlot()
+       @qt_compat.Slot()
        @misc_utils.log_exception(_moduleLogger)
        def _on_recipients_changed(self):
                with qui_utils.notify_error(self._errorLog):
@@ -663,14 +686,14 @@ class MainWindow(qwrappers.WindowWrapper):
        def _on_child_close(self, obj = None):
                self._smsEntryDialog = None
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_login_requested(self, checked = True):
                with qui_utils.notify_error(self._errorLog):
                        self._prompt_for_login()
 
-       @QtCore.pyqtSlot(int)
+       @qt_compat.Slot(int)
        @misc_utils.log_exception(_moduleLogger)
        def _on_tab_changed(self, index):
                with qui_utils.notify_error(self._errorLog):
@@ -679,22 +702,22 @@ class MainWindow(qwrappers.WindowWrapper):
                        if self._app.alarmHandler.alarmType == self._app.alarmHandler.ALARM_APPLICATION:
                                self._app.ledHandler.off()
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_refresh(self, checked = True):
                with qui_utils.notify_error(self._errorLog):
                        self._tabsContents[self._currentTab].refresh(force=True)
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_refresh_connection(self, checked = True):
                with qui_utils.notify_error(self._errorLog):
                        self._session.refresh_connection()
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_import(self, checked = True):
                with qui_utils.notify_error(self._errorLog):
@@ -707,8 +730,8 @@ class MainWindow(qwrappers.WindowWrapper):
                        if self._tabsContents[self.CONTACTS_TAB].has_child:
                                self._tabsContents[self.CONTACTS_TAB].child.update_addressbooks()
 
-       @QtCore.pyqtSlot()
-       @QtCore.pyqtSlot(bool)
+       @qt_compat.Slot()
+       @qt_compat.Slot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_account(self, checked = True):
                with qui_utils.notify_error(self._errorLog):