Commit f853be5a authored by Luci Stanescu's avatar Luci Stanescu

Added support for incoming session ringing

parent 1a71a3b9
......@@ -11,10 +11,12 @@ from application.notification import IObserver, NotificationCenter
from application.python.util import Null
from zope.interface import implements
from sipsimple.account import Account, BonjourAccount
from sipsimple.application import SIPApplication
from sipsimple.configuration.backend.file import FileBackend
from sipsimple.configuration.settings import SIPSimpleSettings
from blink.configuration.account import AccountExtension, BonjourAccountExtension
from blink.configuration.settings import SIPSimpleSettingsExtension
from blink.mainwindow import MainWindow
from blink.resources import ApplicationData
......@@ -32,6 +34,8 @@ class Blink(QApplication):
self.application = SIPApplication()
self.main_window = MainWindow()
Account.register_extension(AccountExtension)
BonjourAccount.register_extension(BonjourAccountExtension)
SIPSimpleSettings.register_extension(SIPSimpleSettingsExtension)
session_manager = SessionManager()
session_manager.initialize(self.main_window, self.main_window.session_model)
......
# Copyright (C) 2010 AG Projects. See LICENSE for details.
#
"""Blink account settings extensions."""
__all__ = ['AccountExtension', 'BonjourAccountExtension']
from sipsimple.configuration import Setting, SettingsGroup, SettingsObjectExtension
from blink.configuration.datatypes import CustomSoundFile, DefaultPath
class SoundSettings(SettingsGroup):
inbound_ringtone = Setting(type=CustomSoundFile, default=CustomSoundFile(DefaultPath), nillable=True)
class AccountExtension(SettingsObjectExtension):
sounds = SoundSettings
class BonjourAccountExtension(SettingsObjectExtension):
sounds = SoundSettings
......@@ -3,9 +3,10 @@
"""Definitions of datatypes for use in settings extensions."""
__all__ = ['ApplicationDataPath', 'SoundFile']
__all__ = ['ApplicationDataPath', 'SoundFile', 'DefaultPath', 'CustomSoundFile']
import os
import re
from blink.resources import ApplicationData
......@@ -26,7 +27,7 @@ class SoundFile(object):
def __init__(self, path, volume=100):
self.path = path
self.volume = int(volume)
if self.volume < 0 or self.volume > 100:
if not (0 <= self.volume <= 100):
raise ValueError('illegal volume level: %d' % self.volume)
def __getstate__(self):
......@@ -54,3 +55,46 @@ class SoundFile(object):
del _get_path, _set_path
class DefaultPath(object):
def __repr__(self):
return self.__class__.__name__
class CustomSoundFile(object):
def __init__(self, path=DefaultPath, volume=100):
self.path = path
self.volume = int(volume)
if self.volume < 0 or self.volume > 100:
raise ValueError('illegal volume level: %d' % self.volume)
def __getstate__(self):
if self.path is DefaultPath:
return u'default'
else:
return u'file:%s,%s' % (self.__dict__['path'], self.volume)
def __setstate__(self, state):
match = re.match(r'^(?P<type>default|file:)(?P<path>.+?)?(,(?P<volume>\d+))?$', state)
if match is None:
raise ValueError('illegal value: %r' % state)
data = match.groupdict()
if data.pop('type') == 'default':
data['path'] = DefaultPath
data['volume'] = data['volume'] or 100
self.__init__(**data)
def __repr__(self):
return '%s(%r, %r)' % (self.__class__.__name__, self.path, self.volume)
def _get_path(self):
path = self.__dict__['path']
return path if path is DefaultPath else ApplicationData.get(path)
def _set_path(self, path):
if path is not DefaultPath:
path = os.path.normpath(path)
if path.startswith(ApplicationData.directory+os.path.sep):
path = path[len(ApplicationData.directory+os.path.sep):]
self.__dict__['path'] = path
path = property(_get_path, _set_path)
del _get_path, _set_path
......@@ -17,7 +17,8 @@ class AudioSettingsExtension(AudioSettings):
class SoundSettings(SettingsGroup):
outbound_ringtone = Setting(type=SoundFile, default=SoundFile(Resources.get('sounds/ring_outbound.wav')), nillable=True)
inbound_ringtone = Setting(type=SoundFile, default=SoundFile(Resources.get('sounds/inbound_ringtone.wav')), nillable=True)
outbound_ringtone = Setting(type=SoundFile, default=SoundFile(Resources.get('sounds/outbound_ringtone.wav')), nillable=True)
class SIPSimpleSettingsExtension(SettingsObjectExtension):
......
This diff is collapsed.
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