# plugin for pympd for track in list folowing.
# based on logger plugin by Natan 'whatah' Zohar

import gtk
import os
__name = 'Song Follow'
__version = '0.02'
__author = "Yasha Davidov"
__blurb = 'This plugin makes the cursor follow the current song in Now Playing'

class Songfollow:

    # called when we load the plugin. we get passed the mainWindow, plugin menu
    # item as well as a connection to mpd.
    def _init(self, data, get):
        self.xml, self.pluginMenu, self.pympd, self.base_dir, self.parser = data
        self.data = data
        #lets get main playlist window
        #self.playlistView = self.xml.get_widget("playlistTreeView")
        self.playlistBox = self.xml.get_widget("vbox12")
        self.jump = get('playlist_jump_to_song')

    def _conf(self, hasConf=False):
        if hasConf:
            return False

    # update plugin, data is of type mpdclient.Status
    def _spin(self, data, songChanged=False):
        #dont try to move playlist selection if it's not visible
        if not self.playlistBox.get_property('visible'):
            return
        song=self.pympd.getCurrentSong()
        if song == False:
            return
        if songChanged == True:
            #we got a new song
            #self.playlistView.set_cursor((int(song.pos),))
            self.jump(None)

    # called on plugin unloaded
    def _unload(self):
        return
