Ejemplo n.º 1
0
    def _onAccContextMenu(self, label):
        acc = self._getSelectedAccount()
        if not acc:
            return

        if label == 'Unregister':
            acc.setRegistration(False)
        elif label == 'Reregister':
            acc.setRegistration(True)
        elif label == 'Online':
            ps = pj.PresenceStatus()
            ps.status = pj.PJSUA_BUDDY_STATUS_ONLINE
            acc.setOnlineStatus(ps)
        elif label == 'Invisible':
            ps = pj.PresenceStatus()
            ps.status = pj.PJSUA_BUDDY_STATUS_OFFLINE
            acc.setOnlineStatus(ps)
        elif label == 'Away':
            ps = pj.PresenceStatus()
            ps.status = pj.PJSUA_BUDDY_STATUS_ONLINE
            ps.activity = pj.PJRPID_ACTIVITY_AWAY
            ps.note = "Away"
            acc.setOnlineStatus(ps)
        elif label == 'Busy':
            ps = pj.PresenceStatus()
            ps.status = pj.PJSUA_BUDDY_STATUS_ONLINE
            ps.activity = pj.PJRPID_ACTIVITY_BUSY
            ps.note = "Busy"
            acc.setOnlineStatus(ps)
        elif label == 'Settings...':
            self.cfgChanged = False
            dlg = accountsetting.Dialog(self.master, acc.cfg)
            if dlg.doModal():
                self.updateAccount(acc)
                acc.modify(acc.cfg)
        elif label == 'Delete...':
            msg = "Do you really want to delete account '%s'?" % acc.cfg.idUri
            if msgbox.askquestion('Delete account?', msg,
                                  default=msgbox.NO) != u'yes':
                return
            iid = str(acc.randId)
            self.accList.remove(acc)
            acc.setRegistration(False)
            acc.deleting = True
            del acc
            self.tv.delete((iid, ))
        elif label == 'Add buddy...':
            cfg = pj.BuddyConfig()
            dlg = buddy.SettingDialog(self.master, cfg)
            if dlg.doModal():
                self._createBuddy(acc, cfg)
        else:
            assert not ("Unknown menu " + label)
Ejemplo n.º 2
0
    def _login(self):
        # Initialize configuration of account
        acc_cfg = pj.AccountConfig()
        # Create LoginDialog
        dlg = Login(self, acc_cfg)
        # Wait for response
        if dlg.do_modal():
            # Initialize account
            self.acc = Account(self)
            # Set configuration
            self.acc.cfg = acc_cfg
            self.acc.create(self.acc.cfg)
            # Set online status
            ps = pj.PresenceStatus()
            ps.status = pj.PJSUA_BUDDY_STATUS_ONLINE
            self.acc.setOnlineStatus(ps)

            # Update title
            self.title(self.acc.cfg.idUri)
            # Get the uri of server
            self.domain = self.acc.cfg.regConfig.registrarUri.split(':')[1]
            # Reset all
            self.buddy_list = {}
            self.chat_list = {}
            for key in self.buddy_view.get_children():
                self.buddy_view.delete(key)
        # If never login
        if not self.acc:
            # Then exit
            self._exit()
