Commit a6c0a0c5 authored by Saul Ibarra's avatar Saul Ibarra

Added preliminary support for MWI

parent af325601
...@@ -329,6 +329,13 @@ class MainWindow(base_class, ui_class): ...@@ -329,6 +329,13 @@ class MainWindow(base_class, ui_class):
account = account if account is not BonjourAccount() and account.server.settings_url else None account = account if account is not BonjourAccount() and account.server.settings_url else None
self.server_tools_window.open_buy_pstn_access_page(account) self.server_tools_window.open_buy_pstn_access_page(account)
def _AH_VoicemailActionTriggered(self, action, checked):
account, received_voicemail_uri = action.data().toPyObject()
voicemail_uri = account.message_summary.voicemail_uri or received_voicemail_uri
if voicemail_uri:
session_manager = SessionManager()
session_manager.start_call(voicemail_uri, voicemail_uri, account=account)
def _SH_AddContactButtonClicked(self, clicked): def _SH_AddContactButtonClicked(self, clicked):
model = self.contact_model model = self.contact_model
selected_items = ((index.row(), model.data(index)) for index in self.contact_list.selectionModel().selectedIndexes()) selected_items = ((index.row(), model.data(index)) for index in self.contact_list.selectionModel().selectedIndexes())
...@@ -535,6 +542,12 @@ class MainWindow(base_class, ui_class): ...@@ -535,6 +542,12 @@ class MainWindow(base_class, ui_class):
action.setChecked(account.enabled) action.setChecked(account.enabled)
action.triggered.connect(partial(self._AH_AccountActionTriggered, action)) action.triggered.connect(partial(self._AH_AccountActionTriggered, action))
self.accounts_menu.addAction(action) self.accounts_menu.addAction(action)
if isinstance(account, Account) and account.enabled and account.message_summary.enabled:
vm_action = QAction(account.id, None)
vm_action.setData(QVariant((account, None)))
vm_action.setEnabled(account.message_summary.voicemail_uri is not None)
vm_action.triggered.connect(partial(self._AH_VoicemailActionTriggered, vm_action))
self.voicemail_menu.addAction(vm_action)
def _NH_SIPApplicationDidStart(self, notification): def _NH_SIPApplicationDidStart(self, notification):
self.load_audio_devices() self.load_audio_devices()
...@@ -589,10 +602,41 @@ class MainWindow(base_class, ui_class): ...@@ -589,10 +602,41 @@ class MainWindow(base_class, ui_class):
else: else:
self.google_contacts_action.setText(u'Enable Google Contacts') self.google_contacts_action.setText(u'Enable Google Contacts')
elif isinstance(notification.sender, (Account, BonjourAccount)): elif isinstance(notification.sender, (Account, BonjourAccount)):
if 'enabled' in notification.data.modified:
account = notification.sender account = notification.sender
if 'enabled' in notification.data.modified:
action = (action for action in self.accounts_menu.actions() if action.data().toPyObject() is account).next() action = (action for action in self.accounts_menu.actions() if action.data().toPyObject() is account).next()
action.setChecked(account.enabled) action.setChecked(account.enabled)
if account.enabled and account.message_summary.enabled:
vm_action = QAction(account.id, None)
vm_action.setData(QVariant((account, None)))
vm_action.setEnabled(account.message_summary.voicemail_uri is not None)
vm_action.triggered.connect(partial(self._AH_VoicemailActionTriggered, vm_action))
self.voicemail_menu.addAction(vm_action)
else:
try:
vm_action = (action for action in self.voicemail_menu.actions() if action.data().toPyObject()[0] is account).next()
except StopIteration:
pass
else:
self.voicemail_menu.removeAction(vm_action)
if 'message_summary.enabled' in notification.data.modified:
if account.message_summary.enabled:
vm_action = QAction(account.id, None)
vm_action.setData(QVariant((account, None)))
vm_action.setEnabled(account.message_summary.voicemail_uri is not None)
vm_action.triggered.connect(partial(self._AH_VoicemailActionTriggered, vm_action))
self.voicemail_menu.addAction(vm_action)
else:
vm_action = (action for action in self.voicemail_menu.actions() if action.data().toPyObject()[0] is account).next()
self.voicemail_menu.removeAction(action)
if 'message_summary.voicemail_uri' in notification.data.modified:
if account.message_summary.enabled:
vm_action = (action for action in self.voicemail_menu.actions() if action.data().toPyObject()[0] is account).next()
vm_action.setEnabled(account.message_summary.voicemail_uri is not None)
def _NH_SIPAccountManagerWillStart(self, notification):
notification_center = NotificationCenter()
notification_center.add_observer(self, name='SIPAccountMWIDidGetSummary')
def _NH_SIPAccountManagerDidAddAccount(self, notification): def _NH_SIPAccountManagerDidAddAccount(self, notification):
account = notification.data.account account = notification.data.account
...@@ -606,6 +650,9 @@ class MainWindow(base_class, ui_class): ...@@ -606,6 +650,9 @@ class MainWindow(base_class, ui_class):
account = notification.data.account account = notification.data.account
action = (action for action in self.accounts_menu.actions() if action.data().toPyObject() is account).next() action = (action for action in self.accounts_menu.actions() if action.data().toPyObject() is account).next()
self.account_menu.removeAction(action) self.account_menu.removeAction(action)
if isinstance(account, Account) and account.enabled and account.message_summary.enabled:
action = (action for action in self.voicemail_menu.actions() if action.data().toPyObject()[0] is account).next()
self.voicemail_menu.removeAction(action)
def _NH_SIPAccountManagerDidChangeDefaultAccount(self, notification): def _NH_SIPAccountManagerDidChangeDefaultAccount(self, notification):
if notification.data.account is None: if notification.data.account is None:
...@@ -614,6 +661,19 @@ class MainWindow(base_class, ui_class): ...@@ -614,6 +661,19 @@ class MainWindow(base_class, ui_class):
selected_items = self.contact_list.selectionModel().selectedIndexes() selected_items = self.contact_list.selectionModel().selectedIndexes()
self.enable_call_buttons(len(selected_items)==1 and isinstance(self.contact_model.data(selected_items[0]), Contact)) self.enable_call_buttons(len(selected_items)==1 and isinstance(self.contact_model.data(selected_items[0]), Contact))
def _NH_SIPAccountMWIDidGetSummary(self, notification):
account = notification.sender
summary = notification.data.message_summary
action = (action for action in self.voicemail_menu.actions() if action.data().toPyObject()[0] is account).next()
action.setData(QVariant((account, summary.message_account)))
action.setEnabled(True if account.message_summary.voicemail_uri is not None or summary.message_account is not None else False)
if summary.messages_waiting and summary.summaries.get('voice-message') is not None:
new_messages = int(summary.summaries.get('voice-message').get('new_messages', 0))
vm_text = u'%d new messages' % new_messages if new_messages > 0 else u'No new messages'
else:
vm_text = u'No new messages'
action.setText(u'%s - %s' % (account.id, vm_text))
del ui_class, base_class del ui_class, base_class
...@@ -939,6 +939,14 @@ padding: 2px;</string> ...@@ -939,6 +939,14 @@ padding: 2px;</string>
<property name="title"> <property name="title">
<string>&amp;History</string> <string>&amp;History</string>
</property> </property>
<widget class="QMenu" name="voicemail_menu">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>&amp;Voicemail</string>
</property>
</widget>
<widget class="QMenu" name="missed_calls_menu"> <widget class="QMenu" name="missed_calls_menu">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
...@@ -978,6 +986,7 @@ padding: 2px;</string> ...@@ -978,6 +986,7 @@ padding: 2px;</string>
<addaction name="redial_action"/> <addaction name="redial_action"/>
<addaction name="history_action"/> <addaction name="history_action"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="voicemail_menu"/>
<addaction name="missed_calls_menu"/> <addaction name="missed_calls_menu"/>
<addaction name="placed_calls_menu"/> <addaction name="placed_calls_menu"/>
<addaction name="received_calls_menu"/> <addaction name="received_calls_menu"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment