Ejemplo n.º 1
0
 def __init__(self, account, uri, display_name, parent=None):
     super(PendingWatcherDialog, self).__init__(parent)
     self.setWindowFlags(Qt.WindowStaysOnTopHint)
     self.setAttribute(Qt.WA_DeleteOnClose)
     with Resources.directory:
         self.setupUi(self)
     addressbook_manager = addressbook.AddressbookManager()
     try:
         self.contact = next(contact for contact in addressbook_manager.get_contacts() if uri in (addr.uri for addr in contact.uris))
     except StopIteration:
         self.contact = None
     else:
         display_name = self.contact.name
         icon_manager = IconManager()
         icon = icon_manager.get(self.contact.id)
         if icon is not None:
             self.user_icon.setPixmap(icon.pixmap(32))
     self.account_label.setText(u'For account %s' % account.id)
     self.name_label.setText(display_name or uri)
     self.uri_label.setText(uri)
     font = self.name_label.font()
     font.setPointSizeF(self.uri_label.fontInfo().pointSizeF() + 3)
     font.setFamily("Sans Serif")
     self.name_label.setFont(font)
     self.accept_button.released.connect(self._accept_watcher)
     self.block_button.released.connect(self._block_watcher)
     self.position = None
     self.timer = QTimer()
     self.timer.timeout.connect(self._SH_TimerFired)
     self.timer.start(60000)
Ejemplo n.º 2
0
 def __init__(self, account, uri, display_name, parent=None):
     super(PendingWatcherDialog, self).__init__(parent)
     self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
     self.setAttribute(Qt.WA_DeleteOnClose)
     with Resources.directory:
         self.setupUi(self)
     default_font_size = self.uri_label.fontInfo().pointSizeF()
     name_font_size = limit(default_font_size + 3, max=14)
     font = self.name_label.font()
     font.setPointSizeF(name_font_size)
     self.name_label.setFont(font)
     addressbook_manager = addressbook.AddressbookManager()
     try:
         self.contact = next(contact for contact in addressbook_manager.get_contacts() if uri in (addr.uri for addr in contact.uris))
     except StopIteration:
         self.contact = None
     else:
         display_name = self.contact.name
         icon_manager = IconManager()
         icon = icon_manager.get(self.contact.id)
         if icon is not None:
             self.user_icon.setPixmap(icon.pixmap(48))
     self.description_label.setText(u'Wants to subscribe to your availability information at {}'.format(account.id))
     self.name_label.setText(display_name or uri)
     self.uri_label.setText(uri)
     self.accept_button.released.connect(self._accept_watcher)
     self.block_button.released.connect(self._block_watcher)
     self.position = None
     self.timer = QTimer()
     self.timer.timeout.connect(self._SH_TimerFired)
     self.timer.start(60000)
Ejemplo n.º 3
0
    def _NH_XCAPManagerDidReloadData(self, notification):
        account = notification.sender.account
        blink_settings = BlinkSettings()
        icon_manager = IconManager()

        offline_status = notification.data.offline_status
        status_icon = notification.data.status_icon

        try:
            offline_note = next(note for service in offline_status.pidf.services for note in service.notes)
        except (AttributeError, StopIteration):
            offline_note = None

        blink_settings.presence.offline_note = offline_note
        blink_settings.save()

        if status_icon:
            icon_hash = hashlib.sha1(status_icon.data).hexdigest()
            icon_desc = IconDescriptor(status_icon.url, icon_hash)
            if not blink_settings.presence.icon or blink_settings.presence.icon.etag != icon_hash:
                icon = icon_manager.store_data('avatar', status_icon.data)
                blink_settings.presence.icon = IconDescriptor(FileURL(icon.filename), icon_hash) if icon is not None else None
                blink_settings.save()
        else:
            icon_desc = None
            icon_manager.remove('avatar')
            blink_settings.presence.icon = None
            blink_settings.save()

        account.xcap.icon = icon_desc
        account.save()
Ejemplo n.º 4
0
 def __init__(self, account, uri, display_name, parent=None):
     super(PendingWatcherDialog, self).__init__(parent)
     self.setWindowFlags(Qt.WindowStaysOnTopHint)
     self.setAttribute(Qt.WA_DeleteOnClose)
     with Resources.directory:
         self.setupUi(self)
     addressbook_manager = addressbook.AddressbookManager()
     try:
         self.contact = next(
             contact for contact in addressbook_manager.get_contacts()
             if uri in (addr.uri for addr in contact.uris))
     except StopIteration:
         self.contact = None
     else:
         display_name = self.contact.name
         icon_manager = IconManager()
         icon = icon_manager.get(self.contact.id)
         if icon is not None:
             self.user_icon.setPixmap(icon.pixmap(32))
     self.account_label.setText(u'For account %s' % account.id)
     self.name_label.setText(display_name or uri)
     self.uri_label.setText(uri)
     font = self.name_label.font()
     font.setPointSizeF(self.uri_label.fontInfo().pointSizeF() + 3)
     font.setFamily("Sans Serif")
     self.name_label.setFont(font)
     self.accept_button.released.connect(self._accept_watcher)
     self.block_button.released.connect(self._block_watcher)
     self.position = None
     self.timer = QTimer()
     self.timer.timeout.connect(self._SH_TimerFired)
     self.timer.start(60000)