Ejemplo n.º 3
0
 def startup(self):
     self._logger.debug("entered startup()")
     ep_cfg = pjsua2.EpConfig()
     ep_cfg.uaConfig.mainThreadOnly = True
     ep_cfg.uaConfig.threadCnt = 0
     version = pkg_resources.require("gtkapplication")[0].version
     ep_cfg.uaConfig.userAgent = "pyphone-{0}".format(version)
     self._logger.debug('ep_cfg.uaConfig.userAgent = %s',
                        ep_cfg.uaConfig.userAgent)
     ep_cfg.logConfig.msgLogging = 1
     ep_cfg.logConfig.level = 5
     ep_cfg.logConfig.consoleLevel = 5
     decor = pjsua2.PJ_LOG_HAS_YEAR | pjsua2.PJ_LOG_HAS_MONTH | pjsua2.PJ_LOG_HAS_DAY_OF_MON | pjsua2.PJ_LOG_HAS_TIME | pjsua2.PJ_LOG_HAS_MICRO_SEC | pjsua2.PJ_LOG_HAS_SENDER | pjsua2.PJ_LOG_HAS_NEWLINE | pjsua2.PJ_LOG_HAS_SPACE | pjsua2.PJ_LOG_HAS_THREAD_SWC | pjsua2.PJ_LOG_HAS_INDENT
     self._logger.debug('decor = %s', decor)
     ep_cfg.logConfig.decor = decor
     ep_cfg.logConfig.filename = "logs/pjsip.log"
     ep_cfg.logConfig.fileFlags = pjsua2.PJ_O_APPEND
     pjsip_log_writer = gtkapplication.api.sip.logger.PjLogger()
     ep_cfg.logConfig.writer = pjsip_log_writer
     sip_container = gtkapplication.api.sip.pjsip_container.sip_container
     sip_container.pjsip_log_writer = pjsip_log_writer
     sip_container.ep = pjsua2.Endpoint()
     ep = sip_container.ep
     ep.libCreate()
     ep.libInit(ep_cfg)
     pjsip_version = ep.libVersion().full
     self._logger.debug('pjsip_version = %s', pjsip_version)
     sip_udp_tranport_config = pjsua2.TransportConfig()
     sip_udp_tranport_config.port = 5060
     sip_udp_tranport_config.enabled = 1
     ep.transportCreate(pjsua2.PJSIP_TRANSPORT_UDP, sip_udp_tranport_config)
     self._logger.debug("transport created")
     acfg = pjsua2.AccountConfig()
     acfg.idUri = gtkapplication.data.config_data.PROFILE_DATA['sip_uri']
     acfg.regConfig.registrarUri = gtkapplication.data.config_data.PROFILE_DATA[
         'sip_registrar_uri']
     acfg.regConfig.registerOnAdd = True
     acfg.regConfig.timeoutSec = 60
     acfg.regConfig.retryIntervalSec = 60
     aci = pjsua2.AuthCredInfo()
     aci.scheme = "digest"
     aci.realm = "*"
     aci.username = gtkapplication.data.config_data.PROFILE_DATA[
         'sip_username']
     aci.dataType = 0
     aci.data = gtkapplication.data.config_data.PROFILE_DATA['sip_password']
     aciv = pjsua2.AuthCredInfoVector()
     aciv.append(aci)
     acfg.sipConfig.authCreds = aciv
     sip_container.sip_account_list.append(
         gtkapplication.api.sip.account.Account(acfg))
     sip_account = sip_container.sip_account_list[0]
     sip_account.cfg = acfg
     sip_account.create(acfg, True)
     presence_status = pjsua2.PresenceStatus()
     presence_status.status = pjsua2.PJSUA_BUDDY_STATUS_ONLINE
     sip_account.setOnlineStatus(presence_status)
     self._logger.debug("sip account created: %r", sip_account)
     bcfg = pjsua2.BuddyConfig()
     bcfg.uri = gtkapplication.data.config_data.PROFILE_DATA[
         'sip_buddy_uri']
     bcfg.subscribe = True
     buddy = gtkapplication.api.sip.buddy.Buddy(sip_account)
     buddy.create(sip_account, bcfg)
     sip_account.server_buddy = buddy
     contact_manager = gtkapplication.api.contacts.contact_manager.ContactManager(
     )
     contact_manager.create_free_buddy_contacts(sip_account)
     acfg = pjsua2.AccountConfig()
     acfg.idUri = gtkapplication.data.config_data.PROFILE_DATA[
         'twilio_sip_uri']
     acfg.regConfig.registrarUri = gtkapplication.data.config_data.PROFILE_DATA[
         'twilio_sip_registrar_uri']
     self._logger.debug("twilio sip_uri = '%s', registrar = %s", acfg.idUri,
                        acfg.regConfig.registrarUri)
     acfg.regConfig.registerOnAdd = True
     acfg.regConfig.timeoutSec = 60
     acfg.regConfig.retryIntervalSec = 60
     aci = pjsua2.AuthCredInfo()
     aci.scheme = "digest"
     aci.realm = "*"
     aci.username = gtkapplication.data.config_data.PROFILE_DATA[
         'twilio_sip_username']
     aci.dataType = 0
     aci.data = gtkapplication.data.config_data.PROFILE_DATA[
         'twilio_sip_password']
     aciv = pjsua2.AuthCredInfoVector()
     aciv.append(aci)
     acfg.sipConfig.authCreds = aciv
     sip_container.sip_account_list.append(
         gtkapplication.api.sip.account.Account(acfg))
     twilio_sip_account = sip_container.sip_account_list[1]
     twilio_sip_account.cfg = acfg
     twilio_sip_account.create(acfg, True)
     presence_status = pjsua2.PresenceStatus()
     presence_status.status = pjsua2.PJSUA_BUDDY_STATUS_ONLINE
     twilio_sip_account.setOnlineStatus(presence_status)
     ep.libStart()
     self._logger.debug("after libStart()")
     tone_generator = pjsua2.ToneGenerator()
     tone_generator.createToneGenerator(16000, 1)
     sip_container.tone_generator = tone_generator
     self._logger.debug("tone generator created")
     self._source_tag = GObject.timeout_add(50,
                                            self.poll_pjsip_events_timer,
                                            False)
     self._logger.debug("timer started source_tag is %s", self._source_tag)
     self._logger.info("timer started")