Esempio n. 1
0
 def _NH_SystemDidWakeUpFromSleep(self, sender, data):
     BlinkLogger().log_info("Computer wake up from sleep")
     bonjour_account = BonjourAccount()
     if not bonjour_account.enabled and self.bonjour_disabled_on_sleep:
         BlinkLogger().log_debug("Enabling Bonjour discovery after wakeup from sleep")
         bonjour_account.enabled=True
         self.bonjour_disabled_on_sleep=False
Esempio n. 2
0
 def _NH_SystemDidWakeUpFromSleep(self, sender, data):
     BlinkLogger().log_info(u"Computer wake up from sleep")
     bonjour_account = BonjourAccount()
     if not bonjour_account.enabled and self.bonjour_disabled_on_sleep:
         BlinkLogger().log_debug(u"Enabling Bonjour discovery after wakeup from sleep")
         bonjour_account.enabled=True
         self.bonjour_disabled_on_sleep=False
Esempio n. 3
0
 def _NH_SystemWillSleep(self, sender, data):
     bonjour_account = BonjourAccount()
     if bonjour_account.enabled:
         BlinkLogger().log_info("Computer will go to sleep")
         BlinkLogger().log_debug("Disabling Bonjour discovery during sleep")
         bonjour_account.enabled=False
         self.bonjour_disabled_on_sleep=True
Esempio n. 4
0
 def _NH_SystemWillSleep(self, sender, data):
     bonjour_account = BonjourAccount()
     if bonjour_account.enabled:
         BlinkLogger().log_info(u"Computer will go to sleep")
         BlinkLogger().log_debug(u"Disabling Bonjour discovery during sleep")
         bonjour_account.enabled=False
         self.bonjour_disabled_on_sleep=True
Esempio n. 5
0
 def _NH_CFGSettingsObjectDidChange(self, notification):
     settings = SIPSimpleSettings()
     blink_settings = BlinkSettings()
     icon_manager = IconManager()
     if notification.sender is settings:
         if 'audio.muted' in notification.data.modified:
             self.mute_action.setChecked(settings.audio.muted)
             self.mute_button.setChecked(settings.audio.muted)
         if 'audio.silent' in notification.data.modified:
             self.silent_action.setChecked(settings.audio.silent)
             self.silent_button.setChecked(settings.audio.silent)
         if 'audio.output_device' in notification.data.modified:
             action = (action for action in self.output_devices_group.actions() if action.data() == settings.audio.output_device).next()
             action.setChecked(True)
         if 'audio.input_device' in notification.data.modified:
             action = (action for action in self.input_devices_group.actions() if action.data() == settings.audio.input_device).next()
             action.setChecked(True)
         if 'audio.alert_device' in notification.data.modified:
             action = (action for action in self.alert_devices_group.actions() if action.data() == settings.audio.alert_device).next()
             action.setChecked(True)
         if 'video.device' in notification.data.modified:
             action = (action for action in self.video_devices_group.actions() if action.data() == settings.video.device).next()
             action.setChecked(True)
         if 'answering_machine.enabled' in notification.data.modified:
             self.answering_machine_action.setChecked(settings.answering_machine.enabled)
         if 'chat.auto_accept' in notification.data.modified:
             self.auto_accept_chat_action.setChecked(settings.chat.auto_accept)
         if 'sounds.play_message_alerts' in notification.data.modified:
             self.received_messages_sound_action.setChecked(settings.sounds.play_message_alerts)
         if 'google_contacts.authorization_token' in notification.data.modified:
             authorization_token = notification.sender.google_contacts.authorization_token
             if authorization_token is None:
                 self.google_contacts_action.setText(u'Enable &Google Contacts...')
             else:
                 self.google_contacts_action.setText(u'Disable &Google Contacts')
             if authorization_token is InvalidToken:
                 self.google_contacts_dialog.open_for_incorrect_password()
     elif notification.sender is blink_settings:
         if 'presence.current_state' in notification.data.modified:
             state = getattr(AccountState, blink_settings.presence.current_state.state, AccountState.Available)
             self.account_state.setState(state, blink_settings.presence.current_state.note)
         if 'presence.icon' in notification.data.modified:
             self.set_user_icon(icon_manager.get('avatar'))
         if 'presence.offline_note' in notification.data.modified:
             # TODO: set offline note -Saul
             pass
     elif isinstance(notification.sender, (Account, BonjourAccount)):
         account_manager = AccountManager()
         account = notification.sender
         if 'enabled' in notification.data.modified:
             action = (action for action in self.accounts_menu.actions() if action.data() is account).next()
             action.setChecked(account.enabled)
         if 'display_name' in notification.data.modified and account is account_manager.default_account:
             self.display_name.setText(account.display_name or u'')
         if set(['enabled', 'message_summary.enabled', 'message_summary.voicemail_uri']).intersection(notification.data.modified):
             action = (action for action in self.voicemail_menu.actions() if action.data() is account).next()
             action.setVisible(False if account is BonjourAccount() else account.enabled and account.message_summary.enabled)
             action.setEnabled(False if account is BonjourAccount() else account.voicemail_uri is not None)
