amarok plugin



Hi all,

I wrote an Amarok plugin (see attachment & [1]) and I'd be happy to
get feedback on it (I only started using kupfer yesterday).

There are two things that I couldn't figure out:
- start amarok if not running and user hits "play" (via dbus)
- make sure Amarok does not show up twice in kupfer's menu. It shows
up once with the "Launch" option (like every normal application), and
a second time with the "Search Contents" option (that's my plugin).

I hope someone could help me find the solutions of these problems.

thanks & all the best,
andreas

[1] http://andreas.kotowicz.de/div/amarok.py
from __future__ import absolute_import

__kupfer_name__ = _("Amarok")
__kupfer_sources__ = ("AmarokSource", )
__description__ = _("Control Amarok media player.")
__version__ = "2010-10-22"
__author__ = "Andreas Kotowicz <andreas kotowicz gmail com>"

''' 
    TODO (don't know how to do these things):

        - start amarok if not running and user hits "play" (via dbus)
        - make sure Amarok does not show up twice in kupfer's menu

'''

import dbus

from kupfer.objects import RunnableLeaf, Source
from kupfer.obj.apps import AppLeafContentMixin
from kupfer import icons, pretty


from kupfer import plugin_support
plugin_support.check_dbus_connection()

SERVICE_NAME = "org.kde.amarok"
OBJECT_PATH = "/Player"

def _get_amarok():
	""" Return the dbus proxy object for Amarok
	    we will activate it over d-bus (start if not running)
	"""
	bus = dbus.SessionBus()
	try:
		amarok_obj = bus.get_object(SERVICE_NAME, OBJECT_PATH)
	except dbus.DBusException, e:
		pretty.print_error(__name__, e)
		return
	return amarok_obj

class StopAfterCurrent (RunnableLeaf):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("StopAfterCurrent"))
	def run(self):
		_get_amarok().StopAfterCurrent()
	def get_description(self):
		return _("Stop Amarok playback after current song")
	def get_icon_name(self):
		return "media-playback-stop"

class ShowOSD (RunnableLeaf):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("Show OSD"))
	def run(self):
		_get_amarok().ShowOSD()
	def get_description(self):
		return _("Show  Amarok OSD")
	def get_gicon(self):
		return icons.ComposedIcon("dialog-information", "audio-x-generic")
	def get_icon_name(self):
		return "dialog-information"

class Play (RunnableLeaf):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("Play"))
	def run(self):
		_get_amarok().Play()
	def get_description(self):
		return _("Resume playback in Amarok")
	def get_icon_name(self):
		return "media-playback-start"

class Pause (RunnableLeaf):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("Pause"))
	def run(self):
		_get_amarok().Pause()
	def get_description(self):
		return _("Pause playback in Amarok")
	def get_icon_name(self):
		return "media-playback-pause"

class Next (RunnableLeaf):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("Next"))
	def run(self):
		_get_amarok().Next()
	def get_description(self):
		return _("Jump to next track in Amarok")
	def get_icon_name(self):
		return "media-skip-forward"

class Previous (RunnableLeaf):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("Previous"))
	def run(self):
		_get_amarok().Prev()
	def get_description(self):
		return _("Jump to previous track in Amarok")
	def get_icon_name(self):
		return "media-skip-backward"

class Mute (RunnableLeaf):
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("Mute"))
	def run(self):
		_get_amarok().Mute()
	def get_description(self):
		return _("Mute / Unmute Amarok")
	def get_icon_name(self):
		return "audio-volume-muted"

class AmarokSource (AppLeafContentMixin, Source):
	appleaf_content_id = 'amarok'
	def __init__(self):
		Source.__init__(self, _("Amarok"))
	def get_items(self):
		yield Play()
		yield Pause()
		yield Next()
		yield Previous()
		yield Mute()
		yield StopAfterCurrent()
		yield ShowOSD()
	def provides(self):
		yield RunnableLeaf
	def get_description(self):
		return __description__
	def get_icon_name(self):
		return "amarok"

# EOF


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]