Esempio n. 1
0
    def __on_auth_ok(self, username, password):
        self.__username = username
        self.__password = password
        keyring.get_keyring().store_login('google', self.__username, self.__password)

        for ui in self.__auth_uis:
            ui.hide()

        if self.__auth_dialog:
            self.__auth_dialog.hide()

        hooks = self.__post_auth_hooks
        self.__post_auth_hooks = []
        for h in hooks:
            h()

        self.__consider_checking_mail()
Esempio n. 2
0
    def __init__(self):
        self.__logger = logging.getLogger("bigboard.Google")
        self.__username = None
        self.__password = None
        self.__fetcher = AsyncHTTPLib2Fetcher()
        self.__auth_dialog = None
        self.__auth_uis = []
        self.__post_auth_hooks = []

        k = keyring.get_keyring()

        try:
            username, password = k.get_login("google")
            self.__username = username
            self.__password = password            
        except TypeError:
            self.__username = None
            self.__password = None

        self.__mail_checker = None
        self.__consider_checking_mail()
Esempio n. 3
0
    def save_account_changes(self, account, new_properties):

        _logger.debug("Saving new props for account %s: %s" % (str(account), str(new_properties.keys())))
        set_password = False

        ## special-case handling of password since it goes in the keyring
        if 'password' in new_properties:
            if 'username' in new_properties:
                username = new_properties['username']
            else:
                username = account.get_username()

            if 'url' in new_properties:
                url = new_properties['url']
            else:
                url = account.get_url()

            k = keyring.get_keyring()
            
            k.store_login(kind=account.get_kind().get_id(),
                          username=username,
                          url=url,
                          password=new_properties['password'])

            set_password = True

        ## now do everything else by stuffing it in gconf
            
        gconf_dir = account._get_gconf_dir()
        if not gconf_dir:
            gconf_dir = self.__find_unused_gconf_dir(account.get_kind())

            ## associate the Account with this new gconf dir.
            ## basically this means if a weblogindriver account
            ## is modified, it becomes a gconf account also.
            ## We would also do this on seeing a new gconf
            ## dir appear in gconf spontaneously, but doing
            ## it here ensures that we definitely attach
            ## to the proper previous Account
            account._set_gconf_dir(gconf_dir)
            self.__gconf_accounts.add(account)
            
        base_key = '/apps/bigboard/accounts/' + gconf_dir
        
        def set_account_prop(gconf, base_key, prop, value):
            _logger.debug("prop %s value %s" % (prop, str(value)))
            if isinstance(value, AccountKind):
                value = value.get_id()
            gconf.set_value(base_key + '/' + prop, value)

        set_account_prop(self.__gconf, base_key, 'kind', account.get_kind())

        if 'username' in new_properties:
            set_account_prop(self.__gconf, base_key, 'username', new_properties['username'])
        if 'url' in new_properties:
            set_account_prop(self.__gconf, base_key, 'url', new_properties['url'])

        ## enable it last, so we ignore the other settings until we do this
        if 'enabled' in new_properties:
            set_account_prop(self.__gconf, base_key, 'enabled', new_properties['enabled'])

        ## keyring doesn't have change notification so we have to do the work for it
        if set_password:
            ## this should notice a new password
            self.__update_account(account)
Esempio n. 4
0
    import gtk, gtk.gdk

    import bigboard.libbig
    try:
        import bigboard.bignative as bignative
    except:
        import bignative

    gtk.gdk.threads_init()

    libbig.logutil.init('DEBUG', ['AsyncHTTP2LibFetcher'])

    bignative.set_application_name("BigBoard")

    keyring.get_keyring().store_login('google', 'havoc.pennington', 'wrong')

    #AuthDialog().present('foo', 'bar')
    #gtk.main()
    sys.exit(0)

    g = get_google()

    def display(x):
        print x
    
    #g.fetch_documents(display, display)
    g.fetch_calendar(display, display)
    #g.fetch_new_mail(display, display)

    gtk.main()
Esempio n. 5
0
    def __update_account(self, account):

        _logger.debug("Updating account %s" % (str(account)))

        ## note that "kind" is never updated (not allowed to change without
        ## making a new Account object)

        was_enabled = account in self.__enabled_accounts
        if was_enabled != account.get_enabled():
            raise Exception("account enabled state messed up")

        fields = { }

        ## first, look for the info from our local gconf storage
        gconf_base = '/apps/bigboard/accounts'
        gconf_dir = account._get_gconf_dir()
        if gconf_dir and gconf_dir in self.__gconf_info:
            gconf_info = self.__gconf_info[gconf_dir]

            if 'username' in gconf_info:
                fields['username'] = gconf_info['username']

            if 'enabled' in gconf_info:
                fields['enabled'] = gconf_info['enabled']

            if 'url' in gconf_info:
                fields['url'] = gconf_info['url']
        elif gconf_dir and gconf_dir not in self.__gconf_info:
            ## Account object originating with a gconf item
            ## apparently now deleted, so disable. This
            ## does mean if you create a gconf item corresponding
            ## to something from weblogin driver, then delete the
            ## gconf item, the weblogin account doesn't come back
            ## until you restart the process. Clunky.
            ## deleting a gconf dir isn't what we'd normally do though,
            ## we'd normally set enabled=False in gconf, which would
            ## persist across restarts.
            fields['enabled'] = False

            self.__gconf_accounts.remove(account)

        ## second, look at weblogin driver, though we don't want to prefer
        ## its password over keyring, so there's some trickiness
        weblogin_password = None
        if account.get_kind() in self.__weblogin_info:
            (username, weblogin_password) = self.__weblogin_info[account.get_kind()]
            if 'username' not in fields:
                fields['username'] = username

            ## if account was not disabled explicitly by gconf, we enable it
            if 'enabled' not in fields:
                fields['enabled'] = True
        else:
            if account in self.__weblogin_accounts:
                self.__weblogin_accounts.remove(account)

        ## after compositing all this information, update our account object
        account._update_from_origin(fields)

        ## use updated information to find password
        fields = {}
        
        ## third, look for password in keyring
        k = keyring.get_keyring()                
        password = k.get_password(kind=account.get_kind().get_id(),
                                  username=account.get_username(),
                                  url=account.get_url())
        if password and 'password' not in fields:
            _logger.debug("using password from keyring")
            fields['password'] = password
            
        ## fourth, if no password in keyring, use the weblogin one
        if weblogin_password and 'password' not in fields:
            _logger.debug("using password from weblogin")
            fields['password'] = weblogin_password

        ## if no password found, the password has to be set to empty
        if 'password' not in fields:
            fields['password'] = ''

        ## update account object again if we might have the password
        if 'password' in fields:
            account._update_from_origin(fields)

        ## now add or remove the account from the set of enabled accounts
        if was_enabled and not account.get_enabled():
            self.__enabled_accounts.remove(account)
            self.emit('account-removed', account)
        elif not was_enabled and account.get_enabled():
            self.__enabled_accounts.add(account)
            self.emit('account-added', account)