Esempio n. 6
0
    def _NH_SIPApplicationWillStart(self, sender, data):
        settings = SIPSimpleSettings()
        settings.user_agent = "%s %s (MacOSX)" % (
            NSApp.delegate().applicationName, self._version)
        BlinkLogger().log_info(u"Initializing SIP SIMPLE Client SDK %s" %
                               sdk_version)

        build = str(NSBundle.mainBundle().infoDictionary().objectForKey_(
            "CFBundleVersion"))
        date = str(NSBundle.mainBundle().infoDictionary().objectForKey_(
            "BlinkVersionDate"))
        BlinkLogger().log_info(u"Build %s from %s" % (build, date))

        self.migratePasswordsToKeychain()

        # Set audio settings compatible with AEC and Noise Supressor
        settings.audio.sample_rate = 16000
        settings.audio.tail_length = 15 if settings.audio.enable_aec else 0
        settings.save()
        BlinkLogger().log_info(
            u"Acoustic Echo Canceller is %s" %
            ('enabled' if settings.audio.enable_aec else 'disabled'))

        # Although this setting is set at enrollment time, people who have downloaded previous versions will not have it
        account_manager = AccountManager()
        for account in account_manager.iter_accounts():
            must_save = False
            if account is not BonjourAccount(
            ) and account.sip.primary_proxy is None and account.sip.outbound_proxy and not account.sip.selected_proxy:
                account.sip.primary_proxy = account.sip.outbound_proxy
                must_save = True

            if account is not BonjourAccount(
            ) and settings.tls.verify_server != account.tls.verify_server:
                account.tls.verify_server = settings.tls.verify_server
                must_save = True

            if account.tls.certificate and os.path.basename(
                    account.tls.certificate.normalized) != 'default.crt':
                account.tls.certificate = DefaultValue
                must_save = True

            if account.id.domain == "sip2sip.info":
                if account.server.settings_url is None:
                    account.server.settings_url = "https://blink.sipthor.net/settings.phtml"
                    must_save = True
                if not account.ldap.hostname:
                    account.ldap.hostname = "ldap.sipthor.net"
                    account.ldap.dn = "ou=addressbook, dc=sip2sip, dc=info"
                    account.ldap.enabled = True
                    must_save = True

            if must_save:
                account.save()

        logger = FileLogger()
        logger.start()
        self.ip_address_monitor.start()
Esempio n. 7
0
    def __init__(self):
        super(Blink, self).__init__(sys.argv)
        self.setAttribute(Qt.AA_DontShowIconsInMenus, False)
        self.sip_application = SIPApplication()
        self.first_run = False

        self.setOrganizationDomain("ag-projects.com")
        self.setOrganizationName("AG Projects")
        self.setApplicationName("Blink")
        self.setApplicationVersion(__version__)

        self.main_window = MainWindow()
        self.chat_window = ChatWindow()
        self.main_window.__closed__ = True
        self.chat_window.__closed__ = True
        self.main_window.installEventFilter(self)
        self.chat_window.installEventFilter(self)

        self.main_window.addAction(self.chat_window.control_button.actions.main_window)
        self.chat_window.addAction(self.main_window.quit_action)
        self.chat_window.addAction(self.main_window.help_action)
        self.chat_window.addAction(self.main_window.redial_action)
        self.chat_window.addAction(self.main_window.join_conference_action)
        self.chat_window.addAction(self.main_window.mute_action)
        self.chat_window.addAction(self.main_window.silent_action)
        self.chat_window.addAction(self.main_window.preferences_action)
        self.chat_window.addAction(self.main_window.transfers_window_action)
        self.chat_window.addAction(self.main_window.logs_window_action)
        self.chat_window.addAction(self.main_window.received_files_window_action)
        self.chat_window.addAction(self.main_window.screenshots_window_action)

        self.ip_address_monitor = IPAddressMonitor()
        self.log_manager = LogManager()
        self.presence_manager = PresenceManager()
        self.session_manager = SessionManager()
        self.update_manager = UpdateManager()

        # Prevent application from exiting after last window is closed if system tray was initialized
        if self.main_window.system_tray_icon:
            self.setQuitOnLastWindowClosed(False)

        self.main_window.check_for_updates_action.triggered.connect(self.update_manager.check_for_updates)
        self.main_window.check_for_updates_action.setVisible(self.update_manager != Null)

        if getattr(sys, "frozen", False):
            XMLDocument.schema_path = Resources.get("xml-schemas")

        Account.register_extension(AccountExtension)
        BonjourAccount.register_extension(BonjourAccountExtension)
        Contact.register_extension(ContactExtension)
        Group.register_extension(GroupExtension)
        SIPSimpleSettings.register_extension(SIPSimpleSettingsExtension)

        notification_center = NotificationCenter()
        notification_center.add_observer(self, sender=self.sip_application)

        branding.setup(self)
Esempio n. 8
0
    def __init__(self):
        super(Blink, self).__init__(sys.argv)
        self.setAttribute(Qt.AA_DontShowIconsInMenus, False)
        self.sip_application = SIPApplication()
        self.first_run = False

        self.setOrganizationDomain("ag-projects.com")
        self.setOrganizationName("AG Projects")
        self.setApplicationName("Blink")
        self.setApplicationVersion(__version__)

        self.main_window = MainWindow()
        self.chat_window = ChatWindow()
        self.main_window.__closed__ = True
        self.chat_window.__closed__ = True
        self.main_window.installEventFilter(self)
        self.chat_window.installEventFilter(self)

        self.main_window.addAction(self.chat_window.control_button.actions.main_window)
        self.chat_window.addAction(self.main_window.quit_action)
        self.chat_window.addAction(self.main_window.help_action)
        self.chat_window.addAction(self.main_window.redial_action)
        self.chat_window.addAction(self.main_window.join_conference_action)
        self.chat_window.addAction(self.main_window.mute_action)
        self.chat_window.addAction(self.main_window.silent_action)
        self.chat_window.addAction(self.main_window.preferences_action)
        self.chat_window.addAction(self.main_window.transfers_window_action)
        self.chat_window.addAction(self.main_window.logs_window_action)
        self.chat_window.addAction(self.main_window.received_files_window_action)
        self.chat_window.addAction(self.main_window.screenshots_window_action)

        self.ip_address_monitor = IPAddressMonitor()
        self.log_manager = LogManager()
        self.presence_manager = PresenceManager()
        self.session_manager = SessionManager()
        self.update_manager = UpdateManager()

        # Prevent application from exiting after last window is closed if system tray was initialized
        if self.main_window.system_tray_icon:
            self.setQuitOnLastWindowClosed(False)

        self.main_window.check_for_updates_action.triggered.connect(self.update_manager.check_for_updates)
        self.main_window.check_for_updates_action.setVisible(self.update_manager != Null)

        if getattr(sys, 'frozen', False):
            XMLDocument.schema_path = Resources.get('xml-schemas')

        Account.register_extension(AccountExtension)
        BonjourAccount.register_extension(BonjourAccountExtension)
        Contact.register_extension(ContactExtension)
        Group.register_extension(GroupExtension)
        SIPSimpleSettings.register_extension(SIPSimpleSettingsExtension)

        notification_center = NotificationCenter()
        notification_center.add_observer(self, sender=self.sip_application)

        branding.setup(self)
Esempio n. 9
0
    def _NH_SIPApplicationWillStart(self, sender, data):
        settings = SIPSimpleSettings()
        _version = str(NSBundle.mainBundle().infoDictionary().objectForKey_("CFBundleShortVersionString"))
        settings.user_agent = "%s %s (MacOSX)" % (NSApp.delegate().applicationName, _version)
        BlinkLogger().log_debug("SIP User Agent: %s" % settings.user_agent)
        settings.save()

        self.migratePasswordsToKeychain()
        self.cleanupIcons()

        # Set audio settings compatible with AEC and Noise Suppression
        settings.audio.sample_rate = 32000 if settings.audio.echo_canceller.enabled else 48000
        if NSApp.delegate().service_provider_help_url and settings.service_provider.help_url != NSApp.delegate().service_provider_help_url:
            settings.service_provider.help_url = NSApp.delegate().service_provider_help_url
            settings.save()

        if NSApp.delegate().service_provider_name and settings.service_provider.name != NSApp.delegate().service_provider_name:
            settings.service_provider.name = NSApp.delegate().service_provider_name
            settings.save()

        BlinkLogger().log_debug("Audio engine sampling rate %dKHz covering 0-%dKHz spectrum" % (settings.audio.sample_rate/1000, settings.audio.sample_rate/1000/2))
        BlinkLogger().log_debug("Acoustic Echo Canceller is %s" % ('enabled' if settings.audio.echo_canceller.enabled else 'disabled'))

        account_manager = AccountManager()
        for account in account_manager.iter_accounts():
            must_save = False
            if account is not BonjourAccount() and account.sip.primary_proxy is None and account.sip.outbound_proxy and not account.sip.selected_proxy:
                account.sip.primary_proxy = account.sip.outbound_proxy

            if account is not BonjourAccount() and settings.tls.verify_server != account.tls.verify_server:
                account.tls.verify_server = settings.tls.verify_server

            if account.tls.certificate and os.path.basename(account.tls.certificate.normalized) != 'default.crt':
                account.tls.certificate = DefaultValue

            if account.rtp.encryption_type == '':
                account.rtp.encryption.enabled = False
            elif account.rtp.encryption_type == 'opportunistic':
                account.rtp.encryption.enabled = True
                account.rtp.encryption.key_negotiation = 'opportunistic'
            elif account.rtp.encryption_type == 'sdes_optional':
                account.rtp.encryption.enabled = True
                account.rtp.encryption.key_negotiation = 'sdes_optional'
            elif account.rtp.encryption_type == 'sdes_mandatory':
                account.rtp.encryption.enabled = True
                account.rtp.encryption.key_negotiation = 'sdes_mandatory'
            elif account.rtp.encryption_type == 'zrtp':
                account.rtp.encryption.enabled = True
                account.rtp.encryption.key_negotiation = 'zrtp'
            account.save()

        logger = FileLogger()
        logger.start()
        self.ip_address_monitor.start()
Esempio n. 10
0
    def init(self):

        Account.register_extension(AccountExtension)
        BonjourAccount.register_extension(BonjourAccountExtension)
        Contact.register_extension(BlinkContactExtension)
        Group.register_extension(BlinkGroupExtension)
        SIPSimpleSettings.register_extension(SIPSimpleSettingsExtension)

        self._app.start(FileStorage(ApplicationData.directory))

        # start session mgr
        SessionManager()
Esempio n. 11
0
    def start(self, options):
        self.options = options
        if self.options.enable_bonjour:
            ServerConfig.enable_bonjour = True

        notification_center = NotificationCenter()
        notification_center.add_observer(self, sender=self)
        notification_center.add_observer(self, name='ThorNetworkGotFatalError')

        Account.register_extension(AccountExtension)
        BonjourAccount.register_extension(BonjourAccountExtension)
        SIPSimpleSettings.register_extension(SylkServerSettingsExtension)

        super(SylkServer, self).start(MemoryStorage())
Esempio n. 12
0
    def __init__(self):
        self.application = SIPApplication()
        self.stopping = False
        self.stop_event = Event()

        Account.register_extension(AccountExtension)
        BonjourAccount.register_extension(BonjourAccountExtension)
        SIPSimpleSettings.register_extension(SIPSimpleSettingsExtension)

        self.account_model = AccountModel()
        self.bonjour_services = BonjourServices()
        self.hal = HardwareAbstractionLayer()
        self.session_manager = SessionManager()
        self.web_handler = WebHandler()
Esempio n. 13
0
    def tableViewSelectionDidChange_(self, notification):
        sv = self.passwordText.superview()
        account_info = self.selectedAccount()
        if account_info:
            account = account_info.account
            self.showOptionsForAccount(account)

            self.addressText.setEditable_(False)
            self.passwordText.setEditable_(True)
            self.displayNameText.setHidden_(False)

            self.advancedToggle.setEnabled_(True)
            self.advancedToggle.setState_(NSOnState)
            self.advancedPop.setHidden_(False)
            self.advancedTabView.setHidden_(False)

            if account is BonjourAccount():
                self.passwordText.setHidden_(True)
                self.addressText.setHidden_(True)
                sv.viewWithTag_(20).setHidden_(True)
                sv.viewWithTag_(21).setHidden_(True)
            else:
                self.passwordText.setHidden_(False)
                self.addressText.setHidden_(False)
                sv.viewWithTag_(20).setHidden_(False)
                sv.viewWithTag_(21).setHidden_(False)
            self.diplay_outbound_proxy_radio_if_needed(account)

        else:
            self.addressText.setStringValue_("Please select an account")
            self.selected_proxy_radio_button.setHidden_(True)
            self.addressText.setEditable_(False)
            self.addressText.setHidden_(False)
            self.passwordText.setHidden_(True)
            self.passwordText.setEditable_(False)
            self.displayNameText.setHidden_(True)

            self.advancedToggle.setEnabled_(False)
            self.advancedToggle.setState_(NSOffState)
            self.advancedPop.setHidden_(True)
            self.advancedTabView.setHidden_(True)

            sv.viewWithTag_(20).setHidden_(False)
            sv.viewWithTag_(21).setHidden_(False)

        self.removeButton.setEnabled_(
            account_info is not None
            and account_info.account is not BonjourAccount())
        self.updateRegistrationStatus()
Esempio n. 14
0
    def _NH_SIPAccountManagerDidAddAccount(self, notification):
        account = notification.data.account

        action = self.accounts_menu.addAction(account.id if account is not BonjourAccount() else 'Bonjour')
        action.setEnabled(True if account is not BonjourAccount() else BonjourAccount.mdns_available)
        action.setCheckable(True)
        action.setChecked(account.enabled)
        action.setData(account)
        action.triggered.connect(self._AH_AccountActionTriggered)

        action = self.voicemail_menu.addAction(self.mwi_icons[0], account.id)
        action.setVisible(False if account is BonjourAccount() else account.enabled and account.message_summary.enabled)
        action.setEnabled(False if account is BonjourAccount() else account.voicemail_uri is not None)
        action.setData(account)
        action.triggered.connect(self._AH_VoicemailActionTriggered)
Esempio n. 15
0
    def textView_doCommandBySelector_(self, textView, selector):
        if selector == "insertNewline:" and self.chatViewController.inputText == textView:
            content = str(textView.string())
            textView.setString_("")
            textView.didChangeText()

            if content:
                self.sendMessage(content)

            self.chatViewController.resetTyping()

            recipient = ChatIdentity(self.target_uri, self.display_name)
            self.notification_center.post_notification(
                'ChatViewControllerDidDisplayMessage',
                sender=self,
                data=NotificationData(
                    direction='outgoing',
                    history_entry=False,
                    remote_party=format_identity_to_string(recipient),
                    local_party=format_identity_to_string(self.account) if
                    self.account is not BonjourAccount() else 'bonjour.local',
                    check_contact=True))

            return True

        return False
Esempio n. 16
0
    def start(self, restart=False):
        self.ft_info = FileTransferInfo(
            transfer_id=self.transfer_id,
            direction='outgoing',
            file_size=self.file_size,
            local_uri=format_identity_to_string(self.account)
            if self.account is not BonjourAccount() else 'bonjour',
            remote_uri=self.remote_identity,
            file_path=self.file_path)
        self.ft_info.status = "pending"
        self.status = "Pending"

        notification_center = NotificationCenter()
        if restart:
            notification_center.post_notification(
                "BlinkFileTransferRestarting",
                self,
                data=TimestampedNotificationData())
        else:
            notification_center.post_notification(
                "BlinkFileTransferInitializing",
                self,
                data=TimestampedNotificationData())

        BlinkLogger().log_info(u"Computing checksum for file %s" %
                               os.path.basename(self.file_path))

        self.stop_event.clear()
        self.initiate_file_transfer()
Esempio n. 17
0
    def __init__(self):
        super(Blink, self).__init__(sys.argv)
        self.application = SIPApplication()
        self.auxiliary_thread = AuxiliaryThread()
        self.first_run = False
        self.main_window = MainWindow()

        self.update_manager = UpdateManager()
        self.main_window.check_for_updates_action.triggered.connect(self.update_manager.check_for_updates)
        self.main_window.check_for_updates_action.setVisible(self.update_manager != Null)

        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)
Esempio n. 18
0
 def _NH_SIPAccountDidActivate(self, account, data):
     BlinkLogger().log_info("Account %s activated" % account.id)
     # Activate BonjourConferenceServer discovery
     if account is BonjourAccount():
         call_in_green_thread(self.bonjour_conference_services.start)
     else:
         BlinkLogger().log_info("Account %s loaded %d CAs from %s" % (account.id, len(account.tls_credentials._trusted), account.ca_list))
Esempio n. 19
0
    def showOptionsForAccount(self, account):
        self.updating = True
        if account.display_name:
            self.displayNameText.setStringValue_(account.display_name)
        else:
            self.displayNameText.setStringValue_(u"")

        if account is not BonjourAccount():
            self.addressText.setStringValue_(unicode(account.id))
            self.passwordText.setStringValue_(account.auth.password)

            userdef = NSUserDefaults.standardUserDefaults()
            section = userdef.integerForKey_("SelectedAdvancedSection")
        else:
            userdef = NSUserDefaults.standardUserDefaults()
            section = userdef.integerForKey_("SelectedAdvancedBonjourSection")

        self.createAccountOptionsUI(account)

        if section is not None:
            if section < self.advancedPop.numberOfItems():
                self.advancedPop.selectItemAtIndex_(section)
                self.advancedTabView.selectTabViewItemAtIndex_(section)

        self.updating = False
Esempio n. 20
0
 def migratePasswordsToKeychain(self):
     account_manager = AccountManager()
     configuration_manager = ConfigurationManager()
     bonjour_account = BonjourAccount()
     for account in (account for account in account_manager.iter_accounts()
                     if account is not bonjour_account):
         try:
             stored_auth_password = configuration_manager.get(
                 account.__key__ + ['auth', 'password'])
         except ObjectNotFoundError:
             stored_auth_password = None
         try:
             stored_ldap_password = configuration_manager.get(
                 account.__key__ + ['ldap', 'password'])
         except ObjectNotFoundError:
             stored_ldap_password = None
         try:
             stored_web_password = configuration_manager.get(
                 account.__key__ + ['server', 'web_password'])
         except ObjectNotFoundError:
             stored_web_password = None
         if (stored_auth_password, stored_ldap_password,
                 stored_web_password) != ('keychain', 'keychain',
                                          'keychain'):
             Account.auth.password.dirty[account.auth] = True
             Account.ldap.password.dirty[account.ldap] = True
             Account.server.web_password.dirty[account.server] = True
             account.save()
Esempio n. 21
0
    def init(self):
        self._version = str(NSBundle.mainBundle().infoDictionary().objectForKey_("CFBundleShortVersionString"))

        #first_start = not os.path.exists(ApplicationData.get('config'))

        Account.register_extension(AccountExtension)
        BonjourAccount.register_extension(BonjourAccountExtension)
        Contact.register_extension(BlinkContactExtension)
        ContactGroup.register_extension(BlinkContactGroupExtension)
        SIPSimpleSettings.register_extension(SIPSimpleSettingsExtension)

        self._app.start(FileStorage(ApplicationData.directory))
        self.init_configurations()

        # start session mgr
        SessionManager()
Esempio n. 22
0
 def filterAcceptsRow(self, source_row, source_parent):
     source_model = self.sourceModel()
     source_index = source_model.index(source_row, 0, source_parent)
     account_info = source_model.data(source_index, Qt.UserRole)
     return bool(account_info.account is not BonjourAccount()
                 and account_info.account.enabled
                 and account_info.account.server.settings_url)
Esempio n. 23
0
 def _NH_SIPApplicationDidStart(self, notification):
     self.ip_address_monitor.start()
     self.main_window.show()
     accounts = AccountManager().get_accounts()
     if not accounts or (self.first_run and accounts == [BonjourAccount()]):
         self.main_window.preferences_window.show_create_account_dialog()
     self.update_manager.initialize()
Esempio n. 24
0
 def init_policy_data(self, account):
     if account is not BonjourAccount():
         if not self.policy_data.has_key(account.id):
             self.policy_data[account.id] = {}
         for event in self.tabViewForEvent.keys():
             if not self.policy_data[account.id].has_key(event):
                 self.policy_data[account.id][event] = []
Esempio n. 25
0
    def offline_state(self):
        if self.account is BonjourAccount():
            return None

        blink_settings = BlinkSettings()

        account_id = hashlib.md5(self.account.id.encode()).hexdigest()
        timestamp = ISOTimestamp.now()

        doc = pidf.PIDF(str(self.account.uri))

        person = pidf.Person('PID-%s' % account_id)
        person.timestamp = timestamp
        person.activities = rpid.Activities()
        person.activities.add('offline')
        doc.add(person)

        service = pidf.Service('SID-%s' % account_id)
        service.status = 'closed'
        service.status.extended = 'offline'
        service.contact = str(self.account.uri)
        service.timestamp = timestamp
        service.capabilities = caps.ServiceCapabilities()
        service.display_name = self.account.display_name or None
        service.icon = "%s#blink-icon%s" % (
            self.account.xcap.icon.url, self.account.xcap.icon.etag
        ) if self.account.xcap.icon is not None else None
        if blink_settings.presence.offline_note:
            service.notes.add(blink_settings.presence.offline_note)
        doc.add(service)

        return doc
Esempio n. 26
0
 def _NH_SIPSessionDidEnd(self, notification):
     if notification.sender.account is BonjourAccount():
         return
     session = notification.sender
     entry = HistoryEntry.from_session(session)
     bisect.insort(self.calls, entry)
     self.calls = self.calls[-self.history_size:]
     self.save()
Esempio n. 27
0
    def start(self, restart=False):
        notification_center = NotificationCenter()
        file_path = self._file_selector.name.decode() if isinstance(
            self._file_selector.name, bytes) else self._file_selector.name

        self.ft_info = FileTransferInfo(
            transfer_id=str(uuid.uuid4()),
            direction='outgoing',
            file_size=self._file_selector.size,
            local_uri=format_identity_to_string(self.account)
            if self.account is not BonjourAccount() else 'bonjour.local',
            remote_uri=self.remote_identity,
            file_path=file_path)

        self.status = NSLocalizedString("Offering File...", "Label")
        self.ft_info.status = "proposing"

        self.log_info("Initiating DNS Lookup of %s to %s" %
                      (self.account, self.target_uri))
        lookup = DNSLookup()
        notification_center.add_observer(self, sender=lookup)

        if isinstance(self.account,
                      Account) and self.account.sip.outbound_proxy is not None:
            uri = SIPURI(host=self.account.sip.outbound_proxy.host,
                         port=self.account.sip.outbound_proxy.port,
                         parameters={
                             'transport':
                             self.account.sip.outbound_proxy.transport
                         })
            self.log_info("Initiating DNS Lookup for %s (through proxy %s)" %
                          (self.target_uri, uri))
        elif isinstance(self.account,
                        Account) and self.account.sip.always_use_my_proxy:
            uri = SIPURI(host=self.account.id.domain)
            self.log_info(
                "Initiating DNS Lookup for %s (through account %s proxy)" %
                (self.target_uri, self.account.id))
        else:
            uri = self.target_uri
            self.log_info("Initiating DNS Lookup for %s" % self.target_uri)

        settings = SIPSimpleSettings()

        tls_name = None
        if isinstance(self.account, Account):
            tls_name = self.account.sip.tls_name or self.account.id.domain

        lookup.lookup_sip_proxy(uri,
                                settings.sip.transport_list,
                                tls_name=tls_name)

        if restart:
            notification_center.post_notification(
                "BlinkFileTransferWillRestart", self)
        else:
            notification_center.post_notification(
                "BlinkFileTransferNewOutgoing", sender=self)
Esempio n. 28
0
 def _resolve_cb(self, file, flags, interface_index, error_code, fullname,
                 host_target, port, txtrecord):
     notification_center = NotificationCenter()
     settings = SIPSimpleSettings()
     file = BonjourResolutionFile.find_by_file(file)
     if error_code == bonjour.kDNSServiceErr_NoError:
         txt = bonjour.TXTRecord.parse(txtrecord)
         name = txt['name'].decode('utf-8') if 'name' in txt else None
         host = re.match(r'^(.*?)(\.local)?\.?$', host_target).group(1)
         contact = txt.get('contact', file.service_description.name).split(
             None, 1)[0].strip('<>')
         try:
             uri = FrozenSIPURI.parse(contact)
         except SIPCoreError:
             pass
         else:
             account = BonjourAccount()
             service_description = file.service_description
             transport = uri.transport
             supported_transport = transport in settings.sip.transport_list and (
                 transport != 'tls' or account.tls.certificate is not None)
             if not supported_transport and service_description in self._servers:
                 del self._servers[service_description]
                 notification_center.post_notification(
                     'BonjourConferenceServicesDidRemoveServer',
                     sender=self,
                     data=TimestampedNotificationData(
                         server=service_description))
             elif supported_transport:
                 try:
                     contact_uri = account.contact[transport]
                 except KeyError:
                     return
                 if uri != contact_uri:
                     notification_name = 'BonjourConferenceServicesDidUpdateServer' if service_description in self._servers else 'BonjourConferenceServicesDidAddServer'
                     notification_data = TimestampedNotificationData(
                         server=service_description,
                         name=name,
                         host=host,
                         uri=uri)
                     server_description = BonjourConferenceServerDescription(
                         uri, host, name)
                     self._servers[service_description] = server_description
                     notification_center.post_notification(
                         notification_name,
                         sender=self,
                         data=notification_data)
     else:
         self._files.remove(file)
         self._select_proc.kill(RestartSelect)
         file.close()
         error = bonjour.BonjourError(error_code)
         notification_center.post_notification(
             'BonjourConferenceServicesDiscoveryFailure',
             sender=self,
             data=TimestampedNotificationData(error=str(error),
                                              transport=file.transport))
Esempio n. 29
0
    def updateBonjourPresenceState(self):
        bonjour_account = BonjourAccount()
        if not bonjour_account.enabled:
            return

        status = None
        note = self.owner.presenceNoteText.stringValue()
        selected_item = self.owner.presenceActivityPopUp.selectedItem()
        if selected_item is not None:
            activity_object = selected_item.representedObject()
            if activity_object is not None:
                status = activity_object['extended_status']
        if status in (None, 'offline'):
            bonjour_account.presence_state = None
        else:
            bonjour_account.presence_state = BonjourPresenceState(status, note)

        NotificationCenter().post_notification('BonjourAccountPresenceStateDidChange', sender=bonjour_account)
Esempio n. 30
0
    def init(self):
        self._version = str(
            NSBundle.mainBundle().infoDictionary().objectForKey_(
                "CFBundleShortVersionString"))

        #first_start = not os.path.exists(ApplicationData.get('config'))

        Account.register_extension(AccountExtension)
        BonjourAccount.register_extension(BonjourAccountExtension)
        Contact.register_extension(BlinkContactExtension)
        ContactGroup.register_extension(BlinkContactGroupExtension)
        SIPSimpleSettings.register_extension(SIPSimpleSettingsExtension)

        self._app.start(FileStorage(ApplicationData.directory))
        self.init_configurations()

        # start session mgr
        SessionManager()
Esempio n. 31
0
    def _NH_SIPApplicationDidStart(self, sender, data):
        settings = SIPSimpleSettings()
        settings.audio.enable_aec = settings.audio.echo_canceller.enabled
        settings.audio.sound_card_delay = settings.audio.echo_canceller.tail_length
        self._app.engine.enable_colorbar_device = False

        BlinkLogger().log_debug("SDK loaded")
        BlinkLogger().log_debug("SIP device ID: %s" % settings.instance_id)
        available_codecs_print = list(beautify_audio_codec(codec.decode()) for codec in self._app.engine._ua.available_codecs)
        codecs_print = list(beautify_audio_codec(codec) for codec in settings.rtp.audio_codec_list)
        BlinkLogger().log_info("Available audio codecs: %s" % ", ".join(available_codecs_print))
        BlinkLogger().log_info("Enabled audio codecs: %s" % ", ".join(codecs_print))

        if settings.audio.input_device is None:
            BlinkLogger().log_info("Switching audio input device to system default")
            settings.audio.input_device = 'system_default'
        if settings.audio.output_device is None:
            BlinkLogger().log_info("Switching audio output device to system default")
            settings.audio.output_device = 'system_default'
        if settings.audio.alert_device is None:
            BlinkLogger().log_info("Switching audio alert device to system default")
            settings.audio.alert_device = 'system_default'

        try:
            from VideoController import VideoController
        except ImportError:
            pass
        else:
            if settings.video.max_bitrate is not None and settings.video.max_bitrate > 10000:
                settings.video.max_bitrate = 4.0

            available_video_codecs_print = list(beautify_video_codec(codec.decode()) for codec in self._app.engine._ua.available_video_codecs)
            video_codecs_print = list(beautify_video_codec(codec) for codec in settings.rtp.video_codec_list)
            BlinkLogger().log_info("Available video codecs: %s" % ", ".join(available_video_codecs_print))
            BlinkLogger().log_info("Enabled video codecs: %s" % ", ".join(video_codecs_print))
            BlinkLogger().log_info(u"Available video cameras: %s" % ", ".join(NSApp.delegate().video_devices))
            if settings.video.device != "system_default" and settings.video.device != self._app.video_device.real_name and self._app.video_device.real_name != None:
                settings.video.device = self._app.video_device.real_name
                BlinkLogger().log_info(u"Using video camera %s" % self._app.video_device.real_name)
            elif settings.video.device is None:
                devices = list(device for device in self._app.engine.video_devices if device not in ('system_default', None))
                if devices:
                    BlinkLogger().log_info("Switching video camera to %s" % devices[0])
                    settings.video.device = devices[0]
            else:
                BlinkLogger().log_info("Using video camera %s" % self._app.video_device.real_name)
        settings.save()

        bonjour_account = BonjourAccount()
        if bonjour_account.enabled:
            for transport in settings.sip.transport_list:
                try:
                    BlinkLogger().log_debug('Bonjour Account listens on %s' % bonjour_account.contact[transport])
                except KeyError:
                    pass

        self.init_configurations()
    def updateBonjourPresenceState(self):
        bonjour_account = BonjourAccount()
        if not bonjour_account.enabled:
            return

        status = None
        settings = SIPSimpleSettings()
        note = settings.presence_state.note
        selected_item = self.owner.presenceActivityPopUp.selectedItem()
        if selected_item is not None:
            activity_object = selected_item.representedObject()
            if activity_object is not None:
                status = activity_object['extended_status']
        if status in (None, 'offline'):
            bonjour_account.presence_state = None
        else:
            bonjour_account.presence_state = BonjourPresenceState(status, note)

        NotificationCenter().post_notification('BonjourAccountPresenceStateDidChange', sender=bonjour_account)