Ejemplo n.º 5
0
 def __init__(self, account, uri, display_name, parent=None):
     super(PendingWatcherDialog, self).__init__(parent)
     self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
     self.setAttribute(Qt.WA_DeleteOnClose)
     with Resources.directory:
         self.setupUi(self)
     default_font_size = self.uri_label.fontInfo().pointSizeF()
     name_font_size = limit(default_font_size + 3, max=14)
     font = self.name_label.font()
     font.setPointSizeF(name_font_size)
     self.name_label.setFont(font)
     addressbook_manager = addressbook.AddressbookManager()
     try:
         self.contact = next(
             contact for contact in addressbook_manager.get_contacts()
             if uri in (addr.uri for addr in contact.uris))
     except StopIteration:
         self.contact = None
     else:
         display_name = self.contact.name
         icon_manager = IconManager()
         icon = icon_manager.get(self.contact.id)
         if icon is not None:
             self.user_icon.setPixmap(icon.pixmap(48))
     self.description_label.setText(
         'Wants to subscribe to your availability information at {}'.format(
             account.id))
     self.name_label.setText(display_name or uri)
     self.uri_label.setText(uri)
     self.accept_button.released.connect(self._accept_watcher)
     self.block_button.released.connect(self._block_watcher)
     self.position = None
     self.timer = QTimer()
     self.timer.timeout.connect(self._SH_TimerFired)
     self.timer.start(60000)
Ejemplo n.º 6
0
 def _update_presence_state(self, contact, state, note, icon):
     icon_manager = IconManager()
     contact.presence.state = state
     contact.presence.note = note
     if icon is not None:
         icon_manager.store_data(contact.id, icon.data)
         contact.icon = icon.descriptor
     contact.save()
Ejemplo n.º 7
0
 def _update_presence_state(self, contact, state, note, icon):
     icon_manager = IconManager()
     contact.presence.state = state
     contact.presence.note = note
     if icon is not None:
         icon_manager.store_data(contact.id, icon.data)
         contact.icon = icon.descriptor
     contact.save()
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
 def init_with_contact(self, contact):
     if contact is None:
         self.icon = self.contact_icon = None
     else:
         icon_manager = IconManager()
         self.contact_icon = icon_manager.get(contact.id)
         self.icon = icon_manager.get(contact.id + '_alt') or self.contact_icon
         if contact.alternate_icon is not None:
             self.last_icon_directory = os.path.dirname(contact.alternate_icon.url.path)
     self.filename = self.NotSelected
Ejemplo n.º 11
0
 def init_with_contact(self, contact):
     if contact is None:
         self.icon = self.contact_icon = None
     else:
         icon_manager = IconManager()
         self.contact_icon = icon_manager.get(contact.id)
         self.icon = icon_manager.get(contact.id + '_alt') or self.contact_icon
         if contact.alternate_icon is not None:
             self.last_icon_directory = os.path.dirname(contact.alternate_icon.url.path)
     self.filename = self.NotSelected
