def _SH_AudioCallButtonClicked(self): list_view = self.contact_list if self.contacts_view.currentWidget() is self.contact_list_panel else self.search_list selected_indexes = list_view.selectionModel().selectedIndexes() contact = list_view.model().data(selected_indexes[0]) if selected_indexes else Null address = contact.uri or unicode(self.search_box.text()) name = contact.name or None session_manager = SessionManager() session_manager.start_call(name, address, contact=contact, account=BonjourAccount() if isinstance(contact, BonjourNeighbour) else None)
def _AH_HistoryMenuTriggered(self, action): account_manager = AccountManager() session_manager = SessionManager() try: account = account_manager.get_account(action.entry.account_id) except KeyError: account = None contact, contact_uri = URIUtils.find_contact(action.entry.uri) session_manager.create_session(contact, contact_uri, [StreamDescription('audio')], account=account) # TODO: memorize media type and use it? -Saul (not sure about history in/out -Dan)
def acceptNavigationRequest(self, frame, request, navigation_type): if navigation_type == QWebPage.NavigationTypeLinkClicked and self.linkDelegationPolicy() == QWebPage.DontDelegateLinks and request.url().scheme() in ('sip', 'sips'): blink = QApplication.instance() contact, contact_uri = URIUtils.find_contact(request.url().toString()) session_manager = SessionManager() session_manager.create_session(contact, contact_uri, [StreamDescription('audio')]) blink.main_window.raise_() blink.main_window.activateWindow() return False return super(WebPage, self).acceptNavigationRequest(frame, request, navigation_type)
def _SH_ChatSessionButtonClicked(self): list_view = self.contact_list if self.contacts_view.currentWidget() is self.contact_list_panel else self.search_list if list_view.detail_view.isVisible(): list_view.detail_view._AH_StartChatSession() else: selected_indexes = list_view.selectionModel().selectedIndexes() if selected_indexes: contact = selected_indexes[0].data(Qt.UserRole) contact_uri = contact.uri else: contact, contact_uri = URIUtils.find_contact(self.search_box.text()) session_manager = SessionManager() session_manager.create_session(contact, contact_uri, [StreamDescription('chat')], connect=False)
def _AH_ShareMyScreenActionTriggered(self): list_view = self.contact_list if self.contacts_view.currentWidget() is self.contact_list_panel else self.search_list if list_view.detail_view.isVisible(): list_view.detail_view._AH_ShareMyScreen() else: selected_indexes = list_view.selectionModel().selectedIndexes() if selected_indexes: contact = selected_indexes[0].data(Qt.UserRole) contact_uri = contact.uri else: contact, contact_uri = URIUtils.find_contact(self.search_box.text()) session_manager = SessionManager() session_manager.create_session(contact, contact_uri, [StreamDescription('screen-sharing', mode='server'), StreamDescription('audio')])
def _SH_ShareDocumentButtonClicked(self): list_view = self.contact_list if self.contacts_view.currentWidget() is self.contact_list_panel else self.search_list selected_indexes = list_view.selectionModel().selectedIndexes() if selected_indexes: contact = selected_indexes[0].data(Qt.UserRole) contact_uri = contact.uri else: contact, contact_uri = URIUtils.find_contact(self.search_box.text()) filename = QFileDialog.getOpenFileName(self, "Share a Document", "", "OpenDocument Files (*.odt)") if filename: session_manager = SessionManager() session_manager.create_session(contact, contact_uri, [StreamDescription('document-sharing', filename=filename)])
def create_message_session(self, uri): from blink.contacts import URIUtils contact, contact_uri = URIUtils.find_contact(uri) session_manager = SessionManager() account = AccountManager().default_account try: next(session for session in self.sessions if session.reusable and session.contact.settings is contact.settings) except StopIteration: session_manager.create_session(contact, contact_uri, [StreamDescription('messages')], account=account, connect=False)
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)
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)
def _NH_SIPEngineGotMessage(self, notification): account_manager = AccountManager() account = account_manager.find_account(notification.data.request_uri) if account is None: return data = notification.data content_type = data.headers.get('Content-Type', Null).content_type from_header = data.headers.get('From', Null) x_replicated_message = data.headers.get('X-Replicated-Message', Null) to_header = data.headers.get('To', Null) if x_replicated_message is Null: cpim_message = None if content_type == "message/cpim": try: cpim_message = CPIMPayload.decode(data.body) except CPIMParserError: log.warning( 'SIP message from %s to %s rejected: CPIM parse error' % (from_header.uri, '%s@%s' % (to_header.uri.user, to_header.uri.host))) return body = cpim_message.content if isinstance( cpim_message.content, str) else cpim_message.content.decode() content_type = cpim_message.content_type sender = cpim_message.sender or from_header disposition = next( ([item.strip() for item in header.value.split(',')] for header in cpim_message.additional_headers if header.name == 'Disposition-Notification'), None) message_id = next( (header.value for header in cpim_message.additional_headers if header.name == 'Message-ID'), str(uuid.uuid4())) else: payload = SimplePayload.decode(data.body, data.content_type) body = payload.content.decode() content_type = payload.content_type sender = from_header disposition = None message_id = str(uuid.uuid4()) if (content_type.lower().startswith('text/') and '-----BEGIN PGP MESSAGE-----' in body and body.strip().endswith('-----END PGP MESSAGE-----') and content_type != 'text/pgp-private-key'): return if content_type.lower() == 'text/pgp-public-key': return from blink.contacts import URIUtils contact, contact_uri = URIUtils.find_contact(sender.uri) session_manager = SessionManager() notification_center = NotificationCenter() try: blink_session = next( session for session in self.sessions if session.reusable and session.contact.settings is contact.settings) except StopIteration: if content_type.lower() in [ IsComposingDocument.content_type, IMDNDocument.content_type ]: return else: blink_session = session_manager.create_session( contact, contact_uri, [StreamDescription('messages')], account=account, connect=False) if content_type.lower() == IsComposingDocument.content_type: try: document = IsComposingMessage.parse(body) except ParserError as e: log.warning('Failed to parse Is-Composing payload: %s' % str(e)) else: data = NotificationData( state=document.state.value, refresh=document.refresh.value if document.refresh is not None else 120, content_type=document.content_type.value if document.content_type is not None else None, last_active=document.last_active.value if document.last_active is not None else None, sender=sender) notification_center.post_notification( 'BlinkGotComposingIndication', sender=blink_session, data=data) return timestamp = str( cpim_message.timestamp ) if cpim_message is not None and cpim_message.timestamp is not None else str( ISOTimestamp.now()) if account.sms.use_cpim and account.sms.enable_imdn and content_type.lower( ) == IMDNDocument.content_type: # print("-- IMDN received") document = IMDNDocument.parse(body) imdn_message_id = document.message_id.value imdn_status = document.notification.status.__str__() imdn_datetime = document.datetime.__str__() notification_center.post_notification( 'BlinkGotDispositionNotification', sender=blink_session, data=NotificationData(id=imdn_message_id, status=imdn_status)) return message = BlinkMessage(body, content_type, sender, timestamp=timestamp, id=message_id, disposition=disposition) notification_center.post_notification('BlinkMessageIsParsed', sender=blink_session, data=message) if disposition is not None and 'positive-delivery' in disposition: # print("-- Should send delivered imdn") self.send_imdn_message(blink_session, message_id, timestamp, 'delivered') self._add_contact_to_messages_group(blink_session) notification_center.post_notification('BlinkGotMessage', sender=blink_session, data=message) else: # TODO handle replicated messages pass
def _SH_SearchBoxReturnPressed(self): address = self.search_box.text() if address: contact, contact_uri = URIUtils.find_contact(address) session_manager = SessionManager() session_manager.create_session(contact, contact_uri, [StreamDescription('audio')])
def _AH_RedialActionTriggered(self): session_manager = SessionManager() if session_manager.last_dialed_uri is not None: session_manager.start_call(None, unicode(session_manager.last_dialed_uri))
def _SH_ContactDoubleClicked(self, index): contact = index.model().data(index) if not isinstance(contact, Contact): return session_manager = SessionManager() session_manager.start_call(contact.name, contact.uri, contact=contact, account=BonjourAccount() if isinstance(contact, BonjourNeighbour) else None)
def _SH_SearchBoxReturnPressed(self): address = unicode(self.search_box.text()) if address: session_manager = SessionManager() session_manager.start_call(None, address)
def _AH_VoicemailActionTriggered(self, action, checked): account = action.data() contact, contact_uri = URIUtils.find_contact(account.voicemail_uri, display_name='Voicemail') session_manager = SessionManager() session_manager.create_session(contact, contact_uri, [StreamDescription('audio')], account=account)
def _AH_RedialActionTriggered(self): session_manager = SessionManager() if session_manager.last_dialed_uri is not None: contact, contact_uri = URIUtils.find_contact(session_manager.last_dialed_uri) session_manager.create_session(contact, contact_uri, [StreamDescription('audio')]) # TODO: remember used media types and redial with them. -Saul
def _AH_VoicemailActionTriggered(self, checked): account = self.sender().data() contact, contact_uri = URIUtils.find_contact(account.voicemail_uri, display_name='Voicemail') session_manager = SessionManager() session_manager.create_session(contact, contact_uri, [StreamDescription('audio')], account=account)