Esempio n. 33
0
 def _CH_discover(self, command):
     notification_center = NotificationCenter()
     settings = SIPSimpleSettings()
     if self._discover_timer is not None and self._discover_timer.active():
         self._discover_timer.cancel()
     self._discover_timer = None
     account = BonjourAccount()
     supported_transports = set(
         transport for transport in settings.sip.transport_list
         if transport != 'tls' or account.tls.certificate is not None)
     discoverable_transports = set(
         'tcp' if transport == 'tls' else transport
         for transport in supported_transports)
     old_files = []
     for file in (
             f for f in self._files[:]
             if isinstance(f, (BonjourDiscoveryFile, BonjourResolutionFile))
             and f.transport not in discoverable_transports):
         old_files.append(file)
         self._files.remove(file)
     self._select_proc.kill(RestartSelect)
     for file in old_files:
         file.close()
     for service_description in [
             service for service, description in self._servers.iteritems()
             if description.uri.transport not in supported_transports
     ]:
         del self._servers[service_description]
         notification_center.post_notification(
             'BonjourConferenceServicesDidRemoveServer',
             sender=self,
             data=TimestampedNotificationData(server=service_description))
     discovered_transports = set(file.transport for file in self._files
                                 if isinstance(file, BonjourDiscoveryFile))
     missing_transports = discoverable_transports - discovered_transports
     added_transports = set()
     for transport in missing_transports:
         notification_center.post_notification(
             'BonjourConferenceServicesWillInitiateDiscovery',
             sender=self,
             data=TimestampedNotificationData(transport=transport))
         try:
             file = bonjour.DNSServiceBrowse(regtype="_sipfocus._%s" %
                                             transport,
                                             callBack=self._browse_cb)
         except bonjour.BonjourError, e:
             notification_center.post_notification(
                 'BonjourConferenceServicesDiscoveryDidFail',
                 sender=self,
                 data=TimestampedNotificationData(reason=str(e),
                                                  transport=transport))
         else:
             self._files.append(BonjourDiscoveryFile(file, transport))
             added_transports.add(transport)
Esempio n. 34
0
 def _NH_SIPAccountWillActivate(self, notification):
     if notification.sender is not BonjourAccount():
         notification.center.add_observer(self,
                                          sender=notification.sender,
                                          name='CFGSettingsObjectDidChange')
         notification.center.add_observer(self,
                                          sender=notification.sender,
                                          name='SIPAccountGotPresenceState')
         notification.center.add_observer(self,
                                          sender=notification.sender,
                                          name='SIPAccountGotPresenceWinfo')
Esempio n. 35
0
 def _NH_SIPApplicationDidStart(self, notification):
     self.ip_address_monitor.start()
     self.fetch_account()
     self.main_window.show()
     settings = SIPSimpleSettings()
     accounts = AccountManager().get_accounts()
     if not accounts or (self.first_run and accounts==[BonjourAccount()]):
         self.main_window.preferences_window.show_create_account_dialog()
     if settings.google_contacts.authorization_token is InvalidToken:
         self.main_window.google_contacts_dialog.open_for_incorrect_password()
     self.update_manager.initialize()
Esempio n. 36
0
    def init(self):
        if NSApp.delegate().account_extension:
            Account.register_extension(NSApp.delegate().account_extension)
        else:
            Account.register_extension(AccountExtension)

        BonjourAccount.register_extension(BonjourAccountExtension)
        Contact.register_extension(BlinkContactExtension)
        Group.register_extension(BlinkGroupExtension)
        ContactURI.register_extension(BlinkContactURIExtension)
        if NSApp.delegate().general_extension:
            SIPSimpleSettings.register_extension(NSApp.delegate().general_extension)
        else:
            SIPSimpleSettings.register_extension(SIPSimpleSettingsExtension)

        app = AppKit.NSApplication.sharedApplication()
        self._app.start(FileStorage(ApplicationData.directory))

        # start session mgr
        SessionManager()
Esempio n. 37
0
    def _NH_SIPEngineTransportDidDisconnect(self, notification):
        self.transport_lost_timestamp = int(time.time())

        transport = '%s:%s' % (notification.data.transport,
                               notification.data.remote_address)
        try:
            self.active_transports.remove(transport)
        except KeyError:
            return

        for account_info in self.contactsWindowController.accounts:
            account = account_info.account

            if account is BonjourAccount():
                continue

            if not account.enabled:
                continue

            if account_info.registrar != transport:
                continue

            account_info.register_state = 'failed'

            if host is None or host.default_ip is None:
                account_info.register_failure_reason = NSLocalizedString(
                    "No Internet connection", "Label")
            else:
                account_info.register_failure_reason = NSLocalizedString(
                    "Connection failed", "Label")

            self.contactsWindowController.refreshAccountList()
            BlinkLogger().log_info('Reconnecting account %s' % account.id)

            account.reregister()
            account.resubscribe()
            presence_state = account.presence_state
            account.presence_state = None
            account.presence_state = presence_state

        if notification.data.reason != 'Success':
            BlinkLogger().log_info(
                "%s connection %s <-> %s lost" %
                (notification.data.transport, notification.data.local_address,
                 notification.data.remote_address))
            #nc_title = NSLocalizedString("Connection failed", "Label")
            #nc_body = NSLocalizedString("Remote Address", "Label") + " %s:%s" % (notification.data.transport, notification.data.remote_address)
            #self.gui_notify(nc_title, nc_body)

        else:
            NotificationCenter().post_notification(
                "BlinkTransportFailed",
                data=NotificationData(transport=transport))
Esempio n. 38
0
 def diplay_outbound_proxy_radio_if_needed(self, account):
     tab = self.advancedTabView.selectedTabViewItem()
     if account is not BonjourAccount():
         self.selected_proxy_radio_button.setHidden_(
             False if tab.identifier() == 'sip'
             and self.advancedToggle.state() == NSOnState else True)
         self.selected_proxy_radio_button.setEnabled_(
             True if account.sip.always_use_my_proxy
             and account.sip.alternative_proxy is not None else False)
         self.selected_proxy_radio_button.selectCellWithTag_(
             account.sip.selected_proxy)
     else:
         self.selected_proxy_radio_button.setHidden_(True)