Ejemplo n.º 12
0
    def _NH_XCAPManagerDidReloadData(self, notification):
        account = notification.sender.account
        blink_settings = BlinkSettings()
        icon_manager = IconManager()

        offline_status = notification.data.offline_status
        status_icon = notification.data.status_icon

        try:
            offline_note = next(note
                                for service in offline_status.pidf.services
                                for note in service.notes)
        except (AttributeError, StopIteration):
            offline_note = None

        blink_settings.presence.offline_note = offline_note
        blink_settings.save()

        try:
            offline_icon = next(service.icon
                                for service in offline_status.pidf.services)
        except (AttributeError, StopIteration):
            offline_icon_hash = None
        else:
            offline_icon_hash = str(offline_icon).partition(
                '#blink-icon')[2] or None

        if status_icon:
            icon_hash = hashlib.sha1(status_icon.data).hexdigest()
            icon_desc = IconDescriptor(status_icon.url, icon_hash)
            if not blink_settings.presence.icon or blink_settings.presence.icon.etag != icon_hash:
                icon = icon_manager.store_data('avatar', status_icon.data)
                blink_settings.presence.icon = IconDescriptor(
                    FileURL(icon.filename),
                    icon_hash) if icon is not None else None
                blink_settings.save()
            elif account.xcap.icon != icon_desc and icon_hash != offline_icon_hash:
                self._should_set_offline_status.add(account.id)
        else:
            if blink_settings.presence.icon is None is not account.xcap.icon:
                self._should_set_offline_status.add(account.id)
            elif blink_settings.presence.icon is account.xcap.icon is offline_status is None and account.xcap_manager.pidf_manipulation.supported:
                state = BlinkPresenceState(account).offline_state
                account.xcap_manager.set_offline_status(
                    OfflineStatus(state) if state is not None else None)
            icon_desc = None
            icon_manager.remove('avatar')
            blink_settings.presence.icon = None
            blink_settings.save()

        account.xcap.icon = icon_desc
        account.save()
Ejemplo n.º 13
0
 def _NH_CFGSettingsObjectDidChange(self, notification):
     if notification.sender is BlinkSettings():
         account_manager = AccountManager()
         if 'presence.offline_note' in notification.data.modified:
             for account in (account for account in account_manager.get_accounts() if account.xcap.discovered):
                 state = BlinkPresenceState(account).offline_state
                 account.xcap_manager.set_offline_status(OfflineStatus(state) if state is not None else None)
         if 'presence.icon' in notification.data.modified:
             icon = IconManager().get('avatar')
             status_icon = Icon(icon.content, icon.content_type) if icon is not None else None
             for account in (account for account in account_manager.get_accounts() if account.xcap.discovered):
                 account.xcap_manager.set_status_icon(status_icon)
         if 'presence.current_state' in notification.data.modified:
             for account in (account for account in account_manager.get_accounts() if account.enabled and account.presence.enabled):
                 account.presence_state = BlinkPresenceState(account).online_state
     else:
         account = notification.sender
         if {'xcap.enabled', 'xcap.xcap_root'}.intersection(notification.data.modified):
             account.xcap.icon = None
             account.save()
         elif {'presence.enabled', 'display_name', 'xcap.icon'}.intersection(notification.data.modified) and account.presence.enabled:
             account.presence_state = BlinkPresenceState(account).online_state
             if account.xcap.discovered and (set(notification.data.modified) != {'xcap.icon'} or account.id in self._should_set_offline_status):
                 state = BlinkPresenceState(account).offline_state
                 account.xcap_manager.set_offline_status(OfflineStatus(state) if state is not None else None)
             if account.id in self._should_set_offline_status:  # do not use set.discard() here to avoid race conditions. it should only be removed if present.
                 self._should_set_offline_status.remove(account.id)
Ejemplo n.º 14
0
    def _NH_XCAPManagerDidReloadData(self, notification):
        account = notification.sender.account
        blink_settings = BlinkSettings()
        icon_manager = IconManager()

        offline_status = notification.data.offline_status
        status_icon = notification.data.status_icon

        try:
            offline_note = next(note for service in offline_status.pidf.services for note in service.notes)
        except (AttributeError, StopIteration):
            offline_note = None

        blink_settings.presence.offline_note = offline_note
        blink_settings.save()

        try:
            offline_icon = next(service.icon for service in offline_status.pidf.services)
        except (AttributeError, StopIteration):
            offline_icon_hash = None
        else:
            offline_icon_hash = str(offline_icon).partition('#blink-icon')[2] or None

        if status_icon:
            icon_hash = hashlib.sha1(status_icon.data).hexdigest()
            icon_desc = IconDescriptor(status_icon.url, icon_hash)
            if not blink_settings.presence.icon or blink_settings.presence.icon.etag != icon_hash:
                icon = icon_manager.store_data('avatar', status_icon.data)
                blink_settings.presence.icon = IconDescriptor(FileURL(icon.filename), icon_hash) if icon is not None else None
                blink_settings.save()
            elif account.xcap.icon != icon_desc and icon_hash != offline_icon_hash:
                self._should_set_offline_status.add(account.id)
        else:
            if blink_settings.presence.icon is None is not account.xcap.icon:
                self._should_set_offline_status.add(account.id)
            elif blink_settings.presence.icon is account.xcap.icon is offline_status is None and account.xcap_manager.pidf_manipulation.supported:
                state = BlinkPresenceState(account).offline_state
                account.xcap_manager.set_offline_status(OfflineStatus(state) if state is not None else None)
            icon_desc = None
            icon_manager.remove('avatar')
            blink_settings.presence.icon = None
            blink_settings.save()

        account.xcap.icon = icon_desc
        account.save()
