Enabling support for configuring voicemail check on missed call
authorEd Page <eopage@byu.net>
Sat, 19 Mar 2011 02:20:49 +0000 (21:20 -0500)
committerEd Page <eopage@byu.net>
Tue, 19 Apr 2011 23:49:31 +0000 (18:49 -0500)
src/call_handler.py
src/dialcentral_qt.py
src/dialogs.py

index 756dc6a..b90e109 100644 (file)
@@ -45,7 +45,14 @@ class _MissedCallWatcher(QtCore.QObject):
        def isSupported(self):
                return self._isSupported
 
+       @property
+       def isStarted(self):
+               return self._isStarted
+
        def start(self):
+               if self._isStarted:
+                       _moduleLogger.info("voicemail monitor already started")
+                       return
                try:
                        self._newChannelSignaller.start()
                except RuntimeError:
@@ -110,6 +117,10 @@ class _DummyMissedCallWatcher(QtCore.QObject):
        def isSupported(self):
                return False
 
+       @property
+       def isStarted(self):
+               return self._isStarted
+
        def start(self):
                self._isStarted = True
 
index d625fb3..d7c1723 100755 (executable)
@@ -271,6 +271,7 @@ class MainWindow(qwrappers.WindowWrapper):
                self._voicemailRefreshDelay.setSingleShot(True)
                self._callHandler = call_handler.MissedCallWatcher()
                self._callHandler.callMissed.connect(self._voicemailRefreshDelay.start)
+               self._updateVoicemailOnMissedCall = False
 
                self._defaultCredentials = "", ""
                self._curentCredentials = "", ""
@@ -433,6 +434,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 +505,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 +547,13 @@ class MainWindow(qwrappers.WindowWrapper):
                        import dialogs
                        self._accountDialog = dialogs.AccountDialog(self._app)
                        self._accountDialog.setIfNotificationsSupported(self._app.alarmHandler.backgroundNotificationsSupported)
+
+               if 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 +578,12 @@ class MainWindow(qwrappers.WindowWrapper):
                                callbackNumber = self._accountDialog.selectedCallback
                                self._session.set_callback_number(callbackNumber)
 
+                       if 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
@@ -623,7 +639,8 @@ class MainWindow(qwrappers.WindowWrapper):
                        for tab in self._tabsContents:
                                tab.enable()
                        self._initialize_tab(self._currentTab)
-                       self._callHandler.start()
+                       if self._updateVoicemailOnMissedCall:
+                               self._callHandler.start()
 
        @QtCore.pyqtSlot()
        @misc_utils.log_exception(_moduleLogger)
index 57d9bde..3800916 100644 (file)
@@ -173,6 +173,10 @@ class AccountDialog(object):
        ALARM_BACKGROUND = "Background Alert"
        ALARM_APPLICATION = "Application Alert"
 
+       VOICEMAIL_CHECK_NOT_SUPPORTED = "Not Supported"
+       VOICEMAIL_CHECK_DISABLED = "Disabled"
+       VOICEMAIL_CHECK_ENABLED = "Enabled"
+
        def __init__(self, app):
                self._app = app
                self._doClear = False
@@ -188,6 +192,7 @@ class AccountDialog(object):
                self._missedCallsNotificationButton = QtGui.QCheckBox("Missed Calls")
                self._voicemailNotificationButton = QtGui.QCheckBox("Voicemail")
                self._smsNotificationButton = QtGui.QCheckBox("SMS")
+               self._voicemailOnMissedButton = QtGui.QCheckBox("Voicemail Update on Missed Calls")
                self._clearButton = QtGui.QPushButton("Clear Account")
                self._clearButton.clicked.connect(self._on_clear)
                self._callbackSelector = QtGui.QComboBox()
@@ -209,10 +214,11 @@ class AccountDialog(object):
                self._credLayout.addWidget(self._voicemailNotificationButton, 4, 1)
                self._credLayout.addWidget(QtGui.QLabel(""), 5, 0)
                self._credLayout.addWidget(self._smsNotificationButton, 5, 1)
-
                self._credLayout.addWidget(QtGui.QLabel(""), 6, 0)
-               self._credLayout.addWidget(self._clearButton, 6, 1)
-               self._credLayout.addWidget(QtGui.QLabel(""), 3, 0)
+               self._credLayout.addWidget(self._voicemailOnMissedButton, 6, 1)
+
+               self._credLayout.addWidget(QtGui.QLabel(""), 7, 0)
+               self._credLayout.addWidget(self._clearButton, 7, 1)
 
                self._loginButton = QtGui.QPushButton("&Apply")
                self._buttonLayout = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Cancel)
@@ -260,6 +266,29 @@ class AccountDialog(object):
        def set_account_number(self, num):
                self._accountNumberLabel.setText(num)
 
+       def _set_voicemail_on_missed(self, status):
+               if status == self.VOICEMAIL_CHECK_NOT_SUPPORTED:
+                       self._voicemailOnMissedButton.setChecked(False)
+                       self._voicemailOnMissedButton.hide()
+               elif status == self.VOICEMAIL_CHECK_DISABLED:
+                       self._voicemailOnMissedButton.setChecked(False)
+                       self._voicemailOnMissedButton.show()
+               elif status == self.VOICEMAIL_CHECK_ENABLED:
+                       self._voicemailOnMissedButton.setChecked(True)
+                       self._voicemailOnMissedButton.show()
+               else:
+                       raise RuntimeError("Unsupported option for updating voicemail on missed calls %r" % status)
+
+       def _get_voicemail_on_missed(self):
+               if not self._voicemailOnMissedButton.isVisible():
+                       return self.VOICEMAIL_CHECK_NOT_SUPPORTED
+               elif self._voicemailOnMissedButton.isChecked():
+                       return self.VOICEMAIL_CHECK_ENABLED
+               else:
+                       return self.VOICEMAIL_CHECK_DISABLED
+
+       updateVMOnMissedCall = property(_get_voicemail_on_missed, _set_voicemail_on_missed)
+
        def _set_notifications(self, enabled):
                for i in xrange(self._notificationSelecter.count()):
                        if self._notificationSelecter.itemText(i) == enabled: