#!/usr/bin/python
# -*- coding: UTF8 -*-

# -----------------------------------------------------------------------------
# Tux Droid - audacious remote script
# Copyright (C) 2007 Vincent Fretin <vincent.fretin@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# -----------------------------------------------------------------------------

"""
Use remote keys to control audacious media player and sound volume.
The following keys are supported:
K_VOLUMEPLUS K_VOLUMEMINUS K_PREVIOUS K_PLAYPAUSE K_NEXT K_STOP
Head button play/pause.

CHANGES
=======
2007/04/21 - version 1.0:
    - initial version
"""

__author__ = "Vincent Fretin (vincent.fretin@gmail.com)"
__version__ = "1.0"
__date__ = "2007/04/21"
__copyright__ = "Copyright (C) 2007 Vincent Fretin"
__license__ = "GPL2+"


import sys
sys.path.append('/opt/tuxdroid/api/python')
from tux import *

def remote_key_pressed(key):
    print "Button %s is pressed"%remote_bt_name[key]

tux.event.on_remote=remote_key_pressed

def increase_volume():
    tux.sys.shell("amixer set PCM 5%+")
def decrease_volume():
    tux.sys.shell("amixer set PCM 5%-")
def previous():
    tux.sys.shell("audacious --rew")
def play_pause():
    tux.sys.shell("audacious --play-pause")
def next():
    tux.sys.shell("audacious --fwd")
def stop():
    tux.sys.shell("audacious --stop")

tux.event.on_remote_bt[K_VOLUMEPLUS] = increase_volume
tux.event.on_remote_bt[K_VOLUMEMINUS] = decrease_volume
tux.event.on_remote_bt[K_PREVIOUS] = previous
tux.event.on_remote_bt[K_PLAYPAUSE] = play_pause
tux.event.on_remote_bt[K_NEXT] = next
tux.event.on_remote_bt[K_STOP] = stop

tux.event.on_head_bt_pushed = play_pause

# exit the script if tuxdaemon exited
tux.daemon.auto_connect(False)
while tux.daemon.connected:
    tux.sys.wait(1)
tux.destroy()