Ejemplo n.º 15
0
 def setupUi(self):
     super(ServerToolsWindow, self).setupUi(self)
     self.account_button.default_avatar = QIcon(Resources.get('icons/default-avatar.png'))
     self.account_button.setIcon(IconManager().get('avatar') or self.account_button.default_avatar)
     self.account_button.setMenu(QMenu(self.account_button))
     self.back_button.setMenu(QMenu(self.back_button))
     self.back_button.setEnabled(False)
     self.forward_button.setMenu(QMenu(self.forward_button))
     self.forward_button.setEnabled(False)
Ejemplo n.º 16
0
    def resolveAvatarUrl(self, url):
        if url.startswith("/avatar/"):
            uri = SIPURI.parse(url[8:].decode("hex"))

            # TODO: see if there is an official way to get this, including notification of changes
            # also needs fixing of webodf, allowing custom avatar renderer
            if self.account.uri == uri:
                avatar = IconManager().get('avatar')
                return avatar.filename if avatar != None else self.default_user_icon_filename

            contact, contact_uri = URIUtils.find_contact(uri)
            return contact.icon.filename

        return ""
Ejemplo n.º 17
0
 def _SH_AccountStateClicked(self, checked):
     filename = QFileDialog.getOpenFileName(self, 'Select Icon', self.last_icon_directory, "Images (*.png *.tiff *.jpg *.xmp *.svg)")[0]
     if filename:
         self.last_icon_directory = os.path.dirname(filename)
         filename = filename if os.path.realpath(filename) != os.path.realpath(self.default_icon_path) else None
         blink_settings = BlinkSettings()
         icon_manager = IconManager()
         if filename is not None:
             icon = icon_manager.store_file('avatar', filename)
             if icon is not None:
                 blink_settings.presence.icon = IconDescriptor(FileURL(icon.filename), hashlib.sha1(icon.content).hexdigest())
             else:
                 icon_manager.remove('avatar')
                 blink_settings.presence.icon = None
         else:
             icon_manager.remove('avatar')
             blink_settings.presence.icon = None
         blink_settings.save()
Ejemplo n.º 18
0
 def _SH_AccountStateClicked(self, checked):
     filename = QFileDialog.getOpenFileName(self, u'Select Icon', self.last_icon_directory, u"Images (*.png *.tiff *.jpg *.xmp *.svg)")
     if filename:
         self.last_icon_directory = os.path.dirname(filename)
         filename = filename if os.path.realpath(filename) != os.path.realpath(self.default_icon_path) else None
         blink_settings = BlinkSettings()
         icon_manager = IconManager()
         if filename is not None:
             icon = icon_manager.store_file('avatar', filename)
             if icon is not None:
                 blink_settings.presence.icon = IconDescriptor(FileURL(icon.filename), hashlib.sha1(icon.content).hexdigest())
             else:
                 icon_manager.remove('avatar')
                 blink_settings.presence.icon = None
         else:
             icon_manager.remove('avatar')
             blink_settings.presence.icon = None
         blink_settings.save()
Ejemplo n.º 19
0
 def update_from_contact(self, contact):
     icon_manager = IconManager()
     if self.icon is self.contact_icon:
         self.icon = self.contact_icon = icon_manager.get(contact.id)
     else:
         self.contact_icon = icon_manager.get(contact.id)
Ejemplo n.º 20
0
 def _NH_SIPAccountDidDiscoverXCAPSupport(self, notification):
     account = notification.sender
     icon = IconManager().get('avatar')
     if icon is not None:
         account.xcap_manager.set_status_icon(
             Icon(icon.content, icon.content_type))
