コード例 #1
0
ファイル: config.py プロジェクト: jldupont/dbus_lastfm
        Bus.publish(self, "user_params", params)

    
    def _resetChanged(self):
        self.username_changed=False
        self.api_key_changed=False
        self.secret_key_changed=False
        self.params_changed=False
    
    def _applyState(self, state):
        self.bapply.props.sensitive=state
    


cfg=Config()
Bus.subscribe("user_params", cfg.h_user_params)



class App:

    ICON_PATH="/usr/share/icons"
    ICON_FILE="dlastfm.png"
    
    def __init__(self, curdir):
        self.curdir=curdir
        
        self._statusIcon=gtk.StatusIcon()
        self._statusIcon.set_from_stock(gtk.STOCK_ABOUT)
        self._statusIcon.set_visible(True)
        self._statusIcon.set_tooltip("DBus Last.fm")
コード例 #2
0
ファイル: auth_agent.py プロジェクト: jldupont/dbus_lastfm
        
        If a valid 'url' is received, open a browser tab
        for the user to 'authorize' the application
        """
        _status, url=response
        webbrowser.open_new_tab(url)
        
    def h_apieb(self, response):
        """
        API response errback
        """
        _,code, msg=response
        tcode=self._msgTable.get(code, "unknown")
        Bus.publish(self, "error", tcode)
        Bus.publish(self, "log", "Authorization error, code(%s) msg(%s)" % (code, msg))
    

class AuthorizeAgent(object):
    
    def h_authorize(self, _):
        """
        Bus message handler
        """
        ahandler=AuthResponseAgent()
        Bus.publish(self, "method_call", {"method":"auth.getToken"}, 
                    {"c":ahandler.h_apicb, "e":ahandler.h_apieb})

    
aagent=AuthorizeAgent()
Bus.subscribe("authorize", aagent.h_authorize)
コード例 #3
0
ファイル: account.py プロジェクト: jldupont/dbus_lastfm
    @dbus.service.method('fm.last.api.account', in_signature="s")
    def setSecretKey(self, secret_key):
        self.gatePublish("user_params", {"secret_key":secret_key})

    ## ================================================================== Authentication

    @dbus.service.method('fm.last.api.account', 
                         out_signature="v", 
                         async_callbacks=("_callback", "_errback"))
    def getAuthUrl(self, _callback, _errback):
        """
        Returns an URL pointing to an authorization page
        
        An "authorization token" must first be retrieved from Last.fm
        and thus the current session (if any) will be lost.
        """
        self.gatePublish("method_call", {"method":"auth.getToken"}, 
                    {"c":_callback, "e":_errback})

    @dbus.service.method('fm.last.api.account') 
    def clearSession(self):
        """
        Clears all session related user parameters
        """
        self.gatePublish("user_params", {"auth_token":"", "token":""})


    
api=DbusApiAccount()
Bus.subscribe("user_params", api._snif_user_params)
コード例 #4
0
ファイル: user_msg.py プロジェクト: jldupont/dbus_lastfm
    """
    _msgs={"api_access_error":"Error whilst accessing Last.FM web api. <br/>Is the service authentified?"
           ,"conn_error":"Connection error. <br/>Is Internet access functional?"
           ,"auth_error":"Authorization error. <br/>Are the 'api_key' and 'secret_key' valid?"
           ,"api_error":"Web API error. <br/>Has Last.fm's Web API changed?"
           ,"unknown":"Unknown error!"
           }
    
    def h_error(self, _, errorType, *pa, **kwa):
        errmsg=self._msgs.get(errorType, None)
        if not errmsg:
            errmsg=self._msgs.get("unknown")
        self._doNotify("DBus Last.fm - Error", errmsg)
        
    def _doNotify(self, summary, msg):
        pynotify.init("DBus Last.fm")
        n=pynotify.Notification(summary, msg)
        n.show()
    

usermsg=UserMessenger()
Bus.subscribe("error", usermsg.h_error)




if __name__=="__main__":
    u=UserMessenger()
    u.h_error("", "api_access_error")
    #u.h_error("", "conn_error")
    #u.h_error("", "foo")