Commit 6ceff169 authored by Adrian Georgescu's avatar Adrian Georgescu

Show sip account registrar address in preferences panel

parent d336f427
...@@ -65,6 +65,7 @@ class AccountInfo(object): ...@@ -65,6 +65,7 @@ class AccountInfo(object):
def __init__(self, account): def __init__(self, account):
self.account = account self.account = account
self.registration_state = None self.registration_state = None
self.registrar = None
@property @property
def name(self): def name(self):
...@@ -105,6 +106,7 @@ class AccountModel(QAbstractListModel): ...@@ -105,6 +106,7 @@ class AccountModel(QAbstractListModel):
notification_center.add_observer(self, name='SIPAccountRegistrationDidSucceed') notification_center.add_observer(self, name='SIPAccountRegistrationDidSucceed')
notification_center.add_observer(self, name='SIPAccountRegistrationDidFail') notification_center.add_observer(self, name='SIPAccountRegistrationDidFail')
notification_center.add_observer(self, name='SIPAccountRegistrationDidEnd') notification_center.add_observer(self, name='SIPAccountRegistrationDidEnd')
notification_center.add_observer(self, name='SIPAccountDidDeactivate')
notification_center.add_observer(self, name='BonjourAccountWillRegister') notification_center.add_observer(self, name='BonjourAccountWillRegister')
notification_center.add_observer(self, name='BonjourAccountRegistrationDidSucceed') notification_center.add_observer(self, name='BonjourAccountRegistrationDidSucceed')
notification_center.add_observer(self, name='BonjourAccountRegistrationDidFail') notification_center.add_observer(self, name='BonjourAccountRegistrationDidFail')
...@@ -154,6 +156,7 @@ class AccountModel(QAbstractListModel): ...@@ -154,6 +156,7 @@ class AccountModel(QAbstractListModel):
except ValueError: except ValueError:
return return
self.accounts[position].registration_state = 'started' self.accounts[position].registration_state = 'started'
self.accounts[position].registrar = None
self.dataChanged.emit(self.index(position), self.index(position)) self.dataChanged.emit(self.index(position), self.index(position))
def _NH_SIPAccountRegistrationDidSucceed(self, notification): def _NH_SIPAccountRegistrationDidSucceed(self, notification):
...@@ -162,15 +165,41 @@ class AccountModel(QAbstractListModel): ...@@ -162,15 +165,41 @@ class AccountModel(QAbstractListModel):
except ValueError: except ValueError:
return return
self.accounts[position].registration_state = 'succeeded' self.accounts[position].registration_state = 'succeeded'
if notification.sender is not BonjourAccount():
registrar = notification.data.registrar
self.accounts[position].registrar = "%s:%s:%s" % (registrar.transport, registrar.address, registrar.port)
self.dataChanged.emit(self.index(position), self.index(position)) self.dataChanged.emit(self.index(position), self.index(position))
notification.center.post_notification('SIPRegistrationInfoDidChange', sender=notification.sender)
def _NH_SIPAccountDidDeactivate(self, notification):
try:
position = self.accounts.index(notification.sender)
except ValueError:
return
self.accounts[position].registration_state = None
self.accounts[position].registrar = None
self.dataChanged.emit(self.index(position), self.index(position))
notification.center.post_notification('SIPRegistrationInfoDidChange', sender=notification.sender)
def _NH_SIPAccountRegistrationDidFail(self, notification): def _NH_SIPAccountRegistrationDidFail(self, notification):
try: try:
position = self.accounts.index(notification.sender) position = self.accounts.index(notification.sender)
except ValueError: except ValueError:
return return
self.accounts[position].registration_state = 'failed'
reason = 'Unknown reason'
if hasattr(notification.data, 'error'):
reason = notification.data.error
elif hasattr(notification.data, 'reason'):
reason = notification.data.reason
self.accounts[position].registration_state = 'failed (%s)' % (reason.decode() if isinstance(reason, bytes) else reason)
self.accounts[position].registrar = None
self.dataChanged.emit(self.index(position), self.index(position)) self.dataChanged.emit(self.index(position), self.index(position))
notification.center.post_notification('SIPRegistrationInfoDidChange', sender=notification.sender)
def _NH_SIPAccountRegistrationDidEnd(self, notification): def _NH_SIPAccountRegistrationDidEnd(self, notification):
try: try:
...@@ -178,6 +207,7 @@ class AccountModel(QAbstractListModel): ...@@ -178,6 +207,7 @@ class AccountModel(QAbstractListModel):
except ValueError: except ValueError:
return return
self.accounts[position].registration_state = 'ended' self.accounts[position].registration_state = 'ended'
self.accounts[position].registrar = None
self.dataChanged.emit(self.index(position), self.index(position)) self.dataChanged.emit(self.index(position), self.index(position))
_NH_BonjourAccountWillRegister = _NH_SIPAccountWillRegister _NH_BonjourAccountWillRegister = _NH_SIPAccountWillRegister
......
...@@ -465,7 +465,6 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -465,7 +465,6 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
combo_box.initStyleOption(option) combo_box.initStyleOption(option)
wide_padding = (combo_box.height() - combo_box.style().subControlRect(QStyle.CC_ComboBox, option, QStyle.SC_ComboBoxEditField, combo_box).height() >= 10) wide_padding = (combo_box.height() - combo_box.style().subControlRect(QStyle.CC_ComboBox, option, QStyle.SC_ComboBoxEditField, combo_box).height() >= 10)
if False and wide_padding: # TODO: review later and decide if its worth or not -Dan if False and wide_padding: # TODO: review later and decide if its worth or not -Dan
print("found wide padding")
self.audio_alert_device_button.setStyleSheet("""QComboBox { padding: 4px 4px 4px 4px; }""") self.audio_alert_device_button.setStyleSheet("""QComboBox { padding: 4px 4px 4px 4px; }""")
self.audio_input_device_button.setStyleSheet("""QComboBox { padding: 4px 4px 4px 4px; }""") self.audio_input_device_button.setStyleSheet("""QComboBox { padding: 4px 4px 4px 4px; }""")
self.audio_output_device_button.setStyleSheet("""QComboBox { padding: 4px 4px 4px 4px; }""") self.audio_output_device_button.setStyleSheet("""QComboBox { padding: 4px 4px 4px 4px; }""")
...@@ -763,8 +762,15 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -763,8 +762,15 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
self.password_editor.setText(account.auth.password) self.password_editor.setText(account.auth.password)
selected_index = self.account_list.selectionModel().selectedIndexes()[0] selected_index = self.account_list.selectionModel().selectedIndexes()[0]
selected_account_info = self.account_list.model().data(selected_index, Qt.UserRole) selected_account_info = self.account_list.model().data(selected_index, Qt.UserRole)
if not account.enabled:
selected_account_info.registration_state = None
selected_account_info.registrar = None
if selected_account_info.registration_state: if selected_account_info.registration_state:
self.account_registration_label.setText('Registration %s' % selected_account_info.registration_state.title()) if selected_account_info.registration_state == 'succeeded' and selected_account_info.registrar is not None:
self.account_registration_label.setText('Registered at %s' % selected_account_info.registrar)
else:
self.account_registration_label.setText('Registration %s' % selected_account_info.registration_state.title())
else: else:
self.account_registration_label.setText('Not Registered') self.account_registration_label.setText('Not Registered')
else: else:
...@@ -969,6 +975,21 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -969,6 +975,21 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
self._update_logs_size_label() self._update_logs_size_label()
self.pages.setCurrentIndex(action.index) self.pages.setCurrentIndex(action.index)
def _NH_SIPRegistrationInfoDidChange(self, notification):
self.refresh_account_registration_widgets(notification.sender)
def refresh_account_registration_widgets(self, account):
try:
selected_index = self.account_list.selectionModel().selectedIndexes()[0]
except IndexError:
return
selected_account = selected_index.data(Qt.UserRole).account
if account.id != selected_account.id:
return
self.load_account_settings(selected_account)
def _SH_AccountListSelectionChanged(self, selected, deselected): def _SH_AccountListSelectionChanged(self, selected, deselected):
try: try:
selected_index = self.account_list.selectionModel().selectedIndexes()[0] selected_index = self.account_list.selectionModel().selectedIndexes()[0]
...@@ -1668,6 +1689,7 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -1668,6 +1689,7 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
notification.center.add_observer(self, name='VideoDevicesDidChange') notification.center.add_observer(self, name='VideoDevicesDidChange')
notification.center.add_observer(self, name='VideoDeviceDidChangeCamera') notification.center.add_observer(self, name='VideoDeviceDidChangeCamera')
notification.center.add_observer(self, name='CFGSettingsObjectDidChange') notification.center.add_observer(self, name='CFGSettingsObjectDidChange')
notification.center.add_observer(self, name='SIPRegistrationInfoDidChange')
def _NH_AudioDevicesDidChange(self, notification): def _NH_AudioDevicesDidChange(self, notification):
self.load_audio_devices() self.load_audio_devices()
...@@ -1707,6 +1729,8 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -1707,6 +1729,8 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
account = notification.sender account = notification.sender
if 'enabled' in notification.data.modified: if 'enabled' in notification.data.modified:
self.account_enabled_button.setChecked(account.enabled) self.account_enabled_button.setChecked(account.enabled)
if not account.enabled:
self.refresh_account_registration_widgets(account)
self.reregister_button.setEnabled(account.enabled) self.reregister_button.setEnabled(account.enabled)
if 'display_name' in notification.data.modified: if 'display_name' in notification.data.modified:
self.display_name_editor.setText(account.display_name or '') self.display_name_editor.setText(account.display_name or '')
......
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