Ejemplo n.º 21
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.saved_account_state = None

        notification_center = NotificationCenter()
        notification_center.add_observer(self, name='SIPApplicationWillStart')
        notification_center.add_observer(self, name='SIPApplicationDidStart')
        notification_center.add_observer(self, name='SIPAccountGotMessageSummary')
        notification_center.add_observer(self, name='SIPAccountGotPendingWatcher')
        notification_center.add_observer(self, name='BlinkSessionNewOutgoing')
        notification_center.add_observer(self, name='BlinkSessionDidReinitializeForOutgoing')
        notification_center.add_observer(self, name='BlinkSessionTransferNewOutgoing')
        notification_center.add_observer(self, name='BlinkFileTransferNewIncoming')
        notification_center.add_observer(self, name='BlinkFileTransferNewOutgoing')
        notification_center.add_observer(self, sender=AccountManager())

        icon_manager = IconManager()

        self.pending_watcher_dialogs = []

        self.mwi_icons = [QIcon(Resources.get('icons/mwi-%d.png' % i)) for i in range(0, 11)]
        self.mwi_icons.append(QIcon(Resources.get('icons/mwi-many.png')))

        with Resources.directory:
            self.setupUi()

        self.setWindowTitle('Blink')

        geometry = QSettings().value("main_window/geometry")
        if geometry:
            self.restoreGeometry(geometry)

        self.default_icon_path = Resources.get('icons/default-avatar.png')
        self.default_icon = QIcon(self.default_icon_path)
        self.last_icon_directory = Path('~').normalized
        self.set_user_icon(icon_manager.get('avatar'))

        self.active_sessions_label.hide()
        self.enable_call_buttons(False)
        self.conference_button.setEnabled(False)
        self.hangup_all_button.setEnabled(False)
        self.sip_server_settings_action.setEnabled(False)
        self.search_for_people_action.setEnabled(False)
        self.history_on_server_action.setEnabled(False)
        self.main_view.setCurrentWidget(self.contacts_panel)
        self.contacts_view.setCurrentWidget(self.contact_list_panel)
        self.search_view.setCurrentWidget(self.search_list_panel)

        # System tray
        if QSystemTrayIcon.isSystemTrayAvailable():
            self.system_tray_icon = QSystemTrayIcon(QIcon(Resources.get('icons/blink.png')), self)
            self.system_tray_icon.activated.connect(self._SH_SystemTrayIconActivated)
            menu = QMenu(self)
            menu.addAction("Show", self._AH_SystemTrayShowWindow)
            menu.addAction(QIcon(Resources.get('icons/application-exit.png')), "Quit", self._AH_QuitActionTriggered)
            self.system_tray_icon.setContextMenu(menu)
            self.system_tray_icon.show()
        else:
            self.system_tray_icon = None

        # Accounts
        self.account_model = AccountModel(self)
        self.enabled_account_model = ActiveAccountModel(self.account_model, self)
        self.server_tools_account_model = ServerToolsAccountModel(self.account_model, self)
        self.identity.setModel(self.enabled_account_model)

        # Contacts
        self.contact_model = ContactModel(self)
        self.contact_search_model = ContactSearchModel(self.contact_model, self)
        self.contact_list.setModel(self.contact_model)
        self.search_list.setModel(self.contact_search_model)

        # Sessions (audio)
        self.session_model = AudioSessionModel(self)
        self.session_list.setModel(self.session_model)
        self.session_list.selectionModel().selectionChanged.connect(self._SH_SessionListSelectionChanged)

        # History
        self.history_manager = HistoryManager()

        # Windows, dialogs and panels
        self.about_panel = AboutPanel(self)
        self.conference_dialog = ConferenceDialog(self)
        self.contact_editor_dialog = ContactEditorDialog(self)
        self.filetransfer_window = FileTransferWindow()
        self.preferences_window = PreferencesWindow(self.account_model, None)
        self.server_tools_window = ServerToolsWindow(self.server_tools_account_model, None)

        # Signals
        self.account_state.stateChanged.connect(self._SH_AccountStateChanged)
        self.account_state.clicked.connect(self._SH_AccountStateClicked)
        self.activity_note.editingFinished.connect(self._SH_ActivityNoteEditingFinished)
        self.add_contact_button.clicked.connect(self._SH_AddContactButtonClicked)
        self.add_search_contact_button.clicked.connect(self._SH_AddContactButtonClicked)
        self.audio_call_button.clicked.connect(self._SH_AudioCallButtonClicked)
        self.video_call_button.clicked.connect(self._SH_VideoCallButtonClicked)
        self.chat_session_button.clicked.connect(self._SH_ChatSessionButtonClicked)
        self.back_to_contacts_button.clicked.connect(self.search_box.clear)  # this can be set in designer -Dan
        self.conference_button.makeConference.connect(self._SH_MakeConference)
        self.conference_button.breakConference.connect(self._SH_BreakConference)

        self.contact_list.selectionModel().selectionChanged.connect(self._SH_ContactListSelectionChanged)
        self.contact_model.itemsAdded.connect(self._SH_ContactModelAddedItems)
        self.contact_model.itemsRemoved.connect(self._SH_ContactModelRemovedItems)

        self.display_name.editingFinished.connect(self._SH_DisplayNameEditingFinished)
        self.hangup_all_button.clicked.connect(self._SH_HangupAllButtonClicked)

        self.identity.activated[int].connect(self._SH_IdentityChanged)
        self.identity.currentIndexChanged[int].connect(self._SH_IdentityCurrentIndexChanged)

        self.mute_button.clicked.connect(self._SH_MuteButtonClicked)

        self.search_box.textChanged.connect(self._SH_SearchBoxTextChanged)
        self.search_box.returnPressed.connect(self._SH_SearchBoxReturnPressed)
        self.search_box.shortcut.activated.connect(self.search_box.setFocus)

        self.search_list.selectionModel().selectionChanged.connect(self._SH_SearchListSelectionChanged)

        self.server_tools_account_model.rowsInserted.connect(self._SH_ServerToolsAccountModelChanged)
        self.server_tools_account_model.rowsRemoved.connect(self._SH_ServerToolsAccountModelChanged)

        self.session_model.sessionAdded.connect(self._SH_AudioSessionModelAddedSession)
        self.session_model.sessionRemoved.connect(self._SH_AudioSessionModelRemovedSession)
        self.session_model.structureChanged.connect(self._SH_AudioSessionModelChangedStructure)

        self.silent_button.clicked.connect(self._SH_SilentButtonClicked)
        self.switch_view_button.viewChanged.connect(self._SH_SwitchViewButtonChangedView)

        # Blink menu actions
        self.about_action.triggered.connect(self.about_panel.show)
        self.add_account_action.triggered.connect(self.preferences_window.show_add_account_dialog)
        self.manage_accounts_action.triggered.connect(self.preferences_window.show_for_accounts)
        self.help_action.triggered.connect(partial(QDesktopServices.openUrl, QUrl('http://icanblink.com/help/')))
        self.preferences_action.triggered.connect(self.preferences_window.show)
        self.auto_accept_chat_action.triggered.connect(self._AH_AutoAcceptChatActionTriggered)
        self.received_messages_sound_action.triggered.connect(self._AH_ReceivedMessagesSoundActionTriggered)
        self.answering_machine_action.triggered.connect(self._AH_EnableAnsweringMachineActionTriggered)
        self.release_notes_action.triggered.connect(partial(QDesktopServices.openUrl, QUrl('http://icanblink.com/changelog/')))
        self.quit_action.triggered.connect(self._AH_QuitActionTriggered)

        # Call menu actions
        self.redial_action.triggered.connect(self._AH_RedialActionTriggered)
        self.join_conference_action.triggered.connect(self.conference_dialog.show)
        self.history_menu.aboutToShow.connect(self._SH_HistoryMenuAboutToShow)
        self.history_menu.triggered.connect(self._AH_HistoryMenuTriggered)
        self.output_devices_group.triggered.connect(self._AH_AudioOutputDeviceChanged)
        self.input_devices_group.triggered.connect(self._AH_AudioInputDeviceChanged)
        self.alert_devices_group.triggered.connect(self._AH_AudioAlertDeviceChanged)
        self.video_devices_group.triggered.connect(self._AH_VideoDeviceChanged)
        self.mute_action.triggered.connect(self._SH_MuteButtonClicked)
        self.silent_action.triggered.connect(self._SH_SilentButtonClicked)

        # Tools menu actions
        self.sip_server_settings_action.triggered.connect(self._AH_SIPServerSettings)
        self.search_for_people_action.triggered.connect(self._AH_SearchForPeople)
        self.history_on_server_action.triggered.connect(self._AH_HistoryOnServer)
        self.google_contacts_action.triggered.connect(self._AH_GoogleContactsActionTriggered)

        # Window menu actions
        self.chat_window_action.triggered.connect(self._AH_ChatWindowActionTriggered)
        self.transfers_window_action.triggered.connect(self._AH_TransfersWindowActionTriggered)
        self.logs_window_action.triggered.connect(self._AH_LogsWindowActionTriggered)
        self.received_files_window_action.triggered.connect(self._AH_ReceivedFilesWindowActionTriggered)
        self.screenshots_window_action.triggered.connect(self._AH_ScreenshotsWindowActionTriggered)
