Commit 8f452420 authored by Tijmen de Mes's avatar Tijmen de Mes

Added a setting to show both name and uri in call history


GH-2
parent a9ddfd06
...@@ -123,12 +123,17 @@ class BlinkPresenceSettings(SettingsGroup): ...@@ -123,12 +123,17 @@ class BlinkPresenceSettings(SettingsGroup):
icon = Setting(type=IconDescriptor, nillable=True) icon = Setting(type=IconDescriptor, nillable=True)
class BlinkInterfaceSettings(SettingsGroup):
show_history_name_and_uri = Setting(type=bool, default=False)
class BlinkSettings(SettingsObject): class BlinkSettings(SettingsObject):
__id__ = 'BlinkSettings' __id__ = 'BlinkSettings'
chat_window = ChatWindowSettings chat_window = ChatWindowSettings
presence = BlinkPresenceSettings presence = BlinkPresenceSettings
screen_sharing = BlinkScreenSharingSettings screen_sharing = BlinkScreenSharingSettings
interface = BlinkInterfaceSettings
screenshots_directory = Setting(type=Path, default=Path('~/Downloads')) screenshots_directory = Setting(type=Path, default=Path('~/Downloads'))
transfers_directory = Setting(type=Path, default=Path('~/Downloads')) transfers_directory = Setting(type=Path, default=Path('~/Downloads'))
......
...@@ -19,6 +19,7 @@ from sipsimple.addressbook import AddressbookManager ...@@ -19,6 +19,7 @@ from sipsimple.addressbook import AddressbookManager
from sipsimple.threading import run_in_thread from sipsimple.threading import run_in_thread
from sipsimple.util import ISOTimestamp from sipsimple.util import ISOTimestamp
from blink.configuration.settings import BlinkSettings
from blink.resources import ApplicationData, Resources from blink.resources import ApplicationData, Resources
from blink.messages import BlinkMessage from blink.messages import BlinkMessage
from blink.util import run_in_gui_thread from blink.util import run_in_gui_thread
...@@ -38,19 +39,11 @@ class HistoryManager(object, metaclass=Singleton): ...@@ -38,19 +39,11 @@ class HistoryManager(object, metaclass=Singleton):
sip_prefix_re = re.compile('^sips?:') sip_prefix_re = re.compile('^sips?:')
def __init__(self): def __init__(self):
try: self.calls = []
data = pickle.load(open(ApplicationData.get('calls_history'), "rb"))
if not isinstance(data, list) or not all(isinstance(item, HistoryEntry) and item.text and isinstance(item.call_time, ISOTimestamp) for item in data):
raise ValueError("invalid save data")
except Exception as e:
traceback.print_exc()
self.calls = []
else:
self.calls = data[-self.history_size:]
self.message_history = MessageHistory() self.message_history = MessageHistory()
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.add_observer(self, name='SIPApplicationDidStart')
notification_center.add_observer(self, name='SIPSessionDidEnd') notification_center.add_observer(self, name='SIPSessionDidEnd')
notification_center.add_observer(self, name='SIPSessionDidFail') notification_center.add_observer(self, name='SIPSessionDidFail')
notification_center.add_observer(self, name='ChatStreamGotMessage') notification_center.add_observer(self, name='ChatStreamGotMessage')
...@@ -81,6 +74,16 @@ class HistoryManager(object, metaclass=Singleton): ...@@ -81,6 +74,16 @@ class HistoryManager(object, metaclass=Singleton):
handler = getattr(self, '_NH_%s' % notification.name, Null) handler = getattr(self, '_NH_%s' % notification.name, Null)
handler(notification) handler(notification)
def _NH_SIPApplicationDidStart(self, notification):
try:
data = pickle.load(open(ApplicationData.get('calls_history'), "rb"))
if not isinstance(data, list) or not all(isinstance(item, HistoryEntry) and item.text and isinstance(item.call_time, ISOTimestamp) for item in data):
raise ValueError("invalid save data")
except Exception as e:
traceback.print_exc()
else:
self.calls = data[-self.history_size:]
def _NH_SIPSessionDidEnd(self, notification): def _NH_SIPSessionDidEnd(self, notification):
if notification.sender.account is BonjourAccount(): if notification.sender.account is BonjourAccount():
return return
...@@ -466,6 +469,10 @@ class HistoryEntry(object): ...@@ -466,6 +469,10 @@ class HistoryEntry(object):
@property @property
def text(self): def text(self):
result = str(self.name or self.uri) result = str(self.name or self.uri)
blink_settings = BlinkSettings()
if blink_settings.interface.show_history_name_and_uri:
result = f'{str(self.name)} ({str(self.uri)})'
if self.call_time: if self.call_time:
call_time = self.call_time.astimezone(tzlocal()) call_time = self.call_time.astimezone(tzlocal())
call_date = call_time.date() call_date = call_time.date()
......
...@@ -346,6 +346,9 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -346,6 +346,9 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
self.auto_answer_interval.valueChanged[int].connect(self._SH_AutoAnswerIntervalChanged) self.auto_answer_interval.valueChanged[int].connect(self._SH_AutoAnswerIntervalChanged)
self.account_auto_answer.clicked.connect(self._SH_AccountAutoAnswerChanged) self.account_auto_answer.clicked.connect(self._SH_AccountAutoAnswerChanged)
# Interface
self.history_name_and_uri_button.clicked.connect(self._SH_HistoryNameAndUriButtonClicked)
# Setup initial state (show the accounts page right after start) # Setup initial state (show the accounts page right after start)
self.accounts_action.trigger() self.accounts_action.trigger()
self.account_tab_widget.setCurrentIndex(0) self.account_tab_widget.setCurrentIndex(0)
...@@ -767,6 +770,8 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -767,6 +770,8 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
self.tls_cert_file_editor.setText(settings.tls.certificate or '') self.tls_cert_file_editor.setText(settings.tls.certificate or '')
self.tls_verify_server_button.setChecked(settings.tls.verify_server) self.tls_verify_server_button.setChecked(settings.tls.verify_server)
self.history_name_and_uri_button.setChecked(blink_settings.interface.show_history_name_and_uri)
def load_account_settings(self, account): def load_account_settings(self, account):
"""Load the account settings from configuration into the UI controls""" """Load the account settings from configuration into the UI controls"""
settings = SIPSimpleSettings() settings = SIPSimpleSettings()
...@@ -1792,6 +1797,11 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -1792,6 +1797,11 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
settings.tls.ca_list = ca_path settings.tls.ca_list = ca_path
settings.save() settings.save()
def _SH_HistoryNameAndUriButtonClicked(self, checked):
settings = BlinkSettings()
settings.interface.show_history_name_and_uri = checked
settings.save()
@run_in_gui_thread @run_in_gui_thread
def handle_notification(self, notification): def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null) handler = getattr(self, '_NH_%s' % notification.name, Null)
......
...@@ -3652,6 +3652,74 @@ ...@@ -3652,6 +3652,74 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="interface_tab">
<attribute name="title">
<string>Interface</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_6">
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<property name="spacing">
<number>5</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>History menu</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="history_name_and_uri_button">
<property name="text">
<string>Show both name and URI</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="Line" name="line_14">
<property name="baseSize">
<size>
<width>0</width>
<height>10</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>
......
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