Beispiel #1
0
 def __request_authorization(cls):
     from blaplay.blagui import blaguiutils
     response = blaguiutils.question_dialog(
         "last.fm authorization required", "In order to submit tracks to "
         "the last.fm scrobbler, blaplay needs to be authorized to use "
         "your account. Open the last.fm authorization page now?")
     if response == gtk.RESPONSE_YES:
         blautil.open_url(
             "http://www.last.fm/api/auth/?api_key=%s&token=%s" % (
             blaconst.LASTFM_APIKEY, cls.__token))
     return False
Beispiel #2
0
def create_popup_menu(track=None):
    user = blacfg.getstring("lastfm", "user")
    if not user:
        return None

    menu = gtk.Menu()

    # User profile
    m = gtk.MenuItem("View your profile")
    m.connect("activate",
              lambda *x: blautil.open_url("http://last.fm/user/%s" % user))
    menu.append(m)

    # Love/Unlove song
    artist = title = track_label = None
    if track is None:
        track = player.get_track()
    try:
        artist = track[ARTIST].replace(" ", "+")
        title =  track[TITLE].replace(" ", "+")
    except TypeError:
        return menu

    limit = 40
    track_label = "%s - %s" % (track[ARTIST], track[TITLE])
    if len(track_label) > limit:
        track_label = "%s..." % track_label[:limit]

    m = gtk.MenuItem("Love song \"%s\"" % track_label)
    m.connect("activate", lambda *x: love_unlove_song(track, unlove=False))
    menu.append(m)

    m = gtk.MenuItem("Unlove song \"%s\"" % track_label)
    m.connect("activate", lambda *x: love_unlove_song(track, unlove=True))
    menu.append(m)

    m = gtk.MenuItem("View song profile of \"%s\"" % track_label)
    m.connect(
        "activate",
        lambda *x: blautil.open_url("http://last.fm/music/%s/_/%s" %
                                    (artist, title)))
    menu.append(m)

    m = gtk.MenuItem("View artist profile of \"%s\"" % track[ARTIST])
    m.connect(
        "activate",
        lambda *x: blautil.open_url("http://last.fm/music/%s" % artist))
    menu.append(m)

    return menu
Beispiel #3
0
    def __button_press_event(self, event):
        if event.button not in (1, 2, 3):
            return True

        try:
            path = self.__treeview.get_path_at_pos(
                *map(int, [event.x, event.y]))[0]
        except TypeError:
            return False

        model = self.__treeview.get_model()
        event_ = model[path][0]
        if not isinstance(event_, BlaEvent):
            return True
        if event.button in (1, 2):
            if event.type in (gtk.gdk._2BUTTON_PRESS, gtk.gdk._3BUTTON_PRESS):
                return True
            return False

        model = self.__treeview.get_model()
        event_url = event_.event_url
        menu = gtk.Menu()
        m = gtk.MenuItem("View event page")
        m.connect("activate", lambda *x: blautil.open_url(event_url))
        menu.append(m)
        menu.show_all()
        menu.popup(None, None, None, event.button, event.time)

        return False
Beispiel #4
0
    def __button_press_event(self, event):
        if event.button not in (1, 2, 3):
            return True

        try:
            path = self.__treeview.get_path_at_pos(
                *map(int, [event.x, event.y]))[0]
        except TypeError:
            return False

        model = self.__treeview.get_model()
        release = model[path][0]
        if not isinstance(release, BlaRelease):
            return True
        if event.button in (1, 2):
            if event.type in (gtk.gdk._2BUTTON_PRESS, gtk.gdk._3BUTTON_PRESS):
                return True
            return False

        release_url = release.release_url
        artist_url = release.artist_url

        items = [
            ("View release page", lambda *x: blautil.open_url(release_url)),
            ("View artist profile", lambda *x: blautil.open_url(artist_url))
        ]

        user = blacfg.getstring("lastfm", "user")
        if user:
            artist_history_url = os.path.basename(release.artist_url)
            artist_history_url = (
                "http://www.last.fm/user/%s/library/music/%s" %
                (user, artist_history_url))
            items.append(("View artist history",
                          lambda *x: blautil.open_url(artist_history_url)))

        menu = gtk.Menu()
        for label, callback in items:
            m = gtk.MenuItem(label)
            m.connect("activate", callback)
            menu.append(m)

        menu.show_all()
        menu.popup(None, None, None, event.button, event.time)
        return False
Beispiel #5
0
 def __row_activated(self, treeview, path, column):
     blautil.open_url(treeview.get_model()[path][0].release_url)