#ifndef PLAYER_HPP
#define PLAYER_HPP

#include <cc++/thread.h>

#include "simplefile.hpp"

#include "config.hpp"

#include <string>

class Player : public ost::Thread
{
public:
  virtual bool play_next() 
  {
    if (play_next_track) {
      play_next_track = false;
      return true;
    } else
      return false;
  }
  
  virtual int is_playing() = 0;
  virtual int is_buffering() = 0;
  virtual int is_mute() = 0;
  virtual void gather_info() = 0;
  virtual void addfile(const Simplefile &file) = 0;
  virtual void play() = 0;
  void stop();
  virtual void stop_player() = 0;
  virtual void pause() = 0;
  virtual void ff() = 0;
  virtual void fb() = 0;

  virtual int getpos()=0;
  virtual void setpos(int p)=0;

  virtual void mute() = 0;
  virtual void volup() = 0;
  virtual void voldown() = 0;
  virtual int getvol()=0;
  virtual void setvol(int vol) = 0;

  virtual void update_cdrom(const std::string& cdrom) = 0;

  // for audio cd playback
  virtual void collect_info(const std::string& filename) = 0;
  
  virtual ~Player() {};

  void next();
  void prev();

  Simplefile p_cur_nr() const { return cur_nr; }
  void set_cur_nr(const Simplefile &state) { cur_nr = state; }

  virtual std::string p_title() const { return title; }
  virtual std::string p_artist() const { return artist; }
  virtual std::string p_album() const { return album; }

  void set_title(const std::string& t) { title = t; }
  void set_artist(const std::string& a) { artist = a; }
  void set_album(const std::string& a) { album = a; }

  int p_cur_time() const { return cur_time; }
  int p_total_time() const { return total_time; }

  void next_helper();

  // in percent
  int buffering_state;

  std::pair<int, bool> load_saved_values();

protected:

  void run() 
  {
    while (true)
      sleep (100000);
  }

  // implemented in terms of:
  Config *conf;

  void prev_helper();

  Player(const std::string& t, const std::string& art, 
	 const std::string& al, int ct, int tt, int bs);

  bool play_next_track;

  std::string last_type;
  
  int old_volume;

  Simplefile cur_nr;

  std::string title;
  std::string artist;
  std::string album;
  
  // in seconds
  int cur_time;
  int total_time;
};

#endif
