Ejemplo n.º 1
0
 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})
Ejemplo n.º 2
0
 def on_cenable_toggled(self, wcenable):
     """
     DBus API enable checkbox
     """
     state=wcenable.props.active
     Bus.publish(self, "user_params", {"dbus_enable": str(state)})
     return True
Ejemplo n.º 3
0
 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))
Ejemplo n.º 4
0
 def _publishParams(self, params={}):
     """
     Publish any change
     """
     for param in self._paramsList:
         wgt=self.builder.get_object("e%s"%param)
         value=wgt.get_text()
         params[param]=value
     Bus.publish(self, "user_params", params)
Ejemplo n.º 5
0
 def on_bauth_clicked(self, wbauth):
     Bus.publish(self, "authorize")
     return True
Ejemplo n.º 6
0
 def show(self):
     Bus.publish(self, "user_params?")
     self.bapply.props.sensitive=False 
     self.window.present()
Ejemplo n.º 7
0
        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")
Ejemplo n.º 8
0
 def gatePublish(self, *pa):
     if self._enable:
         Bus.publish(self, *pa)        
Ejemplo n.º 9
0
 def __init__(self):
     bus_name = dbus.service.BusName('fm.lastfm.api', bus=dbus.SessionBus())
     dbus.service.Object.__init__(self, bus_name, '/account')
     self._cache={}
     self._enable=False
     Bus.publish(self, "user_params?")
Ejemplo n.º 10
0
    @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)
Ejemplo n.º 11
0
        
        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)
Ejemplo n.º 12
0
    """
    _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")