Ejemplo n.º 22
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.saved_account_state = None

        notification_center = NotificationCenter()
        notification_center.add_observer(self, name='SIPApplicationWillStart')
        notification_center.add_observer(self, name='SIPApplicationDidStart')
        notification_center.add_observer(self, name='SIPAccountGotMessageSummary')
        notification_center.add_observer(self, name='SIPAccountGotPendingWatcher')
        notification_center.add_observer(self, name='BlinkSessionNewOutgoing')
        notification_center.add_observer(self, name='BlinkSessionDidReinitializeForOutgoing')
        notification_center.add_observer(self, name='FileTransferNewIncoming')
        notification_center.add_observer(self, name='FileTransferNewOutgoing')
        notification_center.add_observer(self, sender=AccountManager())

        icon_manager = IconManager()

        self.pending_watcher_dialogs = []

        self.mwi_icons = [QIcon(Resources.get('icons/mwi-%d.png' % i)) for i in xrange(0, 11)]
        self.mwi_icons.append(QIcon(Resources.get('icons/mwi-many.png')))

        with Resources.directory:
            self.setupUi()

        self.setWindowTitle('Blink')
        self.setWindowIconText('Blink')

        geometry = QSettings().value("main_window/geometry")
        if geometry:
            self.restoreGeometry(geometry)

        self.default_icon_path = Resources.get('icons/default-avatar.png')
        self.default_icon = QIcon(self.default_icon_path)
        self.last_icon_directory = Path('~').normalized
        self.set_user_icon(icon_manager.get('avatar'))

        self.active_sessions_label.hide()
        self.enable_call_buttons(False)
        self.conference_button.setEnabled(False)
        self.hangup_all_button.setEnabled(False)
        self.sip_server_settings_action.setEnabled(False)
        self.search_for_people_action.setEnabled(False)
        self.history_on_server_action.setEnabled(False)
        self.main_view.setCurrentWidget(self.contacts_panel)
        self.contacts_view.setCurrentWidget(self.contact_list_panel)
        self.search_view.setCurrentWidget(self.search_list_panel)

        # System tray
        if QSystemTrayIcon.isSystemTrayAvailable() and not os.getenv('XDG_CURRENT_DESKTOP', '').lower().startswith('unity'):
            self.system_tray_icon = QSystemTrayIcon(QIcon(Resources.get('icons/blink.png')), self)
            self.system_tray_icon.activated.connect(self._SH_SystemTrayIconActivated)
            menu = QMenu(self)
            menu.addAction(QAction("Show", self, triggered=self._AH_SystemTrayShowWindow))
            menu.addAction(QAction(QIcon(Resources.get('icons/application-exit.png')), "Quit", self, triggered=self._AH_QuitActionTriggered))
            self.system_tray_icon.setContextMenu(menu)
            self.system_tray_icon.show()
        else:
            self.system_tray_icon = None

        # Accounts
        self.account_model = AccountModel(self)
        self.enabled_account_model = ActiveAccountModel(self.account_model, self)
        self.server_tools_account_model = ServerToolsAccountModel(self.account_model, self)
        self.identity.setModel(self.enabled_account_model)

        # Contacts
        self.contact_model = ContactModel(self)
        self.contact_search_model = ContactSearchModel(self.contact_model, self)
        self.contact_list.setModel(self.contact_model)
        self.search_list.setModel(self.contact_search_model)

        # Sessions (audio)
        self.session_model = AudioSessionModel(self)
        self.session_list.setModel(self.session_model)
        self.session_list.selectionModel().selectionChanged.connect(self._SH_SessionListSelectionChanged)

        # History
        self.history_manager = HistoryManager()

        # Windows, dialogs and panels
        self.about_panel = AboutPanel(self)
        self.conference_dialog = ConferenceDialog(self)
        self.contact_editor_dialog = ContactEditorDialog(self)
        self.google_contacts_dialog = GoogleContactsDialog(self)
        self.filetransfer_window = FileTransferWindow()
        self.preferences_window = PreferencesWindow(self.account_model, None)
        self.server_tools_window = ServerToolsWindow(self.server_tools_account_model, None)

        # Signals
        self.account_state.stateChanged.connect(self._SH_AccountStateChanged)
        self.account_state.clicked.connect(self._SH_AccountStateClicked)
        self.activity_note.editingFinished.connect(self._SH_ActivityNoteEditingFinished)
        self.add_contact_button.clicked.connect(self._SH_AddContactButtonClicked)
        self.add_search_contact_button.clicked.connect(self._SH_AddContactButtonClicked)
        self.audio_call_button.clicked.connect(self._SH_AudioCallButtonClicked)
        self.video_call_button.clicked.connect(self._SH_VideoCallButtonClicked)
        self.chat_session_button.clicked.connect(self._SH_ChatSessionButtonClicked)
        self.back_to_contacts_button.clicked.connect(self.search_box.clear) # this can be set in designer -Dan
        self.conference_button.makeConference.connect(self._SH_MakeConference)
        self.conference_button.breakConference.connect(self._SH_BreakConference)

        self.contact_list.selectionModel().selectionChanged.connect(self._SH_ContactListSelectionChanged)
        self.contact_model.itemsAdded.connect(self._SH_ContactModelAddedItems)
        self.contact_model.itemsRemoved.connect(self._SH_ContactModelRemovedItems)

        self.display_name.editingFinished.connect(self._SH_DisplayNameEditingFinished)
        self.hangup_all_button.clicked.connect(self._SH_HangupAllButtonClicked)

        self.identity.activated[int].connect(self._SH_IdentityChanged)
        self.identity.currentIndexChanged[int].connect(self._SH_IdentityCurrentIndexChanged)

        self.mute_button.clicked.connect(self._SH_MuteButtonClicked)

        self.search_box.textChanged.connect(self._SH_SearchBoxTextChanged)
        self.search_box.returnPressed.connect(self._SH_SearchBoxReturnPressed)
        self.search_box.shortcut.activated.connect(self.search_box.setFocus)

        self.search_list.selectionModel().selectionChanged.connect(self._SH_SearchListSelectionChanged)

        self.server_tools_account_model.rowsInserted.connect(self._SH_ServerToolsAccountModelChanged)
        self.server_tools_account_model.rowsRemoved.connect(self._SH_ServerToolsAccountModelChanged)

        self.session_model.sessionAdded.connect(self._SH_AudioSessionModelAddedSession)
        self.session_model.sessionRemoved.connect(self._SH_AudioSessionModelRemovedSession)
        self.session_model.structureChanged.connect(self._SH_AudioSessionModelChangedStructure)

        self.silent_button.clicked.connect(self._SH_SilentButtonClicked)
        self.switch_view_button.viewChanged.connect(self._SH_SwitchViewButtonChangedView)

        # Blink menu actions
        self.about_action.triggered.connect(self.about_panel.show)
        self.add_account_action.triggered.connect(self.preferences_window.show_add_account_dialog)
        self.manage_accounts_action.triggered.connect(self.preferences_window.show_for_accounts)
        self.help_action.triggered.connect(partial(QDesktopServices.openUrl, QUrl(u'http://icanblink.com/help-qt.phtml')))
        self.preferences_action.triggered.connect(self.preferences_window.show)
        self.auto_accept_chat_action.triggered.connect(self._AH_AutoAcceptChatActionTriggered)
        self.received_messages_sound_action.triggered.connect(self._AH_ReceivedMessagesSoundActionTriggered)
        self.answering_machine_action.triggered.connect(self._AH_EnableAnsweringMachineActionTriggered)
        self.release_notes_action.triggered.connect(partial(QDesktopServices.openUrl, QUrl(u'http://icanblink.com/changelog-qt.phtml')))
        self.quit_action.triggered.connect(self._AH_QuitActionTriggered)

        # Call menu actions
        self.redial_action.triggered.connect(self._AH_RedialActionTriggered)
        self.join_conference_action.triggered.connect(self.conference_dialog.show)
        self.history_menu.aboutToShow.connect(self._SH_HistoryMenuAboutToShow)
        self.history_menu.triggered.connect(self._AH_HistoryMenuTriggered)
        self.output_devices_group.triggered.connect(self._AH_AudioOutputDeviceChanged)
        self.input_devices_group.triggered.connect(self._AH_AudioInputDeviceChanged)
        self.alert_devices_group.triggered.connect(self._AH_AudioAlertDeviceChanged)
        self.video_devices_group.triggered.connect(self._AH_VideoDeviceChanged)
        self.mute_action.triggered.connect(self._SH_MuteButtonClicked)
        self.silent_action.triggered.connect(self._SH_SilentButtonClicked)

        # Tools menu actions
        self.sip_server_settings_action.triggered.connect(self._AH_SIPServerSettings)
        self.search_for_people_action.triggered.connect(self._AH_SearchForPeople)
        self.history_on_server_action.triggered.connect(self._AH_HistoryOnServer)

        # Window menu actions
        self.chat_window_action.triggered.connect(self._AH_ChatWindowActionTriggered)
        self.transfers_window_action.triggered.connect(self._AH_TransfersWindowActionTriggered)
        self.logs_window_action.triggered.connect(self._AH_LogsWindowActionTriggered)
        self.received_files_window_action.triggered.connect(self._AH_ReceivedFilesWindowActionTriggered)
        self.screenshots_window_action.triggered.connect(self._AH_ScreenshotsWindowActionTriggered)
Ejemplo n.º 23
0
 def update_from_contact(self, contact):
     icon_manager = IconManager()
     if self.icon is self.contact_icon:
         self.icon = self.contact_icon = icon_manager.get(contact.id)
     else:
         self.contact_icon = icon_manager.get(contact.id)
Ejemplo n.º 24
0
 def _NH_CFGSettingsObjectDidChange(self, notification):
     if 'presence.icon' in notification.data.modified:
         self.account_button.setIcon(IconManager().get('avatar') or self.account_button.default_avatar)