#! /usr/bin/env python

# Panflute
# Copyright (C) 2009 Paul Kuliniewicz <paul@kuliniewicz.org>
#
# 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., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.

"""
Launch the preferred player via the Panflute daemon, implicitly starting
the daemon if it isn't already running.

The intent of this script is to be used to automatically activate the
org.mpris.panflute service, though it could also be invoked directly.
"""

import dbus
import dbus.exceptions
import sys

if __name__ == "__main__":
    try:
        bus = dbus.SessionBus ()
        proxy = bus.get_object ("org.kuliniewicz.Panflute", "/connectors/preferred")
        connector = dbus.Interface (proxy, "org.kuliniewicz.Panflute.Connector")
        connector.Launch ()
    except dbus.exceptions.DBusException, e:
        sys.exit ("Couldn't launch player: {0}".format (e))
